]> Shamusworld >> Repos - architektonas/blobdiff - src/actions/rs_actionlibraryinsert.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionlibraryinsert.cpp
index e6881cd2edc153bb6518c72ea8d879feb75aebd5..4fdab2ff80b04d5a1efdcb2a0574b17af57a7dd6 100644 (file)
@@ -1,41 +1,28 @@
-/****************************************************************************
-** $Id: rs_actionlibraryinsert.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_actionlibraryinsert.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_actionlibraryinsert.h"
 
-#include "commands.h"
-#include "rs_creation.h"
-#include "rs_modification.h"
+#include "rs_dialogfactory.h"
+#include "rs_graphicview.h"
+#include "rs_preview.h"
 #include "rs_units.h"
 
 /**
  * Constructor.
  */
-RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container,
-       RS_GraphicView & graphicView):
+RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container, RS_GraphicView & graphicView):
        RS_PreviewActionInterface("Library Insert", container, graphicView)
 {
 }
@@ -44,14 +31,9 @@ RS_ActionLibraryInsert::~RS_ActionLibraryInsert()
 {
 }
 
-QAction * RS_ActionLibraryInsert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
+/*virtual*/ RS2::ActionType RS_ActionLibraryInsert::rtti()
 {
-       QAction * action = new QAction(tr("&Insert Library Object"), 0);
-//     QAction* action = new QAction(tr("Insert Library Object"),
-//                                                                     tr("&Insert Library Object"),
-//                                                                     QKeySequence(), NULL);
-       action->setStatusTip(tr("Inserts an Object from the part library."));
-       return action;
+       return RS2::ActionLibraryInsert;
 }
 
 void RS_ActionLibraryInsert::init(int status)
@@ -60,13 +42,13 @@ void RS_ActionLibraryInsert::init(int status)
 
        reset();
 
-    /*if (graphic!=NULL) {
-        block = graphic->getActiveBlock();
-        if (block!=NULL) {
-            data.name = block->getName();
-        }
-}*/
-    //trigger();
+       /*if (graphic!=NULL) {
+           block = graphic->getActiveBlock();
+           if (block!=NULL) {
+               data.name = block->getName();
+           }
+          }*/
+       //trigger();
 }
 
 void RS_ActionLibraryInsert::setFile(const QString & file)
@@ -79,14 +61,14 @@ void RS_ActionLibraryInsert::setFile(const QString & file)
 
 void RS_ActionLibraryInsert::reset()
 {
-    /*data = RS_InsertData("",
-                         Vector(0.0,0.0),
-                         Vector(1.0,1.0),
-                         0.0,
-                         1, 1,
-                         Vector(1.0,1.0),
-                         NULL,
-                         RS2::Update);*/
+       /*data = RS_InsertData("",
+                            Vector(0.0,0.0),
+                            Vector(1.0,1.0),
+                            0.0,
+                            1, 1,
+                            Vector(1.0,1.0),
+                            NULL,
+                            RS2::Update);*/
 
        data.insertionPoint = Vector(false);
        data.factor = 1.0;
@@ -118,7 +100,8 @@ void RS_ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e)
                preview->addAllFrom(prev);
                preview->move(data.insertionPoint);
                preview->scale(data.insertionPoint,
-                                               Vector(data.factor, data.factor));
+                       Vector(data.factor, data.factor));
+
                // unit conversion:
                if (graphic != NULL)
                {
@@ -143,7 +126,7 @@ void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
 {
        if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
        {
-               RS_CoordinateEvent ce(snapPoint(e));
+               Vector ce(snapPoint(e));
                coordinateEvent(&ce);
        }
        else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
@@ -153,12 +136,12 @@ void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e)
        }
 }
 
-void RS_ActionLibraryInsert::coordinateEvent(RS_CoordinateEvent * e)
+void RS_ActionLibraryInsert::coordinateEvent(Vector * e)
 {
        if (e == NULL)
                return;
 
-       data.insertionPoint = e->getCoordinate();
+       data.insertionPoint = *e;
        trigger();
 }
 
@@ -175,6 +158,7 @@ void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
        switch (getStatus())
        {
        case SetTargetPoint:
+
                if (checkCommand("angle", c))
                {
                        deleteSnapper();
@@ -199,18 +183,14 @@ void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
                double a = RS_Math::eval(c, &ok);
 
                if (ok == true)
-               {
                        data.angle = RS_Math::deg2rad(a);
-               }
                else
-               {
                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-               }
 
                RS_DIALOGFACTORY->requestOptions(this, true, true);
                setStatus(lastStatus);
        }
-               break;
+       break;
 
        case SetFactor:
        {
@@ -218,18 +198,14 @@ void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e)
                double f = RS_Math::eval(c, &ok);
 
                if (ok == true)
-               {
                        setFactor(f);
-               }
                else
-               {
                        RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
-               }
 
                RS_DIALOGFACTORY->requestOptions(this, true, true);
                setStatus(lastStatus);
        }
-               break;
+       break;
 
        default:
                break;
@@ -245,8 +221,8 @@ QStringList RS_ActionLibraryInsert::getAvailableCommands()
        case SetTargetPoint:
                cmd += command("angle");
                cmd += command("factor");
-               ;
                break;
+
        default:
                break;
        }
@@ -275,12 +251,15 @@ void RS_ActionLibraryInsert::updateMouseButtonHints()
        case SetTargetPoint:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
                break;
+
        case SetAngle:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), "");
                break;
+
        case SetFactor:
                RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), "");
                break;
+
        default:
                RS_DIALOGFACTORY->updateMouseWidget("", "");
                break;
@@ -300,3 +279,23 @@ void RS_ActionLibraryInsert::updateToolBar()
                RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
 }
 
+double RS_ActionLibraryInsert::getAngle()
+{
+       return data.angle;
+}
+
+void RS_ActionLibraryInsert::setAngle(double a)
+{
+       data.angle = a;
+}
+
+double RS_ActionLibraryInsert::getFactor()
+{
+       return data.factor;
+}
+
+void RS_ActionLibraryInsert::setFactor(double f)
+{
+       data.factor = f;
+}
+