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>
31 #include <Graphic3d_GraphicDevice.hxx>
32 #include <Xw_GraphicDevice.hxx>
33 #include <Xw_WindowQuality.hxx>
34 #include <Xw_Window.hxx>
35 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
36 #include <X11/Xutil.h>
41 #include <Graphic3d_WNTGraphicDevice.hxx>
42 #include <WNT_WClass.hxx>
43 #include <WNT_Window.hxx>
45 #define _CRT_SECURE_NO_DEPRECATE
46 #pragma warning (disable:4996)
52 //==============================================================================
54 //==============================================================================
55 // VIEWER GLOBAL VARIABLES
56 //==============================================================================
58 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
60 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
61 extern const Handle(NIS_InteractiveContext)& TheNISContext();
64 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
65 static Handle(Graphic3d_WNTGraphicDevice) GD;
69 static Handle(WNT_Window)& VT_GetWindow() {
70 static Handle(WNT_Window) WNTWin;
75 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
76 static Handle(Graphic3d_GraphicDevice) GD;
79 static Handle(Xw_Window)& VT_GetWindow(){
80 static Handle(Xw_Window) XWWin;
83 static Display *display;
85 static void VProcessEvents(ClientData,int);
89 static Standard_Boolean DegenerateMode = Standard_True;
94 static void OSWindowSetup();
96 //==============================================================================
97 // EVENT GLOBAL VARIABLES
98 //==============================================================================
100 static int Start_Rot = 0;
101 static int ZClipIsOn = 0;
102 static int X_Motion= 0,Y_Motion=0; // Current cursor position
103 static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
106 //==============================================================================
109 static LRESULT WINAPI ViewerWindowProc(
114 static LRESULT WINAPI AdvViewerWindowProc(
122 //==============================================================================
125 //==============================================================================
127 const Handle(MMgt_TShared)& ViewerTest::WClass()
129 static Handle(MMgt_TShared) theWClass;
131 if (theWClass.IsNull()) {
132 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
133 CS_VREDRAW | CS_HREDRAW, 0, 0,
134 ::LoadCursor (NULL, IDC_ARROW));
140 //==============================================================================
141 //function : ViewerInit
142 //purpose : Create the window viewer and initialize all the global variable
143 //==============================================================================
145 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
146 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
148 static Standard_Boolean isFirst = Standard_True;
150 Standard_Integer aPxLeft = 0;
151 Standard_Integer aPxTop = 460;
152 Standard_Integer aPxWidth = 409;
153 Standard_Integer aPxHeight = 409;
154 if (thePxWidth != 0 && thePxHeight != 0)
158 aPxWidth = thePxWidth;
159 aPxHeight = thePxHeight;
164 // Create the Graphic device
166 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
167 if (VT_GetWindow().IsNull())
169 // Create the Graphic device and the window
170 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
172 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
173 Handle(WNT_WClass)::DownCast (WClass()),
178 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
181 if (GetG3dDevice().IsNull()) GetG3dDevice() =
182 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
183 if (VT_GetWindow().IsNull())
185 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
191 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
195 Handle(V3d_Viewer) a3DViewer, a3DCollector;
196 // Viewer and View creation
198 TCollection_ExtendedString NameOfWindow("Visu3D");
200 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
201 NameOfWindow = TCollection_ExtendedString("Collector");
202 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
203 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
204 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
205 Handle(NIS_View) aView =
206 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
207 if ( aView.IsNull() ) {
208 // Handle (V3d_View) V = a3DViewer->CreateView();
209 aView = new NIS_View (a3DViewer, VT_GetWindow());
210 ViewerTest::CurrentView(aView);
211 TheNISContext()->AttachView (aView);
213 Handle(V3d_View) a3DViewCol;
214 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
217 if ( ViewerTest::GetAISContext().IsNull() ) {
218 Handle(AIS_InteractiveContext) C =
219 new AIS_InteractiveContext(a3DViewer,a3DCollector);
220 ViewerTest::SetAISContext(C);
223 // Setup for X11 or NT
225 // Viewer and View creation
227 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
229 Handle (V3d_View) V = ViewerTest::CurrentView();
231 V->SetDegenerateModeOn();
233 DegenerateMode = V->DegenerateModeIsOn();
235 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
237 V->SetZClippingDepth(0.5);
238 V->SetZClippingWidth(ZCLIPWIDTH/2.);
239 a3DViewer->SetDefaultLights();
240 a3DViewer->SetLightOn();
243 #if TCL_MAJOR_VERSION < 8
244 Tk_CreateFileHandler((void*)ConnectionNumber(display),
245 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
247 Tk_CreateFileHandler(ConnectionNumber(display),
248 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
252 isFirst = Standard_False;
254 VT_GetWindow()->Map();
257 //==============================================================================
259 //purpose : Create the window viewer and initialize all the global variable
260 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
261 //==============================================================================
263 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
265 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
266 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
267 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
268 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
269 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
273 //==============================================================================
274 //function : ProcessKeyPress
275 //purpose : Handle KeyPress event from a CString
276 //==============================================================================
278 static void ProcessKeyPress( char *buf_ret )
280 //cout << "KeyPress" << endl;
281 const Handle(V3d_View) aView = ViewerTest::CurrentView();
282 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
283 // Letter in alphabetic order
285 if ( !strcasecmp(buf_ret, "A") ) {
287 aView->SetProj(V3d_XposYnegZpos);
289 else if ( !strcasecmp(buf_ret, "D") ) {
293 else if ( !strcasecmp(buf_ret, "F") ) {
295 if (aNisView.IsNull())
298 aNisView->FitAll3d();
300 else if ( !strcasecmp(buf_ret, "H") ) {
302 cout << "HLR" << endl;
304 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
305 else aView->SetDegenerateModeOn();
306 DegenerateMode = aView->DegenerateModeIsOn();
308 ViewerTest::CurrentView()->SetDegenerateModeOff();
311 else if ( !strcasecmp(buf_ret, "D") ) {
315 else if ( !strcasecmp(buf_ret, "S") ) {
317 cout << "passage en mode 1 (shading pour les shapes)" << endl;
319 ViewerTest::CurrentView()->SetDegenerateModeOn();
321 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
322 if(Ctx->NbCurrents()==0 ||
323 Ctx->NbSelected()==0)
324 Ctx->SetDisplayMode(AIS_Shaded);
326 if(Ctx->HasOpenedContext()){
327 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
328 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
331 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
332 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
334 Ctx->UpdateCurrentViewer();
337 else if ( !strcasecmp(buf_ret, "U") ) {
339 cout<<"passage au mode par defaut"<<endl;
341 ViewerTest::CurrentView()->SetDegenerateModeOn();
343 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
344 if(Ctx->NbCurrents()==0 ||
345 Ctx->NbSelected()==0)
346 Ctx->SetDisplayMode(AIS_WireFrame);
348 if(Ctx->HasOpenedContext()){
349 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
350 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
353 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
354 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
356 Ctx->UpdateCurrentViewer();
360 else if ( !strcasecmp(buf_ret, "T") ) {
362 aView->SetProj(V3d_Zpos);
364 else if ( !strcasecmp(buf_ret, "B") ) {
366 aView->SetProj(V3d_Zneg);
368 else if ( !strcasecmp(buf_ret, "L") ) {
370 aView->SetProj(V3d_Xneg);
372 else if ( !strcasecmp(buf_ret, "R") ) {
374 aView->SetProj(V3d_Xpos);
377 else if ( !strcasecmp(buf_ret, "W") ) {
380 ViewerTest::CurrentView()->SetDegenerateModeOn();
382 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
384 ViewerTest::CurrentView()->SetDegenerateModeOn();
386 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
387 if(Ctx->NbCurrents()==0 ||
388 Ctx->NbSelected()==0)
389 Ctx->SetDisplayMode(AIS_WireFrame);
391 if(Ctx->HasOpenedContext()){
392 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
393 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
396 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
397 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
399 Ctx->UpdateCurrentViewer();
402 else if ( !strcasecmp(buf_ret, "Z") ) {
406 cout << "ZClipping OFF" << endl;
409 aView->SetZClippingType(V3d_OFF);
413 cout << "ZClipping ON" << endl;
416 aView->SetZClippingType(V3d_FRONT);
420 else if ( !strcasecmp(buf_ret, ",") ) {
421 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
425 else if ( !strcasecmp(buf_ret, ".") ) {
426 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
430 Standard_Integer Num = atoi(buf_ret);
432 ViewerTest::StandardModeActivation(Num);
436 //==============================================================================
437 //function : ProcessExpose
438 //purpose : Redraw the View on an Expose Event
439 //==============================================================================
441 static void ProcessExpose( )
442 { //cout << "Expose" << endl;
443 ViewerTest::CurrentView()->Redraw();
446 //==============================================================================
447 //function : ProcessConfigure
448 //purpose : Resize the View on an Configure Event
449 //==============================================================================
451 static void ProcessConfigure()
453 Handle(V3d_View) V = ViewerTest::CurrentView();
459 //==============================================================================
460 //function : ProcessButton1Press
462 //==============================================================================
464 static Standard_Boolean ProcessButton1Press(
467 Standard_Boolean pick,
468 Standard_Boolean shift )
470 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
472 Standard_Real X, Y, Z;
474 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
476 Draw::Set(argv[1], X);
477 Draw::Set(argv[2], Y);
478 Draw::Set(argv[3], Z);}
489 //==============================================================================
490 //function : ProcessButton3Press
491 //purpose : Start Rotation
492 //==============================================================================
494 static void ProcessButton3Press()
498 ViewerTest::CurrentView()->SetDegenerateModeOn();
499 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
502 //==============================================================================
503 //function : ProcessButtonRelease
504 //purpose : Start Rotation
505 //==============================================================================
507 static void ProcessButtonRelease()
513 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
517 ViewerTest::CurrentView()->SetDegenerateModeOff();
521 //==============================================================================
522 //function : ProcessZClipMotion
524 //==============================================================================
526 void ProcessZClipMotion()
528 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
529 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
530 static Standard_Real CurZPos = 0.;
532 //Quantity_Length VDX, VDY;
533 //a3DView->Size(VDX,VDY);
534 //Standard_Real VDZ = a3DView->ZSize();
535 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
537 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
539 // Front = Depth + width/2.
540 Standard_Real D = 0.5;
541 Standard_Real W = 0.1;
547 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
549 a3DView->SetZClippingType(V3d_OFF);
550 a3DView->SetZClippingDepth(D);
551 a3DView->SetZClippingWidth(W);
552 a3DView->SetZClippingType(V3d_FRONT);
556 X_ButtonPress = X_Motion;
557 Y_ButtonPress = Y_Motion;
561 //==============================================================================
562 //function : ProcessControlButton1Motion
564 //==============================================================================
566 static void ProcessControlButton1Motion()
568 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
570 X_ButtonPress = X_Motion;
571 Y_ButtonPress = Y_Motion;
574 //==============================================================================
575 //function : ProcessControlButton2Motion
577 //==============================================================================
579 static void ProcessControlButton2Motion()
581 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
582 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
584 dy = -dy; // Xwindow Y axis is from top to Bottom
586 ViewerTest::CurrentView()->Panning( dx, dy );
588 X_ButtonPress = X_Motion;
589 Y_ButtonPress = Y_Motion;
592 //==============================================================================
593 //function : ProcessControlButton3Motion
595 //==============================================================================
597 static void ProcessControlButton3Motion()
599 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
602 //==============================================================================
603 //function : ProcessPointerMotion
605 //==============================================================================
607 static void ProcessMotion()
609 //pre-hilights detected objects at mouse position
611 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
612 EM->MoveTo(X_Motion, Y_Motion);
616 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
618 Xpix = X_Motion;Ypix=Y_Motion;
621 //==============================================================================
623 //purpose : Switch to an Axonometric view
625 //==============================================================================
627 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
628 { if ( ViewerTest::CurrentView().IsNull() ) {
629 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
630 // VInit(di, argc, argv);
633 ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
638 //==============================================================================
640 //purpose : Switch to a Top View
642 //==============================================================================
644 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
647 if ( ViewerTest::CurrentView().IsNull() ) {
648 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
650 // VInit(di, , argv);
653 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
658 //==============================================================================
660 //purpose : Dsiplay help on viewer Keyboead and mouse commands
662 //==============================================================================
664 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
667 di << "Q : Quit the application" << "\n";
669 di << "========================="<<"\n";
670 di << "F : FitAll" << "\n";
671 di << "T : TopView" << "\n";
672 di << "A : AxonometricView" << "\n";
673 di << "R : ResetView" << "\n";
675 di << "========================="<<"\n";
676 di << "S : Shading" << "\n";
677 di << "W : Wireframe" << "\n";
678 di << "H : HidelLineRemoval" << "\n";
680 di << "========================="<<"\n";
681 di << "Selection mode "<<"\n";
682 di << "0 : Shape" <<"\n";
683 di << "1 : Vertex" <<"\n";
684 di << "2 : Edge" <<"\n";
685 di << "3 : Wire" <<"\n";
686 di << "4 : Face" <<"\n";
687 di << "5 : Shell" <<"\n";
688 di << "6 : Solid" <<"\n";
689 di << "7 : Compound" <<"\n";
691 di << "=========================="<<"\n";
692 di << "D : Remove Selected Object"<<"\n";
693 di << "=========================="<<"\n";
698 Standard_Boolean IsDragged = Standard_False;
700 Standard_Integer xx1, yy1, xx2, yy2;
701 //the first and last point in viewer co-ordinates
703 Standard_Boolean DragFirst;
708 static Standard_Boolean Ppick = 0;
709 static Standard_Integer Pargc = 0;
710 static const char** Pargv = NULL;
713 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
718 if ( !ViewerTest::CurrentView().IsNull() ) {
720 WPARAM fwKeys = wParam;
725 IsDragged = Standard_False;
728 HDC hdc = GetDC( hwnd );
729 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
730 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
731 SetROP2( hdc, R2_NOT );
732 Rectangle( hdc, xx1, yy1, xx2, yy2 );
733 ReleaseDC( hwnd, hdc );
735 const Handle(ViewerTest_EventManager) EM =
736 ViewerTest::CurrentEventManager();
737 if ( fwKeys & MK_SHIFT )
738 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
739 max( xx1, xx2 ), min( yy1, yy2 ));
741 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
742 max( xx1, xx2 ), min( yy1, yy2 ));
744 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
747 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
749 IsDragged = Standard_True;
750 DragFirst = Standard_True;
751 xx1 = LOWORD(lParam);
752 yy1 = HIWORD(lParam);
754 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
761 HDC hdc = GetDC( hwnd );
763 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
764 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
765 SetROP2( hdc, R2_NOT );
768 Rectangle( hdc, xx1, yy1, xx2, yy2 );
770 DragFirst = Standard_False;
771 xx2 = LOWORD(lParam);
772 yy2 = HIWORD(lParam);
774 Rectangle( hdc, xx1, yy1, xx2, yy2 );
776 SelectObject( hdc, anObj );
778 ReleaseDC( hwnd, hdc );
781 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
785 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
789 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
793 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
798 /*static Standard_Boolean Ppick = 0;
799 static Standard_Integer Pargc = 0;
800 static char** Pargv = NULL;*/
804 if ( !ViewerTest::CurrentView().IsNull() ) {
809 // do not destroy the window - just hide it!
810 VT_GetWindow()->Unmap();
813 //cout << "\t WM_PAINT" << endl;
814 BeginPaint(hwnd, &ps);
820 //cout << "\t WM_SIZE" << endl;
825 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
827 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
829 c[0] = (char) wParam;
838 //cout << "\t WM_xBUTTONUP" << endl;
840 ProcessButtonRelease();
847 //cout << "\t WM_xBUTTONDOWN" << endl;
848 WPARAM fwKeys = wParam;
852 X_ButtonPress = LOWORD(lParam);
853 Y_ButtonPress = HIWORD(lParam);
855 if ( Msg == WM_LBUTTONDOWN) {
856 if(fwKeys & MK_CONTROL) {
857 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
859 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
861 else if ( Msg == WM_RBUTTONDOWN ) {
863 ProcessButton3Press( );
870 //cout << "\t WM_MOUSEMOVE" << endl;
871 WPARAM fwKeys = wParam;
872 X_Motion = LOWORD(lParam);
873 Y_Motion = HIWORD(lParam);
876 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
878 X_ButtonPress = LOWORD(lParam);
879 Y_ButtonPress = HIWORD(lParam);
881 if ( fwKeys & MK_RBUTTON ) {
883 ProcessButton3Press();
887 if ( fwKeys & MK_CONTROL ) {
888 if ( fwKeys & MK_LBUTTON ) {
889 ProcessControlButton1Motion();
891 else if ( fwKeys & MK_MBUTTON ||
892 ((fwKeys&MK_LBUTTON) &&
893 (fwKeys&MK_RBUTTON) ) ){
894 ProcessControlButton2Motion();
896 else if ( fwKeys & MK_RBUTTON ) {
897 ProcessControlButton3Motion();
901 else if ( fwKeys & MK_SHIFT ) {
902 if ( fwKeys & MK_MBUTTON ||
903 ((fwKeys&MK_LBUTTON) &&
904 (fwKeys&MK_RBUTTON) ) ) {
905 cout << "ProcessZClipMotion()" << endl;
906 ProcessZClipMotion();
911 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
912 ProcessZClipMotion();
921 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
926 return DefWindowProc( hwnd, Msg, wParam, lParam );
932 //==============================================================================
933 //function : ViewerMainLoop
934 //purpose : Get a Event on the view and dispatch it
935 //==============================================================================
938 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
941 //cout << "No yet implemented on WNT" << endl;
942 /*static Standard_Boolean Ppick = 0;
943 static Standard_Integer Pargc = 0;
944 static char** Pargv = NULL;*/
946 //Ppick = (argc > 0)? -1 : 0;
947 Ppick = (argc > 0)? 1 : 0;
955 cout << "Start picking" << endl;
957 //while ( Ppick == -1 ) {
958 while ( Ppick == 1 ) {
959 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
960 if (GetMessage(&msg, NULL, 0, 0) ) {
961 TranslateMessage(&msg);
962 DispatchMessage(&msg);
966 cout << "Picking done" << endl;
975 int min( int a, int b )
983 int max( int a, int b )
991 int ViewerMainLoop(Standard_Integer argc, const char** argv)
993 { Standard_Boolean pick = argc > 0;
997 static XEvent report;
999 XNextEvent( display, &report );
1000 // cout << "rep type = " << report.type << endl;
1001 // cout << "rep button = " << report.xbutton.button << endl;
1003 switch ( report.type ) {
1009 case ConfigureNotify:
1020 XComposeStatus status_in_out;
1022 ret_len = XLookupString( ( XKeyEvent *)&report ,
1023 (char *) buf_ret , 10 ,
1024 &ks_ret , &status_in_out ) ;
1027 buf_ret[ret_len] = '\0' ;
1030 ProcessKeyPress( buf_ret);
1035 // cout << "ButtonPress" << endl;
1037 X_ButtonPress = report.xbutton.x;
1038 Y_ButtonPress = report.xbutton.y;
1040 if ( report.xbutton.button == Button1 )
1041 if( report.xbutton.state & ControlMask )
1042 pick = ProcessButton1Press( argc, argv, pick,
1043 ( report.xbutton.state & ShiftMask) );
1046 IsDragged = Standard_True;
1047 xx1 = X_ButtonPress;
1048 yy1 = Y_ButtonPress;
1049 DragFirst = Standard_True;
1051 else if ( report.xbutton.button == Button3 )
1053 ProcessButton3Press();
1058 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1059 // cout << IsDragged << endl;
1060 // cout << DragFirst << endl;
1066 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1067 GC gc = XCreateGC( display, aWindow, 0, 0 );
1068 // XSetFunction( display, gc, GXinvert );
1069 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1072 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1073 if( aContext.IsNull() )
1075 cout << "The context is null. Please use vinit before createmesh" << endl;
1079 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1080 if( report.xbutton.button==1 )
1084 aContext->ShiftSelect();
1085 // cout << "shift select" << endl;
1090 // cout << "select" << endl;
1095 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1096 max( xx1, xx2 ), max( yy1, yy2 ),
1097 ViewerTest::CurrentView());
1098 // cout << "shift select" << endl;
1102 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1103 max( xx1, xx2 ), max( yy1, yy2 ),
1104 ViewerTest::CurrentView() );
1105 // cout << "select" << endl;
1108 ProcessButtonRelease();
1110 IsDragged = Standard_False;
1113 ProcessButtonRelease();
1120 X_Motion = report.xmotion.x;
1121 Y_Motion = report.xmotion.y;
1125 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1126 GC gc = XCreateGC( display, aWindow, 0, 0 );
1127 XSetFunction( display, gc, GXinvert );
1130 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1134 DragFirst = Standard_False;
1136 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1137 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1142 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1144 // remove all the ButtonMotionMask
1145 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1147 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1148 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1150 Quantity_Length VDX, VDY;
1152 ViewerTest::CurrentView()->Size(VDX,VDY);
1153 Standard_Real VDZ =0 ;
1154 VDZ = ViewerTest::CurrentView()->ZSize();
1156 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1157 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1159 Quantity_Length dx = 0 ;
1160 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1164 dx = dx / VDX * VDZ;
1168 // Front = Depth + width/2.
1169 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1170 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1172 ViewerTest::CurrentView()->Redraw();
1176 if ( report.xmotion.state & ControlMask ) {
1177 if ( report.xmotion.state & Button1Mask ) {
1178 ProcessControlButton1Motion();
1180 else if ( report.xmotion.state & Button2Mask ) {
1181 ProcessControlButton2Motion();
1183 else if ( report.xmotion.state & Button3Mask ) {
1184 ProcessControlButton3Motion();
1199 //==============================================================================
1200 //function : VProcessEvents
1201 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1202 // event in the Viewer window
1203 //==============================================================================
1205 static void VProcessEvents(ClientData,int)
1207 //cout << "VProcessEvents" << endl;
1210 while (XPending(display)) {
1211 ViewerMainLoop( 0, NULL);
1216 //==============================================================================
1217 //function : OSWindowSetup
1218 //purpose : Setup for the X11 window to be able to cath the event
1219 //==============================================================================
1222 static void OSWindowSetup()
1227 Window window = VT_GetWindow()->XWindow();
1229 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1230 display = (Display * ) theDisplay;
1231 // display = (Display *)GetG3dDevice()->XDisplay();
1233 XSynchronize(display, 1);
1235 VT_GetWindow()->Map();
1237 // X11 : For keyboard on SUN
1239 wmhints.flags = InputHint;
1242 XSetWMHints( display, window, &wmhints);
1244 XSelectInput( display, window, ExposureMask | KeyPressMask |
1245 ButtonPressMask | ButtonReleaseMask |
1246 StructureNotifyMask |
1248 Button1MotionMask | Button2MotionMask |
1252 XSynchronize(display, 0);
1261 //==============================================================================
1264 //purpose : Fitall, no DRAW arguments
1265 //Draw arg : No args
1266 //==============================================================================
1268 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1270 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1271 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1272 if (V.IsNull() == Standard_False) {
1274 } else if (aView.IsNull() == Standard_False) {
1280 //==============================================================================
1282 //purpose : ZFitall, no DRAW arguments
1283 //Draw arg : No args
1284 //==============================================================================
1286 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1288 Handle(V3d_View) V = ViewerTest::CurrentView();
1289 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1292 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1294 Handle(V3d_View) V = ViewerTest::CurrentView();
1295 if ( !V.IsNull() ) V->Redraw(); return 0;
1299 //==============================================================================
1301 //purpose : Remove all the object from the viewer
1302 //Draw arg : No args
1303 //==============================================================================
1305 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1307 Handle(V3d_View) V = ViewerTest::CurrentView();
1309 ViewerTest::Clear();
1313 //==============================================================================
1316 //==============================================================================
1318 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1319 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1322 di << argv[0] << "Invalid number of arguments" << "\n";
1326 while (ViewerMainLoop( argc, argv)) {
1334 //==============================================================================
1335 //function : InitViewerTest
1336 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1337 //==============================================================================
1339 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1341 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1342 ViewerTest::SetAISContext(context);
1343 viewer->InitActiveViews();
1344 Handle(V3d_View) view = viewer->ActiveView();
1345 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1346 ViewerTest::ResetEventManager();
1347 Handle(Aspect_GraphicDevice) device = viewer->Device();
1348 Handle(Aspect_Window) window = view->Window();
1351 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1352 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1354 static int first = 1;
1356 #if TCL_MAJOR_VERSION < 8
1357 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1358 TK_READABLE, VProcessEvents, (ClientData) 0);
1360 Tk_CreateFileHandler(ConnectionNumber(display),
1361 TK_READABLE, VProcessEvents, (ClientData) 0);
1369 //==============================================================================
1371 //purpose : Load image as background
1372 //==============================================================================
1374 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1376 if (argc < 2 || argc > 3)
1378 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1379 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1383 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1384 if(AISContext.IsNull())
1386 di << "use 'vinit' command before " << argv[0] << "\n";
1390 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1393 const char* szType = argv[2];
1394 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1395 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1396 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1397 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1400 di << "Wrong fill type : " << szType << "\n";
1401 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1406 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1407 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1412 //==============================================================================
1413 //function : VSetBgMode
1414 //purpose : Change background image fill type
1415 //==============================================================================
1417 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1421 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1422 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1426 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1427 if(AISContext.IsNull())
1429 di << "use 'vinit' command before " << argv[0] << "\n";
1433 Aspect_FillMethod aFillType;
1436 const char* szType = argv[1];
1437 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1438 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1439 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1440 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1443 di << "Wrong fill type : " << szType << "\n";
1444 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1449 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1450 V3dView->SetBgImageStyle(aFillType, Standard_True);
1455 //==============================================================================
1456 //function : VSetGradientBg
1457 //purpose : Mount gradient background
1458 //==============================================================================
1459 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1463 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1464 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1465 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1466 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1470 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1471 if(AISContext.IsNull())
1473 di << "use 'vinit' command before " << argv[0] << "\n";
1479 Standard_Real R1 = atof(argv[1])/255.;
1480 Standard_Real G1 = atof(argv[2])/255.;
1481 Standard_Real B1 = atof(argv[3])/255.;
1482 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1484 Standard_Real R2 = atof(argv[4])/255.;
1485 Standard_Real G2 = atof(argv[5])/255.;
1486 Standard_Real B2 = atof(argv[6])/255.;
1488 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1489 int aType = atoi(argv[7]);
1490 if( aType < 0 || aType > 8 )
1492 di << "Wrong fill type " << "\n";
1493 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1494 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1498 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1500 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1501 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1507 //==============================================================================
1508 //function : VSetGradientBgMode
1509 //purpose : Change gradient background fill style
1510 //==============================================================================
1511 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1515 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1516 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1517 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1521 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1522 if(AISContext.IsNull())
1524 di << "use 'vinit' command before " << argv[0] << "\n";
1529 int aType = atoi(argv[1]);
1530 if( aType < 0 || aType > 8 )
1532 di << "Wrong fill type " << "\n";
1533 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1534 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1538 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1540 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1541 V3dView->SetBgGradientStyle( aMethod, 1 );
1547 //==============================================================================
1548 //function : VSetColorBg
1549 //purpose : Set color background
1550 //==============================================================================
1551 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1555 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1556 di << "R,G,B = [0..255]" << "\n";
1560 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1561 if(AISContext.IsNull())
1563 di << "use 'vinit' command before " << argv[0] << "\n";
1569 Standard_Real R = atof(argv[1])/255.;
1570 Standard_Real G = atof(argv[2])/255.;
1571 Standard_Real B = atof(argv[3])/255.;
1572 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1574 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1575 V3dView->SetBackgroundColor( aColor );
1582 //==============================================================================
1584 //purpose : View Scaling
1585 //==============================================================================
1587 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1589 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1590 if ( V3dView.IsNull() ) return 1;
1593 di << argv[0] << "Invalid number of arguments" << "\n";
1596 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1599 //==============================================================================
1600 //function : VTestZBuffTrihedron
1601 //purpose : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view
1602 //==============================================================================
1604 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1606 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1607 if ( V3dView.IsNull() ) return 1;
1609 // Set up default trihedron parameters
1610 V3dView->ZBufferTriedronSetup();
1611 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1616 //==============================================================================
1617 //function : VRotate
1618 //purpose : Camera Rotating
1619 //==============================================================================
1621 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1622 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1623 if ( V3dView.IsNull() ) {
1628 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1630 } else if ( argc == 7 ) {
1631 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1634 di << argv[0] << " Invalid number of arguments" << "\n";
1639 //==============================================================================
1641 //purpose : View zoom in / out (relative to current zoom)
1642 //==============================================================================
1644 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1645 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1646 if ( V3dView.IsNull() ) {
1651 Standard_Real coef = atof(argv[1]);
1652 if ( coef <= 0.0 ) {
1653 di << argv[1] << "Invalid value" << "\n";
1656 V3dView->SetZoom( atof(argv[1]) );
1659 di << argv[0] << " Invalid number of arguments" << "\n";
1664 //==============================================================================
1666 //purpose : View panning (in pixels)
1667 //==============================================================================
1669 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1670 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1671 if ( V3dView.IsNull() ) return 1;
1674 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1677 di << argv[0] << " Invalid number of arguments" << "\n";
1683 //==============================================================================
1684 //function : VExport
1685 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1686 //==============================================================================
1688 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1690 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1691 if (V3dView.IsNull())
1696 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1700 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1701 TCollection_AsciiString aFormatStr;
1703 TCollection_AsciiString aFileName (argv[1]);
1704 Standard_Integer aLen = aFileName.Length();
1708 aFormatStr = TCollection_AsciiString (argv[2]);
1712 if (aFileName.Value (aLen - 2) == '.')
1714 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1716 else if (aFileName.Value (aLen - 3) == '.')
1718 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1722 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1728 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1732 aFormatStr.UpperCase();
1733 if (aFormatStr == "PS")
1734 anExpFormat = Graphic3d_EF_PostScript;
1735 else if (aFormatStr == "EPS")
1736 anExpFormat = Graphic3d_EF_EnhPostScript;
1737 else if (aFormatStr == "TEX")
1738 anExpFormat = Graphic3d_EF_TEX;
1739 else if (aFormatStr == "PDF")
1740 anExpFormat = Graphic3d_EF_PDF;
1741 else if (aFormatStr == "SVG")
1742 anExpFormat = Graphic3d_EF_SVG;
1743 else if (aFormatStr == "PGF")
1744 anExpFormat = Graphic3d_EF_PGF;
1745 else if (aFormatStr == "EMF")
1746 anExpFormat = Graphic3d_EF_EMF;
1749 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1753 if (!V3dView->View()->Export (argv[1], anExpFormat))
1755 std::cout << "Export failed!\n";
1761 //==============================================================================
1762 //function : VColorScale
1763 //purpose : representation color scale
1764 //==============================================================================
1765 #include <V3d_ColorScale.hxx>
1767 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1769 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1771 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1775 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1776 if(aContext.IsNull()) {
1777 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1781 Standard_Real minRange = 0. , maxRange = 100. ;
1783 Standard_Integer numIntervals = 10 ;
1784 Standard_Real textHeight = 16. ;
1785 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1786 Standard_Real X = 0., Y = 0. ;
1792 minRange = atof( argv[1] );
1793 maxRange = atof( argv[2] );
1794 numIntervals = atoi( argv[3] );
1797 textHeight = atof( argv[4] );
1799 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1802 X = atof( argv[6] );
1803 Y = atof( argv[7] );
1806 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1807 if ( curView.IsNull( ) )
1809 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1810 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1811 if( ! aCS.IsNull( ) )
1813 aCS->SetPosition( X , Y );
1814 aCS->SetHeight( 0.95) ;
1815 aCS->SetTextHeight( textHeight );
1816 aCS->SetRange( minRange , maxRange );
1817 aCS->SetNumberOfIntervals( numIntervals );
1818 aCS->SetLabelPosition( position );
1819 if( !curView->ColorScaleIsDisplayed() )
1820 curView->ColorScaleDisplay( );
1825 //==============================================================================
1826 //function : VGraduatedTrihedron
1827 //purpose : Displays a graduated trihedron
1828 //==============================================================================
1830 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
1832 const char *str = arg;
1835 unsigned short c1 = *str++;
1836 unsigned short c2 = *str++;
1837 if (!c1 || !c2) break;
1838 name += (Standard_ExtCharacter)((c1 << 8) | c2);
1842 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1845 if (argc != 2 && argc < 5)
1847 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
1848 di<<"Usage: type help "<<argv[0]<<"\n";
1849 return 1; //TCL_ERROR
1852 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
1854 // Create 3D view if it doesn't exist
1855 if ( aV3dView.IsNull() )
1857 ViewerTest::ViewerInit();
1858 aV3dView = ViewerTest::CurrentView();
1859 if( aV3dView.IsNull() )
1861 di << "Error: Cannot create a 3D view\n";
1862 return 1; //TCL_ERROR
1866 // Erase (==0) or display (!=0)
1867 const int display = atoi(argv[1]);
1872 TCollection_AsciiString font;
1874 font.AssignCat("Courier");
1876 font.AssignCat(argv[5]);
1878 // Text is multibyte
1879 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
1882 TCollection_ExtendedString xname, yname, zname;
1887 AddMultibyteString(xname, argv[2]);
1888 AddMultibyteString(yname, argv[3]);
1889 AddMultibyteString(zname, argv[4]);
1905 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
1906 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
1907 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
1908 Standard_True/*drawgrid*/,
1909 Standard_True/*drawaxes*/,
1910 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
1911 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
1912 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
1913 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
1914 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
1915 Quantity_NOC_WHITE/*gridcolor*/,
1916 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
1917 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
1920 aV3dView->GraduatedTrihedronErase();
1922 ViewerTest::GetAISContext()->UpdateCurrentViewer();
1928 //==============================================================================
1929 //function : VPrintView
1930 //purpose : Test printing algorithm, print the view to image file with given
1931 // width and height. Printing implemented only for WNT.
1932 //==============================================================================
1933 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
1937 di << "Printing implemented only for wnt!\n";
1941 Handle(AIS_InteractiveContext) aContextAIS = NULL;
1942 Handle(V3d_View) aView = NULL;
1943 aContextAIS = ViewerTest::GetAISContext();
1944 if (!aContextAIS.IsNull())
1946 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
1947 Vwr->InitActiveViews();
1948 if(Vwr->MoreActiveViews())
1949 aView = Vwr->ActiveView();
1955 di << "Call vinit before!\n";
1960 di << "Use: " << argv[0];
1961 di << " width height filename [print algo=0]\n";
1962 di << "width, height of the intermediate buffer for operation\n";
1963 di << "algo : {0|1}\n";
1964 di << " 0 - stretch algorithm\n";
1965 di << " 1 - tile algorithm\n";
1966 di << "test printing algorithms into an intermediate buffer\n";
1967 di << "with saving output to an image file\n";
1971 // get the input params
1972 Standard_Integer aWidth = atoi (argv[1]);
1973 Standard_Integer aHeight = atoi (argv[2]);
1974 Standard_Integer aMode = 0;
1975 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
1977 aMode = atoi (argv[4]);
1979 // check the input parameters
1980 if (aWidth <= 0 || aHeight <= 0)
1982 di << "Width and height must be positive values!\n";
1985 if (aMode != 0 && aMode != 1)
1988 Image_CRawBufferData aRawBuffer;
1989 HDC anDC = CreateCompatibleDC(0);
1991 // define compatible bitmap
1992 BITMAPINFO aBitmapData;
1993 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
1994 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
1995 aBitmapData.bmiHeader.biWidth = aWidth ;
1996 aBitmapData.bmiHeader.biHeight = aHeight;
1997 aBitmapData.bmiHeader.biPlanes = 1;
1998 aBitmapData.bmiHeader.biBitCount = 24;
1999 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2000 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2001 aBitmapData.bmiHeader.biClrUsed = 0;
2002 aBitmapData.bmiHeader.biClrImportant = 0;
2003 aBitmapData.bmiHeader.biCompression = BI_RGB;
2004 aBitmapData.bmiHeader.biSizeImage = 0;
2006 // Create Device Independent Bitmap
2007 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2008 &aRawBuffer.dataPtr, NULL, 0);
2009 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2011 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2012 if (aRawBuffer.dataPtr != 0)
2015 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2017 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2019 // succesfully printed into an intermediate buffer
2022 Handle(Image_PixMap) anImageBitmap =
2023 new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr,
2025 aWidth*3 + aWidth%4, 24, 0);
2026 isSaved = anImageBitmap->Dump(aFileName.ToCString());
2030 di << "Print operation failed due to printing errors or\n";
2031 di << "insufficient memory available\n";
2032 di << "Please, try to use smaller dimensions for this test\n";
2033 di << "command, as it allocates intermediate buffer for storing\n";
2034 di << "the result\n";
2039 di << "Can't allocate memory for intermediate buffer\n";
2040 di << "Please use smaller dimensions\n";
2045 SelectObject (anDC, anOldBitmap);
2046 DeleteObject (aMemoryBitmap);
2052 di << "Save to file operation failed. This operation may fail\n";
2053 di << "if you don't have enough available memory, then you can\n";
2054 di << "use smaller dimensions for the output file\n";
2063 //=======================================================================
2064 //function : ViewerCommands
2066 //=======================================================================
2068 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
2071 const char *group = "ZeViewer";
2072 theCommands.Add("vinit" ,
2073 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
2074 __FILE__,VInit,group);
2075 theCommands.Add("vhelp" ,
2076 "vhelp : display help on the viewer commands",
2077 __FILE__,VHelp,group);
2078 theCommands.Add("vtop" ,
2079 "vtop or <T> : Top view" ,
2080 __FILE__,VTop,group);
2081 theCommands.Add("vaxo" ,
2082 " vaxo or <A> : Axonometric view ",
2083 __FILE__,VAxo,group);
2084 theCommands.Add("vpick" ,
2085 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
2087 theCommands.Add("vfit" ,
2088 "vfit or <F> : vfit",
2089 __FILE__,VFit,group);
2090 theCommands.Add("vzfit" ,
2092 __FILE__,VZFit,group);
2093 theCommands.Add("vrepaint",
2094 "vrepaint : vrepaint, force redraw",
2095 __FILE__,VRepaint,group);
2096 theCommands.Add("vclear",
2098 __FILE__,VClear,group);
2099 theCommands.Add("vsetbg",
2100 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
2101 __FILE__,VSetBg,group);
2102 theCommands.Add("vsetbgmode",
2103 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
2104 __FILE__,VSetBgMode,group);
2105 theCommands.Add("vsetgradientbg",
2106 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
2107 __FILE__,VSetGradientBg,group);
2108 theCommands.Add("vsetgrbgmode",
2109 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
2110 __FILE__,VSetGradientBgMode,group);
2111 theCommands.Add("vsetcolorbg",
2112 "vsetcolorbg : vsetcolorbg r g b : Set background color",
2113 __FILE__,VSetColorBg,group);
2114 theCommands.Add("vscale",
2115 "vscale : vscale X Y Z",
2116 __FILE__,VScale,group);
2117 theCommands.Add("vzbufftrihedron",
2118 "vzbufftrihedron : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view",
2119 __FILE__,VTestZBuffTrihedron,group);
2120 theCommands.Add("vrotate",
2121 "vrotate : vrotate AX AY AZ [X Y Z]",
2122 __FILE__,VRotate,group);
2123 theCommands.Add("vzoom",
2124 "vzoom : vzoom coef",
2125 __FILE__,VZoom,group);
2126 theCommands.Add("vpan",
2127 "vpan : vpan dx dy",
2128 __FILE__,VPan,group);
2129 theCommands.Add("vexport",
2130 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
2131 " : exports the view to a vector file of a given format"
2132 " : notice that EMF format requires patched gl2ps",
2133 __FILE__,VExport,group);
2134 theCommands.Add("vcolorscale",
2135 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
2136 __FILE__,VColorScale,group);
2137 theCommands.Add("vgraduatedtrihedron",
2138 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
2139 __FILE__,VGraduatedTrihedron,group);
2140 theCommands.Add("vprintview" ,
2141 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
2142 __FILE__,VPrintView,group);