Salome HOME
Performance optimization: allow to put temporary objects into selection attributes...
authormpv <mpv@opencascade.com>
Wed, 19 Aug 2015 10:56:45 +0000 (13:56 +0300)
committermpv <mpv@opencascade.com>
Wed, 19 Aug 2015 10:56:45 +0000 (13:56 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelectionList.h

index f3f4d27a3c46d34ea92dfa5c3577716004bee615..767e86331386183fe001085890b1f41722e11874 100644 (file)
@@ -76,8 +76,18 @@ Standard_GUID kPART_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb27");
 // TDataStd_Integer - type of the selected shape (for construction)
 // TDF_Reference - from ReferenceAttribute, the context
 void Model_AttributeSelection::setValue(const ResultPtr& theContext,
-  const std::shared_ptr<GeomAPI_Shape>& theSubShape)
+  const std::shared_ptr<GeomAPI_Shape>& theSubShape, const bool theTemporarily)
 {
+  if (theTemporarily) { // just keep the stored without DF update
+    myTmpContext = theContext;
+    myTmpSubShape = theSubShape;
+    owner()->data()->sendAttributeUpdated(this);
+    return;
+  } else {
+    myTmpContext.reset();
+    myTmpSubShape.reset();
+  }
+
   const std::shared_ptr<GeomAPI_Shape>& anOldShape = value();
   bool isOldContext = theContext == myRef.value();
   bool isOldShape = isOldContext &&
@@ -142,6 +152,10 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
 
 std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
 {
+  if (myTmpContext.get() || myTmpSubShape.get()) {
+    return myTmpSubShape;
+  }
+
   std::shared_ptr<GeomAPI_Shape> aResult;
   if (myRef.isInitialized()) {
     TDF_Label aSelLab = selectionLabel();
@@ -229,6 +243,10 @@ void Model_AttributeSelection::setID(const std::string theID)
 }
 
 ResultPtr Model_AttributeSelection::context() {
+  if (myTmpContext.get() || myTmpSubShape.get()) {
+    return myTmpContext;
+  }
+
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
   // for parts there could be same-data result, so take the last enabled
   if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group()) {
index 91e77e6e81f544da6c8372c21538aaa82e614c05..1340a34d00e1fe1d226c47bf17afc58c2436e4d8 100644 (file)
@@ -21,10 +21,19 @@ class Model_AttributeSelection : public ModelAPI_AttributeSelection
 {
   Model_AttributeReference myRef;  ///< The reference functionality reusage
   TDF_LabelMap myScope; ///< the map of valid labels for naming selection solving
+  /// temporarily storages to avoid keeping in the data structure if not needed
+  ResultPtr myTmpContext;
+  /// temporarily storages to avoid keeping in the data structure if not needed
+  std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
 public:
   /// Defines the result and its selected sub-shape
+  /// \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 setValue(
-    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
+    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+    const bool theTemporarily = false);
 
   /// Returns the selected subshape
   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
index 8191553d15d588e3f0c1262a0aab7e07863e1b3b..1d4725c2279bf61389136e007d5ed532a5636fd0 100644 (file)
@@ -21,7 +21,8 @@
 using namespace std;
 
 void Model_AttributeSelectionList::append(
-    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
+    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+    const bool theTemporarily)
 {
   // do not use the degenerated edge as a shape, a list is not incremented in this case
   if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
@@ -41,7 +42,7 @@ void Model_AttributeSelectionList::append(
   }
   aNewAttr->setID(id());
   mySize->Set(aNewTag);
-  aNewAttr->setValue(theContext, theSubShape);
+  aNewAttr->setValue(theContext, theSubShape, theTemporarily);
   owner()->data()->sendAttributeUpdated(this);
 }
 
index e0eba6b710f751af189c82a39235dc66b6aff742..676737116e8ea1292e9eac44bd8caf466a542f10 100644 (file)
@@ -26,8 +26,13 @@ class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
   Handle(TDataStd_Comment) mySelectionType;  ///< Contains current type name (same as selection attribute)
 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 std::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
index 71c850e59830047483ded064f64885f76fd9bcd9..eccafa5f69dcc3dd7cd55fdbfb94216fb630ac31 100644 (file)
@@ -19,8 +19,13 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
 {
  public:
   /// Defines the result and its selected sub-shape
+  /// \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)
   virtual void setValue(
-    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+    const bool theTemporarily = false) = 0;
 
   /// Returns the selected subshape
   virtual std::shared_ptr<GeomAPI_Shape> value() = 0;
index 68c7eed8ec445cdfbb5243340eeabf11f0eb2a83..b12aa518d54daaf898b7b79168e76be2016304b2 100644 (file)
@@ -20,8 +20,13 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
 {
  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)
   virtual void append(const ResultPtr& theContext,
-                      const GeomShapePtr& theSubShape) = 0;
+                      const GeomShapePtr& theSubShape,
+                      const bool theTemporarily = false) = 0;
 
   /// 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