]> Shamusworld >> Repos - architektonas/commitdiff
Fixed Rotate tool to work with Arcs.
authorShamus Hammons <jlhamm@acm.org>
Thu, 7 May 2015 16:26:47 +0000 (11:26 -0500)
committerShamus Hammons <jlhamm@acm.org>
Thu, 7 May 2015 16:26:47 +0000 (11:26 -0500)
Also, minor bugfix in Geometry: the rotation vector was backwards.

README
src/drawingview.cpp
src/fileio.cpp
src/geometry.cpp
src/mathconstants.h
src/structs.h
src/utils.cpp

diff --git a/README b/README
index fba26cd6d3e10712487ed56f462557533a9c862d..e402b44569e12635b9868068aee50250b06ec402 100644 (file)
--- a/README
+++ b/README
@@ -43,7 +43,7 @@ RibbonSoft's product.
 Initial thoughts on naming centered around FooCAD or CADFoo (with Foo being
 whatever), but a long search on the internet brought forth the conclusion that
 such paths have been well trodden by just about anyone who has even given a
-thought towards creating computer aided design software. And so it was
+passing thought towards creating computer aided design software. And so it was
 manifestly clear that a different naming scheme would be required. After much
 reflection and several false starts, the name Architektonas was chosen as a
 rough English transliteration of the Greek word for architect. We feel it's a
index aeb764cc5781ff38364f7a99eb154c4898c360bd..8104f82b2ca7644698f60b67e1fecb46582d32f2 100644 (file)
@@ -370,13 +370,13 @@ void DrawingView::RenderObjects(Painter * painter, std::vector<void *> & v)
                {
                        Circle * ci = (Circle *)obj;
                        painter->SetBrush(QBrush(Qt::NoBrush));
-                       painter->DrawEllipse(ci->p[0], ci->radius, ci->radius);
+                       painter->DrawEllipse(ci->p[0], ci->radius[0], ci->radius[0]);
                        break;
                }
                case OTArc:
                {
                        Arc * a = (Arc *)obj;
-                       painter->DrawArc(a->p[0], a->radius, a->angle1, a->angle2);
+                       painter->DrawArc(a->p[0], a->radius[0], a->angle[0], a->angle[1]);
                        break;
                }
                case OTDimension:
@@ -707,7 +707,7 @@ void DrawingView::RotateHandler(int mode, Point p)
                        if (shiftDown)
                                return;
 
-                       double angle = Vector(toolPoint[1], toolPoint[0]).Angle();
+                       double angle = Vector(toolPoint[0], toolPoint[1]).Angle();
                        std::vector<void *>::iterator j = select.begin();
                        std::vector<Object>::iterator i = toolScratch.begin();
 
@@ -719,6 +719,15 @@ void DrawingView::RotateHandler(int mode, Point p)
                                Object * obj2 = (Object *)(*j);
                                obj2->p[0] = p1;
                                obj2->p[1] = p2;
+
+                               if (obj.type == OTArc)
+                               {
+//printf("Obj2->angle[0] = %f, obj.angle[0] = %f, angle = %f\n", obj2->angle[0], obj.angle[0], angle);
+                                       obj2->angle[0] = obj.angle[0] + angle;
+
+                                       if (obj2->angle[0] > PI_TIMES_2)
+                                               obj2->angle[0] -= PI_TIMES_2;
+                               }
                        }
                }
 
@@ -913,26 +922,25 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                }
 
                if (Global::selectionInProgress)
-               {
-                       // Select all the stuff inside of selection
                        Global::selectionInProgress = false;
 
-                       // Clear our vectors
-                       select.clear();
-                       hover.clear();
+// Should be we do this automagically? Hmm...
+               // Clear our vectors
+               select.clear();
+               hover.clear();
 
-                       // Scoop 'em up
-                       std::vector<void *>::iterator i;
+               // Scoop 'em up
+               std::vector<void *>::iterator i;
 
-                       for(i=document.objects.begin(); i!=document.objects.end(); i++)
-                       {
-                               if (((Object *)(*i))->selected)
-                                       select.push_back(*i);
+               for(i=document.objects.begin(); i!=document.objects.end(); i++)
+               {
+                       if (((Object *)(*i))->selected)
+                               select.push_back(*i);
 
 //hmm, this is no good, too late to do any good :-P
 //                             if ((*i)->hovered)
 //                                     hover.push_back(*i);
-                       }
+//                     }
                }
        }
        else if (event->button() == Qt::MiddleButton)
@@ -1058,7 +1066,7 @@ void DrawingView::CheckObjectBounds(void)
                {
                        Circle * c = (Circle *)obj;
 
-                       if (Global::selection.contains(c->p[0].x - c->radius, c->p[0].y - c->radius) && Global::selection.contains(c->p[0].x + c->radius, c->p[0].y + c->radius))
+                       if (Global::selection.contains(c->p[0].x - c->radius[0], c->p[0].y - c->radius[0]) && Global::selection.contains(c->p[0].x + c->radius[0], c->p[0].y + c->radius[0]))
                                c->selected = true;
 
                        break;
@@ -1067,8 +1075,8 @@ void DrawingView::CheckObjectBounds(void)
                {
                        Arc * a = (Arc *)obj;
 
-                       double start = a->angle1;
-                       double end = start + a->angle2;
+                       double start = a->angle[0];
+                       double end = start + a->angle[1];
                        QPointF p1(cos(start), sin(start));
                        QPointF p2(cos(end), sin(end));
                        QRectF bounds(p1, p2);
@@ -1119,8 +1127,8 @@ void DrawingView::CheckObjectBounds(void)
                        if ((start < ((3.0 * PI) + PI_OVER_2)) && (end > ((3.0 * PI) + PI_OVER_2)))
                                bounds.setBottom(-1.0);
 
-                       bounds.setTopLeft(QPointF(bounds.left() * a->radius, bounds.top() * a->radius));
-                       bounds.setBottomRight(QPointF(bounds.right() * a->radius, bounds.bottom() * a->radius));
+                       bounds.setTopLeft(QPointF(bounds.left() * a->radius[0], bounds.top() * a->radius[0]));
+                       bounds.setBottomRight(QPointF(bounds.right() * a->radius[0], bounds.bottom() * a->radius[0]));
                        bounds.translate(a->p[0].x, a->p[0].y);
 
                        if (Global::selection.contains(bounds))
index 27ed4f3c3ccec27eacee2403c6bc0b891863c5f3..101f0701f0059f98eca014ec36e1507bdc1bbb05 100644 (file)
@@ -113,8 +113,8 @@ OTHER CONSIDERATIONS:
 
 */
 
-enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc, OTFDimension,
-       OTFPolygon, OTFText, OTFImage, OTFBlock, OTFEndOfFile };
+enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc,
+       OTFDimension, OTFPolygon, OTFText, OTFImage, OTFBlock, OTFEndOfFile };
 
 
 /*static*/ bool FileIO::SaveAtnsFile(FILE * file, Container * object)
index e572fab6bbc64d93e8a6e1d85a01dfd6edf2bf2a..e0ad270c019d3e297c61786efe00974218384caf 100644 (file)
@@ -83,10 +83,14 @@ Point Geometry::MirrorPointAroundLine(Point point, Point tail, Point head)
 }
 
 
+//
+// point: The point we're rotating
+// rotationPoint: The point we're rotating around
+//
 Point Geometry::RotatePointAroundPoint(Point point, Point rotationPoint, double angle)
 {
-       Vector v = Vector(point, rotationPoint);
-//     Vector v = Vector(rotationPoint, point);
+//     Vector v = Vector(point, rotationPoint);
+       Vector v = Vector(rotationPoint, point);
        double px = (v.x * cos(angle)) - (v.y * sin(angle));
        double py = (v.x * sin(angle)) + (v.y * cos(angle));
 
index 1910a4eea071eb93ccdad254fcb8ac06e7cb2ad3..42f4940343c5119aa97867f63e225e01f643657e 100644 (file)
@@ -17,5 +17,7 @@
 #define PI                 3.14159265358979323846264338327
 #define PI_OVER_2          (PI / 2.0)
 #define PI3_OVER_2         ((3.0 * PI) / 2.0)
+#define PI_TIMES_2         (PI * 2.0)
 #define RADIANS_TO_DEGREES (180.0 / PI)
 #define DEGREES_TO_RADIANS (PI / 180.0)
+
index 398cfa773fd4390c1cb4e83e2afba75ed046eaac..e0e17c89bf8dd5ce82ce381cfd555051557ee79c 100644 (file)
@@ -7,7 +7,7 @@
 #include "global.h"
 #include "vector.h"
 
-enum ObjectType { OTNone, OTLine, OTCircle, OTEllipse, OTArc, OTDimension, OTSpline, OTText, OTContainer };
+enum ObjectType { OTNone, OTLine, OTCircle, OTEllipse, OTArc, OTPolygon, OTDimension, OTSpline, OTText, OTContainer };
 
 enum DimensionType { DTLinear, DTLinearVert, DTLinearHorz, DTRadial, DTDiametric, DTCircumferential, DTAngular, DTLeader };
 
@@ -26,7 +26,9 @@ enum ToolState { TSNone, TSPoint1, TSPoint2, TSDone };
        bool hovered;     \
        bool hitPoint[4]; \
        bool hitObject;   \
-       Point p[4];
+       Point p[4];       \
+       double angle[2];  \
+       double radius[2];
 
 struct Line {
        OBJECT_COMMON;
@@ -39,35 +41,32 @@ struct Line {
 
 struct Circle {
        OBJECT_COMMON;
-       double radius;
 
        Circle(): type(OTCircle), id(Global::objectID++) {}
        Circle(Vector pt1, double r, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTCircle), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), hitObject(false), radius(r) { p[0] = pt1; }
+               style(l), selected(false), hovered(false), hitObject(false)
+               { p[0] = pt1; radius[0] = r; }
 };
 
 struct Ellipse {
        OBJECT_COMMON;
-       double radius1;
-       double radius2;
 
        Ellipse(): type(OTEllipse), id(Global::objectID++) {}
        Ellipse(Vector pt1, Vector pt2, double r1, double r2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTEllipse), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), hitObject(false), radius1(r1), radius2(r2) { p[0] = pt1; p[1] = pt2; }
+               style(l), selected(false), hovered(false), hitObject(false)
+               { p[0] = pt1; p[1] = pt2; radius[0] = r1; radius[1] = r2; }
 };
 
 struct Arc {
        OBJECT_COMMON;
-       double radius;
-       double angle1;
-       double angle2;
 
        Arc(): type(OTArc), id(Global::objectID++) {}
        Arc(Vector pt1, double r, double a1, double a2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
                type(OTArc), id(Global::objectID++), layer(0), color(c), thickness(th),
-               style(l), selected(false), hovered(false), hitObject(false), radius(r), angle1(a1), angle2(a2) { p[0] = pt1; }
+               style(l), selected(false), hovered(false), hitObject(false)
+               { p[0] = pt1; radius[0] = r; angle[0] = a1, angle[1] = a2; }
 };
 
 struct Dimension {
@@ -91,10 +90,21 @@ struct Text {
                style(LSSolid), selected(false), hovered(false), hitObject(false), s(str) { p[0] = pt1; }
 };
 
+struct Polygon {
+       OBJECT_COMMON;
+
+       Polygon(): type(OTPolygon), id(Global::objectID++) {}
+};
+
+struct Spline {
+       OBJECT_COMMON;
+
+       Spline(): type(OTSpline), id(Global::objectID++) {}
+};
+
 struct Container {
        OBJECT_COMMON;
        std::vector<void *> objects;
-       double angle;
        double scale;
 
        Container(): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false) {}
index c6b457e8bb8e59e9802c64dfeb445c33b6e4d6b4..2c3e1a46ecd56d64084289e93d0c037538c283c0 100644 (file)
@@ -148,6 +148,10 @@ void RestorePointsTo(std::vector<void *> & v, std::vector<Object> & s)
                Object * obj2 = (Object *)(*j);
                obj2->p[0] = (*i).p[0];
                obj2->p[1] = (*i).p[1];
+               obj2->angle[0] = (*i).angle[0];
+               obj2->angle[1] = (*i).angle[1];
+//we don't do this because we want to keep selected & friends from changing
+//             memcpy(obj2, *j, sizeof(Object));
        }
 }