1 // rs_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 "rs_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 RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
24 RS_PreviewActionInterface("Draw Lines with relative angles",
25 container, graphicView)
29 this->fixedAngle = fixedAngle;
34 RS_ActionDrawLineRelAngle::~RS_ActionDrawLineRelAngle()
38 /*virtual*/ RS2::ActionType RS_ActionDrawLineRelAngle::rtti()
40 return RS2::ActionDrawLineRelAngle;
43 void RS_ActionDrawLineRelAngle::trigger()
45 RS_PreviewActionInterface::trigger();
51 RS_Creation creation(container, graphicView);
52 creation.createLineRelAngle(pos,
59 RS_Entity* newEntity = NULL;
61 newEntity = new RS_Line(container,
64 if (newEntity!=NULL) {
65 newEntity->setLayerToActive();
66 newEntity->setPenToActive();
67 container->addEntity(newEntity);
71 document->startUndoCycle();
72 document->addUndoable(newEntity);
73 document->endUndoCycle();
76 graphicView->drawEntity(newEntity);
83 RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:"
89 void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e)
91 RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin");
93 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
98 entity = catchEntity(e, RS2::ResolveAll);
102 //length = graphicView->toGraphDX(graphicView->getWidth());
103 //Vector mouse = snapPoint(e);
106 /*RS_Creation creation(NULL, NULL);
107 RS_Line* l = creation.createLineRelAngle(mouse,
115 RS_Creation creation(preview, NULL, false);
116 creation.createLineRelAngle(pos,
127 line = (RS_Line*)l->clone();
131 preview->addEntity(l);
141 RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end");
144 void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e)
146 if (e->button() == Qt::LeftButton)
151 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
154 && (en->rtti() == RS2::EntityLine
155 || en->rtti() == RS2::EntityArc
156 || en->rtti() == RS2::EntityCircle))
160 entity->setHighlighted(true);
161 graphicView->drawEntity(entity);
169 Vector ce(snapPoint(e));
170 coordinateEvent(&ce);
178 else if (e->button() == Qt::RightButton)
186 entity->setHighlighted(false);
187 graphicView->drawEntity(entity);
189 init(getStatus() - 1);
193 void RS_ActionDrawLineRelAngle::coordinateEvent(Vector * e)
210 void RS_ActionDrawLineRelAngle::commandEvent(RS_CommandEvent * e)
212 QString c = e->getCommand().toLower();
214 if (checkCommand("help", c))
216 if (RS_DIALOGFACTORY != NULL)
217 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
218 + getAvailableCommands().join(", "));
227 if (!fixedAngle && checkCommand("angle", c))
234 else if (checkCommand("length", c))
239 setStatus(SetLength);
245 double a = RS_Math::eval(c, &ok);
248 angle = RS_Math::deg2rad(a);
249 else if (RS_DIALOGFACTORY != NULL)
250 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
252 if (RS_DIALOGFACTORY != NULL)
253 RS_DIALOGFACTORY->requestOptions(this, true, true);
260 double l = RS_Math::eval(c, &ok);
264 else if (RS_DIALOGFACTORY != NULL)
265 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
267 if (RS_DIALOGFACTORY != NULL)
268 RS_DIALOGFACTORY->requestOptions(this, true, true);
278 QStringList RS_ActionDrawLineRelAngle::getAvailableCommands()
288 cmd += command("angle");
289 cmd += command("length");
299 void RS_ActionDrawLineRelAngle::updateMouseButtonHints()
301 if (RS_DIALOGFACTORY != NULL)
306 RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"),
311 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
316 RS_DIALOGFACTORY->updateMouseWidget("", "");
322 void RS_ActionDrawLineRelAngle::showOptions()
324 RS_ActionInterface::showOptions();
326 if (RS_DIALOGFACTORY != NULL)
327 RS_DIALOGFACTORY->requestOptions(this, true);
330 void RS_ActionDrawLineRelAngle::hideOptions()
332 RS_ActionInterface::hideOptions();
334 if (RS_DIALOGFACTORY != NULL)
335 RS_DIALOGFACTORY->requestOptions(this, false);
338 void RS_ActionDrawLineRelAngle::updateMouseCursor()
340 graphicView->setMouseCursor(RS2::CadCursor);
343 void RS_ActionDrawLineRelAngle::updateToolBar()
345 if (RS_DIALOGFACTORY != NULL)
348 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
350 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
354 void RS_ActionDrawLineRelAngle::setAngle(double a)
359 double RS_ActionDrawLineRelAngle::getAngle()
364 void RS_ActionDrawLineRelAngle::setLength(double l)
369 double RS_ActionDrawLineRelAngle::getLength()
374 bool RS_ActionDrawLineRelAngle::hasFixedAngle()