1 // rs_actiondrawlinepolygon2.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_actiondrawlinepolygon2.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 RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons",
24 container, graphicView)
26 corner1 = Vector(false);
27 corner2 = Vector(false);
32 RS_ActionDrawLinePolygon2::~RS_ActionDrawLinePolygon2()
36 /*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon2::rtti()
38 return RS2::ActionDrawLinePolygon2;
41 void RS_ActionDrawLinePolygon2::trigger()
43 RS_PreviewActionInterface::trigger();
49 RS_Creation creation(container, graphicView);
50 bool ok = creation.createPolygon2(corner1, corner2, number);
53 RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger: No polygon added\n");
56 void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent * e)
58 RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin");
60 Vector mouse = snapPoint(e);
75 RS_Creation creation(preview, NULL, false);
76 creation.createPolygon2(corner1, corner2, number);
87 void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent * e)
89 if (e->button() == Qt::LeftButton)
91 Vector ce(snapPoint(e));
94 else if (e->button() == Qt::RightButton)
99 init(getStatus() - 1);
103 void RS_ActionDrawLinePolygon2::coordinateEvent(Vector * e)
114 setStatus(SetCorner2);
115 graphicView->moveRelativeZero(mouse);
128 void RS_ActionDrawLinePolygon2::updateMouseButtonHints()
130 if (RS_DIALOGFACTORY != NULL)
135 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
140 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
145 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
149 RS_DIALOGFACTORY->updateMouseWidget("", "");
155 void RS_ActionDrawLinePolygon2::showOptions()
157 RS_ActionInterface::showOptions();
159 if (RS_DIALOGFACTORY != NULL)
160 RS_DIALOGFACTORY->requestOptions(this, true);
163 void RS_ActionDrawLinePolygon2::hideOptions()
165 RS_ActionInterface::hideOptions();
167 if (RS_DIALOGFACTORY != NULL)
168 RS_DIALOGFACTORY->requestOptions(this, false);
171 void RS_ActionDrawLinePolygon2::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 RS_ActionDrawLinePolygon2::getAvailableCommands()
233 cmd += command("number");
243 void RS_ActionDrawLinePolygon2::updateMouseCursor()
245 graphicView->setMouseCursor(RS2::CadCursor);
248 void RS_ActionDrawLinePolygon2::updateToolBar()
250 if (RS_DIALOGFACTORY != NULL)
253 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
259 int RS_ActionDrawLinePolygon2::getNumber()
264 void RS_ActionDrawLinePolygon2::setNumber(int n)