1 // rs_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 "rs_actiondrawlinepolygon.h"
17 #include "rs_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons",
23 container, graphicView)
25 center = Vector(false);
26 corner = Vector(false);
31 RS_ActionDrawLinePolygon::~RS_ActionDrawLinePolygon()
35 /*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon::rtti()
37 return RS2::ActionDrawLinePolygon;
40 void RS_ActionDrawLinePolygon::trigger()
42 RS_PreviewActionInterface::trigger();
48 RS_Creation creation(container, graphicView);
49 bool ok = creation.createPolygon(center, corner, number);
52 RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger: No polygon added\n");
55 void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e)
57 RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin");
59 Vector mouse = snapPoint(e);
74 RS_Creation creation(preview, NULL, false);
75 creation.createPolygon(center, corner, number);
86 void RS_ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent * e)
88 if (e->button() == Qt::LeftButton)
90 Vector ce(snapPoint(e));
93 else if (e->button() == Qt::RightButton)
98 init(getStatus() - 1);
102 void RS_ActionDrawLinePolygon::coordinateEvent(Vector * e)
113 setStatus(SetCorner);
114 graphicView->moveRelativeZero(mouse);
127 void RS_ActionDrawLinePolygon::updateMouseButtonHints()
129 if (RS_DIALOGFACTORY != NULL)
134 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"),
139 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), "");
143 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
147 RS_DIALOGFACTORY->updateMouseWidget("", "");
153 void RS_ActionDrawLinePolygon::showOptions()
155 RS_ActionInterface::showOptions();
157 if (RS_DIALOGFACTORY != NULL)
158 RS_DIALOGFACTORY->requestOptions(this, true);
161 void RS_ActionDrawLinePolygon::hideOptions()
163 RS_ActionInterface::hideOptions();
165 if (RS_DIALOGFACTORY != NULL)
166 RS_DIALOGFACTORY->requestOptions(this, false);
169 void RS_ActionDrawLinePolygon::commandEvent(RS_CommandEvent * e)
171 QString c = e->getCommand().toLower();
173 if (checkCommand("help", c))
175 if (RS_DIALOGFACTORY != NULL)
176 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
177 + getAvailableCommands().join(", "));
186 if (checkCommand("number", c))
191 lastStatus = (Status)getStatus();
192 setStatus(SetNumber);
198 int n = c.toInt(&ok);
202 if (n > 0 && n < 10000)
204 else if (RS_DIALOGFACTORY != NULL)
205 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
209 else if (RS_DIALOGFACTORY != NULL)
210 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
212 if (RS_DIALOGFACTORY != NULL)
213 RS_DIALOGFACTORY->requestOptions(this, true, true);
214 setStatus(lastStatus);
223 QStringList RS_ActionDrawLinePolygon::getAvailableCommands()
231 cmd += command("number");
241 void RS_ActionDrawLinePolygon::updateMouseCursor()
243 graphicView->setMouseCursor(RS2::CadCursor);
246 void RS_ActionDrawLinePolygon::updateToolBar()
248 if (RS_DIALOGFACTORY != NULL)
251 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
253 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
257 int RS_ActionDrawLinePolygon::getNumber()
262 void RS_ActionDrawLinePolygon::setNumber(int n)