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_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons",
23 container, graphicView)
25 corner1 = Vector(false);
26 corner2 = Vector(false);
31 RS_ActionDrawLinePolygon2::~RS_ActionDrawLinePolygon2()
35 /*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon2::rtti()
37 return RS2::ActionDrawLinePolygon2;
40 void RS_ActionDrawLinePolygon2::trigger()
42 RS_PreviewActionInterface::trigger();
48 RS_Creation creation(container, graphicView);
49 bool ok = creation.createPolygon2(corner1, corner2, number);
52 RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger: No polygon added\n");
55 void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent * e)
57 RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin");
59 Vector mouse = snapPoint(e);
74 RS_Creation creation(preview, NULL, false);
75 creation.createPolygon2(corner1, corner2, number);
86 void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent * e)
88 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
90 Vector ce(snapPoint(e));
93 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
98 init(getStatus() - 1);
102 void RS_ActionDrawLinePolygon2::coordinateEvent(Vector * e)
113 setStatus(SetCorner2);
114 graphicView->moveRelativeZero(mouse);
127 void RS_ActionDrawLinePolygon2::updateMouseButtonHints()
129 if (RS_DIALOGFACTORY != NULL)
134 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
139 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
144 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
148 RS_DIALOGFACTORY->updateMouseWidget("", "");
154 void RS_ActionDrawLinePolygon2::showOptions()
156 RS_ActionInterface::showOptions();
158 if (RS_DIALOGFACTORY != NULL)
159 RS_DIALOGFACTORY->requestOptions(this, true);
162 void RS_ActionDrawLinePolygon2::hideOptions()
164 RS_ActionInterface::hideOptions();
166 if (RS_DIALOGFACTORY != NULL)
167 RS_DIALOGFACTORY->requestOptions(this, false);
170 void RS_ActionDrawLinePolygon2::commandEvent(RS_CommandEvent * e)
172 QString c = e->getCommand().toLower();
174 if (checkCommand("help", c))
176 if (RS_DIALOGFACTORY != NULL)
177 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
178 + getAvailableCommands().join(", "));
187 if (checkCommand("number", c))
192 lastStatus = (Status)getStatus();
193 setStatus(SetNumber);
199 int n = c.toInt(&ok);
203 if (n > 0 && n < 10000)
205 else if (RS_DIALOGFACTORY != NULL)
206 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
210 else if (RS_DIALOGFACTORY != NULL)
211 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression."));
213 if (RS_DIALOGFACTORY != NULL)
214 RS_DIALOGFACTORY->requestOptions(this, true, true);
215 setStatus(lastStatus);
224 QStringList RS_ActionDrawLinePolygon2::getAvailableCommands()
232 cmd += command("number");
242 void RS_ActionDrawLinePolygon2::updateMouseCursor()
244 graphicView->setMouseCursor(RS2::CadCursor);
247 void RS_ActionDrawLinePolygon2::updateToolBar()
249 if (RS_DIALOGFACTORY != NULL)
252 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
254 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
258 int RS_ActionDrawLinePolygon2::getNumber()
263 void RS_ActionDrawLinePolygon2::setNumber(int n)