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_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;
41 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
42 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
44 /**\class ModelHighAPI_Dumper
46 * \brief Dump engine for the model
48 class ModelHighAPI_Dumper
51 /// Default constructor
53 ModelHighAPI_Dumper();
55 /// Sets instance of a dumper
57 static void setInstance(ModelHighAPI_Dumper* theDumper);
59 /// Returns instance of a dumper
61 static ModelHighAPI_Dumper* getInstance();
64 virtual ~ModelHighAPI_Dumper() {}
66 /// Dump given document into the file
67 /// \return \c true, if succeed
69 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
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)
75 void importModule(const std::string& theModuleName,
76 const std::string& theObject = std::string());
78 /// Returns name of specified entity
80 const std::string& name(const EntityPtr& theEntity);
82 /// Returns name of parent composite feature for specified entity
84 const std::string& parentName(const FeaturePtr& theFeature);
86 /// Dump given feature
87 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
89 /// Return name of getter for corresponding attribute
90 virtual std::string attributeGetter(const FeaturePtr& theFeature,
91 const std::string& theAttrName) const = 0;
93 /// Save all dumps into specified file
95 bool exportTo(const std::string& theFileName);
99 ModelHighAPI_Dumper& operator<<(const char theChar);
102 ModelHighAPI_Dumper& operator<<(const char* theString);
105 ModelHighAPI_Dumper& operator<<(const std::string& theString);
108 ModelHighAPI_Dumper& operator<<(const int theValue);
111 ModelHighAPI_Dumper& operator<<(const double theValue);
115 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
116 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
118 /// Dump GeomAPI_Pnt in the following form:
119 /// "GeomAPI_Pnt(X, Y, Z)"
121 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
123 /// "GeomAPI_Dir(X, Y, Z)"
125 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
127 /// Dump GeomDataAPI_Dir in the following form:
130 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
131 /// Dump GeomDataAPI_Point in the following form:
134 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
135 /// Dump GeomDataAPI_Point2D in the following form:
138 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
140 /// Dump AttributeBoolean
142 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
143 /// Dump AttributeInteger
145 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
146 /// Dump AttributeDouble
148 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
149 /// Dump AttributeString
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
154 ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
158 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
161 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
163 /// Dump AttributeRefAttr
165 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
166 /// Dump AttributeRefAttrList as follows:
167 /// "[obj1, obj2, obj3, ...]"
169 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
170 /// Dump AttributeRefList as follows:
171 /// "[obj1, obj2, obj3, ...]"
173 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
174 /// Dump AttributeSelection
176 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
177 /// Dump AttributeSelectionList
179 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
181 /// Clear dump buffer
183 void clear(bool bufferOnly = false);
184 /// clear list of not dumped entities
185 MODELHIGHAPI_EXPORT void clearNotDumped();
188 /// Dump "setName" command if last entity had user-defined name
189 MODELHIGHAPI_EXPORT void dumpEntitySetName();
192 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
193 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
195 /// Iterate all features in document and dump them into intermediate buffer
196 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
198 /// Iterate all features in composite feature and dump them into intermediate buffer
199 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
201 /// Check the entity is already dumped
202 bool isDumped(const EntityPtr& theEntity) const;
205 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
206 typedef std::map<std::string, std::set<std::string> > ModulesMap;
208 static ModelHighAPI_Dumper* mySelf;
210 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
211 std::ostringstream myFullDump; ///< full buffer of dumped data
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
218 std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet