1 // File: ViewerTest_ViewerCommands.cxx
2 // Created: Tue Sep 1 10:28:35 1998
3 // Author: Robert COUBLANC
4 // <rob@robox.paris1.matra-dtv.fr>
6 // Robert Boehne 30 May 2000 : Dec Osf
16 #include <Graphic3d_ExportFormat.hxx>
17 #include <ViewerTest.hxx>
18 #include <ViewerTest_EventManager.hxx>
19 #include <Visual3d_View.hxx>
20 #include <NIS_View.hxx>
21 #include <NIS_Triangulated.hxx>
22 #include <NIS_InteractiveContext.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <Draw_Interpretor.hxx>
26 #include <Draw_Appli.hxx>
27 #include <Aspect_PrintAlgo.hxx>
28 #include <Image_PixMap.hxx>
29 #include <TColStd_SequenceOfInteger.hxx>
32 #include <Graphic3d_GraphicDevice.hxx>
33 #include <Xw_GraphicDevice.hxx>
34 #include <Xw_WindowQuality.hxx>
35 #include <Xw_Window.hxx>
36 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
37 #include <X11/Xutil.h>
42 #include <Graphic3d_WNTGraphicDevice.hxx>
43 #include <WNT_WClass.hxx>
44 #include <WNT_Window.hxx>
46 #define _CRT_SECURE_NO_DEPRECATE
47 #pragma warning (disable:4996)
53 //==============================================================================
55 //==============================================================================
56 // VIEWER GLOBAL VARIABLES
57 //==============================================================================
59 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
61 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
62 extern const Handle(NIS_InteractiveContext)& TheNISContext();
65 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
66 static Handle(Graphic3d_WNTGraphicDevice) GD;
70 static Handle(WNT_Window)& VT_GetWindow() {
71 static Handle(WNT_Window) WNTWin;
76 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
77 static Handle(Graphic3d_GraphicDevice) GD;
80 static Handle(Xw_Window)& VT_GetWindow(){
81 static Handle(Xw_Window) XWWin;
84 static Display *display;
86 static void VProcessEvents(ClientData,int);
90 static Standard_Boolean DegenerateMode = Standard_True;
95 static void OSWindowSetup();
97 //==============================================================================
98 // EVENT GLOBAL VARIABLES
99 //==============================================================================
101 static int Start_Rot = 0;
102 static int ZClipIsOn = 0;
103 static int X_Motion= 0,Y_Motion=0; // Current cursor position
104 static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
107 //==============================================================================
110 static LRESULT WINAPI ViewerWindowProc(
115 static LRESULT WINAPI AdvViewerWindowProc(
123 //==============================================================================
126 //==============================================================================
128 const Handle(MMgt_TShared)& ViewerTest::WClass()
130 static Handle(MMgt_TShared) theWClass;
132 if (theWClass.IsNull()) {
133 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
134 CS_VREDRAW | CS_HREDRAW, 0, 0,
135 ::LoadCursor (NULL, IDC_ARROW));
141 //==============================================================================
142 //function : ViewerInit
143 //purpose : Create the window viewer and initialize all the global variable
144 //==============================================================================
146 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
147 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
149 static Standard_Boolean isFirst = Standard_True;
151 Standard_Integer aPxLeft = 0;
152 Standard_Integer aPxTop = 460;
153 Standard_Integer aPxWidth = 409;
154 Standard_Integer aPxHeight = 409;
155 if (thePxWidth != 0 && thePxHeight != 0)
159 aPxWidth = thePxWidth;
160 aPxHeight = thePxHeight;
165 // Create the Graphic device
167 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
168 if (VT_GetWindow().IsNull())
170 // Create the Graphic device and the window
171 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
173 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
174 Handle(WNT_WClass)::DownCast (WClass()),
179 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
182 if (GetG3dDevice().IsNull()) GetG3dDevice() =
183 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
184 if (VT_GetWindow().IsNull())
186 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
192 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
196 Handle(V3d_Viewer) a3DViewer, a3DCollector;
197 // Viewer and View creation
199 TCollection_ExtendedString NameOfWindow("Visu3D");
201 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
202 NameOfWindow = TCollection_ExtendedString("Collector");
203 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
204 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
205 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
206 Handle(NIS_View) aView =
207 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
208 if ( aView.IsNull() ) {
209 // Handle (V3d_View) V = a3DViewer->CreateView();
210 aView = new NIS_View (a3DViewer, VT_GetWindow());
211 ViewerTest::CurrentView(aView);
212 TheNISContext()->AttachView (aView);
214 Handle(V3d_View) a3DViewCol;
215 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
218 if ( ViewerTest::GetAISContext().IsNull() ) {
219 Handle(AIS_InteractiveContext) C =
220 new AIS_InteractiveContext(a3DViewer,a3DCollector);
221 ViewerTest::SetAISContext(C);
224 // Setup for X11 or NT
226 // Viewer and View creation
228 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
230 Handle (V3d_View) V = ViewerTest::CurrentView();
232 V->SetDegenerateModeOn();
234 DegenerateMode = V->DegenerateModeIsOn();
236 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
238 V->SetZClippingDepth(0.5);
239 V->SetZClippingWidth(ZCLIPWIDTH/2.);
240 a3DViewer->SetDefaultLights();
241 a3DViewer->SetLightOn();
244 #if TCL_MAJOR_VERSION < 8
245 Tk_CreateFileHandler((void*)ConnectionNumber(display),
246 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
248 Tk_CreateFileHandler(ConnectionNumber(display),
249 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
253 isFirst = Standard_False;
255 VT_GetWindow()->Map();
258 //==============================================================================
260 //purpose : Create the window viewer and initialize all the global variable
261 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
262 //==============================================================================
264 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
266 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
267 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
268 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
269 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
270 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
274 //==============================================================================
275 //function : ProcessKeyPress
276 //purpose : Handle KeyPress event from a CString
277 //==============================================================================
279 static void ProcessKeyPress( char *buf_ret )
281 //cout << "KeyPress" << endl;
282 const Handle(V3d_View) aView = ViewerTest::CurrentView();
283 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
284 // Letter in alphabetic order
286 if ( !strcasecmp(buf_ret, "A") ) {
288 aView->SetProj(V3d_XposYnegZpos);
290 else if ( !strcasecmp(buf_ret, "D") ) {
294 else if ( !strcasecmp(buf_ret, "F") ) {
296 if (aNisView.IsNull())
299 aNisView->FitAll3d();
301 else if ( !strcasecmp(buf_ret, "H") ) {
303 cout << "HLR" << endl;
305 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
306 else aView->SetDegenerateModeOn();
307 DegenerateMode = aView->DegenerateModeIsOn();
309 ViewerTest::CurrentView()->SetDegenerateModeOff();
312 else if ( !strcasecmp(buf_ret, "D") ) {
316 else if ( !strcasecmp(buf_ret, "S") ) {
318 cout << "passage en mode 1 (shading pour les shapes)" << endl;
320 ViewerTest::CurrentView()->SetDegenerateModeOn();
322 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
323 if(Ctx->NbCurrents()==0 ||
324 Ctx->NbSelected()==0)
325 Ctx->SetDisplayMode(AIS_Shaded);
327 if(Ctx->HasOpenedContext()){
328 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
329 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
332 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
333 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
335 Ctx->UpdateCurrentViewer();
338 else if ( !strcasecmp(buf_ret, "U") ) {
340 cout<<"passage au mode par defaut"<<endl;
342 ViewerTest::CurrentView()->SetDegenerateModeOn();
344 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
345 if(Ctx->NbCurrents()==0 ||
346 Ctx->NbSelected()==0)
347 Ctx->SetDisplayMode(AIS_WireFrame);
349 if(Ctx->HasOpenedContext()){
350 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
351 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
354 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
355 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
357 Ctx->UpdateCurrentViewer();
361 else if ( !strcasecmp(buf_ret, "T") ) {
363 aView->SetProj(V3d_Zpos);
365 else if ( !strcasecmp(buf_ret, "B") ) {
367 aView->SetProj(V3d_Zneg);
369 else if ( !strcasecmp(buf_ret, "L") ) {
371 aView->SetProj(V3d_Xneg);
373 else if ( !strcasecmp(buf_ret, "R") ) {
375 aView->SetProj(V3d_Xpos);
378 else if ( !strcasecmp(buf_ret, "W") ) {
381 ViewerTest::CurrentView()->SetDegenerateModeOn();
383 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
385 ViewerTest::CurrentView()->SetDegenerateModeOn();
387 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
388 if(Ctx->NbCurrents()==0 ||
389 Ctx->NbSelected()==0)
390 Ctx->SetDisplayMode(AIS_WireFrame);
392 if(Ctx->HasOpenedContext()){
393 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
394 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
397 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
398 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
400 Ctx->UpdateCurrentViewer();
403 else if ( !strcasecmp(buf_ret, "Z") ) {
407 cout << "ZClipping OFF" << endl;
410 aView->SetZClippingType(V3d_OFF);
414 cout << "ZClipping ON" << endl;
417 aView->SetZClippingType(V3d_FRONT);
421 else if ( !strcasecmp(buf_ret, ",") ) {
422 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
426 else if ( !strcasecmp(buf_ret, ".") ) {
427 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
431 Standard_Integer Num = atoi(buf_ret);
433 ViewerTest::StandardModeActivation(Num);
437 //==============================================================================
438 //function : ProcessExpose
439 //purpose : Redraw the View on an Expose Event
440 //==============================================================================
442 static void ProcessExpose( )
443 { //cout << "Expose" << endl;
444 ViewerTest::CurrentView()->Redraw();
447 //==============================================================================
448 //function : ProcessConfigure
449 //purpose : Resize the View on an Configure Event
450 //==============================================================================
452 static void ProcessConfigure()
454 Handle(V3d_View) V = ViewerTest::CurrentView();
460 //==============================================================================
461 //function : ProcessButton1Press
463 //==============================================================================
465 static Standard_Boolean ProcessButton1Press(
468 Standard_Boolean pick,
469 Standard_Boolean shift )
471 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
473 Standard_Real X, Y, Z;
475 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
477 Draw::Set(argv[1], X);
478 Draw::Set(argv[2], Y);
479 Draw::Set(argv[3], Z);}
490 //==============================================================================
491 //function : ProcessButton3Press
492 //purpose : Start Rotation
493 //==============================================================================
495 static void ProcessButton3Press()
499 ViewerTest::CurrentView()->SetDegenerateModeOn();
500 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
503 //==============================================================================
504 //function : ProcessButtonRelease
505 //purpose : Start Rotation
506 //==============================================================================
508 static void ProcessButtonRelease()
514 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
518 ViewerTest::CurrentView()->SetDegenerateModeOff();
522 //==============================================================================
523 //function : ProcessZClipMotion
525 //==============================================================================
527 void ProcessZClipMotion()
529 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
530 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
531 static Standard_Real CurZPos = 0.;
533 //Quantity_Length VDX, VDY;
534 //a3DView->Size(VDX,VDY);
535 //Standard_Real VDZ = a3DView->ZSize();
536 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
538 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
540 // Front = Depth + width/2.
541 Standard_Real D = 0.5;
542 Standard_Real W = 0.1;
548 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
550 a3DView->SetZClippingType(V3d_OFF);
551 a3DView->SetZClippingDepth(D);
552 a3DView->SetZClippingWidth(W);
553 a3DView->SetZClippingType(V3d_FRONT);
557 X_ButtonPress = X_Motion;
558 Y_ButtonPress = Y_Motion;
562 //==============================================================================
563 //function : ProcessControlButton1Motion
565 //==============================================================================
567 static void ProcessControlButton1Motion()
569 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
571 X_ButtonPress = X_Motion;
572 Y_ButtonPress = Y_Motion;
575 //==============================================================================
576 //function : ProcessControlButton2Motion
578 //==============================================================================
580 static void ProcessControlButton2Motion()
582 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
583 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
585 dy = -dy; // Xwindow Y axis is from top to Bottom
587 ViewerTest::CurrentView()->Panning( dx, dy );
589 X_ButtonPress = X_Motion;
590 Y_ButtonPress = Y_Motion;
593 //==============================================================================
594 //function : ProcessControlButton3Motion
596 //==============================================================================
598 static void ProcessControlButton3Motion()
600 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
603 //==============================================================================
604 //function : ProcessPointerMotion
606 //==============================================================================
608 static void ProcessMotion()
610 //pre-hilights detected objects at mouse position
612 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
613 EM->MoveTo(X_Motion, Y_Motion);
617 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
619 Xpix = X_Motion;Ypix=Y_Motion;
622 //==============================================================================
624 //purpose : Switch to an Axonometric view
626 //==============================================================================
628 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
629 { if ( ViewerTest::CurrentView().IsNull() ) {
630 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
631 // VInit(di, argc, argv);
634 ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
639 //==============================================================================
641 //purpose : Switch to a Top View
643 //==============================================================================
645 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
648 if ( ViewerTest::CurrentView().IsNull() ) {
649 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
651 // VInit(di, , argv);
654 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
659 //==============================================================================
661 //purpose : Dsiplay help on viewer Keyboead and mouse commands
663 //==============================================================================
665 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
668 di << "Q : Quit the application" << "\n";
670 di << "========================="<<"\n";
671 di << "F : FitAll" << "\n";
672 di << "T : TopView" << "\n";
673 di << "A : AxonometricView" << "\n";
674 di << "R : ResetView" << "\n";
676 di << "========================="<<"\n";
677 di << "S : Shading" << "\n";
678 di << "W : Wireframe" << "\n";
679 di << "H : HidelLineRemoval" << "\n";
681 di << "========================="<<"\n";
682 di << "Selection mode "<<"\n";
683 di << "0 : Shape" <<"\n";
684 di << "1 : Vertex" <<"\n";
685 di << "2 : Edge" <<"\n";
686 di << "3 : Wire" <<"\n";
687 di << "4 : Face" <<"\n";
688 di << "5 : Shell" <<"\n";
689 di << "6 : Solid" <<"\n";
690 di << "7 : Compound" <<"\n";
692 di << "=========================="<<"\n";
693 di << "D : Remove Selected Object"<<"\n";
694 di << "=========================="<<"\n";
699 Standard_Boolean IsDragged = Standard_False;
701 Standard_Integer xx1, yy1, xx2, yy2;
702 //the first and last point in viewer co-ordinates
704 Standard_Boolean DragFirst;
709 static Standard_Boolean Ppick = 0;
710 static Standard_Integer Pargc = 0;
711 static const char** Pargv = NULL;
714 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
719 if ( !ViewerTest::CurrentView().IsNull() ) {
721 WPARAM fwKeys = wParam;
726 IsDragged = Standard_False;
729 HDC hdc = GetDC( hwnd );
730 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
731 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
732 SetROP2( hdc, R2_NOT );
733 Rectangle( hdc, xx1, yy1, xx2, yy2 );
734 ReleaseDC( hwnd, hdc );
736 const Handle(ViewerTest_EventManager) EM =
737 ViewerTest::CurrentEventManager();
738 if ( fwKeys & MK_SHIFT )
739 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
740 max( xx1, xx2 ), min( yy1, yy2 ));
742 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
743 max( xx1, xx2 ), min( yy1, yy2 ));
745 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
748 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
750 IsDragged = Standard_True;
751 DragFirst = Standard_True;
752 xx1 = LOWORD(lParam);
753 yy1 = HIWORD(lParam);
755 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
762 HDC hdc = GetDC( hwnd );
764 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
765 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
766 SetROP2( hdc, R2_NOT );
769 Rectangle( hdc, xx1, yy1, xx2, yy2 );
771 DragFirst = Standard_False;
772 xx2 = LOWORD(lParam);
773 yy2 = HIWORD(lParam);
775 Rectangle( hdc, xx1, yy1, xx2, yy2 );
777 SelectObject( hdc, anObj );
779 ReleaseDC( hwnd, hdc );
782 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
786 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
790 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
794 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
799 /*static Standard_Boolean Ppick = 0;
800 static Standard_Integer Pargc = 0;
801 static char** Pargv = NULL;*/
805 if ( !ViewerTest::CurrentView().IsNull() ) {
810 // do not destroy the window - just hide it!
811 VT_GetWindow()->Unmap();
814 //cout << "\t WM_PAINT" << endl;
815 BeginPaint(hwnd, &ps);
821 //cout << "\t WM_SIZE" << endl;
826 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
828 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
830 c[0] = (char) wParam;
839 //cout << "\t WM_xBUTTONUP" << endl;
841 ProcessButtonRelease();
848 //cout << "\t WM_xBUTTONDOWN" << endl;
849 WPARAM fwKeys = wParam;
853 X_ButtonPress = LOWORD(lParam);
854 Y_ButtonPress = HIWORD(lParam);
856 if ( Msg == WM_LBUTTONDOWN) {
857 if(fwKeys & MK_CONTROL) {
858 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
860 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
862 else if ( Msg == WM_RBUTTONDOWN ) {
864 ProcessButton3Press( );
871 //cout << "\t WM_MOUSEMOVE" << endl;
872 WPARAM fwKeys = wParam;
873 X_Motion = LOWORD(lParam);
874 Y_Motion = HIWORD(lParam);
877 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
879 X_ButtonPress = LOWORD(lParam);
880 Y_ButtonPress = HIWORD(lParam);
882 if ( fwKeys & MK_RBUTTON ) {
884 ProcessButton3Press();
888 if ( fwKeys & MK_CONTROL ) {
889 if ( fwKeys & MK_LBUTTON ) {
890 ProcessControlButton1Motion();
892 else if ( fwKeys & MK_MBUTTON ||
893 ((fwKeys&MK_LBUTTON) &&
894 (fwKeys&MK_RBUTTON) ) ){
895 ProcessControlButton2Motion();
897 else if ( fwKeys & MK_RBUTTON ) {
898 ProcessControlButton3Motion();
902 else if ( fwKeys & MK_SHIFT ) {
903 if ( fwKeys & MK_MBUTTON ||
904 ((fwKeys&MK_LBUTTON) &&
905 (fwKeys&MK_RBUTTON) ) ) {
906 cout << "ProcessZClipMotion()" << endl;
907 ProcessZClipMotion();
912 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
913 ProcessZClipMotion();
922 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
927 return DefWindowProc( hwnd, Msg, wParam, lParam );
933 //==============================================================================
934 //function : ViewerMainLoop
935 //purpose : Get a Event on the view and dispatch it
936 //==============================================================================
939 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
942 //cout << "No yet implemented on WNT" << endl;
943 /*static Standard_Boolean Ppick = 0;
944 static Standard_Integer Pargc = 0;
945 static char** Pargv = NULL;*/
947 //Ppick = (argc > 0)? -1 : 0;
948 Ppick = (argc > 0)? 1 : 0;
956 cout << "Start picking" << endl;
958 //while ( Ppick == -1 ) {
959 while ( Ppick == 1 ) {
960 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
961 if (GetMessage(&msg, NULL, 0, 0) ) {
962 TranslateMessage(&msg);
963 DispatchMessage(&msg);
967 cout << "Picking done" << endl;
976 int min( int a, int b )
984 int max( int a, int b )
992 int ViewerMainLoop(Standard_Integer argc, const char** argv)
994 { Standard_Boolean pick = argc > 0;
998 static XEvent report;
1000 XNextEvent( display, &report );
1001 // cout << "rep type = " << report.type << endl;
1002 // cout << "rep button = " << report.xbutton.button << endl;
1004 switch ( report.type ) {
1010 case ConfigureNotify:
1021 XComposeStatus status_in_out;
1023 ret_len = XLookupString( ( XKeyEvent *)&report ,
1024 (char *) buf_ret , 10 ,
1025 &ks_ret , &status_in_out ) ;
1028 buf_ret[ret_len] = '\0' ;
1031 ProcessKeyPress( buf_ret);
1036 // cout << "ButtonPress" << endl;
1038 X_ButtonPress = report.xbutton.x;
1039 Y_ButtonPress = report.xbutton.y;
1041 if ( report.xbutton.button == Button1 )
1042 if( report.xbutton.state & ControlMask )
1043 pick = ProcessButton1Press( argc, argv, pick,
1044 ( report.xbutton.state & ShiftMask) );
1047 IsDragged = Standard_True;
1048 xx1 = X_ButtonPress;
1049 yy1 = Y_ButtonPress;
1050 DragFirst = Standard_True;
1052 else if ( report.xbutton.button == Button3 )
1054 ProcessButton3Press();
1059 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1060 // cout << IsDragged << endl;
1061 // cout << DragFirst << endl;
1067 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1068 GC gc = XCreateGC( display, aWindow, 0, 0 );
1069 // XSetFunction( display, gc, GXinvert );
1070 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1073 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1074 if( aContext.IsNull() )
1076 cout << "The context is null. Please use vinit before createmesh" << endl;
1080 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1081 if( report.xbutton.button==1 )
1085 aContext->ShiftSelect();
1086 // cout << "shift select" << endl;
1091 // cout << "select" << endl;
1096 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1097 max( xx1, xx2 ), max( yy1, yy2 ),
1098 ViewerTest::CurrentView());
1099 // cout << "shift select" << endl;
1103 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1104 max( xx1, xx2 ), max( yy1, yy2 ),
1105 ViewerTest::CurrentView() );
1106 // cout << "select" << endl;
1109 ProcessButtonRelease();
1111 IsDragged = Standard_False;
1114 ProcessButtonRelease();
1121 X_Motion = report.xmotion.x;
1122 Y_Motion = report.xmotion.y;
1126 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1127 GC gc = XCreateGC( display, aWindow, 0, 0 );
1128 XSetFunction( display, gc, GXinvert );
1131 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1135 DragFirst = Standard_False;
1137 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1138 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1143 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1145 // remove all the ButtonMotionMask
1146 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1148 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1149 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1151 Quantity_Length VDX, VDY;
1153 ViewerTest::CurrentView()->Size(VDX,VDY);
1154 Standard_Real VDZ =0 ;
1155 VDZ = ViewerTest::CurrentView()->ZSize();
1157 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1158 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1160 Quantity_Length dx = 0 ;
1161 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1165 dx = dx / VDX * VDZ;
1169 // Front = Depth + width/2.
1170 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1171 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1173 ViewerTest::CurrentView()->Redraw();
1177 if ( report.xmotion.state & ControlMask ) {
1178 if ( report.xmotion.state & Button1Mask ) {
1179 ProcessControlButton1Motion();
1181 else if ( report.xmotion.state & Button2Mask ) {
1182 ProcessControlButton2Motion();
1184 else if ( report.xmotion.state & Button3Mask ) {
1185 ProcessControlButton3Motion();
1200 //==============================================================================
1201 //function : VProcessEvents
1202 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1203 // event in the Viewer window
1204 //==============================================================================
1206 static void VProcessEvents(ClientData,int)
1208 //cout << "VProcessEvents" << endl;
1211 while (XPending(display)) {
1212 ViewerMainLoop( 0, NULL);
1217 //==============================================================================
1218 //function : OSWindowSetup
1219 //purpose : Setup for the X11 window to be able to cath the event
1220 //==============================================================================
1223 static void OSWindowSetup()
1228 Window window = VT_GetWindow()->XWindow();
1230 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1231 display = (Display * ) theDisplay;
1232 // display = (Display *)GetG3dDevice()->XDisplay();
1234 XSynchronize(display, 1);
1236 VT_GetWindow()->Map();
1238 // X11 : For keyboard on SUN
1240 wmhints.flags = InputHint;
1243 XSetWMHints( display, window, &wmhints);
1245 XSelectInput( display, window, ExposureMask | KeyPressMask |
1246 ButtonPressMask | ButtonReleaseMask |
1247 StructureNotifyMask |
1249 Button1MotionMask | Button2MotionMask |
1253 XSynchronize(display, 0);
1262 //==============================================================================
1265 //purpose : Fitall, no DRAW arguments
1266 //Draw arg : No args
1267 //==============================================================================
1269 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1271 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1272 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1273 if (V.IsNull() == Standard_False) {
1275 } else if (aView.IsNull() == Standard_False) {
1281 //==============================================================================
1283 //purpose : ZFitall, no DRAW arguments
1284 //Draw arg : No args
1285 //==============================================================================
1287 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1289 Handle(V3d_View) V = ViewerTest::CurrentView();
1290 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1293 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1295 Handle(V3d_View) V = ViewerTest::CurrentView();
1296 if ( !V.IsNull() ) V->Redraw(); return 0;
1300 //==============================================================================
1302 //purpose : Remove all the object from the viewer
1303 //Draw arg : No args
1304 //==============================================================================
1306 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1308 Handle(V3d_View) V = ViewerTest::CurrentView();
1310 ViewerTest::Clear();
1314 //==============================================================================
1317 //==============================================================================
1319 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1320 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1323 di << argv[0] << "Invalid number of arguments" << "\n";
1327 while (ViewerMainLoop( argc, argv)) {
1335 //==============================================================================
1336 //function : InitViewerTest
1337 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1338 //==============================================================================
1340 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1342 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1343 ViewerTest::SetAISContext(context);
1344 viewer->InitActiveViews();
1345 Handle(V3d_View) view = viewer->ActiveView();
1346 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1347 ViewerTest::ResetEventManager();
1348 Handle(Aspect_GraphicDevice) device = viewer->Device();
1349 Handle(Aspect_Window) window = view->Window();
1352 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1353 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1355 static int first = 1;
1357 #if TCL_MAJOR_VERSION < 8
1358 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1359 TK_READABLE, VProcessEvents, (ClientData) 0);
1361 Tk_CreateFileHandler(ConnectionNumber(display),
1362 TK_READABLE, VProcessEvents, (ClientData) 0);
1370 //==============================================================================
1372 //purpose : Load image as background
1373 //==============================================================================
1375 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1377 if (argc < 2 || argc > 3)
1379 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1380 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1384 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1385 if(AISContext.IsNull())
1387 di << "use 'vinit' command before " << argv[0] << "\n";
1391 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1394 const char* szType = argv[2];
1395 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1396 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1397 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1398 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1401 di << "Wrong fill type : " << szType << "\n";
1402 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1407 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1408 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1413 //==============================================================================
1414 //function : VSetBgMode
1415 //purpose : Change background image fill type
1416 //==============================================================================
1418 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1422 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1423 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1427 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1428 if(AISContext.IsNull())
1430 di << "use 'vinit' command before " << argv[0] << "\n";
1434 Aspect_FillMethod aFillType;
1437 const char* szType = argv[1];
1438 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1439 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1440 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1441 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1444 di << "Wrong fill type : " << szType << "\n";
1445 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1450 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1451 V3dView->SetBgImageStyle(aFillType, Standard_True);
1456 //==============================================================================
1457 //function : VSetGradientBg
1458 //purpose : Mount gradient background
1459 //==============================================================================
1460 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1464 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1465 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1466 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1467 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1471 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1472 if(AISContext.IsNull())
1474 di << "use 'vinit' command before " << argv[0] << "\n";
1480 Standard_Real R1 = atof(argv[1])/255.;
1481 Standard_Real G1 = atof(argv[2])/255.;
1482 Standard_Real B1 = atof(argv[3])/255.;
1483 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1485 Standard_Real R2 = atof(argv[4])/255.;
1486 Standard_Real G2 = atof(argv[5])/255.;
1487 Standard_Real B2 = atof(argv[6])/255.;
1489 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1490 int aType = atoi(argv[7]);
1491 if( aType < 0 || aType > 8 )
1493 di << "Wrong fill type " << "\n";
1494 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1495 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1499 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1501 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1502 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1508 //==============================================================================
1509 //function : VSetGradientBgMode
1510 //purpose : Change gradient background fill style
1511 //==============================================================================
1512 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1516 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1517 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1518 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1522 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1523 if(AISContext.IsNull())
1525 di << "use 'vinit' command before " << argv[0] << "\n";
1530 int aType = atoi(argv[1]);
1531 if( aType < 0 || aType > 8 )
1533 di << "Wrong fill type " << "\n";
1534 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1535 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1539 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1541 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1542 V3dView->SetBgGradientStyle( aMethod, 1 );
1548 //==============================================================================
1549 //function : VSetColorBg
1550 //purpose : Set color background
1551 //==============================================================================
1552 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1556 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1557 di << "R,G,B = [0..255]" << "\n";
1561 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1562 if(AISContext.IsNull())
1564 di << "use 'vinit' command before " << argv[0] << "\n";
1570 Standard_Real R = atof(argv[1])/255.;
1571 Standard_Real G = atof(argv[2])/255.;
1572 Standard_Real B = atof(argv[3])/255.;
1573 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1575 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1576 V3dView->SetBackgroundColor( aColor );
1583 //==============================================================================
1585 //purpose : View Scaling
1586 //==============================================================================
1588 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1590 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1591 if ( V3dView.IsNull() ) return 1;
1594 di << argv[0] << "Invalid number of arguments" << "\n";
1597 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1600 //==============================================================================
1601 //function : VTestZBuffTrihedron
1602 //purpose : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view
1603 //==============================================================================
1605 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1607 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1608 if ( V3dView.IsNull() ) return 1;
1610 // Set up default trihedron parameters
1611 V3dView->ZBufferTriedronSetup();
1612 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1617 //==============================================================================
1618 //function : VRotate
1619 //purpose : Camera Rotating
1620 //==============================================================================
1622 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1623 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1624 if ( V3dView.IsNull() ) {
1629 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1631 } else if ( argc == 7 ) {
1632 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1635 di << argv[0] << " Invalid number of arguments" << "\n";
1640 //==============================================================================
1642 //purpose : View zoom in / out (relative to current zoom)
1643 //==============================================================================
1645 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1646 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1647 if ( V3dView.IsNull() ) {
1652 Standard_Real coef = atof(argv[1]);
1653 if ( coef <= 0.0 ) {
1654 di << argv[1] << "Invalid value" << "\n";
1657 V3dView->SetZoom( atof(argv[1]) );
1660 di << argv[0] << " Invalid number of arguments" << "\n";
1665 //==============================================================================
1667 //purpose : View panning (in pixels)
1668 //==============================================================================
1670 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1671 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1672 if ( V3dView.IsNull() ) return 1;
1675 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1678 di << argv[0] << " Invalid number of arguments" << "\n";
1684 //==============================================================================
1685 //function : VExport
1686 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1687 //==============================================================================
1689 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1691 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1692 if (V3dView.IsNull())
1697 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1701 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1702 TCollection_AsciiString aFormatStr;
1704 TCollection_AsciiString aFileName (argv[1]);
1705 Standard_Integer aLen = aFileName.Length();
1709 aFormatStr = TCollection_AsciiString (argv[2]);
1713 if (aFileName.Value (aLen - 2) == '.')
1715 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1717 else if (aFileName.Value (aLen - 3) == '.')
1719 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1723 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1729 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1733 aFormatStr.UpperCase();
1734 if (aFormatStr == "PS")
1735 anExpFormat = Graphic3d_EF_PostScript;
1736 else if (aFormatStr == "EPS")
1737 anExpFormat = Graphic3d_EF_EnhPostScript;
1738 else if (aFormatStr == "TEX")
1739 anExpFormat = Graphic3d_EF_TEX;
1740 else if (aFormatStr == "PDF")
1741 anExpFormat = Graphic3d_EF_PDF;
1742 else if (aFormatStr == "SVG")
1743 anExpFormat = Graphic3d_EF_SVG;
1744 else if (aFormatStr == "PGF")
1745 anExpFormat = Graphic3d_EF_PGF;
1746 else if (aFormatStr == "EMF")
1747 anExpFormat = Graphic3d_EF_EMF;
1750 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1754 if (!V3dView->View()->Export (argv[1], anExpFormat))
1756 std::cout << "Export failed!\n";
1762 //==============================================================================
1763 //function : VColorScale
1764 //purpose : representation color scale
1765 //==============================================================================
1766 #include <V3d_ColorScale.hxx>
1768 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1770 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1772 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1776 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1777 if(aContext.IsNull()) {
1778 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1782 Standard_Real minRange = 0. , maxRange = 100. ;
1784 Standard_Integer numIntervals = 10 ;
1785 Standard_Real textHeight = 16. ;
1786 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1787 Standard_Real X = 0., Y = 0. ;
1793 minRange = atof( argv[1] );
1794 maxRange = atof( argv[2] );
1795 numIntervals = atoi( argv[3] );
1798 textHeight = atof( argv[4] );
1800 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1803 X = atof( argv[6] );
1804 Y = atof( argv[7] );
1807 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1808 if ( curView.IsNull( ) )
1810 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1811 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1812 if( ! aCS.IsNull( ) )
1814 aCS->SetPosition( X , Y );
1815 aCS->SetHeight( 0.95) ;
1816 aCS->SetTextHeight( textHeight );
1817 aCS->SetRange( minRange , maxRange );
1818 aCS->SetNumberOfIntervals( numIntervals );
1819 aCS->SetLabelPosition( position );
1820 if( !curView->ColorScaleIsDisplayed() )
1821 curView->ColorScaleDisplay( );
1826 //==============================================================================
1827 //function : VGraduatedTrihedron
1828 //purpose : Displays a graduated trihedron
1829 //==============================================================================
1831 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
1833 const char *str = arg;
1836 unsigned short c1 = *str++;
1837 unsigned short c2 = *str++;
1838 if (!c1 || !c2) break;
1839 name += (Standard_ExtCharacter)((c1 << 8) | c2);
1843 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1846 if (argc != 2 && argc < 5)
1848 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
1849 di<<"Usage: type help "<<argv[0]<<"\n";
1850 return 1; //TCL_ERROR
1853 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
1855 // Create 3D view if it doesn't exist
1856 if ( aV3dView.IsNull() )
1858 ViewerTest::ViewerInit();
1859 aV3dView = ViewerTest::CurrentView();
1860 if( aV3dView.IsNull() )
1862 di << "Error: Cannot create a 3D view\n";
1863 return 1; //TCL_ERROR
1867 // Erase (==0) or display (!=0)
1868 const int display = atoi(argv[1]);
1873 TCollection_AsciiString font;
1875 font.AssignCat("Courier");
1877 font.AssignCat(argv[5]);
1879 // Text is multibyte
1880 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
1883 TCollection_ExtendedString xname, yname, zname;
1888 AddMultibyteString(xname, argv[2]);
1889 AddMultibyteString(yname, argv[3]);
1890 AddMultibyteString(zname, argv[4]);
1906 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
1907 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
1908 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
1909 Standard_True/*drawgrid*/,
1910 Standard_True/*drawaxes*/,
1911 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
1912 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
1913 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
1914 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
1915 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
1916 Quantity_NOC_WHITE/*gridcolor*/,
1917 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
1918 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
1921 aV3dView->GraduatedTrihedronErase();
1923 ViewerTest::GetAISContext()->UpdateCurrentViewer();
1929 //==============================================================================
1930 //function : VPrintView
1931 //purpose : Test printing algorithm, print the view to image file with given
1932 // width and height. Printing implemented only for WNT.
1933 //==============================================================================
1934 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
1938 di << "Printing implemented only for wnt!\n";
1942 Handle(AIS_InteractiveContext) aContextAIS = NULL;
1943 Handle(V3d_View) aView = NULL;
1944 aContextAIS = ViewerTest::GetAISContext();
1945 if (!aContextAIS.IsNull())
1947 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
1948 Vwr->InitActiveViews();
1949 if(Vwr->MoreActiveViews())
1950 aView = Vwr->ActiveView();
1956 di << "Call vinit before!\n";
1961 di << "Use: " << argv[0];
1962 di << " width height filename [print algo=0]\n";
1963 di << "width, height of the intermediate buffer for operation\n";
1964 di << "algo : {0|1}\n";
1965 di << " 0 - stretch algorithm\n";
1966 di << " 1 - tile algorithm\n";
1967 di << "test printing algorithms into an intermediate buffer\n";
1968 di << "with saving output to an image file\n";
1972 // get the input params
1973 Standard_Integer aWidth = atoi (argv[1]);
1974 Standard_Integer aHeight = atoi (argv[2]);
1975 Standard_Integer aMode = 0;
1976 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
1978 aMode = atoi (argv[4]);
1980 // check the input parameters
1981 if (aWidth <= 0 || aHeight <= 0)
1983 di << "Width and height must be positive values!\n";
1986 if (aMode != 0 && aMode != 1)
1989 Image_CRawBufferData aRawBuffer;
1990 HDC anDC = CreateCompatibleDC(0);
1992 // define compatible bitmap
1993 BITMAPINFO aBitmapData;
1994 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
1995 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
1996 aBitmapData.bmiHeader.biWidth = aWidth ;
1997 aBitmapData.bmiHeader.biHeight = aHeight;
1998 aBitmapData.bmiHeader.biPlanes = 1;
1999 aBitmapData.bmiHeader.biBitCount = 24;
2000 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2001 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2002 aBitmapData.bmiHeader.biClrUsed = 0;
2003 aBitmapData.bmiHeader.biClrImportant = 0;
2004 aBitmapData.bmiHeader.biCompression = BI_RGB;
2005 aBitmapData.bmiHeader.biSizeImage = 0;
2007 // Create Device Independent Bitmap
2008 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2009 &aRawBuffer.dataPtr, NULL, 0);
2010 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2012 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2013 if (aRawBuffer.dataPtr != 0)
2016 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2018 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2020 // succesfully printed into an intermediate buffer
2023 Handle(Image_PixMap) anImageBitmap =
2024 new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr,
2026 aWidth*3 + aWidth%4, 24, 0);
2027 isSaved = anImageBitmap->Dump(aFileName.ToCString());
2031 di << "Print operation failed due to printing errors or\n";
2032 di << "insufficient memory available\n";
2033 di << "Please, try to use smaller dimensions for this test\n";
2034 di << "command, as it allocates intermediate buffer for storing\n";
2035 di << "the result\n";
2040 di << "Can't allocate memory for intermediate buffer\n";
2041 di << "Please use smaller dimensions\n";
2046 SelectObject (anDC, anOldBitmap);
2047 DeleteObject (aMemoryBitmap);
2053 di << "Save to file operation failed. This operation may fail\n";
2054 di << "if you don't have enough available memory, then you can\n";
2055 di << "use smaller dimensions for the output file\n";
2064 //==============================================================================
2065 //function : VZLayer
2066 //purpose : Test z layer operations for v3d viewer
2067 //==============================================================================
2068 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2070 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2071 if (aContextAIS.IsNull())
2073 di << "Call vinit before!\n";
2078 di << "Use: vzlayer " << argv[0];
2079 di << " add/del/get [id]\n";
2080 di << " add - add new z layer to viewer and print its id\n";
2081 di << " del - del z layer by its id\n";
2082 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2083 di << "id - the layer identificator value defined when removing z layer\n";
2087 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2088 if (aViewer.IsNull())
2090 di << "No active viewer!\n";
2094 // perform operation
2095 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2098 Standard_Integer aNewId;
2099 if (!aViewer->AddZLayer (aNewId))
2101 di << "Impossible to add new z layer!\n";
2105 di << "New z layer added with index: " << aNewId << "\n";
2107 else if (anOp == "del")
2111 di << "Please also provide as argument id of z layer to remove\n";
2115 Standard_Integer aDelId = atoi (argv[2]);
2116 if (!aViewer->RemoveZLayer (aDelId))
2118 di << "Impossible to remove the z layer or invalid id!\n";
2122 di << "Z layer " << aDelId << " has been removed\n";
2124 else if (anOp == "get")
2126 TColStd_SequenceOfInteger anIds;
2127 aViewer->GetAllZLayers (anIds);
2128 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2130 di << anIds.Value (aSeqIdx) << " ";
2137 di << "Invalid operation, please use { add / del / get }\n";
2144 //=======================================================================
2145 //function : ViewerCommands
2147 //=======================================================================
2149 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
2152 const char *group = "ZeViewer";
2153 theCommands.Add("vinit" ,
2154 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
2155 __FILE__,VInit,group);
2156 theCommands.Add("vhelp" ,
2157 "vhelp : display help on the viewer commands",
2158 __FILE__,VHelp,group);
2159 theCommands.Add("vtop" ,
2160 "vtop or <T> : Top view" ,
2161 __FILE__,VTop,group);
2162 theCommands.Add("vaxo" ,
2163 " vaxo or <A> : Axonometric view ",
2164 __FILE__,VAxo,group);
2165 theCommands.Add("vpick" ,
2166 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
2168 theCommands.Add("vfit" ,
2169 "vfit or <F> : vfit",
2170 __FILE__,VFit,group);
2171 theCommands.Add("vzfit" ,
2173 __FILE__,VZFit,group);
2174 theCommands.Add("vrepaint",
2175 "vrepaint : vrepaint, force redraw",
2176 __FILE__,VRepaint,group);
2177 theCommands.Add("vclear",
2179 __FILE__,VClear,group);
2180 theCommands.Add("vsetbg",
2181 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
2182 __FILE__,VSetBg,group);
2183 theCommands.Add("vsetbgmode",
2184 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
2185 __FILE__,VSetBgMode,group);
2186 theCommands.Add("vsetgradientbg",
2187 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
2188 __FILE__,VSetGradientBg,group);
2189 theCommands.Add("vsetgrbgmode",
2190 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
2191 __FILE__,VSetGradientBgMode,group);
2192 theCommands.Add("vsetcolorbg",
2193 "vsetcolorbg : vsetcolorbg r g b : Set background color",
2194 __FILE__,VSetColorBg,group);
2195 theCommands.Add("vscale",
2196 "vscale : vscale X Y Z",
2197 __FILE__,VScale,group);
2198 theCommands.Add("vzbufftrihedron",
2199 "vzbufftrihedron : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view",
2200 __FILE__,VTestZBuffTrihedron,group);
2201 theCommands.Add("vrotate",
2202 "vrotate : vrotate AX AY AZ [X Y Z]",
2203 __FILE__,VRotate,group);
2204 theCommands.Add("vzoom",
2205 "vzoom : vzoom coef",
2206 __FILE__,VZoom,group);
2207 theCommands.Add("vpan",
2208 "vpan : vpan dx dy",
2209 __FILE__,VPan,group);
2210 theCommands.Add("vexport",
2211 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
2212 " : exports the view to a vector file of a given format"
2213 " : notice that EMF format requires patched gl2ps",
2214 __FILE__,VExport,group);
2215 theCommands.Add("vcolorscale",
2216 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
2217 __FILE__,VColorScale,group);
2218 theCommands.Add("vgraduatedtrihedron",
2219 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
2220 __FILE__,VGraduatedTrihedron,group);
2221 theCommands.Add("vprintview" ,
2222 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
2223 __FILE__,VPrintView,group);
2224 theCommands.Add("vzlayer",
2225 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
2226 __FILE__,VZLayer,group);