1 // actiondrawarctangential.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 06/03/2010 Added this text. :-)
17 #include "actiondrawarctangential.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDrawArcTangential::ActionDrawArcTangential(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw arcs tangential",
25 container, graphicView)
30 ActionDrawArcTangential::~ActionDrawArcTangential()
34 /*virtual*/ RS2::ActionType ActionDrawArcTangential::rtti()
36 return RS2::ActionDrawArcTangential;
39 void ActionDrawArcTangential::reset()
43 point = Vector(false);
46 void ActionDrawArcTangential::init(int status)
48 ActionInterface::init(status);
52 void ActionDrawArcTangential::trigger()
54 ActionInterface::trigger();
56 if (point.valid == false || baseEntity == NULL)
58 RS_DEBUG->print("ActionDrawArcTangential::trigger: "
59 "conditions not met");
64 RS_Arc * arc = new RS_Arc(container, data);
65 arc->setLayerToActive();
66 arc->setPenToActive();
67 container->addEntity(arc);
72 document->startUndoCycle();
73 document->addUndoable(arc);
74 document->endUndoCycle();
78 graphicView->moveRelativeZero(Vector(0.0, 0.0));
79 graphicView->drawEntity(arc);
80 graphicView->moveRelativeZero(arc->getCenter());
83 setStatus(SetBaseEntity);
87 void ActionDrawArcTangential::preparePreview()
89 if (baseEntity != NULL && point.valid)
96 startPoint = baseEntity->getStartpoint();
97 direction = RS_Math::correctAngle(baseEntity->getDirection1() + M_PI);
101 startPoint = baseEntity->getEndpoint();
102 direction = RS_Math::correctAngle(baseEntity->getDirection2() + M_PI);
105 RS_Arc arc(NULL, RS_ArcData());
106 bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius);
109 data = arc.getData();
113 void ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
121 point = snapPoint(e);
126 // RS_Arc * arc = new RS_Arc(preview, data);
129 // preview->addEntity(arc);
139 void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
141 if (e->button() == Qt::LeftButton)
148 Vector coord = graphicView->toGraph(e->x(), e->y());
149 RS_Entity * entity = catchEntity(coord, RS2::ResolveAll);
153 if (entity->isAtomic())
155 baseEntity = (RS_AtomicEntity *)entity;
157 if (baseEntity->getStartpoint().distanceTo(coord)
158 < baseEntity->getEndpoint().distanceTo(coord))
161 isStartPoint = false;
162 setStatus(SetEndAngle);
163 updateMouseButtonHints();
175 // set angle (point that defines the angle)
178 Vector ce(snapPoint(e));
179 coordinateEvent(&ce);
184 else if (e->button() == Qt::RightButton)
188 init(getStatus() - 1);
192 void ActionDrawArcTangential::coordinateEvent(Vector * e)
214 void ActionDrawArcTangential::commandEvent(RS_CommandEvent * e)
216 QString c = e->getCommand().toLower();
218 if (checkCommand("help", c))
220 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
221 + getAvailableCommands().join(", "));
226 QStringList ActionDrawArcTangential::getAvailableCommands()
232 void ActionDrawArcTangential::showOptions()
234 ActionInterface::showOptions();
236 if (RS_DIALOGFACTORY != NULL)
237 RS_DIALOGFACTORY->requestOptions(this, true);
238 updateMouseButtonHints();
241 void ActionDrawArcTangential::hideOptions()
243 ActionInterface::hideOptions();
245 if (RS_DIALOGFACTORY != NULL)
246 RS_DIALOGFACTORY->requestOptions(this, false);
249 void ActionDrawArcTangential::updateMouseButtonHints()
254 RS_DIALOGFACTORY->updateMouseWidget(
255 tr("Specify base entity"),
260 RS_DIALOGFACTORY->updateMouseWidget(
261 tr("Specify end angle"), tr("Back"));
265 RS_DIALOGFACTORY->updateMouseWidget("", "");
270 void ActionDrawArcTangential::updateMouseCursor()
272 graphicView->setMouseCursor(RS2::CadCursor);
275 void ActionDrawArcTangential::updateToolBar()
278 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
280 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
283 void ActionDrawArcTangential::setRadius(double r)
288 double ActionDrawArcTangential::getRadius()