]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/actiondrawlineangle.cpp
Phase two of adding polyline functionality...
[architektonas] / src / actions / actiondrawlineangle.cpp
index 53edc1fa723185942d31a0b61dce46ae9f5397b0..aeff68adceb9969d1699c6f69060a271996a3cd5 100644 (file)
@@ -3,7 +3,9 @@
 // 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
+// Portions copyright (C) 2001-2003 RibbonSoft
+// Copyright (C) 2010 Underground Software
+// See the README and GPLv2 files for licensing and warranty information
 //
 // JLH = James L. Hammons <jlhamm@acm.org>
 //
 
 #include "actiondrawlineangle.h"
 
-#include "rs_commandevent.h"
-#include "rs_dialogfactory.h"
+#include "commandevent.h"
+#include "debug.h"
+#include "dialogfactory.h"
 #include "graphicview.h"
-#include "rs_preview.h"
+#include "preview.h"
 
-ActionDrawLineAngle::ActionDrawLineAngle(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
-       ActionInterface("Draw lines with given angle",
-               container, graphicView)
+ActionDrawLineAngle::ActionDrawLineAngle(EntityContainer & container,
+       GraphicView & graphicView, double a, bool fa):
+       ActionInterface("Draw lines with given angle", container, graphicView),
+       pos(Vector(false)), angle(a), length(1.0), fixedAngle(fa), snpPoint(0)
 {
-       this->angle = angle;
-       length = 1.0;
-       snpPoint = 0;
-       this->fixedAngle = fixedAngle;
-       pos = Vector(false);
        reset();
+       //hm.
+//     graphicView.snapper.SetContainer(&container);
+//     graphicView.snapper.SetGraphicView(&graphicView);
+//     graphicView.snapper.SetVisible();
+//     graphicView.preview.SetVisible();
 }
 
 ActionDrawLineAngle::~ActionDrawLineAngle()
@@ -43,27 +47,25 @@ ActionDrawLineAngle::~ActionDrawLineAngle()
 
 void ActionDrawLineAngle::reset()
 {
-       data = RS_LineData(Vector(false), Vector(false));
+       data = LineData(Vector(false), Vector(false));
 }
 
 void ActionDrawLineAngle::init(int status)
 {
        ActionInterface::init(status);
-
        reset();
 }
 
 void ActionDrawLineAngle::trigger()
 {
        ActionInterface::trigger();
-
        preparePreview();
-       RS_Line * line = new RS_Line(container, data);
+       Line * line = new Line(container, data);
        line->setLayerToActive();
        line->setPenToActive();
        container->addEntity(line);
 
-       // upd. undo list:
+       // Update undo list:
        if (document)
        {
                document->startUndoCycle();
@@ -71,29 +73,33 @@ void ActionDrawLineAngle::trigger()
                document->endUndoCycle();
        }
 
-       deleteSnapper();
+//     deleteSnapper();
        graphicView->moveRelativeZero(Vector(0.0, 0.0));
        graphicView->drawEntity(line);
        graphicView->moveRelativeZero(data.startpoint);
-       RS_DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d",
-               line->getId());
+       graphicView->redraw();
+       DEBUG->print("ActionDrawLineAngle::trigger(): line added: %d", line->getId());
 }
 
 void ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e)
 {
-       RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
+       DEBUG->print("ActionDrawLineAngle::mouseMoveEvent begin");
 
        if (getStatus() == SetPos)
        {
                pos = snapPoint(e);
-               deletePreview();
-               clearPreview();
+//             deletePreview();
+//             clearPreview();
+//             preparePreview();
+//             preview->addEntity(new Line(preview, data));
+//             drawPreview();
                preparePreview();
-//             preview->addEntity(new RS_Line(preview, data));
-               drawPreview();
+               graphicView->preview.clear();
+               graphicView->preview.addEntity(new Line(&(graphicView->preview), data));
        }
 
-       RS_DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
+       graphicView->redraw();
+       DEBUG->print("ActionDrawLineAngle::mouseMoveEvent end");
 }
 
 void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
@@ -102,16 +108,20 @@ void ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e)
        {
                if (getStatus() == SetPos)
                {
-                       Vector ce(snapPoint(e));
+//                     Vector ce(snapPoint(e));
+                       Vector ce(graphicView->snapper.snapPoint(e));
                        coordinateEvent(&ce);
                }
        }
        else if (e->button() == Qt::RightButton)
        {
-               deletePreview();
-               deleteSnapper();
+//             deletePreview();
+//             deleteSnapper();
                init(getStatus() - 1);
        }
+
+       graphicView->preview.clear();                           // Remove entities from container
+       graphicView->redraw();
 }
 
 void ActionDrawLineAngle::preparePreview()
@@ -131,12 +141,12 @@ void ActionDrawLineAngle::preparePreview()
                p1 = pos;
 
        p2 += p1;
-       data = RS_LineData(p1, p2);
+       data = LineData(p1, p2);
 }
 
 void ActionDrawLineAngle::coordinateEvent(Vector * e)
 {
-       if (e == NULL)
+       if (!e)
                return;
 
        switch (getStatus())
@@ -151,13 +161,13 @@ void ActionDrawLineAngle::coordinateEvent(Vector * e)
        }
 }
 
-void ActionDrawLineAngle::commandEvent(RS_CommandEvent * e)
+void ActionDrawLineAngle::commandEvent(CommandEvent * e)
 {
        QString c = e->getCommand().toLower();
 
        if (checkCommand("help", c))
        {
-               RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+               DIALOGFACTORY->commandMessage(msgAvailableCommands()
                        + getAvailableCommands().join(", "));
                return;
        }
@@ -165,48 +175,51 @@ void ActionDrawLineAngle::commandEvent(RS_CommandEvent * e)
        switch (getStatus())
        {
        case SetPos:
-
                if (!fixedAngle && checkCommand("angle", c))
                {
-                       deleteSnapper();
-                       deletePreview();
-                       clearPreview();
+//                     deleteSnapper();
+//                     deletePreview();
+//                     clearPreview();
                        setStatus(SetAngle);
                }
                else if (checkCommand("length", c))
                {
-                       deleteSnapper();
-                       deletePreview();
-                       clearPreview();
+//                     deleteSnapper();
+//                     deletePreview();
+//                     clearPreview();
                        setStatus(SetLength);
                }
                break;
 
-       case SetAngle: {
+       case SetAngle:
+       {
                bool ok;
-               double a = RS_Math::eval(c, &ok);
+               double a = Math::eval(c, &ok);
 
-               if (ok == true)
-                       angle = RS_Math::deg2rad(a);
+               if (ok)
+                       angle = Math::deg2rad(a);
                else
-                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-               RS_DIALOGFACTORY->requestOptions(this, true, true);
+                       DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+
+               DIALOGFACTORY->requestOptions(this, true, true);
                setStatus(SetPos);
        }
-       break;
+               break;
 
-       case SetLength: {
+       case SetLength:
+       {
                bool ok;
-               double l = RS_Math::eval(c, &ok);
+               double l = Math::eval(c, &ok);
 
-               if (ok == true)
+               if (ok)
                        length = l;
                else
-                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-               RS_DIALOGFACTORY->requestOptions(this, true, true);
+                       DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+
+               DIALOGFACTORY->requestOptions(this, true, true);
                setStatus(SetPos);
        }
-       break;
+               break;
 
        default:
                break;
@@ -220,9 +233,9 @@ QStringList ActionDrawLineAngle::getAvailableCommands()
        switch (getStatus())
        {
        case SetPos:
-
                if (!fixedAngle)
                        cmd += command("angle");
+
                cmd += command("length");
                break;
 
@@ -238,16 +251,15 @@ void ActionDrawLineAngle::updateMouseButtonHints()
        switch (getStatus())
        {
        case SetPos:
-               RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"),
-                       tr("Cancel"));
+               DIALOGFACTORY->updateMouseWidget(tr("Specify position"), tr("Cancel"));
                break;
 
        case SetAngle:
-               RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
+               DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back"));
                break;
 
        case SetLength:
-               RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
+               DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back"));
                break;
 
        default:
@@ -258,15 +270,13 @@ void ActionDrawLineAngle::updateMouseButtonHints()
 void ActionDrawLineAngle::showOptions()
 {
        ActionInterface::showOptions();
-
-       RS_DIALOGFACTORY->requestOptions(this, true);
+       DIALOGFACTORY->requestOptions(this, true);
 }
 
 void ActionDrawLineAngle::hideOptions()
 {
        ActionInterface::hideOptions();
-
-       RS_DIALOGFACTORY->requestOptions(this, false);
+       DIALOGFACTORY->requestOptions(this, false);
 }
 
 void ActionDrawLineAngle::updateMouseCursor()
@@ -277,14 +287,15 @@ void ActionDrawLineAngle::updateMouseCursor()
 void ActionDrawLineAngle::updateToolBar()
 {
        if (!isFinished())
-               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
        else
-               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
+               DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
 }
 
 void ActionDrawLineAngle::setSnapPoint(int sp)
 {
        snpPoint = sp;
+//     graphicView->redraw();
 }
 
 int ActionDrawLineAngle::getSnapPoint()
@@ -295,6 +306,7 @@ int ActionDrawLineAngle::getSnapPoint()
 void ActionDrawLineAngle::setAngle(double a)
 {
        angle = a;
+//     graphicView->redraw();
 }
 
 double ActionDrawLineAngle::getAngle()
@@ -305,6 +317,7 @@ double ActionDrawLineAngle::getAngle()
 void ActionDrawLineAngle::setLength(double l)
 {
        length = l;
+//     graphicView->redraw();
 }
 
 double ActionDrawLineAngle::getLength()