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;
41 class ModelAPI_Result;
43 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
44 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
45 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
46 typedef std::shared_ptr<ModelAPI_Result> ResultPtr;
48 /**\class ModelHighAPI_Dumper
50 * \brief Dump engine for the model
52 class ModelHighAPI_Dumper
55 /// Default constructor
57 ModelHighAPI_Dumper();
59 /// Sets instance of a dumper
61 static void setInstance(ModelHighAPI_Dumper* theDumper);
63 /// Returns instance of a dumper
65 static ModelHighAPI_Dumper* getInstance();
68 virtual ~ModelHighAPI_Dumper() {}
70 /// Dump given document into the file
71 /// \return \c true, if succeed
73 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
75 /// Add module to list of imported modules
76 /// \param theModuleName name of the module to be imported
77 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
79 void importModule(const std::string& theModuleName,
80 const std::string& theObject = std::string());
82 /// Returns name of specified entity
84 const std::string& name(const EntityPtr& theEntity);
86 /// Returns name of parent composite feature for specified entity
88 const std::string& parentName(const FeaturePtr& theFeature);
90 /// Dump given feature
91 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
93 /// Return name of getter for corresponding attribute
94 virtual std::string attributeGetter(const FeaturePtr& theFeature,
95 const std::string& theAttrName) const = 0;
97 /// Save all dumps into specified file
99 bool exportTo(const std::string& theFileName);
103 ModelHighAPI_Dumper& operator<<(const char theChar);
106 ModelHighAPI_Dumper& operator<<(const char* theString);
109 ModelHighAPI_Dumper& operator<<(const std::string& theString);
112 ModelHighAPI_Dumper& operator<<(const bool theValue);
115 ModelHighAPI_Dumper& operator<<(const int theValue);
118 ModelHighAPI_Dumper& operator<<(const double theValue);
122 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
123 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
125 /// Dump GeomAPI_Pnt in the following form:
126 /// "GeomAPI_Pnt(X, Y, Z)"
128 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
130 /// "GeomAPI_Dir(X, Y, Z)"
132 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
134 /// Dump GeomDataAPI_Dir in the following form:
137 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
138 /// Dump GeomDataAPI_Point in the following form:
141 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
142 /// Dump GeomDataAPI_Point2D in the following form:
145 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
147 /// Dump AttributeBoolean
149 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
150 /// Dump AttributeInteger
152 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
153 /// Dump AttributeDouble
155 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
156 /// Dump AttributeString
158 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
159 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
161 ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
165 ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult);
169 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
172 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
174 /// Dump AttributeRefAttr
176 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
177 /// Dump AttributeRefAttrList as follows:
178 /// "[obj1, obj2, obj3, ...]"
180 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
181 /// Dump AttributeRefList as follows:
182 /// "[obj1, obj2, obj3, ...]"
184 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
185 /// Dump AttributeSelection
187 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
188 /// Dump AttributeSelectionList
190 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
191 /// Dump AttributeReference
193 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
195 /// Clear dump buffer
197 void clear(bool bufferOnly = false);
198 /// clear list of not dumped entities
199 MODELHIGHAPI_EXPORT void clearNotDumped();
202 /// Dump "setName" command if last entity had user-defined name
203 MODELHIGHAPI_EXPORT void dumpEntitySetName();
206 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
207 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
209 /// Iterate all features in document and dump them into intermediate buffer
210 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
212 /// Dump composite feature and all it sub-features
213 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool isForce = false);
215 /// Iterate all features in composite feature and dump them into intermediate buffer
216 /// \param theComposite [in] parent composite feature
217 /// \param theDumpModelDo [in] shows that command "model.do()" should be written at the end
219 bool processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool theDumpModelDo = false);
221 /// Check the entity is already dumped
222 bool isDumped(const EntityPtr& theEntity) const;
225 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
226 typedef std::map<std::string, std::set<std::string> > ModulesMap;
227 typedef std::map<DocumentPtr, std::map<std::string, int> > NbFeaturesMap;
229 static ModelHighAPI_Dumper* mySelf;
231 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
232 std::ostringstream myFullDump; ///< full buffer of dumped data
234 ModulesMap myModules; ///< modules and entities to be imported
235 EntityNameMap myNames; ///< names of the entities
236 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name
238 NbFeaturesMap myFeatureCount; ///< number of features of each kind
241 std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet
243 friend class SketchAPI_Sketch;