Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Interface.h
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_
21 #define SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_
22
23 //--------------------------------------------------------------------------------------
24 #include "ModelHighAPI.h"
25
26 #include <list>
27 #include <map>
28 #include <memory>
29 #include <string>
30 #include <iostream>
31 //--------------------------------------------------------------------------------------
32 class ModelAPI_Feature;
33 class ModelAPI_Result;
34 class ModelHighAPI_Selection;
35 class ModelHighAPI_Dumper;
36 //--------------------------------------------------------------------------------------
37 /**\class ModelHighAPI_Interface
38  * \ingroup CPPHighAPI
39  * \brief Base class for feature interfaces
40  */
41 class ModelHighAPI_Interface
42 {
43 public:
44   /// Constructor
45   MODELHIGHAPI_EXPORT
46   explicit ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature);
47   /// Destructor
48   MODELHIGHAPI_EXPORT
49   virtual ~ModelHighAPI_Interface();
50
51   /// Return ModelAPI_Feature
52   MODELHIGHAPI_EXPORT
53   std::shared_ptr<ModelAPI_Feature> feature() const;
54
55   /// If feature is composite return intefrace for sub-feature by zero-based index,
56   /// or empty pointer if feature not composite or does not have sub-feature with such index.
57   MODELHIGHAPI_EXPORT
58   std::shared_ptr<ModelHighAPI_Interface> subFeature(const int theIndex) const;
59
60   /// Shortcut for feature()->getKind()
61   MODELHIGHAPI_EXPORT
62   const std::string& getKind() const;
63
64   /// Shortcut for feature()->execute()
65   /// \param isForce start execution of feature instead of sending events
66   MODELHIGHAPI_EXPORT
67   void execute(bool isForce = false);
68
69   /// Shortcut for feature()->data()->setName()
70   MODELHIGHAPI_EXPORT
71   void setName(const std::wstring& theName);
72
73   /// Shortcut for feature()->data()->name()
74   MODELHIGHAPI_EXPORT
75   std::wstring name() const;
76
77   /// Return firts object of the feature
78   MODELHIGHAPI_EXPORT
79   virtual ModelHighAPI_Selection result() const;
80
81   /// Return all objects of the feature
82   MODELHIGHAPI_EXPORT
83   virtual std::list<ModelHighAPI_Selection> results() const;
84
85   /// Return default result. Default implementation feature()->lastResult()
86   MODELHIGHAPI_EXPORT
87   virtual std::shared_ptr<ModelAPI_Result> defaultResult() const;
88
89   /// Throw exception to event loop
90   MODELHIGHAPI_EXPORT
91   void throwException(const std::string & theDescription);
92
93   /// Return name of getter for specified attribute
94   MODELHIGHAPI_EXPORT
95   const std::string& attributeGetter(const std::string& theAttrName);
96
97   /// Dump wrapped feature
98   MODELHIGHAPI_EXPORT
99   virtual void dump(ModelHighAPI_Dumper& /*theDumper*/) const {}
100
101 protected:
102   std::shared_ptr<ModelAPI_Feature> myFeature; ///< feature of this interface
103
104   std::map<std::string, std::string> myAttrGetter; ///< names of attributes and their getters
105 };
106
107 //! Pointer on Interface object
108 typedef std::shared_ptr<ModelHighAPI_Interface> InterfacePtr;
109
110 //--------------------------------------------------------------------------------------
111 //--------------------------------------------------------------------------------------
112 #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_ */