1 // rs_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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
15 #include "rs_actiondrawcircle2p.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDrawCircle2P::RS_ActionDrawCircle2P(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw circles",
23 container, graphicView)
28 RS_ActionDrawCircle2P::~RS_ActionDrawCircle2P()
32 void RS_ActionDrawCircle2P::reset()
35 point1 = Vector(false);
36 point2 = Vector(false);
39 void RS_ActionDrawCircle2P::init(int status)
41 RS_PreviewActionInterface::init(status);
46 void RS_ActionDrawCircle2P::trigger()
48 RS_PreviewActionInterface::trigger();
54 RS_Circle * circle = new RS_Circle(container, data);
55 circle->setLayerToActive();
56 circle->setPenToActive();
57 container->addEntity(circle);
62 document->startUndoCycle();
63 document->addUndoable(circle);
64 document->endUndoCycle();
68 Vector rz = graphicView->getRelativeZero();
69 graphicView->moveRelativeZero(Vector(0.0, 0.0));
70 graphicView->drawEntity(circle);
71 graphicView->moveRelativeZero(rz);
77 else if (RS_DIALOGFACTORY != NULL)
78 RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data."));
81 void RS_ActionDrawCircle2P::preparePreview()
85 if (point1.valid && point2.valid)
87 RS_Circle circle(NULL, data);
88 bool suc = circle.createFrom2P(point1, point2);
91 data = circle.getData();
95 void RS_ActionDrawCircle2P::mouseMoveEvent(QMouseEvent * e)
97 Vector mouse = snapPoint(e);
111 RS_Circle * circle = new RS_Circle(preview, data);
114 preview->addEntity(circle);
124 void RS_ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e)
126 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
127 if (e->button() == Qt::LeftButton)
129 Vector ce(snapPoint(e));
130 coordinateEvent(&ce);
132 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
133 else if (e->button() == Qt::RightButton)
137 init(getStatus() - 1);
141 void RS_ActionDrawCircle2P::coordinateEvent(Vector * e)
152 graphicView->moveRelativeZero(mouse);
153 setStatus(SetPoint2);
158 graphicView->moveRelativeZero(mouse);
167 void RS_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 RS_ActionDrawCircle2P::getAvailableCommands()
186 void RS_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 RS_ActionDrawCircle2P::updateMouseCursor()
211 graphicView->setMouseCursor(RS2::CadCursor);
214 void RS_ActionDrawCircle2P::updateToolBar()
216 if (RS_DIALOGFACTORY != NULL)
219 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
221 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);