1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Robert Boehne 30 May 2000 : Dec Osf
32 #include <AIS_Shape.hxx>
33 #include <AIS_Drawer.hxx>
34 #include <AIS_InteractiveObject.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_GraphicDriver.hxx>
40 #include <Graphic3d_ExportFormat.hxx>
41 #include <Graphic3d_NameOfTextureEnv.hxx>
42 #include <Graphic3d_TextureEnv.hxx>
43 #include <Graphic3d_TextureParams.hxx>
44 #include <Graphic3d_TypeOfTextureFilter.hxx>
45 #include <ViewerTest.hxx>
46 #include <ViewerTest_EventManager.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <Visual3d_View.hxx>
49 #include <Visual3d_ViewManager.hxx>
50 #include <V3d_LayerMgr.hxx>
51 #include <NIS_View.hxx>
52 #include <NIS_Triangulated.hxx>
53 #include <NIS_InteractiveContext.hxx>
54 #include <AIS_InteractiveContext.hxx>
55 #include <Draw_Interpretor.hxx>
57 #include <Draw_Appli.hxx>
58 #include <Aspect_PrintAlgo.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <OSD_Timer.hxx>
61 #include <TColStd_SequenceOfInteger.hxx>
62 #include <TColStd_HSequenceOfReal.hxx>
63 #include <TColgp_Array1OfPnt2d.hxx>
64 #include <Visual3d_LayerItem.hxx>
65 #include <V3d_LayerMgr.hxx>
66 #include <V3d_LayerMgrPointer.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
70 #include <Graphic3d.hxx>
76 #include <Visual3d_Layer.hxx>
79 #if defined(_WIN32) || defined(__WIN32__)
80 #include <WNT_WClass.hxx>
81 #include <WNT_Window.hxx>
84 #define _CRT_SECURE_NO_DEPRECATE
85 #pragma warning (disable:4996)
87 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
88 #include <Cocoa_Window.hxx>
91 #include <Xw_Window.hxx>
92 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
93 #include <X11/Xutil.h>
97 //==============================================================================
99 //==============================================================================
100 // VIEWER GLOBAL VARIABLES
101 //==============================================================================
103 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
105 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
106 extern const Handle(NIS_InteractiveContext)& TheNISContext();
107 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
109 #if defined(_WIN32) || defined(__WIN32__)
110 static Handle(WNT_Window)& VT_GetWindow() {
111 static Handle(WNT_Window) WNTWin;
114 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
115 static Handle(Cocoa_Window)& VT_GetWindow()
117 static Handle(Cocoa_Window) aWindow;
120 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
122 static Handle(Xw_Window)& VT_GetWindow(){
123 static Handle(Xw_Window) XWWin;
126 static Display *display;
128 static void VProcessEvents(ClientData,int);
131 static Handle(Graphic3d_GraphicDriver)& GetGraphicDriver()
133 static Handle(Graphic3d_GraphicDriver) aGraphicDriver;
134 return aGraphicDriver;
137 static Standard_Boolean MyHLRIsOn = Standard_False;
139 #define ZCLIPWIDTH 1.
141 static void OSWindowSetup();
143 //==============================================================================
144 // EVENT GLOBAL VARIABLES
145 //==============================================================================
147 static int Start_Rot = 0;
148 static int ZClipIsOn = 0;
149 int X_Motion = 0; // Current cursor position
151 int X_ButtonPress = 0; // Last ButtonPress position
152 int Y_ButtonPress = 0;
153 Standard_Boolean IsDragged = Standard_False;
154 Standard_Boolean DragFirst;
156 //==============================================================================
159 static LRESULT WINAPI ViewerWindowProc(
164 static LRESULT WINAPI AdvViewerWindowProc(
172 //==============================================================================
175 //==============================================================================
177 const Handle(MMgt_TShared)& ViewerTest::WClass()
179 static Handle(MMgt_TShared) theWClass;
180 #if defined(_WIN32) || defined(__WIN32__)
181 if (theWClass.IsNull())
183 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
184 CS_VREDRAW | CS_HREDRAW, 0, 0,
185 ::LoadCursor (NULL, IDC_ARROW));
191 //==============================================================================
192 //function : ViewerInit
193 //purpose : Create the window viewer and initialize all the global variable
194 //==============================================================================
196 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
197 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
199 static Standard_Boolean isFirst = Standard_True;
201 // Default position and dimension of the viewer window.
202 // Note that left top corner is set to be sufficiently small to have
203 // window fit in the small screens (actual for remote desktops, see #23003).
204 // The position corresponds to the window's client area, thus some
205 // gap is added for window frame to be visible.
206 Standard_Integer aPxLeft = 20;
207 Standard_Integer aPxTop = 40;
208 Standard_Integer aPxWidth = 409;
209 Standard_Integer aPxHeight = 409;
210 if (thePxWidth != 0 && thePxHeight != 0)
214 aPxWidth = thePxWidth;
215 aPxHeight = thePxHeight;
220 Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
221 if (GetGraphicDriver().IsNull())
223 GetGraphicDriver() = Graphic3d::InitGraphicDriver (aDisplayConnection);
225 #if defined(_WIN32) || defined(__WIN32__)
226 if (VT_GetWindow().IsNull())
228 VT_GetWindow() = new WNT_Window ("Test3d",
229 Handle(WNT_WClass)::DownCast (WClass()),
235 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
236 if (VT_GetWindow().IsNull())
238 VT_GetWindow() = new Cocoa_Window ("Test3d",
240 aPxWidth, aPxHeight);
241 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
244 if (VT_GetWindow().IsNull())
246 VT_GetWindow() = new Xw_Window (aDisplayConnection,
249 aPxWidth, aPxHeight);
252 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
254 Handle(V3d_Viewer) a3DViewer, a3DCollector;
255 // Viewer and View creation
257 TCollection_ExtendedString NameOfWindow("Visu3D");
259 a3DViewer = new V3d_Viewer(GetGraphicDriver(), NameOfWindow.ToExtString());
260 NameOfWindow = TCollection_ExtendedString("Collector");
261 a3DCollector = new V3d_Viewer(GetGraphicDriver(), NameOfWindow.ToExtString());
262 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
263 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
264 Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
267 //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
268 aView = new NIS_View (a3DViewer, VT_GetWindow());
269 ViewerTest::CurrentView(aView);
270 TheNISContext()->AttachView (aView);
274 if ( ViewerTest::GetAISContext().IsNull() ) {
275 Handle(AIS_InteractiveContext) C =
276 new AIS_InteractiveContext(a3DViewer,a3DCollector);
277 ViewerTest::SetAISContext(C);
280 // Setup for X11 or NT
282 // Viewer and View creation
284 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
286 Handle (V3d_View) V = ViewerTest::CurrentView();
287 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
289 V->SetZClippingDepth(0.5);
290 V->SetZClippingWidth(ZCLIPWIDTH/2.);
291 a3DViewer->SetDefaultLights();
292 a3DViewer->SetLightOn();
294 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
295 #if TCL_MAJOR_VERSION < 8
296 Tk_CreateFileHandler((void*)ConnectionNumber(display),
297 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
299 Tk_CreateFileHandler(ConnectionNumber(display),
300 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
304 isFirst = Standard_False;
307 VT_GetWindow()->Map();
308 ViewerTest::CurrentView()->Redraw();
311 //==============================================================================
313 //purpose : Create the window viewer and initialize all the global variable
314 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
315 //==============================================================================
317 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
319 Standard_Integer aPxLeft = (argc > 1) ? Draw::Atoi (argv[1]) : 0;
320 Standard_Integer aPxTop = (argc > 2) ? Draw::Atoi (argv[2]) : 0;
321 Standard_Integer aPxWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
322 Standard_Integer aPxHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
323 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
327 //==============================================================================
329 //purpose : hidden lines removal algorithm
330 //==============================================================================
332 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
334 if (ViewerTest::CurrentView().IsNull())
336 di << argv[0] << ": Call vinit before this command, please.\n";
342 di << argv[0] << ": Wrong number of command arguments.\n"
343 << "Type help " << argv[0] << " for more information.\n";
347 Standard_Boolean isHLROn =
348 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
350 if (isHLROn == MyHLRIsOn)
356 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
361 //==============================================================================
362 //function : VHLRType
363 //purpose : change type of using HLR algorithm
364 //==============================================================================
366 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
368 if (ViewerTest::CurrentView().IsNull())
370 di << argv[0] << ": Call vinit before this command, please.\n";
376 di << argv[0] << ": Wrong number of command arguments.\n"
377 << "Type help " << argv[0] << " for more information.\n";
381 Prs3d_TypeOfHLR aTypeOfHLR =
382 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
386 AIS_ListOfInteractive aListOfShapes;
387 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
388 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
389 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
390 anIter.More(); anIter.Next())
392 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
395 if (aShape->TypeOfHLR() != aTypeOfHLR)
396 aShape->SetTypeOfHLR (aTypeOfHLR);
400 ViewerTest::CurrentView()->Update();
405 for (Standard_Integer i = 2; i < argc; ++i)
407 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
408 TCollection_AsciiString aName (argv[i]);
410 if (!aMap.IsBound2 (aName))
412 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
415 Handle(AIS_Shape) anAISObject =
416 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
417 if (anAISObject.IsNull())
419 anAISObject->SetTypeOfHLR (aTypeOfHLR);
421 anAISObject->Redisplay();
423 ViewerTest::CurrentView()->Update();
429 //==============================================================================
430 //function : VT_ProcessKeyPress
431 //purpose : Handle KeyPress event from a CString
432 //==============================================================================
433 void VT_ProcessKeyPress (const char* buf_ret)
435 //cout << "KeyPress" << endl;
436 const Handle(V3d_View) aView = ViewerTest::CurrentView();
437 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
438 // Letter in alphabetic order
440 if ( !strcasecmp(buf_ret, "A") ) {
442 aView->SetProj(V3d_XposYnegZpos);
444 else if ( !strcasecmp(buf_ret, "D") ) {
448 else if ( !strcasecmp(buf_ret, "F") ) {
450 if (aNisView.IsNull())
453 aNisView->FitAll3d();
455 else if ( !strcasecmp(buf_ret, "H") ) {
457 cout << "HLR" << endl;
458 aView->SetComputedMode (!aView->ComputedMode());
459 MyHLRIsOn = aView->ComputedMode();
461 else if ( !strcasecmp(buf_ret, "P") ) {
463 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
464 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
465 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
467 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
468 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
470 AIS_ListOfInteractive aListOfShapes;
471 aContext->DisplayedObjects(aListOfShapes);
472 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
473 anIter.More(); anIter.Next())
475 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
478 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
479 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
481 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
487 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
489 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
492 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
493 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
495 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
500 aContext->UpdateCurrentViewer();
503 else if ( !strcasecmp(buf_ret, "S") ) {
505 cout << "passage en mode 1 (shading pour les shapes)" << endl;
507 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
508 if(Ctx->NbCurrents()==0 ||
509 Ctx->NbSelected()==0)
510 Ctx->SetDisplayMode(AIS_Shaded);
512 if(Ctx->HasOpenedContext()){
513 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
514 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
517 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
518 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
520 Ctx->UpdateCurrentViewer();
523 else if ( !strcasecmp(buf_ret, "U") ) {
524 // Unset display mode
525 cout<<"passage au mode par defaut"<<endl;
527 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
528 if(Ctx->NbCurrents()==0 ||
529 Ctx->NbSelected()==0)
530 Ctx->SetDisplayMode(AIS_WireFrame);
532 if(Ctx->HasOpenedContext()){
533 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
534 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
537 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
538 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
540 Ctx->UpdateCurrentViewer();
544 else if ( !strcasecmp(buf_ret, "T") ) {
546 aView->SetProj(V3d_Zpos);
548 else if ( !strcasecmp(buf_ret, "B") ) {
550 aView->SetProj(V3d_Zneg);
552 else if ( !strcasecmp(buf_ret, "L") ) {
554 aView->SetProj(V3d_Xneg);
556 else if ( !strcasecmp(buf_ret, "R") ) {
558 aView->SetProj(V3d_Xpos);
561 else if ( !strcasecmp(buf_ret, "W") ) {
563 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
564 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
565 if(Ctx->NbCurrents()==0 ||
566 Ctx->NbSelected()==0)
567 Ctx->SetDisplayMode(AIS_WireFrame);
569 if(Ctx->HasOpenedContext()){
570 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
571 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
574 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
575 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
577 Ctx->UpdateCurrentViewer();
580 else if ( !strcasecmp(buf_ret, "Z") ) {
584 cout << "ZClipping OFF" << endl;
587 aView->SetZClippingType(V3d_OFF);
591 cout << "ZClipping ON" << endl;
594 aView->SetZClippingType(V3d_FRONT);
598 else if ( !strcasecmp(buf_ret, ",") ) {
599 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
603 else if ( !strcasecmp(buf_ret, ".") ) {
604 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
608 Standard_Integer Num = Draw::Atoi(buf_ret);
610 ViewerTest::StandardModeActivation(Num);
614 //==============================================================================
615 //function : VT_ProcessExpose
616 //purpose : Redraw the View on an Expose Event
617 //==============================================================================
618 void VT_ProcessExpose()
620 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
621 if (!aView3d.IsNull())
627 //==============================================================================
628 //function : VT_ProcessConfigure
629 //purpose : Resize the View on an Configure Event
630 //==============================================================================
631 void VT_ProcessConfigure()
633 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
634 if (aView3d.IsNull())
639 aView3d->MustBeResized();
644 //==============================================================================
645 //function : VT_ProcessButton1Press
647 //==============================================================================
648 Standard_Boolean VT_ProcessButton1Press(
651 Standard_Boolean pick,
652 Standard_Boolean shift)
654 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
656 Standard_Real X, Y, Z;
658 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
660 Draw::Set(argv[1], X);
661 Draw::Set(argv[2], Y);
662 Draw::Set(argv[3], Z);}
673 //==============================================================================
674 //function : VT_ProcessButton1Release
675 //purpose : End selecting
676 //==============================================================================
677 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
681 IsDragged = Standard_False;
682 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
685 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
686 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
690 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
691 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
696 //==============================================================================
697 //function : VT_ProcessButton3Press
698 //purpose : Start Rotation
699 //==============================================================================
700 void VT_ProcessButton3Press()
705 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
707 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
710 //==============================================================================
711 //function : VT_ProcessButton3Release
712 //purpose : End rotation
713 //==============================================================================
714 void VT_ProcessButton3Release()
721 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
726 //==============================================================================
727 //function : ProcessZClipMotion
729 //==============================================================================
731 void ProcessZClipMotion()
733 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
734 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
735 static Standard_Real CurZPos = 0.;
737 //Quantity_Length VDX, VDY;
738 //a3DView->Size(VDX,VDY);
739 //Standard_Real VDZ = a3DView->ZSize();
740 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
742 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
744 // Front = Depth + width/2.
745 Standard_Real D = 0.5;
746 Standard_Real W = 0.1;
752 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
754 a3DView->SetZClippingType(V3d_OFF);
755 a3DView->SetZClippingDepth(D);
756 a3DView->SetZClippingWidth(W);
757 a3DView->SetZClippingType(V3d_FRONT);
761 X_ButtonPress = X_Motion;
762 Y_ButtonPress = Y_Motion;
766 //==============================================================================
767 //function : ProcessControlButton1Motion
769 //==============================================================================
771 static void ProcessControlButton1Motion()
773 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
775 X_ButtonPress = X_Motion;
776 Y_ButtonPress = Y_Motion;
779 //==============================================================================
780 //function : VT_ProcessControlButton2Motion
782 //==============================================================================
783 void VT_ProcessControlButton2Motion()
785 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
786 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
788 dy = -dy; // Xwindow Y axis is from top to Bottom
790 ViewerTest::CurrentView()->Panning( dx, dy );
792 X_ButtonPress = X_Motion;
793 Y_ButtonPress = Y_Motion;
796 //==============================================================================
797 //function : VT_ProcessControlButton3Motion
799 //==============================================================================
800 void VT_ProcessControlButton3Motion()
804 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
808 //==============================================================================
809 //function : VT_ProcessMotion
811 //==============================================================================
812 void VT_ProcessMotion()
814 //pre-hilights detected objects at mouse position
816 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
817 EM->MoveTo(X_Motion, Y_Motion);
821 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
823 Xpix = X_Motion;Ypix=Y_Motion;
826 //==============================================================================
827 //function : ViewProject: implements VAxo, VTop, VLeft, ...
828 //purpose : Switches to an axonometric, top, left and other views
829 //==============================================================================
831 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
833 if ( ViewerTest::CurrentView().IsNull() )
835 di<<"Call vinit before this command, please"<<"\n";
839 ViewerTest::CurrentView()->SetProj(ori);
843 //==============================================================================
845 //purpose : Switch to an Axonometric view
847 //==============================================================================
849 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
851 return ViewProject(di, V3d_XposYnegZpos);
854 //==============================================================================
856 //purpose : Switch to a Top View
858 //==============================================================================
860 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
862 return ViewProject(di, V3d_Zpos);
865 //==============================================================================
867 //purpose : Switch to a Bottom View
869 //==============================================================================
871 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
873 return ViewProject(di, V3d_Zneg);
876 //==============================================================================
878 //purpose : Switch to a Left View
880 //==============================================================================
882 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
884 return ViewProject(di, V3d_Ypos);
887 //==============================================================================
889 //purpose : Switch to a Right View
891 //==============================================================================
893 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
895 return ViewProject(di, V3d_Yneg);
898 //==============================================================================
900 //purpose : Switch to a Front View
902 //==============================================================================
904 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
906 return ViewProject(di, V3d_Xpos);
909 //==============================================================================
911 //purpose : Switch to a Back View
913 //==============================================================================
915 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
917 return ViewProject(di, V3d_Xneg);
920 //==============================================================================
922 //purpose : Dsiplay help on viewer Keyboead and mouse commands
924 //==============================================================================
926 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
929 di << "Q : Quit the application" << "\n";
931 di << "========================="<<"\n";
932 di << "F : FitAll" << "\n";
933 di << "T : TopView" << "\n";
934 di << "B : BottomView" << "\n";
935 di << "R : RightView" << "\n";
936 di << "L : LeftView" << "\n";
937 di << "A : AxonometricView" << "\n";
938 di << "D : ResetView" << "\n";
940 di << "========================="<<"\n";
941 di << "S : Shading" << "\n";
942 di << "W : Wireframe" << "\n";
943 di << "H : HidelLineRemoval" << "\n";
944 di << "U : Unset display mode" << "\n";
946 di << "========================="<<"\n";
947 di << "Selection mode "<<"\n";
948 di << "0 : Shape" <<"\n";
949 di << "1 : Vertex" <<"\n";
950 di << "2 : Edge" <<"\n";
951 di << "3 : Wire" <<"\n";
952 di << "4 : Face" <<"\n";
953 di << "5 : Shell" <<"\n";
954 di << "6 : Solid" <<"\n";
955 di << "7 : Compound" <<"\n";
957 di << "========================="<<"\n";
958 di << "Z : Switch Z clipping On/Off" << "\n";
959 di << ", : Hilight next detected" << "\n";
960 di << ". : Hilight previous detected" << "\n";
967 static Standard_Boolean Ppick = 0;
968 static Standard_Integer Pargc = 0;
969 static const char** Pargv = NULL;
972 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
977 if ( !ViewerTest::CurrentView().IsNull() ) {
979 WPARAM fwKeys = wParam;
984 IsDragged = Standard_False;
987 HDC hdc = GetDC( hwnd );
988 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
989 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
990 SetROP2( hdc, R2_NOT );
991 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
992 ReleaseDC( hwnd, hdc );
994 const Handle(ViewerTest_EventManager) EM =
995 ViewerTest::CurrentEventManager();
996 if ( fwKeys & MK_SHIFT )
997 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
998 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1000 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1001 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1003 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1005 case WM_LBUTTONDOWN:
1006 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1008 IsDragged = Standard_True;
1009 DragFirst = Standard_True;
1010 X_ButtonPress = LOWORD(lParam);
1011 Y_ButtonPress = HIWORD(lParam);
1013 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1020 HDC hdc = GetDC( hwnd );
1022 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1023 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1024 SetROP2( hdc, R2_NOT );
1027 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1029 DragFirst = Standard_False;
1030 X_Motion = LOWORD(lParam);
1031 Y_Motion = HIWORD(lParam);
1033 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1035 SelectObject( hdc, anObj );
1037 ReleaseDC( hwnd, hdc );
1040 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1044 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1048 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1052 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1057 /*static Standard_Boolean Ppick = 0;
1058 static Standard_Integer Pargc = 0;
1059 static char** Pargv = NULL;*/
1063 if ( !ViewerTest::CurrentView().IsNull() ) {
1068 // do not destroy the window - just hide it!
1069 VT_GetWindow()->Unmap();
1072 BeginPaint(hwnd, &ps);
1073 EndPaint(hwnd, &ps);
1078 VT_ProcessConfigure();
1082 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1085 c[0] = (char) wParam;
1087 VT_ProcessKeyPress (c);
1095 VT_ProcessButton3Release();
1098 case WM_LBUTTONDOWN:
1099 case WM_MBUTTONDOWN:
1100 case WM_RBUTTONDOWN:
1102 WPARAM fwKeys = wParam;
1106 X_ButtonPress = LOWORD(lParam);
1107 Y_ButtonPress = HIWORD(lParam);
1109 if (Msg == WM_LBUTTONDOWN)
1111 if (fwKeys & MK_CONTROL)
1113 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1117 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1120 else if (Msg == WM_RBUTTONDOWN)
1123 VT_ProcessButton3Press();
1130 //cout << "\t WM_MOUSEMOVE" << endl;
1131 WPARAM fwKeys = wParam;
1132 X_Motion = LOWORD(lParam);
1133 Y_Motion = HIWORD(lParam);
1136 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1138 X_ButtonPress = LOWORD(lParam);
1139 Y_ButtonPress = HIWORD(lParam);
1141 if ( fwKeys & MK_RBUTTON ) {
1143 VT_ProcessButton3Press();
1147 if ( fwKeys & MK_CONTROL ) {
1148 if ( fwKeys & MK_LBUTTON ) {
1149 ProcessControlButton1Motion();
1151 else if ( fwKeys & MK_MBUTTON ||
1152 ((fwKeys&MK_LBUTTON) &&
1153 (fwKeys&MK_RBUTTON) ) ){
1154 VT_ProcessControlButton2Motion();
1156 else if ( fwKeys & MK_RBUTTON ) {
1157 VT_ProcessControlButton3Motion();
1161 else if ( fwKeys & MK_SHIFT ) {
1162 if ( fwKeys & MK_MBUTTON ||
1163 ((fwKeys&MK_LBUTTON) &&
1164 (fwKeys&MK_RBUTTON) ) ) {
1165 cout << "ProcessZClipMotion()" << endl;
1166 ProcessZClipMotion();
1171 if ((fwKeys & MK_MBUTTON
1172 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1174 ProcessZClipMotion();
1184 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1189 return DefWindowProc( hwnd, Msg, wParam, lParam );
1195 //==============================================================================
1196 //function : ViewerMainLoop
1197 //purpose : Get a Event on the view and dispatch it
1198 //==============================================================================
1201 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1204 //cout << "No yet implemented on WNT" << endl;
1205 /*static Standard_Boolean Ppick = 0;
1206 static Standard_Integer Pargc = 0;
1207 static char** Pargv = NULL;*/
1209 //Ppick = (argc > 0)? -1 : 0;
1210 Ppick = (argc > 0)? 1 : 0;
1218 cout << "Start picking" << endl;
1220 //while ( Ppick == -1 ) {
1221 while ( Ppick == 1 ) {
1222 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
1223 if (GetMessage(&msg, NULL, 0, 0) ) {
1224 TranslateMessage(&msg);
1225 DispatchMessage(&msg);
1229 cout << "Picking done" << endl;
1235 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
1237 int min( int a, int b )
1245 int max( int a, int b )
1253 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1255 { Standard_Boolean pick = argc > 0;
1259 static XEvent report;
1261 XNextEvent( display, &report );
1262 // cout << "rep type = " << report.type << endl;
1263 // cout << "rep button = " << report.xbutton.button << endl;
1265 switch ( report.type ) {
1271 case ConfigureNotify:
1273 VT_ProcessConfigure();
1282 XComposeStatus status_in_out;
1284 ret_len = XLookupString( ( XKeyEvent *)&report ,
1285 (char *) buf_ret , 10 ,
1286 &ks_ret , &status_in_out ) ;
1289 buf_ret[ret_len] = '\0' ;
1293 VT_ProcessKeyPress (buf_ret);
1298 // cout << "ButtonPress" << endl;
1300 X_ButtonPress = report.xbutton.x;
1301 Y_ButtonPress = report.xbutton.y;
1303 if (report.xbutton.button == Button1)
1305 if (report.xbutton.state & ControlMask)
1307 pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
1311 IsDragged = Standard_True;
1312 DragFirst = Standard_True;
1315 else if (report.xbutton.button == Button3)
1318 VT_ProcessButton3Press();
1324 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1325 // cout << IsDragged << endl;
1326 // cout << DragFirst << endl;
1332 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1333 GC gc = XCreateGC( display, aWindow, 0, 0 );
1334 // XSetFunction( display, gc, GXinvert );
1335 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1338 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1339 if( aContext.IsNull() )
1341 cout << "The context is null. Please use vinit before createmesh" << endl;
1345 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1346 if( report.xbutton.button==1 )
1350 aContext->ShiftSelect();
1351 // cout << "shift select" << endl;
1356 // cout << "select" << endl;
1361 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1362 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1363 ViewerTest::CurrentView());
1364 // cout << "shift select" << endl;
1368 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1369 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1370 ViewerTest::CurrentView() );
1371 // cout << "select" << endl;
1374 VT_ProcessButton3Release();
1376 IsDragged = Standard_False;
1379 VT_ProcessButton3Release();
1386 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1387 GC gc = XCreateGC( display, aWindow, 0, 0 );
1388 XSetFunction( display, gc, GXinvert );
1391 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1393 X_Motion = report.xmotion.x;
1394 Y_Motion = report.xmotion.y;
1395 DragFirst = Standard_False;
1397 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1401 X_Motion = report.xmotion.x;
1402 Y_Motion = report.xmotion.y;
1404 // remove all the ButtonMotionMask
1405 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1407 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1408 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1410 Quantity_Length VDX, VDY;
1412 ViewerTest::CurrentView()->Size(VDX,VDY);
1413 Standard_Real VDZ =0 ;
1414 VDZ = ViewerTest::CurrentView()->ZSize();
1416 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1417 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1419 Quantity_Length dx = 0 ;
1420 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1424 dx = dx / VDX * VDZ;
1428 // Front = Depth + width/2.
1429 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1430 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1432 ViewerTest::CurrentView()->Redraw();
1436 if ( report.xmotion.state & ControlMask ) {
1437 if ( report.xmotion.state & Button1Mask ) {
1438 ProcessControlButton1Motion();
1440 else if ( report.xmotion.state & Button2Mask ) {
1441 VT_ProcessControlButton2Motion();
1443 else if ( report.xmotion.state & Button3Mask ) {
1444 VT_ProcessControlButton3Motion();
1460 //==============================================================================
1461 //function : VProcessEvents
1462 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1463 // event in the Viewer window
1464 //==============================================================================
1466 static void VProcessEvents(ClientData,int)
1468 //cout << "VProcessEvents" << endl;
1471 while (XPending(display)) {
1472 ViewerMainLoop( 0, NULL);
1477 //==============================================================================
1478 //function : OSWindowSetup
1479 //purpose : Setup for the X11 window to be able to cath the event
1480 //==============================================================================
1483 static void OSWindowSetup()
1485 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1488 Window window = VT_GetWindow()->XWindow();
1490 display = GetGraphicDriver()->GetDisplayConnection()->GetDisplay();
1491 // display = (Display *)GetG3dDevice()->XDisplay();
1493 XSynchronize(display, 1);
1495 VT_GetWindow()->Map();
1497 // X11 : For keyboard on SUN
1499 wmhints.flags = InputHint;
1502 XSetWMHints( display, window, &wmhints);
1504 XSelectInput( display, window, ExposureMask | KeyPressMask |
1505 ButtonPressMask | ButtonReleaseMask |
1506 StructureNotifyMask |
1508 Button1MotionMask | Button2MotionMask |
1512 XSynchronize(display, 0);
1521 //==============================================================================
1524 //purpose : Fitall, no DRAW arguments
1525 //Draw arg : No args
1526 //==============================================================================
1528 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1530 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1531 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1532 if (V.IsNull() == Standard_False) {
1534 } else if (aView.IsNull() == Standard_False) {
1540 //==============================================================================
1542 //purpose : ZFitall, no DRAW arguments
1543 //Draw arg : No args
1544 //==============================================================================
1546 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1548 Handle(V3d_View) V = ViewerTest::CurrentView();
1549 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1552 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1554 Handle(V3d_View) V = ViewerTest::CurrentView();
1555 if ( !V.IsNull() ) V->Redraw(); return 0;
1559 //==============================================================================
1561 //purpose : Remove all the object from the viewer
1562 //Draw arg : No args
1563 //==============================================================================
1565 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1567 Handle(V3d_View) V = ViewerTest::CurrentView();
1569 ViewerTest::Clear();
1573 //==============================================================================
1576 //==============================================================================
1578 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1579 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1582 di << argv[0] << "Invalid number of arguments" << "\n";
1586 while (ViewerMainLoop( argc, argv)) {
1592 //==============================================================================
1593 //function : InitViewerTest
1594 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1595 //==============================================================================
1597 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1599 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1600 ViewerTest::SetAISContext(context);
1601 viewer->InitActiveViews();
1602 Handle(V3d_View) view = viewer->ActiveView();
1603 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1604 ViewerTest::ResetEventManager();
1605 Handle(Aspect_Window) window = view->Window();
1606 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1608 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1609 GetGraphicDriver() = viewer->Driver();
1611 static int first = 1;
1613 #if TCL_MAJOR_VERSION < 8
1614 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1615 TK_READABLE, VProcessEvents, (ClientData) 0);
1617 Tk_CreateFileHandler(ConnectionNumber(display),
1618 TK_READABLE, VProcessEvents, (ClientData) 0);
1625 //==============================================================================
1627 //purpose : Load image as background
1628 //==============================================================================
1630 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1632 if (argc < 2 || argc > 3)
1634 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1635 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1639 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1640 if(AISContext.IsNull())
1642 di << "use 'vinit' command before " << argv[0] << "\n";
1646 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1649 const char* szType = argv[2];
1650 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1651 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1652 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1653 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1656 di << "Wrong fill type : " << szType << "\n";
1657 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1662 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1663 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1668 //==============================================================================
1669 //function : VSetBgMode
1670 //purpose : Change background image fill type
1671 //==============================================================================
1673 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1677 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1678 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1682 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1683 if(AISContext.IsNull())
1685 di << "use 'vinit' command before " << argv[0] << "\n";
1689 Aspect_FillMethod aFillType;
1692 const char* szType = argv[1];
1693 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1694 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1695 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1696 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1699 di << "Wrong fill type : " << szType << "\n";
1700 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1705 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1706 V3dView->SetBgImageStyle(aFillType, Standard_True);
1711 //==============================================================================
1712 //function : VSetGradientBg
1713 //purpose : Mount gradient background
1714 //==============================================================================
1715 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1719 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1720 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1721 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1722 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1726 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1727 if(AISContext.IsNull())
1729 di << "use 'vinit' command before " << argv[0] << "\n";
1735 Standard_Real R1 = Draw::Atof(argv[1])/255.;
1736 Standard_Real G1 = Draw::Atof(argv[2])/255.;
1737 Standard_Real B1 = Draw::Atof(argv[3])/255.;
1738 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1740 Standard_Real R2 = Draw::Atof(argv[4])/255.;
1741 Standard_Real G2 = Draw::Atof(argv[5])/255.;
1742 Standard_Real B2 = Draw::Atof(argv[6])/255.;
1744 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1745 int aType = Draw::Atoi(argv[7]);
1746 if( aType < 0 || aType > 8 )
1748 di << "Wrong fill type " << "\n";
1749 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1750 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1754 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1756 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1757 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1763 //==============================================================================
1764 //function : VSetGradientBgMode
1765 //purpose : Change gradient background fill style
1766 //==============================================================================
1767 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1771 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1772 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1773 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1777 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1778 if(AISContext.IsNull())
1780 di << "use 'vinit' command before " << argv[0] << "\n";
1785 int aType = Draw::Atoi(argv[1]);
1786 if( aType < 0 || aType > 8 )
1788 di << "Wrong fill type " << "\n";
1789 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1790 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1794 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1796 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1797 V3dView->SetBgGradientStyle( aMethod, 1 );
1803 //==============================================================================
1804 //function : VSetColorBg
1805 //purpose : Set color background
1806 //==============================================================================
1807 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1811 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1812 di << "R,G,B = [0..255]" << "\n";
1816 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1817 if(AISContext.IsNull())
1819 di << "use 'vinit' command before " << argv[0] << "\n";
1825 Standard_Real R = Draw::Atof(argv[1])/255.;
1826 Standard_Real G = Draw::Atof(argv[2])/255.;
1827 Standard_Real B = Draw::Atof(argv[3])/255.;
1828 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1830 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1831 V3dView->SetBackgroundColor( aColor );
1838 //==============================================================================
1840 //purpose : View Scaling
1841 //==============================================================================
1843 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1845 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1846 if ( V3dView.IsNull() ) return 1;
1849 di << argv[0] << "Invalid number of arguments" << "\n";
1852 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1855 //==============================================================================
1856 //function : VTestZBuffTrihedron
1857 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1858 //==============================================================================
1860 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1862 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1863 if ( V3dView.IsNull() ) return 1;
1865 V3dView->ZBufferTriedronSetup();
1868 // Set up default trihedron parameters
1869 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1873 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1874 const char* aPosType = argv[1];
1876 if ( strcmp(aPosType, "center") == 0 )
1878 aPosition = Aspect_TOTP_CENTER;
1880 if (strcmp(aPosType, "left_lower") == 0)
1882 aPosition = Aspect_TOTP_LEFT_LOWER;
1884 if (strcmp(aPosType, "left_upper") == 0)
1886 aPosition = Aspect_TOTP_LEFT_UPPER;
1888 if (strcmp(aPosType, "right_lower") == 0)
1890 aPosition = Aspect_TOTP_RIGHT_LOWER;
1892 if (strcmp(aPosType, "right_upper") == 0)
1894 aPosition = Aspect_TOTP_RIGHT_UPPER;
1897 di << argv[1] << " Invalid type of alignment" << "\n";
1898 di << "Must be one of [ center, left_lower," << "\n";
1899 di << "left_upper, right_lower, right_upper ]" << "\n";
1903 Standard_Real R = Draw::Atof(argv[2])/255.;
1904 Standard_Real G = Draw::Atof(argv[3])/255.;
1905 Standard_Real B = Draw::Atof(argv[4])/255.;
1906 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1908 Standard_Real aScale = Draw::Atof(argv[5]);
1912 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1916 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1917 const char* aPresType = argv[6];
1919 if ( strcmp(aPresType, "wireframe") == 0 )
1921 aPresentation = V3d_WIREFRAME;
1923 if (strcmp(aPresType, "zbuffer") == 0)
1925 aPresentation = V3d_ZBUFFER;
1928 di << argv[6] << " Invalid type of visualization" << "\n";
1929 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1933 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1937 di << argv[0] << " Invalid number of arguments" << "\n";
1946 //==============================================================================
1947 //function : VRotate
1948 //purpose : Camera Rotating
1949 //==============================================================================
1951 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1952 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1953 if ( V3dView.IsNull() ) {
1958 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1960 } else if ( argc == 7 ) {
1961 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
1964 di << argv[0] << " Invalid number of arguments" << "\n";
1969 //==============================================================================
1971 //purpose : View zoom in / out (relative to current zoom)
1972 //==============================================================================
1974 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1975 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1976 if ( V3dView.IsNull() ) {
1981 Standard_Real coef = Draw::Atof(argv[1]);
1982 if ( coef <= 0.0 ) {
1983 di << argv[1] << "Invalid value" << "\n";
1986 V3dView->SetZoom( Draw::Atof(argv[1]) );
1989 di << argv[0] << " Invalid number of arguments" << "\n";
1994 //==============================================================================
1996 //purpose : View panning (in pixels)
1997 //==============================================================================
1999 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2000 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2001 if ( V3dView.IsNull() ) return 1;
2004 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2007 di << argv[0] << " Invalid number of arguments" << "\n";
2013 //==============================================================================
2014 //function : VExport
2015 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2016 //==============================================================================
2018 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2020 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2021 if (V3dView.IsNull())
2026 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2030 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2031 TCollection_AsciiString aFormatStr;
2033 TCollection_AsciiString aFileName (argv[1]);
2034 Standard_Integer aLen = aFileName.Length();
2038 aFormatStr = TCollection_AsciiString (argv[2]);
2042 if (aFileName.Value (aLen - 2) == '.')
2044 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2046 else if (aFileName.Value (aLen - 3) == '.')
2048 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2052 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2058 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2062 aFormatStr.UpperCase();
2063 if (aFormatStr == "PS")
2064 anExpFormat = Graphic3d_EF_PostScript;
2065 else if (aFormatStr == "EPS")
2066 anExpFormat = Graphic3d_EF_EnhPostScript;
2067 else if (aFormatStr == "TEX")
2068 anExpFormat = Graphic3d_EF_TEX;
2069 else if (aFormatStr == "PDF")
2070 anExpFormat = Graphic3d_EF_PDF;
2071 else if (aFormatStr == "SVG")
2072 anExpFormat = Graphic3d_EF_SVG;
2073 else if (aFormatStr == "PGF")
2074 anExpFormat = Graphic3d_EF_PGF;
2075 else if (aFormatStr == "EMF")
2076 anExpFormat = Graphic3d_EF_EMF;
2079 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2084 if (!V3dView->View()->Export (argv[1], anExpFormat))
2086 di << "Error: export of image to " << aFormatStr << " failed!\n";
2089 catch (Standard_Failure)
2091 di << "Error: export of image to " << aFormatStr << " failed";
2092 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
2097 //==============================================================================
2098 //function : VColorScale
2099 //purpose : representation color scale
2100 //==============================================================================
2101 #include <V3d_ColorScale.hxx>
2103 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2105 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2107 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2111 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2112 if(aContext.IsNull()) {
2113 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2117 Standard_Real minRange = 0. , maxRange = 100. ;
2119 Standard_Integer numIntervals = 10 ;
2120 Standard_Integer textHeight = 16;
2121 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2122 Standard_Real X = 0., Y = 0. ;
2128 minRange = Draw::Atof( argv[1] );
2129 maxRange = Draw::Atof( argv[2] );
2130 numIntervals = Draw::Atoi( argv[3] );
2133 textHeight = Draw::Atoi( argv[4] );
2135 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2138 X = Draw::Atof( argv[6] );
2139 Y = Draw::Atof( argv[7] );
2142 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2143 if ( curView.IsNull( ) )
2145 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2146 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2147 if( ! aCS.IsNull( ) )
2149 aCS->SetPosition( X , Y );
2150 aCS->SetHeight( 0.95) ;
2151 aCS->SetTextHeight( textHeight );
2152 aCS->SetRange( minRange , maxRange );
2153 aCS->SetNumberOfIntervals( numIntervals );
2154 aCS->SetLabelPosition( position );
2155 if( !curView->ColorScaleIsDisplayed() )
2156 curView->ColorScaleDisplay( );
2161 //==============================================================================
2162 //function : VGraduatedTrihedron
2163 //purpose : Displays a graduated trihedron
2164 //==============================================================================
2166 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2168 const char *str = arg;
2171 unsigned short c1 = *str++;
2172 unsigned short c2 = *str++;
2173 if (!c1 || !c2) break;
2174 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2178 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2181 if (argc != 2 && argc < 5)
2183 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2184 di<<"Usage: type help "<<argv[0]<<"\n";
2185 return 1; //TCL_ERROR
2188 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2190 // Create 3D view if it doesn't exist
2191 if ( aV3dView.IsNull() )
2193 ViewerTest::ViewerInit();
2194 aV3dView = ViewerTest::CurrentView();
2195 if( aV3dView.IsNull() )
2197 di << "Error: Cannot create a 3D view\n";
2198 return 1; //TCL_ERROR
2202 // Erase (==0) or display (!=0)
2203 const int display = Draw::Atoi(argv[1]);
2208 TCollection_AsciiString font;
2210 font.AssignCat("Courier");
2212 font.AssignCat(argv[5]);
2214 // Text is multibyte
2215 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
2218 TCollection_ExtendedString xname, yname, zname;
2223 AddMultibyteString(xname, argv[2]);
2224 AddMultibyteString(yname, argv[3]);
2225 AddMultibyteString(zname, argv[4]);
2241 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2242 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2243 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2244 Standard_True/*drawgrid*/,
2245 Standard_True/*drawaxes*/,
2246 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2247 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2248 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2249 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2250 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2251 Quantity_NOC_WHITE/*gridcolor*/,
2252 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2253 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2256 aV3dView->GraduatedTrihedronErase();
2258 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2264 //==============================================================================
2265 //function : VPrintView
2266 //purpose : Test printing algorithm, print the view to image file with given
2267 // width and height. Printing implemented only for WNT.
2268 //==============================================================================
2269 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2273 di << "Printing implemented only for wnt!\n";
2277 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2278 Handle(V3d_View) aView = NULL;
2279 aContextAIS = ViewerTest::GetAISContext();
2280 if (!aContextAIS.IsNull())
2282 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2283 Vwr->InitActiveViews();
2284 if(Vwr->MoreActiveViews())
2285 aView = Vwr->ActiveView();
2291 di << "Call vinit before!\n";
2296 di << "Use: " << argv[0];
2297 di << " width height filename [print algo=0]\n";
2298 di << "width, height of the intermediate buffer for operation\n";
2299 di << "algo : {0|1}\n";
2300 di << " 0 - stretch algorithm\n";
2301 di << " 1 - tile algorithm\n";
2302 di << "test printing algorithms into an intermediate buffer\n";
2303 di << "with saving output to an image file\n";
2307 // get the input params
2308 Standard_Integer aWidth = Draw::Atoi (argv[1]);
2309 Standard_Integer aHeight = Draw::Atoi (argv[2]);
2310 Standard_Integer aMode = 0;
2311 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2313 aMode = Draw::Atoi (argv[4]);
2315 // check the input parameters
2316 if (aWidth <= 0 || aHeight <= 0)
2318 di << "Width and height must be positive values!\n";
2321 if (aMode != 0 && aMode != 1)
2324 // define compatible bitmap
2325 HDC anDC = CreateCompatibleDC(0);
2326 BITMAPINFO aBitmapData;
2327 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2328 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2329 aBitmapData.bmiHeader.biWidth = aWidth ;
2330 aBitmapData.bmiHeader.biHeight = aHeight;
2331 aBitmapData.bmiHeader.biPlanes = 1;
2332 aBitmapData.bmiHeader.biBitCount = 24;
2333 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2334 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2335 aBitmapData.bmiHeader.biClrUsed = 0;
2336 aBitmapData.bmiHeader.biClrImportant = 0;
2337 aBitmapData.bmiHeader.biCompression = BI_RGB;
2338 aBitmapData.bmiHeader.biSizeImage = 0;
2340 // Create Device Independent Bitmap
2341 void* aBitsOut = NULL;
2342 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2343 &aBitsOut, NULL, 0);
2344 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2346 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2347 if (aBitsOut != NULL)
2350 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2352 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2354 // succesfully printed into an intermediate buffer
2357 Image_PixMap aWrapper;
2358 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2359 aWrapper.SetTopDown (false);
2361 Image_AlienPixMap anImageBitmap;
2362 anImageBitmap.InitCopy (aWrapper);
2363 isSaved = anImageBitmap.Save (aFileName);
2367 di << "Print operation failed due to printing errors or\n";
2368 di << "insufficient memory available\n";
2369 di << "Please, try to use smaller dimensions for this test\n";
2370 di << "command, as it allocates intermediate buffer for storing\n";
2371 di << "the result\n";
2376 di << "Can't allocate memory for intermediate buffer\n";
2377 di << "Please use smaller dimensions\n";
2382 SelectObject (anDC, anOldBitmap);
2383 DeleteObject (aMemoryBitmap);
2389 di << "Save to file operation failed. This operation may fail\n";
2390 di << "if you don't have enough available memory, then you can\n";
2391 di << "use smaller dimensions for the output file\n";
2400 //==============================================================================
2401 //function : VZLayer
2402 //purpose : Test z layer operations for v3d viewer
2403 //==============================================================================
2404 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2406 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2407 if (aContextAIS.IsNull())
2409 di << "Call vinit before!\n";
2414 di << "Use: vzlayer " << argv[0];
2415 di << " add/del/get [id]\n";
2416 di << " add - add new z layer to viewer and print its id\n";
2417 di << " del - del z layer by its id\n";
2418 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2419 di << "id - the layer identificator value defined when removing z layer\n";
2423 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2424 if (aViewer.IsNull())
2426 di << "No active viewer!\n";
2430 // perform operation
2431 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2434 Standard_Integer aNewId;
2435 if (!aViewer->AddZLayer (aNewId))
2437 di << "Impossible to add new z layer!\n";
2441 di << "New z layer added with index: " << aNewId << "\n";
2443 else if (anOp == "del")
2447 di << "Please also provide as argument id of z layer to remove\n";
2451 Standard_Integer aDelId = Draw::Atoi (argv[2]);
2452 if (!aViewer->RemoveZLayer (aDelId))
2454 di << "Impossible to remove the z layer or invalid id!\n";
2458 di << "Z layer " << aDelId << " has been removed\n";
2460 else if (anOp == "get")
2462 TColStd_SequenceOfInteger anIds;
2463 aViewer->GetAllZLayers (anIds);
2464 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2466 di << anIds.Value (aSeqIdx) << " ";
2473 di << "Invalid operation, please use { add / del / get }\n";
2480 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2482 // this class provides a presentation of text item in v3d view under-/overlayer
2483 class V3d_TextItem : public Visual3d_LayerItem
2488 DEFINE_STANDARD_RTTI(V3d_TextItem)
2491 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2492 const Standard_Real theX1,
2493 const Standard_Real theY1,
2494 const Standard_Real theHeight,
2495 const TCollection_AsciiString& theFontName,
2496 const Quantity_Color& theColor,
2497 const Quantity_Color& theSubtitleColor,
2498 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2499 const Handle(Visual3d_Layer)& theLayer);
2502 Standard_EXPORT void RedrawLayerPrs();
2508 Standard_Real myHeight;
2509 TCollection_AsciiString myText;
2510 TCollection_AsciiString myFontName;
2511 Quantity_Color myColor;
2512 Quantity_Color mySubtitleColor;
2513 Aspect_TypeOfDisplayText myType;
2514 Handle(Visual3d_Layer) myLayer;
2518 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2519 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2521 // create and add to display the text item
2522 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2523 const Standard_Real theX1,
2524 const Standard_Real theY1,
2525 const Standard_Real theHeight,
2526 const TCollection_AsciiString& theFontName,
2527 const Quantity_Color& theColor,
2528 const Quantity_Color& theSubtitleColor,
2529 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2530 const Handle(Visual3d_Layer)& theLayer)
2531 : myX1 (theX1), myY1 (theY1),
2533 myHeight (theHeight),
2536 mySubtitleColor (theSubtitleColor),
2537 myType (theTypeOfDisplay),
2538 myFontName (theFontName)
2540 if (!myLayer.IsNull ())
2541 myLayer->AddLayerItem (this);
2545 void V3d_TextItem::RedrawLayerPrs ()
2547 if (myLayer.IsNull ())
2550 myLayer->SetColor (myColor);
2551 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2552 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2555 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2557 // The Visual3d_LayerItem line item for "vlayerline" command
2558 // it provides a presentation of line with user-defined
2559 // linewidth, linetype and transparency.
2560 class V3d_LineItem : public Visual3d_LayerItem
2564 DEFINE_STANDARD_RTTI(V3d_LineItem)
2567 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2568 Standard_Real X2, Standard_Real Y2,
2569 V3d_LayerMgrPointer theLayerMgr,
2570 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2571 Standard_Real theWidth = 0.5,
2572 Standard_Real theTransp = 1.0);
2575 Standard_EXPORT void RedrawLayerPrs();
2579 Standard_Real myX1, myY1, myX2, myY2;
2580 Standard_Real myWidth;
2581 Standard_Real myTransparency;
2582 Aspect_TypeOfLine myType;
2583 V3d_LayerMgrPointer myLayerMgr;
2586 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2587 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2589 // default constructor for line item
2590 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2591 Standard_Real X2, Standard_Real Y2,
2592 V3d_LayerMgrPointer theLayerMgr,
2593 Aspect_TypeOfLine theType,
2594 Standard_Real theWidth,
2595 Standard_Real theTransp) :
2596 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2597 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2599 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
2600 myLayerMgr->Overlay()->AddLayerItem (this);
2604 void V3d_LineItem::RedrawLayerPrs ()
2606 Handle (Visual3d_Layer) aOverlay;
2609 aOverlay = myLayerMgr->Overlay();
2611 if (!aOverlay.IsNull())
2613 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2614 aOverlay->SetColor(aColor);
2615 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2616 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2617 aOverlay->BeginPolyline();
2618 aOverlay->AddVertex(myX1, myY1);
2619 aOverlay->AddVertex(myX2, myY2);
2620 aOverlay->ClosePrimitive();
2624 //=============================================================================
2625 //function : VLayerLine
2626 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2627 // : linewidth, transparency coefficient
2628 //============================================================================
2629 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2631 // get the active view
2632 Handle(V3d_View) aView = ViewerTest::CurrentView();
2635 di << "Call vinit before!\n";
2640 di << "Use: " << argv[0];
2641 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2642 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2643 di << " 0 - solid \n";
2644 di << " 1 - dashed \n";
2645 di << " 2 - dot \n";
2646 di << " 3 - dashdot\n";
2647 di << " transparency : { 0.0 - 1.0 } \n";
2648 di << " 0.0 - transparent\n";
2649 di << " 1.0 - visible \n";
2653 // get the input params
2654 Standard_Real X1 = Draw::Atof(argv[1]);
2655 Standard_Real Y1 = Draw::Atof(argv[2]);
2656 Standard_Real X2 = Draw::Atof(argv[3]);
2657 Standard_Real Y2 = Draw::Atof(argv[4]);
2659 Standard_Real aWidth = 0.5;
2660 Standard_Integer aType = 0;
2661 Standard_Real aTransparency = 1.0;
2665 aWidth = Draw::Atof(argv[5]);
2669 aType = (Standard_Integer) Draw::Atoi(argv[6]);
2674 aTransparency = Draw::Atof(argv[7]);
2675 if (aTransparency < 0 || aTransparency > 1.0)
2676 aTransparency = 1.0;
2679 // select appropriate line type
2680 Aspect_TypeOfLine aLineType;
2684 aLineType = Aspect_TOL_DASH;
2688 aLineType = Aspect_TOL_DOT;
2692 aLineType = Aspect_TOL_DOTDASH;
2696 aLineType = Aspect_TOL_SOLID;
2699 // replace layer manager
2700 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2701 aView->SetLayerMgr(aMgr);
2704 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2710 aView->MustBeResized();
2716 //=======================================================================
2717 //function : VOverlayText
2718 //purpose : Test text displaying in view overlay
2719 //=======================================================================
2720 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2722 // get the active view
2723 Handle(V3d_View) aView = ViewerTest::CurrentView();
2726 di << "No active view. Please call vinit.\n";
2729 else if (argc < 4 || argc > 13)
2731 di << "Use: " << argv[0];
2732 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2733 di << "[background_color: R G B]\n";
2734 di << " height - pixel height of the text (default=10.0)\n";
2735 di << " font_name - name of font (default=courier)\n";
2736 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2737 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2738 di << " background_color- R G B values used for subtitle and decal text\n";
2739 di << "(default=255.0 255.0 255.0)\n";
2743 TCollection_AsciiString aText (argv[1]);
2744 Standard_Real aPosX = Draw::Atof(argv[2]);
2745 Standard_Real aPosY = Draw::Atof(argv[3]);
2746 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
2749 TCollection_AsciiString aFontName = "Courier";
2751 aFontName = TCollection_AsciiString (argv[5]);
2754 Quantity_Parameter aColorRed = 1.0;
2755 Quantity_Parameter aColorGreen = 1.0;
2756 Quantity_Parameter aColorBlue = 1.0;
2759 aColorRed = Draw::Atof (argv[6])/255.;
2760 aColorGreen = Draw::Atof (argv[7])/255.;
2761 aColorBlue = Draw::Atof (argv[8])/255.;
2765 TCollection_AsciiString aDispStr;
2767 aDispStr = TCollection_AsciiString (argv[9]);
2769 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2770 if (aDispStr.IsEqual ("subtitle"))
2771 aTextType = Aspect_TODT_SUBTITLE;
2772 else if (aDispStr.IsEqual ("decal"))
2773 aTextType = Aspect_TODT_DEKALE;
2774 else if (aDispStr.IsEqual ("blend"))
2775 aTextType = Aspect_TODT_BLEND;
2778 Quantity_Parameter aSubRed = 1.0;
2779 Quantity_Parameter aSubGreen = 1.0;
2780 Quantity_Parameter aSubBlue = 1.0;
2783 aSubRed = Draw::Atof (argv[10])/255.;
2784 aSubGreen = Draw::Atof (argv[11])/255.;
2785 aSubBlue = Draw::Atof (argv[12])/255.;
2788 // check fo current overlay
2789 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2790 if (anOverlay.IsNull ())
2792 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2793 anOverlay = aMgr->Overlay ();
2794 aView->SetLayerMgr (aMgr);
2797 Quantity_Color aTextColor (aColorRed, aColorGreen,
2798 aColorBlue, Quantity_TOC_RGB);
2799 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2800 aSubBlue, Quantity_TOC_RGB);
2803 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2804 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2807 aView->MustBeResized();
2813 //==============================================================================
2816 //==============================================================================
2818 static int VGrid (Draw_Interpretor& theDI,
2819 Standard_Integer theArgNb,
2820 const char** theArgVec)
2822 // get the active view
2823 Handle(V3d_View) aView = ViewerTest::CurrentView();
2824 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2825 if (aView.IsNull() || aViewer.IsNull())
2827 std::cerr << "No active view. Please call vinit.\n";
2831 Aspect_GridType aType = aViewer->GridType();
2832 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2834 Standard_Integer anIter = 1;
2835 for (; anIter < theArgNb; ++anIter)
2837 const char* aValue = theArgVec[anIter];
2840 aType = Aspect_GT_Rectangular;
2842 else if (*aValue == 'c')
2844 aType = Aspect_GT_Circular;
2846 else if (*aValue == 'l')
2848 aMode = Aspect_GDM_Lines;
2850 else if (*aValue == 'p')
2852 aMode = Aspect_GDM_Points;
2854 else if (strcmp (aValue, "off" ) == 0)
2856 aViewer->DeactivateGrid();
2865 Standard_Integer aTail = (theArgNb - anIter);
2868 aViewer->ActivateGrid (aType, aMode);
2871 else if (aTail != 2 && aTail != 5)
2873 std::cerr << "Incorrect arguments number! Usage:\n"
2874 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2878 Quantity_Length anOriginX, anOriginY;
2879 Quantity_PlaneAngle aRotAngle;
2880 if (aType == Aspect_GT_Rectangular)
2882 Quantity_Length aRStepX, aRStepY;
2883 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2885 anOriginX = Draw::Atof (theArgVec[anIter++]);
2886 anOriginY = Draw::Atof (theArgVec[anIter++]);
2889 aRStepX = Draw::Atof (theArgVec[anIter++]);
2890 aRStepY = Draw::Atof (theArgVec[anIter++]);
2891 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2893 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2894 aViewer->ActivateGrid (aType, aMode);
2896 else if (aType == Aspect_GT_Circular)
2898 Quantity_Length aRadiusStep;
2899 Standard_Integer aDivisionNumber;
2900 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2902 anOriginX = Draw::Atof (theArgVec[anIter++]);
2903 anOriginY = Draw::Atof (theArgVec[anIter++]);
2906 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
2907 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
2908 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2911 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2912 aViewer->ActivateGrid (aType, aMode);
2918 //==============================================================================
2921 //==============================================================================
2923 static int VFps (Draw_Interpretor& theDI,
2924 Standard_Integer theArgNb,
2925 const char** theArgVec)
2927 // get the active view
2928 Handle(V3d_View) aView = ViewerTest::CurrentView();
2931 std::cerr << "No active view. Please call vinit.\n";
2935 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
2938 std::cerr << "Incorrect arguments!\n";
2942 // the time is meaningless for first call
2943 // due to async OpenGl rendering
2946 // redraw view in loop to estimate average values
2949 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2955 const Standard_Real aTime = aTimer.ElapsedTime();
2956 aTimer.OSD_Chronometer::Show (aCpu);
2958 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2959 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2961 // return statistics
2962 theDI << "FPS: " << aFpsAver << "\n"
2963 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2969 //==============================================================================
2972 //==============================================================================
2974 static int VVbo (Draw_Interpretor& theDI,
2975 Standard_Integer theArgNb,
2976 const char** theArgVec)
2979 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2980 if (aContextAIS.IsNull())
2982 std::cerr << "No active view. Please call vinit.\n";
2986 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
2988 if (aDriver.IsNull())
2990 std::cerr << "Graphic driver not available.\n";
2996 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2998 std::cerr << "Wrong number of arguments.\n";
3002 aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
3006 //==============================================================================
3007 //function : VMemGpu
3009 //==============================================================================
3011 static int VMemGpu (Draw_Interpretor& theDI,
3012 Standard_Integer theArgNb,
3013 const char** theArgVec)
3016 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3017 if (aContextAIS.IsNull())
3019 std::cerr << "No active view. Please call vinit.\n";
3023 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3025 if (aDriver.IsNull())
3027 std::cerr << "Graphic driver not available.\n";
3031 Standard_Size aFreeBytes = 0;
3032 TCollection_AsciiString anInfo;
3033 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3035 std::cerr << "Information not available.\n";
3039 if (theArgNb > 1 && *theArgVec[1] == 'f')
3041 theDI << Standard_Real (aFreeBytes);
3051 // ==============================================================================
3052 // function : VReadPixel
3054 // ==============================================================================
3055 static int VReadPixel (Draw_Interpretor& theDI,
3056 Standard_Integer theArgNb,
3057 const char** theArgVec)
3059 // get the active view
3060 Handle(V3d_View) aView = ViewerTest::CurrentView();
3063 std::cerr << "No active view. Please call vinit.\n";
3066 else if (theArgNb < 3)
3068 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3072 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3073 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
3075 Standard_Integer aWidth, aHeight;
3076 aView->Window()->Size (aWidth, aHeight);
3077 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3078 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3079 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3081 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
3085 Standard_Boolean toShowName = Standard_False;
3086 Standard_Boolean toShowHls = Standard_False;
3087 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
3089 TCollection_AsciiString aParam (theArgVec[anIter]);
3090 if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb")))
3092 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3093 aBufferType = Graphic3d_BT_RGB;
3095 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
3097 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3098 aBufferType = Graphic3d_BT_RGB;
3099 toShowHls = Standard_True;
3101 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
3103 aFormat = Image_PixMap::ImgRGBF;
3104 aBufferType = Graphic3d_BT_RGB;
3106 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
3108 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3109 aBufferType = Graphic3d_BT_RGBA;
3111 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
3113 aFormat = Image_PixMap::ImgRGBAF;
3114 aBufferType = Graphic3d_BT_RGBA;
3116 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
3118 aFormat = Image_PixMap::ImgGrayF;
3119 aBufferType = Graphic3d_BT_Depth;
3121 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
3123 toShowName = Standard_True;
3127 Image_PixMap anImage;
3128 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
3130 std::cerr << "Image allocation failed\n";
3133 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
3135 std::cerr << "Image dump failed\n";
3139 Quantity_Parameter anAlpha;
3140 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
3143 if (aBufferType == Graphic3d_BT_RGBA)
3145 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3149 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3154 switch (aBufferType)
3157 case Graphic3d_BT_RGB:
3161 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3165 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3169 case Graphic3d_BT_RGBA:
3171 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3174 case Graphic3d_BT_Depth:
3176 theDI << aColor.Red() << "\n";
3185 //==============================================================================
3186 //function : VDiffImage
3187 //purpose : The draw-command compares two images.
3188 //==============================================================================
3190 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3194 theDI << "Not enough arguments.\n";
3199 const char* anImgPathRef = theArgVec[1];
3200 const char* anImgPathNew = theArgVec[2];
3202 // get string tolerance and check its validity
3203 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
3204 if (aTolColor < 0.0)
3206 if (aTolColor > 1.0)
3209 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
3210 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
3212 // image file of difference
3213 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3215 // compare the images
3216 Image_Diff aComparer;
3217 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3222 aComparer.SetColorTolerance (aTolColor);
3223 aComparer.SetBorderFilterOn (isBorderFilterOn);
3224 Standard_Integer aDiffColorsNb = aComparer.Compare();
3225 theDI << aDiffColorsNb << "\n";
3227 // save image of difference
3228 if (aDiffImagePath != NULL)
3230 aComparer.SaveDiffImage (aDiffImagePath);
3236 //=======================================================================
3237 //function : VSelect
3238 //purpose : Emulates different types of selection by mouse:
3239 // 1) single click selection
3240 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
3241 // 3) selection with polygon having corners at
3242 // pixel positions (x1,y1),...,(xn,yn)
3243 // 4) any of these selections with shift button pressed
3244 //=======================================================================
3245 static Standard_Integer VSelect (Draw_Interpretor& di,
3246 Standard_Integer argc,
3251 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
3255 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
3256 if(myAIScontext.IsNull())
3258 di << "use 'vinit' command before " << argv[0] << "\n";
3261 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
3262 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
3263 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
3266 if(isShiftSelection)
3267 aCurrentEventManager->ShiftSelect();
3269 aCurrentEventManager->Select();
3273 if(isShiftSelection)
3274 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3276 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3280 Standard_Integer anUpper = 0;
3282 if(isShiftSelection)
3283 anUpper = (argc-1)/2;
3286 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
3288 for(Standard_Integer i=1;i<=anUpper;++i)
3289 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
3291 if(isShiftSelection)
3292 aCurrentEventManager->ShiftSelect(aPolyline);
3294 aCurrentEventManager->Select(aPolyline);
3299 //=======================================================================
3300 //function : VMoveTo
3301 //purpose : Emulates cursor movement to defined pixel position
3302 //=======================================================================
3303 static Standard_Integer VMoveTo (Draw_Interpretor& di,
3304 Standard_Integer argc,
3309 di << "Usage : " << argv[0] << " x y" << "\n";
3313 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3314 if(aContext.IsNull())
3316 di << "use 'vinit' command before " << argv[0] << "\n";
3319 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
3323 //=======================================================================
3324 //function : VViewParams
3325 //purpose : Gets or sets AIS View characteristics
3326 //=======================================================================
3327 static Standard_Integer VViewParams (Draw_Interpretor& di,
3328 Standard_Integer argc,
3331 if ( argc != 1 && argc != 13)
3333 di << "Usage : " << argv[0] << "\n";
3336 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
3337 if ( anAISView.IsNull () )
3339 di << "use 'vinit' command before " << argv[0] << "\n";
3343 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
3344 Standard_Real anAISViewCenterCoordinateX = 0.0;
3345 Standard_Real anAISViewCenterCoordinateY = 0.0;
3346 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3347 Standard_Real anAISViewProjX = 0.0;
3348 Standard_Real anAISViewProjY = 0.0;
3349 Standard_Real anAISViewProjZ = 0.0;
3350 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3351 Standard_Real anAISViewUpX = 0.0;
3352 Standard_Real anAISViewUpY = 0.0;
3353 Standard_Real anAISViewUpZ = 0.0;
3354 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3355 Standard_Real anAISViewAtX = 0.0;
3356 Standard_Real anAISViewAtY = 0.0;
3357 Standard_Real anAISViewAtZ = 0.0;
3358 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3359 di << "Scale of current view: " << anAISViewScale << "\n";
3360 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
3361 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
3362 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
3363 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
3367 Quantity_Factor anAISViewScale = atof (argv [1]);
3368 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
3369 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
3370 Standard_Real anAISViewProjX = atof (argv [4]);
3371 Standard_Real anAISViewProjY = atof (argv [5]);
3372 Standard_Real anAISViewProjZ = atof (argv [6]);
3373 Standard_Real anAISViewUpX = atof (argv [7]);
3374 Standard_Real anAISViewUpY = atof (argv [8]);
3375 Standard_Real anAISViewUpZ = atof (argv [9]);
3376 Standard_Real anAISViewAtX = atof (argv [10]);
3377 Standard_Real anAISViewAtY = atof (argv [11]);
3378 Standard_Real anAISViewAtZ = atof (argv [12]);
3379 anAISView -> V3d_View::SetScale (anAISViewScale);
3380 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3381 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3382 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3383 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3388 //=======================================================================
3389 //function : VChangeSelected
3390 //purpose : Adds the shape to selection or remove one from it
3391 //=======================================================================
3392 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
3393 Standard_Integer argc,
3398 di<<"Usage : " << argv[0] << " shape \n";
3402 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3403 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3404 TCollection_AsciiString aName(argv[1]);
3405 Handle(AIS_InteractiveObject) anAISObject;
3407 if(!aMap.IsBound2(aName))
3409 di<<"Use 'vdisplay' before";
3414 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
3415 if(anAISObject.IsNull()){
3416 di<<"No interactive object \n";
3420 if(aContext->HasOpenedContext())
3422 aContext->AddOrRemoveSelected(anAISObject);
3426 aContext->AddOrRemoveCurrentObject(anAISObject);
3432 //=======================================================================
3433 //function : VZClipping
3434 //purpose : Gets or sets ZClipping mode, width and depth
3435 //=======================================================================
3436 static Standard_Integer VZClipping (Draw_Interpretor& di,
3437 Standard_Integer argc,
3442 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3443 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3446 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3447 if(aContext.IsNull())
3449 di << "use 'vinit' command before " << argv[0] << "\n";
3452 Handle(V3d_View) aView = ViewerTest::CurrentView();
3453 V3d_TypeOfZclipping aZClippingMode;
3456 TCollection_AsciiString aZClippingModeString;
3457 Quantity_Length aDepth, aWidth;
3458 aZClippingMode = aView->ZClipping(aDepth, aWidth);
3459 switch (aZClippingMode)
3462 aZClippingModeString.Copy("OFF");
3465 aZClippingModeString.Copy("BACK");
3468 aZClippingModeString.Copy("FRONT");
3471 aZClippingModeString.Copy("SLICE");
3474 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
3477 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
3478 << "ZClipping depth = " << aDepth << "\n"
3479 << "ZClipping width = " << aWidth << "\n";
3485 Standard_Integer aStatus = 0;
3486 if ( strcmp (argv [1], "OFF") == 0 ) {
3488 aZClippingMode = V3d_OFF;
3490 if ( strcmp (argv [1], "BACK") == 0 ) {
3492 aZClippingMode = V3d_BACK;
3494 if ( strcmp (argv [1], "FRONT") == 0 ) {
3496 aZClippingMode = V3d_FRONT;
3498 if ( strcmp (argv [1], "SLICE") == 0 ) {
3500 aZClippingMode = V3d_SLICE;
3504 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3505 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3508 aView->SetZClippingType(aZClippingMode);
3512 Quantity_Length aDepth = 0., aWidth = 1.;
3515 aDepth = atof(argv[1]);
3516 aWidth = atof(argv[2]);
3520 aDepth = atof(argv[2]);
3521 aWidth = atof(argv[3]);
3524 if(aDepth<0. || aDepth>1.)
3526 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3527 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3530 if(aWidth<0. || aWidth>1.)
3532 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3533 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3537 aView->SetZClippingDepth(aDepth);
3538 aView->SetZClippingWidth(aWidth);
3545 //=======================================================================
3546 //function : VNbSelected
3547 //purpose : Returns number of selected objects
3548 //=======================================================================
3549 static Standard_Integer VNbSelected (Draw_Interpretor& di,
3550 Standard_Integer argc,
3555 di << "Usage : " << argv[0] << "\n";
3558 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3559 if(aContext.IsNull())
3561 di << "use 'vinit' command before " << argv[0] << "\n";
3564 di << aContext->NbSelected() << "\n";
3568 //=======================================================================
3569 //function : VAntialiasing
3570 //purpose : Switches altialiasing on or off
3571 //=======================================================================
3572 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
3573 Standard_Integer argc,
3578 di << "Usage : " << argv[0] << " [1|0]" << "\n";
3582 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3583 if(aContext.IsNull())
3585 di << "use 'vinit' command before " << argv[0] << "\n";
3589 Handle(V3d_View) aView = ViewerTest::CurrentView();
3591 if((argc == 2) && (atof(argv[1]) == 0))
3592 aView->SetAntialiasingOff();
3594 aView->SetAntialiasingOn();
3599 //=======================================================================
3600 //function : VPurgeDisplay
3601 //purpose : Switches altialiasing on or off
3602 //=======================================================================
3603 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
3604 Standard_Integer argc,
3609 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
3612 Standard_Boolean isCollectorToo = Standard_False;
3615 isCollectorToo = (atoi(argv [1]) != 0);
3617 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3618 if (aContext.IsNull())
3620 di << "use 'vinit' command before " << argv[0] << "\n";
3623 aContext->CloseAllContexts(Standard_False);
3624 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
3628 //=======================================================================
3629 //function : VSetViewSize
3631 //=======================================================================
3632 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
3633 Standard_Integer argc,
3636 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3637 if(aContext.IsNull())
3639 di << "use 'vinit' command before " << argv[0] << "\n";
3644 di<<"Usage : " << argv[0] << " Size\n";
3647 Standard_Real aSize = atof(argv[1]);
3650 di<<"Bad Size value : " << aSize << "\n";
3654 Handle(V3d_View) aView = ViewerTest::CurrentView();
3655 aView->SetSize(aSize);
3659 //=======================================================================
3660 //function : VMoveView
3662 //=======================================================================
3663 static Standard_Integer VMoveView (Draw_Interpretor& di,
3664 Standard_Integer argc,
3667 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3668 if(aContext.IsNull())
3670 di << "use 'vinit' command before " << argv[0] << "\n";
3673 if(argc < 4 || argc > 5)
3675 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3678 Standard_Real Dx = atof(argv[1]);
3679 Standard_Real Dy = atof(argv[2]);
3680 Standard_Real Dz = atof(argv[3]);
3681 Standard_Boolean aStart = Standard_True;
3684 aStart = (atoi(argv[4]) > 0);
3687 Handle(V3d_View) aView = ViewerTest::CurrentView();
3688 aView->Move(Dx,Dy,Dz,aStart);
3692 //=======================================================================
3693 //function : VTranslateView
3695 //=======================================================================
3696 static Standard_Integer VTranslateView (Draw_Interpretor& di,
3697 Standard_Integer argc,
3700 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3701 if(aContext.IsNull())
3703 di << "use 'vinit' command before " << argv[0] << "\n";
3706 if(argc < 4 || argc > 5)
3708 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3711 Standard_Real Dx = atof(argv[1]);
3712 Standard_Real Dy = atof(argv[2]);
3713 Standard_Real Dz = atof(argv[3]);
3714 Standard_Boolean aStart = Standard_True;
3717 aStart = (atoi(argv[4]) > 0);
3720 Handle(V3d_View) aView = ViewerTest::CurrentView();
3721 aView->Translate(Dx,Dy,Dz,aStart);
3725 //=======================================================================
3726 //function : VTurnView
3728 //=======================================================================
3729 static Standard_Integer VTurnView (Draw_Interpretor& di,
3730 Standard_Integer argc,
3733 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3734 if(aContext.IsNull()) {
3735 di << "use 'vinit' command before " << argv[0] << "\n";
3738 if(argc < 4 || argc > 5){
3739 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
3742 Standard_Real Ax = atof(argv[1]);
3743 Standard_Real Ay = atof(argv[2]);
3744 Standard_Real Az = atof(argv[3]);
3745 Standard_Boolean aStart = Standard_True;
3748 aStart = (atoi(argv[4]) > 0);
3751 Handle(V3d_View) aView = ViewerTest::CurrentView();
3752 aView->Turn(Ax,Ay,Az,aStart);
3756 //==============================================================================
3757 //function : VTextureEnv
3758 //purpose : ENables or disables environment mapping
3759 //==============================================================================
3760 class OCC_TextureEnv : public Graphic3d_TextureEnv
3763 OCC_TextureEnv(const Standard_CString FileName);
3764 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
3765 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
3766 const Standard_Boolean theModulateFlag,
3767 const Graphic3d_TypeOfTextureFilter theFilter,
3768 const Standard_ShortReal theXScale,
3769 const Standard_ShortReal theYScale,
3770 const Standard_ShortReal theXShift,
3771 const Standard_ShortReal theYShift,
3772 const Standard_ShortReal theAngle);
3773 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
3775 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
3776 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
3777 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
3779 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
3780 : Graphic3d_TextureEnv(theFileName)
3784 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
3785 : Graphic3d_TextureEnv(theTexId)
3789 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
3790 const Standard_Boolean theModulateFlag,
3791 const Graphic3d_TypeOfTextureFilter theFilter,
3792 const Standard_ShortReal theXScale,
3793 const Standard_ShortReal theYScale,
3794 const Standard_ShortReal theXShift,
3795 const Standard_ShortReal theYShift,
3796 const Standard_ShortReal theAngle)
3798 myParams->SetRepeat (theRepeatFlag);
3799 myParams->SetModulate (theModulateFlag);
3800 myParams->SetFilter (theFilter);
3801 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
3802 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
3803 myParams->SetRotation (theAngle);
3806 static int VTextureEnv (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3808 // get the active view
3809 Handle(V3d_View) aView = ViewerTest::CurrentView();
3812 std::cerr << "No active view. Please call vinit.\n";
3816 // Checking the input arguments
3817 Standard_Boolean anEnableFlag = Standard_False;
3818 Standard_Boolean isOk = theArgNb >= 2;
3821 TCollection_AsciiString anEnableOpt(theArgVec[1]);
3822 anEnableFlag = anEnableOpt.IsEqual("on");
3823 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
3827 isOk = (theArgNb == 3 || theArgNb == 11);
3830 TCollection_AsciiString aTextureOpt(theArgVec[2]);
3831 isOk = (!aTextureOpt.IsIntegerValue() ||
3832 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
3834 if (isOk && theArgNb == 11)
3836 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
3837 aModulateOpt(theArgVec[4]),
3838 aFilterOpt (theArgVec[5]),
3839 aSScaleOpt (theArgVec[6]),
3840 aTScaleOpt (theArgVec[7]),
3841 aSTransOpt (theArgVec[8]),
3842 aTTransOpt (theArgVec[9]),
3843 anAngleOpt (theArgVec[10]);
3844 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
3845 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
3846 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
3847 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
3848 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
3849 anAngleOpt.IsRealValue());
3856 std::cerr << "Usage :" << std::endl;
3857 std::cerr << theArgVec[0] << " off" << std::endl;
3858 std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
3864 TCollection_AsciiString aTextureOpt(theArgVec[2]);
3865 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
3866 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
3867 new OCC_TextureEnv(theArgVec[2]);
3871 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
3872 aTexEnv->SetTextureParameters(
3873 aRepeatOpt. IsEqual("repeat"),
3874 aModulateOpt.IsEqual("modulate"),
3875 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
3876 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
3877 Graphic3d_TOTF_TRILINEAR,
3878 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
3879 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
3880 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
3881 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
3882 (Standard_ShortReal)Draw::Atof(theArgVec[10])
3885 aView->SetTextureEnv(aTexEnv);
3886 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
3888 else // Disabling environment mapping
3890 aView->SetSurfaceDetail(V3d_TEX_NONE);
3891 Handle(Graphic3d_TextureEnv) aTexture;
3892 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
3899 //=======================================================================
3900 //function : ViewerCommands
3902 //=======================================================================
3904 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3907 const char *group = "ZeViewer";
3908 theCommands.Add("vinit" ,
3909 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3910 __FILE__,VInit,group);
3911 theCommands.Add("vhelp" ,
3912 "vhelp : display help on the viewer commands",
3913 __FILE__,VHelp,group);
3914 theCommands.Add("vtop" ,
3915 "vtop or <T> : Top view" ,
3916 __FILE__,VTop,group);
3917 theCommands.Add("vbottom" ,
3918 "vbottom : Bottom view" ,
3919 __FILE__,VBottom,group);
3920 theCommands.Add("vleft" ,
3921 "vleft : Left view" ,
3922 __FILE__,VLeft,group);
3923 theCommands.Add("vright" ,
3924 "vright : Right view" ,
3925 __FILE__,VRight,group);
3926 theCommands.Add("vaxo" ,
3927 " vaxo or <A> : Axonometric view ",
3928 __FILE__,VAxo,group);
3929 theCommands.Add("vfront" ,
3930 "vfront : Front view" ,
3931 __FILE__,VFront,group);
3932 theCommands.Add("vback" ,
3933 "vback : Back view" ,
3934 __FILE__,VBack,group);
3935 theCommands.Add("vpick" ,
3936 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
3938 theCommands.Add("vfit" ,
3939 "vfit or <F> : vfit",
3940 __FILE__,VFit,group);
3941 theCommands.Add("vzfit" ,
3943 __FILE__,VZFit,group);
3944 theCommands.Add("vrepaint",
3945 "vrepaint : vrepaint, force redraw",
3946 __FILE__,VRepaint,group);
3947 theCommands.Add("vclear",
3949 __FILE__,VClear,group);
3950 theCommands.Add("vsetbg",
3951 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
3952 __FILE__,VSetBg,group);
3953 theCommands.Add("vsetbgmode",
3954 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
3955 __FILE__,VSetBgMode,group);
3956 theCommands.Add("vsetgradientbg",
3957 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
3958 __FILE__,VSetGradientBg,group);
3959 theCommands.Add("vsetgrbgmode",
3960 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
3961 __FILE__,VSetGradientBgMode,group);
3962 theCommands.Add("vsetcolorbg",
3963 "vsetcolorbg : vsetcolorbg r g b : Set background color",
3964 __FILE__,VSetColorBg,group);
3965 theCommands.Add("vscale",
3966 "vscale : vscale X Y Z",
3967 __FILE__,VScale,group);
3968 theCommands.Add("vzbufftrihedron",
3969 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3970 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3971 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
3972 __FILE__,VTestZBuffTrihedron,group);
3973 theCommands.Add("vrotate",
3974 "vrotate : vrotate AX AY AZ [X Y Z]",
3975 __FILE__,VRotate,group);
3976 theCommands.Add("vzoom",
3977 "vzoom : vzoom coef",
3978 __FILE__,VZoom,group);
3979 theCommands.Add("vpan",
3980 "vpan : vpan dx dy",
3981 __FILE__,VPan,group);
3982 theCommands.Add("vexport",
3983 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3984 " : exports the view to a vector file of a given format"
3985 " : notice that EMF format requires patched gl2ps",
3986 __FILE__,VExport,group);
3987 theCommands.Add("vcolorscale",
3988 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3989 __FILE__,VColorScale,group);
3990 theCommands.Add("vgraduatedtrihedron",
3991 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
3992 __FILE__,VGraduatedTrihedron,group);
3993 theCommands.Add("vprintview" ,
3994 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3995 __FILE__,VPrintView,group);
3996 theCommands.Add("vzlayer",
3997 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3998 __FILE__,VZLayer,group);
3999 theCommands.Add("voverlaytext",
4000 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
4001 " : height - pixel height of the text (default=10.0)"
4002 " : font_name - name of font (default=courier)"
4003 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
4004 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
4005 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
4006 __FILE__,VOverlayText,group);
4007 theCommands.Add("vlayerline",
4008 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
4009 __FILE__,VLayerLine,group);
4010 theCommands.Add ("vgrid",
4011 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
4012 " : Mode - rectangular or circular"
4013 " : Type - lines or points",
4014 __FILE__, VGrid, group);
4015 theCommands.Add ("vfps",
4016 "vfps [framesNb=100] : estimate average frame rate for active view",
4017 __FILE__, VFps, group);
4018 theCommands.Add ("vvbo",
4019 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
4020 __FILE__, VVbo, group);
4021 theCommands.Add ("vmemgpu",
4022 "vmemgpu [f]: print system-dependent GPU memory information if available;"
4023 " with f option returns free memory in bytes",
4024 __FILE__, VMemGpu, group);
4025 theCommands.Add ("vreadpixel",
4026 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
4027 " : Read pixel value for active view",
4028 __FILE__, VReadPixel, group);
4029 theCommands.Add("diffimage",
4030 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
4031 __FILE__, VDiffImage, group);
4032 theCommands.Add ("vselect",
4033 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
4034 "- emulates different types of selection:\n"
4035 "- 1) single click selection\n"
4036 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
4037 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
4038 "- 4) any of these selections with shift button pressed",
4039 __FILE__, VSelect, group);
4040 theCommands.Add ("vmoveto",
4042 "- emulates cursor movement to pixel postion (x,y)",
4043 __FILE__, VMoveTo, group);
4044 theCommands.Add("vviewparams",
4045 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
4046 "- gets or sets current view characteristics",
4047 __FILE__,VViewParams, group);
4048 theCommands.Add("vchangeselected",
4049 "vchangeselected shape"
4050 "- adds to shape to selection or remove one from it",
4051 __FILE__, VChangeSelected, group);
4052 theCommands.Add("vzclipping",
4053 "vzclipping [mode] [depth width]\n"
4054 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
4055 "- gets or sets ZClipping mode, width and depth",
4056 __FILE__,VZClipping,group);
4057 theCommands.Add ("vnbselected",
4058 "vnbselected", __FILE__, VNbSelected, group);
4059 theCommands.Add("vantialiasing",
4060 "vantialiasing 1|0",
4061 __FILE__,VAntialiasing,group);
4062 theCommands.Add ("vpurgedisplay",
4063 "vpurgedisplay [CollectorToo = 0|1]"
4064 "- removes structures which don't belong to objects displayed in neutral point",
4065 __FILE__, VPurgeDisplay, group);
4066 theCommands.Add("vsetviewsize",
4067 "vsetviewsize size",
4068 __FILE__,VSetViewSize,group);
4069 theCommands.Add("vmoveview",
4070 "vmoveview Dx Dy Dz [Start = 1|0]",
4071 __FILE__,VMoveView,group);
4072 theCommands.Add("vtranslateview",
4073 "vtranslateview Dx Dy Dz [Start = 1|0)]",
4074 __FILE__,VTranslateView,group);
4075 theCommands.Add("vturnview",
4076 "vturnview Ax Ay Az [Start = 1|0]",
4077 __FILE__,VTurnView,group);
4078 theCommands.Add("vtextureenv",
4079 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
4080 "or user-defined file and optionally applying texture mapping parameters\n"
4082 " vtextureenv off - disables environment mapping\n"
4083 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
4084 " std_texture = (0..7)\n"
4085 " rep = {clamp|repeat}\n"
4086 " mod = {decal|modulate}\n"
4087 " flt = {nearest|bilinear|trilinear}\n"
4088 " ss, st - scale factors for s and t texture coordinates\n"
4089 " ts, tt - translation for s and t texture coordinates\n"
4090 " rot - texture rotation angle in degrees",
4091 __FILE__, VTextureEnv, group);
4092 theCommands.Add("vhlr" ,
4093 "is_enabled={on|off}"
4094 " - Hidden line removal algorithm:"
4095 " - is_enabled: if is on HLR algorithm is applied\n",
4096 __FILE__,VHLR,group);
4097 theCommands.Add("vhlrtype" ,
4098 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
4099 " - Changes the type of HLR algorithm using for shapes."
4100 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
4101 " if equals to polyalgo, polygonal HLR algorithm is applied."
4102 "If shapes are not given HLR algoithm of given type is applied"
4103 " to all shapes in the view\n",
4104 __FILE__,VHLRType,group);