0020716: Eliminate usage of "config.h" header file
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
index 63e4264..000e20e 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#ifdef HAVE_CONFIG_H
-  #include <config.h>
-#endif
-
 #include <OpenGl_GlCore20.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_Drawer.hxx>
@@ -2480,7 +2476,7 @@ static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const
 
   if (theArgsNb == 1)
   {
-    aCurrentView->ZFitAll();
+    aCurrentView->View()->ZFitAll();
     aCurrentView->Redraw();
     return 0;
   }
@@ -2492,7 +2488,7 @@ static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const
     aScale = Draw::Atoi (theArgVec[1]);
   }
 
-  aCurrentView->ZFitAll (aScale);
+  aCurrentView->View()->ZFitAll (aScale);
   aCurrentView->Redraw();
 
   return 0;
@@ -2851,7 +2847,7 @@ static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, cons
     return 1;
   }
 
-  V3dView->ZFitAll();
+  V3dView->View()->ZFitAll();
 
   return 0;
 }
@@ -5671,7 +5667,7 @@ static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const
     return 1;
   }
 
-  Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
+  Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
 
   if (theArgsNb > 3)
   {
@@ -5682,7 +5678,7 @@ static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const
   if (theArgsNb < 2)
   {
     theDi << "Auto z-fit mode: " << "\n"
-          << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
+          << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
           << "Scale: " << aScale << "\n";
     return 0;
   }
@@ -5694,8 +5690,8 @@ static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const
     aScale = Draw::Atoi (theArgVec[2]);
   }
 
-  aCurrentView->SetAutoZFitMode (isOn, aScale);
-  aCurrentView->AutoZFit();
+  aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
+  aCurrentView->View()->AutoZFit();
   aCurrentView->Redraw();
 
   return 0;
@@ -5810,7 +5806,7 @@ static int VChangeCamera (Draw_Interpretor& theDi, Standard_Integer theArgsNb, c
     return 1;
   }
 
-  ViewerTest::CurrentView()->AutoZFit();
+  ViewerTest::CurrentView()->View()->AutoZFit();
   ViewerTest::CurrentView()->Redraw();
 
   return 0;
@@ -6649,6 +6645,117 @@ static int VFrustumCulling (Draw_Interpretor& theDI,
   return 0;
 }
 
+//=======================================================================
+//function : VHighlightSelected
+//purpose  : 
+//=======================================================================
+static int VHighlightSelected (Draw_Interpretor& theDI,
+                               Standard_Integer  theArgNb,
+                               const char**      theArgVec)
+{
+  if (ViewerTest::GetAISContext().IsNull())
+  {
+    std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
+    return 1;
+  }
+
+  const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+
+  if (theArgNb < 2)
+  {
+    theDI << (aContext->ToHilightSelected() ? "on" : "off");
+    return 0;
+  }
+
+  if (theArgNb != 2)
+  {
+    std::cout  << theArgVec[0] << " error : wrong number of parameters."
+          << "Type 'help" << theArgVec[0] << "' for more information.";
+    return 1;
+  }
+
+  // Parse parameter
+  TCollection_AsciiString aMode (theArgVec[1]);
+  aMode.LowerCase();
+  Standard_Boolean toEnable = Standard_False;
+  if (aMode.IsEqual ("on"))
+  {
+    toEnable = Standard_True;
+  }
+  else if (aMode.IsEqual ("off"))
+  {
+    toEnable = Standard_False;
+  }
+  else
+  {
+    toEnable = Draw::Atoi (theArgVec[1]) != 0;
+  }
+
+  if (toEnable != aContext->ToHilightSelected())
+  {
+    aContext->SetToHilightSelected (toEnable);
+
+    // Move cursor to null position and  back to process updating of detection
+    // and highlighting of selected object immediatly.
+    Standard_Integer aPixX = 0;
+    Standard_Integer aPixY = 0;
+    const Handle(ViewerTest_EventManager)& anEventManager =  ViewerTest::CurrentEventManager();
+
+    anEventManager->GetCurrentPosition (aPixX, aPixY);
+    anEventManager->MoveTo (0, 0);
+    anEventManager->MoveTo (aPixX, aPixY);
+  }
+
+  return 0;
+}
+
+//=======================================================================
+//function : VXRotate
+//purpose  :
+//=======================================================================
+static Standard_Integer VXRotate (Draw_Interpretor& di,
+                                   Standard_Integer argc,
+                                   const char ** argv)
+{
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
+    return 1;
+  }
+  
+  if (argc != 3)
+  {
+    di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aName (argv[1]);
+  Standard_Real anAngle = Draw::Atof (argv[2]);
+
+  // find object
+  ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
+  Handle(AIS_InteractiveObject) anIObj;
+  if (!aMap.IsBound2 (aName) )
+  {
+    di << "Use 'vdisplay' before" << "\n";
+    return 1;
+  }
+  else
+  {
+    anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
+
+    gp_Trsf aTransform;
+    aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
+    aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
+
+    aContext->SetLocation (anIObj, aTransform);
+    aContext->UpdateCurrentViewer();
+  }
+
+  return 0;
+}
+
 //=======================================================================
 //function : ViewerCommands
 //purpose  :
@@ -7017,4 +7124,14 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
   theCommands.Add("vfrustumculling",
     "vfrustumculling [toEnable]: enables/disables objects clipping",
     __FILE__,VFrustumCulling,group);
+  theCommands.Add("vhighlightselected",
+    "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
+    "Without arguments it shows if highlighting of selected objects is enabled now.",
+    __FILE__,VHighlightSelected,group);
+
+
+  theCommands.Add("vxrotate",
+    "vxrotate",
+    __FILE__,VXRotate,group);
+
 }