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 "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
25 ActionDrawArcTangential::ActionDrawArcTangential(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw arcs tangential",
26 container, graphicView)
31 ActionDrawArcTangential::~ActionDrawArcTangential()
35 /*virtual*/ RS2::ActionType ActionDrawArcTangential::rtti()
37 return RS2::ActionDrawArcTangential;
40 void ActionDrawArcTangential::reset()
44 point = Vector(false);
47 void ActionDrawArcTangential::init(int status)
49 ActionInterface::init(status);
53 void ActionDrawArcTangential::trigger()
55 ActionInterface::trigger();
57 if (point.valid == false || baseEntity == NULL)
59 DEBUG->print("ActionDrawArcTangential::trigger: "
60 "conditions not met");
65 Arc * arc = new Arc(container, data);
66 arc->setLayerToActive();
67 arc->setPenToActive();
68 container->addEntity(arc);
73 document->startUndoCycle();
74 document->addUndoable(arc);
75 document->endUndoCycle();
79 graphicView->moveRelativeZero(Vector(0.0, 0.0));
80 graphicView->drawEntity(arc);
81 graphicView->moveRelativeZero(arc->getCenter());
84 setStatus(SetBaseEntity);
88 void ActionDrawArcTangential::preparePreview()
90 if (baseEntity != NULL && point.valid)
97 startPoint = baseEntity->getStartpoint();
98 direction = Math::correctAngle(baseEntity->getDirection1() + M_PI);
102 startPoint = baseEntity->getEndpoint();
103 direction = Math::correctAngle(baseEntity->getDirection2() + M_PI);
106 Arc arc(NULL, ArcData());
107 bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius);
110 data = arc.getData();
114 void ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
122 point = snapPoint(e);
127 // Arc * arc = new Arc(preview, data);
130 // preview->addEntity(arc);
140 void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
142 if (e->button() == Qt::LeftButton)
149 Vector coord = graphicView->toGraph(e->x(), e->y());
150 Entity * entity = catchEntity(coord, RS2::ResolveAll);
154 if (entity->isAtomic())
156 baseEntity = (AtomicEntity *)entity;
158 if (baseEntity->getStartpoint().distanceTo(coord)
159 < baseEntity->getEndpoint().distanceTo(coord))
162 isStartPoint = false;
163 setStatus(SetEndAngle);
164 updateMouseButtonHints();
176 // set angle (point that defines the angle)
179 Vector ce(snapPoint(e));
180 coordinateEvent(&ce);
185 else if (e->button() == Qt::RightButton)
189 init(getStatus() - 1);
193 void ActionDrawArcTangential::coordinateEvent(Vector * e)
215 void ActionDrawArcTangential::commandEvent(CommandEvent * e)
217 QString c = e->getCommand().toLower();
219 if (checkCommand("help", c))
221 DIALOGFACTORY->commandMessage(msgAvailableCommands()
222 + getAvailableCommands().join(", "));
227 QStringList ActionDrawArcTangential::getAvailableCommands()
233 void ActionDrawArcTangential::showOptions()
235 ActionInterface::showOptions();
237 if (DIALOGFACTORY != NULL)
238 DIALOGFACTORY->requestOptions(this, true);
239 updateMouseButtonHints();
242 void ActionDrawArcTangential::hideOptions()
244 ActionInterface::hideOptions();
246 if (DIALOGFACTORY != NULL)
247 DIALOGFACTORY->requestOptions(this, false);
250 void ActionDrawArcTangential::updateMouseButtonHints()
255 DIALOGFACTORY->updateMouseWidget(
256 tr("Specify base entity"),
261 DIALOGFACTORY->updateMouseWidget(
262 tr("Specify end angle"), tr("Back"));
266 DIALOGFACTORY->updateMouseWidget("", "");
271 void ActionDrawArcTangential::updateMouseCursor()
273 graphicView->setMouseCursor(RS2::CadCursor);
276 void ActionDrawArcTangential::updateToolBar()
279 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
281 DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
284 void ActionDrawArcTangential::setRadius(double r)
289 double ActionDrawArcTangential::getRadius()