0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_ConnectedInteractive.cxx
index d2d5010..cf83941 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-
 #include <AIS_ConnectedInteractive.hxx>
+
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_InteractiveObject.hxx>
 #include <AIS_Shape.hxx>
 #include <BRepTools.hxx>
-#include <Geom_Transformation.hxx>
-#include <gp_Trsf.hxx>
 #include <NCollection_DataMap.hxx>
 #include <Precision.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_Presentation.hxx>
-#include <Prs3d_Projector.hxx>
-#include <PrsMgr_ModedPresentation.hxx>
-#include <PrsMgr_Presentation.hxx>
 #include <Select3D_SensitiveEntity.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Selection.hxx>
@@ -53,16 +47,21 @@ IMPLEMENT_STANDARD_RTTIEXT(AIS_ConnectedInteractive,AIS_InteractiveObject)
 AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
 AIS_InteractiveObject(aTypeOfPresentation3d)
 {
-  SetHilightMode(0);
+  //
 }
 
 //=======================================================================
-//function : Connect
-//purpose  : 
+//function : connect
+//purpose  :
 //=======================================================================
-void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj)
+void AIS_ConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
+                                        const Handle(TopLoc_Datum3D)& theLocation)
 {
-  if (myReference == theAnotherObj) return;
+  if (myReference == theAnotherObj)
+  {
+    setLocalTransformation (theLocation);
+    return;
+  }
 
   Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (theAnotherObj);
   if (!aConnected.IsNull())
@@ -75,28 +74,22 @@ void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& the
   }
   else
   {
-    Standard_ProgramError::Raise ("AIS_ConnectedInteractive::Connect() - object without own presentation can not be connected");
+    throw Standard_ProgramError("AIS_ConnectedInteractive::Connect() - object without own presentation can not be connected");
   }
 
   if (!myReference.IsNull())
   {
+    if (myReference->HasInteractiveContext()
+     && myReference->GetContext()->DisplayStatus (myReference) != AIS_DS_None)
+    {
+      myReference.Nullify();
+      throw Standard_ProgramError("AIS_ConnectedInteractive::Connect() - connected object should NOT be displayed in context");
+    }
     myTypeOfPresentation3d = myReference->TypeOfPresentation3d();
   }
+  setLocalTransformation (theLocation);
 }
 
-//=======================================================================
-//function : Connect
-//purpose  : 
-//=======================================================================
-void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, 
-                                        const gp_Trsf&                       theLocation)
-{
-  Connect (theAnotherObj);
-
-  SetLocalTransformation (theLocation);
-}
-
-
 //=======================================================================
 //function : Disconnect
 //purpose  :
@@ -104,12 +97,12 @@ void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& the
 
 void AIS_ConnectedInteractive::Disconnect()
 {
-  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();
     if (!aPrs.IsNull())
     {
-      aPrs->Presentation()->DisconnectAll (Graphic3d_TOC_DESCENDANT);
+      aPrs->DisconnectAll (Graphic3d_TOC_DESCENDANT);
     }
   }
 }
@@ -124,7 +117,7 @@ void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3
   if (HasConnection())
   {
     thePrs->Clear (Standard_False);
-    thePrs->RemoveAll();
+    thePrs->DisconnectAll (Graphic3d_TOC_DESCENDANT);
 
     if (!myReference->HasInteractiveContext())
     {
@@ -144,85 +137,29 @@ void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3
 }
 
 //=======================================================================
-//function : Compute
+//function : computeHLR
 //purpose  :
 //=======================================================================
-void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjector,
-                                        const Handle(Geom_Transformation)& theTransformation,
-                                        const Handle(Prs3d_Presentation)& thePresentation)
+void AIS_ConnectedInteractive::computeHLR (const Handle(Graphic3d_Camera)& theProjector,
+                                           const Handle(TopLoc_Datum3D)& theTransformation,
+                                           const Handle(Prs3d_Presentation)& thePresentation)
 {
-  updateShape (Standard_False);
+  const bool hasTrsf = !theTransformation.IsNull()
+                     && theTransformation->Form() != gp_Identity;
+  updateShape (!hasTrsf);
   if (myShape.IsNull())
   {
     return;
   }
-  const TopLoc_Location& aLocation = myShape.Location();
-  TopoDS_Shape aShape = myShape.Located (TopLoc_Location (theTransformation->Trsf()) * aLocation);
-  Compute (theProjector, thePresentation, aShape);
-}
-
-//=======================================================================
-//function : Compute
-//purpose  :
-//=======================================================================
-void AIS_ConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)
-{
-  updateShape (Standard_True);
-  Compute (aProjector, aPresentation, myShape);
-}
-
-//=======================================================================
-//function : Compute
-//purpose  :
-//=======================================================================
-void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjector,
-                                        const Handle(Prs3d_Presentation)& thePresentation,
-                                        const TopoDS_Shape& theShape)
-{
-  if (myShape.IsNull())
+  if (hasTrsf)
   {
-    return;
+    const TopLoc_Location& aLocation = myShape.Location();
+    TopoDS_Shape aShape = myShape.Located (TopLoc_Location (theTransformation->Trsf()) * aLocation);
+    AIS_Shape::computeHlrPresentation (theProjector, thePresentation, aShape, myDrawer);
   }
-
-  switch (theShape.ShapeType())
+  else
   {
-    case TopAbs_VERTEX:
-    case TopAbs_EDGE:
-    case TopAbs_WIRE:
-    {
-      thePresentation->SetDisplayPriority (4);
-      StdPrs_WFShape::Add (thePresentation, theShape, myDrawer);
-      break;
-    }
-    default:
-    {
-      Handle(Prs3d_Drawer) aDefaultDrawer = GetContext()->DefaultDrawer();
-      if (aDefaultDrawer->DrawHiddenLine()) 
-      {
-        myDrawer->EnableDrawHiddenLine();
-      }
-      else 
-      {
-        myDrawer->DisableDrawHiddenLine();
-      }
-      
-      Aspect_TypeOfDeflection aPrevDeflection = aDefaultDrawer->TypeOfDeflection();
-      aDefaultDrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
-
-      // process HLRAngle and HLRDeviationCoefficient()
-      Standard_Real aPrevAngle = myDrawer->HLRAngle();
-      Standard_Real aNewAngle = aDefaultDrawer->HLRAngle();
-      if (myDrawer->IsAutoTriangulation() &&
-          Abs (aNewAngle - aPrevAngle) > Precision::Angular())
-      {
-        BRepTools::Clean (theShape);
-      }
-
-      myDrawer->SetHLRAngle (aNewAngle);
-      myDrawer->SetHLRDeviationCoefficient (aDefaultDrawer->HLRDeviationCoefficient());
-      StdPrs_HLRPolyShape::Add (thePresentation, theShape, myDrawer, theProjector);
-      aDefaultDrawer->SetTypeOfDeflection (aPrevDeflection);
-    }
+    AIS_Shape::computeHlrPresentation (theProjector, thePresentation, myShape, myDrawer);
   }
 }
 
@@ -279,7 +216,6 @@ void AIS_ConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selectio
 
   const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection (theMode);
   Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
-  Handle(Select3D_SensitiveEntity) aSensitive, aNewSensitive;
 
   TopLoc_Location aLocation (Transformation());
   anOwner->SetLocation (aLocation);
@@ -289,17 +225,16 @@ void AIS_ConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selectio
     myReference->RecomputePrimitives (theMode);
   }
 
-  for (TheRefSel->Init(); TheRefSel->More(); TheRefSel->Next())
+  for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (TheRefSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
   {
-    aSensitive = Handle(Select3D_SensitiveEntity)::DownCast (TheRefSel->Sensitive()->BaseSensitive());
-    if (!aSensitive.IsNull())
+    if (const Handle(Select3D_SensitiveEntity)& aSensitive = aSelEntIter.Value()->BaseSensitive())
     {
       // Get the copy of SE3D
-      aNewSensitive = aSensitive->GetConnected();
-
-      aNewSensitive->Set(anOwner);
-
-      theSelection->Add (aNewSensitive);
+      if (Handle(Select3D_SensitiveEntity) aNewSensitive = aSensitive->GetConnected())
+      {
+        aNewSensitive->Set(anOwner);
+        theSelection->Add (aNewSensitive);
+      }
     }
   }
 }
@@ -316,38 +251,28 @@ void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_
     Shapes2EntitiesMap;
 
   if (!myReference->HasSelection (theMode))
+  {
     myReference->RecomputePrimitives (theMode);
-   
-  const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection (theMode);
+  }
 
+  const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection (theMode);
   if (aRefSel->IsEmpty() || aRefSel->UpdateStatus() == SelectMgr_TOU_Full)
   {
     myReference->RecomputePrimitives (theMode);
   }
-  
-  Handle(StdSelect_BRepOwner) anOwner;
-  TopLoc_Location aDummyLoc;
 
-  Handle(Select3D_SensitiveEntity) aSE, aNewSE;
+  // Fill in the map of subshapes and corresponding sensitive entities associated with aMode
   Shapes2EntitiesMap aShapes2EntitiesMap;
-
-  SensitiveList aSEList;
-  TopoDS_Shape aSubShape;
-
-  // Fill in the map of subshapes and corresponding 
-  // sensitive entities associated with aMode 
-  for (aRefSel->Init(); aRefSel->More(); aRefSel->Next())
+  for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aRefSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
   {
-    aSE = Handle(Select3D_SensitiveEntity)::DownCast (aRefSel->Sensitive()->BaseSensitive());
-    if(!aSE.IsNull())
+    if (const Handle(Select3D_SensitiveEntity)& aSE = aSelEntIter.Value()->BaseSensitive())
     {
-      anOwner = Handle(StdSelect_BRepOwner)::DownCast (aSE->OwnerId());
-      if(!anOwner.IsNull())
+      if (Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (aSE->OwnerId()))
       {
-        aSubShape = anOwner->Shape(); 
+        const TopoDS_Shape& aSubShape = anOwner->Shape();
         if(!aShapes2EntitiesMap.IsBound (aSubShape))
         {
-          aShapes2EntitiesMap.Bind (aSubShape, aSEList);
+          aShapes2EntitiesMap.Bind (aSubShape, SensitiveList());
         }
         aShapes2EntitiesMap (aSubShape).Append (aSE);
       }
@@ -357,21 +282,16 @@ void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_
   // Fill in selection from aShapes2EntitiesMap
   for (Shapes2EntitiesMap::Iterator aMapIt (aShapes2EntitiesMap); aMapIt.More(); aMapIt.Next())
   {
-    aSEList = aMapIt.Value();
-    anOwner = new StdSelect_BRepOwner (aMapIt.Key(), 
-                                       this, 
-                                       aSEList.First()->OwnerId()->Priority(), 
-                                       Standard_True);
+    const SensitiveList& aSEList = aMapIt.Value();
+    Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner (aMapIt.Key(), this, aSEList.First()->OwnerId()->Priority(), Standard_True);
     anOwner->SetLocation (Transformation());
-
     for (SensitiveList::Iterator aListIt (aSEList); aListIt.More(); aListIt.Next())
     {
-      aSE = aListIt.Value();
-
-      aNewSE = aSE->GetConnected();
-      aNewSE->Set (anOwner);
-
-      theSelection->Add (aNewSE);
+      if (Handle(Select3D_SensitiveEntity) aNewSE = aListIt.Value()->GetConnected())
+      {
+        aNewSE->Set (anOwner);
+        theSelection->Add (aNewSE);
+      }
     }
   }