]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/actiondrawpolyline.cpp
Phase two of adding polyline functionality...
[architektonas] / src / actions / actiondrawpolyline.cpp
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f4f81a4c3bebb7d5b2bb7902e3e78abb8648307e 100644 (file)
@@ -0,0 +1,169 @@
+// actiondrawpolyline.cpp
+//
+// Part of the Architektonas Project
+// by James L. Hammons
+// Copyright (C) 2010 Underground Software
+// See the README and GPLv2 files for licensing and warranty information
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -----------------------------------------------------------
+// JLH  09/13/2010  Created this file. :-)
+//
+
+#include "actiondrawpolyline.h"
+
+#include "debug.h"
+#include "dialogfactory.h"
+#include "graphicview.h"
+#include "polyline.h"
+
+ActionDrawPolyline::ActionDrawPolyline(EntityContainer & container,
+       GraphicView & graphicView):
+       ActionInterface("Draw polyline", container, graphicView)
+{
+       vertex = Vector(false);
+       polyline = NULL;
+}
+
+ActionDrawPolyline::~ActionDrawPolyline()
+{
+       if (polyline)
+               delete polyline;
+}
+
+void ActionDrawPolyline::trigger()
+{
+       if (polyline)
+       {
+               container->addEntity(polyline);
+//             deleteSnapper();
+
+               if (document)
+               {
+                       document->startUndoCycle();
+                       document->addUndoable(polyline);
+                       document->endUndoCycle();
+               }
+
+               DEBUG->print("ActionDrawPolyline::trigger(): polyline added: %d", polyline->getId());
+               polyline = NULL;
+       }
+}
+
+void ActionDrawPolyline::mouseMoveEvent(QMouseEvent * e)
+{
+       if (vertex.valid && polyline)
+       {
+               Vector v = snapPoint(e);
+               Entity * ent = polyline->addVertex(v);
+               ent->setLayerToActive();
+               ent->setPenToActive();
+
+//             deleteSnapper();
+//             graphicView->drawEntity(ent);
+//             drawSnapper();
+
+               vertex = v;
+               DEBUG->print("ActionDrawPolyline::mouseMoveEvent(): line added: %d", ent->getId());
+       }
+}
+
+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();
+       }
+}
+
+void ActionDrawPolyline::mouseReleaseEvent(QMouseEvent * e)
+{
+       if (e->button() == Qt::LeftButton)
+       {
+               vertex = Vector(false);
+               trigger();
+       }
+       else if (e->button() == Qt::RightButton)
+       {
+               if (polyline)
+               {
+                       delete polyline;
+                       polyline = NULL;
+               }
+
+//             deleteSnapper();
+               init(getStatus() - 1);
+               graphicView->redraw();  //hm.
+       }
+}
+
+void ActionDrawPolyline::updateMouseButtonHints()
+{
+       switch (getStatus())
+       {
+       case 0:
+               DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel"));
+               break;
+
+       default:
+               DIALOGFACTORY->updateMouseWidget("", "");
+               break;
+       }
+}
+
+void ActionDrawPolyline::updateMouseCursor()
+{
+       graphicView->setMouseCursor(RS2::CadCursor);
+}
+
+void ActionDrawPolyline::updateToolBar()
+{
+       if (!isFinished())
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+       else
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarPolylines);
+}
+
+void ActionDrawPolyline::close()
+{
+#if 0
+//NOTE: We should grey out the "close" button until the conditions for its use are satisfied.
+//      Though I can see how this would be called via cmd line... So I guess it's OK
+       if (history.count() > 2 && start.valid)
+       {
+               data.endpoint = start;
+               trigger();
+               setStatus(SetFirstPoint);
+               graphicView->moveRelativeZero(start);
+       }
+       else
+               DIALOGFACTORY->commandMessage(tr("Cannot close sequence of lines: Not enough entities defined yet."));
+#else
+       DIALOGFACTORY->commandMessage(tr("Close functionality not defined yet..."));
+#endif
+}
+
+void ActionDrawPolyline::undo()
+{
+#if 0
+//NOTE: We should grey out the "undo" button until the conditions for its use are satisfied.
+       if (history.count() > 1)
+       {
+               history.removeLast();
+               graphicView->setCurrentAction(new ActionEditUndo(true, *container, *graphicView));
+               data.startpoint = *history.last();
+               graphicView->moveRelativeZero(data.startpoint);
+               graphicView->preview.clear();
+               graphicView->redraw();
+       }
+       else
+               DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet."));
+#else
+       DIALOGFACTORY->commandMessage(tr("Undo functionality not defined yet..."));
+#endif
+}