Computer Assited Medical Intervention Tool Kit  version 4.1
Action.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef ACTION_H
27 #define ACTION_H
28 
29 // -- Core stuff
30 #include "CamiTKAPI.h"
31 #include <HistoryItem.h>
32 #include <Application.h>
33 
34 #include <QSet>
35 #include <QWidget>
36 #include <QString>
37 #include <QAction>
38 
39 
40 namespace camitk {
41 
42 class ActionExtension;
43 class Property;
44 
207 class CAMITK_API Action : public QObject {
208  Q_OBJECT
209 
210 public:
211 
213  Action(ActionExtension*);
214 
216  ~Action() override;
217 
218 #ifdef ERROR
219 #define CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD ERROR
220 #undef ERROR
221 #endif
222  enum ApplyStatus {
224  SUCCESS,
225  ERROR,
226  WARNING,
227  ABORTED,
228  TRIGGERED
229  };
230 
231 #ifdef CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
232 #define ERROR CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
233 #endif
234 
236  static QString getStatusAsString(ApplyStatus);
237 
238 public slots:
244  ApplyStatus trigger(QWidget* parent = nullptr);
245 
255  virtual ApplyStatus apply() = 0;
256 
264  ApplyStatus applyAndRegister();
265 
266 public:
267 
270 
279  ApplyStatus applyInPipeline();
281 
285  void setInputComponents(ComponentList inputs);
286 
288  void setInputComponent(Component* input);
289 
291  ComponentList getOutputComponents();
292 
294  Component* getOutputComponent();
296 
300 
308  QAction* getQAction();
309 
311  QString getName() const {
312  return name;
313  };
314 
316  QString getDescription() const {
317  return description;
318  };
319 
321  QString getComponent() const {
322  return component;
323  };
324 
326  QString getFamily() const {
327  return family;
328  };
329 
331  QString getExtensionName() const;
332 
334  QStringList getTag() const {
335  return tags;
336  };
337 
339  bool getEmbedded() const {
340  return isEmbedded;
341  };
343 
346 
368  virtual QWidget* getWidget();
369 
371  virtual QPixmap getIcon();
372 
374  const ComponentList getTargets() const;
376 
380  bool getAutoUpdateProperties() const;
381 
383  void setAutoUpdateProperties(bool);
384 
391  Q_INVOKABLE virtual Property* getProperty(QString name);
392 
401  virtual bool addParameter(Property*);
403 
406 
411  void applyTargetPosition(Component* input, Component* target);
412 
419  void applyTargetPosition(Component* input, Component* target, Application::TargetPositionningPolicy policy);
421 
422 protected:
427  void setName(QString name);
430 
432  void setDescription(QString description);
433 
435  void setComponent(QString component);
436 
438  void setFamily(QString family);
439 
441  void addTag(QString tag);
442 
444  void setEmbedded(bool isEmbedded);
445 
447  void setIcon(QPixmap);
448 
450  QWidget* actionWidget;
451 
452 
454 
455 
456 
457 private:
459  QString name;
460 
462  QString description;
463 
465  QString component;
466 
468  QString family;
469 
471  QStringList tags;
472 
474  bool isEmbedded;
475 
477  ActionExtension* extension;
478 
480  QPixmap icon;
481 
483  QAction* qAction;
484 
486  QMap<QString, Property*> parameterMap;
487 
497  ComponentList targetComponents;
498 
500  bool autoUpdateProperties;
501 
504 
512  HistoryItem* item;
513 
517  ComponentList topLevelSelectedComponents;
518 
523  void preProcess();
524 
529  void postProcess();
531 
534 
543  ComponentList aliveBeforeComponents;
544 
548  ComponentList outputComponents;
549 
550 
556  void preProcessInPipeline();
557 
562  void postProcessInPipeline();
563 
564 
565 
567 
568 
569 
570 };
571 
572 }
573 
574 // -------------------- declare the interface for QPluginLoader --------------------
575 Q_DECLARE_INTERFACE(camitk::Action, "TIMC-IMAG.Action/2.1") //TODO use svn version?
576 
577 #endif // ACTION_H
578 
579 
580 
581 
camitk::Action::setFamily
void setFamily(QString family)
the name of the family in which this action is associated
Definition: Action.cpp:129
camitk::Action::isEmbedded
bool isEmbedded
is the widget embedded or not
Definition: Action.h:497
camitk::Action::getIcon
virtual QPixmap getIcon()
the icon to personalize the action (no icon by default)
Definition: Action.cpp:154
camitk::Component::getTransform
const vtkSmartPointer< vtkTransform > getTransform() const override
Get the transformation with respect to the parent frame.
Definition: sdk/libraries/core/component/Component.cpp:666
camitk::Action::item
HistoryItem * item
Definition: Action.h:535
CAMITK_WARNING
#define CAMITK_WARNING(MSG)
Log for warning verbosity (the most common one) Will appear by default.
Definition: Log.h:263
camitk::Action::description
QString description
the descriptionof the action
Definition: Action.h:485
camitk::Action::preProcess
void preProcess()
Save the number of top level components loaded in memory before applying the action.
Definition: Action.cpp:328
camitk::Component::setParentFrame
void setParentFrame(InterfaceFrame *frame, bool keepTransform=true) override
Set the parent frame and update or not its transform during the parent transition.
Definition: sdk/libraries/core/component/Component.cpp:638
camitk::Action::qAction
QAction * qAction
the corresponding QAction
Definition: Action.h:506
camitk::Action::WARNING
@ WARNING
some (partial) error occured during the application of the algorithm
Definition: Action.h:249
CamiTKAPI.h
camitk::Action::SUCCESS
@ SUCCESS
everything went according to plan
Definition: Action.h:247
camitk::Component::isSelected
virtual bool isSelected() const
Check if this data component is selected.
Definition: sdk/libraries/core/component/Component.h:833
camitk::Action::getOutputComponent
Component * getOutputComponent()
Returns the output Components in case of only one Component.
Definition: Action.cpp:318
ActionViewer.h
camitk::Action::ABORTED
@ ABORTED
the action was aborted before completion
Definition: Action.h:250
camitk::ActionWidget
Build a default widget for a given action using its Qt properties. It should be good enough in most o...
Definition: ActionWidget.h:96
camitk::Application::getAllComponents
static const ComponentList & getAllComponents()
get the current application wide list of all Components.
Definition: Application.cpp:889
camitk::Action::ApplyStatus
ApplyStatus
Definition: Action.h:246
camitk::Action::setName
void setName(QString name)
Definition: Action.cpp:113
camitk::Action::getQAction
QAction * getQAction()
Get the corresponding QAction.
Definition: Action.cpp:183
camitk::HistoryItem::addProperty
void addProperty(QByteArray name, QVariant value)
Add a property of the corresponding action to the history item.
Definition: HistoryItem.cpp:65
camitk::Action::setAutoUpdateProperties
void setAutoUpdateProperties(bool)
are the properties to be udpated every time the user makes a change in the widget (default is false)?
Definition: Action.cpp:404
camitk::Action::outputComponents
ComponentList outputComponents
List returned by getOutputComponents()
Definition: Action.h:571
camitk::Action::setComponent
void setComponent(QString component)
the name of the component class that can be used by this action
Definition: Action.cpp:124
Component::isInstanceOf
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
camitk::Action::ERROR
@ ERROR
apply() failed : an error occured (usually it means that the apply() was interrupted)
Definition: Action.h:248
PropertyObject.h
camitk::Action::tags
QStringList tags
the name of the tag called this action
Definition: Action.h:494
camitk::Action::actionWidget
QWidget * actionWidget
the action widget
Definition: Action.h:473
camitk::Action::targetComponents
ComponentList targetComponents
The list of valid (regarding the component property) components for which this action is called.
Definition: Action.h:520
camitk::Action::getTargets
const ComponentList getTargets() const
the currently selected and valid (regarding the component property) components, for which this action...
Definition: Action.cpp:159
camitk::Action::getName
QString getName() const
get the name of the action
Definition: Action.h:334
camitk::Action::~Action
~Action() override
Destructor.
Definition: Action.cpp:73
camitk::HistoryComponent
HistoryComponent class describes the component information (name, type) stored in the history.
Definition: HistoryComponent.h:82
Action.h
camitk::HistoryItem::setInputHistoryComponents
void setInputHistoryComponents(QList< HistoryComponent > inputHistoryComponents)
Set the input components of the history item action.
Definition: HistoryItem.cpp:75
camitk::Application::addHistoryItem
static void addHistoryItem(HistoryItem item)
Add the history item to the application history.
Definition: Application.cpp:928
camitk::Action::postProcess
void postProcess()
Register the action in the history.
Definition: Action.cpp:361
camitk::Action::postProcessInPipeline
void postProcessInPipeline()
Set the right output component list so that the method getOutputComponents() can be called.
Definition: Action.cpp:388
camitk::Application::getSelectedComponents
static const ComponentList & getSelectedComponents()
get the currently selected Components.
Definition: Application.cpp:894
camitk::Action::setEmbedded
void setEmbedded(bool isEmbedded)
set the embedded property (an action is embedded by default, unless specified otherwise by explicitly...
Definition: Action.cpp:139
camitk::Action::Action
Action(ActionExtension *)
Default Constructor: the ActionExtension is needed.
Definition: Action.cpp:62
camitk::Action::getStatusAsString
static QString getStatusAsString(ApplyStatus)
Definition: Action.cpp:87
camitk::Action::getExtensionName
QString getExtensionName() const
the name of the extension in the family in which this action is associated
Definition: Action.cpp:149
camitk::Action::applyInPipeline
ApplyStatus applyInPipeline()
This method encapsulates the apply() method.
Definition: Action.cpp:267
ActionExtension.h
camitk::Action::setInputComponents
void setInputComponents(ComponentList inputs)
Specify the input Component(s) Only applyInPipeline() should be called with this method (maybe apply)...
Definition: Action.cpp:289
camitk::Property
This class describes a property that can be used in components and actions or any class that needs to...
Definition: Property.h:314
ActionWidget.h
camitk::Property::getName
const QString & getName() const
get the name of the property
Definition: Property.cpp:73
camitk::Action::addTag
void addTag(QString tag)
add a tag to the tags list of this action
Definition: Action.cpp:134
Log.h
camitk::HistoryItem::setOutputHistoryComponents
void setOutputHistoryComponents(QList< HistoryComponent > outputHistoryComponents)
Set the output components of the history item action.
Definition: HistoryItem.cpp:85
camitk::Action::family
QString family
the name of the family in which this action is associated
Definition: Action.h:491
camitk::Action::applyAndRegister
ApplyStatus applyAndRegister()
This method is called whenever the action has to be applied on the target list (like the apply()) met...
Definition: Action.cpp:245
camitk::Action
Action class is an abstract class that enables you to build a action (generally on a component)....
Definition: Action.h:230
camitk::Action::TRIGGERED
@ TRIGGERED
the action was triggered only, but not applied
Definition: Action.h:251
camitk::Action::getDescription
QString getDescription() const
the description of the action
Definition: Action.h:339
camitk::Action::apply
virtual ApplyStatus apply()=0
This method is called when the action has to be applied on the target list (get the target lists usin...
camitk::HistoryItem
HistoryItem class describes the entry of an action used in a pipeline, in the history.
Definition: HistoryItem.h:84
camitk::Action::extension
ActionExtension * extension
the extension in which this action is declared and registered
Definition: Action.h:500
camitk::Component::isInstanceOf
bool isInstanceOf(QString className) const override
Assert that a Component instance really inherits from a given className.
Definition: sdk/libraries/core/component/Component.cpp:164
camitk::Action::aliveBeforeComponents
ComponentList aliveBeforeComponents
In case of a pipeline application of the Action (i.e.
Definition: Action.h:566
description
const char * description
Definition: applications/cepgenerator/main.cpp:37
camitk::ActionViewer::getInstance
static ActionViewer * getInstance()
returns the unique instance of ActionViewer
Definition: ActionViewer.cpp:75
camitk::Action::setDescription
void setDescription(QString description)
the description of the action
Definition: Action.cpp:119
camitk::ActionViewer::embedActionWidget
void embedActionWidget(Action *)
embed an action widget in the stacked widget
Definition: ActionViewer.cpp:340
camitk::policy
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding)
camitk::Action::trigger
ApplyStatus trigger(QWidget *parent=nullptr)
This method triggers the action.
Definition: Action.cpp:197
camitk::Action::applyTargetPosition
void applyTargetPosition(Component *input, Component *target)
Change the target frame according to the default frame policy regarding the input's one.
Definition: Action.cpp:427
camitk::Application::SUBFRAME
@ SUBFRAME
New component's parent frame is its parent component.
Definition: Application.h:72
camitk::Application::SAME_TRANSFORMATION
@ SAME_TRANSFORMATION
New component has no parent frame (parent frame is set to nullptr), and its frame is copied from its ...
Definition: Application.h:70
camitk::Application::getPropertyObject
static PropertyObject * getPropertyObject()
Get the property object of the application.
Definition: Application.cpp:1325
camitk::ComponentList
QList< Component * > ComponentList
A list of Component.
Definition: CamiTKAPI.h:89
camitk::Action::setIcon
void setIcon(QPixmap)
set the Pixmap
Definition: Action.cpp:144
camitk::Action::icon
QPixmap icon
the Action pixmap icon
Definition: Action.h:503
camitk::Property::getInitialValue
const QVariant & getInitialValue() const
return the initial (default) value
Definition: Property.cpp:78
camitk::Action::addParameter
virtual bool addParameter(Property *)
Add a new parameter to the action, using the CamiTK property class.
Definition: Action.cpp:417
camitk::Action::name
QString name
the name of the action
Definition: Action.h:482
camitk::ActionExtension
This class describes what is a generic Action extension. To add a ActionExtension to CamiTK core,...
Definition: ActionExtension.h:82
Component
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
CAMITK_TRACE
#define CAMITK_TRACE(MSG)
Log for trace verbosity (the most verbose one, should be used for bug report) The msg will appear onl...
Definition: Log.h:253
camitk::Action::getOutputComponents
ComponentList getOutputComponents()
Returns the output Component(s)
Definition: Action.cpp:313
camitk::setObjectName
setObjectName("RendererWidget")
camitk::Action::getProperty
virtual Q_INVOKABLE Property * getProperty(QString name)
Get a Property given its name.
Definition: Action.cpp:412
camitk::Application::TargetPositionningPolicy
TargetPositionningPolicy
Definition: Application.h:69
camitk::Action::autoUpdateProperties
bool autoUpdateProperties
Should the properties/parameters of this action be automatically updated when the user change somethi...
Definition: Action.h:523
camitk::Application::getTopLevelComponents
static const ComponentList & getTopLevelComponents()
get the current application wide list of instantiated top-level Components.
Definition: Application.cpp:884
camitk::Action::getWidget
virtual QWidget * getWidget()
This method has to be redefined in your Action only if:
Definition: Action.cpp:164
HistoryItem.h
camitk::InterfaceFrame::setTransform
virtual void setTransform(vtkSmartPointer< vtkTransform > transform)=0
Set the current input frame position (according to its parent Frame)
camitk::Action::getAutoUpdateProperties
bool getAutoUpdateProperties() const
Definition: Action.cpp:399
camitk::Action::preProcessInPipeline
void preProcessInPipeline()
Selects the right component(s) (the one that has been set by setInputComponents() ),...
Definition: Action.cpp:353
camitk::Action::topLevelSelectedComponents
ComponentList topLevelSelectedComponents
The list of top level selected components before running the action This list is used to deduce the n...
Definition: Action.h:540
camitk::Action::parameterMap
QMap< QString, Property * > parameterMap
list of CamiTK property decorating the dynamic properties (action parameters)
Definition: Action.h:509
camitk::Action::setInputComponent
void setInputComponent(Component *input)
Specify the input Components in case of only one Component.
Definition: Action.cpp:301
camitk::ActionExtension::getName
virtual QString getName()=0
returns the action extension name (to be overriden in your ActionExtension)
camitk::Action::getComponent
QString getComponent() const
the name of the component class that can be used by this action
Definition: Action.h:344
camitk::Action::component
QString component
the name of the component class that can be used by this action
Definition: Action.h:488
camitk::Component
A Component represents something that could be included in the explorer view, the interactive 3D view...
Definition: sdk/libraries/core/component/Component.h:298
camitk::Component::getModified
virtual bool getModified() const
set the modified flag
Definition: sdk/libraries/core/component/Component.h:887
Application.h
camitk::Application::NO_TRANSFORMATION
@ NO_TRANSFORMATION
New component has no parent frame (parent frame is therefore set to nullptr) and transform is Id.
Definition: Application.h:71
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:49
camitk
Definition: Action.cpp:36