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_creation.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle):
23 RS_PreviewActionInterface("Draw Lines with relative angles",
24 container, graphicView)
28 this->fixedAngle = fixedAngle;
33 RS_ActionDrawLineRelAngle::~RS_ActionDrawLineRelAngle()
37 /*virtual*/ RS2::ActionType RS_ActionDrawLineRelAngle::rtti()
39 return RS2::ActionDrawLineRelAngle;
42 void RS_ActionDrawLineRelAngle::trigger()
44 RS_PreviewActionInterface::trigger();
50 RS_Creation creation(container, graphicView);
51 creation.createLineRelAngle(pos,
58 RS_Entity* newEntity = NULL;
60 newEntity = new RS_Line(container,
63 if (newEntity!=NULL) {
64 newEntity->setLayerToActive();
65 newEntity->setPenToActive();
66 container->addEntity(newEntity);
70 document->startUndoCycle();
71 document->addUndoable(newEntity);
72 document->endUndoCycle();
75 graphicView->drawEntity(newEntity);
82 RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:"
88 void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e)
90 RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin");
92 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
97 entity = catchEntity(e, RS2::ResolveAll);
101 //length = graphicView->toGraphDX(graphicView->getWidth());
102 //Vector mouse = snapPoint(e);
105 /*RS_Creation creation(NULL, NULL);
106 RS_Line* l = creation.createLineRelAngle(mouse,
114 RS_Creation creation(preview, NULL, false);
115 creation.createLineRelAngle(pos,
126 line = (RS_Line*)l->clone();
130 preview->addEntity(l);
140 RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end");
143 void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e)
145 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
150 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
153 && (en->rtti() == RS2::EntityLine
154 || en->rtti() == RS2::EntityArc
155 || en->rtti() == RS2::EntityCircle))
159 entity->setHighlighted(true);
160 graphicView->drawEntity(entity);
168 Vector ce(snapPoint(e));
169 coordinateEvent(&ce);
177 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
185 entity->setHighlighted(false);
186 graphicView->drawEntity(entity);
188 init(getStatus() - 1);
192 void RS_ActionDrawLineRelAngle::coordinateEvent(Vector * e)
209 void RS_ActionDrawLineRelAngle::commandEvent(RS_CommandEvent * e)
211 QString c = e->getCommand().toLower();
213 if (checkCommand("help", c))
215 if (RS_DIALOGFACTORY != NULL)
216 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
217 + getAvailableCommands().join(", "));
226 if (!fixedAngle && checkCommand("angle", c))
233 else if (checkCommand("length", c))
238 setStatus(SetLength);
244 double a = RS_Math::eval(c, &ok);
247 angle = RS_Math::deg2rad(a);
248 else if (RS_DIALOGFACTORY != NULL)
249 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
251 if (RS_DIALOGFACTORY != NULL)
252 RS_DIALOGFACTORY->requestOptions(this, true, true);
259 double l = RS_Math::eval(c, &ok);
263 else if (RS_DIALOGFACTORY != NULL)
264 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
266 if (RS_DIALOGFACTORY != NULL)
267 RS_DIALOGFACTORY->requestOptions(this, true, true);
277 QStringList RS_ActionDrawLineRelAngle::getAvailableCommands()
287 cmd += command("angle");
288 cmd += command("length");
298 void RS_ActionDrawLineRelAngle::updateMouseButtonHints()
300 if (RS_DIALOGFACTORY != NULL)
305 RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"),
310 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
315 RS_DIALOGFACTORY->updateMouseWidget("", "");
321 void RS_ActionDrawLineRelAngle::showOptions()
323 RS_ActionInterface::showOptions();
325 if (RS_DIALOGFACTORY != NULL)
326 RS_DIALOGFACTORY->requestOptions(this, true);
329 void RS_ActionDrawLineRelAngle::hideOptions()
331 RS_ActionInterface::hideOptions();
333 if (RS_DIALOGFACTORY != NULL)
334 RS_DIALOGFACTORY->requestOptions(this, false);
337 void RS_ActionDrawLineRelAngle::updateMouseCursor()
339 graphicView->setMouseCursor(RS2::CadCursor);
342 void RS_ActionDrawLineRelAngle::updateToolBar()
344 if (RS_DIALOGFACTORY != NULL)
347 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
349 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
353 void RS_ActionDrawLineRelAngle::setAngle(double a)
358 double RS_ActionDrawLineRelAngle::getAngle()
363 void RS_ActionDrawLineRelAngle::setLength(double l)
368 double RS_ActionDrawLineRelAngle::getLength()
373 bool RS_ActionDrawLineRelAngle::hasFixedAngle()