0023710: Simplification of presentation managment classes
[occt.git] / src / PrsMgr / PrsMgr_PresentableObject.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 65e4af8..a392bc5
@@ -1,15 +1,21 @@
-// File:       PrsMgr_PresentableObject.cxx
-// Created:    Tue Dec 16 10:36:49 1997
-// Author:     Jean Louis Frenkel
-// Modified by Rob
-// 16-dec-1997  : Update Flag for Presentations. 
-//             <rob@robox.paris1.matra-dtv.fr>
-
+// Created on: 1997-12-16
+// Created by: Jean Louis Frenkel
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <PrsMgr_PresentableObject.ixx>
 #include <PrsMgr_Presentation.hxx>
-#include <PrsMgr_Presentation2d.hxx>
-#include <PrsMgr_Presentation3d.hxx>
 #include <PrsMgr_ModedPresentation.hxx>
 #include <PrsMgr_PresentationManager.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
@@ -21,7 +27,6 @@
 //function : PrsMgr_PresentableObject
 //purpose  : 
 //=======================================================================
-
 PrsMgr_PresentableObject::PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
      :myPresentations(),myTypeOfPresentation3d(aTypeOfPresentation3d)
 {
@@ -31,47 +36,32 @@ PrsMgr_PresentableObject::PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentati
   myTransformPersistence.Point.z = 0.0;
 }
 
-
 //=======================================================================
 //function : Fill
 //purpose  : 
 //=======================================================================
-void PrsMgr_PresentableObject::Fill(const Handle(PrsMgr_PresentationManager)& aPresentationManager,
-                                   const Handle(PrsMgr_Presentation)& aPresentation,
-                                   const Standard_Integer aMode) {
-  if (aPresentation->DynamicType() == STANDARD_TYPE(PrsMgr_Presentation2d)) {
-    Compute(((Handle(PrsMgr_PresentationManager2d)&)aPresentationManager),((Handle(PrsMgr_Presentation2d)&)aPresentation)->Presentation(),aMode);
-  }
-  else if (aPresentation->DynamicType() == STANDARD_TYPE(PrsMgr_Presentation3d)) {
-    Compute(((Handle(PrsMgr_PresentationManager3d)&)aPresentationManager),((Handle(PrsMgr_Presentation3d)&)aPresentation)->Presentation(),aMode);
-    UpdateLocation(((Handle(PrsMgr_Presentation3d)&)aPresentation)->Presentation());
-    Handle(Graphic3d_Structure) aStruct = Handle(Graphic3d_Structure)::DownCast( ((Handle(PrsMgr_Presentation3d)&)aPresentation)->Presentation() );
-    if ( !aStruct.IsNull() ) {
-      aStruct->SetTransformPersistence( GetTransformPersistenceMode(), GetTransformPersistencePoint() );
-    }
-  }
-}
-
-//=======================================================================
-//function : Compute
-//purpose  : 
-//=======================================================================
-void PrsMgr_PresentableObject::Compute(const Handle(PrsMgr_PresentationManager2d)& /*aPresentationManager*/,
-                                      const Handle(Graphic2d_GraphicObject)& /*aPresentation*/,
-                                       const Standard_Integer /*aMode*/) 
+void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
+                                     const Handle(PrsMgr_Presentation)&        thePrs,
+                                     const Standard_Integer                    theMode)
 {
-  Standard_NotImplemented::Raise("cannot compute in a 2d visualizer");
+  Handle(Prs3d_Presentation) aStruct3d = thePrs->Presentation();
+  Compute (thePrsMgr, aStruct3d, theMode);
+  UpdateLocation (aStruct3d);
+  aStruct3d->SetClipPlanes (myClipPlanes);
+  aStruct3d->SetTransformPersistence (GetTransformPersistenceMode(), GetTransformPersistencePoint());
 }
+
 //=======================================================================
 //function : Compute
-//purpose  : 
+//purpose  :
 //=======================================================================
-void PrsMgr_PresentableObject::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
-                                      const Handle(Prs3d_Presentation)& /*aPresentation*/,
-                                       const Standard_Integer /*aMode*/) 
+void PrsMgr_PresentableObject::Compute (const Handle(PrsMgr_PresentationManager)& /*aPresentationManager*/,
+                                        const Handle(Prs3d_Presentation)& /*aPresentation*/,
+                                        const Standard_Integer /*aMode*/)
 {
   Standard_NotImplemented::Raise("cannot compute in a 3d visualizer");
 }
+
 //=======================================================================
 //function : Compute
 //purpose  : 
@@ -81,6 +71,7 @@ void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /*aProject
 {
   Standard_NotImplemented::Raise("cannot compute under a specific projector");
 }
+
 //=======================================================================
 //function : Compute
 //purpose  : 
@@ -113,11 +104,11 @@ void PrsMgr_PresentableObject::Update (const Standard_Boolean AllModes) {
     }
   }
 }
+
 //=======================================================================
 //function : Update
 //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++) {
@@ -146,11 +137,11 @@ void PrsMgr_PresentableObject::Update (const Standard_Integer aMode, const Stand
   }
 
 }
+
 //=======================================================================
 //function : Presentations
 //purpose  : 
 //=======================================================================
-
 PrsMgr_Presentations& PrsMgr_PresentableObject::Presentations() {
   return myPresentations;
 }
@@ -159,18 +150,15 @@ PrsMgr_Presentations& PrsMgr_PresentableObject::Presentations() {
 //function : HasLocation
 //purpose  : 
 //=======================================================================
-
 Standard_Boolean PrsMgr_PresentableObject::HasLocation() const 
 {
-  return !Location().IsIdentity();}
-
-
+  return !Location().IsIdentity();
+}
 
 //=======================================================================
 //function : SetToUpdate
 //purpose  : 
 //=======================================================================
-
 void PrsMgr_PresentableObject::SetToUpdate(const Standard_Integer aMode)
 {
   for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
@@ -178,6 +166,11 @@ void PrsMgr_PresentableObject::SetToUpdate(const Standard_Integer aMode)
       myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True);
   }
 }
+
+//=======================================================================
+//function : SetToUpdate
+//purpose  :
+//=======================================================================
 void PrsMgr_PresentableObject::SetToUpdate()
 {
   for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
@@ -208,21 +201,17 @@ void PrsMgr_PresentableObject::ToBeUpdated(TColStd_ListOfInteger& OutList) const
 
 //=======================================================================
 //function : SetTypeOfPresentation
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-void PrsMgr_PresentableObject::SetTypeOfPresentation(const PrsMgr_TypeOfPresentation3d aType)
+void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d theType)
 {
-  myTypeOfPresentation3d = aType;
-  
-  for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
-    const Handle(PrsMgr_Presentation)& P = myPresentations(IP).Presentation();
-    if(P->KindOfPresentation()==PrsMgr_KOP_3D){
-      Graphic3d_TypeOfStructure Typ = 
-       (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant)?
-         Graphic3d_TOS_COMPUTED : Graphic3d_TOS_ALL;
-      (*(Handle(PrsMgr_Presentation3d)*)&P)->Presentation()->SetVisual(Typ);
-    }
+  myTypeOfPresentation3d = theType;
+  for(Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  {
+    const Handle(PrsMgr_Presentation)& aPrs  = myPresentations (aPrsIter).Presentation();
+    aPrs->Presentation()->SetVisual (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant
+                                   ? Graphic3d_TOS_COMPUTED
+                                   : Graphic3d_TOS_ALL);
   }
 }
 
@@ -244,36 +233,41 @@ void PrsMgr_PresentableObject::SetLocation(const TopLoc_Location& aLoc)
 void PrsMgr_PresentableObject::ResetLocation() 
 {
   TopLoc_Location aLoc;
-  Handle(Geom_Transformation) G = new Geom_Transformation(aLoc.Transformation());
-
-  for(Standard_Integer i=1;i<=myPresentations.Length();i++){
-    const Handle(PrsMgr_Presentation)& P = myPresentations(i).Presentation();
-    if(P->KindOfPresentation()==PrsMgr_KOP_3D){
-      (*((Handle(PrsMgr_Presentation3d)*)&P))->Transform(G);
-    }
+  Handle(Geom_Transformation) aTrsf = new Geom_Transformation (aLoc.Transformation());
+  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  {
+    myPresentations (aPrsIter).Presentation()->Transform (aTrsf);
   }
   myLocation = aLoc;
 }
 
+//=======================================================================
+//function : UpdateLocation
+//purpose  :
+//=======================================================================
 void PrsMgr_PresentableObject::UpdateLocation()
 {
-  if(!HasLocation()) return;
-  Handle(Geom_Transformation) G = new Geom_Transformation(Location().Transformation());
-  if(G->Trsf().Form()==gp_Identity) return;
-  for (Standard_Integer i=1;i<=myPresentations.Length();i++){
-    const Handle(PrsMgr_Presentation)& P = myPresentations(i).Presentation();
-    if(P->KindOfPresentation()==PrsMgr_KOP_3D){
-      (*((Handle(PrsMgr_Presentation3d)*)&P))->Transform(G);
-    }
+  if (!HasLocation())
+  {
+    return;
+  }
+
+  Handle(Geom_Transformation) aTrsf = new Geom_Transformation (Location().Transformation());
+  if (aTrsf->Trsf().Form() == gp_Identity)
+  {
+    return;
   }
-}
 
+  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  {
+    myPresentations (aPrsIter).Presentation()->Transform (aTrsf);
+  }
+}
 
 //=======================================================================
 //function : UpdateLocation
 //purpose  : 
 //=======================================================================
-
 void PrsMgr_PresentableObject::UpdateLocation(const Handle(Prs3d_Presentation)& P)
 {
   if(myLocation.IsIdentity()) return;
@@ -284,28 +278,24 @@ void PrsMgr_PresentableObject::UpdateLocation(const Handle(Prs3d_Presentation)&
 
 //=======================================================================
 //function : SetTransformPersistence
-//purpose  : 
+//purpose  :
 //=======================================================================
-void  PrsMgr_PresentableObject::SetTransformPersistence( const Graphic3d_TransModeFlags& TheFlag,
-                                                        const gp_Pnt& ThePoint )
+void PrsMgr_PresentableObject::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
+                                                        const gp_Pnt&                   thePoint)
 {
-  myTransformPersistence.Flag = TheFlag;
-  myTransformPersistence.Point.x = ThePoint.X();
-  myTransformPersistence.Point.y = ThePoint.Y();
-  myTransformPersistence.Point.z = ThePoint.Z();
-
-  Handle(Graphic3d_Structure) aStruct;
-  for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) 
+  myTransformPersistence.Flag    = theFlag;
+  myTransformPersistence.Point.x = (Standard_ShortReal )thePoint.X();
+  myTransformPersistence.Point.y = (Standard_ShortReal )thePoint.Y();
+  myTransformPersistence.Point.z = (Standard_ShortReal )thePoint.Z();
+  for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
+  {
+    const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
+    if (!aPrs3d.IsNull()
+     && !aPrs3d->Presentation().IsNull())
     {
-      Handle(PrsMgr_Presentation3d) aPrs3d =
-       Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() );
-      if ( !aPrs3d.IsNull() ) 
-       {
-         aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() );
-         if( !aStruct.IsNull() )
-           aStruct->SetTransformPersistence( TheFlag, ThePoint );
-       }
+      aPrs3d->Presentation()->SetTransformPersistence (theFlag, thePoint);
     }
+  }
 }
 
 //=======================================================================
@@ -335,3 +325,92 @@ gp_Pnt  PrsMgr_PresentableObject::GetTransformPersistencePoint() const
 {
   return gp_Pnt( myTransformPersistence.Point.x, myTransformPersistence.Point.y, myTransformPersistence.Point.z );
 }
+
+//=======================================================================
+//function : SetZLayer
+//purpose  :
+//=======================================================================
+void PrsMgr_PresentableObject::SetZLayer 
+  (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
+   const Standard_Integer theLayerId)
+{
+  if (!thePrsMgr.IsNull())
+    thePrsMgr->SetZLayer (this, theLayerId);
+}
+
+//=======================================================================
+//function : GetZLayer
+//purpose  :
+//=======================================================================
+Standard_Integer PrsMgr_PresentableObject::GetZLayer 
+  (const Handle(PrsMgr_PresentationManager)& thePrsMgr) const
+{
+  if (!thePrsMgr.IsNull())
+    return thePrsMgr->GetZLayer (this);
+
+  return -1;
+}
+
+// =======================================================================
+// function : AddClipPlane
+// purpose  :
+// =======================================================================
+void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
+{
+  // add to collection and process changes
+  myClipPlanes.Append (thePlane);
+  UpdateClipping();
+}
+
+// =======================================================================
+// function : RemoveClipPlane
+// purpose  :
+// =======================================================================
+void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
+{
+  // remove from collection and process changes
+  Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (myClipPlanes);
+  for (; aPlaneIt.More(); aPlaneIt.Next())
+  {
+    const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
+    if (aPlane != thePlane)
+      continue;
+
+    myClipPlanes.Remove (aPlaneIt);
+    UpdateClipping();
+    return;
+  }
+}
+
+// =======================================================================
+// function : SetClipPlanes
+// purpose  :
+// =======================================================================
+void PrsMgr_PresentableObject::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
+{
+  // change collection and process changes
+  myClipPlanes = thePlanes;
+  UpdateClipping();
+}
+
+// =======================================================================
+// function : UpdateClipping
+// purpose  :
+// =======================================================================
+void PrsMgr_PresentableObject::UpdateClipping()
+{
+  // affect generated structures
+  for (Standard_Integer aPrsIt = 1; aPrsIt <= myPresentations.Length(); ++aPrsIt)
+  {
+    // 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())
+    {
+      continue;
+    }
+
+    aModedPrs.Presentation()->Presentation()->SetClipPlanes (myClipPlanes);
+  }
+}