1 // actiondrawlinerelangle.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. :-)
17 #include "actiondrawlinerelangle.h"
19 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawLineRelAngle::ActionDrawLineRelAngle(EntityContainer & container,
27 GraphicView & graphicView, double angle, bool fixedAngle):
28 ActionInterface("Draw Lines with relative angles", container, graphicView)
32 this->fixedAngle = fixedAngle;
37 ActionDrawLineRelAngle::~ActionDrawLineRelAngle()
41 /*virtual*/ RS2::ActionType ActionDrawLineRelAngle::rtti()
43 return RS2::ActionDrawLineRelAngle;
46 void ActionDrawLineRelAngle::trigger()
48 ActionInterface::trigger();
54 Creation creation(container, graphicView);
55 creation.createLineRelAngle(pos, entity, angle, length);
58 void ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e)
60 DEBUG->print("ActionDrawLineRelAngle::mouseMoveEvent begin");
61 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
66 entity = catchEntity(e, RS2::ResolveAll);
76 // Creation creation(preview, NULL, false);
77 // creation.createLineRelAngle(pos, entity, angle, length);
87 DEBUG->print("ActionDrawLineRelAngle::mouseMoveEvent end");
90 void ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e)
92 if (e->button() == Qt::LeftButton)
98 Entity * en = catchEntity(e, RS2::ResolveAll);
101 && (en->rtti() == RS2::EntityLine
102 || en->rtti() == RS2::EntityArc
103 || en->rtti() == RS2::EntityCircle))
107 entity->setHighlighted(true);
108 graphicView->drawEntity(entity);
117 Vector ce(snapPoint(e));
118 coordinateEvent(&ce);
126 else if (e->button() == Qt::RightButton)
134 entity->setHighlighted(false);
135 graphicView->drawEntity(entity);
138 init(getStatus() - 1);
142 void ActionDrawLineRelAngle::coordinateEvent(Vector * e)
159 void ActionDrawLineRelAngle::commandEvent(CommandEvent * e)
161 QString c = e->getCommand().toLower();
163 if (checkCommand("help", c))
165 if (DIALOGFACTORY != NULL)
166 DIALOGFACTORY->commandMessage(msgAvailableCommands()
167 + getAvailableCommands().join(", "));
175 if (!fixedAngle && checkCommand("angle", c))
182 else if (checkCommand("length", c))
187 setStatus(SetLength);
194 double a = Math::eval(c, &ok);
197 angle = Math::deg2rad(a);
198 else if (DIALOGFACTORY)
199 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
202 DIALOGFACTORY->requestOptions(this, true, true);
211 double l = Math::eval(c, &ok);
215 else if (DIALOGFACTORY)
216 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
219 DIALOGFACTORY->requestOptions(this, true, true);
230 QStringList ActionDrawLineRelAngle::getAvailableCommands()
239 cmd += command("angle");
240 cmd += command("length");
250 void ActionDrawLineRelAngle::updateMouseButtonHints()
257 DIALOGFACTORY->updateMouseWidget(tr("Select base entity"),
262 DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
267 DIALOGFACTORY->updateMouseWidget("", "");
273 void ActionDrawLineRelAngle::showOptions()
275 ActionInterface::showOptions();
278 DIALOGFACTORY->requestOptions(this, true);
281 void ActionDrawLineRelAngle::hideOptions()
283 ActionInterface::hideOptions();
286 DIALOGFACTORY->requestOptions(this, false);
289 void ActionDrawLineRelAngle::updateMouseCursor()
291 graphicView->setMouseCursor(RS2::CadCursor);
294 void ActionDrawLineRelAngle::updateToolBar()
299 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
301 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
305 void ActionDrawLineRelAngle::setAngle(double a)
310 double ActionDrawLineRelAngle::getAngle()
315 void ActionDrawLineRelAngle::setLength(double l)
320 double ActionDrawLineRelAngle::getLength()
325 bool ActionDrawLineRelAngle::hasFixedAngle()