From: Shamus Hammons Date: Thu, 7 May 2015 16:26:47 +0000 (-0500) Subject: Fixed Rotate tool to work with Arcs. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=da1348151182fe5340495ff8243e662b96c1fbfa Fixed Rotate tool to work with Arcs. Also, minor bugfix in Geometry: the rotation vector was backwards. --- diff --git a/README b/README index fba26cd..e402b44 100644 --- 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 diff --git a/src/drawingview.cpp b/src/drawingview.cpp index aeb764c..8104f82 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -370,13 +370,13 @@ void DrawingView::RenderObjects(Painter * painter, std::vector & 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::iterator j = select.begin(); std::vector::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::iterator i; + // Scoop 'em up + std::vector::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)) diff --git a/src/fileio.cpp b/src/fileio.cpp index 27ed4f3..101f070 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -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) diff --git a/src/geometry.cpp b/src/geometry.cpp index e572fab..e0ad270 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -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)); diff --git a/src/mathconstants.h b/src/mathconstants.h index 1910a4e..42f4940 100644 --- a/src/mathconstants.h +++ b/src/mathconstants.h @@ -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) + diff --git a/src/structs.h b/src/structs.h index 398cfa7..e0e17c8 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 objects; - double angle; double scale; Container(): type(OTContainer), id(Global::objectID++), selected(false), hovered(false), hitObject(false) {} diff --git a/src/utils.cpp b/src/utils.cpp index c6b457e..2c3e1a4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -148,6 +148,10 @@ void RestorePointsTo(std::vector & v, std::vector & 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)); } }