1 /****************************************************************************
2 ** $Id: rs_actiondrawcirclecr.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_actiondrawcirclecr.h"
28 #include "rs_snapper.h"
33 RS_ActionDrawCircleCR::RS_ActionDrawCircleCR(RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Draw circles CR",
36 container, graphicView) {
43 RS_ActionDrawCircleCR::~RS_ActionDrawCircleCR() {}
46 QAction* RS_ActionDrawCircleCR::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
48 QAction * action = new QAction(tr("Center, &Radius"), 0);
49 // QAction* action = new QAction(tr("Circle: Center, Radius"),
50 // tr("Center, &Radius"),
51 // QKeySequence(), NULL);
52 action->setStatusTip(tr("Draw circles with center and radius"));
57 void RS_ActionDrawCircleCR::reset() {
58 data = RS_CircleData(Vector(false), 0.0);
63 void RS_ActionDrawCircleCR::init(int status) {
64 RS_PreviewActionInterface::init(status);
69 void RS_ActionDrawCircleCR::trigger() {
70 RS_PreviewActionInterface::trigger();
72 RS_Circle* circle = new RS_Circle(container,
74 circle->setLayerToActive();
75 circle->setPenToActive();
76 container->addEntity(circle);
80 document->startUndoCycle();
81 document->addUndoable(circle);
82 document->endUndoCycle();
85 Vector rz = graphicView->getRelativeZero();
86 graphicView->moveRelativeZero(Vector(0.0,0.0));
87 graphicView->drawEntity(circle);
88 graphicView->moveRelativeZero(circle->getCenter());
93 RS_DEBUG->print("RS_ActionDrawCircleCR::trigger(): circle added: %d",
99 void RS_ActionDrawCircleCR::mouseMoveEvent(QMouseEvent* e) {
100 RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent begin");
102 Vector mouse = snapPoint(e);
103 switch (getStatus()) {
108 preview->addEntity(new RS_Circle(preview,
114 RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent end");
119 void RS_ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent* e) {
120 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
121 RS_CoordinateEvent ce(snapPoint(e));
122 coordinateEvent(&ce);
123 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
132 void RS_ActionDrawCircleCR::coordinateEvent(RS_CoordinateEvent* e) {
137 Vector mouse = e->getCoordinate();
139 switch (getStatus()) {
152 void RS_ActionDrawCircleCR::commandEvent(RS_CommandEvent* e) {
153 QString c = e->getCommand().toLower();
155 if (checkCommand("help", c)) {
156 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
157 + getAvailableCommands().join(", "));
161 switch (getStatus()) {
163 if (checkCommand("radius", c)) {
167 setStatus(SetRadius);
173 double r = RS_Math::eval(c, &ok);
177 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
179 RS_DIALOGFACTORY->requestOptions(this, true, true);
180 setStatus(SetCenter);
191 QStringList RS_ActionDrawCircleCR::getAvailableCommands() {
194 switch (getStatus()) {
196 cmd += command("radius");
205 void RS_ActionDrawCircleCR::updateMouseButtonHints() {
206 switch (getStatus()) {
208 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle center"),
212 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle radius"),
216 RS_DIALOGFACTORY->updateMouseWidget("", "");
223 void RS_ActionDrawCircleCR::showOptions() {
224 RS_ActionInterface::showOptions();
226 RS_DIALOGFACTORY->requestOptions(this, true);
231 void RS_ActionDrawCircleCR::hideOptions() {
232 RS_ActionInterface::hideOptions();
234 RS_DIALOGFACTORY->requestOptions(this, false);
239 void RS_ActionDrawCircleCR::updateMouseCursor() {
240 graphicView->setMouseCursor(RS2::CadCursor);
245 void RS_ActionDrawCircleCR::updateToolBar() {
247 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
249 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);