]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actionmodifytrimamount.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionmodifytrimamount.cpp
index 9513135e0572c8f0698a15690e6c0bdb92b5a884..65666c82c203f99af5ff0395ef42a0602e69920b 100644 (file)
-/****************************************************************************
-** $Id: rs_actionmodifytrimamount.cpp 1161 2004-12-09 23:10:09Z 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_actionmodifytrimamount.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_actionmodifytrimamount.h"
 
-#include "rs_snapper.h"
+#include "rs_dialogfactory.h"
+#include "rs_modification.h"
 
 RS_ActionModifyTrimAmount::RS_ActionModifyTrimAmount(
-    RS_EntityContainer& container,
-    RS_GraphicView& graphicView)
-        :RS_ActionInterface("Trim Entity by a given amount",
-                    container, graphicView) {
-
-    trimEntity = NULL;
-    trimCoord = Vector(false);
-    distance = 0.0;
+       RS_EntityContainer & container, RS_GraphicView & graphicView):
+       RS_ActionInterface("Trim Entity by a given amount",
+               container, graphicView)
+{
+       trimEntity = NULL;
+       trimCoord = Vector(false);
+       distance = 0.0;
 }
 
-QAction* RS_ActionModifyTrimAmount::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
+RS_ActionModifyTrimAmount::~RS_ActionModifyTrimAmount()
 {
-       QAction * action = new QAction(tr("&Lengthen"), 0);
-//     QAction* action = new QAction(tr("Lengthen"), tr("&Lengthen"),
-//                                                     QKeySequence(), NULL);
-       action->setStatusTip(tr("Lengthen by a given amount"));
-       return action;
 }
 
-void RS_ActionModifyTrimAmount::init(int status)
+/*virtual*/ RS2::ActionType RS_ActionModifyTrimAmount::rtti()
 {
-    RS_ActionInterface::init(status);
-
-    snapMode = RS2::SnapFree;
-    snapRes = RS2::RestrictNothing;
+       return RS2::ActionModifyTrimAmount;
 }
 
+void RS_ActionModifyTrimAmount::init(int status)
+{
+       RS_ActionInterface::init(status);
 
+       snapMode = RS2::SnapFree;
+       snapRes = RS2::RestrictNothing;
+}
 
-void RS_ActionModifyTrimAmount::trigger() {
-
-    RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()");
-
-    if (trimEntity!=NULL && trimEntity->isAtomic()) {
+void RS_ActionModifyTrimAmount::trigger()
+{
+       RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()");
 
-        RS_Modification m(*container, graphicView);
-        m.trimAmount(trimCoord, (RS_AtomicEntity*)trimEntity, distance);
+       if (trimEntity != NULL && trimEntity->isAtomic())
+       {
+               RS_Modification m(*container, graphicView);
+               m.trimAmount(trimCoord, (RS_AtomicEntity *)trimEntity, distance);
 
-        trimEntity = NULL;
-        setStatus(ChooseTrimEntity);
+               trimEntity = NULL;
+               setStatus(ChooseTrimEntity);
 
-        RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
-    }
+               RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
+       }
 }
 
-
-
-void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent* e) {
-
-    trimCoord = graphicView->toGraph(e->x(), e->y());
-    trimEntity = catchEntity(e);
-
-    if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
-        switch (getStatus()) {
-        case ChooseTrimEntity:
-            if (trimEntity!=NULL && trimEntity->isAtomic()) {
-                trigger();
-            } else {
-                if (trimEntity==NULL) {
-                    RS_DIALOGFACTORY->commandMessage(
-                        tr("No entity found. "));
-                } else if (trimEntity->rtti()==RS2::EntityInsert) {
-                    RS_DIALOGFACTORY->commandMessage(
-                        tr("The chosen Entity is in a block. "
-                           "Please edit the block."));
-                } else {
-                    RS_DIALOGFACTORY->commandMessage(
-                        tr("The chosen Entity is not an atomic entity "
-                           "or cannot be trimmed."));
-                }
-            }
-            break;
-
-        default:
-            break;
-        }
-    } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
-        deleteSnapper();
-        init(getStatus()-1);
-    }
+void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e)
+{
+       trimCoord = graphicView->toGraph(e->x(), e->y());
+       trimEntity = catchEntity(e);
+
+       if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
+       {
+               switch (getStatus())
+               {
+               case ChooseTrimEntity:
+
+                       if (trimEntity != NULL && trimEntity->isAtomic())
+                               trigger();
+                       else
+                       {
+                               if (trimEntity == NULL)
+                                       RS_DIALOGFACTORY->commandMessage(
+                                               tr("No entity found. "));
+                               else if (trimEntity->rtti() == RS2::EntityInsert)
+                                       RS_DIALOGFACTORY->commandMessage(
+                                               tr("The chosen Entity is in a block. "
+                                                       "Please edit the block."));
+                               else
+                                       RS_DIALOGFACTORY->commandMessage(
+                                               tr("The chosen Entity is not an atomic entity "
+                                                       "or cannot be trimmed."));
+                       }
+                       break;
+
+               default:
+                       break;
+               }
+       }
+       else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
+       {
+               deleteSnapper();
+               init(getStatus() - 1);
+       }
 }
 
-
-
-void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent* e) {
-    QString c = e->getCommand().toLower();
-
-    if (checkCommand("help", c)) {
-        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
-                                         + getAvailableCommands().join(", "));
-        return;
-    }
-
-    switch (getStatus()) {
-    case ChooseTrimEntity: {
-            bool ok;
-            double d = RS_Math::eval(c, &ok);
-            if (ok==true) {
-                distance = d;
-            } else {
-                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-            }
-            RS_DIALOGFACTORY->requestOptions(this, true, true);
-            setStatus(ChooseTrimEntity);
-        }
-        break;
-
-    default:
-        break;
-    }
+void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent * e)
+{
+       QString c = e->getCommand().toLower();
+
+       if (checkCommand("help", c))
+       {
+               RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
+                       + getAvailableCommands().join(", "));
+               return;
+       }
+
+       switch (getStatus())
+       {
+       case ChooseTrimEntity: {
+               bool ok;
+               double d = RS_Math::eval(c, &ok);
+
+               if (ok == true)
+                       distance = d;
+               else
+                       RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
+               RS_DIALOGFACTORY->requestOptions(this, true, true);
+               setStatus(ChooseTrimEntity);
+       }
+       break;
+
+       default:
+               break;
+       }
 }
 
+QStringList RS_ActionModifyTrimAmount::getAvailableCommands()
+{
+       QStringList cmd;
 
+       switch (getStatus())
+       {
+       case ChooseTrimEntity:
+               break;
 
-QStringList RS_ActionModifyTrimAmount::getAvailableCommands() {
-    QStringList cmd;
-
-    switch (getStatus()) {
-    case ChooseTrimEntity:
-        break;
-    default:
-        break;
-    }
+       default:
+               break;
+       }
 
-    return cmd;
+       return cmd;
 }
 
+void RS_ActionModifyTrimAmount::showOptions()
+{
+       RS_ActionInterface::showOptions();
 
-void RS_ActionModifyTrimAmount::showOptions() {
-    RS_ActionInterface::showOptions();
-
-    RS_DIALOGFACTORY->requestOptions(this, true);
+       RS_DIALOGFACTORY->requestOptions(this, true);
 }
 
+void RS_ActionModifyTrimAmount::hideOptions()
+{
+       RS_ActionInterface::hideOptions();
 
-
-void RS_ActionModifyTrimAmount::hideOptions() {
-    RS_ActionInterface::hideOptions();
-
-    RS_DIALOGFACTORY->requestOptions(this, false);
+       RS_DIALOGFACTORY->requestOptions(this, false);
 }
 
-
-void RS_ActionModifyTrimAmount::updateMouseButtonHints() {
-    switch (getStatus()) {
-    case ChooseTrimEntity:
-        RS_DIALOGFACTORY->updateMouseWidget(
-            tr("Select entity to trim or enter distance:"),
-            tr("Back"));
-        break;
-    default:
-        RS_DIALOGFACTORY->updateMouseWidget("", "");
-        break;
-    }
+void RS_ActionModifyTrimAmount::updateMouseButtonHints()
+{
+       switch (getStatus())
+       {
+       case ChooseTrimEntity:
+               RS_DIALOGFACTORY->updateMouseWidget(
+                       tr("Select entity to trim or enter distance:"),
+                       tr("Back"));
+               break;
+
+       default:
+               RS_DIALOGFACTORY->updateMouseWidget("", "");
+               break;
+       }
 }
 
-
-
-void RS_ActionModifyTrimAmount::updateMouseCursor() {
-    graphicView->setMouseCursor(RS2::CadCursor);
+void RS_ActionModifyTrimAmount::updateMouseCursor()
+{
+       graphicView->setMouseCursor(RS2::CadCursor);
 }
 
-
-
-void RS_ActionModifyTrimAmount::updateToolBar() {
-    RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
+void RS_ActionModifyTrimAmount::updateToolBar()
+{
+       RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
 }
 
+double RS_ActionModifyTrimAmount::getDistance()
+{
+       return distance;
+}
 
-// EOF
+void RS_ActionModifyTrimAmount::setDistance(double d)
+{
+       distance = d;
+}