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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
13 // JLH 06/03/2010 Moved implementation from header to this file
16 #include "actiondrawlineangle.h"
18 #include "rs_commandevent.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 ActionDrawLineAngle::ActionDrawLineAngle(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
24 ActionInterface("Draw lines with given angle",
25 container, graphicView)
30 this->fixedAngle = fixedAngle;
35 ActionDrawLineAngle::~ActionDrawLineAngle()
39 /*virtual*/ RS2::ActionType ActionDrawLineAngle::rtti()
41 return RS2::ActionDrawLineAngle;
44 void ActionDrawLineAngle::reset()
46 data = RS_LineData(Vector(false), Vector(false));
49 void ActionDrawLineAngle::init(int status)
51 ActionInterface::init(status);
56 void ActionDrawLineAngle::trigger()
58 ActionInterface::trigger();
61 RS_Line * line = new RS_Line(container, data);
62 line->setLayerToActive();
63 line->setPenToActive();
64 container->addEntity(line);
69 document->startUndoCycle();
70 document->addUndoable(line);
71 document->endUndoCycle();
75 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 graphicView->drawEntity(line);
77 graphicView->moveRelativeZero(data.startpoint);
78 RS_DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d",
82 void ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
84 RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
86 if (getStatus() == SetPos)
92 // preview->addEntity(new RS_Line(preview, data));
96 RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
99 void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
101 if (e->button() == Qt::LeftButton)
103 if (getStatus() == SetPos)
105 Vector ce(snapPoint(e));
106 coordinateEvent(&ce);
109 else if (e->button() == Qt::RightButton)
113 init(getStatus() - 1);
117 void ActionDrawLineAngle::preparePreview()
123 p2.setPolar(length * -1, angle);
125 p2.setPolar(length, angle);
134 data = RS_LineData(p1, p2);
137 void ActionDrawLineAngle::coordinateEvent(Vector * e)
154 void ActionDrawLineAngle::commandEvent(RS_CommandEvent * e)
156 QString c = e->getCommand().toLower();
158 if (checkCommand("help", c))
160 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
161 + getAvailableCommands().join(", "));
169 if (!fixedAngle && checkCommand("angle", c))
176 else if (checkCommand("length", c))
181 setStatus(SetLength);
187 double a = RS_Math::eval(c, &ok);
190 angle = RS_Math::deg2rad(a);
192 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
193 RS_DIALOGFACTORY->requestOptions(this, true, true);
200 double l = RS_Math::eval(c, &ok);
205 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
206 RS_DIALOGFACTORY->requestOptions(this, true, true);
216 QStringList ActionDrawLineAngle::getAvailableCommands()
225 cmd += command("angle");
226 cmd += command("length");
236 void ActionDrawLineAngle::updateMouseButtonHints()
241 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
246 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
250 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
258 void ActionDrawLineAngle::showOptions()
260 ActionInterface::showOptions();
262 RS_DIALOGFACTORY->requestOptions(this, true);
265 void ActionDrawLineAngle::hideOptions()
267 ActionInterface::hideOptions();
269 RS_DIALOGFACTORY->requestOptions(this, false);
272 void ActionDrawLineAngle::updateMouseCursor()
274 graphicView->setMouseCursor(RS2::CadCursor);
277 void ActionDrawLineAngle::updateToolBar()
280 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
282 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
285 void ActionDrawLineAngle::setSnapPoint(int sp)
290 int ActionDrawLineAngle::getSnapPoint()
295 void ActionDrawLineAngle::setAngle(double a)
300 double ActionDrawLineAngle::getAngle()
305 void ActionDrawLineAngle::setLength(double l)
310 double ActionDrawLineAngle::getLength()
315 bool ActionDrawLineAngle::hasFixedAngle()