]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/actiondrawspline.cpp
In the middle of major refactoring...
[architektonas] / src / actions / actiondrawspline.cpp
similarity index 57%
rename from src/actions/rs_actiondrawspline.cpp
rename to src/actions/actiondrawspline.cpp
index 533ca4b6625c422db3d6d0da7502c7eefba6dca3..13727355ec6a5bd03bce2bdcf56ca8c82a87310a 100644 (file)
@@ -1,4 +1,4 @@
-// rs_actiondrawspline.cpp
+// actiondrawspline.cpp
 //
 // Part of the Architektonas Project
 // Originally part of QCad Community Edition by Andrew Mustun
@@ -12,7 +12,7 @@
 // JLH  06/04/2010  Added this text. :-)
 //
 
-#include "rs_actiondrawspline.h"
+#include "actiondrawspline.h"
 
 #include "rs_commandevent.h"
 #include "commands.h"
@@ -20,8 +20,8 @@
 #include "graphicview.h"
 #include "rs_preview.h"
 
-RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, GraphicView & graphicView):
-       RS_PreviewActionInterface("Draw splines", container, graphicView)
+ActionDrawSpline::ActionDrawSpline(RS_EntityContainer & container, GraphicView & graphicView):
+       ActionInterface("Draw splines", container, graphicView)
 {
        reset();
 #warning "!!! Need to port setAutoDelete() behaviour from Qt3 to Qt4 !!!"
@@ -30,16 +30,16 @@ RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, Graphic
        //bHistory.setAutoDelete(true);
 }
 
-RS_ActionDrawSpline::~RS_ActionDrawSpline()
+ActionDrawSpline::~ActionDrawSpline()
 {
 }
 
-/*virtual*/ RS2::ActionType RS_ActionDrawSpline::rtti()
+/*virtual*/ RS2::ActionType ActionDrawSpline::rtti()
 {
        return RS2::ActionDrawSpline;
 }
 
-void RS_ActionDrawSpline::reset()
+void ActionDrawSpline::reset()
 {
        spline = NULL;
        //start = Vector(false);
@@ -47,22 +47,21 @@ void RS_ActionDrawSpline::reset()
        //bHistory.clear();
 }
 
-void RS_ActionDrawSpline::init(int status)
+void ActionDrawSpline::init(int status)
 {
-       RS_PreviewActionInterface::init(status);
+       ActionInterface::init(status);
 
        reset();
 }
 
-void RS_ActionDrawSpline::trigger()
+void ActionDrawSpline::trigger()
 {
-       RS_PreviewActionInterface::trigger();
+       ActionInterface::trigger();
 
        if (spline == NULL)
                return;
 
        // add the entity
-       //RS_Spline* spline = new RS_Spline(container, data);
        spline->setLayerToActive();
        spline->setPenToActive();
        spline->update();
@@ -83,19 +82,19 @@ void RS_ActionDrawSpline::trigger()
        graphicView->drawEntity(spline);
        graphicView->moveRelativeZero(r);
        drawSnapper();
-       RS_DEBUG->print("RS_ActionDrawSpline::trigger(): spline added: %d", spline->getId());
+       RS_DEBUG->print("ActionDrawSpline::trigger(): spline added: %d", spline->getId());
 
        spline = NULL;
        //history.clear();
 }
 
-void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
+void ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
 {
-       RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent begin");
+       RS_DEBUG->print("ActionDrawSpline::mouseMoveEvent begin");
 
        Vector mouse = snapPoint(e);
 
-       if (getStatus() == SetNextPoint && spline != NULL /*&& point.valid*/)
+       if (getStatus() == SetNextPoint && spline)
        {
                deletePreview();
                clearPreview();
@@ -103,21 +102,21 @@ void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e)
                RS_Spline * tmpSpline = (RS_Spline *)spline->clone();
                tmpSpline->addControlPoint(mouse);
                tmpSpline->update();
-               preview->addEntity(tmpSpline);
+//             preview->addEntity(tmpSpline);
 
                QList<Vector> cpts = tmpSpline->getControlPoints();
                QList<Vector>::iterator it;
 
-               for(it = cpts.begin(); it != cpts.end(); ++it)
-                       preview->addEntity(new RS_Point(preview, RS_PointData(*it)));
+//             for(it=cpts.begin(); it!=cpts.end(); it+)
+//                     preview->addEntity(new RS_Point(preview, RS_PointData(*it)));
 
                drawPreview();
        }
 
-       RS_DEBUG->print("RS_ActionDrawSpline::mouseMoveEvent end");
+       RS_DEBUG->print("ActionDrawSpline::mouseMoveEvent end");
 }
 
-void RS_ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
+void ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
 {
        if (e->button() == Qt::LeftButton)
        {
@@ -136,9 +135,9 @@ void RS_ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e)
        }
 }
 
-void RS_ActionDrawSpline::coordinateEvent(Vector * e)
+void ActionDrawSpline::coordinateEvent(Vector * e)
 {
-       if (e == NULL)
+       if (!e)
                return;
 
        Vector mouse = *e;
@@ -146,20 +145,15 @@ void RS_ActionDrawSpline::coordinateEvent(Vector * e)
        switch (getStatus())
        {
        case SetStartpoint:
-               //data.startpoint = mouse;
-               //point = mouse;
                history.clear();
                history.append(new Vector(mouse));
 
-               if (spline == NULL)
+               if (!spline)
                {
                        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();
@@ -167,31 +161,18 @@ void RS_ActionDrawSpline::coordinateEvent(Vector * e)
 
        case SetNextPoint:
                graphicView->moveRelativeZero(mouse);
-               //point = mouse;
                history.append(new Vector(mouse));
-               //bHistory.append(new double(0.0));
 
-               if (spline != NULL)
+               if (spline)
                {
-                       //graphicView->deleteEntity(spline);
                        spline->addControlPoint(mouse);
-                       //spline->setEndpoint(mouse);
-                       //if (spline->count()==1) {
-                       //spline->setLayerToActive();
-                       //spline->setPenToActive();
-                       //container->addEntity(spline);
-                       //}
                        deletePreview();
                        clearPreview();
                        deleteSnapper();
-                       //graphicView->drawEntity(spline);
                        drawSnapper();
                }
 
-               //trigger();
-               //data.startpoint = data.endpoint;
                updateMouseButtonHints();
-               //graphicView->moveRelativeZero(mouse);
                break;
 
        default:
@@ -199,35 +180,30 @@ void RS_ActionDrawSpline::coordinateEvent(Vector * e)
        }
 }
 
-void RS_ActionDrawSpline::commandEvent(RS_CommandEvent * e)
+void ActionDrawSpline::commandEvent(RS_CommandEvent * e)
 {
        QString c = e->getCommand().toLower();
 
        switch (getStatus())
        {
        case SetStartpoint:
-
                if (checkCommand("help", c))
                {
                        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
                                + getAvailableCommands().join(", "));
                        return;
                }
+
                break;
 
        case SetNextPoint:
-               /*if (checkCommand("close", c)) {
-                   close();
-                   updateMouseButtonHints();
-                   return;
-                  }*/
-
                if (checkCommand("undo", c))
                {
                        undo();
                        updateMouseButtonHints();
                        return;
                }
+
                break;
 
        default:
@@ -235,7 +211,7 @@ void RS_ActionDrawSpline::commandEvent(RS_CommandEvent * e)
        }
 }
 
-QStringList RS_ActionDrawSpline::getAvailableCommands()
+QStringList ActionDrawSpline::getAvailableCommands()
 {
        QStringList cmd;
 
@@ -245,13 +221,12 @@ QStringList RS_ActionDrawSpline::getAvailableCommands()
                break;
 
        case SetNextPoint:
-
                if (history.count() >= 2)
                        cmd += command("undo");
 
-
                if (history.count() >= 3)
                        cmd += command("close");
+
                break;
 
        default:
@@ -261,7 +236,7 @@ QStringList RS_ActionDrawSpline::getAvailableCommands()
        return cmd;
 }
 
-void RS_ActionDrawSpline::updateMouseButtonHints()
+void ActionDrawSpline::updateMouseButtonHints()
 {
        switch (getStatus())
        {
@@ -270,7 +245,8 @@ void RS_ActionDrawSpline::updateMouseButtonHints()
                        tr("Cancel"));
                break;
 
-       case SetNextPoint: {
+       case SetNextPoint:
+       {
                QString msg = "";
 
                if (history.count() >= 3)
@@ -291,7 +267,7 @@ void RS_ActionDrawSpline::updateMouseButtonHints()
                                tr("Specify next control point"),
                                tr("Back"));
        }
-       break;
+               break;
 
        default:
                RS_DIALOGFACTORY->updateMouseWidget("", "");
@@ -299,110 +275,82 @@ void RS_ActionDrawSpline::updateMouseButtonHints()
        }
 }
 
-void RS_ActionDrawSpline::showOptions()
+void ActionDrawSpline::showOptions()
 {
-       RS_ActionInterface::showOptions();
-
+       ActionInterface::showOptions();
        RS_DIALOGFACTORY->requestOptions(this, true);
 }
 
-void RS_ActionDrawSpline::hideOptions()
+void ActionDrawSpline::hideOptions()
 {
-       RS_ActionInterface::hideOptions();
-
+       ActionInterface::hideOptions();
        RS_DIALOGFACTORY->requestOptions(this, false);
 }
 
-void RS_ActionDrawSpline::updateMouseCursor()
+void ActionDrawSpline::updateMouseCursor()
 {
        graphicView->setMouseCursor(RS2::CadCursor);
 }
 
-void RS_ActionDrawSpline::updateToolBar()
+void ActionDrawSpline::updateToolBar()
 {
        if (!isFinished())
                RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
        else
-               //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSplines);
                RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
 }
 
-/*
-   void RS_ActionDrawSpline::close() {
-    if (history.count()>2 && start.valid) {
-        //data.endpoint = start;
-        //trigger();
-                if (spline!=NULL) {
-                        Vector e(spline->getStartpoint());
-                        coordinateEvent(&e);
-                }
-                trigger();
-        setStatus(SetStartpoint);
-        graphicView->moveRelativeZero(start);
-    } else {
-        RS_DIALOGFACTORY->commandMessage(
-            tr("Cannot close sequence of lines: "
-               "Not enough entities defined yet."));
-    }
-   }
- */
-
-void RS_ActionDrawSpline::undo()
+void ActionDrawSpline::undo()
 {
        if (history.count() > 1)
        {
                history.removeLast();
-               //bHistory.removeLast();
                deletePreview();
                clearPreview();
 
-               //graphicView->setCurrentAction(
-               //    new RS_ActionEditUndo(true, *container, *graphicView));
-               if (history.last() != NULL)
+               if (history.last())
                {
                        //point = *history.last();
                }
 
-               if (spline != NULL)
+               if (spline)
                {
                        spline->removeLastControlPoint();
                        Vector * v = history.last();
 
-                       if (v != NULL)
+                       if (v)
                                graphicView->moveRelativeZero(*v);
+
                        graphicView->redraw();
                }
        }
        else
                RS_DIALOGFACTORY->commandMessage(
-                       tr("Cannot undo: "
-                               "Not enough entities defined yet."));
+                       tr("Cannot undo: Not enough entities defined yet."));
 }
 
-void RS_ActionDrawSpline::setDegree(int deg)
+void ActionDrawSpline::setDegree(int deg)
 {
        data.degree = deg;
 
-       if (spline != NULL)
+       if (spline)
                spline->setDegree(deg);
 }
 
-int RS_ActionDrawSpline::getDegree()
+int ActionDrawSpline::getDegree()
 {
        return data.degree;
 }
 
-void RS_ActionDrawSpline::setClosed(bool c)
+void ActionDrawSpline::setClosed(bool c)
 {
        data.closed = c;
 
-       if (spline != NULL)
+       if (spline)
                spline->setClosed(c);
 }
 
-bool RS_ActionDrawSpline::isClosed()
+bool ActionDrawSpline::isClosed()
 {
        return data.closed;
 }
-
-// EOF