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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
15 #include "actiondrawarctangential.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 ActionDrawArcTangential::ActionDrawArcTangential(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw arcs tangential",
23 container, graphicView)
28 ActionDrawArcTangential::~ActionDrawArcTangential()
32 /*virtual*/ RS2::ActionType ActionDrawArcTangential::rtti()
34 return RS2::ActionDrawArcTangential;
37 void ActionDrawArcTangential::reset()
41 point = Vector(false);
44 void ActionDrawArcTangential::init(int status)
46 ActionInterface::init(status);
50 void ActionDrawArcTangential::trigger()
52 ActionInterface::trigger();
54 if (point.valid == false || baseEntity == NULL)
56 RS_DEBUG->print("ActionDrawArcTangential::trigger: "
57 "conditions not met");
62 RS_Arc * arc = new RS_Arc(container, data);
63 arc->setLayerToActive();
64 arc->setPenToActive();
65 container->addEntity(arc);
70 document->startUndoCycle();
71 document->addUndoable(arc);
72 document->endUndoCycle();
76 graphicView->moveRelativeZero(Vector(0.0, 0.0));
77 graphicView->drawEntity(arc);
78 graphicView->moveRelativeZero(arc->getCenter());
81 setStatus(SetBaseEntity);
85 void ActionDrawArcTangential::preparePreview()
87 if (baseEntity != NULL && point.valid)
94 startPoint = baseEntity->getStartpoint();
95 direction = RS_Math::correctAngle(baseEntity->getDirection1() + M_PI);
99 startPoint = baseEntity->getEndpoint();
100 direction = RS_Math::correctAngle(baseEntity->getDirection2() + M_PI);
103 RS_Arc arc(NULL, RS_ArcData());
104 bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius);
107 data = arc.getData();
111 void ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
119 point = snapPoint(e);
124 // RS_Arc * arc = new RS_Arc(preview, data);
127 // preview->addEntity(arc);
137 void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
139 if (e->button() == Qt::LeftButton)
146 Vector coord = graphicView->toGraph(e->x(), e->y());
147 RS_Entity * entity = catchEntity(coord, RS2::ResolveAll);
151 if (entity->isAtomic())
153 baseEntity = (RS_AtomicEntity *)entity;
155 if (baseEntity->getStartpoint().distanceTo(coord)
156 < baseEntity->getEndpoint().distanceTo(coord))
159 isStartPoint = false;
160 setStatus(SetEndAngle);
161 updateMouseButtonHints();
173 // set angle (point that defines the angle)
176 Vector ce(snapPoint(e));
177 coordinateEvent(&ce);
182 else if (e->button() == Qt::RightButton)
186 init(getStatus() - 1);
190 void ActionDrawArcTangential::coordinateEvent(Vector * e)
212 void ActionDrawArcTangential::commandEvent(RS_CommandEvent * e)
214 QString c = e->getCommand().toLower();
216 if (checkCommand("help", c))
218 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
219 + getAvailableCommands().join(", "));
224 QStringList ActionDrawArcTangential::getAvailableCommands()
230 void ActionDrawArcTangential::showOptions()
232 ActionInterface::showOptions();
234 if (RS_DIALOGFACTORY != NULL)
235 RS_DIALOGFACTORY->requestOptions(this, true);
236 updateMouseButtonHints();
239 void ActionDrawArcTangential::hideOptions()
241 ActionInterface::hideOptions();
243 if (RS_DIALOGFACTORY != NULL)
244 RS_DIALOGFACTORY->requestOptions(this, false);
247 void ActionDrawArcTangential::updateMouseButtonHints()
252 RS_DIALOGFACTORY->updateMouseWidget(
253 tr("Specify base entity"),
258 RS_DIALOGFACTORY->updateMouseWidget(
259 tr("Specify end angle"), tr("Back"));
263 RS_DIALOGFACTORY->updateMouseWidget("", "");
268 void ActionDrawArcTangential::updateMouseCursor()
270 graphicView->setMouseCursor(RS2::CadCursor);
273 void ActionDrawArcTangential::updateToolBar()
276 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
278 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
281 void ActionDrawArcTangential::setRadius(double r)
286 double ActionDrawArcTangential::getRadius()