SHAPER  9.12.0
ModelHighAPI_Dumper.h
1 // Copyright (C) 2014-2023 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 
33 class GeomAPI_Pnt;
34 class GeomAPI_Dir;
35 
36 class GeomDataAPI_Dir;
37 class GeomDataAPI_Point;
40 
41 class ModelAPI_Attribute;
56 class ModelAPI_Document;
57 class ModelAPI_Entity;
58 class ModelAPI_Feature;
59 class ModelAPI_Folder;
60 class ModelAPI_Object;
61 class ModelAPI_Result;
62 
63 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
64 typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
65 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
66 typedef std::shared_ptr<ModelAPI_Folder> FolderPtr;
67 typedef std::shared_ptr<ModelAPI_Result> ResultPtr;
68 
69 typedef std::set<std::string> ModulesSet;
70 typedef std::map<DocumentPtr, std::map<std::string, std::pair<int, int> > > NbFeaturesMap;
71 
81 {
82 public:
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 
144 public:
146  MODELHIGHAPI_EXPORT
148 
150  MODELHIGHAPI_EXPORT
151  static void setInstance(ModelHighAPI_Dumper* theDumper);
152 
154  MODELHIGHAPI_EXPORT
156 
158  MODELHIGHAPI_EXPORT
159  virtual ~ModelHighAPI_Dumper();
160 
162  MODELHIGHAPI_EXPORT
163  void addCustomStorage(const DumpStoragePtr& theStorage);
165  MODELHIGHAPI_EXPORT
166  void clearCustomStorage();
169  MODELHIGHAPI_EXPORT
170  bool process(const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theFileName);
171 
175  MODELHIGHAPI_EXPORT
176  void setDumpDir(const std::string& theDumpDir) { myDumpDir = theDumpDir; }
178  MODELHIGHAPI_EXPORT std::string getDumpDir() const { return myDumpDir; }
179 
182  MODELHIGHAPI_EXPORT
183  void importModule(const std::string& theModuleName);
184 
192  MODELHIGHAPI_EXPORT
193  const std::string& name(const EntityPtr& theEntity, bool theSaveNotDumped = true,
194  bool theUseEntityName = false, bool theSetIsDumped = false);
195 
197  MODELHIGHAPI_EXPORT
198  const std::string& parentName(const FeaturePtr& theFeature);
199 
201  virtual void dumpParameter(const FeaturePtr& theFeature) = 0;
203  virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
205  virtual void dumpFolder(const FolderPtr& theFolder) = 0;
206 
209  MODELHIGHAPI_EXPORT
210  void postpone(const EntityPtr& theEntity);
211 
213  MODELHIGHAPI_EXPORT
214  void doNotDumpFeature(const FeaturePtr& theFeature)
215  { myFeaturesToSkip.insert(theFeature); }
216 
221  MODELHIGHAPI_EXPORT
222  void dumpSubFeatureNameAndColor(const std::string theSubFeatureGet,
223  const FeaturePtr& theSubFeature);
224 
226  virtual std::string attributeGetter(const FeaturePtr& theFeature,
227  const std::string& theAttrName) const = 0;
228 
230  virtual std::string featureWrapper(const FeaturePtr& theFeature) const = 0;
231 
233  MODELHIGHAPI_EXPORT
234  ModelHighAPI_Dumper& operator<<(const char theChar);
236  MODELHIGHAPI_EXPORT
237  ModelHighAPI_Dumper& operator<<(const char* theString);
239  MODELHIGHAPI_EXPORT
240  ModelHighAPI_Dumper& operator<<(const std::string& theString);
242  MODELHIGHAPI_EXPORT
243  ModelHighAPI_Dumper& operator<<(const std::wstring& theString);
245  MODELHIGHAPI_EXPORT
246  ModelHighAPI_Dumper& operator<<(const bool theValue);
248  MODELHIGHAPI_EXPORT
249  ModelHighAPI_Dumper& operator<<(const int theValue);
251  MODELHIGHAPI_EXPORT
252  ModelHighAPI_Dumper& operator<<(const double theValue);
254  friend
255  MODELHIGHAPI_EXPORT
257  std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
258 
260  MODELHIGHAPI_EXPORT void newline();
261 
264  MODELHIGHAPI_EXPORT
265  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
268  MODELHIGHAPI_EXPORT
269  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir);
270 
273  MODELHIGHAPI_EXPORT
274  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Dir>& theDir);
277  MODELHIGHAPI_EXPORT
278  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point>& thePoint);
281  MODELHIGHAPI_EXPORT
282  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2D>& thePoint);
284  MODELHIGHAPI_EXPORT
285  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<GeomDataAPI_Point2DArray>& thePointArray);
286 
288  MODELHIGHAPI_EXPORT
289  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool);
291  MODELHIGHAPI_EXPORT
292  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt);
294  MODELHIGHAPI_EXPORT
295  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeIntArray>& theArray);
297  MODELHIGHAPI_EXPORT
298  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal);
300  MODELHIGHAPI_EXPORT
301  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeDoubleArray>& theArray);
303  MODELHIGHAPI_EXPORT
304  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
306  MODELHIGHAPI_EXPORT
307  ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
308 
310  MODELHIGHAPI_EXPORT
311  ModelHighAPI_Dumper& operator<<(const FolderPtr& theFolder);
312 
314  MODELHIGHAPI_EXPORT
315  ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult);
316 
318  MODELHIGHAPI_EXPORT
319  ModelHighAPI_Dumper& operator<<(const std::list<ResultPtr>& theResults);
320 
322  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
323  operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
325  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
326  operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
327 
329  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
330  operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
333  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
334  operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
337  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
338  operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
340  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
341  operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
343  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
344  operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
346  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
347  operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
349  MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
350  operator<<(const std::shared_ptr<ModelAPI_AttributeStringArray>& theArray);
351 
353  MODELHIGHAPI_EXPORT void clearNotDumped();
354 
356  MODELHIGHAPI_EXPORT
357  bool isDumped(const EntityPtr& theEntity) const;
359  MODELHIGHAPI_EXPORT
360  bool isDumped(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr) const;
362  MODELHIGHAPI_EXPORT
363  bool isDumped(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList) const;
364 
366  MODELHIGHAPI_EXPORT
367  size_t indexOfFirstNotDumped(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList) const;
368 
370  MODELHIGHAPI_EXPORT virtual void exportVariables() const;
371 
373  MODELHIGHAPI_EXPORT virtual void exportVariable(const std::string& /*theEntry*/,
374  const std::string& /*theVarName*/) const {}
375 
378  MODELHIGHAPI_EXPORT bool dumpCommentBeforeFeature(const FeaturePtr& theFeature) const;
379 
380 protected:
382  MODELHIGHAPI_EXPORT void dumpEntitySetName();
383 
384 private:
386  const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
387 
389  bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
390 
392  bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
393  bool isForce = false,
394  bool isDumpModelDo = true);
395 
399  MODELHIGHAPI_EXPORT
400  bool processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
401  bool theDumpModelDo = false);
402 
404  void saveResultNames(const FeaturePtr& theFeature);
405 
407  bool isDefaultColor(const ResultPtr& theResult) const;
408 
410  bool isDefaultDeflection(const ResultPtr& theResult) const;
411 
413  bool isDefaultTransparency(const ResultPtr& theResult) const;
414 
416  void dumpPostponed(bool theDumpFolders = false);
417 
418 private:
419  struct EntityName {
420  std::string myCurrentName;
421  std::string myUserName;
422  bool myIsDefault;
423  bool myIsDumped;
424 
425  EntityName() {}
426 
427  EntityName(const std::string& theCurName, const std::string& theUserName, bool theDefault)
428  : myCurrentName(theCurName),
429  myUserName(theUserName),
430  myIsDefault(theDefault),
431  myIsDumped(false)
432  {}
433  };
434  typedef std::map<EntityPtr, EntityName> EntityNameMap;
435 
436  struct LastDumpedEntity {
437  EntityPtr myEntity;
438  bool myUserName;
440  std::list<ResultPtr> myResults;
441 
442  LastDumpedEntity(EntityPtr theEntity, bool theUserName,
443  const std::list<ResultPtr>& theResults = std::list<ResultPtr>())
444  : myEntity(theEntity), myUserName(theUserName), myResults(theResults)
445  {}
446  };
447  typedef std::stack<LastDumpedEntity> DumpStack;
448 
449  static ModelHighAPI_Dumper* mySelf;
450 
451  class DumpStorageBuffer;
452  DumpStorageBuffer* myDumpStorage;
453 
454  ModulesSet myModules;
455  EntityNameMap myNames;
456  DumpStack myEntitiesStack;
457 
458  NbFeaturesMap myFeatureCount;
459 
461  std::set<FeaturePtr> myFeaturesToSkip;
462 
463  std::list<EntityPtr> myPostponed;
464  bool myDumpPostponedInProgress;
465 
466  std::string myDumpDir;
467 
468 protected:
470  std::set<EntityPtr> myNotDumpedEntities;
471 
472  friend class SketchAPI_Sketch;
473  friend class ModelHighAPI_Folder;
474 };
475 
476 #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:52
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:39
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:35
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:1684
void setDumpDir(const std::string &theDumpDir)
Keep path to the true dumping directory.
Definition: ModelHighAPI_Dumper.h:176
void importModule(const std::string &theModuleName)
Add module to list of imported modules.
Definition: ModelHighAPI_Dumper.cpp:895
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:538
const std::string & parentName(const FeaturePtr &theFeature)
Returns name of parent composite feature for specified entity.
Definition: ModelHighAPI_Dumper.cpp:666
virtual ~ModelHighAPI_Dumper()
Destructor.
Definition: ModelHighAPI_Dumper.cpp:522
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:556
void doNotDumpFeature(const FeaturePtr &theFeature)
Set a feature that should not be dumped anyway.
Definition: ModelHighAPI_Dumper.h:214
bool process(const std::shared_ptr< ModelAPI_Document > &theDoc, const std::string &theFileName)
Dump given document into the file.
Definition: ModelHighAPI_Dumper.cpp:699
void postpone(const EntityPtr &theEntity)
Set feature postponed until all its dependencies are not dumped.
Definition: ModelHighAPI_Dumper.cpp:835
void dumpSubFeatureNameAndColor(const std::string theSubFeatureGet, const FeaturePtr &theSubFeature)
Dump sub-feature name and color, without dumping feature creation.
Definition: ModelHighAPI_Dumper.cpp:872
bool isDumped(const EntityPtr &theEntity) const
Check the entity is already dumped.
Definition: ModelHighAPI_Dumper.cpp:965
virtual void dumpFolder(const FolderPtr &theFolder)=0
Dump folder.
static ModelHighAPI_Dumper * getInstance()
Returns instance of a dumper.
Definition: ModelHighAPI_Dumper.cpp:533
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:995
void clearCustomStorage()
Clear custom storages list.
Definition: ModelHighAPI_Dumper.cpp:543
ModelHighAPI_Dumper & operator<<(const char theChar)
Dump character.
Definition: ModelHighAPI_Dumper.cpp:1089
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:573
std::string getDumpDir() const
Return path to the true dumping directory.
Definition: ModelHighAPI_Dumper.h:178
void dumpEntitySetName()
Dump "setName" command if last entity had user-defined name.
Definition: ModelHighAPI_Dumper.cpp:900
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:1079
static void setInstance(ModelHighAPI_Dumper *theDumper)
Sets instance of a dumper.
Definition: ModelHighAPI_Dumper.cpp:527
ModelHighAPI_Dumper()
Default constructor.
Definition: ModelHighAPI_Dumper.cpp:516
std::set< EntityPtr > myNotDumpedEntities
list of entities, used by other features but not dumped yet
Definition: ModelHighAPI_Dumper.h:470
void newline()
Print std::endl from Python.
Definition: ModelHighAPI_Dumper.cpp:1610
virtual void exportVariable(const std::string &, const std::string &) const
Export one variable name to another module (implemented in python)
Definition: ModelHighAPI_Dumper.h:373
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:70