1 // rs_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 "rs_actiondrawlineangle.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLineAngle::RS_ActionDrawLineAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle):
23 RS_PreviewActionInterface("Draw lines with given angle",
24 container, graphicView)
29 this->fixedAngle = fixedAngle;
34 RS_ActionDrawLineAngle::~RS_ActionDrawLineAngle()
38 /*virtual*/ RS2::ActionType RS_ActionDrawLineAngle::rtti()
40 return RS2::ActionDrawLineAngle;
43 void RS_ActionDrawLineAngle::reset()
45 data = RS_LineData(Vector(false), Vector(false));
48 void RS_ActionDrawLineAngle::init(int status)
50 RS_PreviewActionInterface::init(status);
55 void RS_ActionDrawLineAngle::trigger()
57 RS_PreviewActionInterface::trigger();
60 RS_Line * line = new RS_Line(container,
62 line->setLayerToActive();
63 line->setPenToActive();
64 container->addEntity(line);
69 document->startUndoCycle();
70 document->addUndoable(line);
71 document->endUndoCycle();
74 graphicView->moveRelativeZero(Vector(0.0, 0.0));
75 graphicView->drawEntity(line);
76 graphicView->moveRelativeZero(data.startpoint);
77 RS_DEBUG->print("RS_ActionDrawLineAngle::trigger(): line added: %d",
81 void RS_ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
83 RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent begin");
85 if (getStatus() == SetPos)
91 preview->addEntity(new RS_Line(preview,
96 RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent end");
99 void RS_ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
101 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
103 if (getStatus() == SetPos)
105 Vector ce(snapPoint(e));
106 coordinateEvent(&ce);
109 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
113 init(getStatus() - 1);
117 void RS_ActionDrawLineAngle::preparePreview()
123 p2.setPolar(length * -1, angle);
125 p2.setPolar(length, angle);
134 data = RS_LineData(p1, p2);
137 void RS_ActionDrawLineAngle::coordinateEvent(Vector * e)
154 void RS_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 RS_ActionDrawLineAngle::getAvailableCommands()
225 cmd += command("angle");
226 cmd += command("length");
236 void RS_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 RS_ActionDrawLineAngle::showOptions()
260 RS_ActionInterface::showOptions();
262 RS_DIALOGFACTORY->requestOptions(this, true);
265 void RS_ActionDrawLineAngle::hideOptions()
267 RS_ActionInterface::hideOptions();
269 RS_DIALOGFACTORY->requestOptions(this, false);
272 void RS_ActionDrawLineAngle::updateMouseCursor()
274 graphicView->setMouseCursor(RS2::CadCursor);
277 void RS_ActionDrawLineAngle::updateToolBar()
280 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
282 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
285 void RS_ActionDrawLineAngle::setSnapPoint(int sp)
290 int RS_ActionDrawLineAngle::getSnapPoint()
295 void RS_ActionDrawLineAngle::setAngle(double a)
300 double RS_ActionDrawLineAngle::getAngle()
305 void RS_ActionDrawLineAngle::setLength(double l)
310 double RS_ActionDrawLineAngle::getLength()
315 bool RS_ActionDrawLineAngle::hasFixedAngle()