]> Shamusworld >> Repos - architektonas/blobdiff - src/drawdimensionaction.cpp
Readded click to add dimension to object (for Line).
[architektonas] / src / drawdimensionaction.cpp
index 58fa09595028e0e884c54b52cf62073edff64492..d366c2277dacee4137a551b3d46e5e17fb645269 100644 (file)
 //
 
 #include "drawdimensionaction.h"
+#include "applicationwindow.h"
 #include "dimension.h"
+#include "drawingview.h"
+#include "line.h"
 #include "painter.h"
-//#include "vector.h"
 
 
-#define FIRST_POINT 0
-#define NEXT_POINT 1
+enum { FIRST_POINT, NEXT_POINT, NO_POINT };
 
 
 DrawDimensionAction::DrawDimensionAction(): state(0), dimension(NULL)
@@ -35,12 +36,11 @@ DrawDimensionAction::~DrawDimensionAction()
 {
        painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
 
-       // I think stuff like crosshairs should be done in the DrawingView, tho
        if (state == FIRST_POINT)
        {
                painter->DrawHandle(p1);
        }
-       else
+       else if (state == NEXT_POINT)
        {
                painter->DrawLine(p1, p2);
                painter->DrawHandle(p2);
@@ -50,6 +50,21 @@ DrawDimensionAction::~DrawDimensionAction()
 
 /*virtual*/ void DrawDimensionAction::MouseDown(Vector point)
 {
+       obj = ApplicationWindow::drawing->document.lastObjectClicked;
+
+       if (obj)
+       {
+               if (obj->type == OTLine)
+               {
+                       // Make sure we didn't hit an endpoint...
+                       if (!(((Line *) obj)->hitPoint1 || ((Line *)obj)->hitPoint2))
+                       {
+                               state = NO_POINT;
+                               return;
+                       }
+               }
+       }
+
        if (state == FIRST_POINT)
                p1 = point;
        else
@@ -68,7 +83,12 @@ DrawDimensionAction::~DrawDimensionAction()
 
 /*virtual*/ void DrawDimensionAction::MouseReleased(void)
 {
-       if (state == FIRST_POINT)
+       if (state == NO_POINT)
+       {
+               HandleAddDimensionToObject();//ApplicationWindow::drawing->document.lastObjectClicked);
+               state = FIRST_POINT;
+       }
+       else if (state == FIRST_POINT)
        {
                p2 = p1;
                state = NEXT_POINT;
@@ -77,13 +97,45 @@ DrawDimensionAction::~DrawDimensionAction()
        {
                // We create the new object here, and then pass it off to the
                // DrawingView which stuffs it into the document.
-//             line = new Line(p1, p2);
                dimension = new Dimension(p1, p2);
                // We don't need no stinkin' sentinels, when we have signals & slots!
                emit ObjectReady(dimension);
 
                state = FIRST_POINT;
-//             p1 = p2;
+       }
+}
+
+
+/*virtual*/ void DrawDimensionAction::KeyDown(int /*key*/)
+{
+}
+
+
+/*virtual*/ void DrawDimensionAction::KeyReleased(int /*key*/)
+{
+}
+
+
+void DrawDimensionAction::HandleAddDimensionToObject(void)//Object * obj)
+{
+//printf("Adding dimension to object...\n");
+       if (obj->type == OTLine)
+       {
+               Object * existing = ((Line *)obj)->FindAttachedDimension();
+
+               if (existing)
+               {
+                       ((Dimension *)existing)->FlipSides();
+               }
+//printf("--> type == LINE\n");
+               // Should also check here to see if it hit the line proper or just hit
+               // an endpoint...
+               else
+               {
+                       dimension = new Dimension(p1, p2);
+                       ((Line *)obj)->SetDimensionOnLine(dimension);
+                       emit ObjectReady(dimension);
+               }
        }
 }