Salome HOME
Cut too long lines
[modules/shaper.git] / src / Model / Model_Objects.h
index 19572e143001cce978f159a0c629c30f5d6bfb88..b9b8d7f181b7af15719cb4ff689895a943358567 100644 (file)
@@ -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
 //
 // 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 Model_Objects_H_
@@ -40,6 +39,8 @@
 static Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper);
 static Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2);
 
+extern int kUNDEFINED_FEATURE_INDEX;
+
 /**\class Model_Objects
  * \ingroup DataModel
  * \brief Manager of objects of the document. Normally one this class corresponds to
@@ -49,7 +50,7 @@ static Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLa
 class Model_Objects
 {
  public:
-  //! Registers the fieature in the data structure
+  //! Registers the feature 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;
   //!        if it is null, the added feature will be the first
@@ -109,6 +110,10 @@ class Model_Objects
   //! \param theAllowFolder take into account grouping feature by folders
   int size(const std::string& theGroupID, const bool theAllowFolder = false);
 
+  //! Returns the parent object of this child. This may be result or feature, parent of a
+  //! top result. Fast method, that uses internal data structure specifics.
+  std::shared_ptr<ModelAPI_Object> parent(const std::shared_ptr<ModelAPI_Object> theChild);
+
   //! 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);
@@ -118,10 +123,6 @@ 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);
@@ -162,9 +163,17 @@ class Model_Objects
   std::shared_ptr<ModelAPI_Folder> findFolder(
       const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
       const bool theBelow);
+  //! Search a folder containing the given feature.
+  //! Additionally calculates a zero-based index of the feature in this folder.
+  //! \param theFeature feature to search
+  //! \param theIndexInFolder zero-based index in the folder or -1 if the feature is top-level.
+  //! \return the folder containing the feature or empty pointer if the feature is top-level.
+  std::shared_ptr<ModelAPI_Folder> findContainingFolder(
+      const std::shared_ptr<ModelAPI_Feature>& theFeature,
+      int& theIndexInFolder);
   //! Add a list of features to the folder. The correctness of the adding is not performed
   //! (such checks have been done in corresponding find.. method).
-  //! \return \c true if the movement is successfull
+  //! \return \c true if the movement is successful
   bool moveToFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
                     const std::shared_ptr<ModelAPI_Folder>& theFolder);
   //! Remove features from the folder
@@ -182,7 +191,7 @@ class Model_Objects
   //! Returns the owner of this manager
   DocumentPtr owner() {return myDoc;}
 
-  //! Deletes all managed features wit hemmitting of corresponded signal
+  //! Deletes all managed features with emitting of corresponded signal
   ~Model_Objects();
 
  protected:
@@ -194,15 +203,15 @@ class Model_Objects
   //! feature type + "_" + index
   void setUniqueName(FeaturePtr theFeature);
 
-  //! Initializes the foldet with an unique name ("Folder_" + index)
+  //! Initializes the folder 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 theUpdated list of labels that are marked as modified, so features 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 theOpen - on open nothing must be re-executed, 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 theOpen, const bool theExecuteFeatures, const bool theFlush);
@@ -243,8 +252,9 @@ class Model_Objects
 
   /// Returns the next (from the history point of view) feature, any: invisible or disabled
   /// \param theCurrent previous to the resulting feature
-  /// \param theReverse if it is true, iterates in reverced order (next becomes previous)
-  FeaturePtr nextFeature(FeaturePtr theCurrent, const bool theReverse = false);
+  /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+  /// \param theIndex may be used for optimization: index of theCurrent in references array
+  FeaturePtr nextFeature(FeaturePtr theCurrent, int& theIndex, const bool theReverse = false);
   /// Returns to the first (from the history point of view) feature, any: invisible or disabled
   FeaturePtr firstFeature();
   /// Returns to the last (from the history point of view) feature, any: invisible or disabled
@@ -254,8 +264,8 @@ class Model_Objects
 
   /// 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);
+  /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+  TDF_Label nextLabel(TDF_Label theCurrent, int& theIndex, const bool theReverse = false);
 
   /// Returns the result group identifier of the given feature (for this at least one result must
   /// be created before)
@@ -269,14 +279,14 @@ class Model_Objects
   //! 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
+  //! synchronizes 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.
+  // Check whether the predefined-image of the result had user-defined name.
   // If yes, return this name.
   bool hasCustomName(DataPtr theFeatureData,
                      ResultPtr theResult,
@@ -284,12 +294,12 @@ class Model_Objects
                      std::string& theParentName) const;
 
   /// Return object representing a folder or empty pointer
-  ObjectPtr folder(TDF_Label theLabel) const;
+  const ObjectPtr& folder(TDF_Label theLabel) const;
 
  private:
   TDF_Label myMain; ///< main label of the data storage
 
-  DocumentPtr myDoc; ///< doc,ument, owner of this objects manager: needed for events creation
+  DocumentPtr myDoc; ///< document, owner of this objects manager: needed for events creation
 
   /// All managed features (not only in history of OB)
   /// For optimization mapped by labels
@@ -299,7 +309,7 @@ class Model_Objects
   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.
+  /// Each array is updated by demand from scratch, by browsing all the features in the history.
   std::map<std::string, std::vector<ObjectPtr> > myHistory;
 
   friend class Model_Document;