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 "rs_commandevent.h"
20 #include "rs_creation.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
25 ActionDrawLineRelAngle::ActionDrawLineRelAngle(RS_EntityContainer & container,
26 GraphicView & graphicView, double angle, bool fixedAngle):
27 ActionInterface("Draw Lines with relative angles", container, graphicView)
31 this->fixedAngle = fixedAngle;
36 ActionDrawLineRelAngle::~ActionDrawLineRelAngle()
40 /*virtual*/ RS2::ActionType ActionDrawLineRelAngle::rtti()
42 return RS2::ActionDrawLineRelAngle;
45 void ActionDrawLineRelAngle::trigger()
47 ActionInterface::trigger();
53 RS_Creation creation(container, graphicView);
54 creation.createLineRelAngle(pos, entity, angle, length);
57 void ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e)
59 RS_DEBUG->print("ActionDrawLineRelAngle::mouseMoveEvent begin");
60 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
65 entity = catchEntity(e, RS2::ResolveAll);
75 // RS_Creation creation(preview, NULL, false);
76 // creation.createLineRelAngle(pos, entity, angle, length);
86 RS_DEBUG->print("ActionDrawLineRelAngle::mouseMoveEvent end");
89 void ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e)
91 if (e->button() == Qt::LeftButton)
97 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
100 && (en->rtti() == RS2::EntityLine
101 || en->rtti() == RS2::EntityArc
102 || en->rtti() == RS2::EntityCircle))
106 entity->setHighlighted(true);
107 graphicView->drawEntity(entity);
116 Vector ce(snapPoint(e));
117 coordinateEvent(&ce);
125 else if (e->button() == Qt::RightButton)
133 entity->setHighlighted(false);
134 graphicView->drawEntity(entity);
137 init(getStatus() - 1);
141 void ActionDrawLineRelAngle::coordinateEvent(Vector * e)
158 void ActionDrawLineRelAngle::commandEvent(RS_CommandEvent * e)
160 QString c = e->getCommand().toLower();
162 if (checkCommand("help", c))
164 if (RS_DIALOGFACTORY != NULL)
165 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
166 + getAvailableCommands().join(", "));
174 if (!fixedAngle && checkCommand("angle", c))
181 else if (checkCommand("length", c))
186 setStatus(SetLength);
193 double a = RS_Math::eval(c, &ok);
196 angle = RS_Math::deg2rad(a);
197 else if (RS_DIALOGFACTORY)
198 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
200 if (RS_DIALOGFACTORY)
201 RS_DIALOGFACTORY->requestOptions(this, true, true);
210 double l = RS_Math::eval(c, &ok);
214 else if (RS_DIALOGFACTORY)
215 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
217 if (RS_DIALOGFACTORY)
218 RS_DIALOGFACTORY->requestOptions(this, true, true);
229 QStringList ActionDrawLineRelAngle::getAvailableCommands()
238 cmd += command("angle");
239 cmd += command("length");
249 void ActionDrawLineRelAngle::updateMouseButtonHints()
251 if (RS_DIALOGFACTORY)
256 RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"),
261 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
266 RS_DIALOGFACTORY->updateMouseWidget("", "");
272 void ActionDrawLineRelAngle::showOptions()
274 ActionInterface::showOptions();
276 if (RS_DIALOGFACTORY)
277 RS_DIALOGFACTORY->requestOptions(this, true);
280 void ActionDrawLineRelAngle::hideOptions()
282 ActionInterface::hideOptions();
284 if (RS_DIALOGFACTORY)
285 RS_DIALOGFACTORY->requestOptions(this, false);
288 void ActionDrawLineRelAngle::updateMouseCursor()
290 graphicView->setMouseCursor(RS2::CadCursor);
293 void ActionDrawLineRelAngle::updateToolBar()
295 if (RS_DIALOGFACTORY)
298 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
300 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
304 void ActionDrawLineRelAngle::setAngle(double a)
309 double ActionDrawLineRelAngle::getAngle()
314 void ActionDrawLineRelAngle::setLength(double l)
319 double ActionDrawLineRelAngle::getLength()
324 bool ActionDrawLineRelAngle::hasFixedAngle()