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 "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawLineAngle::ActionDrawLineAngle(EntityContainer & container,
27 GraphicView & graphicView, double a, bool fa):
28 ActionInterface("Draw lines with given angle", container, graphicView),
29 pos(Vector(false)), angle(a), length(1.0), fixedAngle(fa), snpPoint(0)
34 ActionDrawLineAngle::~ActionDrawLineAngle()
38 /*virtual*/ RS2::ActionType ActionDrawLineAngle::rtti()
40 return RS2::ActionDrawLineAngle;
43 void ActionDrawLineAngle::reset()
45 data = LineData(Vector(false), Vector(false));
48 void ActionDrawLineAngle::init(int status)
50 ActionInterface::init(status);
54 void ActionDrawLineAngle::trigger()
56 ActionInterface::trigger();
58 Line * line = new Line(container, data);
59 line->setLayerToActive();
60 line->setPenToActive();
61 container->addEntity(line);
66 document->startUndoCycle();
67 document->addUndoable(line);
68 document->endUndoCycle();
72 graphicView->moveRelativeZero(Vector(0.0, 0.0));
73 graphicView->drawEntity(line);
74 graphicView->moveRelativeZero(data.startpoint);
75 graphicView->redraw();
76 DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d", line->getId());
79 void ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
81 DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
83 if (getStatus() == SetPos)
89 // preview->addEntity(new Line(preview, data));
92 graphicView->preview.clear();
93 graphicView->preview.addEntity(new Line(&(graphicView->preview), data));
96 graphicView->redraw();
97 DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
100 void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
102 if (e->button() == Qt::LeftButton)
104 if (getStatus() == SetPos)
106 // Vector ce(snapPoint(e));
107 Vector ce(graphicView->SnapPoint(e));
108 coordinateEvent(&ce);
111 else if (e->button() == Qt::RightButton)
115 init(getStatus() - 1);
118 graphicView->preview.clear(); // Remove entities from container
119 graphicView->redraw();
122 void ActionDrawLineAngle::preparePreview()
128 p2.setPolar(length * -1, angle);
130 p2.setPolar(length, angle);
139 data = LineData(p1, p2);
142 void ActionDrawLineAngle::coordinateEvent(Vector * e)
159 void ActionDrawLineAngle::commandEvent(CommandEvent * e)
161 QString c = e->getCommand().toLower();
163 if (checkCommand("help", c))
165 DIALOGFACTORY->commandMessage(msgAvailableCommands()
166 + getAvailableCommands().join(", "));
173 if (!fixedAngle && checkCommand("angle", c))
180 else if (checkCommand("length", c))
185 setStatus(SetLength);
192 double a = Math::eval(c, &ok);
195 angle = Math::deg2rad(a);
197 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
199 DIALOGFACTORY->requestOptions(this, true, true);
207 double l = Math::eval(c, &ok);
212 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
214 DIALOGFACTORY->requestOptions(this, true, true);
224 QStringList ActionDrawLineAngle::getAvailableCommands()
232 cmd += command("angle");
234 cmd += command("length");
244 void ActionDrawLineAngle::updateMouseButtonHints()
249 DIALOGFACTORY->updateMouseWidget(tr("Specify position"), tr("Cancel"));
253 DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
257 DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
265 void ActionDrawLineAngle::showOptions()
267 ActionInterface::showOptions();
268 DIALOGFACTORY->requestOptions(this, true);
271 void ActionDrawLineAngle::hideOptions()
273 ActionInterface::hideOptions();
274 DIALOGFACTORY->requestOptions(this, false);
277 void ActionDrawLineAngle::updateMouseCursor()
279 graphicView->setMouseCursor(RS2::CadCursor);
282 void ActionDrawLineAngle::updateToolBar()
285 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
287 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
290 void ActionDrawLineAngle::setSnapPoint(int sp)
293 // graphicView->redraw();
296 int ActionDrawLineAngle::getSnapPoint()
301 void ActionDrawLineAngle::setAngle(double a)
304 // graphicView->redraw();
307 double ActionDrawLineAngle::getAngle()
312 void ActionDrawLineAngle::setLength(double l)
315 // graphicView->redraw();
318 double ActionDrawLineAngle::getLength()
323 bool ActionDrawLineAngle::hasFixedAngle()