Salome HOME
Explicitly call execute for nested features before referring
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Interface.h
1 // Name   : ModelHighAPI_Interface.h
2 // Purpose: 
3 //
4 // History:
5 // 17/05/16 - Sergey POKHODENKO - Creation of the file
6
7 #ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_
8 #define SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_
9
10 //--------------------------------------------------------------------------------------
11 #include "ModelHighAPI.h"
12
13 #include <list>
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <iostream>
18 //--------------------------------------------------------------------------------------
19 class ModelAPI_Feature;
20 class ModelAPI_Result;
21 class ModelHighAPI_Selection;
22 class ModelHighAPI_Dumper;
23 //--------------------------------------------------------------------------------------
24 /**\class ModelHighAPI_Interface
25  * \ingroup CPPHighAPI
26  * \brief Base class for feature interfaces
27  */
28 class ModelHighAPI_Interface
29 {
30 public:
31   /// Constructor
32   MODELHIGHAPI_EXPORT
33   explicit ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature);
34   /// Destructor
35   MODELHIGHAPI_EXPORT
36   virtual ~ModelHighAPI_Interface();
37
38   /// Return ModelAPI_Feature
39   MODELHIGHAPI_EXPORT
40   std::shared_ptr<ModelAPI_Feature> feature() const;
41
42   /// If feature is composite return intefrace for sub-feature by zero-based index,
43   /// or empty pointer if feature not composite or does not have sub-feature with such index.
44   MODELHIGHAPI_EXPORT
45   std::shared_ptr<ModelHighAPI_Interface> subFeature(const int theIndex) const;
46
47   /// Shortcut for feature()->getKind()
48   MODELHIGHAPI_EXPORT
49   const std::string& getKind() const;
50
51   /// Shortcut for feature()->execute()
52   /// \param isForce start execution of feature instead of sending events
53   MODELHIGHAPI_EXPORT
54   void execute(bool isForce = false);
55
56   /// Shortcut for feature()->data()->setName()
57   MODELHIGHAPI_EXPORT
58   void setName(const std::string& theName);
59
60   // TODO(spo): rename to selectAll()
61   /// Return all objects of the feature
62   MODELHIGHAPI_EXPORT
63   virtual std::list<ModelHighAPI_Selection> result() const;
64
65   /// Return default result. Default implementation feature()->lastResult()
66   MODELHIGHAPI_EXPORT
67   virtual std::shared_ptr<ModelAPI_Result> defaultResult() const;
68
69   /// Throw exception to event loop
70   MODELHIGHAPI_EXPORT
71   void throwException(const std::string & theDescription);
72
73   /// Return name of getter for specified attribute
74   MODELHIGHAPI_EXPORT
75   const std::string& attributeGetter(const std::string& theAttrName);
76
77   /// Dump wrapped feature
78   MODELHIGHAPI_EXPORT
79   virtual void dump(ModelHighAPI_Dumper& theDumper) const {}
80
81 protected:
82   std::shared_ptr<ModelAPI_Feature> myFeature;
83
84   std::map<std::string, std::string> myAttrGetter; ///< names of attributes and their getters
85 };
86
87 //! Pointer on Interface object
88 typedef std::shared_ptr<ModelHighAPI_Interface> InterfacePtr;
89
90 //--------------------------------------------------------------------------------------
91 //--------------------------------------------------------------------------------------
92 #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_ */