1 // 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 // 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 "actiondrawlinepolygon2.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 ActionDrawLinePolygon2::ActionDrawLinePolygon2(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw Polygons",
26 container, graphicView)
28 corner1 = Vector(false);
29 corner2 = Vector(false);
34 ActionDrawLinePolygon2::~ActionDrawLinePolygon2()
38 /*virtual*/ RS2::ActionType ActionDrawLinePolygon2::rtti()
40 return RS2::ActionDrawLinePolygon2;
43 void ActionDrawLinePolygon2::trigger()
45 ActionInterface::trigger();
51 RS_Creation creation(container, graphicView);
52 bool ok = creation.createPolygon2(corner1, corner2, number);
55 RS_DEBUG->print("ActionDrawLinePolygon2::trigger: No polygon added\n");
58 void ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent * e)
60 RS_DEBUG->print("ActionDrawLinePolygon2::mouseMoveEvent begin");
62 Vector mouse = snapPoint(e);
77 // RS_Creation creation(preview, NULL, false);
78 // creation.createPolygon2(corner1, corner2, number);
89 void ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent * e)
91 if (e->button() == Qt::LeftButton)
93 Vector ce(snapPoint(e));
96 else if (e->button() == Qt::RightButton)
101 init(getStatus() - 1);
105 void ActionDrawLinePolygon2::coordinateEvent(Vector * e)
116 setStatus(SetCorner2);
117 graphicView->moveRelativeZero(mouse);
130 void ActionDrawLinePolygon2::updateMouseButtonHints()
132 if (RS_DIALOGFACTORY != NULL)
137 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
142 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
147 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
151 RS_DIALOGFACTORY->updateMouseWidget("", "");
157 void ActionDrawLinePolygon2::showOptions()
159 ActionInterface::showOptions();
161 if (RS_DIALOGFACTORY != NULL)
162 RS_DIALOGFACTORY->requestOptions(this, true);
165 void ActionDrawLinePolygon2::hideOptions()
167 ActionInterface::hideOptions();
169 if (RS_DIALOGFACTORY != NULL)
170 RS_DIALOGFACTORY->requestOptions(this, false);
173 void ActionDrawLinePolygon2::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 ActionDrawLinePolygon2::getAvailableCommands()
235 cmd += command("number");
245 void ActionDrawLinePolygon2::updateMouseCursor()
247 graphicView->setMouseCursor(RS2::CadCursor);
250 void ActionDrawLinePolygon2::updateToolBar()
252 if (RS_DIALOGFACTORY != NULL)
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
257 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
261 int ActionDrawLinePolygon2::getNumber()
266 void ActionDrawLinePolygon2::setNumber(int n)