-// 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
//
// 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<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#ifndef ModelHighAPI_Dumper_H_
typedef std::shared_ptr<ModelAPI_Folder> FolderPtr;
typedef std::shared_ptr<ModelAPI_Result> ResultPtr;
+typedef std::set<std::string> ModulesSet;
+typedef std::map<DocumentPtr, std::map<std::string, std::pair<int, int> > > 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<ModelAPI_AttributeSelection>& 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<std::string> myDumpBufferHideout;
+
+ friend class ModelHighAPI_Dumper;
+ };
+ typedef std::shared_ptr<DumpStorage> 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<ModelAPI_AttributeSelection>& 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<ModelAPI_AttributeSelection>& theAttrSelect);
+ };
+
public:
/// Default constructor
MODELHIGHAPI_EXPORT
static ModelHighAPI_Dumper* getInstance();
/// Destructor
- virtual ~ModelHighAPI_Dumper() {}
-
- /// Set/unset flag to dump selection attributes by geometrical properties:
- /// inner point in the selected shape
- void setSelectionByGeometry(bool theDumpByGeom = true)
- { myGeometricalSelection = theDumpByGeom; }
+ MODELHIGHAPI_EXPORT
+ virtual ~ModelHighAPI_Dumper();
- /// Set/unset flag to dump selection attributes by weak naming
- void setSelectionWeakNaming(bool theDumpByWeakNaming = true)
- { myWeakNamingSelection = theDumpByWeakNaming; }
+ /// 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
/// 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
/// 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);
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult);
+ /// Dump a list of results
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::list<ResultPtr>& theResults);
+
/// Dump Attribute
MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
MODELHIGHAPI_EXPORT ModelHighAPI_Dumper&
operator<<(const std::shared_ptr<ModelAPI_AttributeStringArray>& theArray);
- /// Clear dump buffer
- MODELHIGHAPI_EXPORT
- void clear(bool bufferOnly = false);
/// clear list of not dumped entities
MODELHIGHAPI_EXPORT void clearNotDumped();
/// Dump composite feature and all it sub-features
bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
- bool isForce = false);
+ bool isForce = false,
+ bool isDumpModelDo = true);
/// Iterate all features in composite feature and dump them into intermediate buffer
/// \param theComposite [in] parent composite feature
myIsDumped(false)
{}
};
-
- typedef std::map<EntityPtr, EntityName> EntityNameMap;
- typedef std::map<std::string, std::set<std::string> > ModulesMap;
- typedef std::map<DocumentPtr, std::map<std::string, std::pair<int, int> > > NbFeaturesMap;
+ typedef std::map<EntityPtr, EntityName> EntityNameMap;
struct LastDumpedEntity {
EntityPtr myEntity; ///< last dumped entity
: myEntity(theEntity), myUserName(theUserName), myResults(theResults)
{}
};
- typedef std::stack<LastDumpedEntity> DumpStack;
+ typedef std::stack<LastDumpedEntity> 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
std::list<EntityPtr> myPostponed; ///< list of postponed entities (sketch constraints or folders)
bool myDumpPostponedInProgress; ///< processing postponed is in progress
- bool myGeometricalSelection; ///< dump selection not by naming, but by coordinates of inner point
- bool myWeakNamingSelection; ///< dump selection by weak naming
-
protected:
/// list of entities, used by other features but not dumped yet
std::set<EntityPtr> myNotDumpedEntities;