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"
22 class GeomDataAPI_Dir;
23 class GeomDataAPI_Point;
24 class GeomDataAPI_Point2D;
26 class ModelAPI_Attribute;
27 class ModelAPI_AttributeBoolean;
28 class ModelAPI_AttributeDouble;
29 class ModelAPI_AttributeInteger;
30 class ModelAPI_AttributeRefAttr;
31 class ModelAPI_AttributeRefAttrList;
32 class ModelAPI_AttributeReference;
33 class ModelAPI_AttributeRefList;
34 class ModelAPI_AttributeSelection;
35 class ModelAPI_AttributeSelectionList;
36 class ModelAPI_AttributeString;
37 class ModelAPI_CompositeFeature;
38 class ModelAPI_Document;
39 class ModelAPI_Entity;
40 class ModelAPI_Feature;
41 class ModelAPI_Object;
42 class ModelAPI_Result;
44 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
45 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
46 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
47 typedef std::shared_ptr<ModelAPI_Result> ResultPtr;
49 /**\class ModelHighAPI_Dumper
51 * \brief Dump engine for the model
53 class ModelHighAPI_Dumper
56 /// Default constructor
58 ModelHighAPI_Dumper();
60 /// Sets instance of a dumper
62 static void setInstance(ModelHighAPI_Dumper* theDumper);
64 /// Returns instance of a dumper
66 static ModelHighAPI_Dumper* getInstance();
69 virtual ~ModelHighAPI_Dumper() {}
71 /// Dump given document into the file
72 /// \return \c true, if succeed
74 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
76 /// Add module to list of imported modules
77 /// \param theModuleName name of the module to be imported
78 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
80 void importModule(const std::string& theModuleName,
81 const std::string& theObject = std::string());
83 /// Returns name of specified entity
84 /// \param theEntity [in] named entity
85 /// \param theSaveNotDumped [in] if \c true, the entity should be stored as not dumped (will be dumped automatically)
86 /// \return name of the entity
88 const std::string& name(const EntityPtr& theEntity, bool theSaveNotDumped = true);
90 /// Returns name of parent composite feature for specified entity
92 const std::string& parentName(const FeaturePtr& theFeature);
94 /// Dump parameter feature only
95 virtual void dumpParameter(const FeaturePtr& theFeature) = 0;
96 /// Dump given feature
97 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
99 /// Return name of getter for corresponding attribute
100 virtual std::string attributeGetter(const FeaturePtr& theFeature,
101 const std::string& theAttrName) const = 0;
103 /// Save all dumps into specified file
105 bool exportTo(const std::string& theFileName);
109 ModelHighAPI_Dumper& operator<<(const char theChar);
112 ModelHighAPI_Dumper& operator<<(const char* theString);
115 ModelHighAPI_Dumper& operator<<(const std::string& theString);
118 ModelHighAPI_Dumper& operator<<(const bool theValue);
121 ModelHighAPI_Dumper& operator<<(const int theValue);
124 ModelHighAPI_Dumper& operator<<(const double theValue);
128 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
129 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
131 /// Dump GeomAPI_Pnt in the following form:
132 /// "GeomAPI_Pnt(X, Y, Z)"
134 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
136 /// "GeomAPI_Dir(X, Y, Z)"
138 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
140 /// Dump GeomDataAPI_Dir in the following form:
143 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
144 /// Dump GeomDataAPI_Point in the following form:
147 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
148 /// Dump GeomDataAPI_Point2D in the following form:
151 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
153 /// Dump AttributeBoolean
155 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
156 /// Dump AttributeInteger
158 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
159 /// Dump AttributeDouble
161 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
162 /// Dump AttributeString
164 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
165 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
167 ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
171 ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult);
175 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
178 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
180 /// Dump AttributeRefAttr
182 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
183 /// Dump AttributeRefAttrList as follows:
184 /// "[obj1, obj2, obj3, ...]"
186 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
187 /// Dump AttributeRefList as follows:
188 /// "[obj1, obj2, obj3, ...]"
190 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
191 /// Dump AttributeSelection
193 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
194 /// Dump AttributeSelectionList
196 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
197 /// Dump AttributeReference
199 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
201 /// Clear dump buffer
203 void clear(bool bufferOnly = false);
204 /// clear list of not dumped entities
205 MODELHIGHAPI_EXPORT void clearNotDumped();
208 /// Dump "setName" command if last entity had user-defined name
209 MODELHIGHAPI_EXPORT void dumpEntitySetName();
212 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
213 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
215 /// Iterate all features in document and dump them into intermediate buffer
216 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
218 /// Dump composite feature and all it sub-features
219 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool isForce = false);
221 /// Iterate all features in composite feature and dump them into intermediate buffer
222 /// \param theComposite [in] parent composite feature
223 /// \param theDumpModelDo [in] shows that command "model.do()" should be written at the end
225 bool processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite, bool theDumpModelDo = false);
227 /// Check the entity is already dumped
228 bool isDumped(const EntityPtr& theEntity) const;
231 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
232 typedef std::map<std::string, std::set<std::string> > ModulesMap;
233 typedef std::map<DocumentPtr, std::map<std::string, int> > NbFeaturesMap;
235 static ModelHighAPI_Dumper* mySelf;
237 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
238 std::ostringstream myFullDump; ///< full buffer of dumped data
240 ModulesMap myModules; ///< modules and entities to be imported
241 EntityNameMap myNames; ///< names of the entities
242 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name
244 NbFeaturesMap myFeatureCount; ///< number of features of each kind
247 std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet
249 friend class SketchAPI_Sketch;