1 // actiondrawcircle2p.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. :-)
17 #include "actiondrawcircle2p.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDrawCircle2P::ActionDrawCircle2P(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw circles",
25 container, graphicView)
30 ActionDrawCircle2P::~ActionDrawCircle2P()
34 void ActionDrawCircle2P::reset()
37 point1 = Vector(false);
38 point2 = Vector(false);
41 void ActionDrawCircle2P::init(int status)
43 ActionInterface::init(status);
48 void ActionDrawCircle2P::trigger()
50 ActionInterface::trigger();
56 RS_Circle * circle = new RS_Circle(container, data);
57 circle->setLayerToActive();
58 circle->setPenToActive();
59 container->addEntity(circle);
64 document->startUndoCycle();
65 document->addUndoable(circle);
66 document->endUndoCycle();
70 Vector rz = graphicView->getRelativeZero();
71 graphicView->moveRelativeZero(Vector(0.0, 0.0));
72 graphicView->drawEntity(circle);
73 graphicView->moveRelativeZero(rz);
79 else if (RS_DIALOGFACTORY != NULL)
80 RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data."));
83 void ActionDrawCircle2P::preparePreview()
87 if (point1.valid && point2.valid)
89 RS_Circle circle(NULL, data);
90 bool suc = circle.createFrom2P(point1, point2);
93 data = circle.getData();
97 void ActionDrawCircle2P::mouseMoveEvent(QMouseEvent * e)
99 Vector mouse = snapPoint(e);
113 // RS_Circle * circle = new RS_Circle(preview, data);
116 // preview->addEntity(circle);
126 void ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e)
128 if (e->button() == Qt::LeftButton)
130 Vector ce(snapPoint(e));
131 coordinateEvent(&ce);
133 else if (e->button() == Qt::RightButton)
137 init(getStatus() - 1);
141 void ActionDrawCircle2P::coordinateEvent(Vector * e)
152 graphicView->moveRelativeZero(mouse);
153 setStatus(SetPoint2);
158 graphicView->moveRelativeZero(mouse);
167 void ActionDrawCircle2P::commandEvent(RS_CommandEvent * e)
169 QString c = e->getCommand().toLower();
171 if (checkCommand("help", c))
173 if (RS_DIALOGFACTORY != NULL)
174 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
175 + getAvailableCommands().join(", "));
180 QStringList ActionDrawCircle2P::getAvailableCommands()
186 void ActionDrawCircle2P::updateMouseButtonHints()
188 if (RS_DIALOGFACTORY != NULL)
193 RS_DIALOGFACTORY->updateMouseWidget(
194 tr("Specify first point"), tr("Cancel"));
198 RS_DIALOGFACTORY->updateMouseWidget(
199 tr("Specify second point"), tr("Back"));
203 RS_DIALOGFACTORY->updateMouseWidget("", "");
209 void ActionDrawCircle2P::updateMouseCursor()
211 graphicView->setMouseCursor(RS2::CadCursor);
214 void ActionDrawCircle2P::updateToolBar()
216 if (RS_DIALOGFACTORY)
219 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
221 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);