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_AttributeSelection;
29 class ModelAPI_AttributeString;
30 class ModelAPI_CompositeFeature;
31 class ModelAPI_Document;
32 class ModelAPI_Entity;
33 class ModelAPI_Feature;
35 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
36 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
38 /**\class ModelHighAPI_Dumper
40 * \brief Dump engine for the model
42 class ModelHighAPI_Dumper
45 /// Default constructor
47 ModelHighAPI_Dumper();
49 /// Sets instance of a dumper
51 static void setInstance(ModelHighAPI_Dumper* theDumper);
53 /// Returns instance of a dumper
55 static ModelHighAPI_Dumper* getInstance();
58 virtual ~ModelHighAPI_Dumper() {}
60 /// Dump given document into the file
61 /// \return \c true, if succeed
63 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
65 /// Add module to list of imported modules
66 /// \param theModuleName name of the module to be imported
67 /// \param theObject name of the entity to be imported from the module (if empty, while module will be imported)
69 void importModule(const std::string& theModuleName,
70 const std::string& theObject = std::string());
72 /// Returns name of specified entity
74 const std::string& name(const EntityPtr& theEntity);
76 /// Returns name of parent composite feature for specified entity
78 const std::string& parentName(const FeaturePtr& theFeature);
80 /// Dump given feature
81 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
83 /// Save all dumps into specified file
85 bool exportTo(const std::string& theFileName);
89 ModelHighAPI_Dumper& operator<<(const char theChar);
92 ModelHighAPI_Dumper& operator<<(const char* theString);
95 ModelHighAPI_Dumper& operator<<(const std::string& theString);
98 ModelHighAPI_Dumper& operator<<(const int theValue);
101 ModelHighAPI_Dumper& operator<<(const double theValue);
105 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
106 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
108 /// Dump GeomAPI_Pnt in the following form:
109 /// "GeomAPI_Pnt(X, Y, Z)"
111 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
113 /// "GeomAPI_Dir(X, Y, Z)"
115 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
117 /// Dump GeomDataAPI_Dir in the following form:
120 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
121 /// Dump GeomDataAPI_Point in the following form:
124 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
125 /// Dump GeomDataAPI_Point2D in the following form:
128 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
130 /// Dump AttributeBoolean
132 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
133 /// Dump AttributeInteger
135 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
136 /// Dump AttributeDouble
138 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
139 /// Dump AttributeString
141 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
142 /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
144 ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity);
146 /// Dump AttributeSelection
148 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
151 /// Dump "setName" command if last entity had user-defined name
152 MODELHIGHAPI_EXPORT void dumpEntitySetName();
154 /// Clear dump buffer
158 ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
159 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
161 /// Iterate all features in document and dump them into intermediate buffer
162 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
164 /// Iterate all features in composite feature and dump them into intermediate buffer
165 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
168 typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
169 typedef std::map<std::string, std::set<std::string> > ModulesMap;
171 static ModelHighAPI_Dumper* mySelf;
173 std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
174 ModulesMap myModules; ///< modules and entities to be imported
175 EntityNameMap myNames; ///< names of the entities
176 EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name