]> Shamusworld >> Repos - architektonas/commitdiff
In the middle of removing Snapper class/fixing snapper rendering...
authorShamus Hammons <jlhamm@acm.org>
Tue, 19 Oct 2010 03:36:43 +0000 (03:36 +0000)
committerShamus Hammons <jlhamm@acm.org>
Tue, 19 Oct 2010 03:36:43 +0000 (03:36 +0000)
28 files changed:
architektonas.pro
src/actions/actiondrawarc.cpp
src/actions/actiondrawarc3p.cpp
src/actions/actiondrawarctangential.cpp
src/actions/actiondrawline.cpp
src/actions/actiondrawpolyline.cpp
src/actions/actiondrawpolyline.h
src/actions/actionmodifymirror.cpp
src/actions/actionmodifytrim.cpp
src/actions/actionpolylineadd.cpp
src/actions/actionpolylineadd.h
src/actions/actionpolylineappend.cpp
src/actions/actionpolylineappend.h
src/actions/actionpolylinedel.cpp
src/actions/actionpolylinedel.h
src/actions/actionpolylinedelbetween.cpp
src/actions/actionpolylinedelbetween.h
src/actions/actionpolylinetrim.cpp
src/actions/actionpolylinetrim.h
src/base/actioninterface.cpp
src/base/actioninterface.h
src/base/eventhandler.cpp
src/base/snapper.cpp
src/forms/polylineoptions.cpp
src/forms/polylineoptions.h
src/mainapp/graphicview.cpp
src/mainapp/graphicview.h
src/widgets/qg_graphicview.cpp

index 417a853fe1de7483916eb0095fe57a2621e80590..a4c73df7bf9861eec6aa18d0eeb544e889e3bbd5 100644 (file)
@@ -27,6 +27,15 @@ INCLUDEPATH += \
        src/widgets \
        src/forms
 
+DEPENDPATH = \
+       fparser \
+       dxflib/include \
+       src/mainapp \
+       src/actions \
+       src/base \
+       src/widgets \
+       src/forms
+
 HEADERS = \
        fparser/fparser.hh
 
index a833e58caa481b42c94fa5de44c60a253e194b5a..3a92e6f90f5b35345cb33c33ebef19b537d3cc45 100644 (file)
@@ -12,6 +12,7 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  06/03/2010  Added this text. :-)
+// JLH  09/17/2010  Fixed preview/snapper rendering.
 //
 
 #include "actiondrawarc.h"
@@ -62,19 +63,15 @@ void ActionDrawArc::trigger()
        container->addEntity(arc);
 
        // upd. undo list:
-       if (document != NULL)
+       if (document)
        {
                document->startUndoCycle();
                document->addUndoable(arc);
                document->endUndoCycle();
        }
 
-       deleteSnapper();
-       graphicView->moveRelativeZero(Vector(0.0, 0.0));
-       graphicView->drawEntity(arc);
        graphicView->moveRelativeZero(arc->getCenter());
-       drawSnapper();
-
+       graphicView->redraw();  //hm.
        setStatus(SetCenter);
        reset();
 
@@ -97,10 +94,8 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
                if (data.center.valid)
                {
                        data.radius = data.center.distanceTo(mouse);
-                       deletePreview();
-                       clearPreview();
-//                     preview->addEntity(new Circle(preview, CircleData(data.center, data.radius)));
-                       drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Circle(&(graphicView->preview), CircleData(data.center, data.radius)));
                }
                break;
 
@@ -112,26 +107,20 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
                else
                        data.angle2 = Math::correctAngle(data.angle1 + M_PI / 3);
 
-               deletePreview();
-               clearPreview();
-//             preview->addEntity(new Arc(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                break;
 
        case SetAngle2:
                data.angle2 = data.center.angleTo(mouse);
-               deletePreview();
-               clearPreview();
-//             preview->addEntity(new Arc(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                break;
 
        case SetIncAngle:
                data.angle2 = data.angle1 + data.center.angleTo(mouse);
-               deletePreview();
-               clearPreview();
-//             preview->addEntity(new Arc(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                break;
 
        case SetChordLength:
@@ -141,18 +130,17 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
                if (fabs(x / (2 * data.radius)) <= 1.0)
                {
                        data.angle2 = data.angle1 + asin(x / (2 * data.radius)) * 2;
-                       deletePreview();
-                       clearPreview();
-//                     preview->addEntity(new Arc(preview, data));
-                       drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                }
        }
-       break;
+               break;
 
        default:
                break;
        }
 
+       graphicView->redraw();
        DEBUG->print("ActionDrawArc::mouseMoveEvent end");
 }
 
@@ -165,9 +153,10 @@ void ActionDrawArc::mouseReleaseEvent(QMouseEvent * e)
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+//             deleteSnapper();
                init(getStatus() - 1);
+               graphicView->redraw();  //hm.
        }
 }
 
@@ -251,35 +240,35 @@ void ActionDrawArc::commandEvent(CommandEvent * e)
 
        switch (getStatus())
        {
-       case SetRadius: {
+       case SetRadius:
+       {
                bool ok;
                double r = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
                        data.radius = r;
                        setStatus(SetAngle1);
                }
-               else if (DIALOGFACTORY != NULL)
+               else if (DIALOGFACTORY)
                        DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
        }
-       break;
+               break;
 
-       case SetAngle1: {
+       case SetAngle1:
+       {
                bool ok;
                double a = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
                        data.angle1 = Math::deg2rad(a);
                        setStatus(SetAngle2);
                }
-               else if (DIALOGFACTORY != NULL)
+               else if (DIALOGFACTORY)
                        DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
        }
-       break;
+               break;
 
        case SetAngle2:
 
@@ -292,53 +281,51 @@ void ActionDrawArc::commandEvent(CommandEvent * e)
                        bool ok;
                        double a = Math::eval(c, &ok);
 
-                       if (ok == true)
+                       if (ok)
                        {
                                data.angle2 = Math::deg2rad(a);
                                trigger();
                        }
-                       else if (DIALOGFACTORY != NULL)
+                       else if (DIALOGFACTORY)
                                DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
                }
                break;
 
-       case SetIncAngle: {
+       case SetIncAngle:
+       {
                bool ok;
                double a = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
                        data.angle2 = data.angle1 + Math::deg2rad(a);
                        trigger();
                }
-               else if (DIALOGFACTORY != NULL)
+               else if (DIALOGFACTORY)
                        DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
        }
-       break;
+               break;
 
-       case SetChordLength: {
+       case SetChordLength:
+       {
                bool ok;
                double l = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
                        if (fabs(l / (2 * data.radius)) <= 1.0)
                        {
                                data.angle2 = data.angle1 + asin(l / (2 * data.radius)) * 2;
                                trigger();
                        }
-                       else if (DIALOGFACTORY != NULL)
-                               DIALOGFACTORY->commandMessage(
-                                       tr("Not a valid chord length"));
+                       else if (DIALOGFACTORY)
+                               DIALOGFACTORY->commandMessage(tr("Not a valid chord length"));
 
                }
-               else if (DIALOGFACTORY != NULL)
+               else if (DIALOGFACTORY)
                        DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
        }
-       break;
+               break;
 
        default:
                break;
@@ -354,7 +341,7 @@ QStringList ActionDrawArc::getAvailableCommands()
 
 void ActionDrawArc::updateMouseButtonHints()
 {
-       if (DIALOGFACTORY != NULL)
+       if (DIALOGFACTORY)
        {
                switch (getStatus())
                {
index 77ed90f16def627cc7306b0915142a4d555863c5..46eeb37c57ae3d25990407913f5a476ab455d83c 100644 (file)
@@ -12,6 +12,7 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  06/03/2010  Added this text. :-)
+// JLH  09/17/2010  Fixed preview/snapper rendering.
 //
 
 #include "actiondrawarc3p.h"
@@ -61,19 +62,19 @@ void ActionDrawArc3P::trigger()
                container->addEntity(arc);
 
                // upd. undo list:
-               if (document != NULL)
+               if (document)
                {
                        document->startUndoCycle();
                        document->addUndoable(arc);
                        document->endUndoCycle();
                }
 
-               deleteSnapper();
-               graphicView->moveRelativeZero(Vector(0.0, 0.0));
-               graphicView->drawEntity(arc);
+//             deleteSnapper();
+//             graphicView->moveRelativeZero(Vector(0.0, 0.0));
+//             graphicView->drawEntity(arc);
                graphicView->moveRelativeZero(arc->getEndpoint());
-               drawSnapper();
-
+//             drawSnapper();
+               graphicView->redraw();
                setStatus(SetPoint1);
                reset();
        }
@@ -88,9 +89,9 @@ void ActionDrawArc3P::preparePreview()
        if (point1.valid && point2.valid && point3.valid)
        {
                Arc arc(NULL, data);
-               bool suc = arc.createFrom3P(point1, point2, point3);
+               bool success = arc.createFrom3P(point1, point2, point3);
 
-               if (suc)
+               if (success)
                        data = arc.getData();
        }
 }
@@ -116,6 +117,8 @@ void ActionDrawArc3P::mouseMoveEvent(QMouseEvent * e)
 //                     clearPreview();
 //                     preview->addEntity(line);
 //                     drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(point1, point2)));
                }
                break;
 
@@ -131,12 +134,16 @@ void ActionDrawArc3P::mouseMoveEvent(QMouseEvent * e)
 //                     clearPreview();
 //                     preview->addEntity(arc);
 //                     drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                }
                break;
 
        default:
                break;
        }
+
+       graphicView->redraw();
 }
 
 void ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e)
@@ -148,9 +155,10 @@ void ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e)
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+//             deleteSnapper();
                init(getStatus() - 1);
+               graphicView->redraw();
        }
 }
 
index f1691fcf6fc051780e875b49ef6c50b2979a5270..a8a16c6d505c14c25a1517e4625a86fdb19e2163 100644 (file)
@@ -12,6 +12,7 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  06/03/2010  Added this text. :-)
+// JLH  09/17/2010  Fixed preview/snapper rendering.
 //
 
 #include "actiondrawarctangential.h"
@@ -22,8 +23,8 @@
 #include "graphicview.h"
 #include "preview.h"
 
-ActionDrawArcTangential::ActionDrawArcTangential(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw arcs tangential",
-               container, graphicView)
+ActionDrawArcTangential::ActionDrawArcTangential(EntityContainer & container, GraphicView & graphicView):
+       ActionInterface("Draw arcs tangential", container, graphicView)
 {
        reset();
 }
@@ -68,26 +69,26 @@ void ActionDrawArcTangential::trigger()
        container->addEntity(arc);
 
        // upd. undo list:
-       if (document != NULL)
+       if (document)
        {
                document->startUndoCycle();
                document->addUndoable(arc);
                document->endUndoCycle();
        }
 
-       deleteSnapper();
-       graphicView->moveRelativeZero(Vector(0.0, 0.0));
-       graphicView->drawEntity(arc);
+//     deleteSnapper();
+//     graphicView->moveRelativeZero(Vector(0.0, 0.0));
+//     graphicView->drawEntity(arc);
        graphicView->moveRelativeZero(arc->getCenter());
-       drawSnapper();
-
+//     drawSnapper();
+       graphicView->redraw();  //hm.
        setStatus(SetBaseEntity);
        reset();
 }
 
 void ActionDrawArcTangential::preparePreview()
 {
-       if (baseEntity != NULL && point.valid)
+       if (baseEntity && point.valid)
        {
                Vector startPoint;
                double direction;
@@ -129,6 +130,9 @@ void ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
 //                     clearPreview();
 //                     preview->addEntity(arc);
 //                     drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
+                       graphicView->redraw();
                }
                break;
 
@@ -149,7 +153,7 @@ void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
                        Vector coord = graphicView->toGraph(e->x(), e->y());
                        Entity * entity = catchEntity(coord, RS2::ResolveAll);
 
-                       if (entity != NULL)
+                       if (entity)
                        {
                                if (entity->isAtomic())
                                {
@@ -184,9 +188,10 @@ void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+       //      deleteSnapper();
                init(getStatus() - 1);
+               graphicView->redraw();  //hm.
        }
 }
 
index a0be6db85b6a1812c2b6164fc4d61e61173e1c61..8bc0bb13401dca28548f90df534bed0bca53addf 100644 (file)
@@ -29,12 +29,8 @@ ActionDrawLine::ActionDrawLine(EntityContainer & container, GraphicView & graphi
 {
        DEBUG->print("ActionDrawLine::ActionDrawLine");
        reset();
-       //hm.
-//     graphicView.snapper.SetContainer(&container);
-//     graphicView.snapper.SetGraphicView(&graphicView);
-//     graphicView.snapper.SetVisible();
-//     graphicView.preview.SetVisible();
        DEBUG->print("ActionDrawLine::ActionDrawLine: OK");
+//printf("ActionDrawLine(): preview is%s visible, snapper is%s visible...\n", (graphicView.preview.Visible() ? "" : " NOT"), (graphicView.snapper.Visible() ? "" : " NOT"));
 }
 
 ActionDrawLine::~ActionDrawLine()
@@ -97,7 +93,8 @@ void ActionDrawLine::mouseMoveEvent(QMouseEvent * e)
        DEBUG->print("ActionDrawLine::mouseMoveEvent begin");
 
        DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point");
-       Vector mouse = graphicView->snapper.snapPoint(e);
+//     Vector mouse = graphicView->snapper.snapPoint(e);
+       Vector mouse = graphicView->SnapPoint(e);
        DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point: OK");
 
        if (getStatus() == SetEndpoint && data.startpoint.valid)
@@ -125,6 +122,10 @@ void ActionDrawLine::mouseMoveEvent(QMouseEvent * e)
 #endif
        }
 
+//OK, snapper & preview are set as NOT visible... why???
+//becuz other things are created in the meantime which turn this stuff off, treating
+//it like it isn't a shared resource which it is...
+//printf("ActionDrawLine::mouseMoveEvent(): preview is%s visible, snapper is%s visible...\n", (graphicView->preview.Visible() ? "" : " NOT"), (graphicView->snapper.Visible() ? "" : " NOT"));
        //hm. [ok, this works. :-D]
        graphicView->redraw();
        DEBUG->print("ActionDrawLine::mouseMoveEvent end");
@@ -134,23 +135,19 @@ void ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
 {
        if (e->button() == Qt::LeftButton)
        {
-               Vector ce(graphicView->snapper.snapPoint(e));
+//             Vector ce(graphicView->snapper.snapPoint(e));
+               Vector ce(graphicView->SnapPoint(e));
                coordinateEvent(&ce);
        }
        else if (e->button() == Qt::RightButton)
        {
-//             if (getStatus() == 0)
-//             {
-//                     graphicView->snapper.SetVisible(false);
-//                     graphicView->preview.SetVisible(false);
-//             }
-
                init(getStatus() - 1);
        }
 
        //hm. [Seems to work OK.]
-       graphicView->preview.clear();                           // Remove entities from container
-       graphicView->redraw();
+       //shouldn't need this...
+//     graphicView->preview.clear();                           // Remove entities from container
+//     graphicView->redraw();
 }
 
 void ActionDrawLine::coordinateEvent(Vector * e)
index 03925ab8439e53609338b5ba5b7150d10a80ace8..65a7270cfe55611c655f1cfc745c83f04e29e78a 100644 (file)
 
 ActionDrawPolyline::ActionDrawPolyline(EntityContainer & container,
        GraphicView & graphicView):
-       ActionInterface("Draw polyline", container, graphicView)
+       ActionInterface("Draw polyline", container, graphicView), vertex(false), polyline(NULL)
 {
-       vertex = Vector(false);
-       polyline = NULL;
+//     vertex = Vector(false);
 }
 
 ActionDrawPolyline::~ActionDrawPolyline()
@@ -43,7 +42,6 @@ void ActionDrawPolyline::trigger()
        if (polyline)
        {
                container->addEntity(polyline);
-//             deleteSnapper();
 
                if (document)
                {
@@ -54,11 +52,13 @@ void ActionDrawPolyline::trigger()
 
                DEBUG->print("ActionDrawPolyline::trigger(): polyline added: %d", polyline->getId());
                polyline = NULL;
+               graphicView->redraw();  //hm.
        }
 }
 
 void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e)
 {
+#if 0
        if (vertex.valid && polyline)
        {
                Vector v = snapPoint(e);
@@ -73,16 +73,68 @@ void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e)
                vertex = v;
                DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId());
        }
+#else
+       Vector mouse = graphicView->snapper.snapPoint(e);
+
+       if (getStatus() == SetNextPoint && startPoint.valid)
+       {
+               // We have to draw a line or arc depending on the state of the "Arc"
+               // checkbox.
+               // We'll start with lines...
+               graphicView->preview.clear();
+               Line * line = new Line(&(graphicView->preview), LineData(startPoint, mouse));
+
+               if (polyline)
+                       graphicView->preview.addEntity(polyline);
+
+               graphicView->preview.addEntity(line);
+       }
+
+       graphicView->redraw();  //hm.
+#endif
+
+#if 0
+       Vector mouse = graphicView->snapper.snapPoint(e);
+       DEBUG->print("ActionDrawLine::mouseMoveEvent: snap point: OK");
+
+       if (getStatus() == SetEndpoint && data.startpoint.valid)
+       {
+               DEBUG->print("ActionDrawLine::mouseMoveEvent: update preview");
+               // This is lame. Creating a new Line every time the endpoint moves.
+               // Surely we can alter the line entity inside the preview, no?
+#if 0
+               graphicView->preview.clear();                   // Remove entities from the container
+               Line * line = new Line(&(graphicView->preview), LineData(data.startpoint, mouse));
+               graphicView->preview.addEntity(line);
+#else
+               // We can assume there's only one line in there, can't we?
+               Line * line = (Line *)graphicView->preview.firstEntity(RS2::ResolveNone);
+
+               if (line)
+               {
+                       line->setEndpoint(mouse);
+               }
+               else
+               {
+                       line = new Line(&(graphicView->preview), LineData(data.startpoint, mouse));
+                       graphicView->preview.addEntity(line);
+               }
+#endif
+       }
+
+       //hm. [ok, this works. :-D]
+       graphicView->redraw();
+#endif
 }
 
 void ActionDrawPolyline::mousePressEvent(QMouseEvent * e)
 {
        if (e->button() == Qt::LeftButton)
        {
-               vertex = snapPoint(e);
-               polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
-               polyline->setLayerToActive();
-               polyline->setPenToActive();
+//             vertex = snapPoint(e);
+//             polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
+//             polyline->setLayerToActive();
+//             polyline->setPenToActive();
        }
 }
 
@@ -90,29 +142,97 @@ void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e)
 {
        if (e->button() == Qt::LeftButton)
        {
-               vertex = Vector(false);
-               trigger();
+               Vector ce(graphicView->snapper.snapPoint(e));
+               coordinateEvent(&ce);
+
+//let's try this...
+               if (!polyline)
+               {
+//printf("ActionDrawPolyline::mouseReleaseEvent(): Creating polyline...\n");
+                       polyline = new Polyline(container, PolylineData(ce, ce, 0));
+//                     vertex = snapPoint(e);
+//                     polyline = new Polyline(container, PolylineData(vertex, vertex, 0));
+                       polyline->setLayerToActive();
+                       polyline->setPenToActive();
+               }
+               else
+               {
+//printf("ActionDrawPolyline::mouseReleaseEvent(): Adding vertex to polyline...\n");
+                       Entity * ent = polyline->addVertex(ce);
+                       ent->setLayerToActive();
+                       ent->setPenToActive();
+               }
        }
        else if (e->button() == Qt::RightButton)
        {
+#if 0
                if (polyline)
                {
                        delete polyline;
                        polyline = NULL;
                }
+#else
+//             if (getStatus() == SetFirstPoint)
+//ANY right button should trigger (? what about adding twice? won't happen)
+               trigger();      // this will set the polyline to NULL once added to the container
+#endif
 
-//             deleteSnapper();
                init(getStatus() - 1);
                graphicView->redraw();  //hm.
        }
 }
 
+void ActionDrawPolyline::coordinateEvent(Vector * coordinate)
+{
+       DEBUG->print("ActionDrawPolyline::coordinateEvent");
+
+       if (!coordinate)
+       {
+               DEBUG->print("ActionDrawPolyline::coordinateEvent: event was NULL");
+               return;
+       }
+
+//     Vector mouse = *e;
+
+       switch (getStatus())
+       {
+       case SetFirstPoint:
+               startPoint = *coordinate;
+//             ClearHistory();
+//             history.append(new Vector(mouse));
+//             start = data.startpoint;
+               setStatus(SetNextPoint);
+               graphicView->moveRelativeZero(*coordinate);
+//             trigger();
+               updateMouseButtonHints();
+               break;
+
+       case SetNextPoint:
+//             data.endpoint = mouse;
+//             history.append(new Vector(mouse));
+//             startPoint = endPoint;
+               startPoint = *coordinate;
+//             trigger();
+               updateMouseButtonHints();
+               break;
+
+       default:
+               break;
+       }
+
+       DEBUG->print("ActionDrawPolyline::coordinateEvent: OK");
+}
+
 void ActionDrawPolyline::updateMouseButtonHints()
 {
        switch (getStatus())
        {
-       case 0:
-               DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
+       case SetFirstPoint:
+               DIALOGFACTORY->updateMouseWidget(tr("Set first point"), tr("Cancel"));
+               break;
+
+       case SetNextPoint:
+               DIALOGFACTORY->updateMouseWidget(tr("Set next point"), tr("Back"));
                break;
 
        default:
index 171e5ea7a8cde99b42833494aba6442720daeda5..b344c577c2f5d090888bc9c1266cb3a906bfeea6 100644 (file)
@@ -27,9 +27,10 @@ class ActionDrawPolyline: public ActionInterface
 
                virtual RS2::ActionType rtti();
                virtual void trigger();
-               virtual void mouseMoveEvent(QMouseEvent * e);
-               virtual void mousePressEvent(QMouseEvent * e);
-               virtual void mouseReleaseEvent(QMouseEvent * e);
+               virtual void mouseMoveEvent(QMouseEvent *);
+               virtual void mousePressEvent(QMouseEvent *);
+               virtual void mouseReleaseEvent(QMouseEvent *);
+               virtual void coordinateEvent(Vector *);
                virtual void updateMouseButtonHints();
                virtual void updateMouseCursor();
                virtual void updateToolBar();
@@ -40,6 +41,7 @@ class ActionDrawPolyline: public ActionInterface
 
        protected:
                Vector vertex;
+               Vector startPoint;
                Polyline * polyline;
                /** Start point of the series of lines. Used for close function. */
                Vector start;
index 786aeeb1704c52afea9b56e8968e04be98572a47..c0cf0e7fa6f6131215c9ee8f5bec537ff5c25e8f 100644 (file)
@@ -65,18 +65,25 @@ void ActionModifyMirror::mouseMoveEvent(QMouseEvent * e)
                        {
                                axisPoint2 = mouse;
 
-                               deletePreview();
-                               clearPreview();
+//                             deletePreview();
+//                             clearPreview();
 /*                             preview->addSelectionFrom(*container);
                                preview->mirror(axisPoint1, axisPoint2);
                                preview->addEntity(new Line(preview,LineData(axisPoint1, axisPoint2)));*/
-                               drawPreview();
+//                             drawPreview();
+                               graphicView->preview.clear();
+                               graphicView->preview.addSelectionFrom(*container);
+                               graphicView->preview.mirror(axisPoint1, axisPoint2);
+                               graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(axisPoint1, axisPoint2)));
+                               graphicView->redraw();
                        }
                        break;
 
                default:
                        break;
                }
+
+               graphicView->redraw();
        }
 
        DEBUG->print("ActionModifyMirror::mouseMoveEvent end");
@@ -91,9 +98,10 @@ void ActionModifyMirror::mouseReleaseEvent(QMouseEvent * e)
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+//             deleteSnapper();
                init(getStatus() - 1);
+               graphicView->redraw();  //hm.
        }
 }
 
@@ -123,10 +131,11 @@ void ActionModifyMirror::coordinateEvent(Vector * e)
                        {
                                data.axisPoint1 = axisPoint1;
                                data.axisPoint2 = axisPoint2;
-                               deletePreview();
-                               clearPreview();
+//                             deletePreview();
+//                             clearPreview();
                                trigger();
                                finish();
+                               graphicView->redraw();  //hm.
                        }
                }
                break;
@@ -148,14 +157,12 @@ void ActionModifyMirror::updateMouseButtonHints()
                    break;*/
                case SetAxisPoint1:
                        DIALOGFACTORY->updateMouseWidget(
-                               tr("Specify first point of mirror line"),
-                               tr("Cancel"));
+                               tr("Specify first point of mirror line"), tr("Cancel"));
                        break;
 
                case SetAxisPoint2:
                        DIALOGFACTORY->updateMouseWidget(
-                               tr("Specify second point of mirror line"),
-                               tr("Back"));
+                               tr("Specify second point of mirror line"), tr("Back"));
                        break;
 
                default:
@@ -172,7 +179,7 @@ void ActionModifyMirror::updateMouseCursor()
 
 void ActionModifyMirror::updateToolBar()
 {
-       if (DIALOGFACTORY != NULL)
+       if (DIALOGFACTORY)
        {
                switch (getStatus())
                {
index efbc6a06289c850c69f0ece612983ac57040672b..f11d064a47604486009563d263f90a08baf25456 100644 (file)
@@ -12,6 +12,7 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/22/2010  Added this text. :-)
+// JLH  09/17/2010  Fixed preview/snapper rendering somewhat. Some bugs remain.
 //
 
 #include "actionmodifytrim.h"
  * @param both Trim both entities.
  */
 ActionModifyTrim::ActionModifyTrim(EntityContainer & container,
-       GraphicView & graphicView, bool both): ActionInterface("Trim Entity",
-               container, graphicView)
+       GraphicView & graphicView, bool b):
+       ActionInterface("Trim Entity", container, graphicView),
+       limitEntity(NULL), limitCoord(false), trimEntity(NULL), trimCoord(false),
+       both(b)
 {
-       trimEntity = NULL;
-       trimCoord = Vector(false);
-       limitEntity = NULL;
-       limitCoord = Vector(false);
-       this->both = both;
+//     trimEntity = NULL;
+//     trimCoord = Vector(false);
+//     limitEntity = NULL;
+//     limitCoord = Vector(false);
+//     this->both = both;
 }
 
 ActionModifyTrim::~ActionModifyTrim()
@@ -53,16 +56,17 @@ void ActionModifyTrim::trigger()
        if (trimEntity && trimEntity->isAtomic() && limitEntity)
        {
                Modification m(*container, graphicView);
-               m.trim(trimCoord, (AtomicEntity *)trimEntity,
-                       limitCoord, limitEntity, both);
+               m.trim(trimCoord, (AtomicEntity *)trimEntity, limitCoord, limitEntity,
+                       both);
 
                trimEntity = NULL;
 
                if (both)
                {
                        limitEntity->setHighlighted(false);
-                       graphicView->drawEntity(limitEntity);
+//                     graphicView->drawEntity(limitEntity);
                        setStatus(ChooseLimitEntity);
+                       graphicView->redraw();  //hm.
                }
                else
                        setStatus(ChooseTrimEntity);
@@ -113,8 +117,9 @@ void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
                        if (limitEntity)
                        {
                                limitEntity->setHighlighted(true);
-                               graphicView->drawEntity(limitEntity);
+//                             graphicView->drawEntity(limitEntity);
                                setStatus(ChooseTrimEntity);
+                               graphicView->redraw();  //hm.
                        }
                        break;
 
@@ -122,7 +127,7 @@ void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
                        trimCoord = mouse;
                        trimEntity = se;
 
-                       if (trimEntity != NULL && trimEntity->isAtomic())
+                       if (trimEntity && trimEntity->isAtomic())
                                trigger();
                        break;
 
@@ -132,15 +137,17 @@ void ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e)
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+//             deleteSnapper();
 
-               if (limitEntity != NULL)
+               if (limitEntity)
                {
                        limitEntity->setHighlighted(false);
-                       graphicView->drawEntity(limitEntity);
+//                     graphicView->drawEntity(limitEntity);
                }
+
                init(getStatus() - 1);
+               graphicView->redraw();  //hm.
        }
 }
 
@@ -183,4 +190,3 @@ void ActionModifyTrim::updateToolBar()
 {
        DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
 }
-
index 6188943feea8fdfc4837aefe7eb6ec043e622f51..436f5c2c47320228697068da73fe17eccd104ea0 100644 (file)
@@ -33,3 +33,8 @@ ActionPolylineAdd::~ActionPolylineAdd()
                delete polyline;
 }
 
+/*virtual*/ RS2::ActionType ActionPolylineAdd::rtti()
+{
+       return RS2::ActionPolylineAdd;
+}
+
index 630be491c63ba8fb4c7383e8d7acf0a068031487..471340d5a41b0e240e9be1a102a2942c4a9769d8 100644 (file)
@@ -16,6 +16,7 @@ class ActionPolylineAdd: public ActionInterface
                ActionPolylineAdd(EntityContainer & container, GraphicView & graphicView);
                ~ActionPolylineAdd();
 
+               virtual RS2::ActionType rtti();
 //             virtual void init(int status = 0);
 //             virtual void trigger();
 //             virtual void mouseMoveEvent(QMouseEvent * e);
index 8a936f8ea965de9a8b04850f2acdc34b2debe81f..528ec93f5cdba550a812cdb3048b4cc4e7f368c5 100644 (file)
@@ -33,3 +33,8 @@ ActionPolylineAppend::~ActionPolylineAppend()
                delete polyline;
 }
 
+/*virtual*/ RS2::ActionType ActionPolylineAppend::rtti()
+{
+       return RS2::ActionPolylineAppend;
+}
+
index 0921402c755028c507429641269ef0407a3753e8..c51bf13781b66ce8526d090d1a3c57a1f3fb5d9a 100644 (file)
@@ -16,6 +16,7 @@ class ActionPolylineAppend: public ActionInterface
                ActionPolylineAppend(EntityContainer & container, GraphicView & graphicView);
                ~ActionPolylineAppend();
 
+               virtual RS2::ActionType rtti();
 //             virtual void init(int status = 0);
 //             virtual void trigger();
 //             virtual void mouseMoveEvent(QMouseEvent * e);
index 078e57b5d8778fc8d68c1b7bb83a0e9dcc5cbac3..af4be0bee7d74fe11b27ed2221b61bd826e5aa40 100644 (file)
@@ -33,3 +33,8 @@ ActionPolylineDel::~ActionPolylineDel()
                delete polyline;
 }
 
+/*virtual*/ RS2::ActionType ActionPolylineDel::rtti()
+{
+       return RS2::ActionPolylineDel;
+}
+
index 3c7d78d4182f97c6402407fa02329ab35889dec8..b940b98f2d2daac2211babe4ccb27c3506207df3 100644 (file)
@@ -16,6 +16,7 @@ class ActionPolylineDel: public ActionInterface
                ActionPolylineDel(EntityContainer & container, GraphicView & graphicView);
                ~ActionPolylineDel();
 
+               virtual RS2::ActionType rtti();
 //             virtual void init(int status = 0);
 //             virtual void trigger();
 //             virtual void mouseMoveEvent(QMouseEvent * e);
index 09b096ae8415a6e06dd289f3d4e93a82482694ec..6c9eff4ea89450ef95e4e926d4b398f38b307511 100644 (file)
@@ -33,3 +33,8 @@ ActionPolylineDelBetween::~ActionPolylineDelBetween()
                delete polyline;
 }
 
+/*virtual*/ RS2::ActionType ActionPolylineDelBetween::rtti()
+{
+       return RS2::ActionPolylineDelBetween;
+}
+
index dd8f7ae77bfa123ee3092a24d2e1dd0c38bb0d7e..ae25e5d2e22e9113d552ea4f3e0341737a92294a 100644 (file)
@@ -16,6 +16,7 @@ class ActionPolylineDelBetween: public ActionInterface
                ActionPolylineDelBetween(EntityContainer & container, GraphicView & graphicView);
                ~ActionPolylineDelBetween();
 
+               virtual RS2::ActionType rtti();
 //             virtual void init(int status = 0);
 //             virtual void trigger();
 //             virtual void mouseMoveEvent(QMouseEvent * e);
index ea12e6fd9156489aed1d0b45d167467776d60b35..884cfef759a5fd3f72227e701ec19dcea71e0289 100644 (file)
@@ -33,3 +33,8 @@ ActionPolylineTrim::~ActionPolylineTrim()
                delete polyline;
 }
 
+/*virtual*/ RS2::ActionType ActionPolylineTrim::rtti()
+{
+       return RS2::ActionPolylineTrim;
+}
+
index b1d82c1a7ed77993c498f46228af319fb06b1dea..d88ec3ee655372f259dff9b28cffccba8d888068 100644 (file)
@@ -16,6 +16,7 @@ class ActionPolylineTrim: public ActionInterface
                ActionPolylineTrim(EntityContainer & container, GraphicView & graphicView);
                ~ActionPolylineTrim();
 
+               virtual RS2::ActionType rtti();
 //             virtual void init(int status = 0);
 //             virtual void trigger();
 //             virtual void mouseMoveEvent(QMouseEvent * e);
index 92b77452451cdb88ea7e26184701cced317fa340..17d1da9f3ba958e95fdeeb77099f5936eb5bdf2a 100644 (file)
 
 #include "commands.h"
 #include "debug.h"
+#include "dialogfactory.h"
 #include "entitycontainer.h"
 #include "graphicview.h"
+#include "grid.h"
+
+/*
+I think what's needed here is for the constructor to save the state of the snapper
+and to restore it in the destructor. This, of course, assumes that the actions are
+created and used in a certain order, perhaps that needs enforcement? Dunno, but worth
+a try as suspend() and resume() seem to fuck it up badly.
+*/
 
 /**
  * Constructor.
  *                    note that an action belongs to this view.
  */
 ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
-       GraphicView & gv): graphicView(&gv), container(&ec)
+       GraphicView & gv): graphicView(&gv), container(&ec),
+//     snapperVisibility(false), previewVisibility(false), suspendCount(0)
+//hm.
+       snapperVisibility(true), previewVisibility(true), suspendCount(0)
 {
        DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
 
@@ -50,17 +62,20 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
        // Document pointer will be used for undo / redo
        document = ec.getDocument();
 
+       // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
        // This is here until I can figure out a better way to contain all of this
        // circular referential nonsense that exists in this codebase. It will be
        // expunged, by Grabthar's Hammer!
-       graphicView->snapper.SetContainer(container);
-       graphicView->snapper.SetGraphicView(graphicView);       // <-- THIS is what I mean! INSANE!
+//     graphicView->snapper.SetContainer(container);
+//     graphicView->snapper.SetGraphicView(graphicView);       // <-- THIS is what I mean! INSANE!
        // Not all actions use these. Perhaps we need to pass params to the contructor
        // in order to set these? Setting the default to true for both?
-       graphicView->snapper.SetVisible();
+//     graphicView->snapper.SetVisible();
+       graphicView->SetSnapperVisible();
        graphicView->preview.SetVisible();
 
        DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
+printf("ActionInterface::ActionInterface() [%08X]\n", this);
 }
 
 /**
@@ -71,6 +86,7 @@ ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
        // would be pure virtual now:
        // hideOptions();
 //JLH: Only it isn't pure virtual...
+printf("ActionInterface::~ActionInterface() [%08X]\n", this);
 }
 
 /**
@@ -112,9 +128,11 @@ void ActionInterface::init(int status/*= 0*/)
        }
        else    // status < 0, e.g. this action is finished
        {
-               graphicView->snapper.SetVisible(false);
+//             graphicView->snapper.SetVisible(false);
+               graphicView->SetSnapperVisible(false);
                graphicView->preview.SetVisible(false);
                graphicView->preview.clear();
+               graphicView->redraw();  //hm.
        }
 }
 
@@ -208,9 +226,9 @@ QStringList ActionInterface::getAvailableCommands()
  *               of progress and decreases when the user goes one
  *               step back (i.e. presses the right mouse button).
  */
-void ActionInterface::setStatus(int status)
+void ActionInterface::setStatus(int value)
 {
-       this->status = status;
+       status = value;
 
        if (status < 0)
        {
@@ -295,6 +313,12 @@ void ActionInterface::finish()
 //     Snapper::finish();              // Sets Snapper::finished = true
        // I think this is where we want to update the screen...
 //     graphicView->redraw();
+       // hm.
+//     graphicView->snapper.SetVisible(false);
+       graphicView->SetSnapperVisible(false);
+       graphicView->preview.SetVisible(false);
+//     graphicView->preview.clear();
+       graphicView->redraw();  //hm.
        DEBUG->print("ActionInterface::finish: OK");
 }
 
@@ -307,15 +331,31 @@ void ActionInterface::setPredecessor(ActionInterface * p)
        predecessor = p;
 }
 
+#if 0
+Here is a problem. suspend() and resume() don't do what they should:
+The problem is that Actions are modifying a shared resource though it's acting
+as if it were not. Case in point below: ActionZoomPan sets the snapper/preview
+visibility to FALSE and then EventHandler calls suspend() here, which queries
+the graphicView to see what its state is. We need to fix this...!
+
+This ties into the problem where we have GraphicView pointers scattered all
+over the place. We need to fix that too!
+#endif
 /**
  * Suspends this action while another action takes place.
  */
 void ActionInterface::suspend()
 {
+#if 0
+printf("ActionInterface::suspend(%i): [%08X] ", ++suspendCount, this);
        // Maybe this is where we need to save the state of the snapper
        // & preview objects???
 //     graphicView->setMouseCursor(RS2::ArrowCursor);
 //     Snapper::suspend();
+       snapperVisibility = graphicView->snapper.Visible();
+       previewVisibility = graphicView->preview.Visible();
+printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
+#endif
 }
 
 /**
@@ -323,9 +363,17 @@ void ActionInterface::suspend()
  */
 void ActionInterface::resume()
 {
+#if 0
+if (suspendCount == 0)
+       printf("!!! RESUME BEFORE SUSPEND !!!\n");
+printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
        updateMouseCursor();
        updateToolBar();
 //     Snapper::resume();
+       graphicView->snapper.SetVisible(snapperVisibility);
+       graphicView->preview.SetVisible(previewVisibility);
+printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
+#endif
 }
 
 /**
@@ -373,17 +421,18 @@ QString ActionInterface::msgAvailableCommands()
 // this one. May go away in the future.
 Vector ActionInterface::snapPoint(QMouseEvent * e)
 {
-       return graphicView->snapper.snapPoint(e);
+//     return graphicView->snapper.snapPoint(e);
+       return graphicView->SnapPoint(e);
 }
 
 Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
 {
-       return graphicView->snapper.catchEntity(e, level);
+       return graphicView->CatchEntity(e, level);
 }
 
 Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
 {
-       return graphicView->snapper.catchEntity(v, level);
+       return graphicView->CatchEntity(v, level);
 }
 
 #warning "!!! Dummy functions need to be deleted once all actions no longer use these !!!"
index a88ee89fa1855d7a7ec6043f0404ac0475b7115b..5ae1d6be36505b00c7bb7faaf7b89f1dc2d6ba97 100644 (file)
@@ -81,31 +81,30 @@ class ActionInterface: public QObject
                 * corner (status 0), and selecting the second corner (status 1).
                 */
                int status;
+               bool snapperVisibility;
+               bool previewVisibility;
+               int suspendCount;
 
        protected:
                /** Action name. Used internally for debugging */
                QString name;
-
                /**
                 * This flag is set when the action has terminated and can be deleted.
                 */
                bool finished;
-
                /**
                 * Pointer to the graphic is this container is a graphic. NULL otherwise
                 */
                Drawing * graphic;
-
                /**
                 * Pointer to the document (graphic or block) or NULL.
                 */
                Document * document;
-
                /**
                 * Predecessor of this action or NULL.
                 */
                ActionInterface * predecessor;
-
+               // hm.
                GraphicView * graphicView;
                EntityContainer * container;
 };
index a8b64179e4207ff8a8a504d10759cdcb1a6de70f..d8d8f2b7addb572252841a57393cabb92cff5a10 100644 (file)
@@ -45,7 +45,7 @@ EventHandler::~EventHandler()
 {
        DEBUG->print("EventHandler::~EventHandler");
 
-       if (defaultAction != NULL)
+       if (defaultAction)
        {
                defaultAction->finish();
                delete defaultAction;
@@ -164,11 +164,22 @@ void EventHandler::mouseMoveEvent(QMouseEvent * e)
        }
 }
 
+#if 0
+Small problem with this approach: Resumes can happen before suspend actions!
+This can wreak havoc with things like snapper/preview states and the like...
+
+Actually, this stuff seems to be pretty useless. Not sure what is accomplished
+by this crap. The only thing I can think of is that it would cause a preview
+to be removed if the mouse goes out of the drawing window, could be a legit
+purpose but this seems too retarded for that. Why wouldn't you just code that
+into GraphicView itself and be done with it?
+#endif
 /**
  * Called by GraphicView
  */
 void EventHandler::mouseLeaveEvent()
 {
+#if 0
        if (actionIndex >= 0 && currentActions[actionIndex]
                && !currentActions[actionIndex]->isFinished())
        {
@@ -180,6 +191,7 @@ void EventHandler::mouseLeaveEvent()
                        defaultAction->suspend();
                //DEBUG->print("currently no action defined");
        }
+#endif
 }
 
 /**
@@ -187,6 +199,7 @@ void EventHandler::mouseLeaveEvent()
  */
 void EventHandler::mouseEnterEvent()
 {
+#if 0
        if (actionIndex >= 0 && currentActions[actionIndex]
                && !currentActions[actionIndex]->isFinished())
        {
@@ -197,6 +210,7 @@ void EventHandler::mouseEnterEvent()
                if (defaultAction)
                        defaultAction->resume();
        }
+#endif
 }
 
 /**
@@ -584,8 +598,8 @@ void EventHandler::cleanUp()
 {
        DEBUG->print("EventHandler::cleanUp");
 
-       int o = 0;                              // old index
-       int n = 0;                              // new index
+       int oldIndex = 0;               // old index
+       int newIndex = 0;               // new index
        int resume = 0;                 // index of action to resume
        bool doResume = false;  // do we need to resume an action
        actionIndex = -1;
@@ -594,41 +608,41 @@ void EventHandler::cleanUp()
 
        do
        {
-               // search first used action (o)
-               while (currentActions[o] == NULL && o < RS_MAXACTIONS)
-                       o++;
+               // Search first used action (oldIndex)
+               while (currentActions[oldIndex] == NULL && oldIndex < RS_MAXACTIONS)
+                       oldIndex++;
 
-               // delete action if it is finished
-               if (o < RS_MAXACTIONS && currentActions[o] != NULL
-                       && currentActions[o]->isFinished())
+               // Delete action if it is finished
+               if (oldIndex < RS_MAXACTIONS && currentActions[oldIndex] != NULL
+                       && currentActions[oldIndex]->isFinished())
                {
-                       delete currentActions[o];
-                       currentActions[o] = NULL;
+                       delete currentActions[oldIndex];
+                       currentActions[oldIndex] = NULL;
                        doResume = true;
                }
 
-               // move a running action up in the stack
-               if (o < RS_MAXACTIONS && currentActions[o] != NULL)
+               // Move a running action up in the stack
+               if (oldIndex < RS_MAXACTIONS && currentActions[oldIndex] != NULL)
                {
-                       if (n != o)
+                       if (newIndex != oldIndex)
                        {
-                               currentActions[n] = currentActions[o];
-                               resume = n;
-                               currentActions[o] = NULL;
+                               currentActions[newIndex] = currentActions[oldIndex];
+                               resume = newIndex;
+                               currentActions[oldIndex] = NULL;
                        }
                        else
                        {
-                               if (o < RS_MAXACTIONS)
-                                       o++;
+                               if (oldIndex < RS_MAXACTIONS)
+                                       oldIndex++;
                        }
 
-                       actionIndex = n;
+                       actionIndex = newIndex;
 
-                       if (n < RS_MAXACTIONS - 1)
-                               n++;
+                       if (newIndex < RS_MAXACTIONS - 1)
+                               newIndex++;
                }
        }
-       while (o < RS_MAXACTIONS);
+       while (oldIndex < RS_MAXACTIONS);
 
        debugActions();
 
index 24aaebff5ab221f29efad1e15dd12f8e3b7f4847..28e600adee65ed2e09d7540062a4b65703627711 100644 (file)
@@ -12,6 +12,8 @@
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/21/2010  Added this text. :-)
+// JLH  10/18/2010  Commented out all functions in preparation for deprecating
+//                  this class.
 //
 
 #include "snapper.h"
 Snapper::Snapper(EntityContainer & c, GraphicView & gv):
        container(&c), graphicView(&gv), finished(false)
 {
+#if 0
        init();
+#endif
 }
 
 Snapper::Snapper(void):
        container(NULL), graphicView(NULL), finished(false)
 {
+#if 0
        init();
+#endif
 }
 
 /**
@@ -52,6 +58,7 @@ Snapper::~Snapper()
  */
 void Snapper::init()
 {
+#if 0
        if (graphicView)
        {
                snapMode = graphicView->getDefaultSnapMode();
@@ -74,56 +81,76 @@ void Snapper::init()
        // Sanity check
        if (snapRange < 2)
                snapRange = 20;
+#endif
 }
 
 void Snapper::finish()
 {
+#if 0
        finished = true;
+#endif
 }
 
 //bleh
 void Snapper::SetContainer(EntityContainer * c)
 {
+#if 0
        container = c;
+#endif
 }
 
 //bleh
 void Snapper::SetGraphicView(GraphicView * v)
 {
+#if 0
        graphicView = v;
+#endif
 }
 
 /**
  * @return Pointer to the entity which was the key entity for the last
  * successful snapping action. If the snap mode is "end point" the key entity
- * is the entity whos end point was caught. If the snap mode didn't require an
+ * is the entity whose end point was caught. If the snap mode didn't require an
  * entity (e.g. free, grid) this method will return NULL.
  */
 Entity * Snapper::getKeyEntity()
 {
+#if 0
        return keyEntity;
+#endif
+       return NULL;
 }
 
 /** Sets a new snap mode. */
 void Snapper::setSnapMode(RS2::SnapMode snapMode)
 {
+#if 0
        this->snapMode = snapMode;
+#endif
 }
 
 /** Sets a new snap restriction. */
 void Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
 {
+#if 0
        this->snapRes = snapRes;
+#endif
 }
 
 RS2::SnapMode Snapper::getSnapMode(void)
 {
+#if 0
        return snapMode;
+#endif
+       return RS2::SnapFree;
 }
 
 RS2::SnapRestriction Snapper::getSnapRestriction(void)
 {
+#if 0
        return snapRes;
+#endif
+       return RS2::RestrictNothing;
 }
 
 /**
@@ -133,9 +160,14 @@ RS2::SnapRestriction Snapper::getSnapRestriction(void)
  */
 void Snapper::setSnapRange(int r)
 {
+#if 0
        snapRange = r;
+#endif
 }
 
+#if 0
+This should get moved into GraphicView...
+#endif
 /**
  * Snap to a coordinate in the drawing using the current snap mode.
  *
@@ -144,6 +176,7 @@ void Snapper::setSnapRange(int r)
  */
 Vector Snapper::snapPoint(QMouseEvent * e)
 {
+#if 0
        DEBUG->print("Snapper::snapPoint");
        snapSpot = Vector(false);
 
@@ -217,6 +250,8 @@ Vector Snapper::snapPoint(QMouseEvent * e)
        DEBUG->print("Snapper::snapPoint: OK");
 
        return snapCoord;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -227,8 +262,11 @@ Vector Snapper::snapPoint(QMouseEvent * e)
  */
 Vector Snapper::snapFree(Vector coord)
 {
+#if 0
        keyEntity = NULL;
        return coord;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -239,10 +277,13 @@ Vector Snapper::snapFree(Vector coord)
  */
 Vector Snapper::snapEndpoint(Vector coord)
 {
+#if 0
        Vector vec(false);
        vec = container->getNearestEndpoint(coord, NULL);
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -253,6 +294,7 @@ Vector Snapper::snapEndpoint(Vector coord)
  */
 Vector Snapper::snapGrid(Vector coord)
 {
+#if 0
        DEBUG->print("Snapper::snapGrid begin");
 
        Vector vec(false);
@@ -295,6 +337,8 @@ Vector Snapper::snapGrid(Vector coord)
        DEBUG->print("Snapper::snapGrid end");
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -305,10 +349,13 @@ Vector Snapper::snapGrid(Vector coord)
  */
 Vector Snapper::snapOnEntity(Vector coord)
 {
+#if 0
        Vector vec(false);
        vec = container->getNearestPointOnEntity(coord, true, NULL, &keyEntity);
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -319,10 +366,13 @@ Vector Snapper::snapOnEntity(Vector coord)
  */
 Vector Snapper::snapCenter(Vector coord)
 {
+#if 0
        Vector vec(false);
        vec = container->getNearestCenter(coord, NULL);
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -333,10 +383,13 @@ Vector Snapper::snapCenter(Vector coord)
  */
 Vector Snapper::snapMiddle(Vector coord)
 {
+#if 0
        Vector vec(false);
        vec = container->getNearestMiddle(coord, NULL);
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -347,10 +400,13 @@ Vector Snapper::snapMiddle(Vector coord)
  */
 Vector Snapper::snapDist(Vector coord)
 {
+#if 0
        Vector vec(false);
        vec = container->getNearestDist(distance, coord, NULL);
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -361,10 +417,13 @@ Vector Snapper::snapDist(Vector coord)
  */
 Vector Snapper::snapIntersection(Vector coord)
 {
+#if 0
        Vector vec(false);
        vec = container->getNearestIntersection(coord, NULL);
 
        return vec;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -376,6 +435,7 @@ Vector Snapper::snapIntersection(Vector coord)
  */
 Vector Snapper::restrictOrthogonal(Vector coord)
 {
+#if 0
        Vector rz = graphicView->getRelativeZero();
        Vector ret(coord);
 
@@ -388,6 +448,8 @@ Vector Snapper::restrictOrthogonal(Vector coord)
                ret = retx;
 
        return ret;
+#endif
+       return Vector(false);
 }
 
 /**
@@ -399,9 +461,12 @@ Vector Snapper::restrictOrthogonal(Vector coord)
  */
 Vector Snapper::restrictHorizontal(Vector coord)
 {
+#if 0
        Vector rz = graphicView->getRelativeZero();
 
        return Vector(coord.x, rz.y);
+#endif
+       return Vector(false);
 }
 
 /**
@@ -413,9 +478,12 @@ Vector Snapper::restrictHorizontal(Vector coord)
  */
 Vector Snapper::restrictVertical(Vector coord)
 {
+#if 0
        Vector rz = graphicView->getRelativeZero();
 
        return Vector(rz.x, coord.y);
+#endif
+       return Vector(false);
 }
 
 /**
@@ -428,13 +496,12 @@ Vector Snapper::restrictVertical(Vector coord)
  */
 Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level)
 {
+#if 0
        DEBUG->print("Snapper::catchEntity");
 
-       // set default distance for points inside solids
+       // Set default distance for points inside solids
        double dist = graphicView->toGraphDX(snapRange) * 0.9;
-
        Entity * entity = container->getNearestEntity(pos, &dist, level);
-
        int idx = -1;
 
        if (entity && entity->getParent())
@@ -442,17 +509,19 @@ Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level)
 
        if (entity && dist <= graphicView->toGraphDX(snapRange))
        {
-               // highlight:
+               // Highlight:
                DEBUG->print("Snapper::catchEntity: found: %d", idx);
                return entity;
        }
-       else
-       {
-               DEBUG->print("Snapper::catchEntity: not found");
-               return NULL;
-       }
+//     else
+//     {
+       DEBUG->print("Snapper::catchEntity: not found");
+       return NULL;
+//     }
 
-       DEBUG->print("Snapper::catchEntity: OK");
+//     DEBUG->print("Snapper::catchEntity: OK");
+#endif
+       return NULL;
 }
 
 /**
@@ -465,18 +534,26 @@ Entity * Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level)
  */
 Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
 {
-    return catchEntity(Vector(graphicView->toGraphX(e->x()),
+#if 0
+       return catchEntity(Vector(graphicView->toGraphX(e->x()),
                graphicView->toGraphY(e->y())), level);
+#endif
+       return NULL;
 }
 
+#if 0
+I think that these suspend() & resume() functions are not used anymore...
+#endif
 /**
  * Suspends this snapper while another action takes place.
  */
 /*virtual*/ void Snapper::suspend()
 {
+#if 0
 #warning "!!! This may need to have SetVisibility() called !!!"
 //     deleteSnapper();
        snapSpot = snapCoord = Vector(false);
+#endif
 }
 
 /**
@@ -484,8 +561,10 @@ Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void Snapper::resume()
 {
+#if 0
 #warning "!!! This may need to have SetVisibility() called !!!"
 //     drawSnapper();
+#endif
 }
 
 /**
@@ -493,8 +572,10 @@ Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void Snapper::hideOptions()
 {
+#if 0
        if (snapMode == RS2::SnapDist && DIALOGFACTORY)
                DIALOGFACTORY->requestSnapDistOptions(distance, false);
+#endif
 }
 
 /**
@@ -502,18 +583,24 @@ Entity * Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void Snapper::showOptions()
 {
+#if 0
        if (snapMode == RS2::SnapDist && DIALOGFACTORY)
                DIALOGFACTORY->requestSnapDistOptions(distance, true);
+#endif
 }
 
 void Snapper::SetVisible(bool visibility/*= true*/)
 {
+#if 0
        visible = visibility;
+#endif
 }
 
 bool Snapper::Visible(void)
 {
+#if 0
        return visible;
+#endif
 }
 
 /*
@@ -524,14 +611,13 @@ GraphicView class... What to do?
 */
 void Snapper::Draw(GraphicView * view, PaintInterface * painter)
 {
+#if 0
        if (finished || !snapSpot.valid || !snapCoord.valid)
                return;
 
 //hm, I don't like graphicView kicking around in here, especially since it now
 //lives inside GraphicView... How to !!! FIX !!!?
 //We'll pass it in for now...
-//     if (snapCoord.valid)
-//     {
        // Snap point (need to make sure the brush is NULL!)
 //     painter->setPen(Pen(Color(0, 127, 255), RS2::Width00, RS2::DashLine));
        painter->setPen(Pen(Color(255, 127, 0), RS2::Width00, RS2::DashLine));
@@ -546,9 +632,8 @@ void Snapper::Draw(GraphicView * view, PaintInterface * painter)
                painter->drawLine(Vector(view->toGuiX(snapCoord.x), 0),
                        Vector(view->toGuiX(snapCoord.x), view->getHeight()));
        }
-//     }
 
-       if (/*snapCoord.valid &&*/ snapCoord != snapSpot)
+       if (snapCoord != snapSpot)
        {
                painter->drawLine(view->toGui(snapSpot) + Vector(-5, 0),
                        view->toGui(snapSpot) + Vector(-1, 4));
@@ -559,4 +644,5 @@ void Snapper::Draw(GraphicView * view, PaintInterface * painter)
                painter->drawLine(view->toGui(snapSpot) + Vector(0, -5),
                        view->toGui(snapSpot) + Vector(-4, -1));
        }
+#endif
 }
index bdc194e1e9a83f214939d4b35187ac08fb7cc875..36ecd6f764b1e2712891c01ca63908ca6f63a0f8 100644 (file)
 
 PolylineOptions::PolylineOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
        QWidget(parent, flags), action(NULL),
-       bClose(new QToolButton(this)),
-       bUndo(new QToolButton(this))
+       closeButton(new QToolButton(this)),
+       undoButton(new QToolButton(this)),
+       arcCheckBox(new QCheckBox(this)),
+       radiusLabel(new QLabel(this)),
+       radiusEdit(new QLineEdit(this))
 {
        QHBoxLayout * layout = new QHBoxLayout(this);
        layout->setContentsMargins(0, 0, 0, 0);
 
-       bClose->setText(tr("Close"));
-       bUndo->setText(tr("Undo"));
+       closeButton->setText(tr("Close"));
+       undoButton->setText(tr("Undo"));
+       arcCheckBox->setText(tr("Arc"));
+       radiusLabel->setText(tr("Radius:"));
 
-       layout->addWidget(bClose);
-       layout->addWidget(bUndo);
+       layout->addWidget(closeButton);
+       layout->addWidget(undoButton);
+       layout->addWidget(arcCheckBox);
+       layout->addWidget(radiusLabel);
+       layout->addWidget(radiusEdit);
 
-       connect(bClose, SIGNAL(clicked()), this, SLOT(close()));
-       connect(bUndo, SIGNAL(clicked()), this, SLOT(undo()));
+       connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+       connect(undoButton, SIGNAL(clicked()), this, SLOT(undo()));
 
        // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
        // nothing will show up on the screen. :-)
index fa4ecfd3a7eded4e58f5e4133659f596ec60eed2..98d0f07d274c538eedcdf15859b2b314fba48180 100644 (file)
@@ -23,8 +23,11 @@ class PolylineOptions: public QWidget
                ActionDrawPolyline * action;
 
        private:
-               QToolButton * bClose;
-               QToolButton * bUndo;
+               QToolButton * closeButton;
+               QToolButton * undoButton;
+               QCheckBox * arcCheckBox;
+               QLabel * radiusLabel;
+               QLineEdit * radiusEdit;
 };
 
 #endif // __POLYLINEOPTIONS_H__
index 4c8ba107be210da42b9afbcfab09937f1ea8ec5e..5b633b2b3a56af1859772b16f4941bf5ac659f10 100644 (file)
@@ -77,6 +77,24 @@ GraphicView::GraphicView(): background(), foreground()
        simulationSmooth = false;
        simulationRapid = false;
        simulationRunning = false;
+
+       // Snapper settings...
+       snapEntity = NULL;
+       snapSpot = Vector(false);
+       snapCoord = Vector(false);
+       snapperVisible = false;
+       snapDistance = 1.0;
+
+       settings.beginGroup("Snap");
+       snapRange = settings.value("Range", 20).toInt();
+       settings.endGroup();
+       settings.beginGroup("Appearance");
+       showCrosshairs = settings.value("ShowCrosshairs", true).toBool();
+       settings.endGroup();
+
+       // Sanity check for snapRange
+       if (snapRange < 2)
+               snapRange = 20;
 }
 
 /**
@@ -919,7 +937,8 @@ void GraphicView::zoomAutoY(bool axis)
                                x1 = toGuiX(l->getStartpoint().x);
                                x2 = toGuiX(l->getEndpoint().x);
 
-                               if (x1 > 0.0 && x1 < (double)getWidth() || x2 > 0.0 && x2 < (double)getWidth())
+                               if ((x1 > 0.0 && x1 < (double)getWidth())
+                                       || (x2 > 0.0 && x2 < (double)getWidth()))
                                {
                                        minY = std::min(minY, l->getStartpoint().y);
                                        minY = std::min(minY, l->getEndpoint().y);
@@ -1176,7 +1195,8 @@ void GraphicView::drawWindow(Vector v1, Vector v2)
 
 /**
  * Draws the entities. If painter is NULL a new painter will
- * be created and destroyed.
+ * be created and destroyed. [NB: Not any more, we don't let the programmer try
+ * to outsmart the toolkit anymore. :-P
  */
 void GraphicView::drawIt()
 {
@@ -2329,3 +2349,354 @@ bool GraphicView::getSimulationRapid()
 {
        return simulationRapid;
 }
+
+/**
+ * Catches an entity which is close to the given position 'pos'.
+ *
+ * @param pos A graphic coordinate.
+ * @param level The level of resolving for iterating through the entity
+ *        container
+ * @return Pointer to the entity or NULL.
+ */
+Entity * GraphicView::CatchEntity(const Vector & pos, RS2::ResolveLevel level)
+{
+       DEBUG->print("GraphicView::CatchEntity");
+
+       // Set default distance for points inside solids
+       double dist = toGraphDX(snapRange) * 0.9;
+       Entity * entity = container->getNearestEntity(pos, &dist, level);
+
+       // DEBUGGING INFO
+       int idx = -1;
+
+       if (entity && entity->getParent())
+               idx = entity->getParent()->findEntity(entity);
+       // END DEBUGGING INFO
+
+       if (entity && dist <= toGraphDX(snapRange))
+       {
+               // Highlight:
+               DEBUG->print("GraphicView::CatchEntity: found: idx=%d", idx);
+               return entity;
+       }
+
+       DEBUG->print("GraphicView::CatchEntity: not found");
+       return NULL;
+}
+
+/**
+ * Catches an entity which is close to the mouse cursor.
+ *
+ * @param e A mouse event.
+ * @param level The level of resolving for iterating through the entity
+ *              container
+ * @return Pointer to the entity or NULL.
+ */
+Entity * GraphicView::CatchEntity(QMouseEvent * e, RS2::ResolveLevel level)
+{
+       return CatchEntity(Vector(toGraphX(e->x()), toGraphY(e->y())), level);
+}
+
+/**
+ * Snap to a coordinate in the drawing using the current snap mode.
+ *
+ * @param e A mouse event.
+ * @return The coordinates of the point or an invalid vector.
+ */
+Vector GraphicView::SnapPoint(QMouseEvent * e)
+{
+       DEBUG->print("GraphicView::SnapPoint");
+       /*Vector*/ snapSpot = Vector(false);
+
+       if (!e)
+       {
+               DEBUG->print(Debug::D_WARNING, "GraphicView::SnapPoint: QMouseEvent is NULL");
+               return snapSpot;
+       }
+
+       Vector mouseCoord = toGraph(e->x(), e->y());
+
+//     switch (snapMode)
+       switch (defaultSnapMode)
+       {
+       case RS2::SnapFree:
+//             snapSpot = snapFree(mouseCoord);
+               snapEntity = NULL;
+               snapSpot = mouseCoord;
+               break;
+
+       case RS2::SnapEndpoint:
+//             snapSpot = snapEndpoint(mouseCoord);
+               snapSpot = container->getNearestEndpoint(mouseCoord, NULL);
+               break;
+
+       case RS2::SnapGrid:
+               snapSpot = SnapGrid(mouseCoord);
+               break;
+
+       case RS2::SnapOnEntity:
+//             snapSpot = snapOnEntity(mouseCoord);
+               snapSpot = container->getNearestPointOnEntity(mouseCoord, true, NULL, &snapEntity);
+               break;
+
+       case RS2::SnapCenter:
+//             snapSpot = snapCenter(mouseCoord);
+               snapSpot = container->getNearestCenter(mouseCoord, NULL);
+               break;
+
+       case RS2::SnapMiddle:
+//             snapSpot = snapMiddle(mouseCoord);
+               snapSpot = container->getNearestMiddle(mouseCoord, NULL);
+               break;
+
+       case RS2::SnapDist:
+//             snapSpot = snapDist(mouseCoord);
+               snapSpot = container->getNearestDist(snapDistance, mouseCoord, NULL);
+               break;
+
+       case RS2::SnapIntersection:
+//             snapSpot = snapIntersection(mouseCoord);
+               snapSpot = container->getNearestIntersection(mouseCoord, NULL);
+               break;
+
+       default:
+               break;
+       }
+
+       // This is declared here because I really, really hate extraneous braces in
+       // my switch statements. :-P
+       Vector relZero = getRelativeZero();
+       Vector restrictX = Vector(relZero.x, snapSpot.y);
+       Vector restrictY = Vector(snapSpot.x, relZero.y);
+//     Vector snapCoord;
+       // Handle snap restrictions that can be activated in addition to the ones above:
+//     switch (snapRes)
+       switch (defaultSnapRes)
+       {
+       case RS2::RestrictOrthogonal:
+////           snapCoord = restrictOrthogonal(snapSpot);
+//             rz = graphicView->getRelativeZero();
+//             retx = Vector(rz.x, snapSpot.y);
+//             rety = Vector(snapSpot.x, rz.y);
+               snapCoord = (restrictX.distanceTo(snapSpot) < restrictY.distanceTo(snapSpot) ?
+                       restrictX : restrictY);
+               break;
+       case RS2::RestrictHorizontal:
+////           snapCoord = restrictHorizontal(snapSpot);
+//             rz = graphicView->getRelativeZero();
+//             snapCoord = Vector(snapSpot.x, rz.y);
+               snapCoord = restrictY;
+               break;
+       case RS2::RestrictVertical:
+////           snapCoord = restrictVertical(snapSpot);
+//             rz = graphicView->getRelativeZero();
+//             snapCoord = Vector(rz.x, snapSpot.y);
+               snapCoord = restrictX;
+               break;
+       default:
+       case RS2::RestrictNothing:
+               snapCoord = snapSpot;
+               break;
+       }
+
+       if (DIALOGFACTORY)
+               DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - relZero);
+
+       DEBUG->print("GraphicView::SnapPoint: OK");
+
+       return snapCoord;
+}
+
+/**
+ * Snaps to a grid point.
+ *
+ * @param coord The mouse coordinate.
+ * @return The coordinates of the point or an invalid vector.
+ */
+Vector GraphicView::SnapGrid(Vector coord)
+{
+       DEBUG->print("GraphicView::snapGrid begin");
+
+       Vector vec(false);
+       double dist = 0.0;
+
+       DEBUG->print("GraphicView::snapGrid 001");
+
+       if (grid)
+       {
+               DEBUG->print("GraphicView::snapGrid 002");
+               Vector * pts = grid->getPoints();
+               DEBUG->print("GraphicView::snapGrid 003");
+               int closest = -1;
+               dist = 32000.00;
+               DEBUG->print("GraphicView::snapGrid 004");
+
+               for(int i=0; i<grid->count(); ++i)
+               {
+                       double d = pts[i].distanceTo(coord);
+
+                       if (d < dist)
+                       {
+                               closest = i;
+                               dist = d;
+                       }
+               }
+
+               DEBUG->print("GraphicView::snapGrid 005");
+
+               if (closest >= 0)
+                       vec = pts[closest];
+
+               DEBUG->print("GraphicView::snapGrid 006");
+       }
+
+       snapEntity = NULL;
+
+       DEBUG->print("GraphicView::snapGrid end");
+
+       return vec;
+}
+
+void GraphicView::DrawSnapper(PaintInterface * painter)
+{
+//Is "finished" used at all? Seems it's used only in ActionInterface, and it's commented out
+//     if (finished || !snapSpot.valid || !snapCoord.valid)
+       if (!snapSpot.valid || !snapCoord.valid)
+#if 1
+{
+printf("DrawSnapper: snapSpot=%s, snapCoord=%s...\n", (snapSpot.valid ? "valid" : "INVALID"), (snapCoord.valid ? "valid" : "INVALID"));
+#endif
+               return;
+#if 1
+}
+#endif
+
+       // Snap point (need to make sure the brush is NULL!)
+//     painter->setPen(Pen(Color(0, 127, 255), RS2::Width00, RS2::DashLine));
+       painter->setPen(Pen(Color(255, 127, 0), RS2::Width00, RS2::DashLine));
+       painter->drawCircle(toGui(snapCoord), 4);
+
+       // Crosshairs
+       if (showCrosshairs)
+       {
+               painter->setPen(Pen(Color(0, 255, 255), RS2::Width00, RS2::DashLine));
+               painter->drawLine(Vector(0, toGuiY(snapCoord.y)),
+                       Vector(getWidth(), toGuiY(snapCoord.y)));
+               painter->drawLine(Vector(toGuiX(snapCoord.x), 0),
+                       Vector(toGuiX(snapCoord.x), getHeight()));
+       }
+
+       // Cursor
+       if (snapCoord != snapSpot)
+       {
+               painter->drawLine(toGui(snapSpot) + Vector(-5, 0), toGui(snapSpot) + Vector(-1, 4));
+               painter->drawLine(toGui(snapSpot) + Vector(0, 5), toGui(snapSpot) + Vector(4, 1));
+               painter->drawLine(toGui(snapSpot) + Vector(5, 0), toGui(snapSpot) + Vector(1, -4));
+               painter->drawLine(toGui(snapSpot) + Vector(0, -5), toGui(snapSpot) + Vector(-4, -1));
+       }
+}
+
+void GraphicView::SetSnapperVisible(bool visibility/*= true*/)
+{
+       snapperVisible = visibility;
+}
+
+bool GraphicView::SnapperVisible(void)
+{
+       return snapperVisible;
+}
+
+#if 0
+/*
+only place this is called is in ActionInterface. And its only function is to
+have it not drawn anymore. But, the GraphicView seems to draw it anyway... So
+some other approach is needed...
+*/
+void Snapper::finish()
+{
+       finished = true;
+}
+
+/**
+ * @return Pointer to the entity which was the key entity for the last
+ * successful snapping action. If the snap mode is "end point" the key entity
+ * is the entity whose end point was caught. If the snap mode didn't require an
+ * entity (e.g. free, grid) this method will return NULL.
+ */
+Entity * Snapper::getKeyEntity()
+{
+       return keyEntity;
+}
+
+/** Sets a new snap mode. */
+void Snapper::setSnapMode(RS2::SnapMode snapMode)
+{
+       this->snapMode = snapMode;
+}
+
+/** Sets a new snap restriction. */
+void Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
+{
+       this->snapRes = snapRes;
+}
+
+RS2::SnapMode Snapper::getSnapMode(void)
+{
+       return snapMode;
+}
+
+RS2::SnapRestriction Snapper::getSnapRestriction(void)
+{
+       return snapRes;
+}
+
+/**
+ * Sets the snap range in pixels for catchEntity().
+ *
+ * @see catchEntity()
+ */
+void Snapper::setSnapRange(int r)
+{
+       snapRange = r;
+}
+
+#if 0
+I think that these suspend() & resume() functions are not used anymore...
+#endif
+/**
+ * Suspends this snapper while another action takes place.
+ */
+/*virtual*/ void Snapper::suspend()
+{
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     deleteSnapper();
+       snapSpot = snapCoord = Vector(false);
+}
+
+/**
+ * Resumes this snapper after it has been suspended.
+ */
+/*virtual*/ void Snapper::resume()
+{
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     drawSnapper();
+}
+
+/**
+ * Hides the snapper options.
+ */
+/*virtual*/ void Snapper::hideOptions()
+{
+       if (snapMode == RS2::SnapDist && DIALOGFACTORY)
+               DIALOGFACTORY->requestSnapDistOptions(distance, false);
+}
+
+/**
+ * Shows the snapper options.
+ */
+/*virtual*/ void Snapper::showOptions()
+{
+       if (snapMode == RS2::SnapDist && DIALOGFACTORY)
+               DIALOGFACTORY->requestSnapDistOptions(distance, true);
+}
+#endif
index 863b7d6311a5f7d08eace23ad616c411051414ab..e4cd758245c8bbca312fd3583cddd651d490c1c8 100644 (file)
@@ -207,18 +207,26 @@ Having this class derive from that one *might* make sense... *Maybe*. Not sure.
                void setSimulationRapid(bool r);
                bool getSimulationRapid();
 
+               Entity * CatchEntity(const Vector &, RS2::ResolveLevel level = RS2::ResolveNone);
+               Entity * CatchEntity(QMouseEvent *, RS2::ResolveLevel level = RS2::ResolveNone);
+               Vector SnapPoint(QMouseEvent *);
+               Vector SnapGrid(Vector);
+               void DrawSnapper(PaintInterface *);
+               void SetSnapperVisible(bool visibility = true);
+               bool SnapperVisible(void);
+
        protected:
                EntityContainer * container;
                EventHandler * eventHandler;
                int mx;                                                         //!< Last known mouse cursor position
                int my;                                                         //!< Last known mouse cursor position
                PaintInterface * painter;
-               Color background;                               //! background color (any color)
-               Color foreground;                               //! foreground color (black or white)
+               Color background;                                       //! background color (any color)
+               Color foreground;                                       //! foreground color (black or white)
                Color gridColor;                                        //! grid color
                Color metaGridColor;                            //! meta grid color
                Color selectedColor;                            //! selected color
-               Color highlightedColor;                 //! highlighted color
+               Color highlightedColor;                         //! highlighted color
                Grid * grid;                                            //! Grid
                /**
                 * Current default snap mode for this graphic view. Used for new
@@ -231,13 +239,19 @@ Having this class derive from that one *might* make sense... *Maybe*. Not sure.
                 */
                RS2::SnapRestriction defaultSnapRes;
                RS2::DrawingMode drawingMode;
-
                /**
                 * Delete mode. If true, all drawing actions will delete in background color
                 * instead.
                 */
                bool deleteMode;
                bool simulationRunning;                         //! If true, the simulation is currectly running
+               double snapDistance;                            //! Manually set snap distance
+               Entity * snapEntity;                            //! Entity to snap to (if any)
+               Vector snapSpot;
+               Vector snapCoord;
+               bool snapperVisible;                            //! Snapper visibility
+               int snapRange;
+               bool showCrosshairs;                            //! Snapper crosshair visibility
 
        private:
                int updateEnabled;
index 9ddec0fe96d280c2b0475a0930f7d641072de334..6b4e1fba93f4a276afd2f8f0bc2b45610f28e1ff 100644 (file)
@@ -825,8 +825,11 @@ of VectorWorks & etc. as well...
 
        // Draw the snapper first, because we want to be able to see the preview on
        // top of this...
-       if (snapper.Visible())
-               snapper.Draw(this, painter);
+//     if (snapper.Visible())
+//             snapper.Draw(this, painter);
+       // Actually, this code can go into drawIt() instead of here...
+       if (snapperVisible)
+               DrawSnapper(painter);
 
        if (preview.Visible())
                preview.Draw(this, painter);