#include <Aspect_TypeOfLine.hxx>
#include <Image_Diff.hxx>
#include <Aspect_DisplayConnection.hxx>
-#include <Graphic3d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
}
}
+//==============================================================================
+//function : RemoveView
+//purpose :
+//==============================================================================
+void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
+ const Standard_Boolean theToRemoveContext)
+{
+ if (!ViewerTest_myViews.IsBound2 (theView))
+ {
+ return;
+ }
+
+ const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
+ RemoveView (aViewName, theToRemoveContext);
+}
+
//==============================================================================
//function : RemoveView
//purpose : Close and remove view from display, clear maps if neccessary
switch (aReport.type) {
case ClientMessage:
{
- if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
+ if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
{
// Close the window
ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
if (theArgsNb == 1)
{
- aCurrentView->ZFitAll();
+ aCurrentView->View()->ZFitAll();
aCurrentView->Redraw();
return 0;
}
aScale = Draw::Atoi (theArgVec[1]);
}
- aCurrentView->ZFitAll (aScale);
+ aCurrentView->View()->ZFitAll (aScale);
aCurrentView->Redraw();
return 0;
return 0;
}
-//==============================================================================
-//function : InitViewerTest
-//purpose : initialisation de toutes les variables static de ViewerTest (dp)
-//==============================================================================
-
-void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
-{
- Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
- ViewerTest::SetAISContext(theContext);
- aViewer->InitActiveViews();
- Handle(V3d_View) aView = aViewer->ActiveView();
- if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
- ViewerTest::ResetEventManager();
- Handle(Aspect_Window) aWindow = aView->Window();
-#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
- // X11
- VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
- OSWindowSetup();
- static int aFirst = 1;
- if ( aFirst ) {
-#if TCL_MAJOR_VERSION < 8
- Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
- TK_READABLE, VProcessEvents, (ClientData) 0);
-#else
- Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
- TK_READABLE, VProcessEvents, (ClientData) 0);
-#endif
- aFirst = 0;
- }
-#endif
-}
-
//==============================================================================
//function : VSetBg
//purpose : Load image as background
return 1;
}
- V3dView->ZFitAll();
+ V3dView->View()->ZFitAll();
return 0;
}
return 1;
}
- Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
+ Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
if (theArgsNb > 3)
{
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;
}
aScale = Draw::Atoi (theArgVec[2]);
}
- aCurrentView->SetAutoZFitMode (isOn, aScale);
- aCurrentView->AutoZFit();
+ aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
+ aCurrentView->View()->AutoZFit();
aCurrentView->Redraw();
return 0;
return 1;
}
- ViewerTest::CurrentView()->AutoZFit();
+ ViewerTest::CurrentView()->View()->AutoZFit();
ViewerTest::CurrentView()->Redraw();
return 0;
return 0;
}
-//=======================================================================
-//function : VRaytrace
-//purpose : Enables/disables OpenCL-based ray-tracing
-//=======================================================================
-
-static Standard_Integer VRaytrace (Draw_Interpretor& ,
- Standard_Integer theArgNb,
- const char** theArgVec)
+inline Standard_Boolean parseOnOff (Standard_CString theArg,
+ Standard_Boolean& theIsOn)
{
- Handle(V3d_View) aView = ViewerTest::CurrentView();
- if (aView.IsNull())
+ TCollection_AsciiString aFlag (theArg);
+ aFlag.LowerCase();
+ if (aFlag == "on")
{
- std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
- return 1;
+ theIsOn = Standard_True;
+ return Standard_True;
}
-
- if (theArgNb < 2
- || Draw::Atoi (theArgVec[1]))
+ else if (aFlag == "off")
{
- aView->SetRaytracingMode();
+ theIsOn = Standard_False;
+ return Standard_True;
}
- else
- {
- aView->SetRasterizationMode();
- }
- aView->Redraw();
- return 0;
+ return Standard_False;
}
//=======================================================================
-//function : VSetRaytraceMode
-//purpose : Enables/disables features of OpenCL-based ray-tracing
+//function : VRenderParams
+//purpose : Enables/disables rendering features
//=======================================================================
-static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
- Standard_Integer theArgNb,
- const char ** theArgVec)
+static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
{
Handle(V3d_View) aView = ViewerTest::CurrentView();
if (aView.IsNull())
{
- std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
+ std::cerr << "Error: no active viewer!\n";
return 1;
}
- else if (theArgNb < 2)
+
+ Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
+
+ if (theArgNb < 2)
{
- std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
- return 1;
+ theDI << "renderMode: ";
+ switch (aParams.Method)
+ {
+ case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
+ case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
+ }
+ theDI << "\n";
+ theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
+ theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
+ theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
+ theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
+ theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
+ return 0;
}
+ Standard_Boolean toPrint = Standard_False;
for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
{
- const TCollection_AsciiString anArg (theArgVec[anArgIter]);
-
- if (anArg.Search ("shad=") > -1)
+ Standard_CString anArg (theArgVec[anArgIter]);
+ TCollection_AsciiString aFlag (anArg);
+ aFlag.LowerCase();
+ if (aFlag == "-echo"
+ || aFlag == "-print")
{
- if (anArg.Token ("=", 2).IntegerValue() != 0)
- aView->EnableRaytracedShadows();
- else
- aView->DisableRaytracedShadows();
+ toPrint = Standard_True;
}
- else if (anArg.Search ("refl=") > -1)
+ else if (aFlag == "-mode"
+ || aFlag == "-rendermode"
+ || aFlag == "-render_mode")
{
- if (anArg.Token ("=", 2).IntegerValue() != 0)
- aView->EnableRaytracedReflections();
+ if (toPrint)
+ {
+ switch (aParams.Method)
+ {
+ case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
+ case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
+ }
+ continue;
+ }
else
- aView->DisableRaytracedReflections();
+ {
+ std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+ return 1;
+ }
+ }
+ else if (aFlag == "-ray"
+ || aFlag == "-raytrace")
+ {
+ if (toPrint)
+ {
+ theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
+ continue;
+ }
+
+ aParams.Method = Graphic3d_RM_RAYTRACING;
+ }
+ else if (aFlag == "-rast"
+ || aFlag == "-raster"
+ || aFlag == "-rasterization")
+ {
+ if (toPrint)
+ {
+ theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
+ continue;
+ }
+
+ aParams.Method = Graphic3d_RM_RASTERIZATION;
}
- else if (anArg.Search ("aa=") > -1)
+ else if (aFlag == "-raydepth"
+ || aFlag == "-ray_depth")
{
- if (anArg.Token ("=", 2).IntegerValue() != 0)
- aView->EnableRaytracedAntialiasing();
+ if (toPrint)
+ {
+ theDI << aParams.RaytracingDepth << " ";
+ continue;
+ }
+ else if (++anArgIter >= theArgNb)
+ {
+ std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+ return 1;
+ }
+
+ const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
+ if (aDepth < 1 || aDepth > 10)
+ {
+ std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
+ return 1;
+ }
else
- aView->DisableRaytracedAntialiasing();
+ {
+ aParams.RaytracingDepth = aDepth;
+ }
+ }
+ else if (aFlag == "-shad"
+ || aFlag == "-shadows")
+ {
+ if (toPrint)
+ {
+ theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
+ continue;
+ }
+
+ Standard_Boolean toEnable = Standard_True;
+ if (++anArgIter < theArgNb
+ && !parseOnOff (theArgVec[anArgIter], toEnable))
+ {
+ --anArgIter;
+ }
+ aParams.IsShadowEnabled = toEnable;
+ }
+ else if (aFlag == "-refl"
+ || aFlag == "-reflections")
+ {
+ if (toPrint)
+ {
+ theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
+ continue;
+ }
+
+ Standard_Boolean toEnable = Standard_True;
+ if (++anArgIter < theArgNb
+ && !parseOnOff (theArgVec[anArgIter], toEnable))
+ {
+ --anArgIter;
+ }
+ aParams.IsReflectionEnabled = toEnable;
+ }
+ else if (aFlag == "-fsaa")
+ {
+ if (toPrint)
+ {
+ theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
+ continue;
+ }
+
+ Standard_Boolean toEnable = Standard_True;
+ if (++anArgIter < theArgNb
+ && !parseOnOff (theArgVec[anArgIter], toEnable))
+ {
+ --anArgIter;
+ }
+ aParams.IsAntialiasingEnabled = toEnable;
+ }
+ else if (aFlag == "-gleam")
+ {
+ if (toPrint)
+ {
+ theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
+ continue;
+ }
+
+ Standard_Boolean toEnable = Standard_True;
+ if (++anArgIter < theArgNb
+ && !parseOnOff (theArgVec[anArgIter], toEnable))
+ {
+ --anArgIter;
+ }
+ aParams.IsTransparentShadowEnabled = toEnable;
}
else
{
- std::cerr << "Unknown argument: " << anArg << "\n";
+ std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
+ return 1;
}
}
return 0;
}
+//=======================================================================
+//function : VFrustumCulling
+//purpose : enables/disables view volume's culling.
+//=======================================================================
+static int VFrustumCulling (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
+{
+ Handle(V3d_View) aView = ViewerTest::CurrentView();
+ if (aView.IsNull())
+ {
+ std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
+ return 1;
+ }
+
+ if (theArgNb < 2)
+ {
+ theDI << (aView->IsCullingEnabled() ? "on" : "off");
+ return 0;
+ }
+ else if (theArgNb != 2)
+ {
+ std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aModeStr (theArgVec[1]);
+ aModeStr.LowerCase();
+ Standard_Boolean toEnable = 0;
+ if (aModeStr == "on")
+ {
+ toEnable = 1;
+ }
+ else if (aModeStr == "off")
+ {
+ toEnable = 0;
+ }
+ else
+ {
+ toEnable = Draw::Atoi (theArgVec[1]) != 0;
+ }
+
+ aView->SetFrustumCulling (toEnable);
+ aView->Redraw();
+ 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 :
"\n\n example: vlight add positional head 1 pos 0 1 1 color red"
"\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
__FILE__, VLight, group);
- theCommands.Add("vraytrace",
- "vraytrace 0|1",
- __FILE__,VRaytrace,group);
- theCommands.Add("vsetraytracemode",
- "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
- __FILE__,VSetRaytraceMode,group);
+ theCommands.Add("vrenderparams",
+ "\n Manages rendering parameters: "
+ "\n '-rayTrace' Enables GPU ray-tracing"
+ "\n '-raster' Disables GPU ray-tracing"
+ "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
+ "\n '-shadows on|off' Enables/disables shadows rendering"
+ "\n '-reflections on|off' Enables/disables specular reflections"
+ "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
+ "\n '-gleam on|off' Enables/disables transparency shadow effects",
+ __FILE__, VRenderParams, group);
+ 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);
+
}