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.
38 * Sets the entity container on which the action class inherited from this
41 * @param name Action name. This can be used internally for debugging mainly.
42 * @param container Entity container this action operates on.
43 * @param graphicView Graphic view instance this action operates on. Please
44 * note that an action belongs to this view.
46 ActionInterface::ActionInterface(const char * name, EntityContainer & ec,
47 GraphicView & gv): graphicView(&gv), container(&ec),
48 // snapperVisibility(false), previewVisibility(false), suspendCount(0)
50 snapperVisibility(true), previewVisibility(true), suspendCount(0)
52 DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\"", name);
58 // Graphic provides a pointer to the graphic if the entity container is a
59 // graphic (i.e. can also hold layers).
60 graphic = ec.getGraphic();
62 // Document pointer will be used for undo / redo
63 document = ec.getDocument();
65 // \o/ \o/ \o/ BY GRABTHAR'S HAMMER, IT HAS BEEN EXPUNGED!!! \o/ \o/ \o/
66 // This is here until I can figure out a better way to contain all of this
67 // circular referential nonsense that exists in this codebase. It will be
68 // expunged, by Grabthar's Hammer!
69 // graphicView->snapper.SetContainer(container);
70 // graphicView->snapper.SetGraphicView(graphicView); // <-- THIS is what I mean! INSANE!
71 // Not all actions use these. Perhaps we need to pass params to the contructor
72 // in order to set these? Setting the default to true for both?
73 // graphicView->snapper.SetVisible();
74 graphicView->SetSnapperVisible();
75 graphicView->preview.SetVisible();
77 DEBUG->print("ActionInterface::ActionInterface: Setting up action: \"%s\": OK", name);
78 printf("ActionInterface::ActionInterface() [%08X]\n", this);
84 /*virtual*/ ActionInterface::~ActionInterface()
86 // would be pure virtual now:
88 //JLH: Only it isn't pure virtual...
89 printf("ActionInterface::~ActionInterface() [%08X]\n", this);
93 * Must be implemented to return the ID of this action.
95 * @todo no default implementation
97 RS2::ActionType ActionInterface::rtti()
99 return RS2::ActionNone;
103 * @return name of this action
105 QString ActionInterface::getName()
111 * Called to initiate an action. This function is often
112 * overwritten by the implementing action.
114 * @param status The status on which to initiate this action.
115 * default is 0 to begin the action.
117 void ActionInterface::init(int status/*= 0*/)
124 //graphicView->setMouseCursor(cursor);
125 updateMouseButtonHints();
129 else // status < 0, e.g. this action is finished
131 // graphicView->snapper.SetVisible(false);
132 graphicView->SetSnapperVisible(false);
133 graphicView->preview.SetVisible(false);
134 graphicView->preview.clear();
135 graphicView->redraw(); //hm.
140 * Called when the mouse moves and this is the current action.
141 * This function can be overwritten by the implementing action.
142 * The default implementation keeps track of the mouse position.
144 void ActionInterface::mouseMoveEvent(QMouseEvent *)
149 * Called when the left mouse button is pressed and this is the
151 * This function can be overwritten by the implementing action.
152 * The default implementation does nothing.
154 void ActionInterface::mousePressEvent(QMouseEvent *)
159 * Called when the left mouse button is released and this is
160 * the current action.
161 * This function can be overwritten by the implementing action.
162 * The default implementation does nothing.
164 void ActionInterface::mouseReleaseEvent(QMouseEvent *)
169 * Called when a key is pressed and this is the current action.
170 * This function can be overwritten by the implementing action.
171 * The default implementation does nothing.
173 void ActionInterface::keyPressEvent(QKeyEvent * e)
179 * Called when a key is released and this is the current action.
180 * This function can be overwritten by the implementing action.
181 * The default implementation does nothing.
183 void ActionInterface::keyReleaseEvent(QKeyEvent * e)
189 * Coordinate event. Triggered usually from a command line.
190 * This function can be overwritten by the implementing action.
191 * The default implementation does nothing.
193 void ActionInterface::coordinateEvent(Vector *)
198 * Called when a command from the command line is launched.
199 * and this is the current action.
200 * This function can be overwritten by the implementing action.
201 * The default implementation does nothing.
203 void ActionInterface::commandEvent(CommandEvent *)
208 * Must be implemented to return the currently available commands
209 * for the command line.
211 QStringList ActionInterface::getAvailableCommands()
218 * Sets the current status (progress) of this action.
219 * The default implementation sets the class variable 'status' to the
220 * given value and finishes the action if 'status' is negative.
222 * @param status Status number. It's up to the action implementor
223 * what the action uses the status for. However, a
224 * negative status number finishes the action. Usually
225 * the status of an action increases for every step
226 * of progress and decreases when the user goes one
227 * step back (i.e. presses the right mouse button).
229 void ActionInterface::setStatus(int value)
239 updateMouseButtonHints();
245 * @return Current status of this action.
247 int ActionInterface::getStatus()
253 * Triggers this action. This should be called after all
254 * data needed for this action was collected / set.
255 * The default implementation does nothing.
257 void ActionInterface::trigger()
262 * Should be overwritten to update the mouse button hints
263 * wherever they might needed.
265 void ActionInterface::updateMouseButtonHints()
270 * Should be overwritten to set the mouse cursor for this action.
272 void ActionInterface::updateMouseCursor()
277 * Should be overwritten to set the toolbar for this action.
279 void ActionInterface::updateToolBar()
284 * @return true, if the action is finished and can be deleted.
286 bool ActionInterface::isFinished()
292 * Forces a termination of the action without any cleanup.
294 void ActionInterface::setFinished()
300 * Finishes this action.
302 void ActionInterface::finish()
304 DEBUG->print("ActionInterface::finish");
306 // graphicView->setMouseCursor(RS2::ArrowCursor);
307 //graphicView->requestToolBar(RS2::ToolBarMain);
309 //Maybe change this to SnapperOff()?
310 //jlh: deleteSnapper();
313 // Snapper::finish(); // Sets Snapper::finished = true
314 // I think this is where we want to update the screen...
315 // graphicView->redraw();
317 // graphicView->snapper.SetVisible(false);
318 graphicView->SetSnapperVisible(false);
319 graphicView->preview.SetVisible(false);
320 // graphicView->preview.clear();
321 graphicView->redraw(); //hm.
322 DEBUG->print("ActionInterface::finish: OK");
326 * Called by the event handler to give this action a chance to
327 * communicate with its predecessor.
329 void ActionInterface::setPredecessor(ActionInterface * p)
335 Here is a problem. suspend() and resume() don't do what they should:
336 The problem is that Actions are modifying a shared resource though it's acting
337 as if it were not. Case in point below: ActionZoomPan sets the snapper/preview
338 visibility to FALSE and then EventHandler calls suspend() here, which queries
339 the graphicView to see what its state is. We need to fix this...!
341 This ties into the problem where we have GraphicView pointers scattered all
342 over the place. We need to fix that too!
345 * Suspends this action while another action takes place.
347 void ActionInterface::suspend()
350 printf("ActionInterface::suspend(%i): [%08X] ", ++suspendCount, this);
351 // Maybe this is where we need to save the state of the snapper
352 // & preview objects???
353 // graphicView->setMouseCursor(RS2::ArrowCursor);
354 // Snapper::suspend();
355 snapperVisibility = graphicView->snapper.Visible();
356 previewVisibility = graphicView->preview.Visible();
357 printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
362 * Resumes an action after it was suspended.
364 void ActionInterface::resume()
367 if (suspendCount == 0)
368 printf("!!! RESUME BEFORE SUSPEND !!!\n");
369 printf("ActionInterface::resume(%i): [%08X] ", suspendCount, this);
372 // Snapper::resume();
373 graphicView->snapper.SetVisible(snapperVisibility);
374 graphicView->preview.SetVisible(previewVisibility);
375 printf("snapperVisibility = %s, previewVisibility = %s...\n", (snapperVisibility ? "true" : "FALSE"), (previewVisibility ? "true" : "FALSE"));
380 * Hides the tool options. Default implementation does nothing.
382 void ActionInterface::hideOptions()
384 // Snapper::hideOptions();
388 * Shows the tool options. Default implementation does nothing.
390 void ActionInterface::showOptions()
392 // Snapper::showOptions();
396 * Calls checkCommand() from the COMMANDS module.
398 bool ActionInterface::checkCommand(const QString & cmd, const QString & str,
399 RS2::ActionType action)
401 return COMMANDS->checkCommand(cmd, str, action);
405 * Calls command() from the COMMANDS module.
407 QString ActionInterface::command(const QString & cmd)
409 return COMMANDS->command(cmd);
413 * Calls msgAvailableCommands() from the COMMANDS module.
415 QString ActionInterface::msgAvailableCommands()
417 return COMMANDS->msgAvailableCommands();
420 // This is here to save some typing in all the action* classes derived from
421 // this one. May go away in the future.
422 Vector ActionInterface::snapPoint(QMouseEvent * e)
424 // return graphicView->snapper.snapPoint(e);
425 return graphicView->SnapPoint(e);
428 Entity * ActionInterface::catchEntity(QMouseEvent * e, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
430 return graphicView->CatchEntity(e, level);
433 Entity * ActionInterface::catchEntity(Vector v, RS2::ResolveLevel level/*= RS2::ResolveNone*/)
435 return graphicView->CatchEntity(v, level);
438 #warning "!!! Dummy functions need to be deleted once all actions no longer use these !!!"
439 //dummy functions, will delete later...
440 void ActionInterface::drawSnapper(void)
444 void ActionInterface::deleteSnapper(void)
448 void ActionInterface::drawPreview(void)
452 void ActionInterface::clearPreview(void)
456 void ActionInterface::deletePreview(void)