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 "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawLinePolygon2::ActionDrawLinePolygon2(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw Polygons",
27 container, graphicView)
29 corner1 = Vector(false);
30 corner2 = Vector(false);
35 ActionDrawLinePolygon2::~ActionDrawLinePolygon2()
39 /*virtual*/ RS2::ActionType ActionDrawLinePolygon2::rtti()
41 return RS2::ActionDrawLinePolygon2;
44 void ActionDrawLinePolygon2::trigger()
46 ActionInterface::trigger();
52 Creation creation(container, graphicView);
53 bool ok = creation.createPolygon2(corner1, corner2, number);
56 DEBUG->print("ActionDrawLinePolygon2::trigger: No polygon added\n");
59 void ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent * e)
61 DEBUG->print("ActionDrawLinePolygon2::mouseMoveEvent begin");
63 Vector mouse = snapPoint(e);
78 // Creation creation(preview, NULL, false);
79 // creation.createPolygon2(corner1, corner2, number);
90 void ActionDrawLinePolygon2::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 ActionDrawLinePolygon2::coordinateEvent(Vector * e)
117 setStatus(SetCorner2);
118 graphicView->moveRelativeZero(mouse);
131 void ActionDrawLinePolygon2::updateMouseButtonHints()
133 if (DIALOGFACTORY != NULL)
138 DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
143 DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
148 DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
152 DIALOGFACTORY->updateMouseWidget("", "");
158 void ActionDrawLinePolygon2::showOptions()
160 ActionInterface::showOptions();
162 if (DIALOGFACTORY != NULL)
163 DIALOGFACTORY->requestOptions(this, true);
166 void ActionDrawLinePolygon2::hideOptions()
168 ActionInterface::hideOptions();
170 if (DIALOGFACTORY != NULL)
171 DIALOGFACTORY->requestOptions(this, false);
174 void ActionDrawLinePolygon2::commandEvent(CommandEvent * e)
176 QString c = e->getCommand().toLower();
178 if (checkCommand("help", c))
180 if (DIALOGFACTORY != NULL)
181 DIALOGFACTORY->commandMessage(msgAvailableCommands()
182 + getAvailableCommands().join(", "));
191 if (checkCommand("number", c))
196 lastStatus = (Status)getStatus();
197 setStatus(SetNumber);
203 int n = c.toInt(&ok);
207 if (n > 0 && n < 10000)
209 else if (DIALOGFACTORY != NULL)
210 DIALOGFACTORY->commandMessage(tr("Not a valid number. "
214 else if (DIALOGFACTORY != NULL)
215 DIALOGFACTORY->commandMessage(tr("Not a valid expression."));
217 if (DIALOGFACTORY != NULL)
218 DIALOGFACTORY->requestOptions(this, true, true);
219 setStatus(lastStatus);
228 QStringList ActionDrawLinePolygon2::getAvailableCommands()
236 cmd += command("number");
246 void ActionDrawLinePolygon2::updateMouseCursor()
248 graphicView->setMouseCursor(RS2::CadCursor);
251 void ActionDrawLinePolygon2::updateToolBar()
253 if (DIALOGFACTORY != NULL)
256 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
258 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
262 int ActionDrawLinePolygon2::getNumber()
267 void ActionDrawLinePolygon2::setNumber(int n)