0028895: Visualization, V3d_View::SetComputedMode() - HLR calculation is performed...
authorkgv <kgv@opencascade.com>
Mon, 10 Jul 2017 12:43:25 +0000 (15:43 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 13 Jul 2017 14:29:40 +0000 (17:29 +0300)
V3d_View::SetComputedMode() - removed implicit View update.

Graphic3d_CView::SetComputedMode(), ::ReCompute() - fixed
uninitialized bounding box of Computed structure.

PrsMgr_Presentation::Compute() - fixed computation of Computed structure
with transformation within Connected presentation.

StdPrs_HLRPolyShape::Add() now creates Graphic3d_ArrayOfSegments instead of
inefficient Graphic3d_ArrayOfPolylines with boundaries at every segment.

Fixed error in test case bugs/vis/bug24388_1.

15 files changed:
samples/CSharp/OCCTProxy/OCCTProxy.cpp
samples/CSharp/OCCTProxy_D3D/OCCTProxyD3D.cpp
samples/mfc/occtdemo/Common/WNT/OCCDemoView.cpp
samples/mfc/standard/04_Viewer3d/src/Viewer3dView.cpp
samples/mfc/standard/08_HLR/src/SelectionDialog.cpp
samples/mfc/standard/09_Animation/src/AnimationView3D.cpp
samples/mfc/standard/10_Convert/src/WNT/OCCDemoView.cpp
samples/mfc/standard/Common/OCC_3dView.cpp
samples/qt/Common/src/View.cxx
src/Graphic3d/Graphic3d_CView.cxx
src/PrsMgr/PrsMgr_Presentation.cxx
src/StdPrs/StdPrs_HLRPolyShape.cxx
src/V3d/V3d_View.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/bugs/vis/bug24388_1

index 933355b..91d4364 100644 (file)
@@ -133,6 +133,7 @@ public:
     if (!myView().IsNull())
     {
       myView()->SetComputedMode (Standard_False);
+      myView()->Redraw();
     }
   }
 
@@ -144,6 +145,7 @@ public:
     if (!myView().IsNull())
     {
       myView()->SetComputedMode (Standard_True);
+      myView()->Redraw();
     }
   }
 
index 165c705..413674e 100644 (file)
@@ -148,6 +148,7 @@ public:
     if (!myView().IsNull())
     {
       myView()->SetComputedMode (Standard_False);
+      myView()->Redraw();
     }
   }
 
@@ -159,6 +160,7 @@ public:
     if (!myView().IsNull())
     {
       myView()->SetComputedMode (Standard_True);
+      myView()->Redraw();
     }
   }
 
index 56ca7b6..d46d6b0 100755 (executable)
@@ -278,6 +278,7 @@ void COCCDemoView::OnLButtonUp(UINT nFlags, CPoint point)
       {
         SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
         myView->SetComputedMode(Standard_True);
+        myView->Redraw();
         SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
       }
       myCurrentMode = CurAction3d_Nothing;
@@ -301,6 +302,7 @@ void COCCDemoView::OnRButtonUp(UINT nFlags, CPoint point)
   {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     myView->SetComputedMode(Standard_True);
+    myView->Redraw();
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
   }
 }
@@ -497,14 +499,17 @@ void COCCDemoView::RedrawVisMode()
   case VIS_WIREFRAME:
     GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame);
     myView->SetComputedMode (Standard_False);
+    myView->Redraw();
     break;
   case VIS_SHADE:
     GetDocument()->GetAISContext()->SetDisplayMode(AIS_Shaded);
     myView->SetComputedMode (Standard_False);
+    myView->Redraw();
     break;
   case VIS_HLR:
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     myView->SetComputedMode (Standard_True);
+    myView->Redraw();
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
     GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame);
     break;
index d4cda75..9be1e1a 100755 (executable)
@@ -306,6 +306,7 @@ void CViewer3dView::OnBUTTONHlrOff()
 {
   myHlrModeIsOn = Standard_False;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
 
   TCollection_AsciiString aMsg ("myView->SetComputedMode (Standard_False);\n"
                                 "  ");
@@ -319,6 +320,7 @@ void CViewer3dView::OnBUTTONHlrOn()
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
   myHlrModeIsOn = Standard_True;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 
   TCollection_AsciiString aMsg ("myView->SetComputedMode (Standard_True);\n"
@@ -616,7 +618,11 @@ void CViewer3dView::OnRButtonDown(UINT nFlags, CPoint point)
 void CViewer3dView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) 
 {
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
-  myView->SetComputedMode (myHlrModeIsOn);
+  if (myHlrModeIsOn)
+  {
+    myView->SetComputedMode (myHlrModeIsOn);
+    myView->Redraw();
+  }
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
@@ -1177,14 +1183,17 @@ void CViewer3dView::RedrawVisMode()
   case VIS_WIREFRAME:
     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
     myView->SetComputedMode (Standard_False);
+    myView->Redraw();
     break;
   case VIS_SHADE:
     GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
     myView->SetComputedMode (Standard_False);
+    myView->Redraw();
     break;
   case VIS_HLR:
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     myView->SetComputedMode (Standard_True);
+    myView->Redraw();
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
     break;
index 6ef0c98..54f8d38 100644 (file)
@@ -435,11 +435,13 @@ void CSelectionDialog::OnHlrMode()
   if (!m_HlrModeIsOn)
   {
     myActiveView->SetComputedMode (m_HlrModeIsOn != 0);
+    myActiveView->Redraw();
   }
   else
   {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     myActiveView->SetComputedMode (m_HlrModeIsOn != 0);
+    myActiveView->Redraw();
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
   }
   OnDisplay(false);
@@ -500,7 +502,11 @@ void CSelectionDialog::OnRButtonUp(UINT nFlags, CPoint point)
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
   // reset the good HLR mode according to the stored one
   //   --> dynamic rotation may have change it
-  myActiveView->SetComputedMode (m_HlrModeIsOn != 0);
+  if (m_HlrModeIsOn != 0)
+  {
+    myActiveView->SetComputedMode (true);
+    myActiveView->Redraw();
+  }
   OnDisplay(false);
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
index 7f57898..0ffae37 100755 (executable)
@@ -258,6 +258,7 @@ void CAnimationView3D::OnBUTTONHlrOff()
 {
   myHlrModeIsOn = Standard_False;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
 }
 
 void CAnimationView3D::OnBUTTONHlrOn() 
@@ -265,6 +266,7 @@ void CAnimationView3D::OnBUTTONHlrOn()
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
   myHlrModeIsOn = Standard_True;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
@@ -470,7 +472,11 @@ void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
 void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) 
 {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
-    myView->SetComputedMode (myHlrModeIsOn);
+    if (myHlrModeIsOn)
+    {
+      myView->SetComputedMode (myHlrModeIsOn);
+      myView->Redraw();
+    }
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
index 93c67d8..2c8dd36 100755 (executable)
@@ -277,6 +277,7 @@ void COCCDemoView::OnLButtonUp(UINT nFlags, CPoint point)
       {
         SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
         myView->SetComputedMode(Standard_True);
+        myView->Redraw();
         SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
       }
       myCurrentMode = CurAction3d_Nothing;
@@ -300,6 +301,7 @@ void COCCDemoView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
   {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     myView->SetComputedMode(Standard_True);
+    myView->Redraw();
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
   }
 }
@@ -496,14 +498,17 @@ void COCCDemoView::RedrawVisMode()
   case VIS_WIREFRAME:
     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
     myView->SetComputedMode (Standard_False);
+    myView->Redraw();
     break;
   case VIS_SHADE:
     GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
     myView->SetComputedMode (Standard_False);
+    myView->Redraw();
     break;
   case VIS_HLR:
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
     myView->SetComputedMode (Standard_True);
+    myView->Redraw();
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
     GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
     break;
index ec8ddbf..1222c2f 100755 (executable)
@@ -216,6 +216,7 @@ void OCC_3dView::OnBUTTONHlrOff()
 {
   myHlrModeIsOn = Standard_False;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
 }
 
 void OCC_3dView::OnBUTTONHlrOn() 
@@ -223,6 +224,7 @@ void OCC_3dView::OnBUTTONHlrOn()
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
   myHlrModeIsOn = Standard_True;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
   SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
@@ -365,6 +367,7 @@ void OCC_3dView::OnLButtonUp(UINT nFlags, CPoint point)
       {
         CWaitCursor aWaitCursor;
         myView->SetComputedMode (myHlrModeIsOn);
+        myView->Redraw();
       }
       else
       {
@@ -415,7 +418,11 @@ void OCC_3dView::OnRButtonDown(UINT nFlags, CPoint point)
 void OCC_3dView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) 
 {
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
-    myView->SetComputedMode (myHlrModeIsOn);
+    if (myHlrModeIsOn)
+    {
+      myView->SetComputedMode (myHlrModeIsOn);
+      myView->Redraw();
+    }
     SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
 }
 
index ae31db2..9cc8ada 100755 (executable)
@@ -204,6 +204,7 @@ void View::hlrOff()
   QApplication::setOverrideCursor( Qt::WaitCursor );
   myHlrModeIsOn = Standard_False;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
   QApplication::restoreOverrideCursor();
 }
 
@@ -212,6 +213,7 @@ void View::hlrOn()
   QApplication::setOverrideCursor( Qt::WaitCursor );
   myHlrModeIsOn = Standard_True;
   myView->SetComputedMode (myHlrModeIsOn);
+  myView->Redraw();
   QApplication::restoreOverrideCursor();
 }
 
@@ -742,7 +744,11 @@ void View::onRButtonUp( Qt::MouseButtons /*nFlags*/, const QPoint point )
         QApplication::setOverrideCursor( Qt::WaitCursor );
         // reset tyhe good Degenerated mode according to the strored one
         //   --> dynamic rotation may have change it
-        myView->SetComputedMode (myHlrModeIsOn);
+        if (myHlrModeIsOn)
+        {
+          myView->SetComputedMode (myHlrModeIsOn);
+          myView->Redraw();
+        }
         QApplication::restoreOverrideCursor();
         myCurrentMode = CurAction3d_Nothing;
     }
index bb63a60..2a0e803 100644 (file)
@@ -258,6 +258,7 @@ void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode)
         myStructsComputed .Append (aCompStruct);
       }
 
+      aCompStruct->CalculateBoundBox();
       eraseStructure   (aStruct->CStructure());
       displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
     }
@@ -306,6 +307,7 @@ void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
   theStruct->IsTransformed() ? theStruct->Compute (this, theStruct->Transformation(), aCompStruct)
                              : theStruct->Compute (this,                              aCompStruct);
   aCompStruct->SetHLRValidation (Standard_True);
+  aCompStruct->CalculateBoundBox();
 
   // of which type will be the computed?
   const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
index 75e8bc4..17ff1c2 100644 (file)
@@ -287,31 +287,7 @@ Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d
                                                           const Handle(Geom_Transformation)&            theTrsf)
 {
   Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager());
-  if (theTrsf->Form() == gp_Translation)
-  {
-    myPresentableObject->Compute (Projector (theProjector), aPrs3d);
-    aPrs3d->SetTransformation (theTrsf);
-    return aPrs3d;
-  }
-
-  // waiting that something is done in gp_Trsf...rob
-  for (Standard_Integer i = 1; i <= 3; ++i)
-  {
-    for (Standard_Integer j = 1; j <= 3; ++j)
-    {
-      if (i != j)
-      {
-        if (Abs (theTrsf->Value (i, j)) > Precision::Confusion())
-        {
-          myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
-          return aPrs3d;
-        }
-      }
-    }
-  }
-
-  myPresentableObject->Compute (Projector (theProjector), aPrs3d);
-  aPrs3d->SetTransformation (theTrsf);
+  myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
   return aPrs3d;
 }
 
index fb2e136..4ade3a1 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
+#include <StdPrs_HLRPolyShape.hxx>
 
 #include <BRepMesh_IncrementalMesh.hxx>
-#include <Graphic3d_ArrayOfPolylines.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
 #include <Graphic3d_Group.hxx>
 #include <HLRAlgo_EdgeIterator.hxx>
 #include <HLRAlgo_EdgeStatus.hxx>
@@ -27,7 +28,6 @@
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <Prs3d_Projector.hxx>
-#include <StdPrs_HLRPolyShape.hxx>
 #include <StdPrs_WFShape.hxx>
 #include <TColgp_SequenceOfPnt.hxx>
 #include <TopAbs.hxx>
@@ -64,9 +64,6 @@ void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
     }
   }
 
-  TColgp_SequenceOfPnt HiddenPnts;
-  TColgp_SequenceOfPnt SeenPnts;
-
   if (aDrawer->IsAutoTriangulation())
   {
     const Standard_Boolean aRel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
@@ -121,48 +118,64 @@ void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
             S,reg1,regn,outl,intl));   
     }
   }
-  
-  // storage in the group:
-  HLRBRep_ListIteratorOfListOfBPoint ItB;
 
-  if (aDrawer->DrawHiddenLine()) {
-    for (ItB.Initialize(BiPntHid); ItB.More(); ItB.Next()) {
-      const HLRBRep_BiPoint& BP = ItB.Value();
-      if (!BP.RgNLine() || BP.OutLine()) {
-        HiddenPnts.Append(BP.P1());
-        HiddenPnts.Append(BP.P2());
+  // storage in the group
+  if (aDrawer->DrawHiddenLine())
+  {
+    Standard_Integer aNbHiddenSegments = 0;
+    for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
+    {
+      const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
+      if (!aBPnt.RgNLine()
+        || aBPnt.OutLine())
+      {
+        ++aNbHiddenSegments;
       }
     }
-  }
+    if (aNbHiddenSegments > 0)
+    {
+      Handle(Graphic3d_ArrayOfSegments) aHiddenArray = new Graphic3d_ArrayOfSegments (aNbHiddenSegments * 2);
+      for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
+      {
+        const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
+        if (!aBPnt.RgNLine()
+          || aBPnt.OutLine())
+        {
+          aHiddenArray->AddVertex (aBPnt.P1());
+          aHiddenArray->AddVertex (aBPnt.P2());
+        }
+      }
 
-  for (ItB.Initialize(BiPntVis); ItB.More(); ItB.Next()) {
-    const HLRBRep_BiPoint& BP = ItB.Value();
-    if (!BP.RgNLine() || BP.OutLine()) {
-      SeenPnts.Append(BP.P1());
-      SeenPnts.Append(BP.P2());
+      aGroup->SetPrimitivesAspect (aDrawer->HiddenLineAspect()->Aspect());
+      aGroup->AddPrimitiveArray (aHiddenArray);
     }
   }
-
-  Standard_Integer nbVertices = HiddenPnts.Length();
-  if(nbVertices > 0) {
-    Handle(Graphic3d_ArrayOfPolylines) HiddenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
-    for(int i=1; i<=nbVertices; i+=2) {
-      HiddenArray->AddBound(2);
-      HiddenArray->AddVertex(HiddenPnts.Value(i));
-      HiddenArray->AddVertex(HiddenPnts.Value(i+1));
+  {
+    Standard_Integer aNbSeenSegments = 0;
+    for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
+    {
+      const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
+      if (!aBPnt.RgNLine()
+        || aBPnt.OutLine())
+      {
+        ++aNbSeenSegments;
+      }
     }
-    aGroup->SetPrimitivesAspect(aDrawer->HiddenLineAspect()->Aspect());
-    aGroup->AddPrimitiveArray(HiddenArray);
-  }
-  nbVertices = SeenPnts.Length();
-  if(nbVertices > 0) {
-    Handle(Graphic3d_ArrayOfPolylines) SeenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
-    for(int i=1; i<=nbVertices; i+=2) {
-      SeenArray->AddBound(2);
-      SeenArray->AddVertex(SeenPnts.Value(i));
-      SeenArray->AddVertex(SeenPnts.Value(i+1));
+    if (aNbSeenSegments > 0)
+    {
+      Handle(Graphic3d_ArrayOfSegments) aSeenArray = new Graphic3d_ArrayOfSegments (aNbSeenSegments * 2);
+      for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
+      {
+        const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
+        if (!aBPnt.RgNLine()
+          || aBPnt.OutLine())
+        {
+          aSeenArray->AddVertex (aBPnt.P1());
+          aSeenArray->AddVertex (aBPnt.P2());
+        }
+      }
+      aGroup->SetPrimitivesAspect (aDrawer->SeenLineAspect()->Aspect());
+      aGroup->AddPrimitiveArray (aSeenArray);
     }
-    aGroup->SetPrimitivesAspect(aDrawer->SeenLineAspect()->Aspect());
-    aGroup->AddPrimitiveArray(SeenArray);
   }
 }   
index acf06ef..9b1c914 100644 (file)
@@ -2710,13 +2710,11 @@ void V3d_View::SetComputedMode (const Standard_Boolean theMode)
     if (myComputedMode)
     {
       myView->SetComputedMode (Standard_True);
-      Update();
     }
   }
   else
   {
     myView->SetComputedMode (Standard_False);
-    Update();
   }
 }
 
index 02c113b..20b1ed0 100644 (file)
@@ -163,8 +163,6 @@ Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
 }
 #endif
 
-static Standard_Boolean MyHLRIsOn = Standard_False;
-
 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>  ViewerTest_myContexts;
 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
@@ -185,6 +183,7 @@ static struct
 //==============================================================================
 
 static int Start_Rot = 0;
+Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
 int X_Motion = 0; // Current cursor position
 int Y_Motion = 0;
 int X_ButtonPress = 0; // Last ButtonPress position
@@ -717,7 +716,6 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
   // Set parameters for V3d_View and V3d_Viewer
   const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
   aV3dView->SetComputedMode(Standard_False);
-  MyHLRIsOn = aV3dView->ComputedMode();
 
   a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
   if (toCreateViewer)
@@ -850,76 +848,142 @@ static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const cha
   return 0;
 }
 
+//! Parse HLR algo type.
+static Standard_Boolean parseHlrAlgoType (const char* theName,
+                                          Prs3d_TypeOfHLR& theType)
+{
+  TCollection_AsciiString aName (theName);
+  aName.LowerCase();
+  if (aName == "polyalgo")
+  {
+    theType = Prs3d_TOH_PolyAlgo;
+  }
+  else if (aName == "algo")
+  {
+    theType = Prs3d_TOH_Algo;
+  }
+  else
+  {
+    return Standard_False;
+  }
+  return Standard_True;
+}
+
 //==============================================================================
 //function : VHLR
 //purpose  : hidden lines removal algorithm
-//draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
 //==============================================================================
 
 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (ViewerTest::CurrentView().IsNull())
+  const Handle(V3d_View) aView = ViewerTest::CurrentView();
+  const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aView.IsNull())
   {
-    di << argv[0] << ": Call vinit before this command, please.\n";
+    std::cerr << "Error: No opened viewer!\n";
     return 1;
   }
 
-  if (argc < 2)
+  Standard_Boolean hasHlrOnArg = Standard_False;
+  Standard_Boolean hasShowHiddenArg = Standard_False;
+  Standard_Boolean isHLROn = Standard_False;
+  Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
+  Prs3d_TypeOfHLR  aTypeOfHLR = Prs3d_TOH_NotSet;
+  ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
+  for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
   {
-    di << argv[0] << ": Wrong number of command arguments.\n"
-      << "Type help " << argv[0] << " for more information.\n";
-    return 1;
+    TCollection_AsciiString anArg (argv[anArgIter]);
+    anArg.LowerCase();
+    if (anUpdateTool.parseRedrawMode (anArg))
+    {
+      continue;
+    }
+    else if (anArg == "-showhidden"
+          && anArgIter + 1 < argc
+          && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
+    {
+      ++anArgIter;
+      hasShowHiddenArg = Standard_True;
+      continue;
+    }
+    else if ((anArg == "-type"
+           || anArg == "-algo"
+           || anArg == "-algotype")
+          && anArgIter + 1 < argc
+          && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
+    {
+      ++anArgIter;
+      continue;
+    }
+    else if (!hasHlrOnArg
+          && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
+    {
+      hasHlrOnArg = Standard_True;
+      continue;
+    }
+    // old syntax
+    else if (!hasShowHiddenArg
+          && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
+    {
+      hasShowHiddenArg = Standard_True;
+      continue;
+    }
+    else
+    {
+      std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+      return 1;
+    }
   }
-
-  // Enable or disable HLR mode.
-  Standard_Boolean isHLROn =
-    (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
-
-  if (isHLROn != MyHLRIsOn)
+  if (!hasHlrOnArg)
   {
-    MyHLRIsOn = isHLROn;
-    ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
+    di << "HLR:        " << aView->ComputedMode() << "\n";
+    di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
+    di << "HlrAlgo:    ";
+    switch (aCtx->DefaultDrawer()->TypeOfHLR())
+    {
+      case Prs3d_TOH_NotSet:   di << "NotSet\n";   break;
+      case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
+      case Prs3d_TOH_Algo:     di << "Algo\n";     break;
+    }
+    anUpdateTool.Invalidate();
+    return 0;
   }
 
-  // Show or hide hidden lines in HLR mode.
-  Standard_Boolean isCurrentShowHidden
-    = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
-
-  Standard_Boolean isShowHidden =
-    (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
-                : isCurrentShowHidden;
-
-
-  if (isShowHidden != isCurrentShowHidden)
+  Standard_Boolean toRecompute = Standard_False;
+  if (aTypeOfHLR != Prs3d_TOH_NotSet
+   && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
   {
-    if (isShowHidden)
+    toRecompute = Standard_True;
+    aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
+  }
+  if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
+  {
+    toRecompute = Standard_True;
+    if (toShowHidden)
     {
-      ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
+      aCtx->DefaultDrawer()->EnableDrawHiddenLine();
     }
     else
     {
-      ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
+      aCtx->DefaultDrawer()->DisableDrawHiddenLine();
     }
+  }
 
-    // Redisplay shapes.
-    if (MyHLRIsOn)
+  // redisplay shapes
+  if (aView->ComputedMode() && isHLROn && toRecompute)
+  {
+    AIS_ListOfInteractive aListOfShapes;
+    aCtx->DisplayedObjects (aListOfShapes);
+    for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
     {
-      AIS_ListOfInteractive aListOfShapes;
-      ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
-
-      for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
+      if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
       {
-        Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
-        if (aShape.IsNull())
-        {
-          continue;
-        }
-        ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
+        aCtx->Redisplay (aShape, Standard_False);
       }
     }
   }
 
-  ViewerTest::CurrentView()->Update();
+  aView->SetComputedMode (isHLROn);
   return 0;
 }
 
@@ -928,66 +992,95 @@ static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 //purpose  : change type of using HLR algorithm
 //==============================================================================
 
-static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
 {
-  if (ViewerTest::CurrentView().IsNull())
-  {
-    di << argv[0] << ": Call vinit before this command, please.\n";
-    return 1;
-  }
-
-  if (argc < 2)
+  const Handle(V3d_View) aView = ViewerTest::CurrentView();
+  const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aView.IsNull())
   {
-    di << argv[0] << ": Wrong number of command arguments.\n"
-      << "Type help " << argv[0] << " for more information.\n";
+    std::cerr << "Error: No opened viewer!\n";
     return 1;
   }
 
-  Prs3d_TypeOfHLR aTypeOfHLR =
-    (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
-
-  if (argc == 2)
+  Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
+  ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
+  AIS_ListOfInteractive aListOfShapes;
+  for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
   {
-    AIS_ListOfInteractive aListOfShapes;
-    ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
-    ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
-    for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
-      anIter.More(); anIter.Next())
+    TCollection_AsciiString anArg (argv[anArgIter]);
+    anArg.LowerCase();
+    if (anUpdateTool.parseRedrawMode (anArg))
     {
-      Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
-      if (aShape.IsNull())
-        continue;
-      if (aShape->TypeOfHLR() != aTypeOfHLR)
-        aShape->SetTypeOfHLR (aTypeOfHLR);
-      if (MyHLRIsOn)
-        ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
+      continue;
     }
-    ViewerTest::CurrentView()->Update();
-    return 0;
-  }
-  else
-  {
-    for (Standard_Integer i = 2; i < argc; ++i)
+    else if ((anArg == "-type"
+           || anArg == "-algo"
+           || anArg == "-algotype")
+          && anArgIter + 1 < argc
+          && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
+    {
+      ++anArgIter;
+      continue;
+    }
+    // old syntax
+    else if (aTypeOfHLR == Prs3d_TOH_NotSet
+          && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
+    {
+      continue;
+    }
+    else
     {
       ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
-      TCollection_AsciiString aName (argv[i]);
-
+      TCollection_AsciiString aName (argv[anArgIter]);
       if (!aMap.IsBound2 (aName))
       {
-        di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n";
-        continue;
+        std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
+        return 1;
       }
-      Handle(AIS_Shape) anAISObject =
-        Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
-      if (anAISObject.IsNull())
-        continue;
-      anAISObject->SetTypeOfHLR (aTypeOfHLR);
-      if (MyHLRIsOn)
-        ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
+
+      Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
+      if (aShape.IsNull())
+      {
+        std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
+        return 1;
+      }
+      aListOfShapes.Append (aShape);
+      continue;
     }
-    ViewerTest::CurrentView()->Update();
+  }
+  if (aTypeOfHLR == Prs3d_TOH_NotSet)
+  {
+    std::cout << "Syntax error: wrong number of arguments!\n";
+    return 1;
+  }
+
+  const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
+  if (isGlobal)
+  {
+    aCtx->DisplayedObjects (aListOfShapes);
+    aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
   }
 
+  for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
+  {
+    Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
+    if (aShape.IsNull())
+    {
+      continue;
+    }
+
+    const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
+                            && aView->ComputedMode();
+    if (!isGlobal
+     || aShape->TypeOfHLR() != aTypeOfHLR)
+    {
+      aShape->SetTypeOfHLR (aTypeOfHLR);
+    }
+    if (toUpdateShape)
+    {
+      aCtx->Redisplay (aShape, Standard_False);
+    }
+  }
   return 0;
 }
 
@@ -1030,13 +1123,10 @@ void ActivateView (const TCollection_AsciiString& theViewName)
       }
 
       ViewerTest::CurrentView (aView);
-      // Update degenerate mode
-      MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
       ViewerTest::SetAISContext (anAISContext);
-      TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
-      aTitle = aTitle + theViewName + "(*)";
+      TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
       SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
-#if defined(_WIN32) || defined(__WIN32__)
+#if defined(_WIN32)
       VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
       VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
@@ -1390,9 +1480,9 @@ void VT_ProcessKeyPress (const char* buf_ret)
   else if (!strcasecmp (buf_ret, "H"))
   {
     // HLR
-    cout << "HLR" << endl;
+    std::cout << "HLR" << std::endl;
     aView->SetComputedMode (!aView->ComputedMode());
-    MyHLRIsOn = aView->ComputedMode();
+    aView->Redraw();
   }
   else if (!strcasecmp (buf_ret, "P"))
   {
@@ -1638,7 +1728,8 @@ void VT_ProcessButton1Release (Standard_Boolean theIsShift)
 void VT_ProcessButton3Press()
 {
   Start_Rot = 1;
-  if (MyHLRIsOn)
+  HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
+  if (HasHlrOnBeforeRotation)
   {
     ViewerTest::CurrentView()->SetComputedMode (Standard_False);
   }
@@ -1654,9 +1745,11 @@ void VT_ProcessButton3Release()
   if (Start_Rot)
   {
     Start_Rot = 0;
-    if (MyHLRIsOn)
+    if (HasHlrOnBeforeRotation)
     {
+      HasHlrOnBeforeRotation = Standard_False;
       ViewerTest::CurrentView()->SetComputedMode (Standard_True);
+      ViewerTest::CurrentView()->Redraw();
     }
   }
 }
@@ -11152,19 +11245,18 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "                              ts, tt      - translation for s and t texture coordinates\n"
     "                              rot         - texture rotation angle in degrees",
     __FILE__, VTextureEnv, group);
-  theCommands.Add("vhlr" ,
-    "is_enabled={on|off} [show_hidden={1|0}]"
-    " - Hidden line removal algorithm:"
-    " - is_enabled: if is on HLR algorithm is applied\n"
-    " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
+  theCommands.Add("vhlr",
+            "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
+      "\n\t\t: Hidden Line Removal algorithm."
+      "\n\t\t:   -showHidden if set ON, hidden lines are drawn as dotted ones"
+      "\n\t\t:   -algoType   type of HLR algorithm.\n",
     __FILE__,VHLR,group);
-  theCommands.Add("vhlrtype" ,
-    "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
-    " - Changes the type of HLR algorithm using for shapes."
-    " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
-    "   if equals to polyalgo, polygonal HLR algorithm is applied."
-    "If shapes are not given HLR algoithm of given type is applied"
-    " to all shapes in the view\n",
+  theCommands.Add("vhlrtype",
+              "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
+      "\n\t\t: Changes the type of HLR algorithm using for shapes:"
+      "\n\t\t:   'algo' - exact HLR algorithm is applied"
+      "\n\t\t:   'polyAlgo' - polygonal HLR algorithm is applied"
+      "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
     __FILE__,VHLRType,group);
   theCommands.Add("vclipplane",
               "vclipplane planeName [{0|1}]"
index 31458fa..9b0cbda 100644 (file)
@@ -13,7 +13,7 @@ vdisplay b
 vrotate 35 0 0
 vfit
 vhlr on 1
-vhlrtype algo a
+vhlrtype algo b
 
 vmoveto 76 304