1 /****************************************************************************
2 ** $Id: rs_actiondrawcircle.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actiondrawcircle.h"
29 #include "rs_snapper.h"
31 RS_ActionDrawCircle::RS_ActionDrawCircle(RS_EntityContainer & container,
32 RS_GraphicView & graphicView):
33 RS_PreviewActionInterface("Draw circles", container, graphicView)
38 RS_ActionDrawCircle::~RS_ActionDrawCircle() {}
40 QAction * RS_ActionDrawCircle::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
42 QAction * action = new QAction(tr("Center, &Point"), 0);
43 // QAction* action = new QAction(tr("Circle: Center, Point"),
44 // tr("Center, &Point"),
45 // QKeySequence(), NULL);
46 action->setStatusTip(tr("Draw circles with center and point"));
50 void RS_ActionDrawCircle::reset()
52 data = RS_CircleData(Vector(false), 0.0);
57 void RS_ActionDrawCircle::init(int status) {
58 RS_PreviewActionInterface::init(status);
65 void RS_ActionDrawCircle::trigger() {
66 RS_PreviewActionInterface::trigger();
68 RS_Circle* circle = new RS_Circle(container,
70 circle->setLayerToActive();
71 circle->setPenToActive();
72 container->addEntity(circle);
76 document->startUndoCycle();
77 document->addUndoable(circle);
78 document->endUndoCycle();
81 Vector rz = graphicView->getRelativeZero();
82 graphicView->moveRelativeZero(Vector(0.0,0.0));
83 graphicView->drawEntity(circle);
84 graphicView->moveRelativeZero(circle->getCenter());
90 RS_DEBUG->print("RS_ActionDrawCircle::trigger(): circle added: %d",
96 void RS_ActionDrawCircle::mouseMoveEvent(QMouseEvent* e) {
97 RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent begin");
99 Vector mouse = snapPoint(e);
100 switch (getStatus()) {
106 if (data.center.valid) {
107 data.radius = data.center.distanceTo(mouse);
110 preview->addEntity(new RS_Circle(preview,
117 RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent end");
122 void RS_ActionDrawCircle::mouseReleaseEvent(QMouseEvent* e) {
123 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
124 RS_CoordinateEvent ce(snapPoint(e));
125 coordinateEvent(&ce);
126 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
135 void RS_ActionDrawCircle::coordinateEvent(RS_CoordinateEvent* e) {
140 Vector mouse = e->getCoordinate();
142 switch (getStatus()) {
145 graphicView->moveRelativeZero(mouse);
146 setStatus(SetRadius);
150 if (data.center.valid) {
151 graphicView->moveRelativeZero(mouse);
152 data.radius = data.center.distanceTo(mouse);
155 //setStatus(SetCenter);
165 void RS_ActionDrawCircle::commandEvent(RS_CommandEvent* e) {
166 QString c = e->getCommand().toLower();
168 if (checkCommand("help", c)) {
169 if (RS_DIALOGFACTORY!=NULL) {
170 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
171 + getAvailableCommands().join(", "));
176 switch (getStatus()) {
180 double r = RS_Math::eval(c, &ok);
184 if (RS_DIALOGFACTORY!=NULL) {
185 RS_DIALOGFACTORY->commandMessage(
186 tr("Not a valid expression"));
190 //setStatus(SetCenter);
201 QStringList RS_ActionDrawCircle::getAvailableCommands() {
207 void RS_ActionDrawCircle::updateMouseButtonHints() {
208 switch (getStatus()) {
210 if (RS_DIALOGFACTORY!=NULL) {
211 RS_DIALOGFACTORY->updateMouseWidget(
212 tr("Specify center"), tr("Cancel"));
216 if (RS_DIALOGFACTORY!=NULL) {
217 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back"));
221 if (RS_DIALOGFACTORY!=NULL) {
222 RS_DIALOGFACTORY->updateMouseWidget("", "");
230 void RS_ActionDrawCircle::showOptions() {
231 RS_ActionInterface::showOptions();
236 void RS_ActionDrawCircle::hideOptions() {
237 RS_ActionInterface::hideOptions();
242 void RS_ActionDrawCircle::updateMouseCursor() {
243 graphicView->setMouseCursor(RS2::CadCursor);
248 void RS_ActionDrawCircle::updateToolBar() {
250 if (RS_DIALOGFACTORY!=NULL) {
251 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
254 if (RS_DIALOGFACTORY!=NULL) {
255 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);