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_AttributeString;
31 class ModelAPI_CompositeFeature;
32 class ModelAPI_Document;
33 class ModelAPI_Entity;
34 class ModelAPI_Feature;
36 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
37 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
39 /**\class ModelHighAPI_Dumper
41 * \brief Dump engine for the model
43 class ModelHighAPI_Dumper
46 /// Default constructor
48 ModelHighAPI_Dumper();
50 /// Sets instance of a dumper
52 static void setInstance(ModelHighAPI_Dumper* theDumper);
54 /// Returns instance of a dumper
56 static ModelHighAPI_Dumper* getInstance();
59 virtual ~ModelHighAPI_Dumper() {}
61 /// Dump given document into the file
62 /// \return \c true, if succeed
64 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
66 /// Add module to list of imported modules
67 /// \param theModuleName name of the module to be imported
68 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
70 void importModule(const std::string& theModuleName,
71 const std::string& theObject = std::string());
73 /// Returns name of specified entity
75 const std::string& name(const EntityPtr& theEntity);
77 /// Returns name of parent composite feature for specified entity
79 const std::string& parentName(const FeaturePtr& theFeature);
81 /// Dump given feature
82 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
84 /// Return name of getter for corresponding attribute
85 virtual std::string attributeGetter(const FeaturePtr& theFeature,
86 const std::string& theAttrName) const = 0;
88 /// Save all dumps into specified file
90 bool exportTo(const std::string& theFileName);
94 ModelHighAPI_Dumper& operator<<(const char theChar);
97 ModelHighAPI_Dumper& operator<<(const char* theString);
100 ModelHighAPI_Dumper& operator<<(const std::string& theString);
103 ModelHighAPI_Dumper& operator<<(const int theValue);
106 ModelHighAPI_Dumper& operator<<(const double theValue);
110 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
111 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
113 /// Dump GeomAPI_Pnt in the following form:
114 /// "GeomAPI_Pnt(X, Y, Z)"
116 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
118 /// "GeomAPI_Dir(X, Y, Z)"
120 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
122 /// Dump GeomDataAPI_Dir in the following form:
125 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
126 /// Dump GeomDataAPI_Point in the following form:
129 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
130 /// Dump GeomDataAPI_Point2D in the following form:
133 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
135 /// Dump AttributeBoolean
137 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
138 /// Dump AttributeInteger
140 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
141 /// Dump AttributeDouble
143 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
144 /// Dump AttributeString
146 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
147 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
149 ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity);
151 /// Dump AttributeRefAttr
153 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
154 /// Dump AttributeSelection
156 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
159 /// Dump "setName" command if last entity had user-defined name
160 MODELHIGHAPI_EXPORT void dumpEntitySetName();
162 /// Clear dump buffer
166 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
167 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
169 /// Iterate all features in document and dump them into intermediate buffer
170 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
172 /// Iterate all features in composite feature and dump them into intermediate buffer
173 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
176 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
177 typedef std::map<std::string, std::set<std::string> > ModulesMap;
179 static ModelHighAPI_Dumper* mySelf;
181 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
182 ModulesMap myModules; ///< modules and entities to be imported
183 EntityNameMap myNames; ///< names of the entities
184 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name