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_commandevent.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 RS_ActionDrawLineAngle::RS_ActionDrawLineAngle(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
24 RS_PreviewActionInterface("Draw lines with given angle",
25 container, graphicView)
30 this->fixedAngle = fixedAngle;
35 RS_ActionDrawLineAngle::~RS_ActionDrawLineAngle()
39 /*virtual*/ RS2::ActionType RS_ActionDrawLineAngle::rtti()
41 return RS2::ActionDrawLineAngle;
44 void RS_ActionDrawLineAngle::reset()
46 data = RS_LineData(Vector(false), Vector(false));
49 void RS_ActionDrawLineAngle::init(int status)
51 RS_PreviewActionInterface::init(status);
56 void RS_ActionDrawLineAngle::trigger()
58 RS_PreviewActionInterface::trigger();
61 RS_Line * line = new RS_Line(container,
63 line->setLayerToActive();
64 line->setPenToActive();
65 container->addEntity(line);
70 document->startUndoCycle();
71 document->addUndoable(line);
72 document->endUndoCycle();
75 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 graphicView->drawEntity(line);
77 graphicView->moveRelativeZero(data.startpoint);
78 RS_DEBUG->print("RS_ActionDrawLineAngle::trigger(): line added: %d",
82 void RS_ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
84 RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent begin");
86 if (getStatus() == SetPos)
92 preview->addEntity(new RS_Line(preview,
97 RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent end");
100 void RS_ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
102 if (e->button() == Qt::LeftButton)
104 if (getStatus() == SetPos)
106 Vector ce(snapPoint(e));
107 coordinateEvent(&ce);
110 else if (e->button() == Qt::RightButton)
114 init(getStatus() - 1);
118 void RS_ActionDrawLineAngle::preparePreview()
124 p2.setPolar(length * -1, angle);
126 p2.setPolar(length, angle);
135 data = RS_LineData(p1, p2);
138 void RS_ActionDrawLineAngle::coordinateEvent(Vector * e)
155 void RS_ActionDrawLineAngle::commandEvent(RS_CommandEvent * e)
157 QString c = e->getCommand().toLower();
159 if (checkCommand("help", c))
161 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
162 + getAvailableCommands().join(", "));
170 if (!fixedAngle && checkCommand("angle", c))
177 else if (checkCommand("length", c))
182 setStatus(SetLength);
188 double a = RS_Math::eval(c, &ok);
191 angle = RS_Math::deg2rad(a);
193 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
194 RS_DIALOGFACTORY->requestOptions(this, true, true);
201 double l = RS_Math::eval(c, &ok);
206 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
207 RS_DIALOGFACTORY->requestOptions(this, true, true);
217 QStringList RS_ActionDrawLineAngle::getAvailableCommands()
226 cmd += command("angle");
227 cmd += command("length");
237 void RS_ActionDrawLineAngle::updateMouseButtonHints()
242 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
247 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
251 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
259 void RS_ActionDrawLineAngle::showOptions()
261 RS_ActionInterface::showOptions();
263 RS_DIALOGFACTORY->requestOptions(this, true);
266 void RS_ActionDrawLineAngle::hideOptions()
268 RS_ActionInterface::hideOptions();
270 RS_DIALOGFACTORY->requestOptions(this, false);
273 void RS_ActionDrawLineAngle::updateMouseCursor()
275 graphicView->setMouseCursor(RS2::CadCursor);
278 void RS_ActionDrawLineAngle::updateToolBar()
281 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
283 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
286 void RS_ActionDrawLineAngle::setSnapPoint(int sp)
291 int RS_ActionDrawLineAngle::getSnapPoint()
296 void RS_ActionDrawLineAngle::setAngle(double a)
301 double RS_ActionDrawLineAngle::getAngle()
306 void RS_ActionDrawLineAngle::setLength(double l)
311 double RS_ActionDrawLineAngle::getLength()
316 bool RS_ActionDrawLineAngle::hasFixedAngle()