Salome HOME
Set unique name to folder (Task 2.3. Ability to put consecutive Features in a folder)
[modules/shaper.git] / src / Model / Model_Objects.h
index 9f947c776f62d0f392f076e63198c4d11736242b..532b161ad1cf34a2b1299ff6587880423aeeb66b 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        Model_Objects.h
-// Created:     15 May 2015
-// Author:      Mikhail PONIKAROV
+// 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 Model_Objects_H_
 #define Model_Objects_H_
@@ -10,6 +24,7 @@
 #include <Model.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Folder.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultParameter.h>
 
@@ -36,7 +51,7 @@ class Model_Objects
  public:
   //! Registers the fieature in the data structure
   //! \param theFeature feature that must be added to the data structure
-  //! \param theAfterThis the feature will be added after this feature; 
+  //! \param theAfterThis the feature will be added after this feature;
   //!        if it is null, the added feature will be the first
   void addFeature(FeaturePtr theFeature, const FeaturePtr theAfterThis);
 
@@ -82,12 +97,18 @@ class Model_Objects
   //! Returns the feature in the group by the index (started from zero)
   //! \param theGroupID group that contains a feature
   //! \param theIndex zero-based index of feature in the group
-  ObjectPtr object(const std::string& theGroupID, const int theIndex);
+  //! \param theAllowFolder take into account grouping feature by folders
+  ObjectPtr object(const std::string& theGroupID,
+                   const int theIndex,
+                   const bool theAllowFolder = false);
 
   //! Returns the number of features in the group
-  int size(const std::string& theGroupID);
+  //! \param theGroupID group of objects
+  //! \param theAllowFolder take into account grouping feature by folders
+  int size(const std::string& theGroupID, const bool theAllowFolder = false);
 
-  ///! Returns all (and disabled) results of the given type. Not fast method (iterates all features).
+  //! Returns all (and disabled) results of the given type.
+  //! Not fast method (iterates all features).
   void allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults);
 
   //! Returns the number of all features: in the history or not
@@ -95,6 +116,10 @@ class Model_Objects
   //! Returns the feature by zero-based index: features in the history or not
   std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex);
 
+  //! Returns feature by the id of the feature (produced by the Data "featureId" method)
+  std::shared_ptr<ModelAPI_Feature> featureById(const int theId);
+
+
   /// Creates a construction result
   std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
@@ -111,6 +136,9 @@ class Model_Objects
   /// Creates a group result
   std::shared_ptr<ModelAPI_ResultGroup> createGroup(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+  /// Creates a field result
+  std::shared_ptr<ModelAPI_ResultField> createField(
+      const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
   /// Creates a parameter result
   std::shared_ptr<ModelAPI_ResultParameter> createParameter(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
@@ -119,6 +147,10 @@ class Model_Objects
   std::shared_ptr<ModelAPI_Feature>
     feature(const std::shared_ptr<ModelAPI_Result>& theResult);
 
+  /// Creates a folder (group of the features in the object browser)
+  std::shared_ptr<ModelAPI_Folder> createFolder(
+      const std::shared_ptr<ModelAPI_Feature>& theBeforeThis);
+
   //! Sets the owner of this manager
   void setOwner(DocumentPtr theDoc);
 
@@ -133,16 +165,22 @@ class Model_Objects
   //! Returns (creates if needed) the features label
   TDF_Label featuresLabel() const;
 
-  //! Initializes feature with a unique name in this group (unique name is generated as 
+  //! Initializes feature with a unique name in this group (unique name is generated as
   //! feature type + "_" + index
   void setUniqueName(FeaturePtr theFeature);
 
+  //! Initializes the foldet with an unique name ("Folder_" + index)
+  void setUniqueName(FolderPtr theFolder);
+
   //! Synchronizes myFeatures list with the updated document
   //! \param theUpdated list of labels that are marked as modified, so featrues must be also
   //! \param theUpdateReferences causes the update of back-references
+  //! \param theExecuteFeatures requires re-execute modified persistent features
+  //!            (not needed on undo/redo/abort/open)
+  //! \param theOpen - on open nothing must be reexecuted, except not persistent results
   //! \param theFlush makes flush all events in the end of all modifications of this method
   void synchronizeFeatures(const TDF_LabelList& theUpdated, const bool theUpdateReferences,
-    const bool theFlush);
+    const bool theOpen, const bool theExecuteFeatures, const bool theFlush);
   //! Synchronizes the BackReferences list in Data of Features and Results
   void synchronizeBackRefs();
 
@@ -152,16 +190,19 @@ class Model_Objects
   //! Initializes the data fields of the feature
   void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag);
 
-  //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
+  //! Allows to store the result in the data tree of the document
+  //! (attaches 'data' of result to tree)
   void storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
                    std::shared_ptr<ModelAPI_Result> theResult,
                    const int theResultIndex = 0);
 
   //! returns the label of result by index; creates this label if it was not created before
-  TDF_Label resultLabel(const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex);
+  TDF_Label resultLabel(const std::shared_ptr<ModelAPI_Data>& theFeatureData,
+                        const int theResultIndex);
 
   //! Updates the results list of the feature basing on the current data tree
-  void updateResults(FeaturePtr theFeature);
+  //! theProcessed is used to avoid update twice (since the function is recursive)
+  void updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& theProcessed);
 
   /// Internally makes document know that feature was removed or added in history after creation
   void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject);
@@ -186,7 +227,12 @@ class Model_Objects
   /// Returns true if theLater is in history of features creation later than theCurrent
   bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const;
 
-  /// Returns the result group identifier of the given feature (for this at least one result must 
+  /// Returns the next or previous label
+  /// \param theCurrent given label
+  /// \param theReverse if it is true, iterates in reverced order (next becomes previous)
+  TDF_Label nextLabel(TDF_Label theCurrent, const bool theReverse = false);
+
+  /// Returns the result group identifier of the given feature (for this at least one result must
   /// be created before)
   std::string featureResultGroup(FeaturePtr theFeature);
 
@@ -194,10 +240,27 @@ class Model_Objects
   //! history. Not very fast method, for calling once, not in big cycles.
   std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures();
 
+  //! Returns all objects of the document including the hidden features which are not in
+  //! history. Not very fast method, for calling once, not in big cycles.
+  std::list<std::shared_ptr<ModelAPI_Object> > allObjects();
+
   //! synchronises back references for the given object basing on the collected data
   void synchronizeBackRefsForObject(
     const std::set<std::shared_ptr<ModelAPI_Attribute>>& theNewRefs, ObjectPtr theObject);
 
+  /// Just removes all features without touching the document data (to be able undo)
+  virtual void eraseAllFeatures();
+
+  // Check whether the pre-image of the result had user-defined name.
+  // If yes, return this name.
+  bool hasCustomName(DataPtr theFeatureData,
+                     ResultPtr theResult,
+                     int theResultIndex,
+                     std::string& theParentName) const;
+
+  /// Return object representing a folder or empty pointer
+  ObjectPtr folder(TDF_Label theLabel) const;
+
  private:
   TDF_Label myMain; ///< main label of the data storage
 
@@ -207,6 +270,9 @@ class Model_Objects
   /// For optimization mapped by labels
   NCollection_DataMap<TDF_Label, FeaturePtr> myFeatures;
 
+  /// Managed folders
+  NCollection_DataMap<TDF_Label, ObjectPtr> myFolders;
+
   /// Map from group id to the array that contains all objects located in history.
   /// Each array is updated by demand from scratch, by browing all the features in the history.
   std::map<std::string, std::vector<ObjectPtr> > myHistory;
@@ -217,6 +283,8 @@ class Model_Objects
   friend class Model_AttributeReference;
   friend class Model_AttributeRefAttr;
   friend class Model_AttributeRefList;
+  friend class Model_AttributeSelection;
+  friend class Model_SelectionNaming;
 };
 
 #endif