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 // Is it? Doesn't seem like it. Whenever you change snap types, the preview disappears.
57 // Not sure what's going on with that.
58 //This doesn't work properly; not sure why that is...
59 //Actually, it's working perfectly. Now we just need to propagate the fixes everywhere. :-/
60 // We'll use snapperVisibility for the save/restore functionality...
61 snapperVisibility = graphicView->SnapperVisible();
67 // Graphic provides a pointer to the graphic if the entity container is a
68 // drawing (i.e. can also hold layers).
69 #warning "!!! Need to rename graphic to drawing !!!"
70 graphic = ec.GetDrawing();
72 // Document pointer will be used for undo / redo
73 document = ec.getDocument();
75 // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
77 // This is here until I can figure out a better way to contain all of this
78 // circular referential nonsense that exists in this codebase. It will be
79 // expunged, by Grabthar's Hammer!
80 // graphicView->snapper.SetContainer(container);
81 // graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
82 // Not all actions use these. Perhaps we need to pass params to the contructor
83 // in order to set these? Setting the default to true for both?
84 // graphicView->snapper.SetVisible();
85 graphicView->SetSnapperVisible();
86 graphicView->preview.SetVisible();
88 DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
89 //printf("ActionInterface::ActionInterface() [%08X]\n", this);
95 /*virtual*/ ActionInterface::~ActionInterface()
97 // would be pure virtual now:
99 //JLH: Only it isn't pure virtual...
100 //printf("ActionInterface::~ActionInterface() [%08X]\n", this);
102 // We'll use snapperVisibility for the save/restore functionality...
103 graphicView->SetSnapperVisible(snapperVisibility);
107 * Must be implemented to return the ID of this action.
109 * @todo no default implementation
111 RS2::ActionType ActionInterface::rtti()
113 return RS2::ActionNone;
117 * @return name of this action
119 QString ActionInterface::getName()
125 * Called to initiate an action. This function is often
126 * overwritten by the implementing action.
128 * @param status The status on which to initiate this action.
129 * default is 0 to begin the action.
131 void ActionInterface::init(int status/*= 0*/)
138 //graphicView->setMouseCursor(cursor);
139 updateMouseButtonHints();
143 else // status < 0, e.g. this action is finished
145 // graphicView->snapper.SetVisible(false);
146 graphicView->SetSnapperVisible(false);
147 graphicView->preview.SetVisible(false);
148 graphicView->preview.clear();
149 graphicView->redraw(); //hm.
154 * Called when the mouse moves and this is the current action.
155 * This function can be overwritten by the implementing action.
156 * The default implementation keeps track of the mouse position.
158 void ActionInterface::mouseMoveEvent(QMouseEvent *)
163 * Called when the left mouse button is pressed and this is the
165 * This function can be overwritten by the implementing action.
166 * The default implementation does nothing.
168 void ActionInterface::mousePressEvent(QMouseEvent *)
173 * Called when the left mouse button is released and this is
174 * the current action.
175 * This function can be overwritten by the implementing action.
176 * The default implementation does nothing.
178 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
183 * Called when a key is pressed and this is the current action.
184 * This function can be overwritten by the implementing action.
185 * The default implementation does nothing.
187 void ActionInterface::keyPressEvent(QKeyEvent * e)
193 * Called when a key is released and this is the current action.
194 * This function can be overwritten by the implementing action.
195 * The default implementation does nothing.
197 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
203 * Coordinate event. Triggered usually from a command line.
204 * This function can be overwritten by the implementing action.
205 * The default implementation does nothing.
207 void ActionInterface::coordinateEvent(Vector *)
212 * Called when a command from the command line is launched.
213 * and this is the current action.
214 * This function can be overwritten by the implementing action.
215 * The default implementation does nothing.
217 void ActionInterface::commandEvent(CommandEvent *)
222 * Must be implemented to return the currently available commands
223 * for the command line.
225 QStringList ActionInterface::getAvailableCommands()
232 * Sets the current status (progress) of this action.
233 * The default implementation sets the class variable 'status' to the
234 * given value and finishes the action if 'status' is negative.
236 * @param status Status number. It's up to the action implementor
237 * what the action uses the status for. However, a
238 * negative status number finishes the action. Usually
239 * the status of an action increases for every step
240 * of progress and decreases when the user goes one
241 * step back (i.e. presses the right mouse button).
243 void ActionInterface::setStatus(int value)
253 updateMouseButtonHints();
259 * @return Current status of this action.
261 int ActionInterface::getStatus()
267 * Triggers this action. This should be called after all
268 * data needed for this action was collected / set.
269 * The default implementation does nothing.
271 void ActionInterface::trigger()
276 * Should be overwritten to update the mouse button hints
277 * wherever they might needed.
279 void ActionInterface::updateMouseButtonHints()
284 * Should be overwritten to set the mouse cursor for this action.
286 void ActionInterface::updateMouseCursor()
291 * Should be overwritten to set the toolbar for this action.
293 void ActionInterface::updateToolBar()
298 * @return true, if the action is finished and can be deleted.
300 bool ActionInterface::isFinished()
306 * Forces a termination of the action without any cleanup.
308 void ActionInterface::setFinished()
314 * Finishes this action.
316 void ActionInterface::finish()
318 DEBUG->print("ActionInterface::finish");
320 // graphicView->setMouseCursor(RS2::ArrowCursor);
321 //graphicView->requestToolBar(RS2::ToolBarMain);
323 //Maybe change this to SnapperOff()?
324 //jlh: deleteSnapper();
327 // Snapper::finish(); // Sets Snapper::finished = true
328 // I think this is where we want to update the screen...
329 // graphicView->redraw();
331 // graphicView->snapper.SetVisible(false);
332 graphicView->SetSnapperVisible(false);
333 //Short circuit the destructor fuxoring with this:
334 //snapperVisibility = false;
335 //Only it causes other stuff to be fuxorred... Grr... Not sure how to fix this...
336 graphicView->preview.SetVisible(false);
337 // graphicView->preview.clear();
338 graphicView->redraw(); //hm.
339 DEBUG->print("ActionInterface::finish: OK");
343 * Called by the event handler to give this action a chance to
344 * communicate with its predecessor.
346 void ActionInterface::setPredecessor(ActionInterface * p)
352 Here is a problem. suspend() and resume() don't do what they should:
353 The problem is that Actions are modifying a shared resource though it's acting
354 as if it were not. Case in point below: ActionZoomPan sets the snapper/preview
355 visibility to FALSE and then EventHandler calls suspend() here, which queries
356 the graphicView to see what its state is. We need to fix this...!
358 This ties into the problem where we have GraphicView pointers scattered all
359 over the place. We need to fix that too!
362 * Suspends this action while another action takes place.
364 void ActionInterface::suspend()
367 printf("ActionInterface::suspend(%i): [%08X] ", ++suspendCount, this);
368 // Maybe this is where we need to save the state of the snapper
369 // & preview objects???
370 // graphicView->setMouseCursor(RS2::ArrowCursor);
371 // Snapper::suspend();
372 snapperVisibility = graphicView->snapper.Visible();
373 previewVisibility = graphicView->preview.Visible();
374 printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
379 * Resumes an action after it was suspended.
381 void ActionInterface::resume()
384 if (suspendCount == 0)
385 printf("!!! RESUME BEFORE SUSPEND !!!\n");
386 printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
389 // Snapper::resume();
390 graphicView->snapper.SetVisible(snapperVisibility);
391 graphicView->preview.SetVisible(previewVisibility);
392 printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
397 * Hides the tool options. Default implementation does nothing.
399 void ActionInterface::hideOptions()
401 // Snapper::hideOptions();
405 * Shows the tool options. Default implementation does nothing.
407 void ActionInterface::showOptions()
409 // Snapper::showOptions();
413 * Calls checkCommand() from the COMMANDS module.
415 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
416 RS2::ActionType action)
418 return COMMANDS->checkCommand(cmd, str, action);
422 * Calls command() from the COMMANDS module.
424 QString ActionInterface::command(const QString & cmd)
426 return COMMANDS->command(cmd);
430 * Calls msgAvailableCommands() from the COMMANDS module.
432 QString ActionInterface::msgAvailableCommands()
434 return COMMANDS->msgAvailableCommands();
437 // This is here to save some typing in all the action* classes derived from
438 // this one. May go away in the future.
439 Vector ActionInterface::snapPoint(QMouseEvent * e)
441 // return graphicView->snapper.snapPoint(e);
442 return graphicView->SnapPoint(e);
445 Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
447 return graphicView->CatchEntity(e, level);
450 Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
452 return graphicView->CatchEntity(v, level);
455 #warning "!!! Dummy functions need to be deleted once all actions no longer use these !!!"
456 //dummy functions, will delete later...
457 void ActionInterface::drawSnapper(void)
461 void ActionInterface::deleteSnapper(void)
465 void ActionInterface::drawPreview(void)
469 void ActionInterface::clearPreview(void)
473 void ActionInterface::deletePreview(void)