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)
33 // graphicView.snapper.SetContainer(&container);
34 // graphicView.snapper.SetGraphicView(&graphicView);
35 // graphicView.snapper.SetVisible();
36 // graphicView.preview.SetVisible();
39 ActionDrawLineAngle::~ActionDrawLineAngle()
43 /*virtual*/ RS2::ActionType ActionDrawLineAngle::rtti()
45 return RS2::ActionDrawLineAngle;
48 void ActionDrawLineAngle::reset()
50 data = LineData(Vector(false), Vector(false));
53 void ActionDrawLineAngle::init(int status)
55 ActionInterface::init(status);
59 void ActionDrawLineAngle::trigger()
61 ActionInterface::trigger();
63 Line * line = new 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 graphicView->redraw();
81 DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d", line->getId());
84 void ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
86 DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
88 if (getStatus() == SetPos)
94 // preview->addEntity(new Line(preview, data));
97 graphicView->preview.clear();
98 graphicView->preview.addEntity(new Line(&(graphicView->preview), data));
101 graphicView->redraw();
102 DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
105 void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
107 if (e->button() == Qt::LeftButton)
109 if (getStatus() == SetPos)
111 // Vector ce(snapPoint(e));
112 Vector ce(graphicView->snapper.snapPoint(e));
113 coordinateEvent(&ce);
116 else if (e->button() == Qt::RightButton)
120 init(getStatus() - 1);
123 graphicView->preview.clear(); // Remove entities from container
124 graphicView->redraw();
127 void ActionDrawLineAngle::preparePreview()
133 p2.setPolar(length * -1, angle);
135 p2.setPolar(length, angle);
144 data = LineData(p1, p2);
147 void ActionDrawLineAngle::coordinateEvent(Vector * e)
164 void ActionDrawLineAngle::commandEvent(CommandEvent * e)
166 QString c = e->getCommand().toLower();
168 if (checkCommand("help", c))
170 DIALOGFACTORY->commandMessage(msgAvailableCommands()
171 + getAvailableCommands().join(", "));
178 if (!fixedAngle && checkCommand("angle", c))
185 else if (checkCommand("length", c))
190 setStatus(SetLength);
197 double a = Math::eval(c, &ok);
200 angle = Math::deg2rad(a);
202 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
204 DIALOGFACTORY->requestOptions(this, true, true);
212 double l = Math::eval(c, &ok);
217 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
219 DIALOGFACTORY->requestOptions(this, true, true);
229 QStringList ActionDrawLineAngle::getAvailableCommands()
237 cmd += command("angle");
239 cmd += command("length");
249 void ActionDrawLineAngle::updateMouseButtonHints()
254 DIALOGFACTORY->updateMouseWidget(tr("Specify position"), tr("Cancel"));
258 DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
262 DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
270 void ActionDrawLineAngle::showOptions()
272 ActionInterface::showOptions();
273 DIALOGFACTORY->requestOptions(this, true);
276 void ActionDrawLineAngle::hideOptions()
278 ActionInterface::hideOptions();
279 DIALOGFACTORY->requestOptions(this, false);
282 void ActionDrawLineAngle::updateMouseCursor()
284 graphicView->setMouseCursor(RS2::CadCursor);
287 void ActionDrawLineAngle::updateToolBar()
290 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
292 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
295 void ActionDrawLineAngle::setSnapPoint(int sp)
298 // graphicView->redraw();
301 int ActionDrawLineAngle::getSnapPoint()
306 void ActionDrawLineAngle::setAngle(double a)
309 // graphicView->redraw();
312 double ActionDrawLineAngle::getAngle()
317 void ActionDrawLineAngle::setLength(double l)
320 // graphicView->redraw();
323 double ActionDrawLineAngle::getLength()
328 bool ActionDrawLineAngle::hasFixedAngle()