X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawarc.cpp;h=e47f1bd23e526d803acd9e4ba67f125cefa03c1e;hb=be33e866f2121c48db93e06d743c5ae3826c1948;hp=2064d718c1f5c9f3fa8c6d18c9ba796cab184302;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawarc.cpp b/src/actions/rs_actiondrawarc.cpp index 2064d71..e47f1bd 100644 --- a/src/actions/rs_actiondrawarc.cpp +++ b/src/actions/rs_actiondrawarc.cpp @@ -1,55 +1,35 @@ -/**************************************************************************** -** $Id: rs_actiondrawarc.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_actiondrawarc.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_actiondrawarc.h" +#include "rs_commandevent.h" #include "commands.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "graphicview.h" +#include "rs_preview.h" -RS_ActionDrawArc::RS_ActionDrawArc(RS_EntityContainer & container, RS_GraphicView & graphicView): +RS_ActionDrawArc::RS_ActionDrawArc(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs", container, graphicView) { - reset(); + reset(); } RS_ActionDrawArc::~RS_ActionDrawArc() { } -QAction * RS_ActionDrawArc::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&Center, Point, Angles"), 0); -// QAction* action = new QAction(tr("Arc: Center, Point, Angles"), -// tr("&Center, Point, Angles"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw arcs")); - return action; -} - RS2::ActionType RS_ActionDrawArc::rtti() { return RS2::ActionDrawArc; @@ -112,6 +92,7 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) break; case SetRadius: + if (data.center.valid) { data.radius = data.center.distanceTo(mouse); @@ -155,6 +136,7 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) case SetChordLength: { double x = data.center.distanceTo(mouse); + if (fabs(x / (2 * data.radius)) <= 1.0) { data.angle2 = data.angle1 + asin(x / (2 * data.radius)) * 2; @@ -164,11 +146,10 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) drawPreview(); } } - break; + break; default: break; - } RS_DEBUG->print("RS_ActionDrawArc::mouseMoveEvent end"); @@ -176,12 +157,12 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) void RS_ActionDrawArc::mouseReleaseEvent(QMouseEvent * e) { - if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (e->button() == Qt::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } - else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + else if (e->button() == Qt::RightButton) { deletePreview(); deleteSnapper(); @@ -189,45 +170,46 @@ void RS_ActionDrawArc::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawArc::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawArc::coordinateEvent(Vector * e) { - if (e == NULL) - return; + if (e == NULL) + return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; - switch (getStatus()) + switch (getStatus()) { - case SetCenter: - data.center = mouse; - graphicView->moveRelativeZero(mouse); - //deleteSnapper(); - setStatus(SetRadius); - break; + case SetCenter: + data.center = mouse; + graphicView->moveRelativeZero(mouse); + //deleteSnapper(); + setStatus(SetRadius); + break; - case SetRadius: - if (data.center.valid) - data.radius = data.center.distanceTo(mouse); + case SetRadius: + + if (data.center.valid) + data.radius = data.center.distanceTo(mouse); setStatus(SetAngle1); - break; + break; - case SetAngle1: - data.angle1 = data.center.angleTo(mouse); - setStatus(SetAngle2); - break; + case SetAngle1: + data.angle1 = data.center.angleTo(mouse); + setStatus(SetAngle2); + break; - case SetAngle2: - data.angle2 = data.center.angleTo(mouse); - trigger(); - break; + case SetAngle2: + data.angle2 = data.center.angleTo(mouse); + trigger(); + break; - case SetIncAngle: - data.angle2 = data.angle1 + data.center.angleTo(mouse); - trigger(); - break; + case SetIncAngle: + data.angle2 = data.angle1 + data.center.angleTo(mouse); + trigger(); + break; - case SetChordLength: + case SetChordLength: { double x = data.center.distanceTo(mouse); @@ -237,187 +219,199 @@ void RS_ActionDrawArc::coordinateEvent(RS_CoordinateEvent * e) trigger(); } } - break; + break; - default: - break; - } + default: + break; + } } void RS_ActionDrawArc::commandEvent(RS_CommandEvent * e) { - QString c = e->getCommand().toLower(); - - if (RS_COMMANDS->checkCommand("help", c)) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - } - return; - } - - if (RS_COMMANDS->checkCommand("reversed", c)) { - e->accept(); - setReversed(!isReversed()); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - return; - } - - switch (getStatus()) { - - case SetRadius: { - bool ok; - double r = RS_Math::eval(c, &ok); - if (ok==true) { - data.radius = r; - setStatus(SetAngle1); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetAngle1: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle1 = RS_Math::deg2rad(a); - setStatus(SetAngle2); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetAngle2: { - if (RS_COMMANDS->checkCommand("angle", c)) { - setStatus(SetIncAngle); - } else if (RS_COMMANDS->checkCommand("chord length", c)) { - setStatus(SetChordLength); - } else { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle2 = RS_Math::deg2rad(a); - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - } - break; - - case SetIncAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle2 = data.angle1 + RS_Math::deg2rad(a); - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetChordLength: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - if (fabs(l/(2*data.radius))<=1.0) { - data.angle2 = data.angle1 + asin(l/(2*data.radius)) * 2; - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage( - tr("Not a valid chord length")); - } - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - default: - break; - } + QString c = e->getCommand().toLower(); + + if (RS_COMMANDS->checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + if (RS_COMMANDS->checkCommand("reversed", c)) + { + e->accept(); + setReversed(!isReversed()); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + return; + } + + switch (getStatus()) + { + case SetRadius: { + bool ok; + double r = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.radius = r; + setStatus(SetAngle1); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetAngle1: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.angle1 = RS_Math::deg2rad(a); + setStatus(SetAngle2); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetAngle2: + + if (RS_COMMANDS->checkCommand("angle", c)) + setStatus(SetIncAngle); + else if (RS_COMMANDS->checkCommand("chord length", c)) + setStatus(SetChordLength); + else + { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.angle2 = RS_Math::deg2rad(a); + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetIncAngle: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.angle2 = data.angle1 + RS_Math::deg2rad(a); + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetChordLength: { + bool ok; + double l = RS_Math::eval(c, &ok); + + if (ok == true) + { + if (fabs(l / (2 * data.radius)) <= 1.0) + { + data.angle2 = data.angle1 + asin(l / (2 * data.radius)) * 2; + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage( + tr("Not a valid chord length")); + + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + default: + break; + } } QStringList RS_ActionDrawArc::getAvailableCommands() { - QStringList cmd; - cmd += RS_COMMANDS->command("reversed"); - return cmd; + QStringList cmd; + cmd += RS_COMMANDS->command("reversed"); + return cmd; } void RS_ActionDrawArc::updateMouseButtonHints() { - if (RS_DIALOGFACTORY != NULL) + if (RS_DIALOGFACTORY != NULL) { - switch (getStatus()) + switch (getStatus()) { - case SetCenter: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel")); - break; - case SetRadius: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); - break; - case SetAngle1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify start angle:"), tr("Back")); - break; - case SetAngle2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify end angle or [Angle/chord Length]"), - tr("Back")); - break; - case SetIncAngle: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify included angle:"), - tr("Back")); - break; - case SetChordLength: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify chord length:"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } + case SetCenter: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel")); + break; + + case SetRadius: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); + break; + + case SetAngle1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify start angle:"), tr("Back")); + break; + + case SetAngle2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify end angle or [Angle/chord Length]"), + tr("Back")); + break; + + case SetIncAngle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify included angle:"), + tr("Back")); + break; + + case SetChordLength: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify chord length:"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } void RS_ActionDrawArc::showOptions() { - RS_ActionInterface::showOptions(); + RS_ActionInterface::showOptions(); - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->requestOptions(this, true); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } void RS_ActionDrawArc::hideOptions() { - RS_ActionInterface::hideOptions(); + RS_ActionInterface::hideOptions(); - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->requestOptions(this, false); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } void RS_ActionDrawArc::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + graphicView->setMouseCursor(RS2::CadCursor); } void RS_ActionDrawArc::updateToolBar() @@ -440,3 +434,4 @@ void RS_ActionDrawArc::setReversed(bool r) { data.reversed = r; } +