1 // rs_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 "rs_actiondrawarctangential.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs tangential",
23 container, graphicView)
28 RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential()
32 /*virtual*/ RS2::ActionType RS_ActionDrawArcTangential::rtti()
34 return RS2::ActionDrawArcTangential;
37 void RS_ActionDrawArcTangential::reset()
41 point = Vector(false);
44 void RS_ActionDrawArcTangential::init(int status)
46 RS_PreviewActionInterface::init(status);
50 void RS_ActionDrawArcTangential::trigger()
52 RS_PreviewActionInterface::trigger();
54 if (point.valid == false || baseEntity == NULL)
56 RS_DEBUG->print("RS_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 RS_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 RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
119 point = snapPoint(e);
124 RS_Arc * arc = new RS_Arc(preview, data);
127 preview->addEntity(arc);
137 void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
139 if (e->button() == Qt::LeftButton)
144 case SetBaseEntity: {
145 Vector coord = graphicView->toGraph(e->x(), e->y());
146 RS_Entity * entity = catchEntity(coord, RS2::ResolveAll);
150 if (entity->isAtomic())
152 baseEntity = (RS_AtomicEntity *)entity;
154 if (baseEntity->getStartpoint().distanceTo(coord)
155 < baseEntity->getEndpoint().distanceTo(coord))
158 isStartPoint = false;
159 setStatus(SetEndAngle);
160 updateMouseButtonHints();
172 // set angle (point that defines the angle)
174 Vector ce(snapPoint(e));
175 coordinateEvent(&ce);
180 else if (e->button() == Qt::RightButton)
184 init(getStatus() - 1);
188 void RS_ActionDrawArcTangential::coordinateEvent(Vector * e)
210 void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent * e)
212 QString c = e->getCommand().toLower();
214 if (checkCommand("help", c))
216 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
217 + getAvailableCommands().join(", "));
222 QStringList RS_ActionDrawArcTangential::getAvailableCommands()
228 void RS_ActionDrawArcTangential::showOptions()
230 RS_ActionInterface::showOptions();
232 if (RS_DIALOGFACTORY != NULL)
233 RS_DIALOGFACTORY->requestOptions(this, true);
234 updateMouseButtonHints();
237 void RS_ActionDrawArcTangential::hideOptions()
239 RS_ActionInterface::hideOptions();
241 if (RS_DIALOGFACTORY != NULL)
242 RS_DIALOGFACTORY->requestOptions(this, false);
245 void RS_ActionDrawArcTangential::updateMouseButtonHints()
250 RS_DIALOGFACTORY->updateMouseWidget(
251 tr("Specify base entity"),
256 RS_DIALOGFACTORY->updateMouseWidget(
257 tr("Specify end angle"), tr("Back"));
261 RS_DIALOGFACTORY->updateMouseWidget("", "");
266 void RS_ActionDrawArcTangential::updateMouseCursor()
268 graphicView->setMouseCursor(RS2::CadCursor);
271 void RS_ActionDrawArcTangential::updateToolBar()
274 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
276 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
279 void RS_ActionDrawArcTangential::setRadius(double r)
284 double RS_ActionDrawArcTangential::getRadius()