1 // actiondrawcircle.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 "actiondrawcircle.h"
20 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
26 ActionDrawCircle::ActionDrawCircle(EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw circles", container, graphicView)
32 ActionDrawCircle::~ActionDrawCircle()
36 /*virtual*/ RS2::ActionType ActionDrawCircle::rtti()
38 return RS2::ActionDrawCircle;
41 void ActionDrawCircle::reset()
43 data = CircleData(Vector(false), 0.0);
46 void ActionDrawCircle::init(int status)
48 ActionInterface::init(status);
53 void ActionDrawCircle::trigger()
55 ActionInterface::trigger();
57 Circle * circle = new Circle(container, data);
58 circle->setLayerToActive();
59 circle->setPenToActive();
60 container->addEntity(circle);
65 document->startUndoCycle();
66 document->addUndoable(circle);
67 document->endUndoCycle();
70 graphicView->preview.clear(); // hm.
72 // Vector rz = graphicView->getRelativeZero();
73 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
74 // graphicView->drawEntity(circle);
75 graphicView->moveRelativeZero(circle->getCenter());
77 graphicView->redraw();
82 DEBUG->print("ActionDrawCircle::trigger(): circle added: %d", circle->getId());
85 void ActionDrawCircle::mouseMoveEvent(QMouseEvent * e)
87 DEBUG->print("ActionDrawCircle::mouseMoveEvent begin");
89 Vector mouse = snapPoint(e);
98 if (data.center.valid)
100 data.radius = data.center.distanceTo(mouse);
101 graphicView->preview.clear();
102 graphicView->preview.addEntity(new Circle(&(graphicView->preview), data));
107 graphicView->redraw();
108 DEBUG->print("ActionDrawCircle::mouseMoveEvent end");
111 void ActionDrawCircle::mouseReleaseEvent(QMouseEvent * e)
113 if (e->button() == Qt::LeftButton)
115 Vector ce(snapPoint(e));
116 coordinateEvent(&ce);
118 else if (e->button() == Qt::RightButton)
122 // //Is this necessary? Or should the base class take care of this kind of crap?
123 // graphicView->preview.clear();
124 init(getStatus() - 1);
125 // Looks like we need at least to redraw... Though shouldn't base class do it???
126 graphicView->redraw();
130 void ActionDrawCircle::coordinateEvent(Vector * e)
141 graphicView->moveRelativeZero(mouse);
142 setStatus(SetRadius);
146 if (data.center.valid)
148 graphicView->moveRelativeZero(mouse);
149 data.radius = data.center.distanceTo(mouse);
160 void ActionDrawCircle::commandEvent(CommandEvent * e)
162 QString c = e->getCommand().toLower();
164 if (checkCommand("help", c))
167 DIALOGFACTORY->commandMessage(msgAvailableCommands()
168 + getAvailableCommands().join(", "));
177 double r = Math::eval(c, &ok);
181 else if (DIALOGFACTORY)
182 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
185 //setStatus(SetCenter);
194 QStringList ActionDrawCircle::getAvailableCommands()
200 void ActionDrawCircle::updateMouseButtonHints()
206 DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel"));
211 DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back"));
216 DIALOGFACTORY->updateMouseWidget("", "");
221 void ActionDrawCircle::showOptions()
223 ActionInterface::showOptions();
226 void ActionDrawCircle::hideOptions()
228 ActionInterface::hideOptions();
231 void ActionDrawCircle::updateMouseCursor()
233 graphicView->setMouseCursor(RS2::CadCursor);
236 void ActionDrawCircle::updateToolBar()
241 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
243 else if (DIALOGFACTORY)
244 DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);