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. :-)
15 // JLH 09/17/2010 Fixed preview/snapper rendering.
18 #include "actiondrawarctangential.h"
20 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawArcTangential::ActionDrawArcTangential(EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw arcs tangential", container, graphicView)
32 ActionDrawArcTangential::~ActionDrawArcTangential()
36 /*virtual*/ RS2::ActionType ActionDrawArcTangential::rtti()
38 return RS2::ActionDrawArcTangential;
41 void ActionDrawArcTangential::reset()
45 point = Vector(false);
48 void ActionDrawArcTangential::init(int status)
50 ActionInterface::init(status);
54 void ActionDrawArcTangential::trigger()
56 ActionInterface::trigger();
58 if (point.valid == false || baseEntity == NULL)
60 DEBUG->print("ActionDrawArcTangential::trigger: "
61 "conditions not met");
66 Arc * arc = new Arc(container, data);
67 arc->setLayerToActive();
68 arc->setPenToActive();
69 container->addEntity(arc);
74 document->startUndoCycle();
75 document->addUndoable(arc);
76 document->endUndoCycle();
80 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
81 // graphicView->drawEntity(arc);
82 graphicView->moveRelativeZero(arc->getCenter());
84 graphicView->redraw(); //hm.
85 setStatus(SetBaseEntity);
89 void ActionDrawArcTangential::preparePreview()
91 if (baseEntity && point.valid)
98 startPoint = baseEntity->getStartpoint();
99 direction = Math::correctAngle(baseEntity->getDirection1() + M_PI);
103 startPoint = baseEntity->getEndpoint();
104 direction = Math::correctAngle(baseEntity->getDirection2() + M_PI);
107 Arc arc(NULL, ArcData());
108 bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius);
111 data = arc.getData();
115 void ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e)
123 point = snapPoint(e);
128 // Arc * arc = new Arc(preview, data);
131 // preview->addEntity(arc);
133 graphicView->preview.clear();
134 graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
135 graphicView->redraw();
144 void ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e)
146 if (e->button() == Qt::LeftButton)
153 Vector coord = graphicView->toGraph(e->x(), e->y());
154 Entity * entity = catchEntity(coord, RS2::ResolveAll);
158 if (entity->isAtomic())
160 baseEntity = (AtomicEntity *)entity;
162 if (baseEntity->getStartpoint().distanceTo(coord)
163 < baseEntity->getEndpoint().distanceTo(coord))
166 isStartPoint = false;
167 setStatus(SetEndAngle);
168 updateMouseButtonHints();
180 // set angle (point that defines the angle)
183 Vector ce(snapPoint(e));
184 coordinateEvent(&ce);
189 else if (e->button() == Qt::RightButton)
193 init(getStatus() - 1);
194 graphicView->redraw(); //hm.
198 void ActionDrawArcTangential::coordinateEvent(Vector * e)
220 void ActionDrawArcTangential::commandEvent(CommandEvent * e)
222 QString c = e->getCommand().toLower();
224 if (checkCommand("help", c))
226 DIALOGFACTORY->commandMessage(msgAvailableCommands()
227 + getAvailableCommands().join(", "));
232 QStringList ActionDrawArcTangential::getAvailableCommands()
238 void ActionDrawArcTangential::showOptions()
240 ActionInterface::showOptions();
242 if (DIALOGFACTORY != NULL)
243 DIALOGFACTORY->requestOptions(this, true);
244 updateMouseButtonHints();
247 void ActionDrawArcTangential::hideOptions()
249 ActionInterface::hideOptions();
251 if (DIALOGFACTORY != NULL)
252 DIALOGFACTORY->requestOptions(this, false);
255 void ActionDrawArcTangential::updateMouseButtonHints()
260 DIALOGFACTORY->updateMouseWidget(
261 tr("Specify base entity"),
266 DIALOGFACTORY->updateMouseWidget(
267 tr("Specify end angle"), tr("Back"));
271 DIALOGFACTORY->updateMouseWidget("", "");
276 void ActionDrawArcTangential::updateMouseCursor()
278 graphicView->setMouseCursor(RS2::CadCursor);
281 void ActionDrawArcTangential::updateToolBar()
284 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
286 DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
289 void ActionDrawArcTangential::setRadius(double r)
294 double ActionDrawArcTangential::getRadius()