]> Shamusworld >> Repos - architektonas/blobdiff - src/base/actioninterface.cpp
Major refactor of Architektonas: Jettisoning old cruft.
[architektonas] / src / base / actioninterface.cpp
diff --git a/src/base/actioninterface.cpp b/src/base/actioninterface.cpp
deleted file mode 100644 (file)
index 00c5439..0000000
+++ /dev/null
@@ -1,475 +0,0 @@
-// actioninterface.cpp
-//
-// Part of the Architektonas Project
-// Originally part of QCad Community Edition by Andrew Mustun
-// Extensively rewritten and refactored by James L. Hammons
-// 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 "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.
- *
- * @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.
- */
-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)
-{
-       DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
-
-// Is it? Doesn't seem like it. Whenever you change snap types, the preview disappears.
-// Not sure what's going on with that.
-//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;
-
-       // Graphic provides a pointer to the graphic if the entity container is a
-       // drawing (i.e. can also hold layers).
-#warning "!!! Need to rename graphic to drawing !!!"
-       graphic = ec.GetDrawing();
-
-       // Document pointer will be used for undo / redo
-       document = ec.getDocument();
-
-       // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
-
-       // 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.
- */
-/*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);
-}
-
-/**
- * Must be implemented to return the ID of this action.
-*
-* @todo no default implementation
- */
-RS2::ActionType ActionInterface::rtti()
-{
-       return RS2::ActionNone;
-}
-
-/**
- * @return name of this action
- */
-QString ActionInterface::getName()
-{
-       return name;
-}
-
-/**
- * Called to initiate an action. This function is often
- * overwritten by the implementing action.
- *
- * @param status The status on which to initiate this action.
- * default is 0 to begin the action.
- */
-void ActionInterface::init(int status/*= 0*/)
-{
-//     Snapper::init();
-       setStatus(status);
-
-       if (status >= 0)
-       {
-               //graphicView->setMouseCursor(cursor);
-               updateMouseButtonHints();
-               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.
-       }
-}
-
-/**
- * Called when the mouse moves and this is the current action.
- * This function can be overwritten by the implementing action.
- * The default implementation keeps track of the mouse position.
- */
-void ActionInterface::mouseMoveEvent(QMouseEvent *)
-{
-}
-
-/**
- * Called when the left mouse button is pressed and this is the
- * current action.
- * This function can be overwritten by the implementing action.
- * The default implementation does nothing.
- */
-void ActionInterface::mousePressEvent(QMouseEvent *)
-{
-}
-
-/**
- * Called when the left mouse button is released and this is
- * the current action.
- * This function can be overwritten by the implementing action.
- * The default implementation does nothing.
- */
-void ActionInterface::mouseReleaseEvent(QMouseEvent *)
-{
-}
-
-/**
- * Called when a key is pressed and this is the current action.
- * This function can be overwritten by the implementing action.
- * The default implementation does nothing.
- */
-void ActionInterface::keyPressEvent(QKeyEvent * e)
-{
-    e->ignore();
-}
-
-/**
- * Called when a key is released and this is the current action.
- * This function can be overwritten by the implementing action.
- * The default implementation does nothing.
- */
-void ActionInterface::keyReleaseEvent(QKeyEvent * e)
-{
-    e->ignore();
-}
-
-/**
- * Coordinate event. Triggered usually from a command line.
- * This function can be overwritten by the implementing action.
- * The default implementation does nothing.
- */
-void ActionInterface::coordinateEvent(Vector *)
-{
-}
-
-/**
- * Called when a command from the command line is launched.
- * and this is the current action.
- * This function can be overwritten by the implementing action.
- * The default implementation does nothing.
- */
-void ActionInterface::commandEvent(CommandEvent *)
-{
-}
-
-/**
- * Must be implemented to return the currently available commands
- *  for the command line.
- */
-QStringList ActionInterface::getAvailableCommands()
-{
-       QStringList l;
-       return l;
-}
-
-/**
- * Sets the current status (progress) of this action.
- * The default implementation sets the class variable 'status' to the
- * given value and finishes the action if 'status' is negative.
- *
- * @param status Status number. It's up to the action implementor
- *               what the action uses the status for. However, a
- *               negative status number finishes the action. Usually
- *               the status of an action increases for every step
- *               of progress and decreases when the user goes one
- *               step back (i.e. presses the right mouse button).
- */
-void ActionInterface::setStatus(int value)
-{
-       status = value;
-
-       if (status < 0)
-       {
-               finish();
-               status = 0;
-       }
-
-       updateMouseButtonHints();
-       updateToolBar();
-       updateMouseCursor();
-}
-
-/**
- * @return Current status of this action.
- */
-int ActionInterface::getStatus()
-{
-       return status;
-}
-
-/**
- * Triggers this action. This should be called after all
- * data needed for this action was collected / set.
- * The default implementation does nothing.
- */
-void ActionInterface::trigger()
-{
-}
-
-/**
- * Should be overwritten to update the mouse button hints
- * wherever they might needed.
- */
-void ActionInterface::updateMouseButtonHints()
-{
-}
-
-/**
- * Should be overwritten to set the mouse cursor for this action.
- */
-void ActionInterface::updateMouseCursor()
-{
-}
-
-/**
- * Should be overwritten to set the toolbar for this action.
- */
-void ActionInterface::updateToolBar()
-{
-}
-
-/**
- * @return true, if the action is finished and can be deleted.
- */
-bool ActionInterface::isFinished()
-{
-       return finished;
-}
-
-/**
- * Forces a termination of the action without any cleanup.
- */
-void ActionInterface::setFinished()
-{
-       status = -1;
-}
-
-/**
- * Finishes this action.
- */
-void ActionInterface::finish()
-{
-       DEBUG->print("ActionInterface::finish");
-       status = -1;
-//     graphicView->setMouseCursor(RS2::ArrowCursor);
-       //graphicView->requestToolBar(RS2::ToolBarMain);
-       updateToolBar();
-//Maybe change this to SnapperOff()?
-//jlh: deleteSnapper();
-       hideOptions();
-       finished = true;
-//     Snapper::finish();              // Sets Snapper::finished = true
-       // I think this is where we want to update the screen...
-//     graphicView->redraw();
-       // 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");
-}
-
-/**
- * Called by the event handler to give this action a chance to
- * communicate with its predecessor.
- */
-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);
-//     Snapper::suspend();
-       snapperVisibility = graphicView->snapper.Visible();
-       previewVisibility = graphicView->preview.Visible();
-printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
-#endif
-}
-
-/**
- * Resumes an action after it was suspended.
- */
-void ActionInterface::resume()
-{
-#if 0
-if (suspendCount == 0)
-       printf("!!! RESUME BEFORE SUSPEND !!!\n");
-printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
-       updateMouseCursor();
-       updateToolBar();
-//     Snapper::resume();
-       graphicView->snapper.SetVisible(snapperVisibility);
-       graphicView->preview.SetVisible(previewVisibility);
-printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
-#endif
-}
-
-/**
- * Hides the tool options. Default implementation does nothing.
- */
-void ActionInterface::hideOptions()
-{
-//     Snapper::hideOptions();
-}
-
-/**
- * Shows the tool options. Default implementation does nothing.
- */
-void ActionInterface::showOptions()
-{
-//     Snapper::showOptions();
-}
-
-/**
- * Calls checkCommand() from the COMMANDS module.
- */
-bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
-       RS2::ActionType action)
-{
-       return COMMANDS->checkCommand(cmd, str, action);
-}
-
-/**
- * Calls command() from the COMMANDS module.
- */
-QString ActionInterface::command(const QString & cmd)
-{
-       return COMMANDS->command(cmd);
-}
-
-/**
- * Calls msgAvailableCommands() from the COMMANDS module.
- */
-QString ActionInterface::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->SnapPoint(e);
-}
-
-Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
-{
-       return graphicView->CatchEntity(e, level);
-}
-
-Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
-{
-       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)
-{
-}
-
-void ActionInterface::deleteSnapper(void)
-{
-}
-
-void ActionInterface::drawPreview(void)
-{
-}
-
-void ActionInterface::clearPreview(void)
-{
-}
-
-void ActionInterface::deletePreview(void)
-{
-}