Computer Assited Medical Intervention Tool Kit  version 5.0
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-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
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 <Application.h>
32 #include <Component.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 class HistoryItem;
45 
208 class CAMITK_API Action : public QObject {
209  Q_OBJECT
210 
211 public:
212 
214  Action(ActionExtension*);
215 
217  ~Action() override;
218 
219 #ifdef ERROR
220 #define CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD ERROR
221 #undef ERROR
222 #endif
223  enum ApplyStatus {
225  SUCCESS,
226  ERROR,
227  WARNING,
228  ABORTED,
229  TRIGGERED
230  };
231 
232 #ifdef CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
233 #define ERROR CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
234 #endif
235 
237  static QString getStatusAsString(ApplyStatus);
238 
239 public slots:
245  camitk::Action::ApplyStatus trigger(QWidget* parent = nullptr);
246 
256  virtual camitk::Action::ApplyStatus apply() = 0;
257 
265  camitk::Action::ApplyStatus applyAndRegister();
266 
267 public:
268 
271 
280  ApplyStatus applyInPipeline();
282 
286  void setInputComponents(ComponentList inputs);
287 
289  void setInputComponent(Component* input);
290 
292  ComponentList getOutputComponents();
293 
295  Component* getOutputComponent();
297 
301 
312  virtual QAction* getQAction(Component* target = nullptr);
313 
315  QString getName() const {
316  return name;
317  };
318 
320  QString getDescription() const {
321  return description;
322  };
323 
325  QString getComponent() const {
326  return component;
327  };
328 
330  QString getFamily() const {
331  return family;
332  };
333 
335  QString getExtensionName() const;
336 
338  QStringList getTag() const {
339  return tags;
340  };
341 
343  bool getEmbedded() const {
344  return isEmbedded;
345  };
347 
350 
372  virtual QWidget* getWidget();
373 
375  virtual QPixmap getIcon();
376 
378  const ComponentList getTargets() const;
379 
381  void updateTargets();
383 
387  bool getAutoUpdateProperties() const;
388 
390  void setAutoUpdateProperties(bool);
391 
398  Q_INVOKABLE virtual camitk::Property* getProperty(QString name);
399 
408  virtual bool addParameter(Property*);
410 
413 
418  void applyTargetPosition(Component* input, Component* target);
419 
426  void applyTargetPosition(Component* input, Component* target, Application::TargetPositionningPolicy policy);
428 
429 protected:
434  void setName(QString name);
437 
439  void setDescription(QString description);
440 
442  void setComponent(QString component);
443 
445  void setFamily(QString family);
446 
448  void addTag(QString tag);
449 
451  void setEmbedded(bool isEmbedded);
452 
454  void setIcon(QPixmap);
455 
457  QWidget* actionWidget;
458 
459 
461 
462 
463 
464 private:
466  QString name;
467 
469  QString description;
470 
472  QString component;
473 
475  QString family;
476 
478  QStringList tags;
479 
481  bool isEmbedded;
482 
484  ActionExtension* extension;
485 
487  QPixmap icon;
488 
490  QAction* qAction;
491 
493  QMap<QString, Property*> parameterMap;
494 
504  ComponentList targetComponents;
505 
507  bool autoUpdateProperties;
508 
511 
519  HistoryItem* item;
520 
524  ComponentList topLevelSelectedComponents;
525 
530  void preProcess();
531 
536  void postProcess();
538 
541 
550  ComponentList aliveBeforeComponents;
551 
555  ComponentList outputComponents;
556 
557 
563  void preProcessInPipeline();
564 
569  void postProcessInPipeline();
570 
571 
572 
574 
575 
576 
577 };
578 
579 }
580 
581 // -------------------- declare the interface for QPluginLoader --------------------
582 Q_DECLARE_INTERFACE(camitk::Action, "TIMC-IMAG.Action/2.1")
583 
584 #endif // ACTION_H
585 
586 
587 
588 
camitk::Action::setFamily
void setFamily(QString family)
the name of the family in which this action is associated
Definition: Action.cpp:136
camitk::Action::isEmbedded
bool isEmbedded
is the widget embedded or not
Definition: Action.h:504
camitk::Action::getIcon
virtual QPixmap getIcon()
the icon to personalize the action (no icon by default)
Definition: Action.cpp:161
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:824
camitk::Action::item
HistoryItem * item
Definition: Action.h:542
CAMITK_WARNING
#define CAMITK_WARNING(MSG)
Log for warning verbosity (the most common one) Will appear by default.
Definition: Log.h:266
camitk::Action::description
QString description
the descriptionof the action
Definition: Action.h:492
camitk::Action::preProcess
void preProcess()
Save the number of top level components loaded in memory before applying the action.
Definition: Action.cpp:347
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:792
camitk::Action::qAction
QAction * qAction
the corresponding QAction
Definition: Action.h:513
camitk::Action::WARNING
@ WARNING
some (partial) error occured during the application of the algorithm
Definition: Action.h:250
CamiTKAPI.h
camitk::Action::SUCCESS
@ SUCCESS
everything went according to plan
Definition: Action.h:248
camitk::Component::isSelected
virtual bool isSelected() const
Check if this data component is selected.
Definition: sdk/libraries/core/component/Component.h:892
camitk::Action::getOutputComponent
Component * getOutputComponent()
Returns the output Components in case of only one Component.
Definition: Action.cpp:337
camitk::Action::ABORTED
@ ABORTED
the action was aborted before completion
Definition: Action.h:251
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:1083
camitk::Application::refresh
static void refresh()
refresh the main window (this will call the refresh method of all viewers)
Definition: Application.cpp:333
camitk::Action::ApplyStatus
ApplyStatus
Definition: Action.h:247
camitk::Action::setName
void setName(QString name)
Definition: Action.cpp:120
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:426
camitk::Action::outputComponents
ComponentList outputComponents
List returned by getOutputComponents()
Definition: Action.h:578
camitk::Action::setComponent
void setComponent(QString component)
the name of the component class that can be used by this action
Definition: Action.cpp:131
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:249
PropertyObject.h
camitk::Action::tags
QStringList tags
the name of the tag called this action
Definition: Action.h:501
camitk::Action::actionWidget
QWidget * actionWidget
the action widget
Definition: Action.h:480
camitk::Action::targetComponents
ComponentList targetComponents
The list of valid (regarding the component property) components for which this action is called.
Definition: Action.h:527
camitk::Action::getTargets
const ComponentList getTargets() const
the currently selected and valid (regarding the component property) components, for which this action...
Definition: Action.cpp:166
camitk::Action::getName
QString getName() const
get the name of the action
Definition: Action.h:338
camitk::Action::~Action
~Action() override
Destructor.
Definition: Action.cpp:72
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:1132
camitk::Action::postProcess
void postProcess()
Register the action in the history.
Definition: Action.cpp:381
camitk::Action::postProcessInPipeline
void postProcessInPipeline()
Set the right output component list so that the method getOutputComponents() can be called.
Definition: Action.cpp:409
camitk::Application::getSelectedComponents
static const ComponentList & getSelectedComponents()
get the currently selected Components.
Definition: Application.cpp:1088
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:146
camitk::Action::Action
Action(ActionExtension *)
Default Constructor: the ActionExtension is needed.
Definition: Action.cpp:61
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:156
camitk::Action::applyInPipeline
ApplyStatus applyInPipeline()
This method encapsulates the apply() method.
Definition: Action.cpp:285
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:307
camitk::Property
This class describes a property that can be used in components and actions or any class that needs to...
Definition: Property.h:303
ActionWidget.h
camitk::Action::addTag
void addTag(QString tag)
add a tag to the tags list of this action
Definition: Action.cpp:141
Log.h
camitk::Action::updateTargets
void updateTargets()
update the target list using the currently selected components
Definition: Action.cpp:171
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:498
camitk::Action::applyAndRegister
camitk::Action::ApplyStatus applyAndRegister()
This method is called whenever the action has to be applied on the target list (like the apply()) met...
Definition: Action.cpp:263
camitk::Action
Action class is an abstract class that enables you to build a action (generally on a component)....
Definition: Action.h:231
camitk::Action::getQAction
virtual QAction * getQAction(Component *target=nullptr)
Get the corresponding QAction.
Definition: Action.cpp:204
camitk::Action::apply
virtual camitk::Action::ApplyStatus apply()=0
This method is called when the action has to be applied on the target list (get the target lists usin...
camitk::Action::TRIGGERED
@ TRIGGERED
the action was triggered only, but not applied
Definition: Action.h:252
camitk::Action::getDescription
QString getDescription() const
the description of the action
Definition: Action.h:343
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:507
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:496
camitk::Action::aliveBeforeComponents
ComponentList aliveBeforeComponents
In case of a pipeline application of the Action (i.e.
Definition: Action.h:573
description
const char * description
Definition: applications/cepgenerator/main.cpp:38
camitk::Action::setDescription
void setDescription(QString description)
the description of the action
Definition: Action.cpp:126
camitk::policy
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding)
camitk::Application::setTriggeredAction
static void setTriggeredAction(Action *action)
set the currently triggered action This is used by Action::trigger(..) to refresh all the viewer (the...
Definition: Application.cpp:1115
camitk::Action::trigger
camitk::Action::ApplyStatus trigger(QWidget *parent=nullptr)
This method triggers the action.
Definition: Action.cpp:218
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:450
camitk::Application::SUBFRAME
@ SUBFRAME
New component's parent frame is its parent component.
Definition: Application.h:91
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:89
camitk::Application::getPropertyObject
static PropertyObject * getPropertyObject()
Get the property object of the application.
Definition: Application.cpp:1531
camitk::ComponentList
QList< Component * > ComponentList
A list of Component.
Definition: CamiTKAPI.h:127
camitk::Action::setIcon
void setIcon(QPixmap)
set the Pixmap
Definition: Action.cpp:151
camitk::Action::icon
QPixmap icon
the Action pixmap icon
Definition: Action.h:510
camitk::Action::addParameter
virtual bool addParameter(Property *)
Add a new parameter to the action, using the CamiTK property class.
Definition: Action.cpp:440
camitk::Action::name
QString name
the name of the action
Definition: Action.h:489
camitk::ActionExtension
This class describes what is a generic Action extension. To add a ActionExtension to CamiTK core,...
Definition: ActionExtension.h:80
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:256
camitk::Action::getOutputComponents
ComponentList getOutputComponents()
Returns the output Component(s)
Definition: Action.cpp:332
camitk::setObjectName
setObjectName("RendererWidget")
camitk::Action::getProperty
virtual Q_INVOKABLE camitk::Property * getProperty(QString name)
Get a Property given its name.
Definition: Action.cpp:435
camitk::Application::TargetPositionningPolicy
TargetPositionningPolicy
Definition: Application.h:88
camitk::Action::autoUpdateProperties
bool autoUpdateProperties
Should the properties/parameters of this action be automatically updated when the user change somethi...
Definition: Action.h:530
camitk::Application::getTopLevelComponents
static const ComponentList & getTopLevelComponents()
get the current application wide list of instantiated top-level Components.
Definition: Application.cpp:1078
camitk::Action::getWidget
virtual QWidget * getWidget()
This method has to be redefined in your Action only if:
Definition: Action.cpp:185
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:421
camitk::Action::preProcessInPipeline
void preProcessInPipeline()
Selects the right component(s) (the one that has been set by setInputComponents() ),...
Definition: Action.cpp:373
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:547
camitk::Action::parameterMap
QMap< QString, Property * > parameterMap
list of CamiTK property decorating the dynamic properties (action parameters)
Definition: Action.h:516
camitk::Action::setInputComponent
void setInputComponent(Component *input)
Specify the input Components in case of only one Component.
Definition: Action.cpp:320
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:348
camitk::Action::component
QString component
the name of the component class that can be used by this action
Definition: Action.h:495
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:302
camitk::Component::getModified
virtual bool getModified() const
set the modified flag
Definition: sdk/libraries/core/component/Component.h:948
Application.h
camitk::PropertyObject::getPropertyValue
virtual QVariant getPropertyValue(unsigned int index)
get the value of the property at the given index, a non valid QVariant if the index is out of bounds ...
Definition: PropertyObject.cpp:111
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:90
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:49
camitk
Definition: Action.cpp:35