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 <Visual3d_View.hxx>
38 #include <Visual3d_ViewManager.hxx>
39 #include <V3d_LayerMgr.hxx>
40 #include <NIS_View.hxx>
41 #include <NIS_Triangulated.hxx>
42 #include <NIS_InteractiveContext.hxx>
43 #include <AIS_InteractiveContext.hxx>
44 #include <Draw_Interpretor.hxx>
46 #include <Draw_Appli.hxx>
47 #include <Aspect_PrintAlgo.hxx>
48 #include <Image_AlienPixMap.hxx>
49 #include <OSD_Timer.hxx>
50 #include <TColStd_SequenceOfInteger.hxx>
51 #include <Visual3d_LayerItem.hxx>
52 #include <V3d_LayerMgr.hxx>
53 #include <V3d_LayerMgrPointer.hxx>
54 #include <Aspect_TypeOfLine.hxx>
55 #include <Image_Diff.hxx>
61 #include <Visual3d_Layer.hxx>
65 #include <Graphic3d_GraphicDevice.hxx>
66 #include <Xw_GraphicDevice.hxx>
67 #include <Xw_WindowQuality.hxx>
68 #include <Xw_Window.hxx>
69 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
70 #include <X11/Xutil.h>
75 #include <Graphic3d_WNTGraphicDevice.hxx>
76 #include <WNT_WClass.hxx>
77 #include <WNT_Window.hxx>
79 #define _CRT_SECURE_NO_DEPRECATE
80 #pragma warning (disable:4996)
86 //==============================================================================
88 //==============================================================================
89 // VIEWER GLOBAL VARIABLES
90 //==============================================================================
92 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
94 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
95 extern const Handle(NIS_InteractiveContext)& TheNISContext();
98 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
99 static Handle(Graphic3d_WNTGraphicDevice) GD;
103 static Handle(WNT_Window)& VT_GetWindow() {
104 static Handle(WNT_Window) WNTWin;
109 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
110 static Handle(Graphic3d_GraphicDevice) GD;
113 static Handle(Xw_Window)& VT_GetWindow(){
114 static Handle(Xw_Window) XWWin;
117 static Display *display;
119 static void VProcessEvents(ClientData,int);
123 static Standard_Boolean DegenerateMode = Standard_True;
126 #define ZCLIPWIDTH 1.
128 static void OSWindowSetup();
130 //==============================================================================
131 // EVENT GLOBAL VARIABLES
132 //==============================================================================
134 static int Start_Rot = 0;
135 static int ZClipIsOn = 0;
136 static int X_Motion= 0,Y_Motion=0; // Current cursor position
137 static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
140 //==============================================================================
143 static LRESULT WINAPI ViewerWindowProc(
148 static LRESULT WINAPI AdvViewerWindowProc(
156 //==============================================================================
159 //==============================================================================
161 const Handle(MMgt_TShared)& ViewerTest::WClass()
163 static Handle(MMgt_TShared) theWClass;
165 if (theWClass.IsNull()) {
166 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
167 CS_VREDRAW | CS_HREDRAW, 0, 0,
168 ::LoadCursor (NULL, IDC_ARROW));
174 //==============================================================================
175 //function : ViewerInit
176 //purpose : Create the window viewer and initialize all the global variable
177 //==============================================================================
179 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
180 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
182 static Standard_Boolean isFirst = Standard_True;
184 // Default position and dimension of the viewer window.
185 // Note that left top corner is set to be sufficiently small to have
186 // window fit in the small screens (actual for remote desktops, see #23003).
187 // The position corresponds to the window's client area, thus some
188 // gap is added for window frame to be visible.
189 Standard_Integer aPxLeft = 20;
190 Standard_Integer aPxTop = 40;
191 Standard_Integer aPxWidth = 409;
192 Standard_Integer aPxHeight = 409;
193 if (thePxWidth != 0 && thePxHeight != 0)
197 aPxWidth = thePxWidth;
198 aPxHeight = thePxHeight;
203 // Create the Graphic device
205 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
206 if (VT_GetWindow().IsNull())
208 // Create the Graphic device and the window
209 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
211 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
212 Handle(WNT_WClass)::DownCast (WClass()),
217 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
220 if (GetG3dDevice().IsNull()) GetG3dDevice() =
221 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
222 if (VT_GetWindow().IsNull())
224 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
230 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
234 Handle(V3d_Viewer) a3DViewer, a3DCollector;
235 // Viewer and View creation
237 TCollection_ExtendedString NameOfWindow("Visu3D");
239 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
240 NameOfWindow = TCollection_ExtendedString("Collector");
241 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
242 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
243 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
244 Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
247 //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
248 aView = new NIS_View (a3DViewer, VT_GetWindow());
249 ViewerTest::CurrentView(aView);
250 TheNISContext()->AttachView (aView);
254 if ( ViewerTest::GetAISContext().IsNull() ) {
255 Handle(AIS_InteractiveContext) C =
256 new AIS_InteractiveContext(a3DViewer,a3DCollector);
257 ViewerTest::SetAISContext(C);
260 // Setup for X11 or NT
262 // Viewer and View creation
264 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
266 Handle (V3d_View) V = ViewerTest::CurrentView();
268 V->SetDegenerateModeOn();
270 DegenerateMode = V->DegenerateModeIsOn();
272 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
274 V->SetZClippingDepth(0.5);
275 V->SetZClippingWidth(ZCLIPWIDTH/2.);
276 a3DViewer->SetDefaultLights();
277 a3DViewer->SetLightOn();
280 #if TCL_MAJOR_VERSION < 8
281 Tk_CreateFileHandler((void*)ConnectionNumber(display),
282 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
284 Tk_CreateFileHandler(ConnectionNumber(display),
285 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
289 isFirst = Standard_False;
291 VT_GetWindow()->Map();
294 //==============================================================================
296 //purpose : Create the window viewer and initialize all the global variable
297 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
298 //==============================================================================
300 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
302 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
303 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
304 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
305 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
306 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
310 //==============================================================================
311 //function : ProcessKeyPress
312 //purpose : Handle KeyPress event from a CString
313 //==============================================================================
315 static void ProcessKeyPress( char *buf_ret )
317 //cout << "KeyPress" << endl;
318 const Handle(V3d_View) aView = ViewerTest::CurrentView();
319 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
320 // Letter in alphabetic order
322 if ( !strcasecmp(buf_ret, "A") ) {
324 aView->SetProj(V3d_XposYnegZpos);
326 else if ( !strcasecmp(buf_ret, "D") ) {
330 else if ( !strcasecmp(buf_ret, "F") ) {
332 if (aNisView.IsNull())
335 aNisView->FitAll3d();
337 else if ( !strcasecmp(buf_ret, "H") ) {
339 cout << "HLR" << endl;
341 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
342 else aView->SetDegenerateModeOn();
343 DegenerateMode = aView->DegenerateModeIsOn();
345 ViewerTest::CurrentView()->SetDegenerateModeOff();
348 else if ( !strcasecmp(buf_ret, "D") ) {
352 else if ( !strcasecmp(buf_ret, "S") ) {
354 cout << "passage en mode 1 (shading pour les shapes)" << endl;
356 ViewerTest::CurrentView()->SetDegenerateModeOn();
358 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
359 if(Ctx->NbCurrents()==0 ||
360 Ctx->NbSelected()==0)
361 Ctx->SetDisplayMode(AIS_Shaded);
363 if(Ctx->HasOpenedContext()){
364 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
365 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
368 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
369 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
371 Ctx->UpdateCurrentViewer();
374 else if ( !strcasecmp(buf_ret, "U") ) {
376 cout<<"passage au mode par defaut"<<endl;
378 ViewerTest::CurrentView()->SetDegenerateModeOn();
380 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
381 if(Ctx->NbCurrents()==0 ||
382 Ctx->NbSelected()==0)
383 Ctx->SetDisplayMode(AIS_WireFrame);
385 if(Ctx->HasOpenedContext()){
386 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
387 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
390 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
391 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
393 Ctx->UpdateCurrentViewer();
397 else if ( !strcasecmp(buf_ret, "T") ) {
399 aView->SetProj(V3d_Zpos);
401 else if ( !strcasecmp(buf_ret, "B") ) {
403 aView->SetProj(V3d_Zneg);
405 else if ( !strcasecmp(buf_ret, "L") ) {
407 aView->SetProj(V3d_Xneg);
409 else if ( !strcasecmp(buf_ret, "R") ) {
411 aView->SetProj(V3d_Xpos);
414 else if ( !strcasecmp(buf_ret, "W") ) {
417 ViewerTest::CurrentView()->SetDegenerateModeOn();
419 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
421 ViewerTest::CurrentView()->SetDegenerateModeOn();
423 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
424 if(Ctx->NbCurrents()==0 ||
425 Ctx->NbSelected()==0)
426 Ctx->SetDisplayMode(AIS_WireFrame);
428 if(Ctx->HasOpenedContext()){
429 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
430 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
433 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
434 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
436 Ctx->UpdateCurrentViewer();
439 else if ( !strcasecmp(buf_ret, "Z") ) {
443 cout << "ZClipping OFF" << endl;
446 aView->SetZClippingType(V3d_OFF);
450 cout << "ZClipping ON" << endl;
453 aView->SetZClippingType(V3d_FRONT);
457 else if ( !strcasecmp(buf_ret, ",") ) {
458 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
462 else if ( !strcasecmp(buf_ret, ".") ) {
463 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
467 Standard_Integer Num = atoi(buf_ret);
469 ViewerTest::StandardModeActivation(Num);
473 //==============================================================================
474 //function : ProcessExpose
475 //purpose : Redraw the View on an Expose Event
476 //==============================================================================
478 static void ProcessExpose( )
479 { //cout << "Expose" << endl;
480 ViewerTest::CurrentView()->Redraw();
483 //==============================================================================
484 //function : ProcessConfigure
485 //purpose : Resize the View on an Configure Event
486 //==============================================================================
488 static void ProcessConfigure()
490 Handle(V3d_View) V = ViewerTest::CurrentView();
496 //==============================================================================
497 //function : ProcessButton1Press
499 //==============================================================================
501 static Standard_Boolean ProcessButton1Press(
504 Standard_Boolean pick,
505 Standard_Boolean shift )
507 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
509 Standard_Real X, Y, Z;
511 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
513 Draw::Set(argv[1], X);
514 Draw::Set(argv[2], Y);
515 Draw::Set(argv[3], Z);}
526 //==============================================================================
527 //function : ProcessButton3Press
528 //purpose : Start Rotation
529 //==============================================================================
531 static void ProcessButton3Press()
535 ViewerTest::CurrentView()->SetDegenerateModeOn();
536 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
539 //==============================================================================
540 //function : ProcessButtonRelease
541 //purpose : Start Rotation
542 //==============================================================================
544 static void ProcessButtonRelease()
550 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
554 ViewerTest::CurrentView()->SetDegenerateModeOff();
558 //==============================================================================
559 //function : ProcessZClipMotion
561 //==============================================================================
563 void ProcessZClipMotion()
565 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
566 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
567 static Standard_Real CurZPos = 0.;
569 //Quantity_Length VDX, VDY;
570 //a3DView->Size(VDX,VDY);
571 //Standard_Real VDZ = a3DView->ZSize();
572 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
574 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
576 // Front = Depth + width/2.
577 Standard_Real D = 0.5;
578 Standard_Real W = 0.1;
584 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
586 a3DView->SetZClippingType(V3d_OFF);
587 a3DView->SetZClippingDepth(D);
588 a3DView->SetZClippingWidth(W);
589 a3DView->SetZClippingType(V3d_FRONT);
593 X_ButtonPress = X_Motion;
594 Y_ButtonPress = Y_Motion;
598 //==============================================================================
599 //function : ProcessControlButton1Motion
601 //==============================================================================
603 static void ProcessControlButton1Motion()
605 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
607 X_ButtonPress = X_Motion;
608 Y_ButtonPress = Y_Motion;
611 //==============================================================================
612 //function : ProcessControlButton2Motion
614 //==============================================================================
616 static void ProcessControlButton2Motion()
618 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
619 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
621 dy = -dy; // Xwindow Y axis is from top to Bottom
623 ViewerTest::CurrentView()->Panning( dx, dy );
625 X_ButtonPress = X_Motion;
626 Y_ButtonPress = Y_Motion;
629 //==============================================================================
630 //function : ProcessControlButton3Motion
632 //==============================================================================
634 static void ProcessControlButton3Motion()
636 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
639 //==============================================================================
640 //function : ProcessPointerMotion
642 //==============================================================================
644 static void ProcessMotion()
646 //pre-hilights detected objects at mouse position
648 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
649 EM->MoveTo(X_Motion, Y_Motion);
653 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
655 Xpix = X_Motion;Ypix=Y_Motion;
658 //==============================================================================
659 //function : ViewProject: implements VAxo, VTop, VLeft, ...
660 //purpose : Switches to an axonometric, top, left and other views
661 //==============================================================================
663 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
665 if ( ViewerTest::CurrentView().IsNull() )
667 di<<"Call vinit before this command, please"<<"\n";
671 ViewerTest::CurrentView()->SetProj(ori);
675 //==============================================================================
677 //purpose : Switch to an Axonometric view
679 //==============================================================================
681 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
683 return ViewProject(di, V3d_XposYnegZpos);
686 //==============================================================================
688 //purpose : Switch to a Top View
690 //==============================================================================
692 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
694 return ViewProject(di, V3d_Zpos);
697 //==============================================================================
699 //purpose : Switch to a Bottom View
701 //==============================================================================
703 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
705 return ViewProject(di, V3d_Zneg);
708 //==============================================================================
710 //purpose : Switch to a Left View
712 //==============================================================================
714 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
716 return ViewProject(di, V3d_Ypos);
719 //==============================================================================
721 //purpose : Switch to a Right View
723 //==============================================================================
725 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
727 return ViewProject(di, V3d_Yneg);
730 //==============================================================================
732 //purpose : Switch to a Front View
734 //==============================================================================
736 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
738 return ViewProject(di, V3d_Xpos);
741 //==============================================================================
743 //purpose : Switch to a Back View
745 //==============================================================================
747 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
749 return ViewProject(di, V3d_Xneg);
752 //==============================================================================
754 //purpose : Dsiplay help on viewer Keyboead and mouse commands
756 //==============================================================================
758 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
761 di << "Q : Quit the application" << "\n";
763 di << "========================="<<"\n";
764 di << "F : FitAll" << "\n";
765 di << "T : TopView" << "\n";
766 di << "A : AxonometricView" << "\n";
767 di << "R : ResetView" << "\n";
769 di << "========================="<<"\n";
770 di << "S : Shading" << "\n";
771 di << "W : Wireframe" << "\n";
772 di << "H : HidelLineRemoval" << "\n";
774 di << "========================="<<"\n";
775 di << "Selection mode "<<"\n";
776 di << "0 : Shape" <<"\n";
777 di << "1 : Vertex" <<"\n";
778 di << "2 : Edge" <<"\n";
779 di << "3 : Wire" <<"\n";
780 di << "4 : Face" <<"\n";
781 di << "5 : Shell" <<"\n";
782 di << "6 : Solid" <<"\n";
783 di << "7 : Compound" <<"\n";
785 di << "=========================="<<"\n";
786 di << "D : Remove Selected Object"<<"\n";
787 di << "=========================="<<"\n";
792 Standard_Boolean IsDragged = Standard_False;
794 Standard_Integer xx1, yy1, xx2, yy2;
795 //the first and last point in viewer co-ordinates
797 Standard_Boolean DragFirst;
802 static Standard_Boolean Ppick = 0;
803 static Standard_Integer Pargc = 0;
804 static const char** Pargv = NULL;
807 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
812 if ( !ViewerTest::CurrentView().IsNull() ) {
814 WPARAM fwKeys = wParam;
819 IsDragged = Standard_False;
822 HDC hdc = GetDC( hwnd );
823 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
824 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
825 SetROP2( hdc, R2_NOT );
826 Rectangle( hdc, xx1, yy1, xx2, yy2 );
827 ReleaseDC( hwnd, hdc );
829 const Handle(ViewerTest_EventManager) EM =
830 ViewerTest::CurrentEventManager();
831 if ( fwKeys & MK_SHIFT )
832 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
833 max( xx1, xx2 ), min( yy1, yy2 ));
835 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
836 max( xx1, xx2 ), min( yy1, yy2 ));
838 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
841 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
843 IsDragged = Standard_True;
844 DragFirst = Standard_True;
845 xx1 = LOWORD(lParam);
846 yy1 = HIWORD(lParam);
848 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
855 HDC hdc = GetDC( hwnd );
857 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
858 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
859 SetROP2( hdc, R2_NOT );
862 Rectangle( hdc, xx1, yy1, xx2, yy2 );
864 DragFirst = Standard_False;
865 xx2 = LOWORD(lParam);
866 yy2 = HIWORD(lParam);
868 Rectangle( hdc, xx1, yy1, xx2, yy2 );
870 SelectObject( hdc, anObj );
872 ReleaseDC( hwnd, hdc );
875 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
879 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
883 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
887 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
892 /*static Standard_Boolean Ppick = 0;
893 static Standard_Integer Pargc = 0;
894 static char** Pargv = NULL;*/
898 if ( !ViewerTest::CurrentView().IsNull() ) {
903 // do not destroy the window - just hide it!
904 VT_GetWindow()->Unmap();
907 //cout << "\t WM_PAINT" << endl;
908 BeginPaint(hwnd, &ps);
914 //cout << "\t WM_SIZE" << endl;
919 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
921 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
923 c[0] = (char) wParam;
932 //cout << "\t WM_xBUTTONUP" << endl;
934 ProcessButtonRelease();
941 //cout << "\t WM_xBUTTONDOWN" << endl;
942 WPARAM fwKeys = wParam;
946 X_ButtonPress = LOWORD(lParam);
947 Y_ButtonPress = HIWORD(lParam);
949 if ( Msg == WM_LBUTTONDOWN) {
950 if(fwKeys & MK_CONTROL) {
951 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
953 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
955 else if ( Msg == WM_RBUTTONDOWN ) {
957 ProcessButton3Press( );
964 //cout << "\t WM_MOUSEMOVE" << endl;
965 WPARAM fwKeys = wParam;
966 X_Motion = LOWORD(lParam);
967 Y_Motion = HIWORD(lParam);
970 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
972 X_ButtonPress = LOWORD(lParam);
973 Y_ButtonPress = HIWORD(lParam);
975 if ( fwKeys & MK_RBUTTON ) {
977 ProcessButton3Press();
981 if ( fwKeys & MK_CONTROL ) {
982 if ( fwKeys & MK_LBUTTON ) {
983 ProcessControlButton1Motion();
985 else if ( fwKeys & MK_MBUTTON ||
986 ((fwKeys&MK_LBUTTON) &&
987 (fwKeys&MK_RBUTTON) ) ){
988 ProcessControlButton2Motion();
990 else if ( fwKeys & MK_RBUTTON ) {
991 ProcessControlButton3Motion();
995 else if ( fwKeys & MK_SHIFT ) {
996 if ( fwKeys & MK_MBUTTON ||
997 ((fwKeys&MK_LBUTTON) &&
998 (fwKeys&MK_RBUTTON) ) ) {
999 cout << "ProcessZClipMotion()" << endl;
1000 ProcessZClipMotion();
1005 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
1006 ProcessZClipMotion();
1015 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1020 return DefWindowProc( hwnd, Msg, wParam, lParam );
1026 //==============================================================================
1027 //function : ViewerMainLoop
1028 //purpose : Get a Event on the view and dispatch it
1029 //==============================================================================
1032 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1035 //cout << "No yet implemented on WNT" << endl;
1036 /*static Standard_Boolean Ppick = 0;
1037 static Standard_Integer Pargc = 0;
1038 static char** Pargv = NULL;*/
1040 //Ppick = (argc > 0)? -1 : 0;
1041 Ppick = (argc > 0)? 1 : 0;
1049 cout << "Start picking" << endl;
1051 //while ( Ppick == -1 ) {
1052 while ( Ppick == 1 ) {
1053 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
1054 if (GetMessage(&msg, NULL, 0, 0) ) {
1055 TranslateMessage(&msg);
1056 DispatchMessage(&msg);
1060 cout << "Picking done" << endl;
1069 int min( int a, int b )
1077 int max( int a, int b )
1085 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1087 { Standard_Boolean pick = argc > 0;
1091 static XEvent report;
1093 XNextEvent( display, &report );
1094 // cout << "rep type = " << report.type << endl;
1095 // cout << "rep button = " << report.xbutton.button << endl;
1097 switch ( report.type ) {
1103 case ConfigureNotify:
1114 XComposeStatus status_in_out;
1116 ret_len = XLookupString( ( XKeyEvent *)&report ,
1117 (char *) buf_ret , 10 ,
1118 &ks_ret , &status_in_out ) ;
1121 buf_ret[ret_len] = '\0' ;
1124 ProcessKeyPress( buf_ret);
1129 // cout << "ButtonPress" << endl;
1131 X_ButtonPress = report.xbutton.x;
1132 Y_ButtonPress = report.xbutton.y;
1134 if ( report.xbutton.button == Button1 )
1135 if( report.xbutton.state & ControlMask )
1136 pick = ProcessButton1Press( argc, argv, pick,
1137 ( report.xbutton.state & ShiftMask) );
1140 IsDragged = Standard_True;
1141 xx1 = X_ButtonPress;
1142 yy1 = Y_ButtonPress;
1143 DragFirst = Standard_True;
1145 else if ( report.xbutton.button == Button3 )
1147 ProcessButton3Press();
1152 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1153 // cout << IsDragged << endl;
1154 // cout << DragFirst << endl;
1160 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1161 GC gc = XCreateGC( display, aWindow, 0, 0 );
1162 // XSetFunction( display, gc, GXinvert );
1163 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1166 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1167 if( aContext.IsNull() )
1169 cout << "The context is null. Please use vinit before createmesh" << endl;
1173 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1174 if( report.xbutton.button==1 )
1178 aContext->ShiftSelect();
1179 // cout << "shift select" << endl;
1184 // cout << "select" << endl;
1189 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1190 max( xx1, xx2 ), max( yy1, yy2 ),
1191 ViewerTest::CurrentView());
1192 // cout << "shift select" << endl;
1196 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1197 max( xx1, xx2 ), max( yy1, yy2 ),
1198 ViewerTest::CurrentView() );
1199 // cout << "select" << endl;
1202 ProcessButtonRelease();
1204 IsDragged = Standard_False;
1207 ProcessButtonRelease();
1214 X_Motion = report.xmotion.x;
1215 Y_Motion = report.xmotion.y;
1219 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1220 GC gc = XCreateGC( display, aWindow, 0, 0 );
1221 XSetFunction( display, gc, GXinvert );
1224 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1228 DragFirst = Standard_False;
1230 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1231 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1236 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1238 // remove all the ButtonMotionMask
1239 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1241 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1242 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1244 Quantity_Length VDX, VDY;
1246 ViewerTest::CurrentView()->Size(VDX,VDY);
1247 Standard_Real VDZ =0 ;
1248 VDZ = ViewerTest::CurrentView()->ZSize();
1250 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1251 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1253 Quantity_Length dx = 0 ;
1254 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1258 dx = dx / VDX * VDZ;
1262 // Front = Depth + width/2.
1263 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1264 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1266 ViewerTest::CurrentView()->Redraw();
1270 if ( report.xmotion.state & ControlMask ) {
1271 if ( report.xmotion.state & Button1Mask ) {
1272 ProcessControlButton1Motion();
1274 else if ( report.xmotion.state & Button2Mask ) {
1275 ProcessControlButton2Motion();
1277 else if ( report.xmotion.state & Button3Mask ) {
1278 ProcessControlButton3Motion();
1293 //==============================================================================
1294 //function : VProcessEvents
1295 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1296 // event in the Viewer window
1297 //==============================================================================
1299 static void VProcessEvents(ClientData,int)
1301 //cout << "VProcessEvents" << endl;
1304 while (XPending(display)) {
1305 ViewerMainLoop( 0, NULL);
1310 //==============================================================================
1311 //function : OSWindowSetup
1312 //purpose : Setup for the X11 window to be able to cath the event
1313 //==============================================================================
1316 static void OSWindowSetup()
1321 Window window = VT_GetWindow()->XWindow();
1323 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1324 display = (Display * ) theDisplay;
1325 // display = (Display *)GetG3dDevice()->XDisplay();
1327 XSynchronize(display, 1);
1329 VT_GetWindow()->Map();
1331 // X11 : For keyboard on SUN
1333 wmhints.flags = InputHint;
1336 XSetWMHints( display, window, &wmhints);
1338 XSelectInput( display, window, ExposureMask | KeyPressMask |
1339 ButtonPressMask | ButtonReleaseMask |
1340 StructureNotifyMask |
1342 Button1MotionMask | Button2MotionMask |
1346 XSynchronize(display, 0);
1355 //==============================================================================
1358 //purpose : Fitall, no DRAW arguments
1359 //Draw arg : No args
1360 //==============================================================================
1362 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1364 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1365 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1366 if (V.IsNull() == Standard_False) {
1368 } else if (aView.IsNull() == Standard_False) {
1374 //==============================================================================
1376 //purpose : ZFitall, no DRAW arguments
1377 //Draw arg : No args
1378 //==============================================================================
1380 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1382 Handle(V3d_View) V = ViewerTest::CurrentView();
1383 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1386 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1388 Handle(V3d_View) V = ViewerTest::CurrentView();
1389 if ( !V.IsNull() ) V->Redraw(); return 0;
1393 //==============================================================================
1395 //purpose : Remove all the object from the viewer
1396 //Draw arg : No args
1397 //==============================================================================
1399 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1401 Handle(V3d_View) V = ViewerTest::CurrentView();
1403 ViewerTest::Clear();
1407 //==============================================================================
1410 //==============================================================================
1412 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1413 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1416 di << argv[0] << "Invalid number of arguments" << "\n";
1420 while (ViewerMainLoop( argc, argv)) {
1428 //==============================================================================
1429 //function : InitViewerTest
1430 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1431 //==============================================================================
1433 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1435 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1436 ViewerTest::SetAISContext(context);
1437 viewer->InitActiveViews();
1438 Handle(V3d_View) view = viewer->ActiveView();
1439 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1440 ViewerTest::ResetEventManager();
1441 Handle(Aspect_GraphicDevice) device = viewer->Device();
1442 Handle(Aspect_Window) window = view->Window();
1445 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1446 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1448 static int first = 1;
1450 #if TCL_MAJOR_VERSION < 8
1451 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1452 TK_READABLE, VProcessEvents, (ClientData) 0);
1454 Tk_CreateFileHandler(ConnectionNumber(display),
1455 TK_READABLE, VProcessEvents, (ClientData) 0);
1463 //==============================================================================
1465 //purpose : Load image as background
1466 //==============================================================================
1468 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1470 if (argc < 2 || argc > 3)
1472 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1473 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1477 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1478 if(AISContext.IsNull())
1480 di << "use 'vinit' command before " << argv[0] << "\n";
1484 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1487 const char* szType = argv[2];
1488 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1489 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1490 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1491 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1494 di << "Wrong fill type : " << szType << "\n";
1495 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1500 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1501 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1506 //==============================================================================
1507 //function : VSetBgMode
1508 //purpose : Change background image fill type
1509 //==============================================================================
1511 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1515 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1516 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1520 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1521 if(AISContext.IsNull())
1523 di << "use 'vinit' command before " << argv[0] << "\n";
1527 Aspect_FillMethod aFillType;
1530 const char* szType = argv[1];
1531 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1532 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1533 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1534 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1537 di << "Wrong fill type : " << szType << "\n";
1538 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1543 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1544 V3dView->SetBgImageStyle(aFillType, Standard_True);
1549 //==============================================================================
1550 //function : VSetGradientBg
1551 //purpose : Mount gradient background
1552 //==============================================================================
1553 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1557 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1558 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1559 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1560 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1564 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1565 if(AISContext.IsNull())
1567 di << "use 'vinit' command before " << argv[0] << "\n";
1573 Standard_Real R1 = atof(argv[1])/255.;
1574 Standard_Real G1 = atof(argv[2])/255.;
1575 Standard_Real B1 = atof(argv[3])/255.;
1576 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1578 Standard_Real R2 = atof(argv[4])/255.;
1579 Standard_Real G2 = atof(argv[5])/255.;
1580 Standard_Real B2 = atof(argv[6])/255.;
1582 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1583 int aType = atoi(argv[7]);
1584 if( aType < 0 || aType > 8 )
1586 di << "Wrong fill type " << "\n";
1587 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1588 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1592 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1594 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1595 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1601 //==============================================================================
1602 //function : VSetGradientBgMode
1603 //purpose : Change gradient background fill style
1604 //==============================================================================
1605 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1609 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1610 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1611 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1615 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1616 if(AISContext.IsNull())
1618 di << "use 'vinit' command before " << argv[0] << "\n";
1623 int aType = atoi(argv[1]);
1624 if( aType < 0 || aType > 8 )
1626 di << "Wrong fill type " << "\n";
1627 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1628 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1632 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1634 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1635 V3dView->SetBgGradientStyle( aMethod, 1 );
1641 //==============================================================================
1642 //function : VSetColorBg
1643 //purpose : Set color background
1644 //==============================================================================
1645 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1649 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1650 di << "R,G,B = [0..255]" << "\n";
1654 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1655 if(AISContext.IsNull())
1657 di << "use 'vinit' command before " << argv[0] << "\n";
1663 Standard_Real R = atof(argv[1])/255.;
1664 Standard_Real G = atof(argv[2])/255.;
1665 Standard_Real B = atof(argv[3])/255.;
1666 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1668 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1669 V3dView->SetBackgroundColor( aColor );
1676 //==============================================================================
1678 //purpose : View Scaling
1679 //==============================================================================
1681 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1683 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1684 if ( V3dView.IsNull() ) return 1;
1687 di << argv[0] << "Invalid number of arguments" << "\n";
1690 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1693 //==============================================================================
1694 //function : VTestZBuffTrihedron
1695 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1696 //==============================================================================
1698 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1700 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1701 if ( V3dView.IsNull() ) return 1;
1703 V3dView->ZBufferTriedronSetup();
1706 // Set up default trihedron parameters
1707 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1711 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1712 const char* aPosType = argv[1];
1714 if ( strcmp(aPosType, "center") == 0 )
1716 aPosition = Aspect_TOTP_CENTER;
1718 if (strcmp(aPosType, "left_lower") == 0)
1720 aPosition = Aspect_TOTP_LEFT_LOWER;
1722 if (strcmp(aPosType, "left_upper") == 0)
1724 aPosition = Aspect_TOTP_LEFT_UPPER;
1726 if (strcmp(aPosType, "right_lower") == 0)
1728 aPosition = Aspect_TOTP_RIGHT_LOWER;
1730 if (strcmp(aPosType, "right_upper") == 0)
1732 aPosition = Aspect_TOTP_RIGHT_UPPER;
1735 di << argv[1] << " Invalid type of alignment" << "\n";
1736 di << "Must be one of [ center, left_lower," << "\n";
1737 di << "left_upper, right_lower, right_upper ]" << "\n";
1741 Standard_Real R = atof(argv[2])/255.;
1742 Standard_Real G = atof(argv[3])/255.;
1743 Standard_Real B = atof(argv[4])/255.;
1744 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1746 Standard_Real aScale = atof(argv[5]);
1750 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1754 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1755 const char* aPresType = argv[6];
1757 if ( strcmp(aPresType, "wireframe") == 0 )
1759 aPresentation = V3d_WIREFRAME;
1761 if (strcmp(aPresType, "zbuffer") == 0)
1763 aPresentation = V3d_ZBUFFER;
1766 di << argv[6] << " Invalid type of visualization" << "\n";
1767 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1771 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1775 di << argv[0] << " Invalid number of arguments" << "\n";
1784 //==============================================================================
1785 //function : VRotate
1786 //purpose : Camera Rotating
1787 //==============================================================================
1789 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1790 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1791 if ( V3dView.IsNull() ) {
1796 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1798 } else if ( argc == 7 ) {
1799 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1802 di << argv[0] << " Invalid number of arguments" << "\n";
1807 //==============================================================================
1809 //purpose : View zoom in / out (relative to current zoom)
1810 //==============================================================================
1812 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1813 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1814 if ( V3dView.IsNull() ) {
1819 Standard_Real coef = atof(argv[1]);
1820 if ( coef <= 0.0 ) {
1821 di << argv[1] << "Invalid value" << "\n";
1824 V3dView->SetZoom( atof(argv[1]) );
1827 di << argv[0] << " Invalid number of arguments" << "\n";
1832 //==============================================================================
1834 //purpose : View panning (in pixels)
1835 //==============================================================================
1837 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1838 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1839 if ( V3dView.IsNull() ) return 1;
1842 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1845 di << argv[0] << " Invalid number of arguments" << "\n";
1851 //==============================================================================
1852 //function : VExport
1853 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1854 //==============================================================================
1856 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1858 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1859 if (V3dView.IsNull())
1864 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1868 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1869 TCollection_AsciiString aFormatStr;
1871 TCollection_AsciiString aFileName (argv[1]);
1872 Standard_Integer aLen = aFileName.Length();
1876 aFormatStr = TCollection_AsciiString (argv[2]);
1880 if (aFileName.Value (aLen - 2) == '.')
1882 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1884 else if (aFileName.Value (aLen - 3) == '.')
1886 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1890 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1896 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1900 aFormatStr.UpperCase();
1901 if (aFormatStr == "PS")
1902 anExpFormat = Graphic3d_EF_PostScript;
1903 else if (aFormatStr == "EPS")
1904 anExpFormat = Graphic3d_EF_EnhPostScript;
1905 else if (aFormatStr == "TEX")
1906 anExpFormat = Graphic3d_EF_TEX;
1907 else if (aFormatStr == "PDF")
1908 anExpFormat = Graphic3d_EF_PDF;
1909 else if (aFormatStr == "SVG")
1910 anExpFormat = Graphic3d_EF_SVG;
1911 else if (aFormatStr == "PGF")
1912 anExpFormat = Graphic3d_EF_PGF;
1913 else if (aFormatStr == "EMF")
1914 anExpFormat = Graphic3d_EF_EMF;
1917 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1921 if (!V3dView->View()->Export (argv[1], anExpFormat))
1923 std::cout << "Export failed!\n";
1929 //==============================================================================
1930 //function : VColorScale
1931 //purpose : representation color scale
1932 //==============================================================================
1933 #include <V3d_ColorScale.hxx>
1935 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1937 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1939 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1943 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1944 if(aContext.IsNull()) {
1945 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1949 Standard_Real minRange = 0. , maxRange = 100. ;
1951 Standard_Integer numIntervals = 10 ;
1952 Standard_Integer textHeight = 16;
1953 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1954 Standard_Real X = 0., Y = 0. ;
1960 minRange = atof( argv[1] );
1961 maxRange = atof( argv[2] );
1962 numIntervals = atoi( argv[3] );
1965 textHeight = atoi( argv[4] );
1967 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1970 X = atof( argv[6] );
1971 Y = atof( argv[7] );
1974 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1975 if ( curView.IsNull( ) )
1977 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1978 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1979 if( ! aCS.IsNull( ) )
1981 aCS->SetPosition( X , Y );
1982 aCS->SetHeight( 0.95) ;
1983 aCS->SetTextHeight( textHeight );
1984 aCS->SetRange( minRange , maxRange );
1985 aCS->SetNumberOfIntervals( numIntervals );
1986 aCS->SetLabelPosition( position );
1987 if( !curView->ColorScaleIsDisplayed() )
1988 curView->ColorScaleDisplay( );
1993 //==============================================================================
1994 //function : VGraduatedTrihedron
1995 //purpose : Displays a graduated trihedron
1996 //==============================================================================
1998 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2000 const char *str = arg;
2003 unsigned short c1 = *str++;
2004 unsigned short c2 = *str++;
2005 if (!c1 || !c2) break;
2006 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2010 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2013 if (argc != 2 && argc < 5)
2015 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2016 di<<"Usage: type help "<<argv[0]<<"\n";
2017 return 1; //TCL_ERROR
2020 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2022 // Create 3D view if it doesn't exist
2023 if ( aV3dView.IsNull() )
2025 ViewerTest::ViewerInit();
2026 aV3dView = ViewerTest::CurrentView();
2027 if( aV3dView.IsNull() )
2029 di << "Error: Cannot create a 3D view\n";
2030 return 1; //TCL_ERROR
2034 // Erase (==0) or display (!=0)
2035 const int display = atoi(argv[1]);
2040 TCollection_AsciiString font;
2042 font.AssignCat("Courier");
2044 font.AssignCat(argv[5]);
2046 // Text is multibyte
2047 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
2050 TCollection_ExtendedString xname, yname, zname;
2055 AddMultibyteString(xname, argv[2]);
2056 AddMultibyteString(yname, argv[3]);
2057 AddMultibyteString(zname, argv[4]);
2073 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2074 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2075 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2076 Standard_True/*drawgrid*/,
2077 Standard_True/*drawaxes*/,
2078 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2079 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2080 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2081 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2082 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2083 Quantity_NOC_WHITE/*gridcolor*/,
2084 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2085 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2088 aV3dView->GraduatedTrihedronErase();
2090 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2096 //==============================================================================
2097 //function : VPrintView
2098 //purpose : Test printing algorithm, print the view to image file with given
2099 // width and height. Printing implemented only for WNT.
2100 //==============================================================================
2101 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2105 di << "Printing implemented only for wnt!\n";
2109 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2110 Handle(V3d_View) aView = NULL;
2111 aContextAIS = ViewerTest::GetAISContext();
2112 if (!aContextAIS.IsNull())
2114 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2115 Vwr->InitActiveViews();
2116 if(Vwr->MoreActiveViews())
2117 aView = Vwr->ActiveView();
2123 di << "Call vinit before!\n";
2128 di << "Use: " << argv[0];
2129 di << " width height filename [print algo=0]\n";
2130 di << "width, height of the intermediate buffer for operation\n";
2131 di << "algo : {0|1}\n";
2132 di << " 0 - stretch algorithm\n";
2133 di << " 1 - tile algorithm\n";
2134 di << "test printing algorithms into an intermediate buffer\n";
2135 di << "with saving output to an image file\n";
2139 // get the input params
2140 Standard_Integer aWidth = atoi (argv[1]);
2141 Standard_Integer aHeight = atoi (argv[2]);
2142 Standard_Integer aMode = 0;
2143 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2145 aMode = atoi (argv[4]);
2147 // check the input parameters
2148 if (aWidth <= 0 || aHeight <= 0)
2150 di << "Width and height must be positive values!\n";
2153 if (aMode != 0 && aMode != 1)
2156 // define compatible bitmap
2157 HDC anDC = CreateCompatibleDC(0);
2158 BITMAPINFO aBitmapData;
2159 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2160 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2161 aBitmapData.bmiHeader.biWidth = aWidth ;
2162 aBitmapData.bmiHeader.biHeight = aHeight;
2163 aBitmapData.bmiHeader.biPlanes = 1;
2164 aBitmapData.bmiHeader.biBitCount = 24;
2165 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2166 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2167 aBitmapData.bmiHeader.biClrUsed = 0;
2168 aBitmapData.bmiHeader.biClrImportant = 0;
2169 aBitmapData.bmiHeader.biCompression = BI_RGB;
2170 aBitmapData.bmiHeader.biSizeImage = 0;
2172 // Create Device Independent Bitmap
2173 void* aBitsOut = NULL;
2174 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2175 &aBitsOut, NULL, 0);
2176 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2178 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2179 if (aBitsOut != NULL)
2182 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2184 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2186 // succesfully printed into an intermediate buffer
2189 Image_PixMap aWrapper;
2190 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2191 aWrapper.SetTopDown (false);
2193 Image_AlienPixMap anImageBitmap;
2194 anImageBitmap.InitCopy (aWrapper);
2195 isSaved = anImageBitmap.Save (aFileName);
2199 di << "Print operation failed due to printing errors or\n";
2200 di << "insufficient memory available\n";
2201 di << "Please, try to use smaller dimensions for this test\n";
2202 di << "command, as it allocates intermediate buffer for storing\n";
2203 di << "the result\n";
2208 di << "Can't allocate memory for intermediate buffer\n";
2209 di << "Please use smaller dimensions\n";
2214 SelectObject (anDC, anOldBitmap);
2215 DeleteObject (aMemoryBitmap);
2221 di << "Save to file operation failed. This operation may fail\n";
2222 di << "if you don't have enough available memory, then you can\n";
2223 di << "use smaller dimensions for the output file\n";
2232 //==============================================================================
2233 //function : VZLayer
2234 //purpose : Test z layer operations for v3d viewer
2235 //==============================================================================
2236 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2238 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2239 if (aContextAIS.IsNull())
2241 di << "Call vinit before!\n";
2246 di << "Use: vzlayer " << argv[0];
2247 di << " add/del/get [id]\n";
2248 di << " add - add new z layer to viewer and print its id\n";
2249 di << " del - del z layer by its id\n";
2250 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2251 di << "id - the layer identificator value defined when removing z layer\n";
2255 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2256 if (aViewer.IsNull())
2258 di << "No active viewer!\n";
2262 // perform operation
2263 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2266 Standard_Integer aNewId;
2267 if (!aViewer->AddZLayer (aNewId))
2269 di << "Impossible to add new z layer!\n";
2273 di << "New z layer added with index: " << aNewId << "\n";
2275 else if (anOp == "del")
2279 di << "Please also provide as argument id of z layer to remove\n";
2283 Standard_Integer aDelId = atoi (argv[2]);
2284 if (!aViewer->RemoveZLayer (aDelId))
2286 di << "Impossible to remove the z layer or invalid id!\n";
2290 di << "Z layer " << aDelId << " has been removed\n";
2292 else if (anOp == "get")
2294 TColStd_SequenceOfInteger anIds;
2295 aViewer->GetAllZLayers (anIds);
2296 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2298 di << anIds.Value (aSeqIdx) << " ";
2305 di << "Invalid operation, please use { add / del / get }\n";
2312 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2314 // this class provides a presentation of text item in v3d view under-/overlayer
2315 class V3d_TextItem : public Visual3d_LayerItem
2320 DEFINE_STANDARD_RTTI(V3d_TextItem)
2323 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2324 const Standard_Real theX1,
2325 const Standard_Real theY1,
2326 const Standard_Real theHeight,
2327 const TCollection_AsciiString& theFontName,
2328 const Quantity_Color& theColor,
2329 const Quantity_Color& theSubtitleColor,
2330 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2331 const Handle(Visual3d_Layer)& theLayer);
2334 Standard_EXPORT void RedrawLayerPrs();
2340 Standard_Real myHeight;
2341 TCollection_AsciiString myText;
2342 TCollection_AsciiString myFontName;
2343 Quantity_Color myColor;
2344 Quantity_Color mySubtitleColor;
2345 Aspect_TypeOfDisplayText myType;
2346 Handle(Visual3d_Layer) myLayer;
2350 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2351 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2353 // create and add to display the text item
2354 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2355 const Standard_Real theX1,
2356 const Standard_Real theY1,
2357 const Standard_Real theHeight,
2358 const TCollection_AsciiString& theFontName,
2359 const Quantity_Color& theColor,
2360 const Quantity_Color& theSubtitleColor,
2361 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2362 const Handle(Visual3d_Layer)& theLayer)
2363 : myX1 (theX1), myY1 (theY1),
2365 myHeight (theHeight),
2368 mySubtitleColor (theSubtitleColor),
2369 myType (theTypeOfDisplay),
2370 myFontName (theFontName)
2372 if (!myLayer.IsNull ())
2373 myLayer->AddLayerItem (this);
2377 void V3d_TextItem::RedrawLayerPrs ()
2379 if (myLayer.IsNull ())
2382 myLayer->SetColor (myColor);
2383 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2384 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2387 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2389 // The Visual3d_LayerItem line item for "vlayerline" command
2390 // it provides a presentation of line with user-defined
2391 // linewidth, linetype and transparency.
2392 class V3d_LineItem : public Visual3d_LayerItem
2396 DEFINE_STANDARD_RTTI(V3d_LineItem)
2399 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2400 Standard_Real X2, Standard_Real Y2,
2401 V3d_LayerMgrPointer theLayerMgr,
2402 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2403 Standard_Real theWidth = 0.5,
2404 Standard_Real theTransp = 1.0);
2407 Standard_EXPORT void RedrawLayerPrs();
2411 Standard_Real myX1, myY1, myX2, myY2;
2412 Standard_Real myWidth;
2413 Standard_Real myTransparency;
2414 Aspect_TypeOfLine myType;
2415 V3d_LayerMgrPointer myLayerMgr;
2418 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2419 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2421 // default constructor for line item
2422 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2423 Standard_Real X2, Standard_Real Y2,
2424 V3d_LayerMgrPointer theLayerMgr,
2425 Aspect_TypeOfLine theType,
2426 Standard_Real theWidth,
2427 Standard_Real theTransp) :
2428 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2429 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2431 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
2432 myLayerMgr->Overlay()->AddLayerItem (this);
2436 void V3d_LineItem::RedrawLayerPrs ()
2438 Handle (Visual3d_Layer) aOverlay;
2441 aOverlay = myLayerMgr->Overlay();
2443 if (!aOverlay.IsNull())
2445 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2446 aOverlay->SetColor(aColor);
2447 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2448 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2449 aOverlay->BeginPolyline();
2450 aOverlay->AddVertex(myX1, myY1);
2451 aOverlay->AddVertex(myX2, myY2);
2452 aOverlay->ClosePrimitive();
2456 //=============================================================================
2457 //function : VLayerLine
2458 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2459 // : linewidth, transparency coefficient
2460 //============================================================================
2461 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2463 // get the active view
2464 Handle(V3d_View) aView = ViewerTest::CurrentView();
2467 di << "Call vinit before!\n";
2472 di << "Use: " << argv[0];
2473 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2474 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2475 di << " 0 - solid \n";
2476 di << " 1 - dashed \n";
2477 di << " 2 - dot \n";
2478 di << " 3 - dashdot\n";
2479 di << " transparency : { 0.0 - 1.0 } \n";
2480 di << " 0.0 - transparent\n";
2481 di << " 1.0 - visible \n";
2485 // get the input params
2486 Standard_Real X1 = atof(argv[1]);
2487 Standard_Real Y1 = atof(argv[2]);
2488 Standard_Real X2 = atof(argv[3]);
2489 Standard_Real Y2 = atof(argv[4]);
2491 Standard_Real aWidth = 0.5;
2492 Standard_Integer aType = 0;
2493 Standard_Real aTransparency = 1.0;
2497 aWidth = atof(argv[5]);
2501 aType = (Standard_Integer) atoi(argv[6]);
2506 aTransparency = atof(argv[7]);
2507 if (aTransparency < 0 || aTransparency > 1.0)
2508 aTransparency = 1.0;
2511 // select appropriate line type
2512 Aspect_TypeOfLine aLineType;
2516 aLineType = Aspect_TOL_DASH;
2520 aLineType = Aspect_TOL_DOT;
2524 aLineType = Aspect_TOL_DOTDASH;
2528 aLineType = Aspect_TOL_SOLID;
2531 // replace layer manager
2532 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2533 aView->SetLayerMgr(aMgr);
2536 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2542 aView->MustBeResized();
2548 //=======================================================================
2549 //function : VOverlayText
2550 //purpose : Test text displaying in view overlay
2551 //=======================================================================
2552 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2554 // get the active view
2555 Handle(V3d_View) aView = ViewerTest::CurrentView();
2558 di << "No active view. Please call vinit.\n";
2561 else if (argc < 4 || argc > 13)
2563 di << "Use: " << argv[0];
2564 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2565 di << "[background_color: R G B]\n";
2566 di << " height - pixel height of the text (default=10.0)\n";
2567 di << " font_name - name of font (default=courier)\n";
2568 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2569 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2570 di << " background_color- R G B values used for subtitle and decal text\n";
2571 di << "(default=255.0 255.0 255.0)\n";
2575 TCollection_AsciiString aText (argv[1]);
2576 Standard_Real aPosX = atof(argv[2]);
2577 Standard_Real aPosY = atof(argv[3]);
2578 Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
2581 TCollection_AsciiString aFontName = "Courier";
2583 aFontName = TCollection_AsciiString (argv[5]);
2586 Quantity_Parameter aColorRed = 1.0;
2587 Quantity_Parameter aColorGreen = 1.0;
2588 Quantity_Parameter aColorBlue = 1.0;
2591 aColorRed = atof (argv[6])/255.;
2592 aColorGreen = atof (argv[7])/255.;
2593 aColorBlue = atof (argv[8])/255.;
2597 TCollection_AsciiString aDispStr;
2599 aDispStr = TCollection_AsciiString (argv[9]);
2601 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2602 if (aDispStr.IsEqual ("subtitle"))
2603 aTextType = Aspect_TODT_SUBTITLE;
2604 else if (aDispStr.IsEqual ("decal"))
2605 aTextType = Aspect_TODT_DEKALE;
2606 else if (aDispStr.IsEqual ("blend"))
2607 aTextType = Aspect_TODT_BLEND;
2610 Quantity_Parameter aSubRed = 1.0;
2611 Quantity_Parameter aSubGreen = 1.0;
2612 Quantity_Parameter aSubBlue = 1.0;
2615 aSubRed = atof (argv[10])/255.;
2616 aSubGreen = atof (argv[11])/255.;
2617 aSubBlue = atof (argv[12])/255.;
2620 // check fo current overlay
2621 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2622 if (anOverlay.IsNull ())
2624 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2625 anOverlay = aMgr->Overlay ();
2626 aView->SetLayerMgr (aMgr);
2629 Quantity_Color aTextColor (aColorRed, aColorGreen,
2630 aColorBlue, Quantity_TOC_RGB);
2631 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2632 aSubBlue, Quantity_TOC_RGB);
2635 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2636 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2639 aView->MustBeResized();
2645 //==============================================================================
2648 //==============================================================================
2650 static int VGrid (Draw_Interpretor& theDI,
2651 Standard_Integer theArgNb,
2652 const char** theArgVec)
2654 // get the active view
2655 Handle(V3d_View) aView = ViewerTest::CurrentView();
2656 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2657 if (aView.IsNull() || aViewer.IsNull())
2659 std::cerr << "No active view. Please call vinit.\n";
2663 Aspect_GridType aType = aViewer->GridType();
2664 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2666 Standard_Integer anIter = 1;
2667 for (; anIter < theArgNb; ++anIter)
2669 const char* aValue = theArgVec[anIter];
2672 aType = Aspect_GT_Rectangular;
2674 else if (*aValue == 'c')
2676 aType = Aspect_GT_Circular;
2678 else if (*aValue == 'l')
2680 aMode = Aspect_GDM_Lines;
2682 else if (*aValue == 'p')
2684 aMode = Aspect_GDM_Points;
2686 else if (strcmp (aValue, "off" ) == 0)
2688 aViewer->DeactivateGrid();
2697 Standard_Integer aTail = (theArgNb - anIter);
2700 aViewer->ActivateGrid (aType, aMode);
2703 else if (aTail != 2 && aTail != 5)
2705 std::cerr << "Incorrect arguments number! Usage:\n"
2706 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2710 Quantity_Length anOriginX, anOriginY;
2711 Quantity_PlaneAngle aRotAngle;
2712 if (aType == Aspect_GT_Rectangular)
2714 Quantity_Length aRStepX, aRStepY;
2715 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2717 anOriginX = atof (theArgVec[anIter++]);
2718 anOriginY = atof (theArgVec[anIter++]);
2721 aRStepX = atof (theArgVec[anIter++]);
2722 aRStepY = atof (theArgVec[anIter++]);
2723 aRotAngle = atof (theArgVec[anIter++]);
2725 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2726 aViewer->ActivateGrid (aType, aMode);
2728 else if (aType == Aspect_GT_Circular)
2730 Quantity_Length aRadiusStep;
2731 Standard_Integer aDivisionNumber;
2732 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2734 anOriginX = atof (theArgVec[anIter++]);
2735 anOriginY = atof (theArgVec[anIter++]);
2738 aRadiusStep = atof (theArgVec[anIter++]);
2739 aDivisionNumber = atoi (theArgVec[anIter++]);
2740 aRotAngle = atof (theArgVec[anIter++]);
2743 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2744 aViewer->ActivateGrid (aType, aMode);
2750 //==============================================================================
2753 //==============================================================================
2755 static int VFps (Draw_Interpretor& theDI,
2756 Standard_Integer theArgNb,
2757 const char** theArgVec)
2759 // get the active view
2760 Handle(V3d_View) aView = ViewerTest::CurrentView();
2763 std::cerr << "No active view. Please call vinit.\n";
2767 Standard_Integer aFramesNb = (theArgNb > 1) ? atoi(theArgVec[1]) : 100;
2770 std::cerr << "Incorrect arguments!\n";
2774 // the time is meaningless for first call
2775 // due to async OpenGl rendering
2778 // redraw view in loop to estimate average values
2781 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2787 const Standard_Real aTime = aTimer.ElapsedTime();
2788 aTimer.OSD_Chronometer::Show (aCpu);
2790 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2791 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2793 // return statistics
2794 theDI << "FPS: " << aFpsAver << "\n"
2795 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2801 //==============================================================================
2804 //==============================================================================
2806 static int VVbo (Draw_Interpretor& theDI,
2807 Standard_Integer theArgNb,
2808 const char** theArgVec)
2811 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2812 if (aContextAIS.IsNull())
2814 std::cerr << "No active view. Please call vinit.\n";
2818 Handle(Graphic3d_GraphicDriver) aDriver =
2819 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2820 if (aDriver.IsNull())
2822 std::cerr << "Graphic driver not available.\n";
2828 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2830 std::cerr << "Wrong number of arguments.\n";
2834 aDriver->EnableVBO (atoi(theArgVec[1]) != 0);
2838 //==============================================================================
2839 //function : VMemGpu
2841 //==============================================================================
2843 static int VMemGpu (Draw_Interpretor& theDI,
2844 Standard_Integer theArgNb,
2845 const char** theArgVec)
2848 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2849 if (aContextAIS.IsNull())
2851 std::cerr << "No active view. Please call vinit.\n";
2855 Handle(Graphic3d_GraphicDriver) aDriver =
2856 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2857 if (aDriver.IsNull())
2859 std::cerr << "Graphic driver not available.\n";
2863 Standard_Size aFreeBytes = 0;
2864 TCollection_AsciiString anInfo;
2865 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
2867 std::cerr << "Information not available.\n";
2871 if (theArgNb > 1 && *theArgVec[1] == 'f')
2873 theDI << Standard_Real (aFreeBytes);
2883 // ==============================================================================
2884 // function : VReadPixel
2886 // ==============================================================================
2887 static int VReadPixel (Draw_Interpretor& theDI,
2888 Standard_Integer theArgNb,
2889 const char** theArgVec)
2891 // get the active view
2892 Handle(V3d_View) aView = ViewerTest::CurrentView();
2895 std::cerr << "No active view. Please call vinit.\n";
2898 else if (theArgNb < 3)
2900 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
2904 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2905 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
2907 Standard_Integer aWidth, aHeight;
2908 aView->Window()->Size (aWidth, aHeight);
2909 const Standard_Integer anX = atoi (theArgVec[1]);
2910 const Standard_Integer anY = atoi (theArgVec[2]);
2911 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
2913 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
2917 Standard_Boolean toShowName = Standard_False;
2918 Standard_Boolean toShowHls = Standard_False;
2919 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
2921 TCollection_AsciiString aParam (theArgVec[anIter]);
2922 if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb")))
2924 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2925 aBufferType = Graphic3d_BT_RGB;
2927 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
2929 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2930 aBufferType = Graphic3d_BT_RGB;
2931 toShowHls = Standard_True;
2933 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
2935 aFormat = Image_PixMap::ImgRGBF;
2936 aBufferType = Graphic3d_BT_RGB;
2938 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
2940 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2941 aBufferType = Graphic3d_BT_RGBA;
2943 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
2945 aFormat = Image_PixMap::ImgRGBAF;
2946 aBufferType = Graphic3d_BT_RGBA;
2948 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
2950 aFormat = Image_PixMap::ImgGrayF;
2951 aBufferType = Graphic3d_BT_Depth;
2953 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
2955 toShowName = Standard_True;
2959 Image_PixMap anImage;
2960 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
2962 std::cerr << "Image allocation failed\n";
2965 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
2967 std::cerr << "Image dump failed\n";
2971 Quantity_Parameter anAlpha;
2972 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
2975 if (aBufferType == Graphic3d_BT_RGBA)
2977 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
2981 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
2986 switch (aBufferType)
2989 case Graphic3d_BT_RGB:
2993 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
2997 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3001 case Graphic3d_BT_RGBA:
3003 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3006 case Graphic3d_BT_Depth:
3008 theDI << aColor.Red() << "\n";
3017 //==============================================================================
3018 //function : VDiffImage
3019 //purpose : The draw-command compares two images.
3020 //==============================================================================
3022 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3026 theDI << "Not enough arguments.\n";
3031 const char* anImgPathRef = theArgVec[1];
3032 const char* anImgPathNew = theArgVec[2];
3034 // get string tolerance and check its validity
3035 Standard_Real aTolColor = atof (theArgVec[3]);
3036 if (aTolColor < 0.0)
3038 if (aTolColor > 1.0)
3041 Standard_Boolean toBlackWhite = (atoi (theArgVec[4]) == 1);
3042 Standard_Boolean isBorderFilterOn = (atoi (theArgVec[5]) == 1);
3044 // image file of difference
3045 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3047 // compare the images
3048 Image_Diff aComparer;
3049 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3054 aComparer.SetColorTolerance (aTolColor);
3055 aComparer.SetBorderFilterOn (isBorderFilterOn);
3056 Standard_Integer aDiffColorsNb = aComparer.Compare();
3057 theDI << aDiffColorsNb << "\n";
3059 // save image of difference
3060 if (aDiffImagePath != NULL)
3062 aComparer.SaveDiffImage (aDiffImagePath);
3068 //=======================================================================
3069 //function : ViewerCommands
3071 //=======================================================================
3073 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3076 const char *group = "ZeViewer";
3077 theCommands.Add("vinit" ,
3078 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3079 __FILE__,VInit,group);
3080 theCommands.Add("vhelp" ,
3081 "vhelp : display help on the viewer commands",
3082 __FILE__,VHelp,group);
3083 theCommands.Add("vtop" ,
3084 "vtop or <T> : Top view" ,
3085 __FILE__,VTop,group);
3086 theCommands.Add("vbottom" ,
3087 "vbottom : Bottom view" ,
3088 __FILE__,VBottom,group);
3089 theCommands.Add("vleft" ,
3090 "vleft : Left view" ,
3091 __FILE__,VLeft,group);
3092 theCommands.Add("vright" ,
3093 "vright : Right view" ,
3094 __FILE__,VRight,group);
3095 theCommands.Add("vaxo" ,
3096 " vaxo or <A> : Axonometric view ",
3097 __FILE__,VAxo,group);
3098 theCommands.Add("vfront" ,
3099 "vfront : Front view" ,
3100 __FILE__,VFront,group);
3101 theCommands.Add("vback" ,
3102 "vback : Back view" ,
3103 __FILE__,VBack,group);
3104 theCommands.Add("vpick" ,
3105 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
3107 theCommands.Add("vfit" ,
3108 "vfit or <F> : vfit",
3109 __FILE__,VFit,group);
3110 theCommands.Add("vzfit" ,
3112 __FILE__,VZFit,group);
3113 theCommands.Add("vrepaint",
3114 "vrepaint : vrepaint, force redraw",
3115 __FILE__,VRepaint,group);
3116 theCommands.Add("vclear",
3118 __FILE__,VClear,group);
3119 theCommands.Add("vsetbg",
3120 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
3121 __FILE__,VSetBg,group);
3122 theCommands.Add("vsetbgmode",
3123 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
3124 __FILE__,VSetBgMode,group);
3125 theCommands.Add("vsetgradientbg",
3126 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
3127 __FILE__,VSetGradientBg,group);
3128 theCommands.Add("vsetgrbgmode",
3129 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
3130 __FILE__,VSetGradientBgMode,group);
3131 theCommands.Add("vsetcolorbg",
3132 "vsetcolorbg : vsetcolorbg r g b : Set background color",
3133 __FILE__,VSetColorBg,group);
3134 theCommands.Add("vscale",
3135 "vscale : vscale X Y Z",
3136 __FILE__,VScale,group);
3137 theCommands.Add("vzbufftrihedron",
3138 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3139 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3140 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
3141 __FILE__,VTestZBuffTrihedron,group);
3142 theCommands.Add("vrotate",
3143 "vrotate : vrotate AX AY AZ [X Y Z]",
3144 __FILE__,VRotate,group);
3145 theCommands.Add("vzoom",
3146 "vzoom : vzoom coef",
3147 __FILE__,VZoom,group);
3148 theCommands.Add("vpan",
3149 "vpan : vpan dx dy",
3150 __FILE__,VPan,group);
3151 theCommands.Add("vexport",
3152 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3153 " : exports the view to a vector file of a given format"
3154 " : notice that EMF format requires patched gl2ps",
3155 __FILE__,VExport,group);
3156 theCommands.Add("vcolorscale",
3157 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3158 __FILE__,VColorScale,group);
3159 theCommands.Add("vgraduatedtrihedron",
3160 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
3161 __FILE__,VGraduatedTrihedron,group);
3162 theCommands.Add("vprintview" ,
3163 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3164 __FILE__,VPrintView,group);
3165 theCommands.Add("vzlayer",
3166 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3167 __FILE__,VZLayer,group);
3168 theCommands.Add("voverlaytext",
3169 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
3170 " : height - pixel height of the text (default=10.0)"
3171 " : font_name - name of font (default=courier)"
3172 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
3173 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
3174 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
3175 __FILE__,VOverlayText,group);
3176 theCommands.Add("vlayerline",
3177 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
3178 __FILE__,VLayerLine,group);
3179 theCommands.Add ("vgrid",
3180 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
3181 " : Mode - rectangular or circular"
3182 " : Type - lines or points",
3183 __FILE__, VGrid, group);
3184 theCommands.Add ("vfps",
3185 "vfps [framesNb=100] : estimate average frame rate for active view",
3186 __FILE__, VFps, group);
3187 theCommands.Add ("vvbo",
3188 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
3189 __FILE__, VVbo, group);
3190 theCommands.Add ("vmemgpu",
3191 "vmemgpu [f]: print system-dependent GPU memory information if available;"
3192 " with f option returns free memory in bytes",
3193 __FILE__, VMemGpu, group);
3194 theCommands.Add ("vreadpixel",
3195 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
3196 " : Read pixel value for active view",
3197 __FILE__, VReadPixel, group);
3198 theCommands.Add("diffimage",
3199 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
3200 __FILE__, VDiffImage, group);