SHAPER 9.16.0
ModelHighAPI_Dumper.h
1// Copyright (C) 2014-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef ModelHighAPI_Dumper_H_
21#define ModelHighAPI_Dumper_H_
22
23#include "ModelHighAPI.h"
24
25#include <list>
26#include <map>
27#include <memory>
28#include <set>
29#include <sstream>
30#include <stack>
31#include <string>
32
33class GeomAPI_Pnt;
34class GeomAPI_Dir;
35
36class GeomDataAPI_Dir;
40
57class ModelAPI_Entity;
59class ModelAPI_Folder;
60class ModelAPI_Object;
61class ModelAPI_Result;
62
63typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
64typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
65typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
66typedef std::shared_ptr<ModelAPI_Folder> FolderPtr;
67typedef std::shared_ptr<ModelAPI_Result> ResultPtr;
68
69typedef std::set<std::string> ModulesSet;
70typedef std::map<DocumentPtr, std::map<std::string, std::pair<int, int> > > NbFeaturesMap;
71
81{
82public:
88 {
89 public:
90 DumpStorage() {}
91 MODELHIGHAPI_EXPORT DumpStorage(const DumpStorage& theOther);
92 MODELHIGHAPI_EXPORT const DumpStorage& operator=(const DumpStorage& theOther);
93
94 virtual ~DumpStorage() {}
95
96 void setFilenameSuffix(const std::string& theSuffix) { myFilenameSuffix = theSuffix; }
97
98 protected:
99 std::ostringstream& buffer() { return myDumpBuffer; }
100 std::ostringstream& fullDump() { return myFullDump; }
101
102 MODELHIGHAPI_EXPORT virtual void reserveBuffer();
103 MODELHIGHAPI_EXPORT virtual void restoreReservedBuffer();
104
105 MODELHIGHAPI_EXPORT
106 virtual void write(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
107
108 MODELHIGHAPI_EXPORT
109 virtual bool exportTo(const std::string& theFilename, const ModulesSet& theUsedModules);
110
111 private:
112 std::string myFilenameSuffix;
113 std::ostringstream myDumpBuffer;
114 std::ostringstream myFullDump;
115
116 std::stack<std::string> myDumpBufferHideout;
117
118 friend class ModelHighAPI_Dumper;
119 };
120 typedef std::shared_ptr<DumpStorage> DumpStoragePtr;
121
127 {
128 protected:
129 MODELHIGHAPI_EXPORT
130 virtual void write(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
131 };
132
138 {
139 protected:
140 MODELHIGHAPI_EXPORT
141 virtual void write(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
142 };
143
144public:
146 MODELHIGHAPI_EXPORT
148
150 MODELHIGHAPI_EXPORT
151 static void setInstance(ModelHighAPI_Dumper* theDumper);
152
154 MODELHIGHAPI_EXPORT
155 void setIsMultiDump(const bool theValue);
156
158 MODELHIGHAPI_EXPORT
160
162 MODELHIGHAPI_EXPORT
163 virtual ~ModelHighAPI_Dumper();
164
166 MODELHIGHAPI_EXPORT
167 void addCustomStorage(const DumpStoragePtr& theStorage);
169 MODELHIGHAPI_EXPORT
170 void clearCustomStorage();
173 MODELHIGHAPI_EXPORT
174 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
175
179 MODELHIGHAPI_EXPORT
180 void setDumpDir(const std::string& theDumpDir) { myDumpDir = theDumpDir; }
182 MODELHIGHAPI_EXPORT std::string getDumpDir() const { return myDumpDir; }
183
186 MODELHIGHAPI_EXPORT
187 void importModule(const std::string& theModuleName);
188
196 MODELHIGHAPI_EXPORT
197 const std::string& name(const EntityPtr& theEntity, bool theSaveNotDumped = true,
198 bool theUseEntityName = false, bool theSetIsDumped = false);
199
201 MODELHIGHAPI_EXPORT
202 const std::string& parentName(const FeaturePtr& theFeature);
203
205 virtual void dumpParameter(const FeaturePtr& theFeature) = 0;
207 virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
209 virtual void dumpFolder(const FolderPtr& theFolder) = 0;
210
213 MODELHIGHAPI_EXPORT
214 void postpone(const EntityPtr& theEntity);
215
217 MODELHIGHAPI_EXPORT
218 void doNotDumpFeature(const FeaturePtr& theFeature)
219 { myFeaturesToSkip.insert(theFeature); }
220
225 MODELHIGHAPI_EXPORT
226 void dumpSubFeatureNameAndColor(const std::string theSubFeatureGet,
227 const FeaturePtr& theSubFeature);
228
230 virtual std::string attributeGetter(const FeaturePtr& theFeature,
231 const std::string& theAttrName) const = 0;
232
234 virtual std::string featureWrapper(const FeaturePtr& theFeature) const = 0;
235
237 MODELHIGHAPI_EXPORT
238 ModelHighAPI_Dumper& operator<<(const char theChar);
240 MODELHIGHAPI_EXPORT
241 ModelHighAPI_Dumper& operator<<(const char* theString);
243 MODELHIGHAPI_EXPORT
244 ModelHighAPI_Dumper& operator<<(const std::string& theString);
246 MODELHIGHAPI_EXPORT
247 ModelHighAPI_Dumper& operator<<(const std::wstring& theString);
249 MODELHIGHAPI_EXPORT
250 ModelHighAPI_Dumper& operator<<(const bool theValue);
252 MODELHIGHAPI_EXPORT
253 ModelHighAPI_Dumper& operator<<(const int theValue);
255 MODELHIGHAPI_EXPORT
256 ModelHighAPI_Dumper& operator<<(const double theValue);
258 friend
259 MODELHIGHAPI_EXPORT
261 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
262
264 MODELHIGHAPI_EXPORT void newline();
265
268 MODELHIGHAPI_EXPORT
269 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
272 MODELHIGHAPI_EXPORT
273 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
274
277 MODELHIGHAPI_EXPORT
278 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
281 MODELHIGHAPI_EXPORT
282 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
285 MODELHIGHAPI_EXPORT
286 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
288 MODELHIGHAPI_EXPORT
289 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2DArray>& thePointArray);
290
292 MODELHIGHAPI_EXPORT
293 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
295 MODELHIGHAPI_EXPORT
296 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
298 MODELHIGHAPI_EXPORT
299 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeIntArray>& theArray);
301 MODELHIGHAPI_EXPORT
302 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
304 MODELHIGHAPI_EXPORT
305 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDoubleArray>& theArray);
307 MODELHIGHAPI_EXPORT
308 ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
310 MODELHIGHAPI_EXPORT
311 ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
312
314 MODELHIGHAPI_EXPORT
315 ModelHighAPI_Dumper& operator<<(const FolderPtr& theFolder);
316
318 MODELHIGHAPI_EXPORT
319 ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult);
320
322 MODELHIGHAPI_EXPORT
323 ModelHighAPI_Dumper& operator<<(const std::list<ResultPtr>& theResults);
324
326 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
327 operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
329 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
330 operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
331
333 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
334 operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
337 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
338 operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
341 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
342 operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
344 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
345 operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
347 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
348 operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
350 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
351 operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
353 MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
354 operator<<(const std::shared_ptr<ModelAPI_AttributeStringArray>& theArray);
355
357 MODELHIGHAPI_EXPORT void clearNotDumped();
358
360 MODELHIGHAPI_EXPORT
361 bool isDumped(const EntityPtr& theEntity) const;
363 MODELHIGHAPI_EXPORT
364 bool isDumped(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr) const;
366 MODELHIGHAPI_EXPORT
367 bool isDumped(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList) const;
368
370 MODELHIGHAPI_EXPORT
371 size_t indexOfFirstNotDumped(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList) const;
372
374 MODELHIGHAPI_EXPORT virtual void exportVariables() const;
375
377 MODELHIGHAPI_EXPORT virtual void exportVariable(const std::string& /*theEntry*/,
378 const std::string& /*theVarName*/) const {}
379
382 MODELHIGHAPI_EXPORT bool dumpCommentBeforeFeature(const FeaturePtr& theFeature) const;
383
384protected:
386 MODELHIGHAPI_EXPORT void dumpEntitySetName();
387
388private:
390 const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
391
393 bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
394
396 bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
397 bool isForce = false,
398 bool isDumpModelDo = true);
399
403 MODELHIGHAPI_EXPORT
404 bool processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
405 bool theDumpModelDo = false);
406
408 void saveResultNames(const FeaturePtr& theFeature);
409
411 bool hasColoredShape(const ResultPtr& theResult, bool theGetSubResults = false) const;
412
414 bool isParentResult(const ResultPtr& theResult) const;
415
417 bool isDefaultColor(const ResultPtr& theResult) const;
418
420 bool isDefaultDeflection(const ResultPtr& theResult) const;
421
423 bool isDefaultTransparency(const ResultPtr& theResult) const;
424
426 void dumpPostponed(bool theDumpFolders = false);
427
428 //Dump global variables for multifile dump
429 void dumpGlobalForMultiFile(const FeaturePtr& theEntity);
430
431private:
432 struct EntityName {
433 std::string myCurrentName;
434 std::string myUserName;
435 bool myIsDefault;
436 bool myIsDumped;
437
438 EntityName() {}
439
440 EntityName(const std::string& theCurName, const std::string& theUserName, bool theDefault)
441 : myCurrentName(theCurName),
442 myUserName(theUserName),
443 myIsDefault(theDefault),
444 myIsDumped(false)
445 {}
446 };
447 typedef std::map<EntityPtr, EntityName> EntityNameMap;
448
449 struct LastDumpedEntity {
450 EntityPtr myEntity;
451 bool myUserName;
453 std::list<ResultPtr> myResults;
454
455 LastDumpedEntity(EntityPtr theEntity, bool theUserName,
456 const std::list<ResultPtr>& theResults = std::list<ResultPtr>())
457 : myEntity(theEntity), myUserName(theUserName), myResults(theResults)
458 {}
459 };
460 typedef std::stack<LastDumpedEntity> DumpStack;
461
462 static ModelHighAPI_Dumper* mySelf;
463
464 class DumpStorageBuffer;
465 DumpStorageBuffer* myDumpStorage;
466
467 ModulesSet myModules;
468 EntityNameMap myNames;
469 DumpStack myEntitiesStack;
470
471 NbFeaturesMap myFeatureCount;
472
474 std::set<FeaturePtr> myFeaturesToSkip;
475
476 std::list<EntityPtr> myPostponed;
477 bool myDumpPostponedInProgress;
478
479 std::string myDumpDir;
480 bool myIsMultifile;
481
482protected:
484 std::set<EntityPtr> myNotDumpedEntities;
485
486 friend class SketchAPI_Sketch;
487 friend class ModelHighAPI_Folder;
488};
489
490#endif
3D direction defined by three normalized coordinates
Definition: GeomAPI_Dir.h:34
3D point defined by three coordinates
Definition: GeomAPI_Pnt.h:38
Attribute that contains 3D direction coordinates.
Definition: GeomDataAPI_Dir.h:35
Attribute that contains array of 2D point coordinates.
Definition: GeomDataAPI_Point2DArray.h:34
Attribute that contains 2D point coordinates.
Definition: GeomDataAPI_Point2D.h:37
Attribute that contains 3D point coordinates.
Definition: GeomDataAPI_Point.h:36
Attribute that contains boolean value.
Definition: ModelAPI_AttributeBoolean.h:31
API for the attribute that contains several double in the array inside.
Definition: ModelAPI_AttributeDoubleArray.h:32
Attribute that contains real value with double precision.
Definition: ModelAPI_AttributeDouble.h:34
API for the attribute that contains several integers in the array inside.
Definition: ModelAPI_AttributeIntArray.h:36
API for the attribute that contains integer (int).
Definition: ModelAPI_AttributeInteger.h:34
Attribute that contains list of references to features (located in the same document) or references t...
Definition: ModelAPI_AttributeRefAttrList.h:34
Attribute that contains reference to an attribute of a feature or reference to a feature (switchable)
Definition: ModelAPI_AttributeRefAttr.h:33
Attribute that contains list of references to features (located in the same document).
Definition: ModelAPI_AttributeRefList.h:33
Attribute that contains reference to feature (located in the same document).
Definition: ModelAPI_AttributeReference.h:32
Attribute that contains list of references to the sub-shapes with possibility to manage them.
Definition: ModelAPI_AttributeSelectionList.h:37
Attribute that contains reference to the sub-shape of some result, the selected shape.
Definition: ModelAPI_AttributeSelection.h:35
API for the attribute that contains several strings in the array inside.
Definition: ModelAPI_AttributeStringArray.h:32
API for the attribute that contains std (null terminated) string.
Definition: ModelAPI_AttributeString.h:33
Generic attribute of the Object.
Definition: ModelAPI_Attribute.h:34
Feature that consists of other features: like sketcher with edges inside.
Definition: ModelAPI_CompositeFeature.h:33
Document for internal data structure of any object storage.
Definition: ModelAPI_Document.h:53
Represents a common parent class for Objects and documents.
Definition: ModelAPI_Entity.h:32
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:41
Folder feature (groups the features).
Definition: ModelAPI_Folder.h:31
Represents any object in the data model and in the object browser.
Definition: ModelAPI_Object.h:45
The result of a feature.
Definition: ModelAPI_Result.h:37
Process selection attributes to be dumped by geometric properties.
Definition: ModelHighAPI_Dumper.h:127
Process selection attributes to be dumped by weak naming.
Definition: ModelHighAPI_Dumper.h:138
Storage for the dumped data.
Definition: ModelHighAPI_Dumper.h:88
Dump engine for the model.
Definition: ModelHighAPI_Dumper.h:81
virtual void exportVariables() const
Export variables names to another module (calls exportVariable implemented in python)
Definition: ModelHighAPI_Dumper.cpp:1778
void setDumpDir(const std::string &theDumpDir)
Keep path to the true dumping directory.
Definition: ModelHighAPI_Dumper.h:180
void importModule(const std::string &theModuleName)
Add module to list of imported modules.
Definition: ModelHighAPI_Dumper.cpp:952
void setIsMultiDump(const bool theValue)
Sets multifile flag value.
Definition: ModelHighAPI_Dumper.cpp:441
virtual std::string attributeGetter(const FeaturePtr &theFeature, const std::string &theAttrName) const =0
Return name of getter for corresponding attribute.
void addCustomStorage(const DumpStoragePtr &theStorage)
Add custom storage to collect corresponding dump.
Definition: ModelHighAPI_Dumper.cpp:544
const std::string & parentName(const FeaturePtr &theFeature)
Returns name of parent composite feature for specified entity.
Definition: ModelHighAPI_Dumper.cpp:672
virtual ~ModelHighAPI_Dumper()
Destructor.
Definition: ModelHighAPI_Dumper.cpp:528
virtual void dumpFeature(const FeaturePtr &theFeature, const bool theForce=false)=0
Dump given feature.
void clearNotDumped()
clear list of not dumped entities
Definition: ModelHighAPI_Dumper.cpp:562
void doNotDumpFeature(const FeaturePtr &theFeature)
Set a feature that should not be dumped anyway.
Definition: ModelHighAPI_Dumper.h:218
bool process(const std::shared_ptr< ModelAPI_Document > &theDoc, const std::string &theFileName)
Dump given document into the file.
Definition: ModelHighAPI_Dumper.cpp:705
void postpone(const EntityPtr &theEntity)
Set feature postponed until all its dependencies are not dumped.
Definition: ModelHighAPI_Dumper.cpp:886
void dumpSubFeatureNameAndColor(const std::string theSubFeatureGet, const FeaturePtr &theSubFeature)
Dump sub-feature name and color, without dumping feature creation.
Definition: ModelHighAPI_Dumper.cpp:929
bool isDumped(const EntityPtr &theEntity) const
Check the entity is already dumped.
Definition: ModelHighAPI_Dumper.cpp:1040
virtual void dumpFolder(const FolderPtr &theFolder)=0
Dump folder.
static ModelHighAPI_Dumper * getInstance()
Returns instance of a dumper.
Definition: ModelHighAPI_Dumper.cpp:539
virtual void dumpParameter(const FeaturePtr &theFeature)=0
Dump parameter feature only.
size_t indexOfFirstNotDumped(const std::shared_ptr< ModelAPI_AttributeRefList > &theRefList) const
Returns the index of the first object in the list which is not dumped yet.
Definition: ModelHighAPI_Dumper.cpp:1070
void clearCustomStorage()
Clear custom storages list.
Definition: ModelHighAPI_Dumper.cpp:549
ModelHighAPI_Dumper & operator<<(const char theChar)
Dump character.
Definition: ModelHighAPI_Dumper.cpp:1182
const std::string & name(const EntityPtr &theEntity, bool theSaveNotDumped=true, bool theUseEntityName=false, bool theSetIsDumped=false)
Returns name of specified entity.
Definition: ModelHighAPI_Dumper.cpp:579
std::string getDumpDir() const
Return path to the true dumping directory.
Definition: ModelHighAPI_Dumper.h:182
void dumpEntitySetName()
Dump "setName" command if last entity had user-defined name.
Definition: ModelHighAPI_Dumper.cpp:957
bool dumpCommentBeforeFeature(const FeaturePtr &theFeature) const
Returns true if the special comment line to improve the readability should be printed before the feat...
Definition: ModelHighAPI_Dumper.cpp:1172
static void setInstance(ModelHighAPI_Dumper *theDumper)
Sets instance of a dumper.
Definition: ModelHighAPI_Dumper.cpp:533
ModelHighAPI_Dumper()
Default constructor.
Definition: ModelHighAPI_Dumper.cpp:521
std::set< EntityPtr > myNotDumpedEntities
list of entities, used by other features but not dumped yet
Definition: ModelHighAPI_Dumper.h:484
void newline()
Print std::endl from Python.
Definition: ModelHighAPI_Dumper.cpp:1704
virtual void exportVariable(const std::string &, const std::string &) const
Export one variable name to another module (implemented in python)
Definition: ModelHighAPI_Dumper.h:377
virtual std::string featureWrapper(const FeaturePtr &theFeature) const =0
Return name of wrapper feature.
Class for filling ModelAPI_Folder.
Definition: ModelHighAPI_Folder.h:39
Interface for Sketch feature.
Definition: SketchAPI_Sketch.h:71