1 // actiondrawlinepolygon.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/04/2010 Added this text. :-)
15 #include "actiondrawlinepolygon.h"
17 #include "rs_commandevent.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 ActionDrawLinePolygon::ActionDrawLinePolygon(RS_EntityContainer & container,
24 GraphicView & graphicView): ActionInterface("Draw Polygons",
25 container, graphicView)
27 center = Vector(false);
28 corner = Vector(false);
33 ActionDrawLinePolygon::~ActionDrawLinePolygon()
37 /*virtual*/ RS2::ActionType ActionDrawLinePolygon::rtti()
39 return RS2::ActionDrawLinePolygon;
42 void ActionDrawLinePolygon::trigger()
44 ActionInterface::trigger();
50 RS_Creation creation(container, graphicView);
51 bool ok = creation.createPolygon(center, corner, number);
54 RS_DEBUG->print("ActionDrawLinePolygon::trigger: No polygon added\n");
57 void ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e)
59 RS_DEBUG->print("ActionDrawLinePolygon::mouseMoveEvent begin");
61 Vector mouse = snapPoint(e);
76 // RS_Creation creation(preview, NULL, false);
77 // creation.createPolygon(center, corner, number);
88 void ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent * e)
90 if (e->button() == Qt::LeftButton)
92 Vector ce(snapPoint(e));
95 else if (e->button() == Qt::RightButton)
100 init(getStatus() - 1);
104 void ActionDrawLinePolygon::coordinateEvent(Vector * e)
115 setStatus(SetCorner);
116 graphicView->moveRelativeZero(mouse);
129 void ActionDrawLinePolygon::updateMouseButtonHints()
131 if (RS_DIALOGFACTORY != NULL)
136 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"),
141 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), "");
145 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
149 RS_DIALOGFACTORY->updateMouseWidget("", "");
155 void ActionDrawLinePolygon::showOptions()
157 ActionInterface::showOptions();
159 if (RS_DIALOGFACTORY != NULL)
160 RS_DIALOGFACTORY->requestOptions(this, true);
163 void ActionDrawLinePolygon::hideOptions()
165 ActionInterface::hideOptions();
167 if (RS_DIALOGFACTORY != NULL)
168 RS_DIALOGFACTORY->requestOptions(this, false);
171 void ActionDrawLinePolygon::commandEvent(RS_CommandEvent * e)
173 QString c = e->getCommand().toLower();
175 if (checkCommand("help", c))
177 if (RS_DIALOGFACTORY != NULL)
178 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
179 + getAvailableCommands().join(", "));
188 if (checkCommand("number", c))
193 lastStatus = (Status)getStatus();
194 setStatus(SetNumber);
200 int n = c.toInt(&ok);
204 if (n > 0 && n < 10000)
206 else if (RS_DIALOGFACTORY != NULL)
207 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
211 else if (RS_DIALOGFACTORY != NULL)
212 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
214 if (RS_DIALOGFACTORY != NULL)
215 RS_DIALOGFACTORY->requestOptions(this, true, true);
216 setStatus(lastStatus);
225 QStringList ActionDrawLinePolygon::getAvailableCommands()
233 cmd += command("number");
243 void ActionDrawLinePolygon::updateMouseCursor()
245 graphicView->setMouseCursor(RS2::CadCursor);
248 void ActionDrawLinePolygon::updateToolBar()
250 if (RS_DIALOGFACTORY != NULL)
253 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
259 int ActionDrawLinePolygon::getNumber()
264 void ActionDrawLinePolygon::setNumber(int n)