0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_Shape.cxx
index 75a7e8f..b1afa4b 100644 (file)
@@ -23,7 +23,6 @@
 #include <BRepBndLib.hxx>
 #include <BRepTools.hxx>
 #include <BRepTools_ShapeSet.hxx>
-#include <Geom_Transformation.hxx>
 #include <gp_Pnt.hxx>
 #include <Graphic3d_ArrayOfPolylines.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_Presentation.hxx>
-#include <Prs3d_Projector.hxx>
 #include <Prs3d_Root.hxx>
 #include <Prs3d_ShadingAspect.hxx>
-#include <StdPrs_BndBox.hxx>
+#include <Prs3d_BndBox.hxx>
 #include <StdPrs_ToolTriangulatedShape.hxx>
-#include <PrsMgr_ModedPresentation.hxx>
 #include <Quantity_Color.hxx>
 #include <Select3D_SensitiveBox.hxx>
 #include <Select3D_SensitiveEntity.hxx>
 #include <StdSelect.hxx>
 #include <StdSelect_BRepOwner.hxx>
 #include <StdSelect_BRepSelectionTool.hxx>
-#include <StdSelect_DisplayMode.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <TopExp.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
 
-static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
-{
-  TColStd_ListIteratorOfListOfInteger It(LL);
-  for(;It.More();It.Next()){
-    if(It.Value()==aMode) 
-      return Standard_True;}
-  return Standard_False;
-}
-
 // Auxiliary macros
 #define replaceAspectWithDef(theMap, theAspect) \
   if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
@@ -166,9 +153,8 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
       }
       catch (Standard_Failure const& anException)
       {
-        Message::DefaultMessenger()->Send (TCollection_AsciiString()
-                                         + "Error: AIS_Shape::Compute() wireframe presentation builder has failed ("
-                                         + anException.GetMessageString() + ")", Message_Fail);
+        Message::SendFail (TCollection_AsciiString("Error: AIS_Shape::Compute() wireframe presentation builder has failed (")
+                         + anException.GetMessageString() + ")");
       }
       break;
     }
@@ -197,9 +183,8 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
           }
           catch (Standard_Failure const& anException)
           {
-            Message::DefaultMessenger()->Send (TCollection_AsciiString()
-                                               + "Error: AIS_Shape::Compute() shaded presentation builder has failed ("
-                                               + anException.GetMessageString() + ")", Message_Fail);
+            Message::SendFail (TCollection_AsciiString("Error: AIS_Shape::Compute() shaded presentation builder has failed (")
+                             + anException.GetMessageString() + ")");
             StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
           }
         }
@@ -221,7 +206,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
       }
       else
       {
-        StdPrs_BndBox::Add (aPrs, BoundingBox(), myDrawer);
+        Prs3d_BndBox::Add (aPrs, BoundingBox(), myDrawer);
       }
     }
   }
@@ -234,7 +219,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
 //function : computeHlrPresentation
 //purpose  :
 //=======================================================================
-void AIS_Shape::computeHlrPresentation (const Handle(Prs3d_Projector)& theProjector,
+void AIS_Shape::computeHlrPresentation (const Handle(Graphic3d_Camera)& theProjector,
                                         const Handle(Prs3d_Presentation)& thePrs,
                                         const TopoDS_Shape& theShape,
                                         const Handle(Prs3d_Drawer)& theDrawer)
@@ -292,19 +277,24 @@ void AIS_Shape::computeHlrPresentation (const Handle(Prs3d_Projector)& theProjec
       switch (theDrawer->TypeOfHLR())
       {
         case Prs3d_TOH_Algo:
-          StdPrs_HLRShape::Add (thePrs, theShape, theDrawer, theProjector);
+        {
+          StdPrs_HLRShape aBuilder;
+          aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
           break;
+        }
         case Prs3d_TOH_PolyAlgo:
-        default:
-          StdPrs_HLRPolyShape::Add (thePrs, theShape, theDrawer, theProjector);
+        case Prs3d_TOH_NotSet:
+        {
+          StdPrs_HLRPolyShape aBuilder;
+          aBuilder.ComputeHLR (thePrs, theShape, theDrawer, theProjector);
           break;
+        }
       }
     }
     catch (Standard_Failure const& anException)
     {
-      Message::DefaultMessenger()->Send (TCollection_AsciiString()
-                                       + "Error: AIS_Shape::Compute() HLR Algorithm has failed ("
-                                       + anException.GetMessageString() + ")", Message_Fail);
+      Message::SendFail (TCollection_AsciiString("Error: AIS_Shape::Compute() HLR Algorithm has failed (")
+                       + anException.GetMessageString() + ")");
       StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
     }
   }
@@ -332,7 +322,7 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
 
 // POP protection against crash in low layers
 
-  Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
+  Standard_Real aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection(shape, myDrawer);
   try
   {
     OCC_CATCH_SIGNALS
@@ -341,14 +331,13 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
                                       shape,
                                       TypOfSel,
                                       aDeflection,
-                                      myDrawer->HLRAngle(),
+                                      myDrawer->DeviationAngle(),
                                       myDrawer->IsAutoTriangulation());
   }
   catch (Standard_Failure const& anException)
   {
-    Message::DefaultMessenger()->Send (TCollection_AsciiString()
-                                       + "Error: AIS_Shape::ComputeSelection(" + aMode + ") has failed ("
-                                       + anException.GetMessageString() + ")", Message_Fail);
+    Message::SendFail (TCollection_AsciiString("Error: AIS_Shape::ComputeSelection(") + aMode + ") has failed ("
+                     + anException.GetMessageString() + ")");
     if (aMode == 0)
     {
       aSelection->Clear();
@@ -411,8 +400,6 @@ void AIS_Shape::SetColor (const Quantity_Color& theColor)
   myDrawer->SetColor (theColor);
   hasOwnColor = Standard_True;
 
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
   if (!toRecompute
    || !myDrawer->HasLink())
   {
@@ -432,8 +419,6 @@ void AIS_Shape::SetColor (const Quantity_Color& theColor)
 
 void AIS_Shape::UnsetColor()
 {
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
   if (!HasColor())
   {
     return;
@@ -578,10 +563,8 @@ bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
 
 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
 {
-  myOwnWidth = theLineWidth;
+  myOwnWidth = (Standard_ShortReal )theLineWidth;
 
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
   if (!setWidth (myDrawer, theLineWidth)
    || !myDrawer->HasLink())
   {
@@ -601,14 +584,12 @@ void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
 
 void AIS_Shape::UnsetWidth()
 {
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
-  if (myOwnWidth == 0.0)
+  if (myOwnWidth == 0.0f)
   {
     return;
   }
 
-  myOwnWidth = 0.0;
+  myOwnWidth = 0.0f;
   if (!HasColor())
   {
     Graphic3d_MapOfAspectsToAspects aReplaceMap;
@@ -655,7 +636,7 @@ void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
                              const Standard_Boolean          theToKeepColor,
                              const Standard_Boolean          theToKeepTransp) const
 {
-  const Quantity_Color aColor  = theDrawer->ShadingAspect()->Material     (myCurrentFacingModel).Color();
+  const Quantity_Color aColor  = theDrawer->ShadingAspect()->Color (myCurrentFacingModel);
   const Standard_Real  aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
   theDrawer->SetupOwnShadingAspect();
   theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
@@ -681,8 +662,6 @@ void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
   setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
   hasOwnMaterial = Standard_True;
 
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
   if (!toRecompute
    || !myDrawer->HasLink())
   {
@@ -701,8 +680,6 @@ void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
 
 void AIS_Shape::UnsetMaterial()
 {
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
   if (!HasMaterial())
   {
     return;
@@ -761,8 +738,6 @@ void AIS_Shape::SetTransparency (const Standard_Real theValue)
   setTransparency (myDrawer, theValue);
   myDrawer->SetTransparency ((Standard_ShortReal )theValue);
 
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
   if (!toRecompute
    || !myDrawer->HasLink())
   {
@@ -781,9 +756,6 @@ void AIS_Shape::SetTransparency (const Standard_Real theValue)
 
 void AIS_Shape::UnsetTransparency()
 {
-  myRecomputeEveryPrs = false; // no mode to recalculate, only viewer update
-  myToRecomputeModes.Clear();
-
   myDrawer->SetTransparency (0.0f);
   if (!myDrawer->HasOwnShadingAspect())
   {
@@ -805,18 +777,6 @@ void AIS_Shape::UnsetTransparency()
   }
 }
 
-//=======================================================================
-//function : LoadRecomputable
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
-{
-  myRecomputeEveryPrs = Standard_False;
-  if(!IsInList(myToRecomputeModes,TheMode))
-    myToRecomputeModes.Append(TheMode);
-}
-
 //=======================================================================
 //function : BoundingBox
 //purpose  : 
@@ -832,7 +792,7 @@ const Bnd_Box& AIS_Shape::BoundingBox()
   }
 
   if(myCompBB) {
-    BRepBndLib::AddClose(myshape, myBB);
+    BRepBndLib::Add (myshape, myBB, false);
     myCompBB = Standard_False;
   }
   return myBB;
@@ -853,20 +813,6 @@ Standard_Boolean AIS_Shape::SetOwnDeviationCoefficient ()
   return itSet;
 }
 
-//=======================================================================
-//function : SetHLROwnDeviationCoefficient
-//purpose  : resets myhasOwnHLRDeviationCoefficient to Standard_False and
-//           returns Standard_True if it change
-//=======================================================================
-
-Standard_Boolean AIS_Shape::SetOwnHLRDeviationCoefficient ()
-{
-  Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationCoefficient();
-  if(itSet)  myDrawer->SetHLRDeviationCoefficient();
-  return itSet;
-
-}
-
 //=======================================================================
 //function : SetOwnDeviationAngle
 //purpose  : resets myhasOwnDeviationAngle to Standard_False and
@@ -881,20 +827,6 @@ Standard_Boolean AIS_Shape::SetOwnDeviationAngle ()
 
 }
 
-//=======================================================================
-//function : SetOwnHLRDeviationAngle
-//purpose  : resets myhasOwnHLRDeviationAngle to Standard_False and
-//           returns Standard_True if it change
-//=======================================================================
-
-Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
-{
-  Standard_Boolean itSet = myDrawer->HasOwnHLRDeviationAngle();
-  if(itSet)  myDrawer->SetHLRAngle();
-  return itSet;
-
-}
-//***** SetOwn
 //=======================================================================
 //function : SetOwnDeviationCoefficient
 //purpose  : 
@@ -903,19 +835,7 @@ Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real  aCoefficient )
 {
   myDrawer->SetDeviationCoefficient( aCoefficient );
-  SetToUpdate(0) ; // WireFrame
-  SetToUpdate(1) ; // Shadding
-}
-
-//=======================================================================
-//function : SetOwnHLRDeviationCoefficient
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real  aCoefficient )
-{
-  myDrawer->SetHLRDeviationCoefficient( aCoefficient );
-  
+  SetToUpdate();
 }
 
 //=======================================================================
@@ -923,11 +843,10 @@ void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real  aCoefficien
 //purpose  : 
 //=======================================================================
 
-void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real  anAngle )
+void AIS_Shape::SetOwnDeviationAngle (const Standard_Real theAngle)
 {
-
-  myDrawer->SetDeviationAngle(anAngle );
-  SetToUpdate(0) ;   // WireFrame
+  myDrawer->SetDeviationAngle (theAngle);
+  SetToUpdate (AIS_WireFrame);
 }
 //=======================================================================
 //function : SetOwnDeviationAngle
@@ -941,8 +860,7 @@ void AIS_Shape::SetAngleAndDeviation ( const Standard_Real  anAngle )
   SetOwnDeviationAngle(anAngle) ;
   SetOwnDeviationCoefficient(OutDefl) ;
   myInitAng = anAngle;
-  SetToUpdate(0);
-  SetToUpdate(1);
+  SetToUpdate();
 }
 
 //=======================================================================
@@ -955,31 +873,6 @@ Standard_Real AIS_Shape::UserAngle() const
   return myInitAng ==0. ? GetContext()->DeviationAngle(): myInitAng;
 }
 
-
-//=======================================================================
-//function : SetHLRAngleAndDeviation
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::SetHLRAngleAndDeviation ( const Standard_Real  anAngle )
-{
-  Standard_Real OutAngl,OutDefl;
-  HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
-  SetOwnHLRDeviationAngle( OutAngl );
-  SetOwnHLRDeviationCoefficient(OutDefl);
-
-}
-//=======================================================================
-//function : SetOwnHLRDeviationAngle
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::SetOwnHLRDeviationAngle ( const Standard_Real  anAngle )
-{
-  myDrawer->SetHLRAngle( anAngle );
-}
-
-//***** GetOwn
 //=======================================================================
 //function : OwnDeviationCoefficient
 //purpose  : 
@@ -993,20 +886,6 @@ Standard_Boolean AIS_Shape::OwnDeviationCoefficient ( Standard_Real &  aCoeffici
   return myDrawer->HasOwnDeviationCoefficient() ;
 }
 
-//=======================================================================
-//function : OwnHLRDeviationCoefficient
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean AIS_Shape::OwnHLRDeviationCoefficient ( Standard_Real & aCoefficient,
-                                                         Standard_Real & aPreviousCoefficient ) const
-{
-  aCoefficient = myDrawer->HLRDeviationCoefficient();
-  aPreviousCoefficient = myDrawer->PreviousHLRDeviationCoefficient ();
-  return myDrawer->HasOwnHLRDeviationCoefficient();
-
-}
-
 //=======================================================================
 //function : OwnDeviationAngle
 //purpose  : 
@@ -1021,14 +900,17 @@ Standard_Boolean AIS_Shape::OwnDeviationAngle ( Standard_Real &  anAngle,
 }
 
 //=======================================================================
-//function : OwnHLRDeviationAngle
+//function : DumpJson
 //purpose  : 
 //=======================================================================
-
-Standard_Boolean AIS_Shape::OwnHLRDeviationAngle ( Standard_Real &  anAngle,
-                                                   Standard_Real & aPreviousAngle ) const
+void AIS_Shape::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
 {
-  anAngle = myDrawer->HLRAngle();
-  aPreviousAngle = myDrawer->PreviousHLRDeviationAngle (); 
-  return myDrawer->HasOwnHLRDeviationAngle();
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
+  OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
+
+  OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myshape)
+  OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBB)
+
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myInitAng)
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCompBB)
 }