-/****************************************************************************
-** $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 <jlhamm@acm.org>
+//
+// 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;
break;
case SetRadius:
+
if (data.center.valid)
{
data.radius = data.center.distanceTo(mouse);
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;
drawPreview();
}
}
- break;
+ break;
default:
break;
-
}
RS_DEBUG->print("RS_ActionDrawArc::mouseMoveEvent end");
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();
}
}
-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);
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()
{
data.reversed = r;
}
+