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_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionDrawCircle2P::RS_ActionDrawCircle2P(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw circles",
22 container, graphicView)
27 RS_ActionDrawCircle2P::~RS_ActionDrawCircle2P()
31 void RS_ActionDrawCircle2P::reset()
34 point1 = Vector(false);
35 point2 = Vector(false);
38 void RS_ActionDrawCircle2P::init(int status)
40 RS_PreviewActionInterface::init(status);
45 void RS_ActionDrawCircle2P::trigger()
47 RS_PreviewActionInterface::trigger();
53 RS_Circle * circle = new RS_Circle(container, data);
54 circle->setLayerToActive();
55 circle->setPenToActive();
56 container->addEntity(circle);
61 document->startUndoCycle();
62 document->addUndoable(circle);
63 document->endUndoCycle();
67 Vector rz = graphicView->getRelativeZero();
68 graphicView->moveRelativeZero(Vector(0.0, 0.0));
69 graphicView->drawEntity(circle);
70 graphicView->moveRelativeZero(rz);
76 else if (RS_DIALOGFACTORY != NULL)
77 RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data."));
80 void RS_ActionDrawCircle2P::preparePreview()
84 if (point1.valid && point2.valid)
86 RS_Circle circle(NULL, data);
87 bool suc = circle.createFrom2P(point1, point2);
90 data = circle.getData();
94 void RS_ActionDrawCircle2P::mouseMoveEvent(QMouseEvent * e)
96 Vector mouse = snapPoint(e);
110 RS_Circle * circle = new RS_Circle(preview, data);
113 preview->addEntity(circle);
123 void RS_ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e)
125 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
126 if (e->button() == Qt::LeftButton)
128 Vector ce(snapPoint(e));
129 coordinateEvent(&ce);
131 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
132 else if (e->button() == Qt::RightButton)
136 init(getStatus() - 1);
140 void RS_ActionDrawCircle2P::coordinateEvent(Vector * e)
151 graphicView->moveRelativeZero(mouse);
152 setStatus(SetPoint2);
157 graphicView->moveRelativeZero(mouse);
166 void RS_ActionDrawCircle2P::commandEvent(RS_CommandEvent * e)
168 QString c = e->getCommand().toLower();
170 if (checkCommand("help", c))
172 if (RS_DIALOGFACTORY != NULL)
173 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
174 + getAvailableCommands().join(", "));
179 QStringList RS_ActionDrawCircle2P::getAvailableCommands()
185 void RS_ActionDrawCircle2P::updateMouseButtonHints()
187 if (RS_DIALOGFACTORY != NULL)
192 RS_DIALOGFACTORY->updateMouseWidget(
193 tr("Specify first point"), tr("Cancel"));
197 RS_DIALOGFACTORY->updateMouseWidget(
198 tr("Specify second point"), tr("Back"));
202 RS_DIALOGFACTORY->updateMouseWidget("", "");
208 void RS_ActionDrawCircle2P::updateMouseCursor()
210 graphicView->setMouseCursor(RS2::CadCursor);
213 void RS_ActionDrawCircle2P::updateToolBar()
215 if (RS_DIALOGFACTORY != NULL)
218 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
220 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);