From e1d1cacbb43055988d0d9db632fdf05c0bea9543 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 14 Sep 2010 03:49:57 +0000 Subject: [PATCH] Phase two of adding polyline functionality... --- architektonas.pro | 2 + src/actions/actiondrawpolyline.cpp | 169 +++++++++++++++++++++++ src/actions/actiondrawpolyline.h | 17 ++- src/actions/actionpolylineadd.cpp | 35 +++++ src/actions/actionpolylineadd.h | 12 +- src/actions/actionpolylineappend.cpp | 35 +++++ src/actions/actionpolylineappend.h | 14 +- src/actions/actionpolylinedel.cpp | 35 +++++ src/actions/actionpolylinedel.h | 14 +- src/actions/actionpolylinedelbetween.cpp | 35 +++++ src/actions/actionpolylinedelbetween.h | 14 +- src/actions/actionpolylinetrim.cpp | 35 +++++ src/actions/actionpolylinetrim.h | 14 +- src/forms/lineoptions.ui | 106 -------------- src/forms/polylineoptions.cpp | 75 ++++++++++ src/forms/polylineoptions.h | 30 ++++ src/widgets/qg_dialogfactory.cpp | 7 +- 17 files changed, 502 insertions(+), 147 deletions(-) delete mode 100644 src/forms/lineoptions.ui create mode 100644 src/forms/polylineoptions.cpp create mode 100644 src/forms/polylineoptions.h diff --git a/architektonas.pro b/architektonas.pro index 1c0c8a5..417a853 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -475,6 +475,7 @@ HEADERS += \ src/forms/linerelangleoptions.h \ src/forms/mousewidget.h \ src/forms/moverotateoptions.h \ + src/forms/polylineoptions.h \ src/forms/printpreviewoptions.h \ src/forms/roundoptions.h \ src/forms/selectionwidget.h \ @@ -563,6 +564,7 @@ SOURCES += \ src/forms/linerelangleoptions.cpp \ src/forms/mousewidget.cpp \ src/forms/moverotateoptions.cpp \ + src/forms/polylineoptions.cpp \ src/forms/printpreviewoptions.cpp \ src/forms/roundoptions.cpp \ src/forms/selectionwidget.cpp \ diff --git a/src/actions/actiondrawpolyline.cpp b/src/actions/actiondrawpolyline.cpp index e69de29..f4f81a4 100644 --- a/src/actions/actiondrawpolyline.cpp +++ b/src/actions/actiondrawpolyline.cpp @@ -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 +// +// 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 +} diff --git a/src/actions/actiondrawpolyline.h b/src/actions/actiondrawpolyline.h index 5ed5a1a..6902f40 100644 --- a/src/actions/actiondrawpolyline.h +++ b/src/actions/actiondrawpolyline.h @@ -7,12 +7,20 @@ class Polyline; /** - * This action class can handle user events to draw freehand lines. + * This class handles polyline creation. * * @author James Hammons */ class ActionDrawPolyline: public ActionInterface { + public: + /** Action States */ + enum Status + { + SetFirstPoint = 0, /**< Setting the first point. */ + SetNextPoint /**< Setting the next point. */ + }; + public: ActionDrawPolyline(EntityContainer & container, GraphicView & graphicView); ~ActionDrawPolyline(); @@ -24,10 +32,17 @@ class ActionDrawPolyline: public ActionInterface virtual void updateMouseButtonHints(); virtual void updateMouseCursor(); virtual void updateToolBar(); + void close(); + void undo(); protected: Vector vertex; Polyline * polyline; + /** Start point of the series of lines. Used for close function. */ + Vector start; + /** Point history (for undo) */ +//This probably won't work, because of arc segments... + QList history; }; #endif // __ACTIONDRAWPOLYLINE_H__ diff --git a/src/actions/actionpolylineadd.cpp b/src/actions/actionpolylineadd.cpp index e69de29..6188943 100644 --- a/src/actions/actionpolylineadd.cpp +++ b/src/actions/actionpolylineadd.cpp @@ -0,0 +1,35 @@ +// actionpolylineadd.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 09/13/2010 Created this file. :-) +// + +#include "actionpolylineadd.h" + +#include "debug.h" +#include "dialogfactory.h" +#include "graphicview.h" +#include "polyline.h" + +ActionPolylineAdd::ActionPolylineAdd(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw polyline", container, graphicView) +{ +// vertex = Vector(false); + polyline = NULL; +} + +ActionPolylineAdd::~ActionPolylineAdd() +{ + if (polyline) + delete polyline; +} + diff --git a/src/actions/actionpolylineadd.h b/src/actions/actionpolylineadd.h index f07be91..630be49 100644 --- a/src/actions/actionpolylineadd.h +++ b/src/actions/actionpolylineadd.h @@ -16,12 +16,12 @@ class ActionPolylineAdd: public ActionInterface ActionPolylineAdd(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineAdd(); - virtual void init(int status = 0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); - virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void updateMouseCursor(); +// virtual void init(int status = 0); +// virtual void trigger(); +// virtual void mouseMoveEvent(QMouseEvent * e); +// virtual void mousePressEvent(QMouseEvent * e); +// virtual void mouseReleaseEvent(QMouseEvent * e); +// virtual void updateMouseCursor(); protected: Polyline * polyline; diff --git a/src/actions/actionpolylineappend.cpp b/src/actions/actionpolylineappend.cpp index e69de29..8a936f8 100644 --- a/src/actions/actionpolylineappend.cpp +++ b/src/actions/actionpolylineappend.cpp @@ -0,0 +1,35 @@ +// actionpolylineappend.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 09/13/2010 Created this file. :-) +// + +#include "actionpolylineappend.h" + +#include "debug.h" +#include "dialogfactory.h" +#include "graphicview.h" +#include "polyline.h" + +ActionPolylineAppend::ActionPolylineAppend(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw polyline", container, graphicView) +{ +// vertex = Vector(false); + polyline = NULL; +} + +ActionPolylineAppend::~ActionPolylineAppend() +{ + if (polyline) + delete polyline; +} + diff --git a/src/actions/actionpolylineappend.h b/src/actions/actionpolylineappend.h index 01e5d28..0921402 100644 --- a/src/actions/actionpolylineappend.h +++ b/src/actions/actionpolylineappend.h @@ -6,7 +6,7 @@ class Polyline; /** - * This action class adds a node to an existing polyline. + * This action class appends a node to an existing polyline. * * @author James Hammons */ @@ -16,12 +16,12 @@ class ActionPolylineAppend: public ActionInterface ActionPolylineAppend(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineAppend(); - virtual void init(int status = 0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); - virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void updateMouseCursor(); +// virtual void init(int status = 0); +// virtual void trigger(); +// virtual void mouseMoveEvent(QMouseEvent * e); +// virtual void mousePressEvent(QMouseEvent * e); +// virtual void mouseReleaseEvent(QMouseEvent * e); +// virtual void updateMouseCursor(); protected: Polyline * polyline; diff --git a/src/actions/actionpolylinedel.cpp b/src/actions/actionpolylinedel.cpp index e69de29..078e57b 100644 --- a/src/actions/actionpolylinedel.cpp +++ b/src/actions/actionpolylinedel.cpp @@ -0,0 +1,35 @@ +// actionpolylinedel.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 09/13/2010 Created this file. :-) +// + +#include "actionpolylinedel.h" + +#include "debug.h" +#include "dialogfactory.h" +#include "graphicview.h" +#include "polyline.h" + +ActionPolylineDel::ActionPolylineDel(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw polyline", container, graphicView) +{ +// vertex = Vector(false); + polyline = NULL; +} + +ActionPolylineDel::~ActionPolylineDel() +{ + if (polyline) + delete polyline; +} + diff --git a/src/actions/actionpolylinedel.h b/src/actions/actionpolylinedel.h index 46f021b..3c7d78d 100644 --- a/src/actions/actionpolylinedel.h +++ b/src/actions/actionpolylinedel.h @@ -6,7 +6,7 @@ class Polyline; /** - * This action class adds a node to an existing polyline. + * This action class deletes a node from an existing polyline. * * @author James Hammons */ @@ -16,12 +16,12 @@ class ActionPolylineDel: public ActionInterface ActionPolylineDel(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineDel(); - virtual void init(int status = 0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); - virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void updateMouseCursor(); +// virtual void init(int status = 0); +// virtual void trigger(); +// virtual void mouseMoveEvent(QMouseEvent * e); +// virtual void mousePressEvent(QMouseEvent * e); +// virtual void mouseReleaseEvent(QMouseEvent * e); +// virtual void updateMouseCursor(); protected: Polyline * polyline; diff --git a/src/actions/actionpolylinedelbetween.cpp b/src/actions/actionpolylinedelbetween.cpp index e69de29..09b096a 100644 --- a/src/actions/actionpolylinedelbetween.cpp +++ b/src/actions/actionpolylinedelbetween.cpp @@ -0,0 +1,35 @@ +// actionpolylinedelbetween.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 09/13/2010 Created this file. :-) +// + +#include "actionpolylinedelbetween.h" + +#include "debug.h" +#include "dialogfactory.h" +#include "graphicview.h" +#include "polyline.h" + +ActionPolylineDelBetween::ActionPolylineDelBetween(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw polyline", container, graphicView) +{ +// vertex = Vector(false); + polyline = NULL; +} + +ActionPolylineDelBetween::~ActionPolylineDelBetween() +{ + if (polyline) + delete polyline; +} + diff --git a/src/actions/actionpolylinedelbetween.h b/src/actions/actionpolylinedelbetween.h index 63d240e..dd8f7ae 100644 --- a/src/actions/actionpolylinedelbetween.h +++ b/src/actions/actionpolylinedelbetween.h @@ -6,7 +6,7 @@ class Polyline; /** - * This action class adds a node to an existing polyline. + * This action class deletes multiple nodes from an existing polyline. * * @author James Hammons */ @@ -16,12 +16,12 @@ class ActionPolylineDelBetween: public ActionInterface ActionPolylineDelBetween(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineDelBetween(); - virtual void init(int status = 0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); - virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void updateMouseCursor(); +// virtual void init(int status = 0); +// virtual void trigger(); +// virtual void mouseMoveEvent(QMouseEvent * e); +// virtual void mousePressEvent(QMouseEvent * e); +// virtual void mouseReleaseEvent(QMouseEvent * e); +// virtual void updateMouseCursor(); protected: Polyline * polyline; diff --git a/src/actions/actionpolylinetrim.cpp b/src/actions/actionpolylinetrim.cpp index e69de29..ea12e6f 100644 --- a/src/actions/actionpolylinetrim.cpp +++ b/src/actions/actionpolylinetrim.cpp @@ -0,0 +1,35 @@ +// actionpolylinetrim.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 09/13/2010 Created this file. :-) +// + +#include "actionpolylinetrim.h" + +#include "debug.h" +#include "dialogfactory.h" +#include "graphicview.h" +#include "polyline.h" + +ActionPolylineTrim::ActionPolylineTrim(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw polyline", container, graphicView) +{ +// vertex = Vector(false); + polyline = NULL; +} + +ActionPolylineTrim::~ActionPolylineTrim() +{ + if (polyline) + delete polyline; +} + diff --git a/src/actions/actionpolylinetrim.h b/src/actions/actionpolylinetrim.h index a07acbc..b1d82c1 100644 --- a/src/actions/actionpolylinetrim.h +++ b/src/actions/actionpolylinetrim.h @@ -6,7 +6,7 @@ class Polyline; /** - * This action class adds a node to an existing polyline. + * This action class trims nodes on an existing polyline. * * @author James Hammons */ @@ -16,12 +16,12 @@ class ActionPolylineTrim: public ActionInterface ActionPolylineTrim(EntityContainer & container, GraphicView & graphicView); ~ActionPolylineTrim(); - virtual void init(int status = 0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); - virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void updateMouseCursor(); +// virtual void init(int status = 0); +// virtual void trigger(); +// virtual void mouseMoveEvent(QMouseEvent * e); +// virtual void mousePressEvent(QMouseEvent * e); +// virtual void mouseReleaseEvent(QMouseEvent * e); +// virtual void updateMouseCursor(); protected: Polyline * polyline; diff --git a/src/forms/lineoptions.ui b/src/forms/lineoptions.ui deleted file mode 100644 index 0883619..0000000 --- a/src/forms/lineoptions.ui +++ /dev/null @@ -1,106 +0,0 @@ - - - LineOptions - - - - 0 - 0 - 200 - 22 - - - - - 0 - 0 - - - - - 200 - 22 - - - - - 280 - 22 - - - - Line Options - - - - 1 - - - - - Close - - - - - - - Undo - - - - - - - - 0 - 0 - - - - QFrame::VLine - - - QFrame::Sunken - - - - - - - - - - bClose - clicked() - LineOptions - close() - - - 20 - 20 - - - 20 - 20 - - - - - bUndo - clicked() - LineOptions - undo() - - - 20 - 20 - - - 20 - 20 - - - - - diff --git a/src/forms/polylineoptions.cpp b/src/forms/polylineoptions.cpp new file mode 100644 index 0000000..5c185ae --- /dev/null +++ b/src/forms/polylineoptions.cpp @@ -0,0 +1,75 @@ +// polylineoptions.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 +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 09/13/2010 Created this file. :-) +// + +// NOTE: Still need to add "Arc" checkbox and "Radius" textedit +#warning "!!! Still need to add 'Arc' checkbox and 'Radius' textedit !!!" + +#include "polylineoptions.h" + +#include "enums.h" +#include "actiondrawpolyline.h" +#include "actioninterface.h" +#include "debug.h" + +PolylineOptions::PolylineOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/): + QWidget(parent, flags), action(NULL), + bClose(new QToolButton(this)), + bUndo(new QToolButton(this)) +{ + QHBoxLayout * layout = new QHBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + + bClose->setText(tr("Close")); + bUndo->setText(tr("Undo")); + + layout->addWidget(bClose); + layout->addWidget(bUndo); + + connect(bClose, SIGNAL(clicked()), this, SLOT(close())); + connect(bUndo, 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. :-) + if (parent) + parent->addWidget(this); +} + +PolylineOptions::~PolylineOptions() +{ +} + +void PolylineOptions::setAction(ActionInterface * a, bool & /*unknown*/) +{ + if (a && a->rtti() == RS2::ActionDrawPolyline) + { + action = (ActionDrawPolyline *)a; + } + else + { + DEBUG->print(Debug::D_ERROR, "PolylineOptions::setAction: wrong action type"); + action = NULL; + } +} + +void PolylineOptions::close() +{ + if (action) + action->close(); +} + +void PolylineOptions::undo() +{ + if (action) + action->undo(); +} diff --git a/src/forms/polylineoptions.h b/src/forms/polylineoptions.h new file mode 100644 index 0000000..ba224cf --- /dev/null +++ b/src/forms/polylineoptions.h @@ -0,0 +1,30 @@ +#ifndef __POLYLINEOPTIONS_H__ +#define __POLYLINEOPTIONS_H__ + +#include + +class ActionDrawPolyline; +class ActionInterface; + +class PolylineOptions: public QWidget +{ + Q_OBJECT + + public: + PolylineOptions(QToolBar * parent = 0, Qt::WindowFlags flags = 0); + ~PolylineOptions(); + + public slots: + void setAction(ActionInterface * a, bool &); + void close(); + void undo(); + + protected: + ActionDrawPolyline * action; + + private: + QToolButton * bClose; + QToolButton * bUndo; +}; + +#endif // __POLYLINEOPTIONS_H__ diff --git a/src/widgets/qg_dialogfactory.cpp b/src/widgets/qg_dialogfactory.cpp index d0944b0..b0a9248 100644 --- a/src/widgets/qg_dialogfactory.cpp +++ b/src/widgets/qg_dialogfactory.cpp @@ -74,6 +74,7 @@ #include "linerelangleoptions.h" #include "mousewidget.h" #include "moverotateoptions.h" +#include "polylineoptions.h" #include "printpreviewoptions.h" #include "roundoptions.h" #include "selectionwidget.h" @@ -82,10 +83,6 @@ #include "textoptions.h" #include "trimamountoptions.h" -#ifdef RS_PROF -#include "qg_polylineoptions.h" -#endif - #ifdef RS_CAM #include "camdialog.h" #endif @@ -895,7 +892,6 @@ them over and over. May need to do some more refactoring based on this idea... */ void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, bool update) { -#ifdef RS_PROF static PolylineOptions * toolWidget = NULL; if (!optionWidget) @@ -912,7 +908,6 @@ void QG_DialogFactory::requestPolylineOptions(ActionInterface * action, bool on, toolWidget = new PolylineOptions(optionWidget); toolWidget->setAction(action, update); } -#endif } /** -- 2.37.2