1 // Copyright (C) 2016-20xx CEA/DEN, EDF R&D -->
3 // File: ModelHighAPI_Dumper.h
4 // Created: 1 August 2016
5 // Author: Artem ZHIDKOV
7 #ifndef ModelHighAPI_Dumper_H_
8 #define ModelHighAPI_Dumper_H_
10 #include "ModelHighAPI.h"
21 class GeomDataAPI_Dir;
22 class GeomDataAPI_Point;
23 class GeomDataAPI_Point2D;
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_AttributeReference;
32 class ModelAPI_AttributeRefList;
33 class ModelAPI_AttributeSelection;
34 class ModelAPI_AttributeSelectionList;
35 class ModelAPI_AttributeString;
36 class ModelAPI_CompositeFeature;
37 class ModelAPI_Document;
38 class ModelAPI_Entity;
39 class ModelAPI_Feature;
40 class ModelAPI_Object;
42 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
43 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
44 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
46 /**\class ModelHighAPI_Dumper
48 * \brief Dump engine for the model
50 class ModelHighAPI_Dumper
53 /// Default constructor
55 ModelHighAPI_Dumper();
57 /// Sets instance of a dumper
59 static void setInstance(ModelHighAPI_Dumper* theDumper);
61 /// Returns instance of a dumper
63 static ModelHighAPI_Dumper* getInstance();
66 virtual ~ModelHighAPI_Dumper() {}
68 /// Dump given document into the file
69 /// \return \c true, if succeed
71 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
73 /// Add module to list of imported modules
74 /// \param theModuleName name of the module to be imported
75 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
77 void importModule(const std::string& theModuleName,
78 const std::string& theObject = std::string());
80 /// Returns name of specified entity
82 const std::string& name(const EntityPtr& theEntity);
84 /// Returns name of parent composite feature for specified entity
86 const std::string& parentName(const FeaturePtr& theFeature);
88 /// Dump given feature
89 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
91 /// Return name of getter for corresponding attribute
92 virtual std::string attributeGetter(const FeaturePtr& theFeature,
93 const std::string& theAttrName) const = 0;
95 /// Save all dumps into specified file
97 bool exportTo(const std::string& theFileName);
101 ModelHighAPI_Dumper& operator<<(const char theChar);
104 ModelHighAPI_Dumper& operator<<(const char* theString);
107 ModelHighAPI_Dumper& operator<<(const std::string& theString);
110 ModelHighAPI_Dumper& operator<<(const bool theValue);
113 ModelHighAPI_Dumper& operator<<(const int theValue);
116 ModelHighAPI_Dumper& operator<<(const double theValue);
120 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
121 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
123 /// Dump GeomAPI_Pnt in the following form:
124 /// "GeomAPI_Pnt(X, Y, Z)"
126 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
128 /// "GeomAPI_Dir(X, Y, Z)"
130 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
132 /// Dump GeomDataAPI_Dir in the following form:
135 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
136 /// Dump GeomDataAPI_Point in the following form:
139 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
140 /// Dump GeomDataAPI_Point2D in the following form:
143 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
145 /// Dump AttributeBoolean
147 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
148 /// Dump AttributeInteger
150 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
151 /// Dump AttributeDouble
153 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
154 /// Dump AttributeString
156 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
157 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
159 ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
163 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
166 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
168 /// Dump AttributeRefAttr
170 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
171 /// Dump AttributeRefAttrList as follows:
172 /// "[obj1, obj2, obj3, ...]"
174 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
175 /// Dump AttributeRefList as follows:
176 /// "[obj1, obj2, obj3, ...]"
178 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
179 /// Dump AttributeSelection
181 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
182 /// Dump AttributeSelectionList
184 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
185 /// Dump AttributeReference
187 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
189 /// Clear dump buffer
191 void clear(bool bufferOnly = false);
192 /// clear list of not dumped entities
193 MODELHIGHAPI_EXPORT void clearNotDumped();
196 /// Dump "setName" command if last entity had user-defined name
197 MODELHIGHAPI_EXPORT void dumpEntitySetName();
200 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
201 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
203 /// Iterate all features in document and dump them into intermediate buffer
204 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
206 /// Dump composite feature and all it sub-features
207 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool isForce = false);
209 /// Iterate all features in composite feature and dump them into intermediate buffer
210 /// \param theComposite [in] parent composite feature
211 /// \param theDumpModelDo [in] shows that command "model.do()" should be written at the end
213 bool processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool theDumpModelDo = false);
215 /// Check the entity is already dumped
216 bool isDumped(const EntityPtr& theEntity) const;
219 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
220 typedef std::map<std::string, std::set<std::string> > ModulesMap;
221 typedef std::map<DocumentPtr, std::map<std::string, int> > NbFeaturesMap;
223 static ModelHighAPI_Dumper* mySelf;
225 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
226 std::ostringstream myFullDump; ///< full buffer of dumped data
228 ModulesMap myModules; ///< modules and entities to be imported
229 EntityNameMap myNames; ///< names of the entities
230 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name
232 NbFeaturesMap myFeatureCount; ///< number of features of each kind
235 std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet
237 friend class SketchAPI_Sketch;