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_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs tangential",
22 container, graphicView)
27 RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential()
31 /*virtual*/ RS2::ActionType RS_ActionDrawArcTangential::rtti()
33 return RS2::ActionDrawArcTangential;
36 void RS_ActionDrawArcTangential::reset()
40 point = Vector(false);
43 void RS_ActionDrawArcTangential::init(int status)
45 RS_PreviewActionInterface::init(status);
49 void RS_ActionDrawArcTangential::trigger()
51 RS_PreviewActionInterface::trigger();
53 if (point.valid == false || baseEntity == NULL)
55 RS_DEBUG->print("RS_ActionDrawArcTangential::trigger: "
56 "conditions not met");
61 RS_Arc * arc = new RS_Arc(container, data);
62 arc->setLayerToActive();
63 arc->setPenToActive();
64 container->addEntity(arc);
69 document->startUndoCycle();
70 document->addUndoable(arc);
71 document->endUndoCycle();
75 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 graphicView->drawEntity(arc);
77 graphicView->moveRelativeZero(arc->getCenter());
80 setStatus(SetBaseEntity);
84 void RS_ActionDrawArcTangential::preparePreview()
86 if (baseEntity != NULL && point.valid)
93 startPoint = baseEntity->getStartpoint();
94 direction = RS_Math::correctAngle(baseEntity->getDirection1() + M_PI);
98 startPoint = baseEntity->getEndpoint();
99 direction = RS_Math::correctAngle(baseEntity->getDirection2() + M_PI);
102 RS_Arc arc(NULL, RS_ArcData());
103 bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius);
106 data = arc.getData();
110 void RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
118 point = snapPoint(e);
123 RS_Arc * arc = new RS_Arc(preview, data);
126 preview->addEntity(arc);
136 void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
138 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
143 case SetBaseEntity: {
144 Vector coord = graphicView->toGraph(e->x(), e->y());
145 RS_Entity * entity = catchEntity(coord, RS2::ResolveAll);
149 if (entity->isAtomic())
151 baseEntity = (RS_AtomicEntity *)entity;
153 if (baseEntity->getStartpoint().distanceTo(coord)
154 < baseEntity->getEndpoint().distanceTo(coord))
157 isStartPoint = false;
158 setStatus(SetEndAngle);
159 updateMouseButtonHints();
171 // set angle (point that defines the angle)
173 Vector ce(snapPoint(e));
174 coordinateEvent(&ce);
179 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
183 init(getStatus() - 1);
187 void RS_ActionDrawArcTangential::coordinateEvent(Vector * e)
209 void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent * e)
211 QString c = e->getCommand().toLower();
213 if (checkCommand("help", c))
215 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
216 + getAvailableCommands().join(", "));
221 QStringList RS_ActionDrawArcTangential::getAvailableCommands()
227 void RS_ActionDrawArcTangential::showOptions()
229 RS_ActionInterface::showOptions();
231 if (RS_DIALOGFACTORY != NULL)
232 RS_DIALOGFACTORY->requestOptions(this, true);
233 updateMouseButtonHints();
236 void RS_ActionDrawArcTangential::hideOptions()
238 RS_ActionInterface::hideOptions();
240 if (RS_DIALOGFACTORY != NULL)
241 RS_DIALOGFACTORY->requestOptions(this, false);
244 void RS_ActionDrawArcTangential::updateMouseButtonHints()
249 RS_DIALOGFACTORY->updateMouseWidget(
250 tr("Specify base entity"),
255 RS_DIALOGFACTORY->updateMouseWidget(
256 tr("Specify end angle"), tr("Back"));
260 RS_DIALOGFACTORY->updateMouseWidget("", "");
265 void RS_ActionDrawArcTangential::updateMouseCursor()
267 graphicView->setMouseCursor(RS2::CadCursor);
270 void RS_ActionDrawArcTangential::updateToolBar()
273 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
275 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
278 void RS_ActionDrawArcTangential::setRadius(double r)
283 double RS_ActionDrawArcTangential::getRadius()