]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actiondrawlineparallel.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actiondrawlineparallel.cpp
index 769f73a9c58562aefad606e8853b4b01bc7db47d..03ab2682e229a6643d21c87b913138b24b85855c 100644 (file)
 
 #include "rs_actiondrawlineparallel.h"
 
-#include "rs_creation.h"
-#include "rs_snapper.h"
 #include "rs_actiondrawlineparallelthrough.h"
+#include "commands.h"
+#include "rs_creation.h"
+#include "rs_dialogfactory.h"
+#include "rs_graphicview.h"
+#include "rs_preview.h"
 
-RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(
-    RS_EntityContainer& container,
-    RS_GraphicView& graphicView)
-        :RS_PreviewActionInterface("Draw Parallels", container, graphicView)
+RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Parallels",
+               container, graphicView)
 {
-    parallel = NULL;
-    entity = NULL;
-    distance = 1.0;
-    number = 1;
-    coord = Vector(false);
+       parallel = NULL;
+       entity = NULL;
+       distance = 1.0;
+       number = 1;
+       coord = Vector(false);
 }
 
-QAction * RS_ActionDrawLineParallel::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
+RS_ActionDrawLineParallel::~RS_ActionDrawLineParallel()
 {
-       QAction * action = NULL;
-
-       if (type == RS2::ActionDrawLineParallel)
-       {
-               action = new QAction(tr("Para&llel"), 0);
-//             action = new QAction(tr("Parallel"), tr("Para&llel"),
-//                                                             QKeySequence(), NULL);
-       }
-       else if (type == RS2::ActionDrawArcParallel)
-       {
-               action = new QAction(tr("&Concentric"), 0);
-//             action = new QAction(tr("Concentric"), tr("&Concentric"),
-//                                                             QKeySequence(), NULL);
-       }
-       else if (type == RS2::ActionDrawCircleParallel)
-       {
-               action = new QAction(tr("&Concentric"), 0);
-//             action = new QAction(tr("Concentric"), tr("&Concentric"),
-//                                                             QKeySequence(), NULL);
-       }
+}
 
-       action->setStatusTip(tr("Draw parallels to existing lines, arcs, circles"));
-       return action;
+/*virtual*/ RS2::ActionType RS_ActionDrawLineParallel::rtti()
+{
+       return RS2::ActionDrawLineParallel;
 }
 
 void RS_ActionDrawLineParallel::trigger()
 {
-    RS_PreviewActionInterface::trigger();
+       RS_PreviewActionInterface::trigger();
 
-    RS_Creation creation(container, graphicView);
-    RS_Entity* e = creation.createParallel(coord,
-                                           distance, number,
-                                           entity);
+       RS_Creation creation(container, graphicView);
+       RS_Entity * e = creation.createParallel(coord, distance, number, entity);
 
-    if (e==NULL) {
-        RS_DEBUG->print("RS_ActionDrawLineParallel::trigger:"
-                        " No parallels added\n");
-    }
+       if (e == NULL)
+               RS_DEBUG->print("RS_ActionDrawLineParallel::trigger: No parallels added\n");
 }
 
+void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
+{
+       RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin");
+       coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
+       entity = catchEntity(e, RS2::ResolveAll);
 
+       switch (getStatus())
+       {
+       case SetEntity:
+       {
+               deletePreview();
+               clearPreview();
+               RS_Creation creation(preview, NULL, false);
+               creation.createParallel(coord, distance, number, entity);
+               drawPreview();
+       }
+       break;
 
-void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent* e) {
-    RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin");
-
-    coord = Vector(graphicView->toGraphX(e->x()),
-                      graphicView->toGraphY(e->y()));
-
-    entity = catchEntity(e, RS2::ResolveAll);
-
-    switch (getStatus()) {
-    case SetEntity: {
-            deletePreview();
-            clearPreview();
-
-            RS_Creation creation(preview, NULL, false);
-            creation.createParallel(coord,
-                                    distance, number,
-                                    entity);
-
-            drawPreview();
-        }
-        break;
-
-    default:
-        break;
-    }
+       default:
+               break;
+       }
 
-    RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end");
+       RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end");
 }
 
+void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
+{
+//     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
+       if (e->button() == Qt::RightButton)
+               init(getStatus() - 1);
+       else
+               trigger();
+}
 
-
-void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent* e) {
-    if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
-        init(getStatus()-1);
-    } else {
-        trigger();
-    }
+void RS_ActionDrawLineParallel::updateMouseButtonHints()
+{
+       if (RS_DIALOGFACTORY != NULL)
+       {
+               switch (getStatus())
+               {
+               case SetEntity:
+                       RS_DIALOGFACTORY->updateMouseWidget(
+                               tr("Specify Distance <%1> or select entity or [%2]")
+                               .arg(distance).arg(RS_COMMANDS->command("through")),
+                               tr("Cancel"));
+                       break;
+
+               case SetNumber:
+                       RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
+                       break;
+
+               default:
+                       RS_DIALOGFACTORY->updateMouseWidget("", "");
+                       break;
+               }
+       }
 }
 
+void RS_ActionDrawLineParallel::showOptions()
+{
+       RS_ActionInterface::showOptions();
 
+       if (RS_DIALOGFACTORY != NULL)
+               RS_DIALOGFACTORY->requestOptions(this, true);
 
-void RS_ActionDrawLineParallel::updateMouseButtonHints() {
-    if (RS_DIALOGFACTORY!=NULL) {
-        switch (getStatus()) {
-        case SetEntity:
-            RS_DIALOGFACTORY->updateMouseWidget(
-                tr("Specify Distance <%1> or select entity or [%2]")
-                .arg(distance).arg(RS_COMMANDS->command("through")),
-                tr("Cancel"));
-            break;
+       updateMouseButtonHints();
+}
 
-        case SetNumber:
-            RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
-            break;
+void RS_ActionDrawLineParallel::hideOptions()
+{
+       RS_ActionInterface::hideOptions();
 
-        default:
-            RS_DIALOGFACTORY->updateMouseWidget("", "");
-            break;
-        }
-    }
+       if (RS_DIALOGFACTORY != NULL)
+               RS_DIALOGFACTORY->requestOptions(this, false);
 }
 
+void RS_ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
+{
+       QString c = e->getCommand().toLower();
 
+       if (checkCommand("help", c))
+       {
+               if (RS_DIALOGFACTORY != NULL)
+                       RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+                               + getAvailableCommands().join(", "));
 
-void RS_ActionDrawLineParallel::showOptions() {
-    RS_ActionInterface::showOptions();
-
-    if (RS_DIALOGFACTORY!=NULL) {
-        RS_DIALOGFACTORY->requestOptions(this, true);
-    }
-    updateMouseButtonHints();
-}
+               return;
+       }
 
+       switch (getStatus())
+       {
+       case SetEntity:
+               if (checkCommand("through", c))
+               {
+                       finish();
+                       graphicView->setCurrentAction(new RS_ActionDrawLineParallelThrough(*container,
+                                       *graphicView));
+               }
+               else if (checkCommand("number", c))
+               {
+                       deleteSnapper();
+                       deletePreview();
+                       clearPreview();
+                       setStatus(SetNumber);
+               }
+               else
+               {
+                       bool ok;
+                       double d = RS_Math::eval(c, &ok);
+
+                       if (ok && d > 1.0e-10)
+                               distance = d;
+                       else    if (RS_DIALOGFACTORY != NULL)
+                               RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+
+
+                       if (RS_DIALOGFACTORY != NULL)
+                               RS_DIALOGFACTORY->requestOptions(this, true, true);
+
+                       updateMouseButtonHints();
+                       //setStatus(SetEntity);
+               }
+               break;
+
+       case SetNumber:
+       {
+               bool ok;
+               int n = c.toInt(&ok);
 
+               if (ok)
+               {
+                       if (n > 0 && n < 100)
+                               number = n;
+                       else    if (RS_DIALOGFACTORY != NULL)
+                               RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
 
-void RS_ActionDrawLineParallel::hideOptions() {
-    RS_ActionInterface::hideOptions();
+               }
+               else    if (RS_DIALOGFACTORY != NULL)
+                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
 
-    if (RS_DIALOGFACTORY!=NULL) {
-        RS_DIALOGFACTORY->requestOptions(this, false);
-    }
-}
 
+               if (RS_DIALOGFACTORY != NULL)
+                       RS_DIALOGFACTORY->requestOptions(this, true, true);
 
+               setStatus(SetEntity);
+       }
+       break;
 
-void RS_ActionDrawLineParallel::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 SetEntity: {
-            if (checkCommand("through", c)) {
-                finish();
-                graphicView->setCurrentAction(
-                    new RS_ActionDrawLineParallelThrough(*container,
-                                                         *graphicView));
-            } else if (checkCommand("number", c)) {
-                deleteSnapper();
-                deletePreview();
-                clearPreview();
-                setStatus(SetNumber);
-            } else {
-                bool ok;
-                double d = RS_Math::eval(c, &ok);
-                if (ok==true && d>1.0e-10) {
-                    distance = d;
-                } else {
-                    if (RS_DIALOGFACTORY!=NULL) {
-                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-                    }
-                }
-                if (RS_DIALOGFACTORY!=NULL) {
-                    RS_DIALOGFACTORY->requestOptions(this, true, true);
-                }
-                updateMouseButtonHints();
-                //setStatus(SetEntity);
-            }
-        }
-        break;
-
-    case SetNumber: {
-            bool ok;
-            int n = c.toInt(&ok);
-            if (ok==true) {
-                if (n>0 && n<100) {
-                    number = n;
-                } else {
-                    if (RS_DIALOGFACTORY!=NULL) {
-                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
-                                                            "Try 1..99"));
-                    }
-                }
-            } else {
-                if (RS_DIALOGFACTORY!=NULL) {
-                    RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-                }
-            }
-            if (RS_DIALOGFACTORY!=NULL) {
-                RS_DIALOGFACTORY->requestOptions(this, true, true);
-            }
-            setStatus(SetEntity);
-        }
-        break;
-
-    default:
-        break;
-    }
+       default:
+               break;
+       }
 }
 
+QStringList RS_ActionDrawLineParallel::getAvailableCommands()
+{
+       QStringList cmd;
 
+       switch (getStatus())
+       {
+       case SetEntity:
+               cmd += command("number");
+               cmd += command("through");
+               break;
 
-QStringList RS_ActionDrawLineParallel::getAvailableCommands() {
-    QStringList cmd;
-
-    switch (getStatus()) {
-    case SetEntity:
-        cmd += command("number");
-        cmd += command("through");
-        break;
-    default:
-        break;
-    }
+       default:
+               break;
+       }
 
-    return cmd;
+       return cmd;
 }
 
+void RS_ActionDrawLineParallel::updateMouseCursor()
+{
+       graphicView->setMouseCursor(RS2::CadCursor);
+}
 
-
-void RS_ActionDrawLineParallel::updateMouseCursor() {
-    graphicView->setMouseCursor(RS2::CadCursor);
+void RS_ActionDrawLineParallel::updateToolBar()
+{
+       if (RS_DIALOGFACTORY != NULL)
+               RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
 }
 
+double RS_ActionDrawLineParallel::getDistance()
+{
+       return distance;
+}
 
+void RS_ActionDrawLineParallel::setDistance(double d)
+{
+       distance = d;
+}
 
-void RS_ActionDrawLineParallel::updateToolBar() {
-    if (RS_DIALOGFACTORY!=NULL) {
-        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
-    }
+int RS_ActionDrawLineParallel::getNumber()
+{
+       return number;
 }
 
+void RS_ActionDrawLineParallel::setNumber(int n)
+{
+       number = n;
+}
 
-// EOF