X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FModelHighAPI%2FModelHighAPI_Dumper.h;h=ccd80c626bd8da98bc5c46553cd73418c83284bf;hb=010db3efe2e727c4f2cc2e99073e036c5ac07f46;hp=b9478e61c2c00321c44acf6730943678c62adde0;hpb=a94fc319f2aa64b43c9a73b5ff7063923648faec;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index b9478e61c..ccd80c626 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #ifndef ModelHighAPI_Dumper_H_ @@ -54,20 +53,89 @@ class ModelAPI_CompositeFeature; class ModelAPI_Document; class ModelAPI_Entity; class ModelAPI_Feature; +class ModelAPI_Folder; class ModelAPI_Object; class ModelAPI_Result; typedef std::shared_ptr DocumentPtr; typedef std::shared_ptr EntityPtr; typedef std::shared_ptr FeaturePtr; +typedef std::shared_ptr FolderPtr; typedef std::shared_ptr ResultPtr; +typedef std::set ModulesSet; +typedef std::map > > NbFeaturesMap; + /**\class ModelHighAPI_Dumper * \ingroup CPPHighAPI * \brief Dump engine for the model + * + * The dumper can be customized by the set of storages (DumpStorage), for example to identify + * dumped selected objects by their geometrical properties. By default, the dump is executed to + * store original names of the selected shapes. */ class ModelHighAPI_Dumper { +public: + /** \class DumpStorage + * \ingroup CPPHighAPI + * \brief Storage for the dumped data. Process selection attributes to be dumped by naming. + */ + class DumpStorage + { + public: + DumpStorage() {} + MODELHIGHAPI_EXPORT DumpStorage(const DumpStorage& theOther); + MODELHIGHAPI_EXPORT const DumpStorage& operator=(const DumpStorage& theOther); + + void setFilenameSuffix(const std::string& theSuffix) { myFilenameSuffix = theSuffix; } + + protected: + std::ostringstream& buffer() { return myDumpBuffer; } + std::ostringstream& fullDump() { return myFullDump; } + + MODELHIGHAPI_EXPORT virtual void reserveBuffer(); + MODELHIGHAPI_EXPORT virtual void restoreReservedBuffer(); + + MODELHIGHAPI_EXPORT + virtual void write(const std::shared_ptr& theAttrSelect); + + MODELHIGHAPI_EXPORT + virtual bool exportTo(const std::string& theFilename, const ModulesSet& theUsedModules); + + private: + std::string myFilenameSuffix; + std::ostringstream myDumpBuffer; + std::ostringstream myFullDump; + + std::stack myDumpBufferHideout; + + friend class ModelHighAPI_Dumper; + }; + typedef std::shared_ptr DumpStoragePtr; + + /** \class DumpStorageGeom + * \ingroup CPPHighAPI + * \brief Process selection attributes to be dumped by geometric properties. + */ + class DumpStorageGeom : public DumpStorage + { + protected: + MODELHIGHAPI_EXPORT + virtual void write(const std::shared_ptr& theAttrSelect); + }; + + /** \class DumpStorageWeak + * \ingroup CPPHighAPI + * \brief Process selection attributes to be dumped by weak naming. + */ + class DumpStorageWeak : public DumpStorage + { + protected: + MODELHIGHAPI_EXPORT + virtual void write(const std::shared_ptr& theAttrSelect); + }; + public: /// Default constructor MODELHIGHAPI_EXPORT @@ -82,7 +150,15 @@ public: static ModelHighAPI_Dumper* getInstance(); /// Destructor - virtual ~ModelHighAPI_Dumper() {} + MODELHIGHAPI_EXPORT + virtual ~ModelHighAPI_Dumper(); + + /// Add custom storage to collect corresponding dump + MODELHIGHAPI_EXPORT + void addCustomStorage(const DumpStoragePtr& theStorage); + /// Clear custom storages list + MODELHIGHAPI_EXPORT + void clearCustomStorage(); /// Dump given document into the file /// \return \c true, if succeed @@ -91,11 +167,8 @@ public: /// Add module to list of imported modules /// \param theModuleName name of the module to be imported - /// \param theObject name of the entity to be imported - /// from the module (if empty, while module will be imported) MODELHIGHAPI_EXPORT - void importModule(const std::string& theModuleName, - const std::string& theObject = std::string()); + void importModule(const std::string& theModuleName); /// Returns name of specified entity /// \param theEntity [in] named entity @@ -116,6 +189,13 @@ public: virtual void dumpParameter(const FeaturePtr& theFeature) = 0; /// Dump given feature virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0; + /// Dump folder + virtual void dumpFolder(const FolderPtr& theFolder) = 0; + + /// Set feature postponed until all its dependencies are not dumped. + /// The name of the feature is stored anyway. + MODELHIGHAPI_EXPORT + void postpone(const EntityPtr& theEntity); /// Set a feature that should not be dumped anyway MODELHIGHAPI_EXPORT @@ -137,10 +217,6 @@ public: /// Return name of wrapper feature virtual std::string featureWrapper(const FeaturePtr& theFeature) const = 0; - /// Save all dumps into specified file - MODELHIGHAPI_EXPORT - bool exportTo(const std::string& theFileName); - /// Dump character MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const char theChar); @@ -203,10 +279,18 @@ public: MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity); + /// Dump folder + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const FolderPtr& theFolder); + /// Dump result MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult); + /// Dump a list of results + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const std::list& theResults); + /// Dump Attribute MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttr); @@ -238,12 +322,19 @@ public: MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theArray); - /// Clear dump buffer - MODELHIGHAPI_EXPORT - void clear(bool bufferOnly = false); /// clear list of not dumped entities MODELHIGHAPI_EXPORT void clearNotDumped(); + /// Check the entity is already dumped + MODELHIGHAPI_EXPORT + bool isDumped(const EntityPtr& theEntity) const; + /// Check theRefAttr is already dumped + MODELHIGHAPI_EXPORT + bool isDumped(const std::shared_ptr& theRefAttr) const; + /// Check all objects in theRefList are already dumped + MODELHIGHAPI_EXPORT + bool isDumped(const std::shared_ptr& theRefList) const; + protected: /// Dump "setName" command if last entity had user-defined name MODELHIGHAPI_EXPORT void dumpEntitySetName(); @@ -266,9 +357,6 @@ private: bool processSubs(const std::shared_ptr& theComposite, bool theDumpModelDo = false); - /// Check the entity is already dumped - bool isDumped(const EntityPtr& theEntity) const; - /// Stores names of results for the given feature void saveResultNames(const FeaturePtr& theFeature); @@ -278,6 +366,12 @@ private: /// Check the result feature has default deflection bool isDefaultDeflection(const ResultPtr& theResult) const; + /// Check the result feature has default transparency + bool isDefaultTransparency(const ResultPtr& theResult) const; + + /// Dump postponed entities + void dumpPostponed(bool theDumpFolders = false); + private: struct EntityName { std::string myCurrentName; ///< default name of current feature @@ -294,10 +388,7 @@ private: myIsDumped(false) {} }; - - typedef std::map EntityNameMap; - typedef std::map > ModulesMap; - typedef std::map > NbFeaturesMap; + typedef std::map EntityNameMap; struct LastDumpedEntity { EntityPtr myEntity; ///< last dumped entity @@ -306,18 +397,18 @@ private: std::list myResults; LastDumpedEntity(EntityPtr theEntity, bool theUserName, - const std::list& theResults) + const std::list& theResults = std::list()) : myEntity(theEntity), myUserName(theUserName), myResults(theResults) {} }; - typedef std::stack DumpStack; + typedef std::stack DumpStack; static ModelHighAPI_Dumper* mySelf; - std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data - std::ostringstream myFullDump; ///< full buffer of dumped data + class DumpStorageBuffer; + DumpStorageBuffer* myDumpStorage; ///< storage of dumped data - ModulesMap myModules; ///< modules and entities to be imported + ModulesSet myModules; ///< modules and entities to be imported EntityNameMap myNames; ///< names of the entities DumpStack myEntitiesStack; ///< stack of dumped entities @@ -326,11 +417,15 @@ private: /// features which should not be dumped (like coincidence and tangency created by tangent arc) std::set myFeaturesToSkip; + std::list myPostponed; ///< list of postponed entities (sketch constraints or folders) + bool myDumpPostponedInProgress; ///< processing postponed is in progress + protected: - /// list of entities, used by other features but not dumped yet + /// list of entities, used by other features but not dumped yet std::set myNotDumpedEntities; friend class SketchAPI_Sketch; + friend class ModelHighAPI_Folder; }; #endif