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 <Visual3d_ViewManager.hxx>
21 #include <V3d_LayerMgr.hxx>
22 #include <NIS_View.hxx>
23 #include <NIS_Triangulated.hxx>
24 #include <NIS_InteractiveContext.hxx>
25 #include <AIS_InteractiveContext.hxx>
26 #include <Draw_Interpretor.hxx>
28 #include <Draw_Appli.hxx>
29 #include <Aspect_PrintAlgo.hxx>
30 #include <Image_PixMap.hxx>
31 #include <TColStd_SequenceOfInteger.hxx>
37 #include <Visual3d_Layer.hxx>
40 #include <Graphic3d_GraphicDevice.hxx>
41 #include <Xw_GraphicDevice.hxx>
42 #include <Xw_WindowQuality.hxx>
43 #include <Xw_Window.hxx>
44 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
45 #include <X11/Xutil.h>
50 #include <Graphic3d_WNTGraphicDevice.hxx>
51 #include <WNT_WClass.hxx>
52 #include <WNT_Window.hxx>
54 #define _CRT_SECURE_NO_DEPRECATE
55 #pragma warning (disable:4996)
61 //==============================================================================
63 //==============================================================================
64 // VIEWER GLOBAL VARIABLES
65 //==============================================================================
67 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
69 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
70 extern const Handle(NIS_InteractiveContext)& TheNISContext();
73 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
74 static Handle(Graphic3d_WNTGraphicDevice) GD;
78 static Handle(WNT_Window)& VT_GetWindow() {
79 static Handle(WNT_Window) WNTWin;
84 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
85 static Handle(Graphic3d_GraphicDevice) GD;
88 static Handle(Xw_Window)& VT_GetWindow(){
89 static Handle(Xw_Window) XWWin;
92 static Display *display;
94 static void VProcessEvents(ClientData,int);
98 static Standard_Boolean DegenerateMode = Standard_True;
101 #define ZCLIPWIDTH 1.
103 static void OSWindowSetup();
105 //==============================================================================
106 // EVENT GLOBAL VARIABLES
107 //==============================================================================
109 static int Start_Rot = 0;
110 static int ZClipIsOn = 0;
111 static int X_Motion= 0,Y_Motion=0; // Current cursor position
112 static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
115 //==============================================================================
118 static LRESULT WINAPI ViewerWindowProc(
123 static LRESULT WINAPI AdvViewerWindowProc(
131 //==============================================================================
134 //==============================================================================
136 const Handle(MMgt_TShared)& ViewerTest::WClass()
138 static Handle(MMgt_TShared) theWClass;
140 if (theWClass.IsNull()) {
141 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
142 CS_VREDRAW | CS_HREDRAW, 0, 0,
143 ::LoadCursor (NULL, IDC_ARROW));
149 //==============================================================================
150 //function : ViewerInit
151 //purpose : Create the window viewer and initialize all the global variable
152 //==============================================================================
154 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
155 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
157 static Standard_Boolean isFirst = Standard_True;
159 Standard_Integer aPxLeft = 0;
160 Standard_Integer aPxTop = 460;
161 Standard_Integer aPxWidth = 409;
162 Standard_Integer aPxHeight = 409;
163 if (thePxWidth != 0 && thePxHeight != 0)
167 aPxWidth = thePxWidth;
168 aPxHeight = thePxHeight;
173 // Create the Graphic device
175 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
176 if (VT_GetWindow().IsNull())
178 // Create the Graphic device and the window
179 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
181 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
182 Handle(WNT_WClass)::DownCast (WClass()),
187 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
190 if (GetG3dDevice().IsNull()) GetG3dDevice() =
191 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
192 if (VT_GetWindow().IsNull())
194 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
200 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
204 Handle(V3d_Viewer) a3DViewer, a3DCollector;
205 // Viewer and View creation
207 TCollection_ExtendedString NameOfWindow("Visu3D");
209 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
210 NameOfWindow = TCollection_ExtendedString("Collector");
211 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
212 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
213 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
214 Handle(NIS_View) aView =
215 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
216 if ( aView.IsNull() ) {
217 // Handle (V3d_View) V = a3DViewer->CreateView();
218 aView = new NIS_View (a3DViewer, VT_GetWindow());
219 ViewerTest::CurrentView(aView);
220 TheNISContext()->AttachView (aView);
222 Handle(V3d_View) a3DViewCol;
223 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
226 if ( ViewerTest::GetAISContext().IsNull() ) {
227 Handle(AIS_InteractiveContext) C =
228 new AIS_InteractiveContext(a3DViewer,a3DCollector);
229 ViewerTest::SetAISContext(C);
232 // Setup for X11 or NT
234 // Viewer and View creation
236 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
238 Handle (V3d_View) V = ViewerTest::CurrentView();
240 V->SetDegenerateModeOn();
242 DegenerateMode = V->DegenerateModeIsOn();
244 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
246 V->SetZClippingDepth(0.5);
247 V->SetZClippingWidth(ZCLIPWIDTH/2.);
248 a3DViewer->SetDefaultLights();
249 a3DViewer->SetLightOn();
252 #if TCL_MAJOR_VERSION < 8
253 Tk_CreateFileHandler((void*)ConnectionNumber(display),
254 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
256 Tk_CreateFileHandler(ConnectionNumber(display),
257 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
261 isFirst = Standard_False;
263 VT_GetWindow()->Map();
266 //==============================================================================
268 //purpose : Create the window viewer and initialize all the global variable
269 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
270 //==============================================================================
272 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
274 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
275 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
276 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
277 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
278 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
282 //==============================================================================
283 //function : ProcessKeyPress
284 //purpose : Handle KeyPress event from a CString
285 //==============================================================================
287 static void ProcessKeyPress( char *buf_ret )
289 //cout << "KeyPress" << endl;
290 const Handle(V3d_View) aView = ViewerTest::CurrentView();
291 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
292 // Letter in alphabetic order
294 if ( !strcasecmp(buf_ret, "A") ) {
296 aView->SetProj(V3d_XposYnegZpos);
298 else if ( !strcasecmp(buf_ret, "D") ) {
302 else if ( !strcasecmp(buf_ret, "F") ) {
304 if (aNisView.IsNull())
307 aNisView->FitAll3d();
309 else if ( !strcasecmp(buf_ret, "H") ) {
311 cout << "HLR" << endl;
313 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
314 else aView->SetDegenerateModeOn();
315 DegenerateMode = aView->DegenerateModeIsOn();
317 ViewerTest::CurrentView()->SetDegenerateModeOff();
320 else if ( !strcasecmp(buf_ret, "D") ) {
324 else if ( !strcasecmp(buf_ret, "S") ) {
326 cout << "passage en mode 1 (shading pour les shapes)" << endl;
328 ViewerTest::CurrentView()->SetDegenerateModeOn();
330 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
331 if(Ctx->NbCurrents()==0 ||
332 Ctx->NbSelected()==0)
333 Ctx->SetDisplayMode(AIS_Shaded);
335 if(Ctx->HasOpenedContext()){
336 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
337 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
340 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
341 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
343 Ctx->UpdateCurrentViewer();
346 else if ( !strcasecmp(buf_ret, "U") ) {
348 cout<<"passage au mode par defaut"<<endl;
350 ViewerTest::CurrentView()->SetDegenerateModeOn();
352 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
353 if(Ctx->NbCurrents()==0 ||
354 Ctx->NbSelected()==0)
355 Ctx->SetDisplayMode(AIS_WireFrame);
357 if(Ctx->HasOpenedContext()){
358 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
359 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
362 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
363 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
365 Ctx->UpdateCurrentViewer();
369 else if ( !strcasecmp(buf_ret, "T") ) {
371 aView->SetProj(V3d_Zpos);
373 else if ( !strcasecmp(buf_ret, "B") ) {
375 aView->SetProj(V3d_Zneg);
377 else if ( !strcasecmp(buf_ret, "L") ) {
379 aView->SetProj(V3d_Xneg);
381 else if ( !strcasecmp(buf_ret, "R") ) {
383 aView->SetProj(V3d_Xpos);
386 else if ( !strcasecmp(buf_ret, "W") ) {
389 ViewerTest::CurrentView()->SetDegenerateModeOn();
391 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
393 ViewerTest::CurrentView()->SetDegenerateModeOn();
395 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
396 if(Ctx->NbCurrents()==0 ||
397 Ctx->NbSelected()==0)
398 Ctx->SetDisplayMode(AIS_WireFrame);
400 if(Ctx->HasOpenedContext()){
401 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
402 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
405 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
406 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
408 Ctx->UpdateCurrentViewer();
411 else if ( !strcasecmp(buf_ret, "Z") ) {
415 cout << "ZClipping OFF" << endl;
418 aView->SetZClippingType(V3d_OFF);
422 cout << "ZClipping ON" << endl;
425 aView->SetZClippingType(V3d_FRONT);
429 else if ( !strcasecmp(buf_ret, ",") ) {
430 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
434 else if ( !strcasecmp(buf_ret, ".") ) {
435 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
439 Standard_Integer Num = atoi(buf_ret);
441 ViewerTest::StandardModeActivation(Num);
445 //==============================================================================
446 //function : ProcessExpose
447 //purpose : Redraw the View on an Expose Event
448 //==============================================================================
450 static void ProcessExpose( )
451 { //cout << "Expose" << endl;
452 ViewerTest::CurrentView()->Redraw();
455 //==============================================================================
456 //function : ProcessConfigure
457 //purpose : Resize the View on an Configure Event
458 //==============================================================================
460 static void ProcessConfigure()
462 Handle(V3d_View) V = ViewerTest::CurrentView();
468 //==============================================================================
469 //function : ProcessButton1Press
471 //==============================================================================
473 static Standard_Boolean ProcessButton1Press(
476 Standard_Boolean pick,
477 Standard_Boolean shift )
479 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
481 Standard_Real X, Y, Z;
483 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
485 Draw::Set(argv[1], X);
486 Draw::Set(argv[2], Y);
487 Draw::Set(argv[3], Z);}
498 //==============================================================================
499 //function : ProcessButton3Press
500 //purpose : Start Rotation
501 //==============================================================================
503 static void ProcessButton3Press()
507 ViewerTest::CurrentView()->SetDegenerateModeOn();
508 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
511 //==============================================================================
512 //function : ProcessButtonRelease
513 //purpose : Start Rotation
514 //==============================================================================
516 static void ProcessButtonRelease()
522 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
526 ViewerTest::CurrentView()->SetDegenerateModeOff();
530 //==============================================================================
531 //function : ProcessZClipMotion
533 //==============================================================================
535 void ProcessZClipMotion()
537 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
538 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
539 static Standard_Real CurZPos = 0.;
541 //Quantity_Length VDX, VDY;
542 //a3DView->Size(VDX,VDY);
543 //Standard_Real VDZ = a3DView->ZSize();
544 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
546 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
548 // Front = Depth + width/2.
549 Standard_Real D = 0.5;
550 Standard_Real W = 0.1;
556 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
558 a3DView->SetZClippingType(V3d_OFF);
559 a3DView->SetZClippingDepth(D);
560 a3DView->SetZClippingWidth(W);
561 a3DView->SetZClippingType(V3d_FRONT);
565 X_ButtonPress = X_Motion;
566 Y_ButtonPress = Y_Motion;
570 //==============================================================================
571 //function : ProcessControlButton1Motion
573 //==============================================================================
575 static void ProcessControlButton1Motion()
577 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
579 X_ButtonPress = X_Motion;
580 Y_ButtonPress = Y_Motion;
583 //==============================================================================
584 //function : ProcessControlButton2Motion
586 //==============================================================================
588 static void ProcessControlButton2Motion()
590 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
591 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
593 dy = -dy; // Xwindow Y axis is from top to Bottom
595 ViewerTest::CurrentView()->Panning( dx, dy );
597 X_ButtonPress = X_Motion;
598 Y_ButtonPress = Y_Motion;
601 //==============================================================================
602 //function : ProcessControlButton3Motion
604 //==============================================================================
606 static void ProcessControlButton3Motion()
608 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
611 //==============================================================================
612 //function : ProcessPointerMotion
614 //==============================================================================
616 static void ProcessMotion()
618 //pre-hilights detected objects at mouse position
620 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
621 EM->MoveTo(X_Motion, Y_Motion);
625 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
627 Xpix = X_Motion;Ypix=Y_Motion;
630 //==============================================================================
632 //purpose : Switch to an Axonometric view
634 //==============================================================================
636 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
637 { if ( ViewerTest::CurrentView().IsNull() ) {
638 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
639 // VInit(di, argc, argv);
642 ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
647 //==============================================================================
649 //purpose : Switch to a Top View
651 //==============================================================================
653 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
656 if ( ViewerTest::CurrentView().IsNull() ) {
657 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
659 // VInit(di, , argv);
662 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
667 //==============================================================================
669 //purpose : Dsiplay help on viewer Keyboead and mouse commands
671 //==============================================================================
673 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
676 di << "Q : Quit the application" << "\n";
678 di << "========================="<<"\n";
679 di << "F : FitAll" << "\n";
680 di << "T : TopView" << "\n";
681 di << "A : AxonometricView" << "\n";
682 di << "R : ResetView" << "\n";
684 di << "========================="<<"\n";
685 di << "S : Shading" << "\n";
686 di << "W : Wireframe" << "\n";
687 di << "H : HidelLineRemoval" << "\n";
689 di << "========================="<<"\n";
690 di << "Selection mode "<<"\n";
691 di << "0 : Shape" <<"\n";
692 di << "1 : Vertex" <<"\n";
693 di << "2 : Edge" <<"\n";
694 di << "3 : Wire" <<"\n";
695 di << "4 : Face" <<"\n";
696 di << "5 : Shell" <<"\n";
697 di << "6 : Solid" <<"\n";
698 di << "7 : Compound" <<"\n";
700 di << "=========================="<<"\n";
701 di << "D : Remove Selected Object"<<"\n";
702 di << "=========================="<<"\n";
707 Standard_Boolean IsDragged = Standard_False;
709 Standard_Integer xx1, yy1, xx2, yy2;
710 //the first and last point in viewer co-ordinates
712 Standard_Boolean DragFirst;
717 static Standard_Boolean Ppick = 0;
718 static Standard_Integer Pargc = 0;
719 static const char** Pargv = NULL;
722 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
727 if ( !ViewerTest::CurrentView().IsNull() ) {
729 WPARAM fwKeys = wParam;
734 IsDragged = Standard_False;
737 HDC hdc = GetDC( hwnd );
738 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
739 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
740 SetROP2( hdc, R2_NOT );
741 Rectangle( hdc, xx1, yy1, xx2, yy2 );
742 ReleaseDC( hwnd, hdc );
744 const Handle(ViewerTest_EventManager) EM =
745 ViewerTest::CurrentEventManager();
746 if ( fwKeys & MK_SHIFT )
747 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
748 max( xx1, xx2 ), min( yy1, yy2 ));
750 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
751 max( xx1, xx2 ), min( yy1, yy2 ));
753 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
756 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
758 IsDragged = Standard_True;
759 DragFirst = Standard_True;
760 xx1 = LOWORD(lParam);
761 yy1 = HIWORD(lParam);
763 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
770 HDC hdc = GetDC( hwnd );
772 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
773 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
774 SetROP2( hdc, R2_NOT );
777 Rectangle( hdc, xx1, yy1, xx2, yy2 );
779 DragFirst = Standard_False;
780 xx2 = LOWORD(lParam);
781 yy2 = HIWORD(lParam);
783 Rectangle( hdc, xx1, yy1, xx2, yy2 );
785 SelectObject( hdc, anObj );
787 ReleaseDC( hwnd, hdc );
790 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
794 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
798 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
802 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
807 /*static Standard_Boolean Ppick = 0;
808 static Standard_Integer Pargc = 0;
809 static char** Pargv = NULL;*/
813 if ( !ViewerTest::CurrentView().IsNull() ) {
818 // do not destroy the window - just hide it!
819 VT_GetWindow()->Unmap();
822 //cout << "\t WM_PAINT" << endl;
823 BeginPaint(hwnd, &ps);
829 //cout << "\t WM_SIZE" << endl;
834 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
836 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
838 c[0] = (char) wParam;
847 //cout << "\t WM_xBUTTONUP" << endl;
849 ProcessButtonRelease();
856 //cout << "\t WM_xBUTTONDOWN" << endl;
857 WPARAM fwKeys = wParam;
861 X_ButtonPress = LOWORD(lParam);
862 Y_ButtonPress = HIWORD(lParam);
864 if ( Msg == WM_LBUTTONDOWN) {
865 if(fwKeys & MK_CONTROL) {
866 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
868 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
870 else if ( Msg == WM_RBUTTONDOWN ) {
872 ProcessButton3Press( );
879 //cout << "\t WM_MOUSEMOVE" << endl;
880 WPARAM fwKeys = wParam;
881 X_Motion = LOWORD(lParam);
882 Y_Motion = HIWORD(lParam);
885 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
887 X_ButtonPress = LOWORD(lParam);
888 Y_ButtonPress = HIWORD(lParam);
890 if ( fwKeys & MK_RBUTTON ) {
892 ProcessButton3Press();
896 if ( fwKeys & MK_CONTROL ) {
897 if ( fwKeys & MK_LBUTTON ) {
898 ProcessControlButton1Motion();
900 else if ( fwKeys & MK_MBUTTON ||
901 ((fwKeys&MK_LBUTTON) &&
902 (fwKeys&MK_RBUTTON) ) ){
903 ProcessControlButton2Motion();
905 else if ( fwKeys & MK_RBUTTON ) {
906 ProcessControlButton3Motion();
910 else if ( fwKeys & MK_SHIFT ) {
911 if ( fwKeys & MK_MBUTTON ||
912 ((fwKeys&MK_LBUTTON) &&
913 (fwKeys&MK_RBUTTON) ) ) {
914 cout << "ProcessZClipMotion()" << endl;
915 ProcessZClipMotion();
920 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
921 ProcessZClipMotion();
930 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
935 return DefWindowProc( hwnd, Msg, wParam, lParam );
941 //==============================================================================
942 //function : ViewerMainLoop
943 //purpose : Get a Event on the view and dispatch it
944 //==============================================================================
947 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
950 //cout << "No yet implemented on WNT" << endl;
951 /*static Standard_Boolean Ppick = 0;
952 static Standard_Integer Pargc = 0;
953 static char** Pargv = NULL;*/
955 //Ppick = (argc > 0)? -1 : 0;
956 Ppick = (argc > 0)? 1 : 0;
964 cout << "Start picking" << endl;
966 //while ( Ppick == -1 ) {
967 while ( Ppick == 1 ) {
968 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
969 if (GetMessage(&msg, NULL, 0, 0) ) {
970 TranslateMessage(&msg);
971 DispatchMessage(&msg);
975 cout << "Picking done" << endl;
984 int min( int a, int b )
992 int max( int a, int b )
1000 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1002 { Standard_Boolean pick = argc > 0;
1006 static XEvent report;
1008 XNextEvent( display, &report );
1009 // cout << "rep type = " << report.type << endl;
1010 // cout << "rep button = " << report.xbutton.button << endl;
1012 switch ( report.type ) {
1018 case ConfigureNotify:
1029 XComposeStatus status_in_out;
1031 ret_len = XLookupString( ( XKeyEvent *)&report ,
1032 (char *) buf_ret , 10 ,
1033 &ks_ret , &status_in_out ) ;
1036 buf_ret[ret_len] = '\0' ;
1039 ProcessKeyPress( buf_ret);
1044 // cout << "ButtonPress" << endl;
1046 X_ButtonPress = report.xbutton.x;
1047 Y_ButtonPress = report.xbutton.y;
1049 if ( report.xbutton.button == Button1 )
1050 if( report.xbutton.state & ControlMask )
1051 pick = ProcessButton1Press( argc, argv, pick,
1052 ( report.xbutton.state & ShiftMask) );
1055 IsDragged = Standard_True;
1056 xx1 = X_ButtonPress;
1057 yy1 = Y_ButtonPress;
1058 DragFirst = Standard_True;
1060 else if ( report.xbutton.button == Button3 )
1062 ProcessButton3Press();
1067 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1068 // cout << IsDragged << endl;
1069 // cout << DragFirst << endl;
1075 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1076 GC gc = XCreateGC( display, aWindow, 0, 0 );
1077 // XSetFunction( display, gc, GXinvert );
1078 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1081 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1082 if( aContext.IsNull() )
1084 cout << "The context is null. Please use vinit before createmesh" << endl;
1088 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1089 if( report.xbutton.button==1 )
1093 aContext->ShiftSelect();
1094 // cout << "shift select" << endl;
1099 // cout << "select" << endl;
1104 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1105 max( xx1, xx2 ), max( yy1, yy2 ),
1106 ViewerTest::CurrentView());
1107 // cout << "shift select" << endl;
1111 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1112 max( xx1, xx2 ), max( yy1, yy2 ),
1113 ViewerTest::CurrentView() );
1114 // cout << "select" << endl;
1117 ProcessButtonRelease();
1119 IsDragged = Standard_False;
1122 ProcessButtonRelease();
1129 X_Motion = report.xmotion.x;
1130 Y_Motion = report.xmotion.y;
1134 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1135 GC gc = XCreateGC( display, aWindow, 0, 0 );
1136 XSetFunction( display, gc, GXinvert );
1139 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1143 DragFirst = Standard_False;
1145 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1146 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1151 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1153 // remove all the ButtonMotionMask
1154 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1156 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1157 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1159 Quantity_Length VDX, VDY;
1161 ViewerTest::CurrentView()->Size(VDX,VDY);
1162 Standard_Real VDZ =0 ;
1163 VDZ = ViewerTest::CurrentView()->ZSize();
1165 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1166 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1168 Quantity_Length dx = 0 ;
1169 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1173 dx = dx / VDX * VDZ;
1177 // Front = Depth + width/2.
1178 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1179 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1181 ViewerTest::CurrentView()->Redraw();
1185 if ( report.xmotion.state & ControlMask ) {
1186 if ( report.xmotion.state & Button1Mask ) {
1187 ProcessControlButton1Motion();
1189 else if ( report.xmotion.state & Button2Mask ) {
1190 ProcessControlButton2Motion();
1192 else if ( report.xmotion.state & Button3Mask ) {
1193 ProcessControlButton3Motion();
1208 //==============================================================================
1209 //function : VProcessEvents
1210 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1211 // event in the Viewer window
1212 //==============================================================================
1214 static void VProcessEvents(ClientData,int)
1216 //cout << "VProcessEvents" << endl;
1219 while (XPending(display)) {
1220 ViewerMainLoop( 0, NULL);
1225 //==============================================================================
1226 //function : OSWindowSetup
1227 //purpose : Setup for the X11 window to be able to cath the event
1228 //==============================================================================
1231 static void OSWindowSetup()
1236 Window window = VT_GetWindow()->XWindow();
1238 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1239 display = (Display * ) theDisplay;
1240 // display = (Display *)GetG3dDevice()->XDisplay();
1242 XSynchronize(display, 1);
1244 VT_GetWindow()->Map();
1246 // X11 : For keyboard on SUN
1248 wmhints.flags = InputHint;
1251 XSetWMHints( display, window, &wmhints);
1253 XSelectInput( display, window, ExposureMask | KeyPressMask |
1254 ButtonPressMask | ButtonReleaseMask |
1255 StructureNotifyMask |
1257 Button1MotionMask | Button2MotionMask |
1261 XSynchronize(display, 0);
1270 //==============================================================================
1273 //purpose : Fitall, no DRAW arguments
1274 //Draw arg : No args
1275 //==============================================================================
1277 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1279 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1280 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1281 if (V.IsNull() == Standard_False) {
1283 } else if (aView.IsNull() == Standard_False) {
1289 //==============================================================================
1291 //purpose : ZFitall, no DRAW arguments
1292 //Draw arg : No args
1293 //==============================================================================
1295 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1297 Handle(V3d_View) V = ViewerTest::CurrentView();
1298 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1301 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1303 Handle(V3d_View) V = ViewerTest::CurrentView();
1304 if ( !V.IsNull() ) V->Redraw(); return 0;
1308 //==============================================================================
1310 //purpose : Remove all the object from the viewer
1311 //Draw arg : No args
1312 //==============================================================================
1314 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1316 Handle(V3d_View) V = ViewerTest::CurrentView();
1318 ViewerTest::Clear();
1322 //==============================================================================
1325 //==============================================================================
1327 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1328 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1331 di << argv[0] << "Invalid number of arguments" << "\n";
1335 while (ViewerMainLoop( argc, argv)) {
1343 //==============================================================================
1344 //function : InitViewerTest
1345 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1346 //==============================================================================
1348 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1350 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1351 ViewerTest::SetAISContext(context);
1352 viewer->InitActiveViews();
1353 Handle(V3d_View) view = viewer->ActiveView();
1354 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1355 ViewerTest::ResetEventManager();
1356 Handle(Aspect_GraphicDevice) device = viewer->Device();
1357 Handle(Aspect_Window) window = view->Window();
1360 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1361 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1363 static int first = 1;
1365 #if TCL_MAJOR_VERSION < 8
1366 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1367 TK_READABLE, VProcessEvents, (ClientData) 0);
1369 Tk_CreateFileHandler(ConnectionNumber(display),
1370 TK_READABLE, VProcessEvents, (ClientData) 0);
1378 //==============================================================================
1380 //purpose : Load image as background
1381 //==============================================================================
1383 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1385 if (argc < 2 || argc > 3)
1387 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1388 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1392 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1393 if(AISContext.IsNull())
1395 di << "use 'vinit' command before " << argv[0] << "\n";
1399 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1402 const char* szType = argv[2];
1403 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1404 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1405 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1406 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1409 di << "Wrong fill type : " << szType << "\n";
1410 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1415 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1416 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1421 //==============================================================================
1422 //function : VSetBgMode
1423 //purpose : Change background image fill type
1424 //==============================================================================
1426 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1430 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1431 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1435 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1436 if(AISContext.IsNull())
1438 di << "use 'vinit' command before " << argv[0] << "\n";
1442 Aspect_FillMethod aFillType;
1445 const char* szType = argv[1];
1446 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1447 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1448 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1449 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1452 di << "Wrong fill type : " << szType << "\n";
1453 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1458 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1459 V3dView->SetBgImageStyle(aFillType, Standard_True);
1464 //==============================================================================
1465 //function : VSetGradientBg
1466 //purpose : Mount gradient background
1467 //==============================================================================
1468 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1472 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1473 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1474 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1475 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1479 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1480 if(AISContext.IsNull())
1482 di << "use 'vinit' command before " << argv[0] << "\n";
1488 Standard_Real R1 = atof(argv[1])/255.;
1489 Standard_Real G1 = atof(argv[2])/255.;
1490 Standard_Real B1 = atof(argv[3])/255.;
1491 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1493 Standard_Real R2 = atof(argv[4])/255.;
1494 Standard_Real G2 = atof(argv[5])/255.;
1495 Standard_Real B2 = atof(argv[6])/255.;
1497 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1498 int aType = atoi(argv[7]);
1499 if( aType < 0 || aType > 8 )
1501 di << "Wrong fill type " << "\n";
1502 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1503 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1507 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1509 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1510 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1516 //==============================================================================
1517 //function : VSetGradientBgMode
1518 //purpose : Change gradient background fill style
1519 //==============================================================================
1520 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1524 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1525 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1526 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1530 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1531 if(AISContext.IsNull())
1533 di << "use 'vinit' command before " << argv[0] << "\n";
1538 int aType = atoi(argv[1]);
1539 if( aType < 0 || aType > 8 )
1541 di << "Wrong fill type " << "\n";
1542 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1543 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1547 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1549 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1550 V3dView->SetBgGradientStyle( aMethod, 1 );
1556 //==============================================================================
1557 //function : VSetColorBg
1558 //purpose : Set color background
1559 //==============================================================================
1560 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1564 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1565 di << "R,G,B = [0..255]" << "\n";
1569 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1570 if(AISContext.IsNull())
1572 di << "use 'vinit' command before " << argv[0] << "\n";
1578 Standard_Real R = atof(argv[1])/255.;
1579 Standard_Real G = atof(argv[2])/255.;
1580 Standard_Real B = atof(argv[3])/255.;
1581 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1583 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1584 V3dView->SetBackgroundColor( aColor );
1591 //==============================================================================
1593 //purpose : View Scaling
1594 //==============================================================================
1596 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1598 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1599 if ( V3dView.IsNull() ) return 1;
1602 di << argv[0] << "Invalid number of arguments" << "\n";
1605 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1608 //==============================================================================
1609 //function : VTestZBuffTrihedron
1610 //purpose : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view
1611 //==============================================================================
1613 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1615 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1616 if ( V3dView.IsNull() ) return 1;
1618 // Set up default trihedron parameters
1619 V3dView->ZBufferTriedronSetup();
1620 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1625 //==============================================================================
1626 //function : VRotate
1627 //purpose : Camera Rotating
1628 //==============================================================================
1630 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1631 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1632 if ( V3dView.IsNull() ) {
1637 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1639 } else if ( argc == 7 ) {
1640 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1643 di << argv[0] << " Invalid number of arguments" << "\n";
1648 //==============================================================================
1650 //purpose : View zoom in / out (relative to current zoom)
1651 //==============================================================================
1653 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1654 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1655 if ( V3dView.IsNull() ) {
1660 Standard_Real coef = atof(argv[1]);
1661 if ( coef <= 0.0 ) {
1662 di << argv[1] << "Invalid value" << "\n";
1665 V3dView->SetZoom( atof(argv[1]) );
1668 di << argv[0] << " Invalid number of arguments" << "\n";
1673 //==============================================================================
1675 //purpose : View panning (in pixels)
1676 //==============================================================================
1678 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1679 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1680 if ( V3dView.IsNull() ) return 1;
1683 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1686 di << argv[0] << " Invalid number of arguments" << "\n";
1692 //==============================================================================
1693 //function : VExport
1694 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1695 //==============================================================================
1697 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1699 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1700 if (V3dView.IsNull())
1705 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1709 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1710 TCollection_AsciiString aFormatStr;
1712 TCollection_AsciiString aFileName (argv[1]);
1713 Standard_Integer aLen = aFileName.Length();
1717 aFormatStr = TCollection_AsciiString (argv[2]);
1721 if (aFileName.Value (aLen - 2) == '.')
1723 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1725 else if (aFileName.Value (aLen - 3) == '.')
1727 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1731 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1737 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1741 aFormatStr.UpperCase();
1742 if (aFormatStr == "PS")
1743 anExpFormat = Graphic3d_EF_PostScript;
1744 else if (aFormatStr == "EPS")
1745 anExpFormat = Graphic3d_EF_EnhPostScript;
1746 else if (aFormatStr == "TEX")
1747 anExpFormat = Graphic3d_EF_TEX;
1748 else if (aFormatStr == "PDF")
1749 anExpFormat = Graphic3d_EF_PDF;
1750 else if (aFormatStr == "SVG")
1751 anExpFormat = Graphic3d_EF_SVG;
1752 else if (aFormatStr == "PGF")
1753 anExpFormat = Graphic3d_EF_PGF;
1754 else if (aFormatStr == "EMF")
1755 anExpFormat = Graphic3d_EF_EMF;
1758 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1762 if (!V3dView->View()->Export (argv[1], anExpFormat))
1764 std::cout << "Export failed!\n";
1770 //==============================================================================
1771 //function : VColorScale
1772 //purpose : representation color scale
1773 //==============================================================================
1774 #include <V3d_ColorScale.hxx>
1776 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1778 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1780 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1784 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1785 if(aContext.IsNull()) {
1786 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1790 Standard_Real minRange = 0. , maxRange = 100. ;
1792 Standard_Integer numIntervals = 10 ;
1793 Standard_Real textHeight = 16. ;
1794 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1795 Standard_Real X = 0., Y = 0. ;
1801 minRange = atof( argv[1] );
1802 maxRange = atof( argv[2] );
1803 numIntervals = atoi( argv[3] );
1806 textHeight = atof( argv[4] );
1808 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1811 X = atof( argv[6] );
1812 Y = atof( argv[7] );
1815 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1816 if ( curView.IsNull( ) )
1818 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1819 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1820 if( ! aCS.IsNull( ) )
1822 aCS->SetPosition( X , Y );
1823 aCS->SetHeight( 0.95) ;
1824 aCS->SetTextHeight( textHeight );
1825 aCS->SetRange( minRange , maxRange );
1826 aCS->SetNumberOfIntervals( numIntervals );
1827 aCS->SetLabelPosition( position );
1828 if( !curView->ColorScaleIsDisplayed() )
1829 curView->ColorScaleDisplay( );
1834 //==============================================================================
1835 //function : VGraduatedTrihedron
1836 //purpose : Displays a graduated trihedron
1837 //==============================================================================
1839 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
1841 const char *str = arg;
1844 unsigned short c1 = *str++;
1845 unsigned short c2 = *str++;
1846 if (!c1 || !c2) break;
1847 name += (Standard_ExtCharacter)((c1 << 8) | c2);
1851 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1854 if (argc != 2 && argc < 5)
1856 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
1857 di<<"Usage: type help "<<argv[0]<<"\n";
1858 return 1; //TCL_ERROR
1861 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
1863 // Create 3D view if it doesn't exist
1864 if ( aV3dView.IsNull() )
1866 ViewerTest::ViewerInit();
1867 aV3dView = ViewerTest::CurrentView();
1868 if( aV3dView.IsNull() )
1870 di << "Error: Cannot create a 3D view\n";
1871 return 1; //TCL_ERROR
1875 // Erase (==0) or display (!=0)
1876 const int display = atoi(argv[1]);
1881 TCollection_AsciiString font;
1883 font.AssignCat("Courier");
1885 font.AssignCat(argv[5]);
1887 // Text is multibyte
1888 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
1891 TCollection_ExtendedString xname, yname, zname;
1896 AddMultibyteString(xname, argv[2]);
1897 AddMultibyteString(yname, argv[3]);
1898 AddMultibyteString(zname, argv[4]);
1914 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
1915 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
1916 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
1917 Standard_True/*drawgrid*/,
1918 Standard_True/*drawaxes*/,
1919 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
1920 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
1921 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
1922 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
1923 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
1924 Quantity_NOC_WHITE/*gridcolor*/,
1925 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
1926 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
1929 aV3dView->GraduatedTrihedronErase();
1931 ViewerTest::GetAISContext()->UpdateCurrentViewer();
1937 //==============================================================================
1938 //function : VPrintView
1939 //purpose : Test printing algorithm, print the view to image file with given
1940 // width and height. Printing implemented only for WNT.
1941 //==============================================================================
1942 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
1946 di << "Printing implemented only for wnt!\n";
1950 Handle(AIS_InteractiveContext) aContextAIS = NULL;
1951 Handle(V3d_View) aView = NULL;
1952 aContextAIS = ViewerTest::GetAISContext();
1953 if (!aContextAIS.IsNull())
1955 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
1956 Vwr->InitActiveViews();
1957 if(Vwr->MoreActiveViews())
1958 aView = Vwr->ActiveView();
1964 di << "Call vinit before!\n";
1969 di << "Use: " << argv[0];
1970 di << " width height filename [print algo=0]\n";
1971 di << "width, height of the intermediate buffer for operation\n";
1972 di << "algo : {0|1}\n";
1973 di << " 0 - stretch algorithm\n";
1974 di << " 1 - tile algorithm\n";
1975 di << "test printing algorithms into an intermediate buffer\n";
1976 di << "with saving output to an image file\n";
1980 // get the input params
1981 Standard_Integer aWidth = atoi (argv[1]);
1982 Standard_Integer aHeight = atoi (argv[2]);
1983 Standard_Integer aMode = 0;
1984 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
1986 aMode = atoi (argv[4]);
1988 // check the input parameters
1989 if (aWidth <= 0 || aHeight <= 0)
1991 di << "Width and height must be positive values!\n";
1994 if (aMode != 0 && aMode != 1)
1997 Image_CRawBufferData aRawBuffer;
1998 HDC anDC = CreateCompatibleDC(0);
2000 // define compatible bitmap
2001 BITMAPINFO aBitmapData;
2002 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2003 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2004 aBitmapData.bmiHeader.biWidth = aWidth ;
2005 aBitmapData.bmiHeader.biHeight = aHeight;
2006 aBitmapData.bmiHeader.biPlanes = 1;
2007 aBitmapData.bmiHeader.biBitCount = 24;
2008 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2009 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2010 aBitmapData.bmiHeader.biClrUsed = 0;
2011 aBitmapData.bmiHeader.biClrImportant = 0;
2012 aBitmapData.bmiHeader.biCompression = BI_RGB;
2013 aBitmapData.bmiHeader.biSizeImage = 0;
2015 // Create Device Independent Bitmap
2016 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2017 &aRawBuffer.dataPtr, NULL, 0);
2018 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2020 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2021 if (aRawBuffer.dataPtr != 0)
2024 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2026 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2028 // succesfully printed into an intermediate buffer
2031 Handle(Image_PixMap) anImageBitmap =
2032 new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr,
2034 aWidth*3 + aWidth%4, 24, 0);
2035 isSaved = anImageBitmap->Dump(aFileName.ToCString());
2039 di << "Print operation failed due to printing errors or\n";
2040 di << "insufficient memory available\n";
2041 di << "Please, try to use smaller dimensions for this test\n";
2042 di << "command, as it allocates intermediate buffer for storing\n";
2043 di << "the result\n";
2048 di << "Can't allocate memory for intermediate buffer\n";
2049 di << "Please use smaller dimensions\n";
2054 SelectObject (anDC, anOldBitmap);
2055 DeleteObject (aMemoryBitmap);
2061 di << "Save to file operation failed. This operation may fail\n";
2062 di << "if you don't have enough available memory, then you can\n";
2063 di << "use smaller dimensions for the output file\n";
2072 //==============================================================================
2073 //function : VZLayer
2074 //purpose : Test z layer operations for v3d viewer
2075 //==============================================================================
2076 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2078 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2079 if (aContextAIS.IsNull())
2081 di << "Call vinit before!\n";
2086 di << "Use: vzlayer " << argv[0];
2087 di << " add/del/get [id]\n";
2088 di << " add - add new z layer to viewer and print its id\n";
2089 di << " del - del z layer by its id\n";
2090 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2091 di << "id - the layer identificator value defined when removing z layer\n";
2095 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2096 if (aViewer.IsNull())
2098 di << "No active viewer!\n";
2102 // perform operation
2103 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2106 Standard_Integer aNewId;
2107 if (!aViewer->AddZLayer (aNewId))
2109 di << "Impossible to add new z layer!\n";
2113 di << "New z layer added with index: " << aNewId << "\n";
2115 else if (anOp == "del")
2119 di << "Please also provide as argument id of z layer to remove\n";
2123 Standard_Integer aDelId = atoi (argv[2]);
2124 if (!aViewer->RemoveZLayer (aDelId))
2126 di << "Impossible to remove the z layer or invalid id!\n";
2130 di << "Z layer " << aDelId << " has been removed\n";
2132 else if (anOp == "get")
2134 TColStd_SequenceOfInteger anIds;
2135 aViewer->GetAllZLayers (anIds);
2136 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2138 di << anIds.Value (aSeqIdx) << " ";
2145 di << "Invalid operation, please use { add / del / get }\n";
2152 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2154 // this class provides a presentation of text item in v3d view under-/overlayer
2155 class V3d_TextItem : public Visual3d_LayerItem
2160 DEFINE_STANDARD_RTTI(V3d_TextItem)
2163 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2164 const Standard_Real theX1,
2165 const Standard_Real theY1,
2166 const Standard_Real theHeight,
2167 const TCollection_AsciiString& theFontName,
2168 const Quantity_Color& theColor,
2169 const Quantity_Color& theSubtitleColor,
2170 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2171 const Handle(Visual3d_Layer)& theLayer);
2174 Standard_EXPORT void RedrawLayerPrs();
2180 Standard_Real myHeight;
2181 TCollection_AsciiString myText;
2182 TCollection_AsciiString myFontName;
2183 Quantity_Color myColor;
2184 Quantity_Color mySubtitleColor;
2185 Aspect_TypeOfDisplayText myType;
2186 Handle(Visual3d_Layer) myLayer;
2190 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2191 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2193 // create and add to display the text item
2194 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2195 const Standard_Real theX1,
2196 const Standard_Real theY1,
2197 const Standard_Real theHeight,
2198 const TCollection_AsciiString& theFontName,
2199 const Quantity_Color& theColor,
2200 const Quantity_Color& theSubtitleColor,
2201 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2202 const Handle(Visual3d_Layer)& theLayer)
2203 : myX1 (theX1), myY1 (theY1),
2205 myHeight (theHeight),
2208 mySubtitleColor (theSubtitleColor),
2209 myType (theTypeOfDisplay),
2210 myFontName (theFontName)
2212 if (!myLayer.IsNull ())
2213 myLayer->AddLayerItem (this);
2217 void V3d_TextItem::RedrawLayerPrs ()
2219 if (myLayer.IsNull ())
2222 myLayer->SetColor (myColor);
2223 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2224 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2227 //=======================================================================
2228 //function : VOverlayText
2229 //purpose : Test text displaying in view overlay
2230 //=======================================================================
2231 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2233 // get the active view
2234 Handle(V3d_View) aView = ViewerTest::CurrentView();
2237 di << "No active view. Please call vinit.\n";
2240 else if (argc < 4 || argc > 13)
2242 di << "Use: " << argv[0];
2243 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2244 di << "[background_color: R G B]\n";
2245 di << " height - pixel height of the text (default=10.0)\n";
2246 di << " font_name - name of font (default=courier)\n";
2247 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2248 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2249 di << " background_color- R G B values used for subtitle and decal text\n";
2250 di << "(default=255.0 255.0 255.0)\n";
2254 TCollection_AsciiString aText (argv[1]);
2255 Standard_Real aPosX = atof(argv[2]);
2256 Standard_Real aPosY = atof(argv[3]);
2257 Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
2260 TCollection_AsciiString aFontName = "Courier";
2262 aFontName = TCollection_AsciiString (argv[5]);
2265 Quantity_Parameter aColorRed = 1.0;
2266 Quantity_Parameter aColorGreen = 1.0;
2267 Quantity_Parameter aColorBlue = 1.0;
2270 aColorRed = atof (argv[6])/255.;
2271 aColorGreen = atof (argv[7])/255.;
2272 aColorBlue = atof (argv[8])/255.;
2276 TCollection_AsciiString aDispStr;
2278 aDispStr = TCollection_AsciiString (argv[9]);
2280 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2281 if (aDispStr.IsEqual ("subtitle"))
2282 aTextType = Aspect_TODT_SUBTITLE;
2283 else if (aDispStr.IsEqual ("decal"))
2284 aTextType = Aspect_TODT_DEKALE;
2285 else if (aDispStr.IsEqual ("blend"))
2286 aTextType = Aspect_TODT_BLEND;
2289 Quantity_Parameter aSubRed = 1.0;
2290 Quantity_Parameter aSubGreen = 1.0;
2291 Quantity_Parameter aSubBlue = 1.0;
2294 aSubRed = atof (argv[10])/255.;
2295 aSubGreen = atof (argv[11])/255.;
2296 aSubBlue = atof (argv[12])/255.;
2299 // check fo current overlay
2300 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2301 if (anOverlay.IsNull ())
2303 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2304 anOverlay = aMgr->Overlay ();
2305 aView->SetLayerMgr (aMgr);
2308 Quantity_Color aTextColor (aColorRed, aColorGreen,
2309 aColorBlue, Quantity_TOC_RGB);
2310 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2311 aSubBlue, Quantity_TOC_RGB);
2314 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2315 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2318 aView->MustBeResized();
2324 //=======================================================================
2325 //function : ViewerCommands
2327 //=======================================================================
2329 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
2332 const char *group = "ZeViewer";
2333 theCommands.Add("vinit" ,
2334 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
2335 __FILE__,VInit,group);
2336 theCommands.Add("vhelp" ,
2337 "vhelp : display help on the viewer commands",
2338 __FILE__,VHelp,group);
2339 theCommands.Add("vtop" ,
2340 "vtop or <T> : Top view" ,
2341 __FILE__,VTop,group);
2342 theCommands.Add("vaxo" ,
2343 " vaxo or <A> : Axonometric view ",
2344 __FILE__,VAxo,group);
2345 theCommands.Add("vpick" ,
2346 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
2348 theCommands.Add("vfit" ,
2349 "vfit or <F> : vfit",
2350 __FILE__,VFit,group);
2351 theCommands.Add("vzfit" ,
2353 __FILE__,VZFit,group);
2354 theCommands.Add("vrepaint",
2355 "vrepaint : vrepaint, force redraw",
2356 __FILE__,VRepaint,group);
2357 theCommands.Add("vclear",
2359 __FILE__,VClear,group);
2360 theCommands.Add("vsetbg",
2361 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
2362 __FILE__,VSetBg,group);
2363 theCommands.Add("vsetbgmode",
2364 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
2365 __FILE__,VSetBgMode,group);
2366 theCommands.Add("vsetgradientbg",
2367 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
2368 __FILE__,VSetGradientBg,group);
2369 theCommands.Add("vsetgrbgmode",
2370 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
2371 __FILE__,VSetGradientBgMode,group);
2372 theCommands.Add("vsetcolorbg",
2373 "vsetcolorbg : vsetcolorbg r g b : Set background color",
2374 __FILE__,VSetColorBg,group);
2375 theCommands.Add("vscale",
2376 "vscale : vscale X Y Z",
2377 __FILE__,VScale,group);
2378 theCommands.Add("vzbufftrihedron",
2379 "vzbufftrihedron : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view",
2380 __FILE__,VTestZBuffTrihedron,group);
2381 theCommands.Add("vrotate",
2382 "vrotate : vrotate AX AY AZ [X Y Z]",
2383 __FILE__,VRotate,group);
2384 theCommands.Add("vzoom",
2385 "vzoom : vzoom coef",
2386 __FILE__,VZoom,group);
2387 theCommands.Add("vpan",
2388 "vpan : vpan dx dy",
2389 __FILE__,VPan,group);
2390 theCommands.Add("vexport",
2391 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
2392 " : exports the view to a vector file of a given format"
2393 " : notice that EMF format requires patched gl2ps",
2394 __FILE__,VExport,group);
2395 theCommands.Add("vcolorscale",
2396 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
2397 __FILE__,VColorScale,group);
2398 theCommands.Add("vgraduatedtrihedron",
2399 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
2400 __FILE__,VGraduatedTrihedron,group);
2401 theCommands.Add("vprintview" ,
2402 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
2403 __FILE__,VPrintView,group);
2404 theCommands.Add("vzlayer",
2405 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
2406 __FILE__,VZLayer,group);
2407 theCommands.Add("voverlaytext",
2408 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
2409 " : height - pixel height of the text (default=10.0)"
2410 " : font_name - name of font (default=courier)"
2411 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
2412 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
2413 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
2414 __FILE__,VOverlayText,group);