]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_Dumper.h
Salome HOME
161e9e61a2d518e5b6886054ebaa7db538baca6d
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Dumper.h
1 // Copyright (C) 2016-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ModelHighAPI_Dumper.h
4 // Created:     1 August 2016
5 // Author:      Artem ZHIDKOV
6
7 #ifndef ModelHighAPI_Dumper_H_
8 #define ModelHighAPI_Dumper_H_
9
10 #include "ModelHighAPI.h"
11
12 #include <map>
13 #include <memory>
14 #include <set>
15 #include <sstream>
16 #include <string>
17
18 class GeomAPI_Pnt;
19 class GeomAPI_Dir;
20
21 class GeomDataAPI_Dir;
22 class GeomDataAPI_Point;
23 class GeomDataAPI_Point2D;
24
25 class ModelAPI_Attribute;
26 class ModelAPI_AttributeBoolean;
27 class ModelAPI_AttributeDouble;
28 class ModelAPI_AttributeInteger;
29 class ModelAPI_AttributeRefAttr;
30 class ModelAPI_AttributeRefAttrList;
31 class ModelAPI_AttributeRefList;
32 class ModelAPI_AttributeSelection;
33 class ModelAPI_AttributeSelectionList;
34 class ModelAPI_AttributeString;
35 class ModelAPI_CompositeFeature;
36 class ModelAPI_Document;
37 class ModelAPI_Entity;
38 class ModelAPI_Feature;
39 class ModelAPI_Object;
40
41 typedef std::shared_ptr<ModelAPI_Entity>  EntityPtr;
42 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
43
44 /**\class ModelHighAPI_Dumper
45  * \ingroup CPPHighAPI
46  * \brief Dump engine for the model
47  */
48 class ModelHighAPI_Dumper
49 {
50 public:
51   /// Default constructor
52   MODELHIGHAPI_EXPORT
53   ModelHighAPI_Dumper();
54
55   /// Sets instance of a dumper
56   MODELHIGHAPI_EXPORT
57   static void setInstance(ModelHighAPI_Dumper* theDumper);
58
59   /// Returns instance of a dumper
60   MODELHIGHAPI_EXPORT
61   static ModelHighAPI_Dumper* getInstance();
62
63   /// Destructor
64   virtual ~ModelHighAPI_Dumper() {}
65
66   /// Dump given document into the file
67   /// \return \c true, if succeed
68   MODELHIGHAPI_EXPORT
69   bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
70
71   /// Add module to list of imported modules
72   /// \param theModuleName  name of the module to be imported
73   /// \param theObject      name of the entity to be imported from the module (if empty, while module will be imported)
74   MODELHIGHAPI_EXPORT
75   void importModule(const std::string& theModuleName,
76                     const std::string& theObject = std::string());
77
78   /// Returns name of specified entity
79   MODELHIGHAPI_EXPORT
80   const std::string& name(const EntityPtr& theEntity);
81
82   /// Returns name of parent composite feature for specified entity
83   MODELHIGHAPI_EXPORT
84   const std::string& parentName(const FeaturePtr& theFeature);
85
86   /// Dump given feature
87   virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
88
89   /// Return name of getter for corresponding attribute
90   virtual std::string attributeGetter(const FeaturePtr& theFeature,
91                                       const std::string& theAttrName) const = 0;
92
93   /// Save all dumps into specified file
94   MODELHIGHAPI_EXPORT
95   bool exportTo(const std::string& theFileName);
96
97   /// Dump character
98   MODELHIGHAPI_EXPORT
99   ModelHighAPI_Dumper& operator<<(const char theChar);
100   /// Dump string
101   MODELHIGHAPI_EXPORT
102   ModelHighAPI_Dumper& operator<<(const char* theString);
103   /// Dump string
104   MODELHIGHAPI_EXPORT
105   ModelHighAPI_Dumper& operator<<(const std::string& theString);
106   /// Dump integer
107   MODELHIGHAPI_EXPORT
108   ModelHighAPI_Dumper& operator<<(const int theValue);
109   /// Dump real
110   MODELHIGHAPI_EXPORT
111   ModelHighAPI_Dumper& operator<<(const double theValue);
112   /// Dump std::endl
113   friend
114   MODELHIGHAPI_EXPORT
115   ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
116                                   std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
117
118   /// Dump GeomAPI_Pnt in the following form:
119   /// "GeomAPI_Pnt(X, Y, Z)"
120   MODELHIGHAPI_EXPORT
121   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
122   /// Dump GeomAPI_Dir
123   /// "GeomAPI_Dir(X, Y, Z)"
124   MODELHIGHAPI_EXPORT
125   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
126
127   /// Dump GeomDataAPI_Dir in the following form:
128   /// "X, Y, Z"
129   MODELHIGHAPI_EXPORT
130   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
131   /// Dump GeomDataAPI_Point in the following form:
132   /// "X, Y, Z"
133   MODELHIGHAPI_EXPORT
134   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
135   /// Dump GeomDataAPI_Point2D in the following form:
136   /// "X, Y"
137   MODELHIGHAPI_EXPORT
138   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
139
140   /// Dump AttributeBoolean
141   MODELHIGHAPI_EXPORT
142   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
143   /// Dump AttributeInteger
144   MODELHIGHAPI_EXPORT
145   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
146   /// Dump AttributeDouble
147   MODELHIGHAPI_EXPORT
148   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
149   /// Dump AttributeString
150   MODELHIGHAPI_EXPORT
151   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
152   /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
153   MODELHIGHAPI_EXPORT
154   ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
155
156   /// Dump Attribute
157   MODELHIGHAPI_EXPORT
158   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
159   /// Dump Object
160   MODELHIGHAPI_EXPORT
161   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
162
163   /// Dump AttributeRefAttr
164   MODELHIGHAPI_EXPORT
165   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
166   /// Dump AttributeRefAttrList as follows:
167   /// "[obj1, obj2, obj3, ...]"
168   MODELHIGHAPI_EXPORT
169   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
170   /// Dump AttributeRefList as follows:
171   /// "[obj1, obj2, obj3, ...]"
172   MODELHIGHAPI_EXPORT
173   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
174   /// Dump AttributeSelection
175   MODELHIGHAPI_EXPORT
176   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
177   /// Dump AttributeSelectionList
178   MODELHIGHAPI_EXPORT
179   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
180
181   /// Clear dump buffer
182   MODELHIGHAPI_EXPORT
183   void clear(bool bufferOnly = false);
184   /// clear list of not dumped entities
185   MODELHIGHAPI_EXPORT void clearNotDumped();
186
187 protected:
188   /// Dump "setName" command if last entity had user-defined name
189   MODELHIGHAPI_EXPORT void dumpEntitySetName();
190
191 private:
192   ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
193   const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
194
195   /// Iterate all features in document and dump them into intermediate buffer
196   bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
197
198   /// Iterate all features in composite feature and dump them into intermediate buffer
199   bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
200
201   /// Check the entity is already dumped
202   bool isDumped(const EntityPtr& theEntity) const;
203
204 private:
205   typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
206   typedef std::map<std::string, std::set<std::string> >      ModulesMap;
207
208   static ModelHighAPI_Dumper* mySelf;
209
210   std::ostringstream  myDumpBuffer;         ///< intermediate buffer to store dumping data
211   std::ostringstream  myFullDump;           ///< full buffer of dumped data
212
213   ModulesMap          myModules;            ///< modules and entities to be imported
214   EntityNameMap       myNames;              ///< names of the entities
215   EntityPtr           myLastEntityWithName; ///< not null, if last dumped entity had user defined name
216
217 protected:
218   std::set<EntityPtr> myNotDumpedEntities;  ///< list of entities, used by other features but not dumped yet
219 };
220
221 #endif