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 "actiondrawarc3p.h"
20 #include "actiondrawarc.h"
21 #include "commandevent.h"
23 #include "dialogfactory.h"
24 #include "graphicview.h"
27 ActionDrawArc3P::ActionDrawArc3P(EntityContainer & container, GraphicView & graphicView):
28 ActionInterface("Draw arcs 3P", container, graphicView)
33 ActionDrawArc3P::~ActionDrawArc3P()
37 void ActionDrawArc3P::reset()
40 point1 = Vector(false);
41 point2 = Vector(false);
42 point3 = Vector(false);
45 void ActionDrawArc3P::init(int status)
47 ActionInterface::init(status);
52 void ActionDrawArc3P::trigger()
54 ActionInterface::trigger();
59 Arc * arc = new Arc(container, data);
60 arc->setLayerToActive();
61 arc->setPenToActive();
62 container->addEntity(arc);
67 document->startUndoCycle();
68 document->addUndoable(arc);
69 document->endUndoCycle();
73 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
74 // graphicView->drawEntity(arc);
75 graphicView->moveRelativeZero(arc->getEndpoint());
77 graphicView->redraw();
82 DIALOGFACTORY->commandMessage(tr("Invalid arc data."));
85 void ActionDrawArc3P::preparePreview()
89 if (point1.valid && point2.valid && point3.valid)
92 bool success = arc.createFrom3P(point1, point2, point3);
99 void ActionDrawArc3P::mouseMoveEvent(QMouseEvent * e)
101 Vector mouse = snapPoint(e);
114 // Line * line = new Line(preview, LineData(point1, point2));
118 // preview->addEntity(line);
120 graphicView->preview.clear();
121 graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(point1, point2)));
131 // Arc * arc = new Arc(preview, data);
135 // preview->addEntity(arc);
137 graphicView->preview.clear();
138 graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
146 graphicView->redraw();
149 void ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e)
151 if (e->button() == Qt::LeftButton)
153 Vector ce(snapPoint(e));
154 coordinateEvent(&ce);
156 else if (e->button() == Qt::RightButton)
160 init(getStatus() - 1);
161 graphicView->redraw();
165 void ActionDrawArc3P::coordinateEvent(Vector * e)
176 graphicView->moveRelativeZero(mouse);
177 setStatus(SetPoint2);
182 graphicView->moveRelativeZero(mouse);
183 setStatus(SetPoint3);
196 void ActionDrawArc3P::commandEvent(CommandEvent * e)
198 QString c = e->getCommand().toLower();
200 if (checkCommand("help", c))
202 DIALOGFACTORY->commandMessage(msgAvailableCommands()
203 + getAvailableCommands().join(", "));
207 if (COMMANDS->checkCommand("center", c, rtti()))
210 graphicView->setCurrentAction(new ActionDrawArc(*container, *graphicView));
214 QStringList ActionDrawArc3P::getAvailableCommands()
220 void ActionDrawArc3P::updateMouseButtonHints()
225 DIALOGFACTORY->updateMouseWidget(tr("Specify startpoint or [Center]"), tr("Cancel"));
229 DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back"));
233 DIALOGFACTORY->updateMouseWidget(tr("Specify endpoint"), tr("Back"));
237 DIALOGFACTORY->updateMouseWidget("", "");
242 void ActionDrawArc3P::updateMouseCursor()
244 graphicView->setMouseCursor(RS2::CadCursor);
247 void ActionDrawArc3P::updateToolBar()
250 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
252 DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);