0029353: Optimization of TPrsStd_AISPresentation::SetSelectionMode()
authorvro <vro@opencascade.com>
Wed, 29 Nov 2017 13:36:21 +0000 (16:36 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 1 Dec 2017 09:04:42 +0000 (12:04 +0300)
src/TPrsStd/TPrsStd_AISPresentation.cxx
src/TPrsStd/TPrsStd_AISPresentation.hxx

index f108b71..cc8d75f 100644 (file)
@@ -595,7 +595,11 @@ void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelecti
 {
   Backup();
   getData()->SetSelectionMode (theSelectionMode);
-  AISUpdate();
+  
+  if ( myAIS.IsNull() )
+    AISUpdate();
+  else
+    ActivateSelectionMode();
 }
 
 //=======================================================================
@@ -871,36 +875,7 @@ void TPrsStd_AISPresentation::AISUpdate()
         myAIS->SetDisplayMode(aMode);
     }
 
-    if ( !aContext.IsNull() && IsDisplayed() )
-      aContext->Redisplay(myAIS, Standard_False);
-
-    if (HasOwnSelectionMode()) {
-      if (!aContext.IsNull())
-      {
-        TColStd_ListOfInteger anActivatedModes;
-        aContext->ActivatedModes (myAIS, anActivatedModes);
-        Standard_Boolean isActivated = Standard_False;
-        Standard_Integer aSelectionMode = SelectionMode();
-        if (aSelectionMode == -1)
-        {
-          aContext->Deactivate(myAIS);
-        }
-        else
-        {
-          for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
-          {
-            if (aModeIter.Value() == aSelectionMode)
-            {
-              isActivated = Standard_True;
-              break;
-            }
-          }
-          if (!isActivated)
-            aContext->Activate (myAIS, aSelectionMode, Standard_False);
-        }
-      } 
-    }
-
+    ActivateSelectionMode();
   }
   
   if (IsDisplayed() && !aContext.IsNull())
@@ -1013,3 +988,40 @@ Handle(AIS_InteractiveContext) TPrsStd_AISPresentation::getAISContext() const
 
   return Handle_AIS_InteractiveContext();
 }
+
+//=======================================================================
+//function : ActivateSelectionMode
+//purpose  : Activates selection mode of the interactive object.
+//           It is called internally on change of selection mode and AISUpdate().
+//=======================================================================
+void TPrsStd_AISPresentation::ActivateSelectionMode()
+{
+  if (!myAIS.IsNull() && HasOwnSelectionMode())
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+    if (!aContext.IsNull())
+    {
+      TColStd_ListOfInteger anActivatedModes;
+      aContext->ActivatedModes (myAIS, anActivatedModes);
+      Standard_Boolean isActivated = Standard_False;
+      Standard_Integer aSelectionMode = SelectionMode();
+      if (aSelectionMode == -1)
+      {
+        aContext->Deactivate(myAIS);
+      }
+      else
+      {
+        for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
+        {
+          if (aModeIter.Value() == aSelectionMode)
+          {
+            isActivated = Standard_True;
+            break;
+          }
+        }
+        if (!isActivated)
+          aContext->Activate (myAIS, aSelectionMode, Standard_False);
+      }
+    } 
+  }
+}
index 672ff5f..e72b759 100644 (file)
@@ -197,6 +197,10 @@ protected:
 private:
 
   Handle(AIS_InteractiveContext) getAISContext() const;
+
+  //! Activates selection mode of the interactive object.
+  //! It is called internally on change of selection mode and AISUpdate().
+  void ActivateSelectionMode();
   
   //! Updates AIS_InteractiveObject stored in the attribute
   //! and applies the visualization settings