]> Shamusworld >> Repos - architektonas/blobdiff - src/base/actioninterface.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / base / actioninterface.cpp
index 4280b5c9c8a40f1b9234212b4bcf6f652403f3d5..1b4d5d8171303c46f9658943b82853a27675bf4a 100644 (file)
 // 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>
 //
 // Who  When        What
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/22/2010  Added this text. :-)
+// JLH  08/09/2010  Preparation for removal of GraphicView object from this
+//                  class
 //
 
 #include "actioninterface.h"
 
 #include "commands.h"
-#include "rs_debug.h"
-#include "rs_entitycontainer.h"
+#include "debug.h"
+#include "dialogfactory.h"
+#include "entitycontainer.h"
 #include "graphicview.h"
+#include "grid.h"
+
+/*
+I think what's needed here is for the constructor to save the state of the snapper
+and to restore it in the destructor. This, of course, assumes that the actions are
+created and used in a certain order, perhaps that needs enforcement? Dunno, but worth
+a try as suspend() and resume() seem to fuck it up badly.
+#define _ASSUAN_DEPRECATED  __attribute__ ((__deprecated__))
+on MS it's: __declspec(deprecated)
+*/
 
 /**
  * Constructor.
  *
- * Sets the entity container on which the action class inherited
- * from this interface operates.
+ * Sets the entity container on which the action class inherited from this
+ * interface operates.
  *
- * @param name Action name. This can be used internally for
- *             debugging mainly.
+ * @param name Action name. This can be used internally for debugging mainly.
  * @param container Entity container this action operates on.
- * @param graphicView Graphic view instance this action operates on.
- *                    Please note that an action belongs to this
- *                    view.
- * @param cursor Default mouse cursor for this action. If the action
- *               is suspended and resumed again the cursor will always
- *               be reset to the one given here.
+ * @param graphicView Graphic view instance this action operates on. Please
+ *                    note that an action belongs to this view.
  */
-ActionInterface::ActionInterface(const char * name, RS_EntityContainer & c,
-       GraphicView & v): graphicView(&v), container(&c)
+ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
+       GraphicView & gv): graphicView(&gv), container(&ec),
+//     snapperVisibility(false), previewVisibility(false), suspendCount(0)
+//hm.
+       snapperVisibility(true), previewVisibility(true), suspendCount(0)
 {
-       RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
+       DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
+
+//This doesn't work properly; not sure why that is...
+//Actually, it's working perfectly. Now we just need to propagate the fixes everywhere. :-/
+       // We'll use snapperVisibility for the save/restore functionality...
+       snapperVisibility = graphicView->SnapperVisible();
 
        this->name = name;
        status = 0;
        finished = false;
-       //triggerOnResume = false;
 
        // Graphic provides a pointer to the graphic if the entity container is a
-       //graphic (i.e. can also hold layers).
-       graphic = c.getGraphic();
+       // graphic (i.e. can also hold layers).
+       graphic = ec.getGraphic();
 
        // Document pointer will be used for undo / redo
-       document = c.getDocument();
+       document = ec.getDocument();
 
-       //this->cursor = cursor;
-       //setSnapMode(graphicView.getDefaultSnapMode());
+       // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
 
-       RS_DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
+       // This is here until I can figure out a better way to contain all of this
+       // circular referential nonsense that exists in this codebase. It will be
+       // expunged, by Grabthar's Hammer!
+//     graphicView->snapper.SetContainer(container);
+//     graphicView->snapper.SetGraphicView(graphicView);       // <-- THIS is what I mean! INSANE!
+       // Not all actions use these. Perhaps we need to pass params to the contructor
+       // in order to set these? Setting the default to true for both?
+//     graphicView->snapper.SetVisible();
+       graphicView->SetSnapperVisible();
+       graphicView->preview.SetVisible();
+
+       DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
+//printf("ActionInterface::ActionInterface() [%08X]\n", this);
 }
 
 /**
  * Destructor.
  */
-ActionInterface::~ActionInterface()
+/*virtual*/ ActionInterface::~ActionInterface()
 {
        // would be pure virtual now:
        // hideOptions();
 //JLH: Only it isn't pure virtual...
+//printf("ActionInterface::~ActionInterface() [%08X]\n", this);
+
+       // We'll use snapperVisibility for the save/restore functionality...
+       graphicView->SetSnapperVisible(snapperVisibility);
 }
 
 /**
@@ -95,7 +127,7 @@ QString ActionInterface::getName()
  */
 void ActionInterface::init(int status/*= 0*/)
 {
-//     RS_Snapper::init();
+//     Snapper::init();
        setStatus(status);
 
        if (status >= 0)
@@ -105,6 +137,14 @@ void ActionInterface::init(int status/*= 0*/)
                updateMouseCursor();
                updateToolBar();
        }
+       else    // status < 0, e.g. this action is finished
+       {
+//             graphicView->snapper.SetVisible(false);
+               graphicView->SetSnapperVisible(false);
+               graphicView->preview.SetVisible(false);
+               graphicView->preview.clear();
+               graphicView->redraw();  //hm.
+       }
 }
 
 /**
@@ -171,7 +211,7 @@ void ActionInterface::coordinateEvent(Vector *)
  * This function can be overwritten by the implementing action.
  * The default implementation does nothing.
  */
-void ActionInterface::commandEvent(RS_CommandEvent *)
+void ActionInterface::commandEvent(CommandEvent *)
 {
 }
 
@@ -197,9 +237,9 @@ QStringList ActionInterface::getAvailableCommands()
  *               of progress and decreases when the user goes one
  *               step back (i.e. presses the right mouse button).
  */
-void ActionInterface::setStatus(int status)
+void ActionInterface::setStatus(int value)
 {
-       this->status = status;
+       status = value;
 
        if (status < 0)
        {
@@ -272,7 +312,7 @@ void ActionInterface::setFinished()
  */
 void ActionInterface::finish()
 {
-       RS_DEBUG->print("ActionInterface::finish");
+       DEBUG->print("ActionInterface::finish");
        status = -1;
 //     graphicView->setMouseCursor(RS2::ArrowCursor);
        //graphicView->requestToolBar(RS2::ToolBarMain);
@@ -281,10 +321,19 @@ void ActionInterface::finish()
 //jlh: deleteSnapper();
        hideOptions();
        finished = true;
-//     RS_Snapper::finish();           // Sets RS_Snapper::finished = true
+//     Snapper::finish();              // Sets Snapper::finished = true
        // I think this is where we want to update the screen...
 //     graphicView->redraw();
-       RS_DEBUG->print("ActionInterface::finish: OK");
+       // hm.
+//     graphicView->snapper.SetVisible(false);
+       graphicView->SetSnapperVisible(false);
+//Short circuit the destructor fuxoring with this:
+//snapperVisibility = false;
+//Only it causes other stuff to be fuxorred... Grr... Not sure how to fix this...
+       graphicView->preview.SetVisible(false);
+//     graphicView->preview.clear();
+       graphicView->redraw();  //hm.
+       DEBUG->print("ActionInterface::finish: OK");
 }
 
 /**
@@ -296,13 +345,31 @@ void ActionInterface::setPredecessor(ActionInterface * p)
        predecessor = p;
 }
 
+#if 0
+Here is a problem. suspend() and resume() don't do what they should:
+The problem is that Actions are modifying a shared resource though it's acting
+as if it were not. Case in point below: ActionZoomPan sets the snapper/preview
+visibility to FALSE and then EventHandler calls suspend() here, which queries
+the graphicView to see what its state is. We need to fix this...!
+
+This ties into the problem where we have GraphicView pointers scattered all
+over the place. We need to fix that too!
+#endif
 /**
  * Suspends this action while another action takes place.
  */
 void ActionInterface::suspend()
 {
+#if 0
+printf("ActionInterface::suspend(%i): [%08X] ", ++suspendCount, this);
+       // Maybe this is where we need to save the state of the snapper
+       // & preview objects???
 //     graphicView->setMouseCursor(RS2::ArrowCursor);
-//     RS_Snapper::suspend();
+//     Snapper::suspend();
+       snapperVisibility = graphicView->snapper.Visible();
+       previewVisibility = graphicView->preview.Visible();
+printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
+#endif
 }
 
 /**
@@ -310,9 +377,17 @@ void ActionInterface::suspend()
  */
 void ActionInterface::resume()
 {
+#if 0
+if (suspendCount == 0)
+       printf("!!! RESUME BEFORE SUSPEND !!!\n");
+printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
        updateMouseCursor();
        updateToolBar();
-//     RS_Snapper::resume();
+//     Snapper::resume();
+       graphicView->snapper.SetVisible(snapperVisibility);
+       graphicView->preview.SetVisible(previewVisibility);
+printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
+#endif
 }
 
 /**
@@ -320,7 +395,7 @@ void ActionInterface::resume()
  */
 void ActionInterface::hideOptions()
 {
-//     RS_Snapper::hideOptions();
+//     Snapper::hideOptions();
 }
 
 /**
@@ -328,51 +403,53 @@ void ActionInterface::hideOptions()
  */
 void ActionInterface::showOptions()
 {
-//     RS_Snapper::showOptions();
+//     Snapper::showOptions();
 }
 
 /**
- * Calls checkCommand() from the RS_COMMANDS module.
+ * Calls checkCommand() from the COMMANDS module.
  */
 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
        RS2::ActionType action)
 {
-       return RS_COMMANDS->checkCommand(cmd, str, action);
+       return COMMANDS->checkCommand(cmd, str, action);
 }
 
 /**
- * Calls command() from the RS_COMMANDS module.
+ * Calls command() from the COMMANDS module.
  */
 QString ActionInterface::command(const QString & cmd)
 {
-       return RS_COMMANDS->command(cmd);
+       return COMMANDS->command(cmd);
 }
 
 /**
- * Calls msgAvailableCommands() from the RS_COMMANDS module.
+ * Calls msgAvailableCommands() from the COMMANDS module.
  */
 QString ActionInterface::msgAvailableCommands()
 {
-       return RS_COMMANDS->msgAvailableCommands();
+       return COMMANDS->msgAvailableCommands();
 }
 
 // This is here to save some typing in all the action* classes derived from
 // this one. May go away in the future.
 Vector ActionInterface::snapPoint(QMouseEvent * e)
 {
-       return graphicView->snapper.snapPoint(e);
+//     return graphicView->snapper.snapPoint(e);
+       return graphicView->SnapPoint(e);
 }
 
-RS_Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
+Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
 {
-       return graphicView->snapper.catchEntity(e, level);
+       return graphicView->CatchEntity(e, level);
 }
 
-RS_Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
+Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
 {
-       return graphicView->snapper.catchEntity(v, level);
+       return graphicView->CatchEntity(v, level);
 }
 
+#warning "!!! Dummy functions need to be deleted once all actions no longer use these !!!"
 //dummy functions, will delete later...
 void ActionInterface::drawSnapper(void)
 {