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 <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_GraphicDriver.hxx>
34 #include <Graphic3d_ExportFormat.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_EventManager.hxx>
37 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
38 #include <Visual3d_View.hxx>
39 #include <Visual3d_ViewManager.hxx>
40 #include <V3d_LayerMgr.hxx>
41 #include <NIS_View.hxx>
42 #include <NIS_Triangulated.hxx>
43 #include <NIS_InteractiveContext.hxx>
44 #include <AIS_InteractiveContext.hxx>
45 #include <Draw_Interpretor.hxx>
47 #include <Draw_Appli.hxx>
48 #include <Aspect_PrintAlgo.hxx>
49 #include <Image_AlienPixMap.hxx>
50 #include <OSD_Timer.hxx>
51 #include <TColStd_SequenceOfInteger.hxx>
52 #include <TColStd_HSequenceOfReal.hxx>
53 #include <TColgp_Array1OfPnt2d.hxx>
54 #include <Visual3d_LayerItem.hxx>
55 #include <V3d_LayerMgr.hxx>
56 #include <V3d_LayerMgrPointer.hxx>
57 #include <Aspect_TypeOfLine.hxx>
58 #include <Image_Diff.hxx>
64 #include <Visual3d_Layer.hxx>
67 #if defined(_WIN32) || defined(__WIN32__)
68 #include <Graphic3d_WNTGraphicDevice.hxx>
69 #include <WNT_WClass.hxx>
70 #include <WNT_Window.hxx>
73 #define _CRT_SECURE_NO_DEPRECATE
74 #pragma warning (disable:4996)
76 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
77 #include <Graphic3d_GraphicDevice.hxx>
78 #include <Cocoa_Window.hxx>
81 #include <Graphic3d_GraphicDevice.hxx>
82 #include <Xw_GraphicDevice.hxx>
83 #include <Xw_WindowQuality.hxx>
84 #include <Xw_Window.hxx>
85 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
86 #include <X11/Xutil.h>
90 //==============================================================================
92 //==============================================================================
93 // VIEWER GLOBAL VARIABLES
94 //==============================================================================
96 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
98 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
99 extern const Handle(NIS_InteractiveContext)& TheNISContext();
100 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
102 #if defined(_WIN32) || defined(__WIN32__)
103 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
104 static Handle(Graphic3d_WNTGraphicDevice) GD;
108 static Handle(WNT_Window)& VT_GetWindow() {
109 static Handle(WNT_Window) WNTWin;
112 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
113 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice()
115 static Handle(Graphic3d_GraphicDevice) aGraphicDevice;
116 return aGraphicDevice;
118 static Handle(Cocoa_Window)& VT_GetWindow()
120 static Handle(Cocoa_Window) aWindow;
123 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
125 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
126 static Handle(Graphic3d_GraphicDevice) GD;
129 static Handle(Xw_Window)& VT_GetWindow(){
130 static Handle(Xw_Window) XWWin;
133 static Display *display;
135 static void VProcessEvents(ClientData,int);
138 static Standard_Boolean DegenerateMode = Standard_True;
140 #define ZCLIPWIDTH 1.
142 static void OSWindowSetup();
144 //==============================================================================
145 // EVENT GLOBAL VARIABLES
146 //==============================================================================
148 static int Start_Rot = 0;
149 static int ZClipIsOn = 0;
150 int X_Motion = 0; // Current cursor position
152 int X_ButtonPress = 0; // Last ButtonPress position
153 int Y_ButtonPress = 0;
154 Standard_Boolean IsDragged = Standard_False;
155 Standard_Boolean DragFirst;
157 //==============================================================================
160 static LRESULT WINAPI ViewerWindowProc(
165 static LRESULT WINAPI AdvViewerWindowProc(
173 //==============================================================================
176 //==============================================================================
178 const Handle(MMgt_TShared)& ViewerTest::WClass()
180 static Handle(MMgt_TShared) theWClass;
181 #if defined(_WIN32) || defined(__WIN32__)
182 if (theWClass.IsNull())
184 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
185 CS_VREDRAW | CS_HREDRAW, 0, 0,
186 ::LoadCursor (NULL, IDC_ARROW));
192 //==============================================================================
193 //function : ViewerInit
194 //purpose : Create the window viewer and initialize all the global variable
195 //==============================================================================
197 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
198 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
200 static Standard_Boolean isFirst = Standard_True;
202 // Default position and dimension of the viewer window.
203 // Note that left top corner is set to be sufficiently small to have
204 // window fit in the small screens (actual for remote desktops, see #23003).
205 // The position corresponds to the window's client area, thus some
206 // gap is added for window frame to be visible.
207 Standard_Integer aPxLeft = 20;
208 Standard_Integer aPxTop = 40;
209 Standard_Integer aPxWidth = 409;
210 Standard_Integer aPxHeight = 409;
211 if (thePxWidth != 0 && thePxHeight != 0)
215 aPxWidth = thePxWidth;
216 aPxHeight = thePxHeight;
221 // Create the Graphic device
222 #if defined(_WIN32) || defined(__WIN32__)
223 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
224 if (VT_GetWindow().IsNull())
226 // Create the Graphic device and the window
227 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
229 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
230 Handle(WNT_WClass)::DownCast (WClass()),
236 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
237 if (GetG3dDevice().IsNull())
239 GetG3dDevice() = new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
241 if (VT_GetWindow().IsNull())
243 VT_GetWindow() = new Cocoa_Window ("Test3d",
245 aPxWidth, aPxHeight);
246 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
249 if (GetG3dDevice().IsNull()) GetG3dDevice() =
250 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
251 if (VT_GetWindow().IsNull())
253 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
261 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
263 Handle(V3d_Viewer) a3DViewer, a3DCollector;
264 // Viewer and View creation
266 TCollection_ExtendedString NameOfWindow("Visu3D");
268 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
269 NameOfWindow = TCollection_ExtendedString("Collector");
270 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
271 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
272 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
273 Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
276 //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
277 aView = new NIS_View (a3DViewer, VT_GetWindow());
278 ViewerTest::CurrentView(aView);
279 TheNISContext()->AttachView (aView);
283 if ( ViewerTest::GetAISContext().IsNull() ) {
284 Handle(AIS_InteractiveContext) C =
285 new AIS_InteractiveContext(a3DViewer,a3DCollector);
286 ViewerTest::SetAISContext(C);
289 // Setup for X11 or NT
291 // Viewer and View creation
293 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
295 Handle (V3d_View) V = ViewerTest::CurrentView();
297 V->SetDegenerateModeOn();
298 DegenerateMode = V->DegenerateModeIsOn();
299 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
301 V->SetZClippingDepth(0.5);
302 V->SetZClippingWidth(ZCLIPWIDTH/2.);
303 a3DViewer->SetDefaultLights();
304 a3DViewer->SetLightOn();
306 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
307 #if TCL_MAJOR_VERSION < 8
308 Tk_CreateFileHandler((void*)ConnectionNumber(display),
309 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
311 Tk_CreateFileHandler(ConnectionNumber(display),
312 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
316 isFirst = Standard_False;
319 VT_GetWindow()->Map();
320 ViewerTest::CurrentView()->Redraw();
323 //==============================================================================
325 //purpose : Create the window viewer and initialize all the global variable
326 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
327 //==============================================================================
329 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
331 Standard_Integer aPxLeft = (argc > 1) ? Draw::Atoi (argv[1]) : 0;
332 Standard_Integer aPxTop = (argc > 2) ? Draw::Atoi (argv[2]) : 0;
333 Standard_Integer aPxWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
334 Standard_Integer aPxHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
335 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
339 //==============================================================================
340 //function : VT_ProcessKeyPress
341 //purpose : Handle KeyPress event from a CString
342 //==============================================================================
343 void VT_ProcessKeyPress (const char* buf_ret)
345 //cout << "KeyPress" << endl;
346 const Handle(V3d_View) aView = ViewerTest::CurrentView();
347 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
348 // Letter in alphabetic order
350 if ( !strcasecmp(buf_ret, "A") ) {
352 aView->SetProj(V3d_XposYnegZpos);
354 else if ( !strcasecmp(buf_ret, "D") ) {
358 else if ( !strcasecmp(buf_ret, "F") ) {
360 if (aNisView.IsNull())
363 aNisView->FitAll3d();
365 else if ( !strcasecmp(buf_ret, "H") ) {
367 cout << "HLR" << endl;
369 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
370 else aView->SetDegenerateModeOn();
371 DegenerateMode = aView->DegenerateModeIsOn();
373 else if ( !strcasecmp(buf_ret, "S") ) {
375 cout << "passage en mode 1 (shading pour les shapes)" << endl;
377 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
378 if(Ctx->NbCurrents()==0 ||
379 Ctx->NbSelected()==0)
380 Ctx->SetDisplayMode(AIS_Shaded);
382 if(Ctx->HasOpenedContext()){
383 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
384 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
387 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
388 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
390 Ctx->UpdateCurrentViewer();
393 else if ( !strcasecmp(buf_ret, "U") ) {
394 // Unset display mode
395 cout<<"passage au mode par defaut"<<endl;
397 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
398 if(Ctx->NbCurrents()==0 ||
399 Ctx->NbSelected()==0)
400 Ctx->SetDisplayMode(AIS_WireFrame);
402 if(Ctx->HasOpenedContext()){
403 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
404 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
407 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
408 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
410 Ctx->UpdateCurrentViewer();
414 else if ( !strcasecmp(buf_ret, "T") ) {
416 aView->SetProj(V3d_Zpos);
418 else if ( !strcasecmp(buf_ret, "B") ) {
420 aView->SetProj(V3d_Zneg);
422 else if ( !strcasecmp(buf_ret, "L") ) {
424 aView->SetProj(V3d_Xneg);
426 else if ( !strcasecmp(buf_ret, "R") ) {
428 aView->SetProj(V3d_Xpos);
431 else if ( !strcasecmp(buf_ret, "W") ) {
433 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
434 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
435 if(Ctx->NbCurrents()==0 ||
436 Ctx->NbSelected()==0)
437 Ctx->SetDisplayMode(AIS_WireFrame);
439 if(Ctx->HasOpenedContext()){
440 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
441 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
444 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
445 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
447 Ctx->UpdateCurrentViewer();
450 else if ( !strcasecmp(buf_ret, "Z") ) {
454 cout << "ZClipping OFF" << endl;
457 aView->SetZClippingType(V3d_OFF);
461 cout << "ZClipping ON" << endl;
464 aView->SetZClippingType(V3d_FRONT);
468 else if ( !strcasecmp(buf_ret, ",") ) {
469 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
473 else if ( !strcasecmp(buf_ret, ".") ) {
474 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
478 Standard_Integer Num = Draw::Atoi(buf_ret);
480 ViewerTest::StandardModeActivation(Num);
484 //==============================================================================
485 //function : VT_ProcessExpose
486 //purpose : Redraw the View on an Expose Event
487 //==============================================================================
488 void VT_ProcessExpose()
490 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
491 if (!aView3d.IsNull())
497 //==============================================================================
498 //function : VT_ProcessConfigure
499 //purpose : Resize the View on an Configure Event
500 //==============================================================================
501 void VT_ProcessConfigure()
503 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
504 if (aView3d.IsNull())
509 aView3d->MustBeResized();
514 //==============================================================================
515 //function : VT_ProcessButton1Press
517 //==============================================================================
518 Standard_Boolean VT_ProcessButton1Press(
521 Standard_Boolean pick,
522 Standard_Boolean shift)
524 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
526 Standard_Real X, Y, Z;
528 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
530 Draw::Set(argv[1], X);
531 Draw::Set(argv[2], Y);
532 Draw::Set(argv[3], Z);}
543 //==============================================================================
544 //function : VT_ProcessButton1Release
545 //purpose : End selecting
546 //==============================================================================
547 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
551 IsDragged = Standard_False;
552 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
555 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
556 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
560 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
561 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
566 //==============================================================================
567 //function : VT_ProcessButton3Press
568 //purpose : Start Rotation
569 //==============================================================================
570 void VT_ProcessButton3Press()
573 ViewerTest::CurrentView()->SetDegenerateModeOn();
574 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
577 //==============================================================================
578 //function : VT_ProcessButton3Release
579 //purpose : End rotation
580 //==============================================================================
581 void VT_ProcessButton3Release()
586 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
590 //==============================================================================
591 //function : ProcessZClipMotion
593 //==============================================================================
595 void ProcessZClipMotion()
597 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
598 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
599 static Standard_Real CurZPos = 0.;
601 //Quantity_Length VDX, VDY;
602 //a3DView->Size(VDX,VDY);
603 //Standard_Real VDZ = a3DView->ZSize();
604 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
606 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
608 // Front = Depth + width/2.
609 Standard_Real D = 0.5;
610 Standard_Real W = 0.1;
616 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
618 a3DView->SetZClippingType(V3d_OFF);
619 a3DView->SetZClippingDepth(D);
620 a3DView->SetZClippingWidth(W);
621 a3DView->SetZClippingType(V3d_FRONT);
625 X_ButtonPress = X_Motion;
626 Y_ButtonPress = Y_Motion;
630 //==============================================================================
631 //function : ProcessControlButton1Motion
633 //==============================================================================
635 static void ProcessControlButton1Motion()
637 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
639 X_ButtonPress = X_Motion;
640 Y_ButtonPress = Y_Motion;
643 //==============================================================================
644 //function : VT_ProcessControlButton2Motion
646 //==============================================================================
647 void VT_ProcessControlButton2Motion()
649 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
650 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
652 dy = -dy; // Xwindow Y axis is from top to Bottom
654 ViewerTest::CurrentView()->Panning( dx, dy );
656 X_ButtonPress = X_Motion;
657 Y_ButtonPress = Y_Motion;
660 //==============================================================================
661 //function : VT_ProcessControlButton3Motion
663 //==============================================================================
664 void VT_ProcessControlButton3Motion()
668 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
672 //==============================================================================
673 //function : VT_ProcessMotion
675 //==============================================================================
676 void VT_ProcessMotion()
678 //pre-hilights detected objects at mouse position
680 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
681 EM->MoveTo(X_Motion, Y_Motion);
685 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
687 Xpix = X_Motion;Ypix=Y_Motion;
690 //==============================================================================
691 //function : ViewProject: implements VAxo, VTop, VLeft, ...
692 //purpose : Switches to an axonometric, top, left and other views
693 //==============================================================================
695 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
697 if ( ViewerTest::CurrentView().IsNull() )
699 di<<"Call vinit before this command, please"<<"\n";
703 ViewerTest::CurrentView()->SetProj(ori);
707 //==============================================================================
709 //purpose : Switch to an Axonometric view
711 //==============================================================================
713 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
715 return ViewProject(di, V3d_XposYnegZpos);
718 //==============================================================================
720 //purpose : Switch to a Top View
722 //==============================================================================
724 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
726 return ViewProject(di, V3d_Zpos);
729 //==============================================================================
731 //purpose : Switch to a Bottom View
733 //==============================================================================
735 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
737 return ViewProject(di, V3d_Zneg);
740 //==============================================================================
742 //purpose : Switch to a Left View
744 //==============================================================================
746 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
748 return ViewProject(di, V3d_Ypos);
751 //==============================================================================
753 //purpose : Switch to a Right View
755 //==============================================================================
757 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
759 return ViewProject(di, V3d_Yneg);
762 //==============================================================================
764 //purpose : Switch to a Front View
766 //==============================================================================
768 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
770 return ViewProject(di, V3d_Xpos);
773 //==============================================================================
775 //purpose : Switch to a Back View
777 //==============================================================================
779 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
781 return ViewProject(di, V3d_Xneg);
784 //==============================================================================
786 //purpose : Dsiplay help on viewer Keyboead and mouse commands
788 //==============================================================================
790 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
793 di << "Q : Quit the application" << "\n";
795 di << "========================="<<"\n";
796 di << "F : FitAll" << "\n";
797 di << "T : TopView" << "\n";
798 di << "B : BottomView" << "\n";
799 di << "R : RightView" << "\n";
800 di << "L : LeftView" << "\n";
801 di << "A : AxonometricView" << "\n";
802 di << "D : ResetView" << "\n";
804 di << "========================="<<"\n";
805 di << "S : Shading" << "\n";
806 di << "W : Wireframe" << "\n";
807 di << "H : HidelLineRemoval" << "\n";
808 di << "U : Unset display mode" << "\n";
810 di << "========================="<<"\n";
811 di << "Selection mode "<<"\n";
812 di << "0 : Shape" <<"\n";
813 di << "1 : Vertex" <<"\n";
814 di << "2 : Edge" <<"\n";
815 di << "3 : Wire" <<"\n";
816 di << "4 : Face" <<"\n";
817 di << "5 : Shell" <<"\n";
818 di << "6 : Solid" <<"\n";
819 di << "7 : Compound" <<"\n";
821 di << "========================="<<"\n";
822 di << "Z : Switch Z clipping On/Off" << "\n";
823 di << ", : Hilight next detected" << "\n";
824 di << ". : Hilight previous detected" << "\n";
831 static Standard_Boolean Ppick = 0;
832 static Standard_Integer Pargc = 0;
833 static const char** Pargv = NULL;
836 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
841 if ( !ViewerTest::CurrentView().IsNull() ) {
843 WPARAM fwKeys = wParam;
848 IsDragged = Standard_False;
851 HDC hdc = GetDC( hwnd );
852 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
853 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
854 SetROP2( hdc, R2_NOT );
855 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
856 ReleaseDC( hwnd, hdc );
858 const Handle(ViewerTest_EventManager) EM =
859 ViewerTest::CurrentEventManager();
860 if ( fwKeys & MK_SHIFT )
861 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
862 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
864 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
865 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
867 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
870 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
872 IsDragged = Standard_True;
873 DragFirst = Standard_True;
874 X_ButtonPress = LOWORD(lParam);
875 Y_ButtonPress = HIWORD(lParam);
877 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
884 HDC hdc = GetDC( hwnd );
886 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
887 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
888 SetROP2( hdc, R2_NOT );
891 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
893 DragFirst = Standard_False;
894 X_Motion = LOWORD(lParam);
895 Y_Motion = HIWORD(lParam);
897 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
899 SelectObject( hdc, anObj );
901 ReleaseDC( hwnd, hdc );
904 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
908 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
912 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
916 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
921 /*static Standard_Boolean Ppick = 0;
922 static Standard_Integer Pargc = 0;
923 static char** Pargv = NULL;*/
927 if ( !ViewerTest::CurrentView().IsNull() ) {
932 // do not destroy the window - just hide it!
933 VT_GetWindow()->Unmap();
936 BeginPaint(hwnd, &ps);
942 VT_ProcessConfigure();
946 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
949 c[0] = (char) wParam;
951 VT_ProcessKeyPress (c);
959 VT_ProcessButton3Release();
966 WPARAM fwKeys = wParam;
970 X_ButtonPress = LOWORD(lParam);
971 Y_ButtonPress = HIWORD(lParam);
973 if (Msg == WM_LBUTTONDOWN)
975 if (fwKeys & MK_CONTROL)
977 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
981 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
984 else if (Msg == WM_RBUTTONDOWN)
987 VT_ProcessButton3Press();
994 //cout << "\t WM_MOUSEMOVE" << endl;
995 WPARAM fwKeys = wParam;
996 X_Motion = LOWORD(lParam);
997 Y_Motion = HIWORD(lParam);
1000 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1002 X_ButtonPress = LOWORD(lParam);
1003 Y_ButtonPress = HIWORD(lParam);
1005 if ( fwKeys & MK_RBUTTON ) {
1007 VT_ProcessButton3Press();
1011 if ( fwKeys & MK_CONTROL ) {
1012 if ( fwKeys & MK_LBUTTON ) {
1013 ProcessControlButton1Motion();
1015 else if ( fwKeys & MK_MBUTTON ||
1016 ((fwKeys&MK_LBUTTON) &&
1017 (fwKeys&MK_RBUTTON) ) ){
1018 VT_ProcessControlButton2Motion();
1020 else if ( fwKeys & MK_RBUTTON ) {
1021 VT_ProcessControlButton3Motion();
1025 else if ( fwKeys & MK_SHIFT ) {
1026 if ( fwKeys & MK_MBUTTON ||
1027 ((fwKeys&MK_LBUTTON) &&
1028 (fwKeys&MK_RBUTTON) ) ) {
1029 cout << "ProcessZClipMotion()" << endl;
1030 ProcessZClipMotion();
1035 if ((fwKeys & MK_MBUTTON
1036 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1038 ProcessZClipMotion();
1048 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1053 return DefWindowProc( hwnd, Msg, wParam, lParam );
1059 //==============================================================================
1060 //function : ViewerMainLoop
1061 //purpose : Get a Event on the view and dispatch it
1062 //==============================================================================
1065 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1068 //cout << "No yet implemented on WNT" << endl;
1069 /*static Standard_Boolean Ppick = 0;
1070 static Standard_Integer Pargc = 0;
1071 static char** Pargv = NULL;*/
1073 //Ppick = (argc > 0)? -1 : 0;
1074 Ppick = (argc > 0)? 1 : 0;
1082 cout << "Start picking" << endl;
1084 //while ( Ppick == -1 ) {
1085 while ( Ppick == 1 ) {
1086 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
1087 if (GetMessage(&msg, NULL, 0, 0) ) {
1088 TranslateMessage(&msg);
1089 DispatchMessage(&msg);
1093 cout << "Picking done" << endl;
1099 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
1101 int min( int a, int b )
1109 int max( int a, int b )
1117 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1119 { Standard_Boolean pick = argc > 0;
1123 static XEvent report;
1125 XNextEvent( display, &report );
1126 // cout << "rep type = " << report.type << endl;
1127 // cout << "rep button = " << report.xbutton.button << endl;
1129 switch ( report.type ) {
1135 case ConfigureNotify:
1137 VT_ProcessConfigure();
1146 XComposeStatus status_in_out;
1148 ret_len = XLookupString( ( XKeyEvent *)&report ,
1149 (char *) buf_ret , 10 ,
1150 &ks_ret , &status_in_out ) ;
1153 buf_ret[ret_len] = '\0' ;
1157 VT_ProcessKeyPress (buf_ret);
1162 // cout << "ButtonPress" << endl;
1164 X_ButtonPress = report.xbutton.x;
1165 Y_ButtonPress = report.xbutton.y;
1167 if (report.xbutton.button == Button1)
1169 if (report.xbutton.state & ControlMask)
1171 pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
1175 IsDragged = Standard_True;
1176 X_ButtonPress = X_ButtonPress;
1177 Y_ButtonPress = Y_ButtonPress;
1178 DragFirst = Standard_True;
1181 else if (report.xbutton.button == Button3)
1184 VT_ProcessButton3Press();
1190 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1191 // cout << IsDragged << endl;
1192 // cout << DragFirst << endl;
1198 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1199 GC gc = XCreateGC( display, aWindow, 0, 0 );
1200 // XSetFunction( display, gc, GXinvert );
1201 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1204 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1205 if( aContext.IsNull() )
1207 cout << "The context is null. Please use vinit before createmesh" << endl;
1211 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1212 if( report.xbutton.button==1 )
1216 aContext->ShiftSelect();
1217 // cout << "shift select" << endl;
1222 // cout << "select" << endl;
1227 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1228 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1229 ViewerTest::CurrentView());
1230 // cout << "shift select" << endl;
1234 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1235 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1236 ViewerTest::CurrentView() );
1237 // cout << "select" << endl;
1240 VT_ProcessButton3Release();
1242 IsDragged = Standard_False;
1245 VT_ProcessButton3Release();
1252 X_Motion = report.xmotion.x;
1253 Y_Motion = report.xmotion.y;
1257 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1258 GC gc = XCreateGC( display, aWindow, 0, 0 );
1259 XSetFunction( display, gc, GXinvert );
1262 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1264 X_Motion = X_Motion;
1265 Y_Motion = Y_Motion;
1266 DragFirst = Standard_False;
1268 //cout << "draw rect : " << X_Motion << ", " << Y_Motion << endl;
1269 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1274 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1276 // remove all the ButtonMotionMask
1277 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1279 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1280 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1282 Quantity_Length VDX, VDY;
1284 ViewerTest::CurrentView()->Size(VDX,VDY);
1285 Standard_Real VDZ =0 ;
1286 VDZ = ViewerTest::CurrentView()->ZSize();
1288 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1289 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1291 Quantity_Length dx = 0 ;
1292 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1296 dx = dx / VDX * VDZ;
1300 // Front = Depth + width/2.
1301 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1302 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1304 ViewerTest::CurrentView()->Redraw();
1308 if ( report.xmotion.state & ControlMask ) {
1309 if ( report.xmotion.state & Button1Mask ) {
1310 ProcessControlButton1Motion();
1312 else if ( report.xmotion.state & Button2Mask ) {
1313 VT_ProcessControlButton2Motion();
1315 else if ( report.xmotion.state & Button3Mask ) {
1316 VT_ProcessControlButton3Motion();
1332 //==============================================================================
1333 //function : VProcessEvents
1334 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1335 // event in the Viewer window
1336 //==============================================================================
1338 static void VProcessEvents(ClientData,int)
1340 //cout << "VProcessEvents" << endl;
1343 while (XPending(display)) {
1344 ViewerMainLoop( 0, NULL);
1349 //==============================================================================
1350 //function : OSWindowSetup
1351 //purpose : Setup for the X11 window to be able to cath the event
1352 //==============================================================================
1355 static void OSWindowSetup()
1357 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1360 Window window = VT_GetWindow()->XWindow();
1362 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1363 display = (Display * ) theDisplay;
1364 // display = (Display *)GetG3dDevice()->XDisplay();
1366 XSynchronize(display, 1);
1368 VT_GetWindow()->Map();
1370 // X11 : For keyboard on SUN
1372 wmhints.flags = InputHint;
1375 XSetWMHints( display, window, &wmhints);
1377 XSelectInput( display, window, ExposureMask | KeyPressMask |
1378 ButtonPressMask | ButtonReleaseMask |
1379 StructureNotifyMask |
1381 Button1MotionMask | Button2MotionMask |
1385 XSynchronize(display, 0);
1394 //==============================================================================
1397 //purpose : Fitall, no DRAW arguments
1398 //Draw arg : No args
1399 //==============================================================================
1401 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1403 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1404 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1405 if (V.IsNull() == Standard_False) {
1407 } else if (aView.IsNull() == Standard_False) {
1413 //==============================================================================
1415 //purpose : ZFitall, no DRAW arguments
1416 //Draw arg : No args
1417 //==============================================================================
1419 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1421 Handle(V3d_View) V = ViewerTest::CurrentView();
1422 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1425 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1427 Handle(V3d_View) V = ViewerTest::CurrentView();
1428 if ( !V.IsNull() ) V->Redraw(); return 0;
1432 //==============================================================================
1434 //purpose : Remove all the object from the viewer
1435 //Draw arg : No args
1436 //==============================================================================
1438 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1440 Handle(V3d_View) V = ViewerTest::CurrentView();
1442 ViewerTest::Clear();
1446 //==============================================================================
1449 //==============================================================================
1451 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1452 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1455 di << argv[0] << "Invalid number of arguments" << "\n";
1459 while (ViewerMainLoop( argc, argv)) {
1465 //==============================================================================
1466 //function : InitViewerTest
1467 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1468 //==============================================================================
1470 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1472 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1473 ViewerTest::SetAISContext(context);
1474 viewer->InitActiveViews();
1475 Handle(V3d_View) view = viewer->ActiveView();
1476 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1477 ViewerTest::ResetEventManager();
1478 Handle(Aspect_GraphicDevice) device = viewer->Device();
1479 Handle(Aspect_Window) window = view->Window();
1480 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1482 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1483 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1485 static int first = 1;
1487 #if TCL_MAJOR_VERSION < 8
1488 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1489 TK_READABLE, VProcessEvents, (ClientData) 0);
1491 Tk_CreateFileHandler(ConnectionNumber(display),
1492 TK_READABLE, VProcessEvents, (ClientData) 0);
1499 //==============================================================================
1501 //purpose : Load image as background
1502 //==============================================================================
1504 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1506 if (argc < 2 || argc > 3)
1508 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1509 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1513 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1514 if(AISContext.IsNull())
1516 di << "use 'vinit' command before " << argv[0] << "\n";
1520 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1523 const char* szType = argv[2];
1524 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1525 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1526 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1527 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1530 di << "Wrong fill type : " << szType << "\n";
1531 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1536 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1537 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1542 //==============================================================================
1543 //function : VSetBgMode
1544 //purpose : Change background image fill type
1545 //==============================================================================
1547 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1551 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1552 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1556 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1557 if(AISContext.IsNull())
1559 di << "use 'vinit' command before " << argv[0] << "\n";
1563 Aspect_FillMethod aFillType;
1566 const char* szType = argv[1];
1567 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1568 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1569 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1570 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1573 di << "Wrong fill type : " << szType << "\n";
1574 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1579 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1580 V3dView->SetBgImageStyle(aFillType, Standard_True);
1585 //==============================================================================
1586 //function : VSetGradientBg
1587 //purpose : Mount gradient background
1588 //==============================================================================
1589 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1593 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1594 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1595 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1596 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1600 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1601 if(AISContext.IsNull())
1603 di << "use 'vinit' command before " << argv[0] << "\n";
1609 Standard_Real R1 = Draw::Atof(argv[1])/255.;
1610 Standard_Real G1 = Draw::Atof(argv[2])/255.;
1611 Standard_Real B1 = Draw::Atof(argv[3])/255.;
1612 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1614 Standard_Real R2 = Draw::Atof(argv[4])/255.;
1615 Standard_Real G2 = Draw::Atof(argv[5])/255.;
1616 Standard_Real B2 = Draw::Atof(argv[6])/255.;
1618 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1619 int aType = Draw::Atoi(argv[7]);
1620 if( aType < 0 || aType > 8 )
1622 di << "Wrong fill type " << "\n";
1623 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1624 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1628 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1630 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1631 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1637 //==============================================================================
1638 //function : VSetGradientBgMode
1639 //purpose : Change gradient background fill style
1640 //==============================================================================
1641 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1645 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1646 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1647 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1651 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1652 if(AISContext.IsNull())
1654 di << "use 'vinit' command before " << argv[0] << "\n";
1659 int aType = Draw::Atoi(argv[1]);
1660 if( aType < 0 || aType > 8 )
1662 di << "Wrong fill type " << "\n";
1663 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1664 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1668 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1670 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1671 V3dView->SetBgGradientStyle( aMethod, 1 );
1677 //==============================================================================
1678 //function : VSetColorBg
1679 //purpose : Set color background
1680 //==============================================================================
1681 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1685 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1686 di << "R,G,B = [0..255]" << "\n";
1690 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1691 if(AISContext.IsNull())
1693 di << "use 'vinit' command before " << argv[0] << "\n";
1699 Standard_Real R = Draw::Atof(argv[1])/255.;
1700 Standard_Real G = Draw::Atof(argv[2])/255.;
1701 Standard_Real B = Draw::Atof(argv[3])/255.;
1702 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1704 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1705 V3dView->SetBackgroundColor( aColor );
1712 //==============================================================================
1714 //purpose : View Scaling
1715 //==============================================================================
1717 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1719 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1720 if ( V3dView.IsNull() ) return 1;
1723 di << argv[0] << "Invalid number of arguments" << "\n";
1726 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1729 //==============================================================================
1730 //function : VTestZBuffTrihedron
1731 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1732 //==============================================================================
1734 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1736 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1737 if ( V3dView.IsNull() ) return 1;
1739 V3dView->ZBufferTriedronSetup();
1742 // Set up default trihedron parameters
1743 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1747 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1748 const char* aPosType = argv[1];
1750 if ( strcmp(aPosType, "center") == 0 )
1752 aPosition = Aspect_TOTP_CENTER;
1754 if (strcmp(aPosType, "left_lower") == 0)
1756 aPosition = Aspect_TOTP_LEFT_LOWER;
1758 if (strcmp(aPosType, "left_upper") == 0)
1760 aPosition = Aspect_TOTP_LEFT_UPPER;
1762 if (strcmp(aPosType, "right_lower") == 0)
1764 aPosition = Aspect_TOTP_RIGHT_LOWER;
1766 if (strcmp(aPosType, "right_upper") == 0)
1768 aPosition = Aspect_TOTP_RIGHT_UPPER;
1771 di << argv[1] << " Invalid type of alignment" << "\n";
1772 di << "Must be one of [ center, left_lower," << "\n";
1773 di << "left_upper, right_lower, right_upper ]" << "\n";
1777 Standard_Real R = Draw::Atof(argv[2])/255.;
1778 Standard_Real G = Draw::Atof(argv[3])/255.;
1779 Standard_Real B = Draw::Atof(argv[4])/255.;
1780 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1782 Standard_Real aScale = Draw::Atof(argv[5]);
1786 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1790 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1791 const char* aPresType = argv[6];
1793 if ( strcmp(aPresType, "wireframe") == 0 )
1795 aPresentation = V3d_WIREFRAME;
1797 if (strcmp(aPresType, "zbuffer") == 0)
1799 aPresentation = V3d_ZBUFFER;
1802 di << argv[6] << " Invalid type of visualization" << "\n";
1803 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1807 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1811 di << argv[0] << " Invalid number of arguments" << "\n";
1820 //==============================================================================
1821 //function : VRotate
1822 //purpose : Camera Rotating
1823 //==============================================================================
1825 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1826 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1827 if ( V3dView.IsNull() ) {
1832 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1834 } else if ( argc == 7 ) {
1835 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]) );
1838 di << argv[0] << " Invalid number of arguments" << "\n";
1843 //==============================================================================
1845 //purpose : View zoom in / out (relative to current zoom)
1846 //==============================================================================
1848 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1849 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1850 if ( V3dView.IsNull() ) {
1855 Standard_Real coef = Draw::Atof(argv[1]);
1856 if ( coef <= 0.0 ) {
1857 di << argv[1] << "Invalid value" << "\n";
1860 V3dView->SetZoom( Draw::Atof(argv[1]) );
1863 di << argv[0] << " Invalid number of arguments" << "\n";
1868 //==============================================================================
1870 //purpose : View panning (in pixels)
1871 //==============================================================================
1873 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1874 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1875 if ( V3dView.IsNull() ) return 1;
1878 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
1881 di << argv[0] << " Invalid number of arguments" << "\n";
1887 //==============================================================================
1888 //function : VExport
1889 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1890 //==============================================================================
1892 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1894 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1895 if (V3dView.IsNull())
1900 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1904 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1905 TCollection_AsciiString aFormatStr;
1907 TCollection_AsciiString aFileName (argv[1]);
1908 Standard_Integer aLen = aFileName.Length();
1912 aFormatStr = TCollection_AsciiString (argv[2]);
1916 if (aFileName.Value (aLen - 2) == '.')
1918 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1920 else if (aFileName.Value (aLen - 3) == '.')
1922 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1926 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1932 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1936 aFormatStr.UpperCase();
1937 if (aFormatStr == "PS")
1938 anExpFormat = Graphic3d_EF_PostScript;
1939 else if (aFormatStr == "EPS")
1940 anExpFormat = Graphic3d_EF_EnhPostScript;
1941 else if (aFormatStr == "TEX")
1942 anExpFormat = Graphic3d_EF_TEX;
1943 else if (aFormatStr == "PDF")
1944 anExpFormat = Graphic3d_EF_PDF;
1945 else if (aFormatStr == "SVG")
1946 anExpFormat = Graphic3d_EF_SVG;
1947 else if (aFormatStr == "PGF")
1948 anExpFormat = Graphic3d_EF_PGF;
1949 else if (aFormatStr == "EMF")
1950 anExpFormat = Graphic3d_EF_EMF;
1953 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1957 if (!V3dView->View()->Export (argv[1], anExpFormat))
1959 std::cout << "Export failed!\n";
1965 //==============================================================================
1966 //function : VColorScale
1967 //purpose : representation color scale
1968 //==============================================================================
1969 #include <V3d_ColorScale.hxx>
1971 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1973 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1975 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1979 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1980 if(aContext.IsNull()) {
1981 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1985 Standard_Real minRange = 0. , maxRange = 100. ;
1987 Standard_Integer numIntervals = 10 ;
1988 Standard_Integer textHeight = 16;
1989 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1990 Standard_Real X = 0., Y = 0. ;
1996 minRange = Draw::Atof( argv[1] );
1997 maxRange = Draw::Atof( argv[2] );
1998 numIntervals = Draw::Atoi( argv[3] );
2001 textHeight = Draw::Atoi( argv[4] );
2003 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2006 X = Draw::Atof( argv[6] );
2007 Y = Draw::Atof( argv[7] );
2010 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2011 if ( curView.IsNull( ) )
2013 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2014 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2015 if( ! aCS.IsNull( ) )
2017 aCS->SetPosition( X , Y );
2018 aCS->SetHeight( 0.95) ;
2019 aCS->SetTextHeight( textHeight );
2020 aCS->SetRange( minRange , maxRange );
2021 aCS->SetNumberOfIntervals( numIntervals );
2022 aCS->SetLabelPosition( position );
2023 if( !curView->ColorScaleIsDisplayed() )
2024 curView->ColorScaleDisplay( );
2029 //==============================================================================
2030 //function : VGraduatedTrihedron
2031 //purpose : Displays a graduated trihedron
2032 //==============================================================================
2034 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2036 const char *str = arg;
2039 unsigned short c1 = *str++;
2040 unsigned short c2 = *str++;
2041 if (!c1 || !c2) break;
2042 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2046 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2049 if (argc != 2 && argc < 5)
2051 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2052 di<<"Usage: type help "<<argv[0]<<"\n";
2053 return 1; //TCL_ERROR
2056 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2058 // Create 3D view if it doesn't exist
2059 if ( aV3dView.IsNull() )
2061 ViewerTest::ViewerInit();
2062 aV3dView = ViewerTest::CurrentView();
2063 if( aV3dView.IsNull() )
2065 di << "Error: Cannot create a 3D view\n";
2066 return 1; //TCL_ERROR
2070 // Erase (==0) or display (!=0)
2071 const int display = Draw::Atoi(argv[1]);
2076 TCollection_AsciiString font;
2078 font.AssignCat("Courier");
2080 font.AssignCat(argv[5]);
2082 // Text is multibyte
2083 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
2086 TCollection_ExtendedString xname, yname, zname;
2091 AddMultibyteString(xname, argv[2]);
2092 AddMultibyteString(yname, argv[3]);
2093 AddMultibyteString(zname, argv[4]);
2109 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2110 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2111 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2112 Standard_True/*drawgrid*/,
2113 Standard_True/*drawaxes*/,
2114 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2115 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2116 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2117 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2118 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2119 Quantity_NOC_WHITE/*gridcolor*/,
2120 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2121 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2124 aV3dView->GraduatedTrihedronErase();
2126 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2132 //==============================================================================
2133 //function : VPrintView
2134 //purpose : Test printing algorithm, print the view to image file with given
2135 // width and height. Printing implemented only for WNT.
2136 //==============================================================================
2137 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2141 di << "Printing implemented only for wnt!\n";
2145 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2146 Handle(V3d_View) aView = NULL;
2147 aContextAIS = ViewerTest::GetAISContext();
2148 if (!aContextAIS.IsNull())
2150 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2151 Vwr->InitActiveViews();
2152 if(Vwr->MoreActiveViews())
2153 aView = Vwr->ActiveView();
2159 di << "Call vinit before!\n";
2164 di << "Use: " << argv[0];
2165 di << " width height filename [print algo=0]\n";
2166 di << "width, height of the intermediate buffer for operation\n";
2167 di << "algo : {0|1}\n";
2168 di << " 0 - stretch algorithm\n";
2169 di << " 1 - tile algorithm\n";
2170 di << "test printing algorithms into an intermediate buffer\n";
2171 di << "with saving output to an image file\n";
2175 // get the input params
2176 Standard_Integer aWidth = Draw::Atoi (argv[1]);
2177 Standard_Integer aHeight = Draw::Atoi (argv[2]);
2178 Standard_Integer aMode = 0;
2179 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2181 aMode = Draw::Atoi (argv[4]);
2183 // check the input parameters
2184 if (aWidth <= 0 || aHeight <= 0)
2186 di << "Width and height must be positive values!\n";
2189 if (aMode != 0 && aMode != 1)
2192 // define compatible bitmap
2193 HDC anDC = CreateCompatibleDC(0);
2194 BITMAPINFO aBitmapData;
2195 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2196 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2197 aBitmapData.bmiHeader.biWidth = aWidth ;
2198 aBitmapData.bmiHeader.biHeight = aHeight;
2199 aBitmapData.bmiHeader.biPlanes = 1;
2200 aBitmapData.bmiHeader.biBitCount = 24;
2201 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2202 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2203 aBitmapData.bmiHeader.biClrUsed = 0;
2204 aBitmapData.bmiHeader.biClrImportant = 0;
2205 aBitmapData.bmiHeader.biCompression = BI_RGB;
2206 aBitmapData.bmiHeader.biSizeImage = 0;
2208 // Create Device Independent Bitmap
2209 void* aBitsOut = NULL;
2210 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2211 &aBitsOut, NULL, 0);
2212 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2214 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2215 if (aBitsOut != NULL)
2218 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2220 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2222 // succesfully printed into an intermediate buffer
2225 Image_PixMap aWrapper;
2226 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2227 aWrapper.SetTopDown (false);
2229 Image_AlienPixMap anImageBitmap;
2230 anImageBitmap.InitCopy (aWrapper);
2231 isSaved = anImageBitmap.Save (aFileName);
2235 di << "Print operation failed due to printing errors or\n";
2236 di << "insufficient memory available\n";
2237 di << "Please, try to use smaller dimensions for this test\n";
2238 di << "command, as it allocates intermediate buffer for storing\n";
2239 di << "the result\n";
2244 di << "Can't allocate memory for intermediate buffer\n";
2245 di << "Please use smaller dimensions\n";
2250 SelectObject (anDC, anOldBitmap);
2251 DeleteObject (aMemoryBitmap);
2257 di << "Save to file operation failed. This operation may fail\n";
2258 di << "if you don't have enough available memory, then you can\n";
2259 di << "use smaller dimensions for the output file\n";
2268 //==============================================================================
2269 //function : VZLayer
2270 //purpose : Test z layer operations for v3d viewer
2271 //==============================================================================
2272 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2274 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2275 if (aContextAIS.IsNull())
2277 di << "Call vinit before!\n";
2282 di << "Use: vzlayer " << argv[0];
2283 di << " add/del/get [id]\n";
2284 di << " add - add new z layer to viewer and print its id\n";
2285 di << " del - del z layer by its id\n";
2286 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2287 di << "id - the layer identificator value defined when removing z layer\n";
2291 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2292 if (aViewer.IsNull())
2294 di << "No active viewer!\n";
2298 // perform operation
2299 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2302 Standard_Integer aNewId;
2303 if (!aViewer->AddZLayer (aNewId))
2305 di << "Impossible to add new z layer!\n";
2309 di << "New z layer added with index: " << aNewId << "\n";
2311 else if (anOp == "del")
2315 di << "Please also provide as argument id of z layer to remove\n";
2319 Standard_Integer aDelId = Draw::Atoi (argv[2]);
2320 if (!aViewer->RemoveZLayer (aDelId))
2322 di << "Impossible to remove the z layer or invalid id!\n";
2326 di << "Z layer " << aDelId << " has been removed\n";
2328 else if (anOp == "get")
2330 TColStd_SequenceOfInteger anIds;
2331 aViewer->GetAllZLayers (anIds);
2332 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2334 di << anIds.Value (aSeqIdx) << " ";
2341 di << "Invalid operation, please use { add / del / get }\n";
2348 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2350 // this class provides a presentation of text item in v3d view under-/overlayer
2351 class V3d_TextItem : public Visual3d_LayerItem
2356 DEFINE_STANDARD_RTTI(V3d_TextItem)
2359 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2360 const Standard_Real theX1,
2361 const Standard_Real theY1,
2362 const Standard_Real theHeight,
2363 const TCollection_AsciiString& theFontName,
2364 const Quantity_Color& theColor,
2365 const Quantity_Color& theSubtitleColor,
2366 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2367 const Handle(Visual3d_Layer)& theLayer);
2370 Standard_EXPORT void RedrawLayerPrs();
2376 Standard_Real myHeight;
2377 TCollection_AsciiString myText;
2378 TCollection_AsciiString myFontName;
2379 Quantity_Color myColor;
2380 Quantity_Color mySubtitleColor;
2381 Aspect_TypeOfDisplayText myType;
2382 Handle(Visual3d_Layer) myLayer;
2386 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2387 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2389 // create and add to display the text item
2390 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2391 const Standard_Real theX1,
2392 const Standard_Real theY1,
2393 const Standard_Real theHeight,
2394 const TCollection_AsciiString& theFontName,
2395 const Quantity_Color& theColor,
2396 const Quantity_Color& theSubtitleColor,
2397 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2398 const Handle(Visual3d_Layer)& theLayer)
2399 : myX1 (theX1), myY1 (theY1),
2401 myHeight (theHeight),
2404 mySubtitleColor (theSubtitleColor),
2405 myType (theTypeOfDisplay),
2406 myFontName (theFontName)
2408 if (!myLayer.IsNull ())
2409 myLayer->AddLayerItem (this);
2413 void V3d_TextItem::RedrawLayerPrs ()
2415 if (myLayer.IsNull ())
2418 myLayer->SetColor (myColor);
2419 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2420 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2423 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2425 // The Visual3d_LayerItem line item for "vlayerline" command
2426 // it provides a presentation of line with user-defined
2427 // linewidth, linetype and transparency.
2428 class V3d_LineItem : public Visual3d_LayerItem
2432 DEFINE_STANDARD_RTTI(V3d_LineItem)
2435 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2436 Standard_Real X2, Standard_Real Y2,
2437 V3d_LayerMgrPointer theLayerMgr,
2438 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2439 Standard_Real theWidth = 0.5,
2440 Standard_Real theTransp = 1.0);
2443 Standard_EXPORT void RedrawLayerPrs();
2447 Standard_Real myX1, myY1, myX2, myY2;
2448 Standard_Real myWidth;
2449 Standard_Real myTransparency;
2450 Aspect_TypeOfLine myType;
2451 V3d_LayerMgrPointer myLayerMgr;
2454 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2455 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2457 // default constructor for line item
2458 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2459 Standard_Real X2, Standard_Real Y2,
2460 V3d_LayerMgrPointer theLayerMgr,
2461 Aspect_TypeOfLine theType,
2462 Standard_Real theWidth,
2463 Standard_Real theTransp) :
2464 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2465 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2467 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
2468 myLayerMgr->Overlay()->AddLayerItem (this);
2472 void V3d_LineItem::RedrawLayerPrs ()
2474 Handle (Visual3d_Layer) aOverlay;
2477 aOverlay = myLayerMgr->Overlay();
2479 if (!aOverlay.IsNull())
2481 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2482 aOverlay->SetColor(aColor);
2483 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2484 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2485 aOverlay->BeginPolyline();
2486 aOverlay->AddVertex(myX1, myY1);
2487 aOverlay->AddVertex(myX2, myY2);
2488 aOverlay->ClosePrimitive();
2492 //=============================================================================
2493 //function : VLayerLine
2494 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2495 // : linewidth, transparency coefficient
2496 //============================================================================
2497 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2499 // get the active view
2500 Handle(V3d_View) aView = ViewerTest::CurrentView();
2503 di << "Call vinit before!\n";
2508 di << "Use: " << argv[0];
2509 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2510 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2511 di << " 0 - solid \n";
2512 di << " 1 - dashed \n";
2513 di << " 2 - dot \n";
2514 di << " 3 - dashdot\n";
2515 di << " transparency : { 0.0 - 1.0 } \n";
2516 di << " 0.0 - transparent\n";
2517 di << " 1.0 - visible \n";
2521 // get the input params
2522 Standard_Real X1 = Draw::Atof(argv[1]);
2523 Standard_Real Y1 = Draw::Atof(argv[2]);
2524 Standard_Real X2 = Draw::Atof(argv[3]);
2525 Standard_Real Y2 = Draw::Atof(argv[4]);
2527 Standard_Real aWidth = 0.5;
2528 Standard_Integer aType = 0;
2529 Standard_Real aTransparency = 1.0;
2533 aWidth = Draw::Atof(argv[5]);
2537 aType = (Standard_Integer) Draw::Atoi(argv[6]);
2542 aTransparency = Draw::Atof(argv[7]);
2543 if (aTransparency < 0 || aTransparency > 1.0)
2544 aTransparency = 1.0;
2547 // select appropriate line type
2548 Aspect_TypeOfLine aLineType;
2552 aLineType = Aspect_TOL_DASH;
2556 aLineType = Aspect_TOL_DOT;
2560 aLineType = Aspect_TOL_DOTDASH;
2564 aLineType = Aspect_TOL_SOLID;
2567 // replace layer manager
2568 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2569 aView->SetLayerMgr(aMgr);
2572 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2578 aView->MustBeResized();
2584 //=======================================================================
2585 //function : VOverlayText
2586 //purpose : Test text displaying in view overlay
2587 //=======================================================================
2588 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2590 // get the active view
2591 Handle(V3d_View) aView = ViewerTest::CurrentView();
2594 di << "No active view. Please call vinit.\n";
2597 else if (argc < 4 || argc > 13)
2599 di << "Use: " << argv[0];
2600 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2601 di << "[background_color: R G B]\n";
2602 di << " height - pixel height of the text (default=10.0)\n";
2603 di << " font_name - name of font (default=courier)\n";
2604 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2605 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2606 di << " background_color- R G B values used for subtitle and decal text\n";
2607 di << "(default=255.0 255.0 255.0)\n";
2611 TCollection_AsciiString aText (argv[1]);
2612 Standard_Real aPosX = Draw::Atof(argv[2]);
2613 Standard_Real aPosY = Draw::Atof(argv[3]);
2614 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
2617 TCollection_AsciiString aFontName = "Courier";
2619 aFontName = TCollection_AsciiString (argv[5]);
2622 Quantity_Parameter aColorRed = 1.0;
2623 Quantity_Parameter aColorGreen = 1.0;
2624 Quantity_Parameter aColorBlue = 1.0;
2627 aColorRed = Draw::Atof (argv[6])/255.;
2628 aColorGreen = Draw::Atof (argv[7])/255.;
2629 aColorBlue = Draw::Atof (argv[8])/255.;
2633 TCollection_AsciiString aDispStr;
2635 aDispStr = TCollection_AsciiString (argv[9]);
2637 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2638 if (aDispStr.IsEqual ("subtitle"))
2639 aTextType = Aspect_TODT_SUBTITLE;
2640 else if (aDispStr.IsEqual ("decal"))
2641 aTextType = Aspect_TODT_DEKALE;
2642 else if (aDispStr.IsEqual ("blend"))
2643 aTextType = Aspect_TODT_BLEND;
2646 Quantity_Parameter aSubRed = 1.0;
2647 Quantity_Parameter aSubGreen = 1.0;
2648 Quantity_Parameter aSubBlue = 1.0;
2651 aSubRed = Draw::Atof (argv[10])/255.;
2652 aSubGreen = Draw::Atof (argv[11])/255.;
2653 aSubBlue = Draw::Atof (argv[12])/255.;
2656 // check fo current overlay
2657 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2658 if (anOverlay.IsNull ())
2660 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2661 anOverlay = aMgr->Overlay ();
2662 aView->SetLayerMgr (aMgr);
2665 Quantity_Color aTextColor (aColorRed, aColorGreen,
2666 aColorBlue, Quantity_TOC_RGB);
2667 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2668 aSubBlue, Quantity_TOC_RGB);
2671 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2672 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2675 aView->MustBeResized();
2681 //==============================================================================
2684 //==============================================================================
2686 static int VGrid (Draw_Interpretor& theDI,
2687 Standard_Integer theArgNb,
2688 const char** theArgVec)
2690 // get the active view
2691 Handle(V3d_View) aView = ViewerTest::CurrentView();
2692 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2693 if (aView.IsNull() || aViewer.IsNull())
2695 std::cerr << "No active view. Please call vinit.\n";
2699 Aspect_GridType aType = aViewer->GridType();
2700 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2702 Standard_Integer anIter = 1;
2703 for (; anIter < theArgNb; ++anIter)
2705 const char* aValue = theArgVec[anIter];
2708 aType = Aspect_GT_Rectangular;
2710 else if (*aValue == 'c')
2712 aType = Aspect_GT_Circular;
2714 else if (*aValue == 'l')
2716 aMode = Aspect_GDM_Lines;
2718 else if (*aValue == 'p')
2720 aMode = Aspect_GDM_Points;
2722 else if (strcmp (aValue, "off" ) == 0)
2724 aViewer->DeactivateGrid();
2733 Standard_Integer aTail = (theArgNb - anIter);
2736 aViewer->ActivateGrid (aType, aMode);
2739 else if (aTail != 2 && aTail != 5)
2741 std::cerr << "Incorrect arguments number! Usage:\n"
2742 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2746 Quantity_Length anOriginX, anOriginY;
2747 Quantity_PlaneAngle aRotAngle;
2748 if (aType == Aspect_GT_Rectangular)
2750 Quantity_Length aRStepX, aRStepY;
2751 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2753 anOriginX = Draw::Atof (theArgVec[anIter++]);
2754 anOriginY = Draw::Atof (theArgVec[anIter++]);
2757 aRStepX = Draw::Atof (theArgVec[anIter++]);
2758 aRStepY = Draw::Atof (theArgVec[anIter++]);
2759 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2761 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2762 aViewer->ActivateGrid (aType, aMode);
2764 else if (aType == Aspect_GT_Circular)
2766 Quantity_Length aRadiusStep;
2767 Standard_Integer aDivisionNumber;
2768 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2770 anOriginX = Draw::Atof (theArgVec[anIter++]);
2771 anOriginY = Draw::Atof (theArgVec[anIter++]);
2774 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
2775 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
2776 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2779 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2780 aViewer->ActivateGrid (aType, aMode);
2786 //==============================================================================
2789 //==============================================================================
2791 static int VFps (Draw_Interpretor& theDI,
2792 Standard_Integer theArgNb,
2793 const char** theArgVec)
2795 // get the active view
2796 Handle(V3d_View) aView = ViewerTest::CurrentView();
2799 std::cerr << "No active view. Please call vinit.\n";
2803 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
2806 std::cerr << "Incorrect arguments!\n";
2810 // the time is meaningless for first call
2811 // due to async OpenGl rendering
2814 // redraw view in loop to estimate average values
2817 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2823 const Standard_Real aTime = aTimer.ElapsedTime();
2824 aTimer.OSD_Chronometer::Show (aCpu);
2826 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2827 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2829 // return statistics
2830 theDI << "FPS: " << aFpsAver << "\n"
2831 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2837 //==============================================================================
2840 //==============================================================================
2842 static int VVbo (Draw_Interpretor& theDI,
2843 Standard_Integer theArgNb,
2844 const char** theArgVec)
2847 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2848 if (aContextAIS.IsNull())
2850 std::cerr << "No active view. Please call vinit.\n";
2854 Handle(Graphic3d_GraphicDriver) aDriver =
2855 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2856 if (aDriver.IsNull())
2858 std::cerr << "Graphic driver not available.\n";
2864 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2866 std::cerr << "Wrong number of arguments.\n";
2870 aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
2874 //==============================================================================
2875 //function : VMemGpu
2877 //==============================================================================
2879 static int VMemGpu (Draw_Interpretor& theDI,
2880 Standard_Integer theArgNb,
2881 const char** theArgVec)
2884 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2885 if (aContextAIS.IsNull())
2887 std::cerr << "No active view. Please call vinit.\n";
2891 Handle(Graphic3d_GraphicDriver) aDriver =
2892 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2893 if (aDriver.IsNull())
2895 std::cerr << "Graphic driver not available.\n";
2899 Standard_Size aFreeBytes = 0;
2900 TCollection_AsciiString anInfo;
2901 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
2903 std::cerr << "Information not available.\n";
2907 if (theArgNb > 1 && *theArgVec[1] == 'f')
2909 theDI << Standard_Real (aFreeBytes);
2919 // ==============================================================================
2920 // function : VReadPixel
2922 // ==============================================================================
2923 static int VReadPixel (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";
2934 else if (theArgNb < 3)
2936 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
2940 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2941 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
2943 Standard_Integer aWidth, aHeight;
2944 aView->Window()->Size (aWidth, aHeight);
2945 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
2946 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
2947 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
2949 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
2953 Standard_Boolean toShowName = Standard_False;
2954 Standard_Boolean toShowHls = Standard_False;
2955 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
2957 TCollection_AsciiString aParam (theArgVec[anIter]);
2958 if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb")))
2960 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2961 aBufferType = Graphic3d_BT_RGB;
2963 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
2965 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2966 aBufferType = Graphic3d_BT_RGB;
2967 toShowHls = Standard_True;
2969 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
2971 aFormat = Image_PixMap::ImgRGBF;
2972 aBufferType = Graphic3d_BT_RGB;
2974 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
2976 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2977 aBufferType = Graphic3d_BT_RGBA;
2979 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
2981 aFormat = Image_PixMap::ImgRGBAF;
2982 aBufferType = Graphic3d_BT_RGBA;
2984 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
2986 aFormat = Image_PixMap::ImgGrayF;
2987 aBufferType = Graphic3d_BT_Depth;
2989 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
2991 toShowName = Standard_True;
2995 Image_PixMap anImage;
2996 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
2998 std::cerr << "Image allocation failed\n";
3001 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
3003 std::cerr << "Image dump failed\n";
3007 Quantity_Parameter anAlpha;
3008 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
3011 if (aBufferType == Graphic3d_BT_RGBA)
3013 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3017 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3022 switch (aBufferType)
3025 case Graphic3d_BT_RGB:
3029 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3033 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3037 case Graphic3d_BT_RGBA:
3039 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3042 case Graphic3d_BT_Depth:
3044 theDI << aColor.Red() << "\n";
3053 //==============================================================================
3054 //function : VDiffImage
3055 //purpose : The draw-command compares two images.
3056 //==============================================================================
3058 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3062 theDI << "Not enough arguments.\n";
3067 const char* anImgPathRef = theArgVec[1];
3068 const char* anImgPathNew = theArgVec[2];
3070 // get string tolerance and check its validity
3071 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
3072 if (aTolColor < 0.0)
3074 if (aTolColor > 1.0)
3077 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
3078 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
3080 // image file of difference
3081 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3083 // compare the images
3084 Image_Diff aComparer;
3085 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3090 aComparer.SetColorTolerance (aTolColor);
3091 aComparer.SetBorderFilterOn (isBorderFilterOn);
3092 Standard_Integer aDiffColorsNb = aComparer.Compare();
3093 theDI << aDiffColorsNb << "\n";
3095 // save image of difference
3096 if (aDiffImagePath != NULL)
3098 aComparer.SaveDiffImage (aDiffImagePath);
3104 //=======================================================================
3105 //function : VSelect
3106 //purpose : Emulates different types of selection by mouse:
3107 // 1) single click selection
3108 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
3109 // 3) selection with polygon having corners at
3110 // pixel positions (x1,y1),...,(xn,yn)
3111 // 4) any of these selections with shift button pressed
3112 //=======================================================================
3113 static Standard_Integer VSelect (Draw_Interpretor& di,
3114 Standard_Integer argc,
3119 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
3123 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
3124 if(myAIScontext.IsNull())
3126 di << "use 'vinit' command before " << argv[0] << "\n";
3129 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
3130 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
3131 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
3134 if(isShiftSelection)
3135 aCurrentEventManager->ShiftSelect();
3137 aCurrentEventManager->Select();
3141 if(isShiftSelection)
3142 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3144 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3148 Standard_Integer anUpper = 0;
3150 if(isShiftSelection)
3151 anUpper = (argc-1)/2;
3154 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
3156 for(Standard_Integer i=1;i<=anUpper;++i)
3157 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
3159 if(isShiftSelection)
3160 aCurrentEventManager->ShiftSelect(aPolyline);
3162 aCurrentEventManager->Select(aPolyline);
3167 //=======================================================================
3168 //function : VMoveTo
3169 //purpose : Emulates cursor movement to defined pixel position
3170 //=======================================================================
3171 static Standard_Integer VMoveTo (Draw_Interpretor& di,
3172 Standard_Integer argc,
3177 di << "Usage : " << argv[0] << " x y" << "\n";
3181 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3182 if(aContext.IsNull())
3184 di << "use 'vinit' command before " << argv[0] << "\n";
3187 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
3191 //=======================================================================
3192 //function : VViewParams
3193 //purpose : Gets or sets AIS View characteristics
3194 //=======================================================================
3195 static Standard_Integer VViewParams (Draw_Interpretor& di,
3196 Standard_Integer argc,
3199 if ( argc != 1 && argc != 13)
3201 di << "Usage : " << argv[0] << "\n";
3204 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
3205 if ( anAISView.IsNull () )
3207 di << "use 'vinit' command before " << argv[0] << "\n";
3211 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
3212 Standard_Real anAISViewCenterCoordinateX = 0.0;
3213 Standard_Real anAISViewCenterCoordinateY = 0.0;
3214 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3215 Standard_Real anAISViewProjX = 0.0;
3216 Standard_Real anAISViewProjY = 0.0;
3217 Standard_Real anAISViewProjZ = 0.0;
3218 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3219 Standard_Real anAISViewUpX = 0.0;
3220 Standard_Real anAISViewUpY = 0.0;
3221 Standard_Real anAISViewUpZ = 0.0;
3222 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3223 Standard_Real anAISViewAtX = 0.0;
3224 Standard_Real anAISViewAtY = 0.0;
3225 Standard_Real anAISViewAtZ = 0.0;
3226 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3227 di << "Scale of current view: " << anAISViewScale << "\n";
3228 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
3229 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
3230 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
3231 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
3235 Quantity_Factor anAISViewScale = atof (argv [1]);
3236 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
3237 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
3238 Standard_Real anAISViewProjX = atof (argv [4]);
3239 Standard_Real anAISViewProjY = atof (argv [5]);
3240 Standard_Real anAISViewProjZ = atof (argv [6]);
3241 Standard_Real anAISViewUpX = atof (argv [7]);
3242 Standard_Real anAISViewUpY = atof (argv [8]);
3243 Standard_Real anAISViewUpZ = atof (argv [9]);
3244 Standard_Real anAISViewAtX = atof (argv [10]);
3245 Standard_Real anAISViewAtY = atof (argv [11]);
3246 Standard_Real anAISViewAtZ = atof (argv [12]);
3247 anAISView -> V3d_View::SetScale (anAISViewScale);
3248 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3249 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3250 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3251 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3256 //=======================================================================
3257 //function : VChangeSelected
3258 //purpose : Adds the shape to selection or remove one from it
3259 //=======================================================================
3260 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
3261 Standard_Integer argc,
3266 di<<"Usage : " << argv[0] << " shape \n";
3270 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3271 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3272 TCollection_AsciiString aName(argv[1]);
3273 Handle(AIS_InteractiveObject) anAISObject;
3275 if(!aMap.IsBound2(aName))
3277 di<<"Use 'vdisplay' before";
3282 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
3283 if(anAISObject.IsNull()){
3284 di<<"No interactive object \n";
3288 if(aContext->HasOpenedContext())
3290 aContext->AddOrRemoveSelected(anAISObject);
3294 aContext->AddOrRemoveCurrentObject(anAISObject);
3300 //=======================================================================
3301 //function : VZClipping
3302 //purpose : Gets or sets ZClipping mode, width and depth
3303 //=======================================================================
3304 static Standard_Integer VZClipping (Draw_Interpretor& di,
3305 Standard_Integer argc,
3310 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3311 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3314 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3315 if(aContext.IsNull())
3317 di << "use 'vinit' command before " << argv[0] << "\n";
3320 Handle(V3d_View) aView = ViewerTest::CurrentView();
3321 V3d_TypeOfZclipping aZClippingMode;
3324 TCollection_AsciiString aZClippingModeString;
3325 Quantity_Length aDepth, aWidth;
3326 aZClippingMode = aView->ZClipping(aDepth, aWidth);
3327 switch (aZClippingMode)
3330 aZClippingModeString.Copy("OFF");
3333 aZClippingModeString.Copy("BACK");
3336 aZClippingModeString.Copy("FRONT");
3339 aZClippingModeString.Copy("SLICE");
3342 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
3345 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
3346 << "ZClipping depth = " << aDepth << "\n"
3347 << "ZClipping width = " << aWidth << "\n";
3353 Standard_Integer aStatus = 0;
3354 if ( strcmp (argv [1], "OFF") == 0 ) {
3356 aZClippingMode = V3d_OFF;
3358 if ( strcmp (argv [1], "BACK") == 0 ) {
3360 aZClippingMode = V3d_BACK;
3362 if ( strcmp (argv [1], "FRONT") == 0 ) {
3364 aZClippingMode = V3d_FRONT;
3366 if ( strcmp (argv [1], "SLICE") == 0 ) {
3368 aZClippingMode = V3d_SLICE;
3372 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3373 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3376 aView->SetZClippingType(aZClippingMode);
3380 Quantity_Length aDepth = 0., aWidth = 1.;
3383 aDepth = atof(argv[1]);
3384 aWidth = atof(argv[2]);
3388 aDepth = atof(argv[2]);
3389 aWidth = atof(argv[3]);
3392 if(aDepth<0. || aDepth>1.)
3394 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3395 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3398 if(aWidth<0. || aWidth>1.)
3400 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3401 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3405 aView->SetZClippingDepth(aDepth);
3406 aView->SetZClippingWidth(aWidth);
3413 //=======================================================================
3414 //function : VNbSelected
3415 //purpose : Returns number of selected objects
3416 //=======================================================================
3417 static Standard_Integer VNbSelected (Draw_Interpretor& di,
3418 Standard_Integer argc,
3423 di << "Usage : " << argv[0] << "\n";
3426 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3427 if(aContext.IsNull())
3429 di << "use 'vinit' command before " << argv[0] << "\n";
3432 di << aContext->NbSelected() << "\n";
3436 //=======================================================================
3437 //function : VAntialiasing
3438 //purpose : Switches altialiasing on or off
3439 //=======================================================================
3440 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
3441 Standard_Integer argc,
3446 di << "Usage : " << argv[0] << " [1|0]" << "\n";
3450 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3451 if(aContext.IsNull())
3453 di << "use 'vinit' command before " << argv[0] << "\n";
3457 Handle(V3d_View) aView = ViewerTest::CurrentView();
3459 if((argc == 2) && (atof(argv[1]) == 0))
3460 aView->SetAntialiasingOff();
3462 aView->SetAntialiasingOn();
3467 //=======================================================================
3468 //function : VPurgeDisplay
3469 //purpose : Switches altialiasing on or off
3470 //=======================================================================
3471 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
3472 Standard_Integer argc,
3477 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
3480 Standard_Boolean isCollectorToo = Standard_False;
3483 isCollectorToo = (atoi(argv [1]) != 0);
3485 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3486 if (aContext.IsNull())
3488 di << "use 'vinit' command before " << argv[0] << "\n";
3491 aContext->CloseAllContexts(Standard_False);
3492 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
3496 //=======================================================================
3497 //function : VSetViewSize
3499 //=======================================================================
3500 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
3501 Standard_Integer argc,
3504 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3505 if(aContext.IsNull())
3507 di << "use 'vinit' command before " << argv[0] << "\n";
3512 di<<"Usage : " << argv[0] << " Size\n";
3515 Standard_Real aSize = atof(argv[1]);
3518 di<<"Bad Size value : " << aSize << "\n";
3522 Handle(V3d_View) aView = ViewerTest::CurrentView();
3523 aView->SetSize(aSize);
3527 //=======================================================================
3528 //function : VMoveView
3530 //=======================================================================
3531 static Standard_Integer VMoveView (Draw_Interpretor& di,
3532 Standard_Integer argc,
3535 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3536 if(aContext.IsNull())
3538 di << "use 'vinit' command before " << argv[0] << "\n";
3541 if(argc < 4 || argc > 5)
3543 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3546 Standard_Real Dx = atof(argv[1]);
3547 Standard_Real Dy = atof(argv[2]);
3548 Standard_Real Dz = atof(argv[3]);
3549 Standard_Boolean aStart = Standard_True;
3552 aStart = (atoi(argv[4]) > 0);
3555 Handle(V3d_View) aView = ViewerTest::CurrentView();
3556 aView->Move(Dx,Dy,Dz,aStart);
3560 //=======================================================================
3561 //function : VTranslateView
3563 //=======================================================================
3564 static Standard_Integer VTranslateView (Draw_Interpretor& di,
3565 Standard_Integer argc,
3568 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3569 if(aContext.IsNull())
3571 di << "use 'vinit' command before " << argv[0] << "\n";
3574 if(argc < 4 || argc > 5)
3576 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3579 Standard_Real Dx = atof(argv[1]);
3580 Standard_Real Dy = atof(argv[2]);
3581 Standard_Real Dz = atof(argv[3]);
3582 Standard_Boolean aStart = Standard_True;
3585 aStart = (atoi(argv[4]) > 0);
3588 Handle(V3d_View) aView = ViewerTest::CurrentView();
3589 aView->Translate(Dx,Dy,Dz,aStart);
3593 //=======================================================================
3594 //function : VTurnView
3596 //=======================================================================
3597 static Standard_Integer VTurnView (Draw_Interpretor& di,
3598 Standard_Integer argc,
3601 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3602 if(aContext.IsNull()) {
3603 di << "use 'vinit' command before " << argv[0] << "\n";
3606 if(argc < 4 || argc > 5){
3607 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
3610 Standard_Real Ax = atof(argv[1]);
3611 Standard_Real Ay = atof(argv[2]);
3612 Standard_Real Az = atof(argv[3]);
3613 Standard_Boolean aStart = Standard_True;
3616 aStart = (atoi(argv[4]) > 0);
3619 Handle(V3d_View) aView = ViewerTest::CurrentView();
3620 aView->Turn(Ax,Ay,Az,aStart);
3624 //=======================================================================
3625 //function : ViewerCommands
3627 //=======================================================================
3629 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3632 const char *group = "ZeViewer";
3633 theCommands.Add("vinit" ,
3634 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3635 __FILE__,VInit,group);
3636 theCommands.Add("vhelp" ,
3637 "vhelp : display help on the viewer commands",
3638 __FILE__,VHelp,group);
3639 theCommands.Add("vtop" ,
3640 "vtop or <T> : Top view" ,
3641 __FILE__,VTop,group);
3642 theCommands.Add("vbottom" ,
3643 "vbottom : Bottom view" ,
3644 __FILE__,VBottom,group);
3645 theCommands.Add("vleft" ,
3646 "vleft : Left view" ,
3647 __FILE__,VLeft,group);
3648 theCommands.Add("vright" ,
3649 "vright : Right view" ,
3650 __FILE__,VRight,group);
3651 theCommands.Add("vaxo" ,
3652 " vaxo or <A> : Axonometric view ",
3653 __FILE__,VAxo,group);
3654 theCommands.Add("vfront" ,
3655 "vfront : Front view" ,
3656 __FILE__,VFront,group);
3657 theCommands.Add("vback" ,
3658 "vback : Back view" ,
3659 __FILE__,VBack,group);
3660 theCommands.Add("vpick" ,
3661 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
3663 theCommands.Add("vfit" ,
3664 "vfit or <F> : vfit",
3665 __FILE__,VFit,group);
3666 theCommands.Add("vzfit" ,
3668 __FILE__,VZFit,group);
3669 theCommands.Add("vrepaint",
3670 "vrepaint : vrepaint, force redraw",
3671 __FILE__,VRepaint,group);
3672 theCommands.Add("vclear",
3674 __FILE__,VClear,group);
3675 theCommands.Add("vsetbg",
3676 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
3677 __FILE__,VSetBg,group);
3678 theCommands.Add("vsetbgmode",
3679 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
3680 __FILE__,VSetBgMode,group);
3681 theCommands.Add("vsetgradientbg",
3682 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
3683 __FILE__,VSetGradientBg,group);
3684 theCommands.Add("vsetgrbgmode",
3685 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
3686 __FILE__,VSetGradientBgMode,group);
3687 theCommands.Add("vsetcolorbg",
3688 "vsetcolorbg : vsetcolorbg r g b : Set background color",
3689 __FILE__,VSetColorBg,group);
3690 theCommands.Add("vscale",
3691 "vscale : vscale X Y Z",
3692 __FILE__,VScale,group);
3693 theCommands.Add("vzbufftrihedron",
3694 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3695 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3696 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
3697 __FILE__,VTestZBuffTrihedron,group);
3698 theCommands.Add("vrotate",
3699 "vrotate : vrotate AX AY AZ [X Y Z]",
3700 __FILE__,VRotate,group);
3701 theCommands.Add("vzoom",
3702 "vzoom : vzoom coef",
3703 __FILE__,VZoom,group);
3704 theCommands.Add("vpan",
3705 "vpan : vpan dx dy",
3706 __FILE__,VPan,group);
3707 theCommands.Add("vexport",
3708 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3709 " : exports the view to a vector file of a given format"
3710 " : notice that EMF format requires patched gl2ps",
3711 __FILE__,VExport,group);
3712 theCommands.Add("vcolorscale",
3713 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3714 __FILE__,VColorScale,group);
3715 theCommands.Add("vgraduatedtrihedron",
3716 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
3717 __FILE__,VGraduatedTrihedron,group);
3718 theCommands.Add("vprintview" ,
3719 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3720 __FILE__,VPrintView,group);
3721 theCommands.Add("vzlayer",
3722 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3723 __FILE__,VZLayer,group);
3724 theCommands.Add("voverlaytext",
3725 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
3726 " : height - pixel height of the text (default=10.0)"
3727 " : font_name - name of font (default=courier)"
3728 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
3729 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
3730 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
3731 __FILE__,VOverlayText,group);
3732 theCommands.Add("vlayerline",
3733 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
3734 __FILE__,VLayerLine,group);
3735 theCommands.Add ("vgrid",
3736 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
3737 " : Mode - rectangular or circular"
3738 " : Type - lines or points",
3739 __FILE__, VGrid, group);
3740 theCommands.Add ("vfps",
3741 "vfps [framesNb=100] : estimate average frame rate for active view",
3742 __FILE__, VFps, group);
3743 theCommands.Add ("vvbo",
3744 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
3745 __FILE__, VVbo, group);
3746 theCommands.Add ("vmemgpu",
3747 "vmemgpu [f]: print system-dependent GPU memory information if available;"
3748 " with f option returns free memory in bytes",
3749 __FILE__, VMemGpu, group);
3750 theCommands.Add ("vreadpixel",
3751 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
3752 " : Read pixel value for active view",
3753 __FILE__, VReadPixel, group);
3754 theCommands.Add("diffimage",
3755 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
3756 __FILE__, VDiffImage, group);
3757 theCommands.Add ("vselect",
3758 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
3759 "- emulates different types of selection:\n"
3760 "- 1) single click selection\n"
3761 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
3762 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
3763 "- 4) any of these selections with shift button pressed",
3764 __FILE__, VSelect, group);
3765 theCommands.Add ("vmoveto",
3767 "- emulates cursor movement to pixel postion (x,y)",
3768 __FILE__, VMoveTo, group);
3769 theCommands.Add("vviewparams",
3770 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
3771 "- gets or sets current view characteristics",
3772 __FILE__,VViewParams, group);
3773 theCommands.Add("vchangeselected",
3774 "vchangeselected shape"
3775 "- adds to shape to selection or remove one from it",
3776 __FILE__, VChangeSelected, group);
3777 theCommands.Add("vzclipping",
3778 "vzclipping [mode] [depth width]\n"
3779 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
3780 "- gets or sets ZClipping mode, width and depth",
3781 __FILE__,VZClipping,group);
3782 theCommands.Add ("vnbselected",
3783 "vnbselected", __FILE__, VNbSelected, group);
3784 theCommands.Add("vantialiasing",
3785 "vantialiasing 1|0",
3786 __FILE__,VAntialiasing,group);
3787 theCommands.Add ("vpurgedisplay",
3788 "vpurgedisplay [CollectorToo = 0|1]"
3789 "- removes structures which don't belong to objects displayed in neutral point",
3790 __FILE__, VPurgeDisplay, group);
3791 theCommands.Add("vsetviewsize",
3792 "vsetviewsize size",
3793 __FILE__,VSetViewSize,group);
3794 theCommands.Add("vmoveview",
3795 "vmoveview Dx Dy Dz [Start = 1|0]",
3796 __FILE__,VMoveView,group);
3797 theCommands.Add("vtranslateview",
3798 "vtranslateview Dx Dy Dz [Start = 1|0)]",
3799 __FILE__,VTranslateView,group);
3800 theCommands.Add("vturnview",
3801 "vturnview Ax Ay Az [Start = 1|0]",
3802 __FILE__,VTurnView,group);