X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawcircle.cpp;h=7b1d50be8c2fab0c995c85c4a280fe9ac43c18c7;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=1c4da96bbf5e42306c166e05ae9619d2d00f0afd;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawcircle.cpp b/src/actions/rs_actiondrawcircle.cpp index 1c4da96..7b1d50b 100644 --- a/src/actions/rs_actiondrawcircle.cpp +++ b/src/actions/rs_actiondrawcircle.cpp @@ -1,262 +1,246 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle.cpp 1134 2004-07-13 23:26:13Z andrew $ -** -** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. -** -** This file is part of the qcadlib Library project. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid qcadlib Professional Edition licenses may use -** this file in accordance with the qcadlib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ +// rs_actiondrawcircle.cpp +// +// Part of the Architektonas Project +// Originally part of QCad Community Edition by Andrew Mustun +// Extensively rewritten and refactored by James L. Hammons +// (C) 2010 Underground Software +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 06/03/2010 Added this text. :-) +// #include "rs_actiondrawcircle.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawCircle::RS_ActionDrawCircle(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawCircle::RS_ActionDrawCircle(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw circles", container, graphicView) { - reset(); + reset(); } -RS_ActionDrawCircle::~RS_ActionDrawCircle() {} - -QAction * RS_ActionDrawCircle::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionDrawCircle::~RS_ActionDrawCircle() { - QAction * action = new QAction(tr("Center, &Point"), 0); -// QAction* action = new QAction(tr("Circle: Center, Point"), -// tr("Center, &Point"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw circles with center and point")); - return action; } -void RS_ActionDrawCircle::reset() +/*virtual*/ RS2::ActionType RS_ActionDrawCircle::rtti() { - data = RS_CircleData(Vector(false), 0.0); + return RS2::ActionDrawCircle; } - - -void RS_ActionDrawCircle::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); +void RS_ActionDrawCircle::reset() +{ + data = RS_CircleData(Vector(false), 0.0); } +void RS_ActionDrawCircle::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawCircle::trigger() { - RS_PreviewActionInterface::trigger(); - - RS_Circle* circle = new RS_Circle(container, - data); - circle->setLayerToActive(); - circle->setPenToActive(); - container->addEntity(circle); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(circle); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(circle->getCenter()); - drawSnapper(); - - setStatus(SetCenter); - reset(); - - RS_DEBUG->print("RS_ActionDrawCircle::trigger(): circle added: %d", - circle->getId()); + reset(); } - - -void RS_ActionDrawCircle::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetCenter: - data.center = mouse; - break; - - case SetRadius: - if (data.center.valid) { - data.radius = data.center.distanceTo(mouse); - deletePreview(); - clearPreview(); - preview->addEntity(new RS_Circle(preview, - data)); - drawPreview(); - } - break; - } - - RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent end"); +void RS_ActionDrawCircle::trigger() +{ + RS_PreviewActionInterface::trigger(); + + RS_Circle * circle = new RS_Circle(container, data); + circle->setLayerToActive(); + circle->setPenToActive(); + container->addEntity(circle); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(circle); + document->endUndoCycle(); + } + + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(circle); + graphicView->moveRelativeZero(circle->getCenter()); + drawSnapper(); + + setStatus(SetCenter); + reset(); + + RS_DEBUG->print("RS_ActionDrawCircle::trigger(): circle added: %d", circle->getId()); } - - -void RS_ActionDrawCircle::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawCircle::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent begin"); + + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetCenter: + data.center = mouse; + break; + + case SetRadius: + + if (data.center.valid) + { + data.radius = data.center.distanceTo(mouse); + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Circle(preview, + data)); + drawPreview(); + } + break; + } + + RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent end"); } - - -void RS_ActionDrawCircle::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCenter: - data.center = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetRadius); - break; - - case SetRadius: - if (data.center.valid) { - graphicView->moveRelativeZero(mouse); - data.radius = data.center.distanceTo(mouse); - trigger(); - } - //setStatus(SetCenter); - break; - - default: - break; - } +void RS_ActionDrawCircle::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawCircle::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - } - return; - } - - switch (getStatus()) { - - case SetRadius: { - bool ok; - double r = RS_Math::eval(c, &ok); - if (ok==true) { - data.radius = r; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage( - tr("Not a valid expression")); - } - } - trigger(); - //setStatus(SetCenter); - } - break; - - default: - break; - } +void RS_ActionDrawCircle::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetCenter: + data.center = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetRadius); + break; + + case SetRadius: + + if (data.center.valid) + { + graphicView->moveRelativeZero(mouse); + data.radius = data.center.distanceTo(mouse); + trigger(); + } + //setStatus(SetCenter); + break; + + default: + break; + } } - - -QStringList RS_ActionDrawCircle::getAvailableCommands() { - QStringList cmd; - return cmd; +void RS_ActionDrawCircle::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case SetRadius: { + bool ok; + double r = RS_Math::eval(c, &ok); + + if (ok == true) + data.radius = r; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage( + tr("Not a valid expression")); + + trigger(); + //setStatus(SetCenter); + } + break; + + default: + break; + } } - -void RS_ActionDrawCircle::updateMouseButtonHints() { - switch (getStatus()) { - case SetCenter: - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify center"), tr("Cancel")); - } - break; - case SetRadius: - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); - } - break; - default: - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateMouseWidget("", ""); - } - break; - } +QStringList RS_ActionDrawCircle::getAvailableCommands() +{ + QStringList cmd; + return cmd; } +void RS_ActionDrawCircle::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetCenter: + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify center"), tr("Cancel")); + break; -void RS_ActionDrawCircle::showOptions() { - RS_ActionInterface::showOptions(); -} + case SetRadius: + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); + break; + default: -void RS_ActionDrawCircle::hideOptions() { - RS_ActionInterface::hideOptions(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDrawCircle::showOptions() +{ + RS_ActionInterface::showOptions(); +} - -void RS_ActionDrawCircle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawCircle::hideOptions() +{ + RS_ActionInterface::hideOptions(); } +void RS_ActionDrawCircle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} +void RS_ActionDrawCircle::updateToolBar() +{ + if (!isFinished()) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); -void RS_ActionDrawCircle::updateToolBar() { - if (!isFinished()) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); - } - } } - // EOF