]> Shamusworld >> Repos - architektonas/blobdiff - src/dimension.cpp
Fixed missing edge cases in line to line intersection function.
[architektonas] / src / dimension.cpp
index 63e1ba2e7f50b9b38778974d467e78b5a24c56e6..27823b39135fb8f7f7ed87f4d482476672a42b19 100644 (file)
@@ -20,7 +20,7 @@
 #include "painter.h"
 
 
-Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Object * p/*= NULL*/):
+Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/Object * p/*= NULL*/):
        Object(p1, p), endpoint(p2),
        dragging(false), draggingHandle1(false), draggingHandle2(false),
        length(p2.Magnitude()), dimensionType(dt), size(0.25), point1(NULL), point2(NULL)
@@ -31,7 +31,7 @@ Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Objec
 
 
 // This is bad, p1 & p2 could be NULL, causing much consternation...
-Dimension::Dimension(Connection p1, Connection p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/):
+Dimension::Dimension(Connection p1, Connection p2, DimensionType dt/*= DTLinear*/, Object * p/*= NULL*/):
        dragging(false), draggingHandle1(false), draggingHandle2(false),
        length(0), dimensionType(dt), size(0.25), point1(p1), point2(p2)
 {
@@ -61,6 +61,7 @@ all objects move as a unified whole.
 
 /*virtual*/ void Dimension::Draw(Painter * painter)
 {
+#if 0
        // If there are valid Vector pointers in here, use them to update the internal
        // positions. Otherwise, we just use the internal positions by default.
        if (point1.object)
@@ -68,11 +69,21 @@ all objects move as a unified whole.
 
        if (point2.object)
                endpoint = point2.object->GetPointAtParameter(point2.t);
+#endif
+
+       painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DotLine));
 
+       if ((state == OSSelected) || ((state == OSInactive) && hitPoint1))
+               painter->DrawHandle(position);
+
+       if ((state == OSSelected) || ((state == OSInactive) && hitPoint2))
+               painter->DrawHandle(endpoint);
+#if 1
        if (state == OSSelected)
-               painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
+               painter->SetPen(QPen(Qt::cyan, 1.0 * Painter::zoom * size, Qt::SolidLine));
        else
 //             painter->SetPen(QPen(Qt::blue, 1.0, Qt::SolidLine));
+#endif
                painter->SetPen(QPen(Qt::blue, 1.0 * Painter::zoom * size, Qt::SolidLine));
 
        painter->SetBrush(QBrush(QColor(Qt::blue)));
@@ -186,16 +197,16 @@ I believe they are pixels.
 
        if (hitPoint1)
        {
-//             oldState = state;
-//             state = OSSelected;
+               oldState = state;
+               state = OSSelected;
                oldPoint = position;
                draggingHandle1 = true;
                return true;
        }
        else if (hitPoint2)
        {
-//             oldState = state;
-//             state = OSSelected;
+               oldState = state;
+               state = OSSelected;
                oldPoint = endpoint;
                draggingHandle2 = true;
                return true;
@@ -208,42 +219,39 @@ I believe they are pixels.
 
 /*virtual*/ void Dimension::PointerMoved(Vector point)
 {
-       // We know this is true because mouse move messages don't come here unless
-       // the object was actually clicked on--therefore we *know* we're being
-       // dragged...
-       objectWasDragged = true;
-
-/*     if (dragging)
+       if (selectionInProgress)
        {
-               // Here we need to check whether or not we're dragging a handle or the object itself...
-               Vector delta = point - oldPoint;
-
-               position += delta;
-               endpoint += delta;
+               // Check for whether or not the rect contains this line
+               if (selection.contains(position.x, position.y)
+                       && selection.contains(endpoint.x, endpoint.y))
+                       state = OSSelected;
+               else
+                       state = OSInactive;
 
-               oldPoint = point;
-               needUpdate = true;
+               return;
        }
-       else*/ if (draggingHandle1)
-       {
-               Vector delta = point - oldPoint;
 
-               position += delta;
+       // Hit test tells us what we hit (if anything) through boolean variables. (It
+       // also tells us whether or not the state changed. --not any more)
+       SaveHitState();
+       HitTest(point);
+       needUpdate = HitStateChanged();
 
-               oldPoint = point;
-               needUpdate = true;
-       }
-       else if (draggingHandle2)
+       objectWasDragged = (/*draggingLine |*/ draggingHandle1 | draggingHandle2);
+
+       if (objectWasDragged)
        {
                Vector delta = point - oldPoint;
 
-               endpoint += delta;
+               if (draggingHandle1)// || draggingLine)
+                       position += delta;
+
+               if (draggingHandle2)// || draggingLine)
+                       endpoint += delta;
 
                oldPoint = point;
                needUpdate = true;
        }
-       else
-               needUpdate = false;
 }
 
 
@@ -316,6 +324,23 @@ about keeping track of old states...
 }
 
 
+void Dimension::SaveHitState(void)
+{
+       oldHitPoint1 = hitPoint1;
+       oldHitPoint2 = hitPoint2;
+//     oldHitLine = hitLine;
+}
+
+
+bool Dimension::HitStateChanged(void)
+{
+       if ((hitPoint1 != oldHitPoint1) || (hitPoint2 != oldHitPoint2))
+               return true;
+
+       return false;
+}
+
+
 /*virtual*/ void Dimension::Enumerate(FILE * file)
 {
        fprintf(file, "DIMENSION %i (%lf,%lf) (%lf,%lf) %i\n", layer, position.x, position.y, endpoint.x, endpoint.y, type);
@@ -352,6 +377,17 @@ same reference number.
 }
 
 
+/*virtual*/ void Dimension::MovePointAtParameter(double parameter, Vector v)
+{
+       if (parameter == 0)
+               position += v;
+       else if (parameter == 1.0)
+               endpoint += v;
+       else
+               {} // Not sure how to handle this case :-P
+}
+
+
 /*virtual*/ void Dimension::Connect(Object * obj, double param)
 {
        // There are four possibilities here...