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"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawLineAngle::ActionDrawLineAngle(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
26 ActionInterface("Draw lines with given angle",
27 container, graphicView)
32 this->fixedAngle = fixedAngle;
37 ActionDrawLineAngle::~ActionDrawLineAngle()
41 /*virtual*/ RS2::ActionType ActionDrawLineAngle::rtti()
43 return RS2::ActionDrawLineAngle;
46 void ActionDrawLineAngle::reset()
48 data = RS_LineData(Vector(false), Vector(false));
51 void ActionDrawLineAngle::init(int status)
53 ActionInterface::init(status);
58 void ActionDrawLineAngle::trigger()
60 ActionInterface::trigger();
63 RS_Line * line = new RS_Line(container, data);
64 line->setLayerToActive();
65 line->setPenToActive();
66 container->addEntity(line);
71 document->startUndoCycle();
72 document->addUndoable(line);
73 document->endUndoCycle();
77 graphicView->moveRelativeZero(Vector(0.0, 0.0));
78 graphicView->drawEntity(line);
79 graphicView->moveRelativeZero(data.startpoint);
80 RS_DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d",
84 void ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
86 RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
88 if (getStatus() == SetPos)
94 // preview->addEntity(new RS_Line(preview, data));
98 RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
101 void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
103 if (e->button() == Qt::LeftButton)
105 if (getStatus() == SetPos)
107 Vector ce(snapPoint(e));
108 coordinateEvent(&ce);
111 else if (e->button() == Qt::RightButton)
115 init(getStatus() - 1);
119 void ActionDrawLineAngle::preparePreview()
125 p2.setPolar(length * -1, angle);
127 p2.setPolar(length, angle);
136 data = RS_LineData(p1, p2);
139 void ActionDrawLineAngle::coordinateEvent(Vector * e)
156 void ActionDrawLineAngle::commandEvent(RS_CommandEvent * e)
158 QString c = e->getCommand().toLower();
160 if (checkCommand("help", c))
162 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
163 + getAvailableCommands().join(", "));
171 if (!fixedAngle && checkCommand("angle", c))
178 else if (checkCommand("length", c))
183 setStatus(SetLength);
189 double a = RS_Math::eval(c, &ok);
192 angle = RS_Math::deg2rad(a);
194 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
195 RS_DIALOGFACTORY->requestOptions(this, true, true);
202 double l = RS_Math::eval(c, &ok);
207 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
208 RS_DIALOGFACTORY->requestOptions(this, true, true);
218 QStringList ActionDrawLineAngle::getAvailableCommands()
227 cmd += command("angle");
228 cmd += command("length");
238 void ActionDrawLineAngle::updateMouseButtonHints()
243 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
248 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
252 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
260 void ActionDrawLineAngle::showOptions()
262 ActionInterface::showOptions();
264 RS_DIALOGFACTORY->requestOptions(this, true);
267 void ActionDrawLineAngle::hideOptions()
269 ActionInterface::hideOptions();
271 RS_DIALOGFACTORY->requestOptions(this, false);
274 void ActionDrawLineAngle::updateMouseCursor()
276 graphicView->setMouseCursor(RS2::CadCursor);
279 void ActionDrawLineAngle::updateToolBar()
282 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
284 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
287 void ActionDrawLineAngle::setSnapPoint(int sp)
292 int ActionDrawLineAngle::getSnapPoint()
297 void ActionDrawLineAngle::setAngle(double a)
302 double ActionDrawLineAngle::getAngle()
307 void ActionDrawLineAngle::setLength(double l)
312 double ActionDrawLineAngle::getLength()
317 bool ActionDrawLineAngle::hasFixedAngle()