]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/actiondrawarc.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actiondrawarc.cpp
index 184781c0873828d6f10a1d4c77d9b41f25d7dd17..3a92e6f90f5b35345cb33c33ebef19b537d3cc45 100644 (file)
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  06/03/2010  Added this text. :-)
+// JLH  09/17/2010  Fixed preview/snapper rendering.
 //
 
 #include "actiondrawarc.h"
 
-#include "rs_commandevent.h"
+#include "commandevent.h"
 #include "commands.h"
-#include "rs_debug.h"
-#include "rs_dialogfactory.h"
+#include "debug.h"
+#include "dialogfactory.h"
 #include "graphicview.h"
-#include "rs_preview.h"
+#include "preview.h"
 
-ActionDrawArc::ActionDrawArc(RS_EntityContainer & container, GraphicView & graphicView):
+ActionDrawArc::ActionDrawArc(EntityContainer & container, GraphicView & graphicView):
        ActionInterface("Draw arcs", container, graphicView)
 {
        reset();
@@ -41,9 +42,9 @@ RS2::ActionType ActionDrawArc::rtti()
 void ActionDrawArc::reset()
 {
        if (data.reversed)
-               data = RS_ArcData(Vector(false), 0.0, 2 * M_PI, 0.0, true);
+               data = ArcData(Vector(false), 0.0, 2 * M_PI, 0.0, true);
        else
-               data = RS_ArcData(Vector(false), 0.0, 0.0, 2 * M_PI, false);
+               data = ArcData(Vector(false), 0.0, 0.0, 2 * M_PI, false);
 }
 
 void ActionDrawArc::init(int status)
@@ -56,34 +57,30 @@ void ActionDrawArc::trigger()
 {
        ActionInterface::trigger();
 
-       RS_Arc * arc = new RS_Arc(container, data);
+       Arc * arc = new Arc(container, data);
        arc->setLayerToActive();
        arc->setPenToActive();
        container->addEntity(arc);
 
        // upd. undo list:
-       if (document != NULL)
+       if (document)
        {
                document->startUndoCycle();
                document->addUndoable(arc);
                document->endUndoCycle();
        }
 
-       deleteSnapper();
-       graphicView->moveRelativeZero(Vector(0.0, 0.0));
-       graphicView->drawEntity(arc);
        graphicView->moveRelativeZero(arc->getCenter());
-       drawSnapper();
-
+       graphicView->redraw();  //hm.
        setStatus(SetCenter);
        reset();
 
-       RS_DEBUG->print("ActionDrawArc::trigger(): arc added: %d", arc->getId());
+       DEBUG->print("ActionDrawArc::trigger(): arc added: %d", arc->getId());
 }
 
 void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
 {
-       RS_DEBUG->print("ActionDrawArc::mouseMoveEvent begin");
+       DEBUG->print("ActionDrawArc::mouseMoveEvent begin");
        Vector mouse = snapPoint(e);
 
        switch (getStatus())
@@ -97,10 +94,8 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
                if (data.center.valid)
                {
                        data.radius = data.center.distanceTo(mouse);
-                       deletePreview();
-                       clearPreview();
-//                     preview->addEntity(new RS_Circle(preview, RS_CircleData(data.center, data.radius)));
-                       drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Circle(&(graphicView->preview), CircleData(data.center, data.radius)));
                }
                break;
 
@@ -108,30 +103,24 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
                data.angle1 = data.center.angleTo(mouse);
 
                if (data.reversed)
-                       data.angle2 = RS_Math::correctAngle(data.angle1 - M_PI / 3);
+                       data.angle2 = Math::correctAngle(data.angle1 - M_PI / 3);
                else
-                       data.angle2 = RS_Math::correctAngle(data.angle1 + M_PI / 3);
+                       data.angle2 = Math::correctAngle(data.angle1 + M_PI / 3);
 
-               deletePreview();
-               clearPreview();
-//             preview->addEntity(new RS_Arc(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                break;
 
        case SetAngle2:
                data.angle2 = data.center.angleTo(mouse);
-               deletePreview();
-               clearPreview();
-//             preview->addEntity(new RS_Arc(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                break;
 
        case SetIncAngle:
                data.angle2 = data.angle1 + data.center.angleTo(mouse);
-               deletePreview();
-               clearPreview();
-//             preview->addEntity(new RS_Arc(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                break;
 
        case SetChordLength:
@@ -141,19 +130,18 @@ void ActionDrawArc::mouseMoveEvent(QMouseEvent * e)
                if (fabs(x / (2 * data.radius)) <= 1.0)
                {
                        data.angle2 = data.angle1 + asin(x / (2 * data.radius)) * 2;
-                       deletePreview();
-                       clearPreview();
-//                     preview->addEntity(new RS_Arc(preview, data));
-                       drawPreview();
+                       graphicView->preview.clear();
+                       graphicView->preview.addEntity(new Arc(&(graphicView->preview), data));
                }
        }
-       break;
+               break;
 
        default:
                break;
        }
 
-       RS_DEBUG->print("ActionDrawArc::mouseMoveEvent end");
+       graphicView->redraw();
+       DEBUG->print("ActionDrawArc::mouseMoveEvent end");
 }
 
 void ActionDrawArc::mouseReleaseEvent(QMouseEvent * e)
@@ -165,9 +153,10 @@ void ActionDrawArc::mouseReleaseEvent(QMouseEvent * e)
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+//             deleteSnapper();
                init(getStatus() - 1);
+               graphicView->redraw();  //hm.
        }
 }
 
@@ -227,118 +216,116 @@ void ActionDrawArc::coordinateEvent(Vector * e)
        }
 }
 
-void ActionDrawArc::commandEvent(RS_CommandEvent * e)
+void ActionDrawArc::commandEvent(CommandEvent * e)
 {
        QString c = e->getCommand().toLower();
 
-       if (RS_COMMANDS->checkCommand("help", c))
+       if (COMMANDS->checkCommand("help", c))
        {
-               if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+               if (DIALOGFACTORY != NULL)
+                       DIALOGFACTORY->commandMessage(msgAvailableCommands()
                                + getAvailableCommands().join(", "));
                return;
        }
 
-       if (RS_COMMANDS->checkCommand("reversed", c))
+       if (COMMANDS->checkCommand("reversed", c))
        {
                e->accept();
                setReversed(!isReversed());
 
-               if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->requestOptions(this, true, true);
+               if (DIALOGFACTORY != NULL)
+                       DIALOGFACTORY->requestOptions(this, true, true);
                return;
        }
 
        switch (getStatus())
        {
-       case SetRadius: {
+       case SetRadius:
+       {
                bool ok;
-               double r = RS_Math::eval(c, &ok);
+               double r = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
                        data.radius = r;
                        setStatus(SetAngle1);
                }
-               else if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
+               else if (DIALOGFACTORY)
+                       DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
        }
-       break;
+               break;
 
-       case SetAngle1: {
+       case SetAngle1:
+       {
                bool ok;
-               double a = RS_Math::eval(c, &ok);
+               double a = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
-                       data.angle1 = RS_Math::deg2rad(a);
+                       data.angle1 = Math::deg2rad(a);
                        setStatus(SetAngle2);
                }
-               else if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
+               else if (DIALOGFACTORY)
+                       DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
        }
-       break;
+               break;
 
        case SetAngle2:
 
-               if (RS_COMMANDS->checkCommand("angle", c))
+               if (COMMANDS->checkCommand("angle", c))
                        setStatus(SetIncAngle);
-               else if (RS_COMMANDS->checkCommand("chord length", c))
+               else if (COMMANDS->checkCommand("chord length", c))
                        setStatus(SetChordLength);
                else
                {
                        bool ok;
-                       double a = RS_Math::eval(c, &ok);
+                       double a = Math::eval(c, &ok);
 
-                       if (ok == true)
+                       if (ok)
                        {
-                               data.angle2 = RS_Math::deg2rad(a);
+                               data.angle2 = Math::deg2rad(a);
                                trigger();
                        }
-                       else if (RS_DIALOGFACTORY != NULL)
-                               RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
+                       else if (DIALOGFACTORY)
+                               DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
                }
                break;
 
-       case SetIncAngle: {
+       case SetIncAngle:
+       {
                bool ok;
-               double a = RS_Math::eval(c, &ok);
+               double a = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
-                       data.angle2 = data.angle1 + RS_Math::deg2rad(a);
+                       data.angle2 = data.angle1 + Math::deg2rad(a);
                        trigger();
                }
-               else if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
+               else if (DIALOGFACTORY)
+                       DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
        }
-       break;
+               break;
 
-       case SetChordLength: {
+       case SetChordLength:
+       {
                bool ok;
-               double l = RS_Math::eval(c, &ok);
+               double l = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                {
                        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 (DIALOGFACTORY)
+                               DIALOGFACTORY->commandMessage(tr("Not a valid chord length"));
 
                }
-               else if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-
+               else if (DIALOGFACTORY)
+                       DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
        }
-       break;
+               break;
 
        default:
                break;
@@ -348,47 +335,47 @@ void ActionDrawArc::commandEvent(RS_CommandEvent * e)
 QStringList ActionDrawArc::getAvailableCommands()
 {
        QStringList cmd;
-       cmd += RS_COMMANDS->command("reversed");
+       cmd += COMMANDS->command("reversed");
        return cmd;
 }
 
 void ActionDrawArc::updateMouseButtonHints()
 {
-       if (RS_DIALOGFACTORY != NULL)
+       if (DIALOGFACTORY)
        {
                switch (getStatus())
                {
                case SetCenter:
-                       RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel"));
+                       DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel"));
                        break;
 
                case SetRadius:
-                       RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back"));
+                       DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back"));
                        break;
 
                case SetAngle1:
-                       RS_DIALOGFACTORY->updateMouseWidget(
+                       DIALOGFACTORY->updateMouseWidget(
                                tr("Specify start angle:"), tr("Back"));
                        break;
 
                case SetAngle2:
-                       RS_DIALOGFACTORY->updateMouseWidget(
+                       DIALOGFACTORY->updateMouseWidget(
                                tr("Specify end angle or [Angle/chord Length]"),
                                tr("Back"));
                        break;
 
                case SetIncAngle:
-                       RS_DIALOGFACTORY->updateMouseWidget(tr("Specify included angle:"),
+                       DIALOGFACTORY->updateMouseWidget(tr("Specify included angle:"),
                                tr("Back"));
                        break;
 
                case SetChordLength:
-                       RS_DIALOGFACTORY->updateMouseWidget(tr("Specify chord length:"),
+                       DIALOGFACTORY->updateMouseWidget(tr("Specify chord length:"),
                                tr("Back"));
                        break;
 
                default:
-                       RS_DIALOGFACTORY->updateMouseWidget("", "");
+                       DIALOGFACTORY->updateMouseWidget("", "");
                        break;
                }
        }
@@ -398,16 +385,16 @@ void ActionDrawArc::showOptions()
 {
        ActionInterface::showOptions();
 
-       if (RS_DIALOGFACTORY)
-               RS_DIALOGFACTORY->requestOptions(this, true);
+       if (DIALOGFACTORY)
+               DIALOGFACTORY->requestOptions(this, true);
 }
 
 void ActionDrawArc::hideOptions()
 {
        ActionInterface::hideOptions();
 
-       if (RS_DIALOGFACTORY)
-               RS_DIALOGFACTORY->requestOptions(this, false);
+       if (DIALOGFACTORY)
+               DIALOGFACTORY->requestOptions(this, false);
 }
 
 void ActionDrawArc::updateMouseCursor()
@@ -417,13 +404,13 @@ void ActionDrawArc::updateMouseCursor()
 
 void ActionDrawArc::updateToolBar()
 {
-       if (!RS_DIALOGFACTORY)
+       if (!DIALOGFACTORY)
                return;
 
        if (!isFinished())
-               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
        else
-               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs);
 }
 
 bool ActionDrawArc::isReversed()