0030124: Visualization, AIS_InteractiveObject - clean up confusing Presentation inval...
[occt.git] / src / PrsMgr / PrsMgr_PresentableObject.cxx
index d5c86f9..fffce5c 100644 (file)
@@ -115,80 +115,101 @@ void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /* aProjec
 }
 
 //=======================================================================
-//function : Update
-//purpose  : 
+//function : ToBeUpdated
+//purpose  :
 //=======================================================================
-void PrsMgr_PresentableObject::Update (const Standard_Boolean AllModes) {
-  Standard_Integer l = myPresentations.Length();
-  Handle(PrsMgr_PresentationManager) PM; 
-  for (Standard_Integer i=1; i <= l; i++) {
-    PM = myPresentations(i).Presentation()->PresentationManager();
-    if(AllModes) 
-      PM->Update(this,myPresentations(i).Mode());
-    else{
-      if(PM->IsDisplayed(this,myPresentations(i).Mode()) ||
-        PM->IsHighlighted(this,myPresentations(i).Mode())){
-       PM->Update(this,myPresentations(i).Mode());
+Standard_Boolean PrsMgr_PresentableObject::ToBeUpdated (Standard_Boolean theToIncludeHidden) const
+{
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
+  {
+    const PrsMgr_ModedPresentation& aModedPrs = aPrsIter.Value();
+    if (aModedPrs.Presentation()->MustBeUpdated())
+    {
+      if (theToIncludeHidden)
+      {
+        return Standard_True;
+      }
+
+      Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs.Presentation()->PresentationManager();
+      if (aPrsMgr->IsDisplayed  (this, aModedPrs.Mode())
+       || aPrsMgr->IsHighlighted(this, aModedPrs.Mode()))
+      {
+        return Standard_True;
       }
-      else
-       SetToUpdate(myPresentations(i).Mode());
     }
   }
+  return Standard_False;
 }
 
 //=======================================================================
-//function : Update
-//purpose  : 
+//function : UpdatePresentations
+//purpose  :
 //=======================================================================
-void PrsMgr_PresentableObject::Update (const Standard_Integer aMode, const Standard_Boolean ClearOther) {
-  Standard_Integer l = myPresentations.Length();
-  for (Standard_Integer i=1; i <= l; i++) {
-    if( myPresentations(i).Mode() == aMode){
-       Handle(PrsMgr_PresentationManager) PM=
-        myPresentations(i).Presentation()->PresentationManager();
-       
-       if(PM->IsDisplayed(this,aMode) ||
-         PM->IsHighlighted(this,aMode)){
-        PM->Update(this,aMode);
-        myPresentations(i).Presentation()->SetUpdateStatus(Standard_False);
-        
-       }
-       else
-        SetToUpdate(myPresentations(i).Mode());
-     }
-    
-  }
-  if(ClearOther) {
-    PrsMgr_Presentations save;
-    save =  myPresentations; 
-    myPresentations.Clear();
-    for (Standard_Integer i=1; i <= l; i++) {
-      if( save(i).Mode() == aMode) myPresentations.Append(save(i));
+Standard_Boolean PrsMgr_PresentableObject::UpdatePresentations (Standard_Boolean theToIncludeHidden)
+{
+  Standard_Boolean hasUpdates = Standard_False;
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
+  {
+    const PrsMgr_ModedPresentation& aModedPrs = aPrsIter.Value();
+    if (aModedPrs.Presentation()->MustBeUpdated())
+    {
+      Handle(PrsMgr_PresentationManager) aPrsMgr = aModedPrs.Presentation()->PresentationManager();
+      if (theToIncludeHidden
+       || aPrsMgr->IsDisplayed  (this, aModedPrs.Mode())
+       || aPrsMgr->IsHighlighted(this, aModedPrs.Mode()))
+      {
+        hasUpdates = Standard_True;
+        aPrsMgr->Update (this, aModedPrs.Mode());
+      }
     }
   }
-
+  return hasUpdates;
 }
 
 //=======================================================================
-//function : SetToUpdate
-//purpose  : 
+//function : Update
+//purpose  :
 //=======================================================================
-void PrsMgr_PresentableObject::SetToUpdate(const Standard_Integer aMode)
+void PrsMgr_PresentableObject::Update (Standard_Integer theMode, Standard_Boolean theToClearOther)
 {
-  for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
-    if(myPresentations(IP).Mode()==aMode)
-      myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True);
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More();)
+  {
+    if (aPrsIter.Value().Mode() == theMode)
+    {
+      Handle(PrsMgr_PresentationManager) aPrsMgr = aPrsIter.Value().Presentation()->PresentationManager();
+      if (aPrsMgr->IsDisplayed  (this, theMode)
+       || aPrsMgr->IsHighlighted(this, theMode))
+      {
+        aPrsMgr->Update (this, theMode);
+        aPrsIter.Value().Presentation()->SetUpdateStatus (Standard_False);
+      }
+      else
+      {
+        SetToUpdate (aPrsIter.Value().Mode());
+      }
+    }
+    else if (theToClearOther)
+    {
+      myPresentations.Remove (aPrsIter);
+      continue;
+    }
+    aPrsIter.Next();
   }
 }
 
 //=======================================================================
 //function : SetToUpdate
-//purpose  :
+//purpose  : 
 //=======================================================================
-void PrsMgr_PresentableObject::SetToUpdate()
+void PrsMgr_PresentableObject::SetToUpdate (Standard_Integer theMode)
 {
-  for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
-    myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True);
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
+  {
+    if (theMode == -1
+     || aPrsIter.Value().Mode() == theMode)
+    {
+      aPrsIter.ChangeValue().Presentation()->SetUpdateStatus(Standard_True);
+    }
   }
 }
 
@@ -196,19 +217,18 @@ void PrsMgr_PresentableObject::SetToUpdate()
 //function : ToBeUpdated
 //purpose  : gets the list of modes to be updated
 //=======================================================================
-void PrsMgr_PresentableObject::ToBeUpdated(TColStd_ListOfInteger& OutList) const
+void PrsMgr_PresentableObject::ToBeUpdated (TColStd_ListOfInteger& theOutList) const
 {
-  OutList.Clear();
-  // on dimensionne les buckets a la taille de la seq.
+  theOutList.Clear();
   TColStd_MapOfInteger MI(myPresentations.Length()); 
-  
-  for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
-    const PrsMgr_ModedPresentation& MP = myPresentations(IP);
-    if(MP.Presentation()->MustBeUpdated())
-      if(!MI.Contains(MP.Mode())){
-        OutList.Append(MP.Mode());
-        MI.Add(MP.Mode());
-      }
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
+  {
+    const PrsMgr_ModedPresentation& aModedPrs = aPrsIter.Value();
+    if (aModedPrs.Presentation()->MustBeUpdated()
+     && MI.Add (aModedPrs.Mode()))
+    {
+      theOutList.Append (aModedPrs.Mode());
+    }
   }
 }
 
@@ -219,9 +239,9 @@ void PrsMgr_PresentableObject::ToBeUpdated(TColStd_ListOfInteger& OutList) const
 void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d theType)
 {
   myTypeOfPresentation3d = theType;
-  for(Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    const Handle(PrsMgr_Presentation)& aPrs  = myPresentations (aPrsIter).Presentation();
+    const Handle(PrsMgr_Presentation)& aPrs  = aPrsIter.Value().Presentation();
     aPrs->Presentation()->SetVisual (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant
                                    ? Graphic3d_TOS_COMPUTED
                                    : Graphic3d_TOS_ALL);
@@ -285,9 +305,9 @@ void PrsMgr_PresentableObject::UpdateTransformation()
     myInvTransformation = myLocalTransformation->Trsf().Inverted();
   }
 
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    myPresentations (aPrsIter).Presentation()->SetTransformation (myTransformation);
+    aPrsIter.ChangeValue().Presentation()->SetTransformation (myTransformation);
   }
 
   for (PrsMgr_ListOfPresentableObjectsIter aChildIter (myChildren); aChildIter.More(); aChildIter.Next())
@@ -302,9 +322,9 @@ void PrsMgr_PresentableObject::UpdateTransformation()
 //=======================================================================
 void PrsMgr_PresentableObject::recomputeComputed() const
 {
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
+    const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value().Presentation();
     if (!aPrs3d.IsNull()
      && !aPrs3d->Presentation().IsNull())
     {
@@ -320,9 +340,9 @@ void PrsMgr_PresentableObject::recomputeComputed() const
 void PrsMgr_PresentableObject::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
 {
   myTransformPersistence = theTrsfPers;
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
+    const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.Value().Presentation();
     if (!aPrs3d.IsNull()
      && !aPrs3d->Presentation().IsNull())
     {
@@ -422,9 +442,9 @@ void PrsMgr_PresentableObject::SetZLayer (const Graphic3d_ZLayerId theLayerId)
   }
 
   myDrawer->SetZLayer (theLayerId);
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    const PrsMgr_ModedPresentation& aModedPrs = myPresentations (aPrsIter);
+    const PrsMgr_ModedPresentation& aModedPrs = aPrsIter.Value();
     if (aModedPrs.Presentation().IsNull()
      || aModedPrs.Presentation()->Presentation().IsNull())
     {
@@ -501,19 +521,14 @@ void PrsMgr_PresentableObject::SetClipPlanes (const Handle(Graphic3d_SequenceOfH
 // =======================================================================
 void PrsMgr_PresentableObject::UpdateClipping()
 {
-  // affect generated structures
-  for (Standard_Integer aPrsIt = 1; aPrsIt <= myPresentations.Length(); ++aPrsIt)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    // pass over presentation manager 3d mechanism right to the structures -
-    // we do not interested in display mode collections.
-    const PrsMgr_ModedPresentation& aModedPrs = myPresentations (aPrsIt);
-    if (aModedPrs.Presentation().IsNull()
-     || aModedPrs.Presentation()->Presentation().IsNull())
+    const PrsMgr_ModedPresentation& aModedPrs = aPrsIter.Value();
+    if (!aModedPrs.Presentation().IsNull()
+     && !aModedPrs.Presentation()->Presentation().IsNull())
     {
-      continue;
+      aModedPrs.Presentation()->Presentation()->SetClipPlanes (myClipPlanes);
     }
-
-    aModedPrs.Presentation()->Presentation()->SetClipPlanes (myClipPlanes);
   }
 }
 
@@ -529,16 +544,14 @@ void PrsMgr_PresentableObject::SetMutable (const Standard_Boolean theIsMutable)
   }
 
   myIsMutable = theIsMutable;
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
   {
-    const PrsMgr_ModedPresentation& aModedPrs = myPresentations (aPrsIter);
-    if (aModedPrs.Presentation().IsNull()
-     || aModedPrs.Presentation()->Presentation().IsNull())
+    const PrsMgr_ModedPresentation& aModedPrs = aPrsIter.Value();
+    if (!aModedPrs.Presentation().IsNull()
+     && !aModedPrs.Presentation()->Presentation().IsNull())
     {
-      continue;
+      aModedPrs.Presentation()->Presentation()->SetMutable (theIsMutable);
     }
-
-    aModedPrs.Presentation()->Presentation()->SetMutable (theIsMutable);
   }
 }