Salome HOME
A unit test for the issue #1799
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.h
index 51001b6d0bbb1918df625d4c233a88981784600d..0caf621b18c0f8cabc9c61816110723b878ed259 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        Model_AttributeSelectionList.h
 // Created:     22 Oct 2014
 // Author:      Mikhail PONIKAROV
@@ -9,8 +11,9 @@
 #include "Model_AttributeSelection.h"
 #include <ModelAPI_AttributeSelectionList.h>
 #include <TDataStd_Integer.hxx>
-#include <TDataStd_Real.hxx>
+#include <TDataStd_Comment.hxx>
 #include <vector>
+#include <map>
 
 /**\class Model_AttributeSelectionList
  * \ingroup DataModel
 
 class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
 {
+  TDF_Label myLab; ///< the main label of this attribute
   Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
-  Handle(TDataStd_Real) mySelectionType;  ///< Contains current index, TODO: make it integer, not real
-  std::vector<boost::shared_ptr<Model_AttributeSelection> > mySubs; /// the selection attributes
+  /// Contains current type name (same as selection attribute)
+  Handle(TDataStd_Comment) mySelectionType;
+  std::shared_ptr<Model_AttributeSelection> myTmpAttr; ///< temporary attribute (the last one)
+  /// the cashed shapes to optimize isInList method: from context to set of shapes in this context
+  std::map<ResultPtr, std::list<std::shared_ptr<GeomAPI_Shape> > > myCash;
+  bool myIsCashed; ///< true if cashing is performed
 public:
   /// Adds the new reference to the end of the list
+  /// \param theContext object where the sub-shape was selected
+  /// \param theSubShape selected sub-shape (if null, the whole context is selected)
+  /// \param theTemporarily if it is true, do not store and name the added in the data framework
+  ///           (used to remove immideately, without the following updates)
   MODEL_EXPORT virtual void append(
-    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+    const bool theTemporarily = false);
+
+  /// Adds the new reference to the end of the list by the naming name of the selected shape
+  /// The type of shape is taken from the current selection type if the given is empty
+  MODEL_EXPORT virtual void append(const std::string theNamingName, const std::string& theType="");
+
+  /// Reset temporary stored values
+  virtual void removeTemporaryValues();
+
+  /// Removes the last element in the list
+  MODEL_EXPORT virtual void removeLast();
+
+  /// Removes the elements from the list.
+  /// \param theIndices a list of indices of elements to be removed
+  MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
 
   /// Returns the number ofselection attributes in the list
   MODEL_EXPORT virtual int size();
 
-  MODEL_EXPORT virtual int selectionType();
+  /// Returns true if the object with the shape are in list
+  /// \param theContext object where the sub-shape was selected
+  /// \param theSubShape selected sub-shape (if null, the whole context is selected)
+  /// \param theTemporarily if it is true, it checks also the temporary added item
+  /// \returns true if the pair is found in the attirbute
+  MODEL_EXPORT virtual bool isInList(
+    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+    const bool theTemporarily = false);
+
+  /// The type of all elements selection
+  /// \returns the index of the OCCT enumeration of the type of shape
+  MODEL_EXPORT virtual const std::string selectionType() const;
 
-  MODEL_EXPORT virtual void setSelectionType(int);
+  /// Sets the type of all elements selection
+  /// \param theType the index of the OCCT enumeration of the type of shape
+  MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
 
   /// Returns the attribute selection by the index (zero based)
-  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
 
   /// Returns all attributes
   MODEL_EXPORT virtual void clear();
 
-  /// Sets the feature object
-  MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+  /// Returns true if attribute was  initialized by some value
+  MODEL_EXPORT virtual bool isInitialized();
+
+  /// Starts or stops cashing of the values in the attribute (the cash may become invalid
+  /// on modification of the attribute or sub-elements, so the cash must be enabled only
+  /// during non-modification operations with this attribute)
+  MODEL_EXPORT virtual void cashValues(const bool theEnabled);
 
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
-  /// Updates the mySubs if needed since it is not persistent value
-  void updateSubs();
+  /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+  virtual void reinit();
 
   friend class Model_Data;
 };