]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actiondrawlinepolygon2.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actiondrawlinepolygon2.cpp
index 3489ab4ed995d57f6290e9d0325cda1cb5d8252d..feaa99f98f04a164ae39ec5b2d6b1942caddb825 100644 (file)
-/****************************************************************************
-** $Id: rs_actiondrawlinepolygon2.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinepolygon2.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 <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -----------------------------------------------------------
+// JLH  06/04/2010  Added this text. :-)
+//
 
 #include "rs_actiondrawlinepolygon2.h"
 
 #include "rs_creation.h"
-#include "rs_snapper.h"
+#include "rs_dialogfactory.h"
+#include "rs_graphicview.h"
+#include "rs_preview.h"
 
+RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons",
+               container, graphicView)
+{
+       corner1 = Vector(false);
+       corner2 = Vector(false);
 
-
-RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2(
-    RS_EntityContainer& container,
-    RS_GraphicView& graphicView)
-        :RS_PreviewActionInterface("Draw Polygons", container, graphicView) {
-
-    corner1 = Vector(false);
-    corner2 = Vector(false);
-
-    number = 3;
+       number = 3;
 }
 
-QAction* RS_ActionDrawLinePolygon2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
+RS_ActionDrawLinePolygon2::~RS_ActionDrawLinePolygon2()
 {
-       QAction * action = new QAction(tr("Polygo&n (Cor,Cor)"), 0);
-//     QAction* action = new QAction(tr("Polygon"), tr("Polygo&n (Cor,Cor)"),
-//                                                                     QKeySequence(), NULL);
-       action->setStatusTip(tr("Draw polygon with two corners"));
-       return action;
 }
 
+/*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon2::rtti()
+{
+       return RS2::ActionDrawLinePolygon2;
+}
 
-void RS_ActionDrawLinePolygon2::trigger() {
-    RS_PreviewActionInterface::trigger();
+void RS_ActionDrawLinePolygon2::trigger()
+{
+       RS_PreviewActionInterface::trigger();
 
-    deleteSnapper();
-    deletePreview();
-    clearPreview();
+       deleteSnapper();
+       deletePreview();
+       clearPreview();
 
-    RS_Creation creation(container, graphicView);
-    bool ok = creation.createPolygon2(corner1, corner2, number);
+       RS_Creation creation(container, graphicView);
+       bool ok = creation.createPolygon2(corner1, corner2, number);
 
-    if (!ok) {
-        RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger:"
-                        " No polygon added\n");
-    }
+       if (!ok)
+               RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger: No polygon added\n");
 }
 
+void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent * e)
+{
+       RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin");
 
+       Vector mouse = snapPoint(e);
 
-void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent* e) {
-    RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin");
-
-    Vector mouse = snapPoint(e);
+       switch (getStatus())
+       {
+       case SetCorner1:
+               break;
 
-    switch (getStatus()) {
-    case SetCorner1:
-        break;
+       case SetCorner2:
 
-    case SetCorner2:
-        if (corner1.valid) {
-            corner2 = mouse;
-            deletePreview();
-            clearPreview();
+               if (corner1.valid)
+               {
+                       corner2 = mouse;
+                       deletePreview();
+                       clearPreview();
 
-            RS_Creation creation(preview, NULL, false);
-            creation.createPolygon2(corner1, corner2, number);
+                       RS_Creation creation(preview, NULL, false);
+                       creation.createPolygon2(corner1, corner2, number);
 
-            drawPreview();
-        }
-        break;
+                       drawPreview();
+               }
+               break;
 
-    default:
-        break;
-    }
+       default:
+               break;
+       }
 }
 
-
-
-void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent* e) {
-    if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-        RS_CoordinateEvent ce(snapPoint(e));
-        coordinateEvent(&ce);
-    } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
-        deletePreview();
-        clearPreview();
-        deleteSnapper();
-        init(getStatus()-1);
-    }
+void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent * e)
+{
+       if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+       {
+               Vector ce(snapPoint(e));
+               coordinateEvent(&ce);
+       }
+       else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
+       {
+               deletePreview();
+               clearPreview();
+               deleteSnapper();
+               init(getStatus() - 1);
+       }
 }
 
-
-
-void RS_ActionDrawLinePolygon2::coordinateEvent(RS_CoordinateEvent* e) {
-    if (e==NULL) {
-        return;
-    }
-
-    Vector mouse = e->getCoordinate();
-
-    switch (getStatus()) {
-    case SetCorner1:
-        corner1 = mouse;
-        setStatus(SetCorner2);
-        graphicView->moveRelativeZero(mouse);
-        break;
-
-    case SetCorner2:
-        corner2 = mouse;
-        trigger();
-        break;
-
-    default:
-        break;
-    }
+void RS_ActionDrawLinePolygon2::coordinateEvent(Vector * e)
+{
+       if (e == NULL)
+               return;
+
+       Vector mouse = *e;
+
+       switch (getStatus())
+       {
+       case SetCorner1:
+               corner1 = mouse;
+               setStatus(SetCorner2);
+               graphicView->moveRelativeZero(mouse);
+               break;
+
+       case SetCorner2:
+               corner2 = mouse;
+               trigger();
+               break;
+
+       default:
+               break;
+       }
 }
 
-
-
-void RS_ActionDrawLinePolygon2::updateMouseButtonHints() {
-    if (RS_DIALOGFACTORY!=NULL) {
-        switch (getStatus()) {
-        case SetCorner1:
-            RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
-                                                tr("Cancel"));
-            break;
-
-        case SetCorner2:
-            RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
-                                                tr("Back"));
-            break;
-
-        case SetNumber:
-            RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
-            break;
-
-        default:
-            RS_DIALOGFACTORY->updateMouseWidget("", "");
-            break;
-        }
-    }
+void RS_ActionDrawLinePolygon2::updateMouseButtonHints()
+{
+       if (RS_DIALOGFACTORY != NULL)
+       {
+               switch (getStatus())
+               {
+               case SetCorner1:
+                       RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
+                               tr("Cancel"));
+                       break;
+
+               case SetCorner2:
+                       RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
+                               tr("Back"));
+                       break;
+
+               case SetNumber:
+                       RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
+                       break;
+
+               default:
+                       RS_DIALOGFACTORY->updateMouseWidget("", "");
+                       break;
+               }
+       }
 }
 
+void RS_ActionDrawLinePolygon2::showOptions()
+{
+       RS_ActionInterface::showOptions();
 
-
-void RS_ActionDrawLinePolygon2::showOptions() {
-    RS_ActionInterface::showOptions();
-
-    if (RS_DIALOGFACTORY!=NULL) {
-        RS_DIALOGFACTORY->requestOptions(this, true);
-    }
+       if (RS_DIALOGFACTORY != NULL)
+               RS_DIALOGFACTORY->requestOptions(this, true);
 }
 
+void RS_ActionDrawLinePolygon2::hideOptions()
+{
+       RS_ActionInterface::hideOptions();
 
-
-void RS_ActionDrawLinePolygon2::hideOptions() {
-    RS_ActionInterface::hideOptions();
-
-    if (RS_DIALOGFACTORY!=NULL) {
-        RS_DIALOGFACTORY->requestOptions(this, false);
-    }
+       if (RS_DIALOGFACTORY != NULL)
+               RS_DIALOGFACTORY->requestOptions(this, false);
 }
 
-
-
-void RS_ActionDrawLinePolygon2::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 SetCorner1:
-    case SetCorner2:
-        if (checkCommand("number", c)) {
-            deleteSnapper();
-            deletePreview();
-            clearPreview();
-            lastStatus = (Status)getStatus();
-            setStatus(SetNumber);
-        }
-        break;
-
-    case SetNumber: {
-            bool ok;
-            int n = c.toInt(&ok);
-            if (ok==true) {
-                if (n>0 && n<10000) {
-                    number = n;
-                } else {
-                    if (RS_DIALOGFACTORY!=NULL) {
-                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
-                                                            "Try 1..9999"));
-                    }
-                }
-            } else {
-                if (RS_DIALOGFACTORY!=NULL) {
-                    RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression."));
-                }
-            }
-            if (RS_DIALOGFACTORY!=NULL) {
-                RS_DIALOGFACTORY->requestOptions(this, true, true);
-            }
-            setStatus(lastStatus);
-        }
-        break;
-
-    default:
-        break;
-    }
+void RS_ActionDrawLinePolygon2::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 SetCorner1:
+       case SetCorner2:
+
+               if (checkCommand("number", c))
+               {
+                       deleteSnapper();
+                       deletePreview();
+                       clearPreview();
+                       lastStatus = (Status)getStatus();
+                       setStatus(SetNumber);
+               }
+               break;
+
+       case SetNumber: {
+               bool ok;
+               int n = c.toInt(&ok);
+
+               if (ok == true)
+               {
+                       if (n > 0 && n < 10000)
+                               number = n;
+                       else if (RS_DIALOGFACTORY != NULL)
+                               RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
+                                               "Try 1..9999"));
+
+               }
+               else if (RS_DIALOGFACTORY != NULL)
+                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression."));
+
+               if (RS_DIALOGFACTORY != NULL)
+                       RS_DIALOGFACTORY->requestOptions(this, true, true);
+               setStatus(lastStatus);
+       }
+       break;
+
+       default:
+               break;
+       }
 }
 
+QStringList RS_ActionDrawLinePolygon2::getAvailableCommands()
+{
+       QStringList cmd;
 
+       switch (getStatus())
+       {
+       case SetCorner1:
+       case SetCorner2:
+               cmd += command("number");
+               break;
 
-QStringList RS_ActionDrawLinePolygon2::getAvailableCommands() {
-    QStringList cmd;
-
-    switch (getStatus()) {
-    case SetCorner1:
-    case SetCorner2:
-        cmd += command("number");
-        break;
-    default:
-        break;
-    }
+       default:
+               break;
+       }
 
-    return cmd;
+       return cmd;
 }
 
-
-
-void RS_ActionDrawLinePolygon2::updateMouseCursor() {
-    graphicView->setMouseCursor(RS2::CadCursor);
+void RS_ActionDrawLinePolygon2::updateMouseCursor()
+{
+       graphicView->setMouseCursor(RS2::CadCursor);
 }
 
+void RS_ActionDrawLinePolygon2::updateToolBar()
+{
+       if (RS_DIALOGFACTORY != NULL)
+       {
+               if (!isFinished())
+                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
+               else
+                       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
+       }
+}
 
-
-void RS_ActionDrawLinePolygon2::updateToolBar() {
-    if (RS_DIALOGFACTORY!=NULL) {
-        if (!isFinished()) {
-            RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
-        } else {
-            RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
-        }
-    }
+int RS_ActionDrawLinePolygon2::getNumber()
+{
+       return number;
 }
 
+void RS_ActionDrawLinePolygon2::setNumber(int n)
+{
+       number = n;
+}
 
-// EOF