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_commandevent.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons",
24 container, graphicView)
26 center = Vector(false);
27 corner = Vector(false);
32 RS_ActionDrawLinePolygon::~RS_ActionDrawLinePolygon()
36 /*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon::rtti()
38 return RS2::ActionDrawLinePolygon;
41 void RS_ActionDrawLinePolygon::trigger()
43 RS_PreviewActionInterface::trigger();
49 RS_Creation creation(container, graphicView);
50 bool ok = creation.createPolygon(center, corner, number);
53 RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger: No polygon added\n");
56 void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e)
58 RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin");
60 Vector mouse = snapPoint(e);
75 RS_Creation creation(preview, NULL, false);
76 creation.createPolygon(center, corner, number);
87 void RS_ActionDrawLinePolygon::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_ActionDrawLinePolygon::coordinateEvent(Vector * e)
114 setStatus(SetCorner);
115 graphicView->moveRelativeZero(mouse);
128 void RS_ActionDrawLinePolygon::updateMouseButtonHints()
130 if (RS_DIALOGFACTORY != NULL)
135 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"),
140 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), "");
144 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
148 RS_DIALOGFACTORY->updateMouseWidget("", "");
154 void RS_ActionDrawLinePolygon::showOptions()
156 RS_ActionInterface::showOptions();
158 if (RS_DIALOGFACTORY != NULL)
159 RS_DIALOGFACTORY->requestOptions(this, true);
162 void RS_ActionDrawLinePolygon::hideOptions()
164 RS_ActionInterface::hideOptions();
166 if (RS_DIALOGFACTORY != NULL)
167 RS_DIALOGFACTORY->requestOptions(this, false);
170 void RS_ActionDrawLinePolygon::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_ActionDrawLinePolygon::getAvailableCommands()
232 cmd += command("number");
242 void RS_ActionDrawLinePolygon::updateMouseCursor()
244 graphicView->setMouseCursor(RS2::CadCursor);
247 void RS_ActionDrawLinePolygon::updateToolBar()
249 if (RS_DIALOGFACTORY != NULL)
252 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
254 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
258 int RS_ActionDrawLinePolygon::getNumber()
263 void RS_ActionDrawLinePolygon::setNumber(int n)