3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/22/2010 Added this text. :-)
15 // JLH 08/09/2010 Preparation for removal of GraphicView object from this
19 #include "actioninterface.h"
23 #include "dialogfactory.h"
24 #include "entitycontainer.h"
25 #include "graphicview.h"
29 I think what's needed here is for the constructor to save the state of the snapper
30 and to restore it in the destructor. This, of course, assumes that the actions are
31 created and used in a certain order, perhaps that needs enforcement? Dunno, but worth
32 a try as suspend() and resume() seem to fuck it up badly.
33 #define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__))
34 on MS it's: __declspec(deprecated)
40 * Sets the entity container on which the action class inherited from this
43 * @param name Action name. This can be used internally for debugging mainly.
44 * @param container Entity container this action operates on.
45 * @param graphicView Graphic view instance this action operates on. Please
46 * note that an action belongs to this view.
48 ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
49 GraphicView & gv): graphicView(&gv), container(&ec),
50 // snapperVisibility(false), previewVisibility(false), suspendCount(0)
52 snapperVisibility(true), previewVisibility(true), suspendCount(0)
54 DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
56 //This doesn't work properly; not sure why that is...
57 //Actually, it's working perfectly. Now we just need to propagate the fixes everywhere. :-/
58 // We'll use snapperVisibility for the save/restore functionality...
59 snapperVisibility = graphicView->SnapperVisible();
65 // Graphic provides a pointer to the graphic if the entity container is a
66 // graphic (i.e. can also hold layers).
67 graphic = ec.getGraphic();
69 // Document pointer will be used for undo / redo
70 document = ec.getDocument();
72 // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
74 // This is here until I can figure out a better way to contain all of this
75 // circular referential nonsense that exists in this codebase. It will be
76 // expunged, by Grabthar's Hammer!
77 // graphicView->snapper.SetContainer(container);
78 // graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
79 // Not all actions use these. Perhaps we need to pass params to the contructor
80 // in order to set these? Setting the default to true for both?
81 // graphicView->snapper.SetVisible();
82 graphicView->SetSnapperVisible();
83 graphicView->preview.SetVisible();
85 DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
86 //printf("ActionInterface::ActionInterface() [%08X]\n", this);
92 /*virtual*/ ActionInterface::~ActionInterface()
94 // would be pure virtual now:
96 //JLH: Only it isn't pure virtual...
97 //printf("ActionInterface::~ActionInterface() [%08X]\n", this);
99 // We'll use snapperVisibility for the save/restore functionality...
100 graphicView->SetSnapperVisible(snapperVisibility);
104 * Must be implemented to return the ID of this action.
106 * @todo no default implementation
108 RS2::ActionType ActionInterface::rtti()
110 return RS2::ActionNone;
114 * @return name of this action
116 QString ActionInterface::getName()
122 * Called to initiate an action. This function is often
123 * overwritten by the implementing action.
125 * @param status The status on which to initiate this action.
126 * default is 0 to begin the action.
128 void ActionInterface::init(int status/*= 0*/)
135 //graphicView->setMouseCursor(cursor);
136 updateMouseButtonHints();
140 else // status < 0, e.g. this action is finished
142 // graphicView->snapper.SetVisible(false);
143 graphicView->SetSnapperVisible(false);
144 graphicView->preview.SetVisible(false);
145 graphicView->preview.clear();
146 graphicView->redraw(); //hm.
151 * Called when the mouse moves and this is the current action.
152 * This function can be overwritten by the implementing action.
153 * The default implementation keeps track of the mouse position.
155 void ActionInterface::mouseMoveEvent(QMouseEvent *)
160 * Called when the left mouse button is pressed and this is the
162 * This function can be overwritten by the implementing action.
163 * The default implementation does nothing.
165 void ActionInterface::mousePressEvent(QMouseEvent *)
170 * Called when the left mouse button is released and this is
171 * the current action.
172 * This function can be overwritten by the implementing action.
173 * The default implementation does nothing.
175 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
180 * Called when a key is pressed and this is the current action.
181 * This function can be overwritten by the implementing action.
182 * The default implementation does nothing.
184 void ActionInterface::keyPressEvent(QKeyEvent * e)
190 * Called when a key is released and this is the current action.
191 * This function can be overwritten by the implementing action.
192 * The default implementation does nothing.
194 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
200 * Coordinate event. Triggered usually from a command line.
201 * This function can be overwritten by the implementing action.
202 * The default implementation does nothing.
204 void ActionInterface::coordinateEvent(Vector *)
209 * Called when a command from the command line is launched.
210 * and this is the current action.
211 * This function can be overwritten by the implementing action.
212 * The default implementation does nothing.
214 void ActionInterface::commandEvent(CommandEvent *)
219 * Must be implemented to return the currently available commands
220 * for the command line.
222 QStringList ActionInterface::getAvailableCommands()
229 * Sets the current status (progress) of this action.
230 * The default implementation sets the class variable 'status' to the
231 * given value and finishes the action if 'status' is negative.
233 * @param status Status number. It's up to the action implementor
234 * what the action uses the status for. However, a
235 * negative status number finishes the action. Usually
236 * the status of an action increases for every step
237 * of progress and decreases when the user goes one
238 * step back (i.e. presses the right mouse button).
240 void ActionInterface::setStatus(int value)
250 updateMouseButtonHints();
256 * @return Current status of this action.
258 int ActionInterface::getStatus()
264 * Triggers this action. This should be called after all
265 * data needed for this action was collected / set.
266 * The default implementation does nothing.
268 void ActionInterface::trigger()
273 * Should be overwritten to update the mouse button hints
274 * wherever they might needed.
276 void ActionInterface::updateMouseButtonHints()
281 * Should be overwritten to set the mouse cursor for this action.
283 void ActionInterface::updateMouseCursor()
288 * Should be overwritten to set the toolbar for this action.
290 void ActionInterface::updateToolBar()
295 * @return true, if the action is finished and can be deleted.
297 bool ActionInterface::isFinished()
303 * Forces a termination of the action without any cleanup.
305 void ActionInterface::setFinished()
311 * Finishes this action.
313 void ActionInterface::finish()
315 DEBUG->print("ActionInterface::finish");
317 // graphicView->setMouseCursor(RS2::ArrowCursor);
318 //graphicView->requestToolBar(RS2::ToolBarMain);
320 //Maybe change this to SnapperOff()?
321 //jlh: deleteSnapper();
324 // Snapper::finish(); // Sets Snapper::finished = true
325 // I think this is where we want to update the screen...
326 // graphicView->redraw();
328 // graphicView->snapper.SetVisible(false);
329 graphicView->SetSnapperVisible(false);
330 //Short circuit the destructor fuxoring with this:
331 //snapperVisibility = false;
332 //Only it causes other stuff to be fuxorred... Grr... Not sure how to fix this...
333 graphicView->preview.SetVisible(false);
334 // graphicView->preview.clear();
335 graphicView->redraw(); //hm.
336 DEBUG->print("ActionInterface::finish: OK");
340 * Called by the event handler to give this action a chance to
341 * communicate with its predecessor.
343 void ActionInterface::setPredecessor(ActionInterface * p)
349 Here is a problem. suspend() and resume() don't do what they should:
350 The problem is that Actions are modifying a shared resource though it's acting
351 as if it were not. Case in point below: ActionZoomPan sets the snapper/preview
352 visibility to FALSE and then EventHandler calls suspend() here, which queries
353 the graphicView to see what its state is. We need to fix this...!
355 This ties into the problem where we have GraphicView pointers scattered all
356 over the place. We need to fix that too!
359 * Suspends this action while another action takes place.
361 void ActionInterface::suspend()
364 printf("ActionInterface::suspend(%i): [%08X] ", ++suspendCount, this);
365 // Maybe this is where we need to save the state of the snapper
366 // & preview objects???
367 // graphicView->setMouseCursor(RS2::ArrowCursor);
368 // Snapper::suspend();
369 snapperVisibility = graphicView->snapper.Visible();
370 previewVisibility = graphicView->preview.Visible();
371 printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
376 * Resumes an action after it was suspended.
378 void ActionInterface::resume()
381 if (suspendCount == 0)
382 printf("!!! RESUME BEFORE SUSPEND !!!\n");
383 printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
386 // Snapper::resume();
387 graphicView->snapper.SetVisible(snapperVisibility);
388 graphicView->preview.SetVisible(previewVisibility);
389 printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
394 * Hides the tool options. Default implementation does nothing.
396 void ActionInterface::hideOptions()
398 // Snapper::hideOptions();
402 * Shows the tool options. Default implementation does nothing.
404 void ActionInterface::showOptions()
406 // Snapper::showOptions();
410 * Calls checkCommand() from the COMMANDS module.
412 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
413 RS2::ActionType action)
415 return COMMANDS->checkCommand(cmd, str, action);
419 * Calls command() from the COMMANDS module.
421 QString ActionInterface::command(const QString & cmd)
423 return COMMANDS->command(cmd);
427 * Calls msgAvailableCommands() from the COMMANDS module.
429 QString ActionInterface::msgAvailableCommands()
431 return COMMANDS->msgAvailableCommands();
434 // This is here to save some typing in all the action* classes derived from
435 // this one. May go away in the future.
436 Vector ActionInterface::snapPoint(QMouseEvent * e)
438 // return graphicView->snapper.snapPoint(e);
439 return graphicView->SnapPoint(e);
442 Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
444 return graphicView->CatchEntity(e, level);
447 Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
449 return graphicView->CatchEntity(v, level);
452 #warning "!!! Dummy functions need to be deleted once all actions no longer use these !!!"
453 //dummy functions, will delete later...
454 void ActionInterface::drawSnapper(void)
458 void ActionInterface::deleteSnapper(void)
462 void ActionInterface::drawPreview(void)
466 void ActionInterface::clearPreview(void)
470 void ActionInterface::deletePreview(void)