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_Entity> EntityPtr;
43 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
45 /**\class ModelHighAPI_Dumper
47 * \brief Dump engine for the model
49 class ModelHighAPI_Dumper
52 /// Default constructor
54 ModelHighAPI_Dumper();
56 /// Sets instance of a dumper
58 static void setInstance(ModelHighAPI_Dumper* theDumper);
60 /// Returns instance of a dumper
62 static ModelHighAPI_Dumper* getInstance();
65 virtual ~ModelHighAPI_Dumper() {}
67 /// Dump given document into the file
68 /// \return \c true, if succeed
70 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
72 /// Add module to list of imported modules
73 /// \param theModuleName name of the module to be imported
74 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
76 void importModule(const std::string& theModuleName,
77 const std::string& theObject = std::string());
79 /// Returns name of specified entity
81 const std::string& name(const EntityPtr& theEntity);
83 /// Returns name of parent composite feature for specified entity
85 const std::string& parentName(const FeaturePtr& theFeature);
87 /// Dump given feature
88 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
90 /// Return name of getter for corresponding attribute
91 virtual std::string attributeGetter(const FeaturePtr& theFeature,
92 const std::string& theAttrName) const = 0;
94 /// Save all dumps into specified file
96 bool exportTo(const std::string& theFileName);
100 ModelHighAPI_Dumper& operator<<(const char theChar);
103 ModelHighAPI_Dumper& operator<<(const char* theString);
106 ModelHighAPI_Dumper& operator<<(const std::string& theString);
109 ModelHighAPI_Dumper& operator<<(const bool theValue);
112 ModelHighAPI_Dumper& operator<<(const int theValue);
115 ModelHighAPI_Dumper& operator<<(const double theValue);
119 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
120 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
122 /// Dump GeomAPI_Pnt in the following form:
123 /// "GeomAPI_Pnt(X, Y, Z)"
125 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
127 /// "GeomAPI_Dir(X, Y, Z)"
129 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
131 /// Dump GeomDataAPI_Dir in the following form:
134 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
135 /// Dump GeomDataAPI_Point in the following form:
138 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
139 /// Dump GeomDataAPI_Point2D in the following form:
142 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
144 /// Dump AttributeBoolean
146 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
147 /// Dump AttributeInteger
149 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
150 /// Dump AttributeDouble
152 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
153 /// Dump AttributeString
155 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
156 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
158 ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
162 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
165 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
167 /// Dump AttributeRefAttr
169 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
170 /// Dump AttributeRefAttrList as follows:
171 /// "[obj1, obj2, obj3, ...]"
173 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
174 /// Dump AttributeRefList as follows:
175 /// "[obj1, obj2, obj3, ...]"
177 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
178 /// Dump AttributeSelection
180 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
181 /// Dump AttributeSelectionList
183 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
184 /// Dump AttributeReference
186 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
188 /// Clear dump buffer
190 void clear(bool bufferOnly = false);
191 /// clear list of not dumped entities
192 MODELHIGHAPI_EXPORT void clearNotDumped();
195 /// Dump "setName" command if last entity had user-defined name
196 MODELHIGHAPI_EXPORT void dumpEntitySetName();
199 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
200 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
202 /// Iterate all features in document and dump them into intermediate buffer
203 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
205 /// Iterate all features in composite feature and dump them into intermediate buffer
206 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
208 /// Check the entity is already dumped
209 bool isDumped(const EntityPtr& theEntity) const;
212 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
213 typedef std::map<std::string, std::set<std::string> > ModulesMap;
215 static ModelHighAPI_Dumper* mySelf;
217 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
218 std::ostringstream myFullDump; ///< full buffer of dumped data
220 ModulesMap myModules; ///< modules and entities to be imported
221 EntityNameMap myNames; ///< names of the entities
222 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name
225 std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet