Salome HOME
Issue #2622: Weak naming
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Dumper.h
index ee432d271dad58dee3cf395d979d814d9324e456..5c854bab23b7f02a50a3ff674aca14397b270e11 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2016-20xx CEA/DEN, EDF R&D -->
-
-// File:        ModelHighAPI_Dumper.h
-// Created:     1 August 2016
-// Author:      Artem ZHIDKOV
+// Copyright (C) 2014-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #ifndef ModelHighAPI_Dumper_H_
 #define ModelHighAPI_Dumper_H_
@@ -40,12 +54,14 @@ 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<ModelAPI_Document> DocumentPtr;
 typedef std::shared_ptr<ModelAPI_Entity>   EntityPtr;
 typedef std::shared_ptr<ModelAPI_Feature>  FeaturePtr;
+typedef std::shared_ptr<ModelAPI_Folder>   FolderPtr;
 typedef std::shared_ptr<ModelAPI_Result>   ResultPtr;
 
 /**\class ModelHighAPI_Dumper
@@ -70,6 +86,15 @@ public:
   /// 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; }
+
+  /// Set/unset flag to dump selection attributes by weak naming
+  void setSelectionWeakNaming(bool theDumpByWeakNaming = true)
+  { myWeakNamingSelection = theDumpByWeakNaming; }
+
   /// Dump given document into the file
   /// \return \c true, if succeed
   MODELHIGHAPI_EXPORT
@@ -102,6 +127,18 @@ 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
+  void doNotDumpFeature(const FeaturePtr& theFeature)
+  { myFeaturesToSkip.insert(theFeature); }
 
   /// Dump sub-feature name and color, without dumping feature creation.
   /// Used for features which creates sub-features in their execute method.
@@ -184,6 +221,10 @@ 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);
@@ -225,6 +266,16 @@ public:
   /// 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<ModelAPI_AttributeRefAttr>& theRefAttr) const;
+  /// Check all objects in theRefList are already dumped
+  MODELHIGHAPI_EXPORT
+  bool isDumped(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList) const;
+
 protected:
   /// Dump "setName" command if last entity had user-defined name
   MODELHIGHAPI_EXPORT void dumpEntitySetName();
@@ -247,9 +298,6 @@ private:
   bool processSubs(const std::shared_ptr<ModelAPI_CompositeFeature>& 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);
 
@@ -259,22 +307,32 @@ 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
     std::string myUserName;    ///< user-defined name
     bool        myIsDefault;   ///< \c true if the name is default
+    bool        myIsDumped;    ///< shows that the names of the feature are already stored
 
     EntityName() {}
 
     EntityName(const std::string& theCurName, const std::string& theUserName, bool theDefault)
-      : myCurrentName(theCurName), myUserName(theUserName), myIsDefault(theDefault)
+      : myCurrentName(theCurName),
+        myUserName(theUserName),
+        myIsDefault(theDefault),
+        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, int> >  NbFeaturesMap;
+  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;
 
   struct LastDumpedEntity {
     EntityPtr            myEntity;   ///< last dumped entity
@@ -283,7 +341,7 @@ private:
     std::list<ResultPtr> myResults;
 
     LastDumpedEntity(EntityPtr theEntity, bool theUserName,
-      const std::list<ResultPtr>& theResults)
+      const std::list<ResultPtr>& theResults = std::list<ResultPtr>())
       : myEntity(theEntity), myUserName(theUserName), myResults(theResults)
     {}
   };
@@ -300,11 +358,21 @@ private:
 
   NbFeaturesMap       myFeatureCount;       ///< number of features of each kind
 
+  /// features which should not be dumped (like coincidence and tangency created by tangent arc)
+  std::set<FeaturePtr> myFeaturesToSkip;
+
+  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
+  /// list of entities, used by other features but not dumped yet
   std::set<EntityPtr> myNotDumpedEntities;
 
   friend class SketchAPI_Sketch;
+  friend class ModelHighAPI_Folder;
 };
 
 #endif