X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawlinepolygon.cpp;h=c9761a634cb10b9495d4ed42c78340a81ed717cb;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=2a43957ab6ec872d0f4269a8bdaef1f2c38681c9;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawlinepolygon.cpp b/src/actions/rs_actiondrawlinepolygon.cpp index 2a43957..c9761a6 100644 --- a/src/actions/rs_actiondrawlinepolygon.cpp +++ b/src/actions/rs_actiondrawlinepolygon.cpp @@ -1,275 +1,266 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinepolygon.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_actiondrawlinepolygon.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/04/2010 Added this text. :-) +// #include "rs_actiondrawlinepolygon.h" #include "rs_creation.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" +RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons", + container, graphicView) +{ + center = Vector(false); + corner = Vector(false); - -RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Polygons", container, graphicView) { - - center = Vector(false); - corner = Vector(false); - - number = 3; + number = 3; } -QAction* RS_ActionDrawLinePolygon::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLinePolygon::~RS_ActionDrawLinePolygon() { - QAction * action = new QAction(tr("Pol&ygon (Cen,Cor)"), 0); -// QAction* action = new QAction(tr("Polygon"), tr("Pol&ygon (Cen,Cor)"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw polygon with center and corner")); - return action; } +/*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon::rtti() +{ + return RS2::ActionDrawLinePolygon; +} -void RS_ActionDrawLinePolygon::trigger() { - RS_PreviewActionInterface::trigger(); +void RS_ActionDrawLinePolygon::trigger() +{ + RS_PreviewActionInterface::trigger(); - deleteSnapper(); - deletePreview(); - clearPreview(); + deleteSnapper(); + deletePreview(); + clearPreview(); - RS_Creation creation(container, graphicView); - bool ok = creation.createPolygon(center, corner, number); + RS_Creation creation(container, graphicView); + bool ok = creation.createPolygon(center, corner, number); - if (!ok) { - RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger:" - " No polygon added\n"); - } + if (!ok) + RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger: No polygon added\n"); } +void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); + switch (getStatus()) + { + case SetCenter: + break; - switch (getStatus()) { - case SetCenter: - break; + case SetCorner: - case SetCorner: - if (center.valid) { - corner = mouse; - deletePreview(); - clearPreview(); + if (center.valid) + { + corner = mouse; + deletePreview(); + clearPreview(); - RS_Creation creation(preview, NULL, false); - creation.createPolygon(center, corner, number); + RS_Creation creation(preview, NULL, false); + creation.createPolygon(center, corner, number); - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } + default: + break; + } } - - -void RS_ActionDrawLinePolygon::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(); - clearPreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + clearPreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawLinePolygon::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCenter: - center = mouse; - setStatus(SetCorner); - graphicView->moveRelativeZero(mouse); - break; - - case SetCorner: - corner = mouse; - trigger(); - break; - - default: - break; - } +void RS_ActionDrawLinePolygon::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetCenter: + center = mouse; + setStatus(SetCorner); + graphicView->moveRelativeZero(mouse); + break; + + case SetCorner: + corner = mouse; + trigger(); + break; + + default: + break; + } } - - -void RS_ActionDrawLinePolygon::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetCenter: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), - ""); - break; - - case SetCorner: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), ""); - break; - - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); - break; - - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLinePolygon::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetCenter: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), + ""); + break; + + case SetCorner: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), ""); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLinePolygon::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLinePolygon::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawLinePolygon::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLinePolygon::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawLinePolygon::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 SetCenter: - case SetCorner: - if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetNumber); - } - break; - - case SetNumber: { - bool ok; - int n = c.toInt(&ok); - if (ok==true) { - if (n>0 && n<10000) { - number = n; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " - "Try 1..9999")); - } - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(lastStatus); - } - break; - - default: - break; - } +void RS_ActionDrawLinePolygon::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 SetCenter: + case SetCorner: + + if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetNumber); + } + break; + + case SetNumber: { + bool ok; + int n = c.toInt(&ok); + + if (ok == true) + { + if (n > 0 && n < 10000) + number = n; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " + "Try 1..9999")); + + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + default: + break; + } } +QStringList RS_ActionDrawLinePolygon::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetCenter: + case SetCorner: + cmd += command("number"); + break; -QStringList RS_ActionDrawLinePolygon::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetCenter: - case SetCorner: - cmd += command("number"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - - -void RS_ActionDrawLinePolygon::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLinePolygon::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawLinePolygon::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } +} - -void RS_ActionDrawLinePolygon::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +int RS_ActionDrawLinePolygon::getNumber() +{ + return number; } +void RS_ActionDrawLinePolygon::setNumber(int n) +{ + number = n; +} -// EOF