1 // actiondrawlineangle.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 05/22/2010 Added this text. :-)
15 // JLH 06/03/2010 Moved implementation from header to this file
18 #include "actiondrawlineangle.h"
20 #include "rs_commandevent.h"
22 #include "rs_dialogfactory.h"
23 #include "graphicview.h"
24 #include "rs_preview.h"
26 ActionDrawLineAngle::ActionDrawLineAngle(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
27 ActionInterface("Draw lines with given angle",
28 container, graphicView)
33 this->fixedAngle = fixedAngle;
38 ActionDrawLineAngle::~ActionDrawLineAngle()
42 /*virtual*/ RS2::ActionType ActionDrawLineAngle::rtti()
44 return RS2::ActionDrawLineAngle;
47 void ActionDrawLineAngle::reset()
49 data = RS_LineData(Vector(false), Vector(false));
52 void ActionDrawLineAngle::init(int status)
54 ActionInterface::init(status);
59 void ActionDrawLineAngle::trigger()
61 ActionInterface::trigger();
64 RS_Line * line = new RS_Line(container, data);
65 line->setLayerToActive();
66 line->setPenToActive();
67 container->addEntity(line);
72 document->startUndoCycle();
73 document->addUndoable(line);
74 document->endUndoCycle();
78 graphicView->moveRelativeZero(Vector(0.0, 0.0));
79 graphicView->drawEntity(line);
80 graphicView->moveRelativeZero(data.startpoint);
81 RS_DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d",
85 void ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
87 RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
89 if (getStatus() == SetPos)
95 // preview->addEntity(new RS_Line(preview, data));
99 RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
102 void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
104 if (e->button() == Qt::LeftButton)
106 if (getStatus() == SetPos)
108 Vector ce(snapPoint(e));
109 coordinateEvent(&ce);
112 else if (e->button() == Qt::RightButton)
116 init(getStatus() - 1);
120 void ActionDrawLineAngle::preparePreview()
126 p2.setPolar(length * -1, angle);
128 p2.setPolar(length, angle);
137 data = RS_LineData(p1, p2);
140 void ActionDrawLineAngle::coordinateEvent(Vector * e)
157 void ActionDrawLineAngle::commandEvent(RS_CommandEvent * e)
159 QString c = e->getCommand().toLower();
161 if (checkCommand("help", c))
163 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
164 + getAvailableCommands().join(", "));
172 if (!fixedAngle && checkCommand("angle", c))
179 else if (checkCommand("length", c))
184 setStatus(SetLength);
190 double a = RS_Math::eval(c, &ok);
193 angle = RS_Math::deg2rad(a);
195 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
196 RS_DIALOGFACTORY->requestOptions(this, true, true);
203 double l = RS_Math::eval(c, &ok);
208 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
209 RS_DIALOGFACTORY->requestOptions(this, true, true);
219 QStringList ActionDrawLineAngle::getAvailableCommands()
228 cmd += command("angle");
229 cmd += command("length");
239 void ActionDrawLineAngle::updateMouseButtonHints()
244 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
249 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
253 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
261 void ActionDrawLineAngle::showOptions()
263 ActionInterface::showOptions();
265 RS_DIALOGFACTORY->requestOptions(this, true);
268 void ActionDrawLineAngle::hideOptions()
270 ActionInterface::hideOptions();
272 RS_DIALOGFACTORY->requestOptions(this, false);
275 void ActionDrawLineAngle::updateMouseCursor()
277 graphicView->setMouseCursor(RS2::CadCursor);
280 void ActionDrawLineAngle::updateToolBar()
283 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
285 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
288 void ActionDrawLineAngle::setSnapPoint(int sp)
293 int ActionDrawLineAngle::getSnapPoint()
298 void ActionDrawLineAngle::setAngle(double a)
303 double ActionDrawLineAngle::getAngle()
308 void ActionDrawLineAngle::setLength(double l)
313 double ActionDrawLineAngle::getLength()
318 bool ActionDrawLineAngle::hasFixedAngle()