X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawarctangential.cpp;h=1f639dce1989cc21067ffc02fb8b43f68735da35;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=809510468375f980068b3cc86d569fce1017d3ac;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawarctangential.cpp b/src/actions/rs_actiondrawarctangential.cpp index 8095104..1f639dc 100644 --- a/src/actions/rs_actiondrawarctangential.cpp +++ b/src/actions/rs_actiondrawarctangential.cpp @@ -1,295 +1,287 @@ -/**************************************************************************** -** $Id: rs_actiondrawarctangential.cpp 1161 2004-12-09 23:10:09Z 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_actiondrawarctangential.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_actiondrawarctangential.h" -#include "commands.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw arcs tangential", - container, graphicView) { - reset(); +RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs tangential", + container, graphicView) +{ + reset(); } - - -RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential() {} - - -QAction* RS_ActionDrawArcTangential::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential() { - QAction * action = new QAction(tr("&Tangential"), 0); -// QAction* action = new QAction(tr("Arc: Tangential"), -// tr("&Tangential"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw arcs tangential to base entity")); - return action; } - -void RS_ActionDrawArcTangential::reset() { - baseEntity = NULL; - isStartPoint = false; - point = Vector(false); +/*virtual*/ RS2::ActionType RS_ActionDrawArcTangential::rtti() +{ + return RS2::ActionDrawArcTangential; } - - -void RS_ActionDrawArcTangential::init(int status) { - RS_PreviewActionInterface::init(status); - - //reset(); +void RS_ActionDrawArcTangential::reset() +{ + baseEntity = NULL; + isStartPoint = false; + point = Vector(false); } - - -void RS_ActionDrawArcTangential::trigger() { - RS_PreviewActionInterface::trigger(); - - if (point.valid==false || baseEntity==NULL) { - RS_DEBUG->print("RS_ActionDrawArcTangential::trigger: " - "conditions not met"); - return; - } - - preparePreview(); - RS_Arc* arc = new RS_Arc(container, data); - arc->setLayerToActive(); - arc->setPenToActive(); - container->addEntity(arc); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(arc); - document->endUndoCycle(); - } - - deleteSnapper(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(arc); - graphicView->moveRelativeZero(arc->getCenter()); - drawSnapper(); - - setStatus(SetBaseEntity); - reset(); +void RS_ActionDrawArcTangential::init(int status) +{ + RS_PreviewActionInterface::init(status); + //reset(); } - - -void RS_ActionDrawArcTangential::preparePreview() { - if (baseEntity!=NULL && point.valid) { - Vector startPoint; - double direction; - if (isStartPoint) { - startPoint = baseEntity->getStartpoint(); - direction = RS_Math::correctAngle(baseEntity->getDirection1()+M_PI); - } else { - startPoint = baseEntity->getEndpoint(); - direction = RS_Math::correctAngle(baseEntity->getDirection2()+M_PI); - } - - RS_Arc arc(NULL, RS_ArcData()); - bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius); - if (suc) { - data = arc.getData(); - } - } +void RS_ActionDrawArcTangential::trigger() +{ + RS_PreviewActionInterface::trigger(); + + if (point.valid == false || baseEntity == NULL) + { + RS_DEBUG->print("RS_ActionDrawArcTangential::trigger: " + "conditions not met"); + return; + } + + preparePreview(); + RS_Arc * arc = new RS_Arc(container, data); + arc->setLayerToActive(); + arc->setPenToActive(); + container->addEntity(arc); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(arc); + document->endUndoCycle(); + } + + deleteSnapper(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(arc); + graphicView->moveRelativeZero(arc->getCenter()); + drawSnapper(); + + setStatus(SetBaseEntity); + reset(); } - -void RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent* e) { - switch (getStatus()) { - case SetBaseEntity: - break; - - case SetEndAngle: { - point = snapPoint(e); - preparePreview(); - if (data.isValid()) { - RS_Arc* arc = new RS_Arc(preview, data); - deletePreview(); - clearPreview(); - preview->addEntity(arc); - drawPreview(); - } - } - break; - - default: - break; - } +void RS_ActionDrawArcTangential::preparePreview() +{ + if (baseEntity != NULL && point.valid) + { + Vector startPoint; + double direction; + + if (isStartPoint) + { + startPoint = baseEntity->getStartpoint(); + direction = RS_Math::correctAngle(baseEntity->getDirection1() + M_PI); + } + else + { + startPoint = baseEntity->getEndpoint(); + direction = RS_Math::correctAngle(baseEntity->getDirection2() + M_PI); + } + + RS_Arc arc(NULL, RS_ArcData()); + bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius); + + if (suc) + data = arc.getData(); + } } - - -void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - - // set base entity: - case SetBaseEntity: { - Vector coord = graphicView->toGraph(e->x(), e->y()); - RS_Entity* entity = catchEntity(coord, RS2::ResolveAll); - if (entity!=NULL) { - if (entity->isAtomic()) { - baseEntity = (RS_AtomicEntity*)entity; - if (baseEntity->getStartpoint().distanceTo(coord) < - baseEntity->getEndpoint().distanceTo(coord)) { - isStartPoint = true; - } else { - isStartPoint = false; - } - setStatus(SetEndAngle); - updateMouseButtonHints(); - } else { - // TODO: warning - } - } - else { - deleteSnapper(); - } - } - break; - - // set angle (point that defines the angle) - case SetEndAngle: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e) +{ + switch (getStatus()) + { + case SetBaseEntity: + break; + + case SetEndAngle: + point = snapPoint(e); + preparePreview(); + + if (data.isValid()) + { + RS_Arc * arc = new RS_Arc(preview, data); + deletePreview(); + clearPreview(); + preview->addEntity(arc); + drawPreview(); + } + break; + + default: + break; + } } +void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::LeftButton) + { + switch (getStatus()) + { + // set base entity: + case SetBaseEntity: { + Vector coord = graphicView->toGraph(e->x(), e->y()); + RS_Entity * entity = catchEntity(coord, RS2::ResolveAll); + + if (entity != NULL) + { + if (entity->isAtomic()) + { + baseEntity = (RS_AtomicEntity *)entity; + + if (baseEntity->getStartpoint().distanceTo(coord) + < baseEntity->getEndpoint().distanceTo(coord)) + isStartPoint = true; + else + isStartPoint = false; + setStatus(SetEndAngle); + updateMouseButtonHints(); + } + else + { + // TODO: warning + } + } + else + deleteSnapper(); + } + break; + + // set angle (point that defines the angle) + case SetEndAngle: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + } + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } +} +void RS_ActionDrawArcTangential::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; -void RS_ActionDrawArcTangential::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - Vector mouse = e->getCoordinate(); + Vector mouse = *e; - switch (getStatus()) { - case SetBaseEntity: - break; + switch (getStatus()) + { + case SetBaseEntity: + break; - case SetEndAngle: - point = mouse; - trigger(); - break; + case SetEndAngle: + point = mouse; + trigger(); + break; - default: - break; - } + default: + break; + } } - - -void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } +void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } } - - -QStringList RS_ActionDrawArcTangential::getAvailableCommands() { - QStringList cmd; - return cmd; +QStringList RS_ActionDrawArcTangential::getAvailableCommands() +{ + QStringList cmd; + return cmd; } +void RS_ActionDrawArcTangential::showOptions() +{ + RS_ActionInterface::showOptions(); -void RS_ActionDrawArcTangential::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } - updateMouseButtonHints(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); + updateMouseButtonHints(); } +void RS_ActionDrawArcTangential::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawArcTangential::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawArcTangential::updateMouseButtonHints() { - switch (getStatus()) { - case SetBaseEntity: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify base entity"), - tr("Cancel")); - break; - case SetEndAngle: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify end angle"), tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDrawArcTangential::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetBaseEntity: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify base entity"), + tr("Cancel")); + break; + + case SetEndAngle: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify end angle"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionDrawArcTangential::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawArcTangential::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawArcTangential::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs); - } +void RS_ActionDrawArcTangential::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs); } +void RS_ActionDrawArcTangential::setRadius(double r) +{ + data.radius = r; +} -// EOF +double RS_ActionDrawArcTangential::getRadius() +{ + return data.radius; +}