Computer Assisted Medical Intervention Tool Kit  version 5.2
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-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, 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 "InterfacePersistence.h"
32 #include <Application.h>
33 #include <Component.h>
34 
35 #include <QSet>
36 #include <QWidget>
37 #include <QString>
38 #include <QAction>
39 
40 
41 namespace camitk {
42 
43 class ActionExtension;
44 class Property;
45 class HistoryItem;
46 
209 class CAMITK_API Action : public QObject, public InterfacePersistence {
210  Q_OBJECT
211 
212 public:
213 
216 
218  ~Action() override;
219 
220 #ifdef ERROR
221 #define CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD ERROR
222 #undef ERROR
223 #endif
225  enum ApplyStatus {
230  TRIGGERED
231  };
232 
233 #ifdef CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
234 #define ERROR CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
235 #endif
236 
238  static QString getStatusAsString(ApplyStatus);
239 
240 
241 
242 public slots:
248  camitk::Action::ApplyStatus trigger(QWidget* parent = nullptr);
249 
260 
268  camitk::Action::ApplyStatus applyAndRegister();
269 
270 public:
271 
274 
283  ApplyStatus applyInPipeline();
285 
289  void setInputComponents(ComponentList inputs);
290 
292  void setInputComponent(Component* input);
293 
295  ComponentList getOutputComponents();
296 
298  Component* getOutputComponent();
300 
304 
315  virtual QAction* getQAction(Component* target = nullptr);
316 
318  QString getName() const {
319  return name;
320  };
321 
323  QString getDescription() const {
324  return description;
325  };
326 
328 
336  CAMITK_API_DEPRECATED("Please use getComponentClassName() instead")
337  QString getComponent() const {
338  return getComponentClassName();
339  };
341 
343  QString getComponentClassName() const {
344  return componentClassName;
345  };
346 
348  QString getFamily() const {
349  return family;
350  };
351 
353  QString getExtensionName() const;
354 
356  QStringList getTag() const {
357  return tags;
358  };
359 
361  bool getEmbedded() const {
362  return isEmbedded;
363  };
365 
368 
390  virtual QWidget* getWidget();
391 
393  virtual QPixmap getIcon();
394 
396  const ComponentList getTargets() const;
397 
399  void updateTargets();
401 
405  bool getAutoUpdateProperties() const;
406 
408  void setAutoUpdateProperties(bool);
409 
416  Q_INVOKABLE virtual camitk::Property* getProperty(QString name);
417 
426  virtual bool addParameter(Property*);
428 
431 
436  void applyTargetPosition(Component* input, Component* target);
437 
444  void applyTargetPosition(Component* input, Component* target, Application::TargetPositionningPolicy policy);
446 
453  virtual QVariant toVariant() const override;
454 
456  virtual void fromVariant(const QVariant&) override;
458 
459 protected:
466  void setName(QString name);
467 
469  void setDescription(QString description);
470 
472 
480  CAMITK_API_DEPRECATED("Please use setComponentClassName(QString componentClassName) instead")
481  void setComponent(QString component);
483 
485  void setComponentClassName(QString componentClassName);
486 
488  void setFamily(QString family);
489 
491  void addTag(QString tag);
492 
494  void setEmbedded(bool isEmbedded);
495 
497  void setIcon(QPixmap);
498 
500  QWidget* actionWidget;
502 
503 private:
505  QString name;
506 
508  QString description;
509 
511  QString componentClassName;
512 
514  QString family;
515 
517  QStringList tags;
518 
520  bool isEmbedded;
521 
523  ActionExtension* extension;
524 
526  QPixmap icon;
527 
529  QAction* qAction;
530 
532  QMap<QString, Property*> parameterMap;
533 
543  ComponentList targetComponents;
544 
546  bool autoUpdateProperties;
547 
550 
558  HistoryItem* item;
559 
563  ComponentList topLevelSelectedComponents;
564 
569  void preProcess();
570 
575  void postProcess();
577 
580 
589  ComponentList aliveBeforeComponents;
590 
594  ComponentList outputComponents;
595 
596 
602  void preProcessInPipeline();
603 
608  void postProcessInPipeline();
609 
610 
611 
613 
614 
615 
616 };
617 
618 }
619 
620 // -------------------- declare the interface for QPluginLoader --------------------
621 Q_DECLARE_INTERFACE(camitk::Action, "TIMC-IMAG.Action/2.1")
622 
623 #endif // ACTION_H
624 
625 
626 
627 
#define CAMITK_API_DEPRECATED(X)
Definition: CamiTKAPI.h:94
#define CAMITK_API
Definition: CamiTKAPI.h:49
const char * description
Definition: applications/cepgenerator/main.cpp:38
Interface for all objects that should be serialized by the PersistenceManager.
Definition: InterfacePersistence.h:36
This class describes what is a generic Action extension.
Definition: ActionExtension.h:57
Action class is an abstract class that enables you to build a action (generally on a component).
Definition: Action.h:209
ApplyStatus
describes what happened during the application of an algorithm (i.e. results of the apply method)
Definition: Action.h:225
@ ERROR
apply() failed : an error occurred (usually it means that the apply() was interrupted)
Definition: Action.h:227
@ SUCCESS
everything went according to plan
Definition: Action.h:226
@ ABORTED
the action was aborted before completion
Definition: Action.h:229
@ WARNING
some (partial) error occurred during the application of the algorithm
Definition: Action.h:228
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...
QString getFamily() const
the name of the family in which this action is associated
Definition: Action.h:348
QString getName() const
get the name of the action
Definition: Action.h:318
QStringList getTag() const
the name of the tag called this action
Definition: Action.h:356
bool getEmbedded() const
argument use to know if the widget is embedded or not
Definition: Action.h:361
QString getDescription() const
the description of the action
Definition: Action.h:323
QString getComponentClassName() const
the name of the component class that can be used by this action
Definition: Action.h:343
TargetPositionningPolicy
: Policy to determine how a newly instantiated component's frame should be initialized regarding of i...
Definition: Application.h:88
A Component represents something that could be included in the explorer view, the interactive 3D view...
Definition: sdk/libraries/core/component/Component.h:303
HistoryItem class describes the entry of an action used in a pipeline, in the history.
Definition: HistoryItem.h:61
This class describes a property that can be used in components and actions or any class that needs to...
Definition: Property.h:280
Definition: Action.cpp:36
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding)