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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actiondrawlinepolygon.h"
19 #include "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawLinePolygon::ActionDrawLinePolygon(RS_EntityContainer & container,
26 GraphicView & graphicView): ActionInterface("Draw Polygons",
27 container, graphicView)
29 center = Vector(false);
30 corner = Vector(false);
35 ActionDrawLinePolygon::~ActionDrawLinePolygon()
39 /*virtual*/ RS2::ActionType ActionDrawLinePolygon::rtti()
41 return RS2::ActionDrawLinePolygon;
44 void ActionDrawLinePolygon::trigger()
46 ActionInterface::trigger();
52 RS_Creation creation(container, graphicView);
53 bool ok = creation.createPolygon(center, corner, number);
56 RS_DEBUG->print("ActionDrawLinePolygon::trigger: No polygon added\n");
59 void ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e)
61 RS_DEBUG->print("ActionDrawLinePolygon::mouseMoveEvent begin");
63 Vector mouse = snapPoint(e);
78 // RS_Creation creation(preview, NULL, false);
79 // creation.createPolygon(center, corner, number);
90 void ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent * e)
92 if (e->button() == Qt::LeftButton)
94 Vector ce(snapPoint(e));
97 else if (e->button() == Qt::RightButton)
102 init(getStatus() - 1);
106 void ActionDrawLinePolygon::coordinateEvent(Vector * e)
117 setStatus(SetCorner);
118 graphicView->moveRelativeZero(mouse);
131 void ActionDrawLinePolygon::updateMouseButtonHints()
133 if (RS_DIALOGFACTORY != NULL)
138 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"),
143 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), "");
147 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
151 RS_DIALOGFACTORY->updateMouseWidget("", "");
157 void ActionDrawLinePolygon::showOptions()
159 ActionInterface::showOptions();
161 if (RS_DIALOGFACTORY != NULL)
162 RS_DIALOGFACTORY->requestOptions(this, true);
165 void ActionDrawLinePolygon::hideOptions()
167 ActionInterface::hideOptions();
169 if (RS_DIALOGFACTORY != NULL)
170 RS_DIALOGFACTORY->requestOptions(this, false);
173 void ActionDrawLinePolygon::commandEvent(RS_CommandEvent * e)
175 QString c = e->getCommand().toLower();
177 if (checkCommand("help", c))
179 if (RS_DIALOGFACTORY != NULL)
180 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
181 + getAvailableCommands().join(", "));
190 if (checkCommand("number", c))
195 lastStatus = (Status)getStatus();
196 setStatus(SetNumber);
202 int n = c.toInt(&ok);
206 if (n > 0 && n < 10000)
208 else if (RS_DIALOGFACTORY != NULL)
209 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
213 else if (RS_DIALOGFACTORY != NULL)
214 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
216 if (RS_DIALOGFACTORY != NULL)
217 RS_DIALOGFACTORY->requestOptions(this, true, true);
218 setStatus(lastStatus);
227 QStringList ActionDrawLinePolygon::getAvailableCommands()
235 cmd += command("number");
245 void ActionDrawLinePolygon::updateMouseCursor()
247 graphicView->setMouseCursor(RS2::CadCursor);
250 void ActionDrawLinePolygon::updateToolBar()
252 if (RS_DIALOGFACTORY != NULL)
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
257 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
261 int ActionDrawLinePolygon::getNumber()
266 void ActionDrawLinePolygon::setNumber(int n)