Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Interface.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_
22 #define SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_
23
24 //--------------------------------------------------------------------------------------
25 #include "ModelHighAPI.h"
26
27 #include <list>
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <iostream>
32 //--------------------------------------------------------------------------------------
33 class ModelAPI_Feature;
34 class ModelAPI_Result;
35 class ModelHighAPI_Selection;
36 class ModelHighAPI_Dumper;
37 //--------------------------------------------------------------------------------------
38 /**\class ModelHighAPI_Interface
39  * \ingroup CPPHighAPI
40  * \brief Base class for feature interfaces
41  */
42 class ModelHighAPI_Interface
43 {
44 public:
45   /// Constructor
46   MODELHIGHAPI_EXPORT
47   explicit ModelHighAPI_Interface(const std::shared_ptr<ModelAPI_Feature> & theFeature);
48   /// Destructor
49   MODELHIGHAPI_EXPORT
50   virtual ~ModelHighAPI_Interface();
51
52   /// Return ModelAPI_Feature
53   MODELHIGHAPI_EXPORT
54   std::shared_ptr<ModelAPI_Feature> feature() const;
55
56   /// If feature is composite return intefrace for sub-feature by zero-based index,
57   /// or empty pointer if feature not composite or does not have sub-feature with such index.
58   MODELHIGHAPI_EXPORT
59   std::shared_ptr<ModelHighAPI_Interface> subFeature(const int theIndex) const;
60
61   /// Shortcut for feature()->getKind()
62   MODELHIGHAPI_EXPORT
63   const std::string& getKind() const;
64
65   /// Shortcut for feature()->execute()
66   /// \param isForce start execution of feature instead of sending events
67   MODELHIGHAPI_EXPORT
68   void execute(bool isForce = false);
69
70   /// Shortcut for feature()->data()->setName()
71   MODELHIGHAPI_EXPORT
72   void setName(const std::string& theName);
73
74   /// Return firts object of the feature
75   MODELHIGHAPI_EXPORT
76   virtual ModelHighAPI_Selection result() const;
77
78   /// Return all objects of the feature
79   MODELHIGHAPI_EXPORT
80   virtual std::list<ModelHighAPI_Selection> results() const;
81
82   /// Return default result. Default implementation feature()->lastResult()
83   MODELHIGHAPI_EXPORT
84   virtual std::shared_ptr<ModelAPI_Result> defaultResult() const;
85
86   /// Throw exception to event loop
87   MODELHIGHAPI_EXPORT
88   void throwException(const std::string & theDescription);
89
90   /// Return name of getter for specified attribute
91   MODELHIGHAPI_EXPORT
92   const std::string& attributeGetter(const std::string& theAttrName);
93
94   /// Dump wrapped feature
95   MODELHIGHAPI_EXPORT
96   virtual void dump(ModelHighAPI_Dumper& theDumper) const {}
97
98 protected:
99   std::shared_ptr<ModelAPI_Feature> myFeature; ///< feature of this interface
100
101   std::map<std::string, std::string> myAttrGetter; ///< names of attributes and their getters
102 };
103
104 //! Pointer on Interface object
105 typedef std::shared_ptr<ModelHighAPI_Interface> InterfacePtr;
106
107 //--------------------------------------------------------------------------------------
108 //--------------------------------------------------------------------------------------
109 #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_INTERFACE_H_ */