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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "actiondrawlinerelangle.h"
17 #include "rs_commandevent.h"
18 #include "rs_creation.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
23 ActionDrawLineRelAngle::ActionDrawLineRelAngle(RS_EntityContainer & container,
24 GraphicView & graphicView, double angle, bool fixedAngle):
25 ActionInterface("Draw Lines with relative angles", container, graphicView)
29 this->fixedAngle = fixedAngle;
34 ActionDrawLineRelAngle::~ActionDrawLineRelAngle()
38 /*virtual*/ RS2::ActionType ActionDrawLineRelAngle::rtti()
40 return RS2::ActionDrawLineRelAngle;
43 void ActionDrawLineRelAngle::trigger()
45 ActionInterface::trigger();
51 RS_Creation creation(container, graphicView);
52 creation.createLineRelAngle(pos, entity, angle, length);
55 void ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e)
57 RS_DEBUG->print("ActionDrawLineRelAngle::mouseMoveEvent begin");
58 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
63 entity = catchEntity(e, RS2::ResolveAll);
73 // RS_Creation creation(preview, NULL, false);
74 // creation.createLineRelAngle(pos, entity, angle, length);
84 RS_DEBUG->print("ActionDrawLineRelAngle::mouseMoveEvent end");
87 void ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e)
89 if (e->button() == Qt::LeftButton)
95 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
98 && (en->rtti() == RS2::EntityLine
99 || en->rtti() == RS2::EntityArc
100 || en->rtti() == RS2::EntityCircle))
104 entity->setHighlighted(true);
105 graphicView->drawEntity(entity);
114 Vector ce(snapPoint(e));
115 coordinateEvent(&ce);
123 else if (e->button() == Qt::RightButton)
131 entity->setHighlighted(false);
132 graphicView->drawEntity(entity);
135 init(getStatus() - 1);
139 void ActionDrawLineRelAngle::coordinateEvent(Vector * e)
156 void ActionDrawLineRelAngle::commandEvent(RS_CommandEvent * e)
158 QString c = e->getCommand().toLower();
160 if (checkCommand("help", c))
162 if (RS_DIALOGFACTORY != NULL)
163 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
164 + getAvailableCommands().join(", "));
172 if (!fixedAngle && checkCommand("angle", c))
179 else if (checkCommand("length", c))
184 setStatus(SetLength);
191 double a = RS_Math::eval(c, &ok);
194 angle = RS_Math::deg2rad(a);
195 else if (RS_DIALOGFACTORY)
196 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
198 if (RS_DIALOGFACTORY)
199 RS_DIALOGFACTORY->requestOptions(this, true, true);
208 double l = RS_Math::eval(c, &ok);
212 else if (RS_DIALOGFACTORY)
213 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
215 if (RS_DIALOGFACTORY)
216 RS_DIALOGFACTORY->requestOptions(this, true, true);
227 QStringList ActionDrawLineRelAngle::getAvailableCommands()
236 cmd += command("angle");
237 cmd += command("length");
247 void ActionDrawLineRelAngle::updateMouseButtonHints()
249 if (RS_DIALOGFACTORY)
254 RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"),
259 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
264 RS_DIALOGFACTORY->updateMouseWidget("", "");
270 void ActionDrawLineRelAngle::showOptions()
272 ActionInterface::showOptions();
274 if (RS_DIALOGFACTORY)
275 RS_DIALOGFACTORY->requestOptions(this, true);
278 void ActionDrawLineRelAngle::hideOptions()
280 ActionInterface::hideOptions();
282 if (RS_DIALOGFACTORY)
283 RS_DIALOGFACTORY->requestOptions(this, false);
286 void ActionDrawLineRelAngle::updateMouseCursor()
288 graphicView->setMouseCursor(RS2::CadCursor);
291 void ActionDrawLineRelAngle::updateToolBar()
293 if (RS_DIALOGFACTORY)
296 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
298 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
302 void ActionDrawLineRelAngle::setAngle(double a)
307 double ActionDrawLineRelAngle::getAngle()
312 void ActionDrawLineRelAngle::setLength(double l)
317 double ActionDrawLineRelAngle::getLength()
322 bool ActionDrawLineRelAngle::hasFixedAngle()