1 // actiondrawcircle3p.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/11/2010 Fixed preview/snapper rendering.
18 #include "actiondrawcircle3p.h"
20 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
25 ActionDrawCircle3P::ActionDrawCircle3P(EntityContainer & container,
26 GraphicView & graphicView):
27 ActionInterface("Draw circles", container, graphicView)
32 ActionDrawCircle3P::~ActionDrawCircle3P()
36 void ActionDrawCircle3P::reset()
39 point1 = Vector(false);
40 point2 = Vector(false);
41 point3 = Vector(false);
44 void ActionDrawCircle3P::init(int status)
46 ActionInterface::init(status);
51 void ActionDrawCircle3P::trigger()
53 ActionInterface::trigger();
58 Circle * circle = new Circle(container, data);
59 circle->setLayerToActive();
60 circle->setPenToActive();
61 container->addEntity(circle);
66 document->startUndoCycle();
67 document->addUndoable(circle);
68 document->endUndoCycle();
72 // Vector rz = graphicView->getRelativeZero();
73 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
74 // graphicView->drawEntity(circle);
75 // graphicView->moveRelativeZero(rz);
77 graphicView->preview.clear(); // hm.
78 graphicView->redraw();
84 DIALOGFACTORY->requestWarningDialog(tr("Invalid circle data."));
87 void ActionDrawCircle3P::preparePreview()
91 if (point1.valid && point2.valid && point3.valid)
93 Circle circle(NULL, data);
94 bool success = circle.createFrom3P(point1, point2, point3);
97 data = circle.getData();
101 void ActionDrawCircle3P::mouseMoveEvent(QMouseEvent * e)
103 Vector mouse = snapPoint(e);
121 // Circle * circle = new Circle(preview, data);
124 // preview->addEntity(circle);
126 graphicView->preview.clear();
127 graphicView->preview.addEntity(new Circle(&(graphicView->preview), data));
133 graphicView->redraw();
136 void ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent * e)
138 if (e->button() == Qt::LeftButton)
140 Vector ce(snapPoint(e));
141 coordinateEvent(&ce);
143 else if (e->button() == Qt::RightButton)
147 init(getStatus() - 1);
148 graphicView->redraw(); // hm.
152 void ActionDrawCircle3P::coordinateEvent(Vector * e)
163 graphicView->moveRelativeZero(mouse);
164 setStatus(SetPoint2);
169 graphicView->moveRelativeZero(mouse);
170 setStatus(SetPoint3);
183 void ActionDrawCircle3P::commandEvent(CommandEvent * e)
185 QString c = e->getCommand().toLower();
187 if (checkCommand("help", c))
189 DIALOGFACTORY->commandMessage(msgAvailableCommands()
190 + getAvailableCommands().join(", "));
195 QStringList ActionDrawCircle3P::getAvailableCommands()
201 void ActionDrawCircle3P::updateMouseButtonHints()
206 DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel"));
210 DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back"));
214 DIALOGFACTORY->updateMouseWidget(tr("Specify third point"), tr("Back"));
218 DIALOGFACTORY->updateMouseWidget("", "");
223 void ActionDrawCircle3P::updateMouseCursor()
225 graphicView->setMouseCursor(RS2::CadCursor);
228 void ActionDrawCircle3P::updateToolBar()
231 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
233 DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);