X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actiondrawspline.cpp;h=91fa9a1b5ef89b04713ce135ddb97dbc7ee3dbe8;hb=27d4a138d23453e93a833e9347444b828a971cb4;hp=f62a25260cd498f3e1c99561c4de81a8918618ff;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actiondrawspline.cpp b/src/actions/rs_actiondrawspline.cpp index f62a252..91fa9a1 100644 --- a/src/actions/rs_actiondrawspline.cpp +++ b/src/actions/rs_actiondrawspline.cpp @@ -1,36 +1,26 @@ -/**************************************************************************** -** $Id: rs_actiondrawspline.cpp 1140 2004-07-24 23:14:15Z 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_actiondrawspline.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_actiondrawspline.h" -#include "rs_actioneditundo.h" -#include "rs_snapper.h" +#include "rs_commandevent.h" +#include "commands.h" +#include "rs_dialogfactory.h" +#include "graphicview.h" +#include "rs_preview.h" -RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Draw splines", container, graphicView) { reset(); @@ -49,65 +39,54 @@ RS_ActionDrawSpline::~RS_ActionDrawSpline() return RS2::ActionDrawSpline; } -QAction * RS_ActionDrawSpline::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&Spline"), 0); -// QAction* action = new QAction(tr("Spline"), tr("&Spline"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw splines")); - return action; -} - void RS_ActionDrawSpline::reset() { spline = NULL; - //start = Vector(false); - history.clear(); - //bHistory.clear(); + //start = Vector(false); + history.clear(); + //bHistory.clear(); } +void RS_ActionDrawSpline::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawSpline::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); + reset(); } +void RS_ActionDrawSpline::trigger() +{ + RS_PreviewActionInterface::trigger(); - -void RS_ActionDrawSpline::trigger() { - RS_PreviewActionInterface::trigger(); - - if (spline==NULL) { + if (spline == NULL) return; - } // add the entity - //RS_Spline* spline = new RS_Spline(container, data); - spline->setLayerToActive(); - spline->setPenToActive(); + //RS_Spline* spline = new RS_Spline(container, data); + spline->setLayerToActive(); + spline->setPenToActive(); spline->update(); - container->addEntity(spline); + container->addEntity(spline); - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(spline); - document->endUndoCycle(); - } + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(spline); + document->endUndoCycle(); + } // upd view - deleteSnapper(); + deleteSnapper(); Vector r = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(spline); - graphicView->moveRelativeZero(r); - drawSnapper(); - RS_DEBUG->print("RS_ActionDrawSpline::trigger(): spline added: %d", spline->getId()); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(spline); + graphicView->moveRelativeZero(r); + drawSnapper(); + RS_DEBUG->print("RS_ActionDrawSpline::trigger(): spline added: %d", spline->getId()); spline = NULL; - //history.clear(); + //history.clear(); } void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e) @@ -126,12 +105,10 @@ void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e) tmpSpline->update(); preview->addEntity(tmpSpline); -// Q3ValueList cpts = tmpSpline->getControlPoints(); -// Q3ValueList::iterator it; QList cpts = tmpSpline->getControlPoints(); QList::iterator it; - for(it=cpts.begin(); it!=cpts.end(); ++it) + for(it = cpts.begin(); it != cpts.end(); ++it) preview->addEntity(new RS_Point(preview, RS_PointData(*it))); drawPreview(); @@ -142,64 +119,67 @@ void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e) void RS_ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e) { - if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (e->button() == Qt::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (e->button() == Qt::RightButton) { if (getStatus() == SetNextPoint) - { trigger(); - } - deletePreview(); - clearPreview(); - deleteSnapper(); - init(getStatus()-1); - } -} - + deletePreview(); + clearPreview(); + deleteSnapper(); + init(getStatus() - 1); + } +} -void RS_ActionDrawSpline::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } +void RS_ActionDrawSpline::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; - switch (getStatus()) { - case SetStartpoint: + switch (getStatus()) + { + case SetStartpoint: //data.startpoint = mouse; - //point = mouse; - history.clear(); - history.append(new Vector(mouse)); - if (spline==NULL) { + //point = mouse; + history.clear(); + history.append(new Vector(mouse)); + + if (spline == NULL) + { spline = new RS_Spline(container, data); spline->addControlPoint(mouse); } - //bHistory.clear(); - //bHistory.append(new double(0.0)); - //start = mouse; - setStatus(SetNextPoint); - graphicView->moveRelativeZero(mouse); - updateMouseButtonHints(); - break; - - case SetNextPoint: - graphicView->moveRelativeZero(mouse); - //point = mouse; - history.append(new Vector(mouse)); - //bHistory.append(new double(0.0)); - if (spline!=NULL) { + + //bHistory.clear(); + //bHistory.append(new double(0.0)); + //start = mouse; + setStatus(SetNextPoint); + graphicView->moveRelativeZero(mouse); + updateMouseButtonHints(); + break; + + case SetNextPoint: + graphicView->moveRelativeZero(mouse); + //point = mouse; + history.append(new Vector(mouse)); + //bHistory.append(new double(0.0)); + + if (spline != NULL) + { //graphicView->deleteEntity(spline); spline->addControlPoint(mouse); //spline->setEndpoint(mouse); //if (spline->count()==1) { - //spline->setLayerToActive(); - //spline->setPenToActive(); - //container->addEntity(spline); + //spline->setLayerToActive(); + //spline->setPenToActive(); + //container->addEntity(spline); //} deletePreview(); clearPreview(); @@ -207,150 +187,156 @@ void RS_ActionDrawSpline::coordinateEvent(RS_CoordinateEvent* e) { //graphicView->drawEntity(spline); drawSnapper(); } - //trigger(); - //data.startpoint = data.endpoint; - updateMouseButtonHints(); - //graphicView->moveRelativeZero(mouse); - break; - default: - break; - } -} + //trigger(); + //data.startpoint = data.endpoint; + updateMouseButtonHints(); + //graphicView->moveRelativeZero(mouse); + break; + default: + break; + } +} +void RS_ActionDrawSpline::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); -void RS_ActionDrawSpline::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); + switch (getStatus()) + { + case SetStartpoint: - switch (getStatus()) { - case SetStartpoint: - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - break; + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + break; - case SetNextPoint: - /*if (checkCommand("close", c)) { - close(); - updateMouseButtonHints(); - return; - }*/ + case SetNextPoint: + /*if (checkCommand("close", c)) { + close(); + updateMouseButtonHints(); + return; + }*/ - if (checkCommand("undo", c)) { - undo(); - updateMouseButtonHints(); - return; - } - break; + if (checkCommand("undo", c)) + { + undo(); + updateMouseButtonHints(); + return; + } + break; - default: - break; - } + default: + break; + } } +QStringList RS_ActionDrawSpline::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetStartpoint: + break; -QStringList RS_ActionDrawSpline::getAvailableCommands() { - QStringList cmd; + case SetNextPoint: - switch (getStatus()) { - case SetStartpoint: - break; - case SetNextPoint: - if (history.count()>=2) { - cmd += command("undo"); - } - if (history.count()>=3) { - cmd += command("close"); - } - break; - default: - break; - } + if (history.count() >= 2) + cmd += command("undo"); - return cmd; -} + if (history.count() >= 3) + cmd += command("close"); + break; + default: + break; + } -void RS_ActionDrawSpline::updateMouseButtonHints() { - switch (getStatus()) { - case SetStartpoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first control point"), - tr("Cancel")); - break; - case SetNextPoint: { - QString msg = ""; - - if (history.count()>=3) { - msg += RS_COMMANDS->command("close"); - msg += "/"; - } - if (history.count()>=2) { - msg += RS_COMMANDS->command("undo"); - } - - if (history.count()>=2) { - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify next control point or [%1]").arg(msg), - tr("Back")); - } else { - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify next control point"), - tr("Back")); - } - } - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } + return cmd; } +void RS_ActionDrawSpline::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetStartpoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first control point"), + tr("Cancel")); + break; -void RS_ActionDrawSpline::showOptions() { - RS_ActionInterface::showOptions(); + case SetNextPoint: { + QString msg = ""; - RS_DIALOGFACTORY->requestOptions(this, true); -} + if (history.count() >= 3) + { + msg += RS_COMMANDS->command("close"); + msg += "/"; + } + if (history.count() >= 2) + msg += RS_COMMANDS->command("undo"); + + if (history.count() >= 2) + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify next control point or [%1]").arg(msg), + tr("Back")); + else + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify next control point"), + tr("Back")); + } + break; + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } +} -void RS_ActionDrawSpline::hideOptions() { - RS_ActionInterface::hideOptions(); +void RS_ActionDrawSpline::showOptions() +{ + RS_ActionInterface::showOptions(); - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawSpline::hideOptions() +{ + RS_ActionInterface::hideOptions(); -void RS_ActionDrawSpline::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + RS_DIALOGFACTORY->requestOptions(this, false); } - -void RS_ActionDrawSpline::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSplines); - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +void RS_ActionDrawSpline::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawSpline::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSplines); + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); +} /* -void RS_ActionDrawSpline::close() { + void RS_ActionDrawSpline::close() { if (history.count()>2 && start.valid) { //data.endpoint = start; //trigger(); - if (spline!=NULL) { - RS_CoordinateEvent e(spline->getStartpoint()); - coordinateEvent(&e); - } - trigger(); + if (spline!=NULL) { + Vector e(spline->getStartpoint()); + coordinateEvent(&e); + } + trigger(); setStatus(SetStartpoint); graphicView->moveRelativeZero(start); } else { @@ -358,55 +344,64 @@ void RS_ActionDrawSpline::close() { tr("Cannot close sequence of lines: " "Not enough entities defined yet.")); } -} -*/ - -void RS_ActionDrawSpline::undo() { - if (history.count()>1) { - history.removeLast(); - //bHistory.removeLast(); - deletePreview(); - clearPreview(); - //graphicView->setCurrentAction( - // new RS_ActionEditUndo(true, *container, *graphicView)); - if (history.last()!=NULL) { - //point = *history.last(); + } + */ + +void RS_ActionDrawSpline::undo() +{ + if (history.count() > 1) + { + history.removeLast(); + //bHistory.removeLast(); + deletePreview(); + clearPreview(); + + //graphicView->setCurrentAction( + // new RS_ActionEditUndo(true, *container, *graphicView)); + if (history.last() != NULL) + { + //point = *history.last(); } - if (spline!=NULL) { + + if (spline != NULL) + { spline->removeLastControlPoint(); - Vector* v = history.last(); - if (v!=NULL) { - graphicView->moveRelativeZero(*v); - } + Vector * v = history.last(); + + if (v != NULL) + graphicView->moveRelativeZero(*v); graphicView->redraw(); } - } else { - RS_DIALOGFACTORY->commandMessage( - tr("Cannot undo: " - "Not enough entities defined yet.")); - } + } + else + RS_DIALOGFACTORY->commandMessage( + tr("Cannot undo: " + "Not enough entities defined yet.")); } - -void RS_ActionDrawSpline::setDegree(int deg) { +void RS_ActionDrawSpline::setDegree(int deg) +{ data.degree = deg; - if (spline!=NULL) { + + if (spline != NULL) spline->setDegree(deg); - } } -int RS_ActionDrawSpline::getDegree() { +int RS_ActionDrawSpline::getDegree() +{ return data.degree; } -void RS_ActionDrawSpline::setClosed(bool c) { +void RS_ActionDrawSpline::setClosed(bool c) +{ data.closed = c; - if (spline!=NULL) { + + if (spline != NULL) spline->setClosed(c); - } } -bool RS_ActionDrawSpline::isClosed() { +bool RS_ActionDrawSpline::isClosed() +{ return data.closed; }