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_AttributeBoolean;
26 class ModelAPI_AttributeDouble;
27 class ModelAPI_AttributeInteger;
28 class ModelAPI_AttributeRefAttr;
29 class ModelAPI_AttributeSelection;
30 class ModelAPI_AttributeSelectionList;
31 class ModelAPI_AttributeString;
32 class ModelAPI_CompositeFeature;
33 class ModelAPI_Document;
34 class ModelAPI_Entity;
35 class ModelAPI_Feature;
37 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
38 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
40 /**\class ModelHighAPI_Dumper
42 * \brief Dump engine for the model
44 class ModelHighAPI_Dumper
47 /// Default constructor
49 ModelHighAPI_Dumper();
51 /// Sets instance of a dumper
53 static void setInstance(ModelHighAPI_Dumper* theDumper);
55 /// Returns instance of a dumper
57 static ModelHighAPI_Dumper* getInstance();
60 virtual ~ModelHighAPI_Dumper() {}
62 /// Dump given document into the file
63 /// \return \c true, if succeed
65 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
67 /// Add module to list of imported modules
68 /// \param theModuleName name of the module to be imported
69 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
71 void importModule(const std::string& theModuleName,
72 const std::string& theObject = std::string());
74 /// Returns name of specified entity
76 const std::string& name(const EntityPtr& theEntity);
78 /// Returns name of parent composite feature for specified entity
80 const std::string& parentName(const FeaturePtr& theFeature);
82 /// Dump given feature
83 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
85 /// Return name of getter for corresponding attribute
86 virtual std::string attributeGetter(const FeaturePtr& theFeature,
87 const std::string& theAttrName) const = 0;
89 /// Save all dumps into specified file
91 bool exportTo(const std::string& theFileName);
95 ModelHighAPI_Dumper& operator<<(const char theChar);
98 ModelHighAPI_Dumper& operator<<(const char* theString);
101 ModelHighAPI_Dumper& operator<<(const std::string& theString);
104 ModelHighAPI_Dumper& operator<<(const int theValue);
107 ModelHighAPI_Dumper& operator<<(const double theValue);
111 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
112 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
114 /// Dump GeomAPI_Pnt in the following form:
115 /// "GeomAPI_Pnt(X, Y, Z)"
117 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
119 /// "GeomAPI_Dir(X, Y, Z)"
121 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
123 /// Dump GeomDataAPI_Dir in the following form:
126 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
127 /// Dump GeomDataAPI_Point in the following form:
130 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
131 /// Dump GeomDataAPI_Point2D in the following form:
134 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
136 /// Dump AttributeBoolean
138 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
139 /// Dump AttributeInteger
141 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
142 /// Dump AttributeDouble
144 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
145 /// Dump AttributeString
147 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
148 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
150 ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity);
152 /// Dump AttributeRefAttr
154 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
155 /// Dump AttributeSelection
157 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
158 /// Dump AttributeSelectionList
160 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
162 /// Clear dump buffer
164 void clear(bool bufferOnly = false);
165 /// clear list of not dumped entities
166 MODELHIGHAPI_EXPORT void clearNotDumped();
169 /// Dump "setName" command if last entity had user-defined name
170 MODELHIGHAPI_EXPORT void dumpEntitySetName();
173 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
174 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
176 /// Iterate all features in document and dump them into intermediate buffer
177 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
179 /// Iterate all features in composite feature and dump them into intermediate buffer
180 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
182 /// Check the entity is already dumped
183 bool isDumped(const EntityPtr& theEntity) const;
186 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
187 typedef std::map<std::string, std::set<std::string> > ModulesMap;
189 static ModelHighAPI_Dumper* mySelf;
191 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
192 std::ostringstream myFullDump; ///< full buffer of dumped data
194 ModulesMap myModules; ///< modules and entities to be imported
195 EntityNameMap myNames; ///< names of the entities
196 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name
199 std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet