1 // actiondrawcirclecr.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 "actiondrawcirclecr.h"
20 #include "commandevent.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
29 ActionDrawCircleCR::ActionDrawCircleCR(EntityContainer & container,
30 GraphicView & graphicView):
31 ActionInterface("Draw circles CR", container, graphicView)
36 ActionDrawCircleCR::~ActionDrawCircleCR()
40 /*virtual*/ RS2::ActionType ActionDrawCircleCR::rtti()
42 return RS2::ActionDrawCircleCR;
45 void ActionDrawCircleCR::reset()
47 data = CircleData(Vector(false), 0.0);
50 void ActionDrawCircleCR::init(int status)
52 ActionInterface::init(status);
55 void ActionDrawCircleCR::trigger()
57 ActionInterface::trigger();
59 Circle * circle = new Circle(container, data);
60 circle->setLayerToActive();
61 circle->setPenToActive();
62 container->addEntity(circle);
67 document->startUndoCycle();
68 document->addUndoable(circle);
69 document->endUndoCycle();
73 // Vector rz = graphicView->getRelativeZero();
74 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
75 // graphicView->drawEntity(circle);
76 // graphicView->moveRelativeZero(circle->getCenter());
78 graphicView->preview.clear(); // hm.
79 graphicView->redraw();
83 DEBUG->print("ActionDrawCircleCR::trigger(): circle added: %d", circle->getId());
86 void ActionDrawCircleCR::mouseMoveEvent(QMouseEvent * e)
88 DEBUG->print("ActionDrawCircleCR::mouseMoveEvent begin");
89 Vector mouse = snapPoint(e);
97 // preview->addEntity(new Circle(preview, data));
99 graphicView->preview.clear();
100 graphicView->preview.addEntity(new Circle(&(graphicView->preview), data));
104 graphicView->redraw();
105 DEBUG->print("ActionDrawCircleCR::mouseMoveEvent end");
108 void ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent * e)
110 if (e->button() == Qt::LeftButton)
112 Vector ce(snapPoint(e));
113 coordinateEvent(&ce);
115 else if (e->button() == Qt::RightButton)
119 init(getStatus() - 1);
120 graphicView->redraw(); // hm.
124 void ActionDrawCircleCR::coordinateEvent(Vector * e)
143 void ActionDrawCircleCR::commandEvent(CommandEvent * e)
145 QString c = e->getCommand().toLower();
147 if (checkCommand("help", c))
149 DIALOGFACTORY->commandMessage(msgAvailableCommands()
150 + getAvailableCommands().join(", "));
158 if (checkCommand("radius", c))
163 setStatus(SetRadius);
170 double r = Math::eval(c, &ok);
175 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
177 DIALOGFACTORY->requestOptions(this, true, true);
178 setStatus(SetCenter);
187 QStringList ActionDrawCircleCR::getAvailableCommands()
194 cmd += command("radius");
204 void ActionDrawCircleCR::updateMouseButtonHints()
209 DIALOGFACTORY->updateMouseWidget(tr("Specify circle center"), tr("Cancel"));
213 DIALOGFACTORY->updateMouseWidget(tr("Specify circle radius"), tr("Back"));
217 DIALOGFACTORY->updateMouseWidget("", "");
222 void ActionDrawCircleCR::showOptions()
224 ActionInterface::showOptions();
226 DIALOGFACTORY->requestOptions(this, true);
229 void ActionDrawCircleCR::hideOptions()
231 ActionInterface::hideOptions();
233 DIALOGFACTORY->requestOptions(this, false);
236 void ActionDrawCircleCR::updateMouseCursor()
238 graphicView->setMouseCursor(RS2::CadCursor);
241 void ActionDrawCircleCR::updateToolBar()
244 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
246 DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);
249 double ActionDrawCircleCR::getRadius()
254 void ActionDrawCircleCR::setRadius(double r)