// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
-
-// Robert Boehne 30 May 2000 : Dec Osf
-
#ifdef HAVE_CONFIG_H
-# include <config.h>
+ #include <config.h>
#endif
#include <OpenGl_GlCore20.hxx>
#endif
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
#include <Cocoa_Window.hxx>
- #include <tk.h>
#else
#include <Xw_Window.hxx>
#include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
#include <tk.h>
#endif
-//==============================================================================
+// Auxiliary definitions
+static const char THE_KEY_DELETE = 127;
//==============================================================================
// VIEWER GLOBAL VARIABLES
//==============================================================================
Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
+Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
extern const Handle(NIS_InteractiveContext)& TheNISContext();
extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
+extern int VErase (Draw_Interpretor& theDI,
+ Standard_Integer theArgNb,
+ const char** theArgVec);
+
#if defined(_WIN32)
static Handle(WNT_Window)& VT_GetWindow() {
static Handle(WNT_Window) WNTWin;
(void)theDisplayName; // avoid warning on unused argument
SetDisplayConnection (new Aspect_DisplayConnection ());
#endif
- aGraphicDriver = new OpenGl_GraphicDriver();
+ aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
- aGraphicDriver->Begin (GetDisplayConnection());
ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
toCreateViewer = Standard_True;
}
}
// Create viewer
- Handle(V3d_Viewer) a3DViewer, a3DCollector;
+ Handle(V3d_Viewer) a3DViewer;
// If it's the single view, we first look for empty context
if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
{
if (anIter.More())
ViewerTest::SetAISContext (anIter.Value());
a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
- a3DCollector= ViewerTest::GetAISContext()->Collector();
}
else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
{
ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
- a3DCollector= ViewerTest::GetAISContext()->Collector();
}
- else if (a3DViewer.IsNull() || a3DCollector.IsNull())
+ else if (a3DViewer.IsNull())
{
toCreateViewer = Standard_True;
TCollection_ExtendedString NameOfWindow("Viewer3D");
a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
NameOfWindow = TCollection_ExtendedString("Collector");
- a3DCollector = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
- a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
}
// AIS context setup
!(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
{
Handle(AIS_InteractiveContext) aContext =
- new AIS_InteractiveContext(a3DViewer, a3DCollector);
+ new AIS_InteractiveContext(a3DViewer);
ViewerTest::SetAISContext (aContext);
ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
}
aView.Nullify();
a3DViewer.Nullify();
- a3DCollector.Nullify();
return aViewNames.GetViewName();
}
}
//==============================================================================
-//function : SplitParameter
-//purpose : Split parameter string to parameter name an patameter value
+//function : splitParameter
+//purpose : Split parameter string to parameter name an parameter value
//==============================================================================
-Standard_Boolean SplitParameter (const TCollection_AsciiString& theString,
- TCollection_AsciiString& theName,
- TCollection_AsciiString& theValue)
+Standard_Boolean splitParameter (const TCollection_AsciiString& theString,
+ TCollection_AsciiString& theName,
+ TCollection_AsciiString& theValue)
{
Standard_Integer aParamNameEnd = theString.FirstLocationInSet("=",1, theString.Length());
if (aParamNameEnd == 0)
for (Standard_Integer i = 1; i < theArgsNb; ++i)
{
TCollection_AsciiString aName = "", aValue = "";
- if(!SplitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
+ if(!splitParameter (TCollection_AsciiString(theArgVec[i]),aName,aValue) && theArgsNb == 2)
{
// In case of syntax: vinit ViewName
aViewName = theArgVec[1];
//purpose : Remove the view defined by its name
//==============================================================================
-static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
+static int VClose (Draw_Interpretor& /*theDi*/,
+ Standard_Integer theArgsNb,
+ const char** theArgVec)
{
- if (theArgsNb < 2)
- {
- theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
- << "Type help " << theArgVec[0] << " for more information.\n";
- return 1;
- }
-
- if (ViewerTest_myViews.IsEmpty())
- {
- theDi << theArgVec[0] <<": there is no views to close.\n";
- return 0;
- }
-
- TCollection_AsciiString anInputString(theArgVec[1]);
-
- // Create list to iterate and remove views from the map of views
NCollection_List<TCollection_AsciiString> aViewList;
- if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
+ if (theArgsNb > 1)
{
- for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
- anIter.More(); anIter.Next())
+ TCollection_AsciiString anArg (theArgVec[1]);
+ anArg.UpperCase();
+ if (anArg.IsEqual ("ALL")
+ || anArg.IsEqual ("*"))
+ {
+ for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
+ anIter.More(); anIter.Next())
+ {
+ aViewList.Append (anIter.Key1());
+ }
+ if (aViewList.IsEmpty())
+ {
+ std::cout << "No view to close\n";
+ return 0;
+ }
+ }
+ else
{
- aViewList.Append(anIter.Key1());
+ ViewerTest_Names aViewName (theArgVec[1]);
+ if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
+ {
+ std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
+ return 1;
+ }
+ aViewList.Append (aViewName.GetViewName());
}
}
else
{
- ViewerTest_Names aViewNames(anInputString);
- aViewList.Append(aViewNames.GetViewName());
+ // close active view
+ if (ViewerTest::CurrentView().IsNull())
+ {
+ std::cerr << "No active view!\n";
+ return 1;
+ }
+ aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
}
- Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
+ Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
anIter.More(); anIter.Next())
{
- ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
+ ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
}
return 0;
const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
// Letter in alphabetic order
- if ( !strcasecmp(buf_ret, "A") ) {
+ if (!strcasecmp (buf_ret, "A"))
+ {
// AXO
aView->SetProj(V3d_XposYnegZpos);
}
- else if ( !strcasecmp(buf_ret, "D") ) {
+ else if (!strcasecmp (buf_ret, "D"))
+ {
// Reset
aView->Reset();
}
- else if ( !strcasecmp(buf_ret, "F") ) {
+ else if (!strcasecmp (buf_ret, "F"))
+ {
// FitAll
if (aNisView.IsNull())
aView->FitAll();
else
aNisView->FitAll3d();
}
- else if ( !strcasecmp(buf_ret, "H") ) {
+ else if (!strcasecmp (buf_ret, "H"))
+ {
// HLR
cout << "HLR" << endl;
aView->SetComputedMode (!aView->ComputedMode());
MyHLRIsOn = aView->ComputedMode();
}
- else if ( !strcasecmp(buf_ret, "P") ) {
+ else if (!strcasecmp (buf_ret, "P"))
+ {
// Type of HLR
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
aContext->UpdateCurrentViewer();
}
- else if ( !strcasecmp(buf_ret, "S") ) {
- // SHADING
- cout << "passage en mode 1 (shading pour les shapes)" << endl;
+ else if (!strcasecmp (buf_ret, "S"))
+ {
+ std::cout << "setup Shaded display mode" << std::endl;
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
Ctx->UpdateCurrentViewer();
}
}
- else if ( !strcasecmp(buf_ret, "U") ) {
+ else if (!strcasecmp (buf_ret, "U"))
+ {
// Unset display mode
- cout<<"passage au mode par defaut"<<endl;
+ std::cout << "reset display mode to defaults" << std::endl;
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
}
}
- else if ( !strcasecmp(buf_ret, "T") ) {
+ else if (!strcasecmp (buf_ret, "T"))
+ {
// Top
aView->SetProj(V3d_Zpos);
}
- else if ( !strcasecmp(buf_ret, "B") ) {
+ else if (!strcasecmp (buf_ret, "B"))
+ {
// Bottom
aView->SetProj(V3d_Zneg);
}
- else if ( !strcasecmp(buf_ret, "L") ) {
+ else if (!strcasecmp (buf_ret, "L"))
+ {
// Left
aView->SetProj(V3d_Xneg);
}
- else if ( !strcasecmp(buf_ret, "R") ) {
+ else if (!strcasecmp (buf_ret, "R"))
+ {
// Right
aView->SetProj(V3d_Xpos);
}
-
- else if ( !strcasecmp(buf_ret, "W") ) {
- // WIREFRAME
- cout << "passage en mode 0 (filaire pour les shapes)" << endl;
+ else if (!strcasecmp (buf_ret, "W"))
+ {
+ std::cout << "setup WireFrame display mode" << std::endl;
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0)
Ctx->UpdateCurrentViewer();
}
}
- else if ( !strcasecmp(buf_ret, "Z") ) {
+ else if (!strcasecmp (buf_ret, "Z"))
+ {
// ZCLIP
-
if ( ZClipIsOn ) {
cout << "ZClipping OFF" << endl;
ZClipIsOn = 0;
aView->Redraw();
}
}
- else if ( !strcasecmp(buf_ret, ",") ) {
+ else if (!strcasecmp (buf_ret, ","))
+ {
ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
-
-
}
- else if ( !strcasecmp(buf_ret, ".") ) {
+ else if (!strcasecmp (buf_ret, "."))
+ {
ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
}
- // Number
- else{
+ else if (*buf_ret == THE_KEY_DELETE)
+ {
+ Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+ if (!aCtx.IsNull()
+ && aCtx->NbCurrents() > 0
+ && aCtx->NbSelected() > 0)
+ {
+ Draw_Interprete ("verase");
+ }
+ }
+ else
+ {
+ // Number
Standard_Integer Num = Draw::Atoi(buf_ret);
if(Num>=0 && Num<=7)
ViewerTest::StandardModeActivation(Num);
di << "W : Wireframe" << "\n";
di << "H : HidelLineRemoval" << "\n";
di << "U : Unset display mode" << "\n";
+ di << "Delete : Remove selection from viewer" << "\n";
di << "========================="<<"\n";
di << "Selection mode "<<"\n";
char c[2];
c[0] = (char) wParam;
c[1] = '\0';
+ if (wParam == VK_DELETE)
+ {
+ c[0] = THE_KEY_DELETE;
+ }
VT_ProcessKeyPress (c);
}
break;
di << " height - pixel height of the text (default=10.0)\n";
di << " font_name - name of font (default=courier)\n";
di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
- di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
+ di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
di << " background_color- R G B values used for subtitle and decal text\n";
di << "(default=255.0 255.0 255.0)\n";
return 1;
aTextType = Aspect_TODT_DEKALE;
else if (aDispStr.IsEqual ("blend"))
aTextType = Aspect_TODT_BLEND;
+ else if (aDispStr.IsEqual ("dimension"))
+ aTextType = Aspect_TODT_DIMENSION;
// subtitle color
Quantity_Parameter aSubRed = 1.0;
Standard_Integer argc,
const char ** argv)
{
- if (argc > 2)
+ if (argc > 1)
{
- di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
+ di << "Usage : " << argv[0] << "\n";
return 1;
}
- Standard_Boolean isCollectorToo = Standard_False;
- if (argc == 2)
- {
- isCollectorToo = (atoi(argv [1]) != 0);
- }
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
{
return 1;
}
aContext->CloseAllContexts(Standard_False);
- di << aContext->PurgeDisplay(isCollectorToo) << "\n";
+ di << aContext->PurgeDisplay() << "\n";
return 0;
}
return 0;
}
+//===============================================================================================
+//function : VDefaults
+//purpose :
+//===============================================================================================
+static int VDefaults (Draw_Interpretor& theDi,
+ Standard_Integer theArgsNb,
+ const char** theArgVec)
+{
+ const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+ if (aCtx.IsNull())
+ {
+ std::cerr << "No active viewer!\n";
+ return 1;
+ }
+
+ Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
+ if (theArgsNb < 2)
+ {
+ if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
+ {
+ theDi << "DeflType: relative\n"
+ << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
+ }
+ else
+ {
+ theDi << "DeflType: absolute\n"
+ << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
+ }
+ theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
+ return 0;
+ }
+
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
+ {
+ TCollection_AsciiString anArg (theArgVec[anArgIter]);
+ TCollection_AsciiString aKey, aValue;
+ if (!splitParameter (anArg, aKey, aValue)
+ || aValue.IsEmpty())
+ {
+ std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
+ return 1;
+ }
+
+ aKey.UpperCase();
+ if (aKey == "ABSDEFL"
+ || aKey == "ABSOLUTEDEFLECTION"
+ || aKey == "DEFL"
+ || aKey == "DEFLECTION")
+ {
+ aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
+ aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
+ }
+ else if (aKey == "RELDEFL"
+ || aKey == "RELATIVEDEFLECTION"
+ || aKey == "DEVCOEFF"
+ || aKey == "DEVIATIONCOEFF"
+ || aKey == "DEVIATIONCOEFFICIENT")
+ {
+ aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
+ aDefParams->SetDeviationCoefficient (aValue.RealValue());
+ }
+ else if (aKey == "ANGDEFL"
+ || aKey == "ANGULARDEFL"
+ || aKey == "ANGULARDEFLECTION")
+ {
+ // currently HLRDeviationAngle is used instead of DeviationAngle in most places
+ aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
+ }
+ else
+ {
+ std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
+ }
+ }
+
+ return 0;
+}
+
+//==============================================================================
+//function : VClInfo
+//purpose : Prints info about active OpenCL device
+//==============================================================================
+
+static Standard_Integer VClInfo (Draw_Interpretor& theDi,
+ Standard_Integer,
+ const char**)
+{
+ Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+ if (aContextAIS.IsNull())
+ {
+ std::cerr << "Call vinit before!\n";
+ return 1;
+ }
+
+ Handle(OpenGl_GraphicDriver) aDrv = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
+ Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
+ NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> anInfo;
+ if (aDrv.IsNull()
+ || aCView == NULL
+ || !aDrv->GetOpenClDeviceInfo (*aCView, anInfo))
+ {
+ theDi << "OpenCL device info is unavailable!\n";
+ return 0;
+ }
+
+ theDi << "OpenCL device info:\n";
+ for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator anIter (anInfo);
+ anIter.More(); anIter.Next())
+ {
+ theDi << anIter.Key() << ": \t" << anIter.Value() << "\n";
+ }
+ return 0;
+}
+
+//=======================================================================
+//function : VRaytrace
+//purpose : Enables/disables OpenCL-based ray-tracing
+//=======================================================================
+
+static Standard_Integer VRaytrace (Draw_Interpretor& ,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
+{
+ Handle(V3d_View) aView = ViewerTest::CurrentView();
+ if (aView.IsNull())
+ {
+ std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
+ return 1;
+ }
+
+ if (theArgNb < 2
+ || Draw::Atoi (theArgVec[1]))
+ {
+ aView->SetRaytracingMode();
+ }
+ else
+ {
+ aView->SetRasterizationMode();
+ }
+ aView->Redraw();
+ return 0;
+}
+
+//=======================================================================
+//function : VSetRaytraceMode
+//purpose : Enables/disables features of OpenCL-based ray-tracing
+//=======================================================================
+
+static Standard_Integer VSetRaytraceMode (Draw_Interpretor&,
+ Standard_Integer theArgNb,
+ const char ** theArgVec)
+{
+ Handle(V3d_View) aView = ViewerTest::CurrentView();
+ if (aView.IsNull())
+ {
+ std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n";
+ return 1;
+ }
+ else if (theArgNb < 2)
+ {
+ std::cerr << "Usage : " << theArgVec[0] << " [shad=0|1] [refl=0|1] [aa=0|1]\n";
+ return 1;
+ }
+
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+ {
+ const TCollection_AsciiString anArg (theArgVec[anArgIter]);
+
+ if (anArg.Search ("shad=") > -1)
+ {
+ if (anArg.Token ("=", 2).IntegerValue() != 0)
+ aView->EnableRaytracedShadows();
+ else
+ aView->DisableRaytracedShadows();
+ }
+ else if (anArg.Search ("refl=") > -1)
+ {
+ if (anArg.Token ("=", 2).IntegerValue() != 0)
+ aView->EnableRaytracedReflections();
+ else
+ aView->DisableRaytracedReflections();
+ }
+ else if (anArg.Search ("aa=") > -1)
+ {
+ if (anArg.Token ("=", 2).IntegerValue() != 0)
+ aView->EnableRaytracedAntialiasing();
+ else
+ aView->DisableRaytracedAntialiasing();
+ }
+ else
+ {
+ std::cerr << "Unknown argument: " << anArg << "\n";
+ }
+ }
+
+ aView->Redraw();
+ return 0;
+}
+
//=======================================================================
//function : ViewerCommands
//purpose :
"Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
__FILE__,VInit,group);
theCommands.Add("vclose" ,
- "view_id [keep_context=0|1]\n"
+ "[view_id [keep_context=0|1]]\n"
"or vclose ALL - to remove all created views\n"
" - removes view(viewer window) defined by its view_id.\n"
" - keep_context: by default 0; if 1 and the last view is deleted"
"vantialiasing 1|0",
__FILE__,VAntialiasing,group);
theCommands.Add ("vpurgedisplay",
- "vpurgedisplay [CollectorToo = 0|1]"
+ "vpurgedisplay"
"- removes structures which don't belong to objects displayed in neutral point",
__FILE__, VPurgeDisplay, group);
theCommands.Add("vsetviewsize",
" 2 - all textures enabled.\n"
" this command sets texture details mode for the specified view.\n"
, __FILE__, VSetTextureMode, group);
+ theCommands.Add("vdefaults",
+ "vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
+ __FILE__, VDefaults, group);
+ theCommands.Add("vraytrace",
+ "vraytrace 0|1",
+ __FILE__,VRaytrace,group);
+ theCommands.Add("vclinfo",
+ "vclinfo",
+ __FILE__,VClInfo,group);
+ theCommands.Add("vsetraytracemode",
+ "vsetraytracemode [shad=0|1] [refl=0|1] [aa=0|1]",
+ __FILE__,VSetRaytraceMode,group);
}