1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Robert Boehne 30 May 2000 : Dec Osf
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <ViewerTest.hxx>
35 #include <ViewerTest_EventManager.hxx>
36 #include <Visual3d_View.hxx>
37 #include <Visual3d_ViewManager.hxx>
38 #include <V3d_LayerMgr.hxx>
39 #include <NIS_View.hxx>
40 #include <NIS_Triangulated.hxx>
41 #include <NIS_InteractiveContext.hxx>
42 #include <AIS_InteractiveContext.hxx>
43 #include <Draw_Interpretor.hxx>
45 #include <Draw_Appli.hxx>
46 #include <Aspect_PrintAlgo.hxx>
47 #include <Image_PixMap.hxx>
48 #include <TColStd_SequenceOfInteger.hxx>
49 #include <Visual3d_LayerItem.hxx>
50 #include <V3d_LayerMgr.hxx>
51 #include <V3d_LayerMgrPointer.hxx>
52 #include <Aspect_TypeOfLine.hxx>
58 #include <Visual3d_Layer.hxx>
61 #include <Graphic3d_GraphicDevice.hxx>
62 #include <Xw_GraphicDevice.hxx>
63 #include <Xw_WindowQuality.hxx>
64 #include <Xw_Window.hxx>
65 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
66 #include <X11/Xutil.h>
71 #include <Graphic3d_WNTGraphicDevice.hxx>
72 #include <WNT_WClass.hxx>
73 #include <WNT_Window.hxx>
75 #define _CRT_SECURE_NO_DEPRECATE
76 #pragma warning (disable:4996)
82 //==============================================================================
84 //==============================================================================
85 // VIEWER GLOBAL VARIABLES
86 //==============================================================================
88 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
90 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
91 extern const Handle(NIS_InteractiveContext)& TheNISContext();
94 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
95 static Handle(Graphic3d_WNTGraphicDevice) GD;
99 static Handle(WNT_Window)& VT_GetWindow() {
100 static Handle(WNT_Window) WNTWin;
105 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
106 static Handle(Graphic3d_GraphicDevice) GD;
109 static Handle(Xw_Window)& VT_GetWindow(){
110 static Handle(Xw_Window) XWWin;
113 static Display *display;
115 static void VProcessEvents(ClientData,int);
119 static Standard_Boolean DegenerateMode = Standard_True;
122 #define ZCLIPWIDTH 1.
124 static void OSWindowSetup();
126 //==============================================================================
127 // EVENT GLOBAL VARIABLES
128 //==============================================================================
130 static int Start_Rot = 0;
131 static int ZClipIsOn = 0;
132 static int X_Motion= 0,Y_Motion=0; // Current cursor position
133 static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
136 //==============================================================================
139 static LRESULT WINAPI ViewerWindowProc(
144 static LRESULT WINAPI AdvViewerWindowProc(
152 //==============================================================================
155 //==============================================================================
157 const Handle(MMgt_TShared)& ViewerTest::WClass()
159 static Handle(MMgt_TShared) theWClass;
161 if (theWClass.IsNull()) {
162 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
163 CS_VREDRAW | CS_HREDRAW, 0, 0,
164 ::LoadCursor (NULL, IDC_ARROW));
170 //==============================================================================
171 //function : ViewerInit
172 //purpose : Create the window viewer and initialize all the global variable
173 //==============================================================================
175 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
176 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
178 static Standard_Boolean isFirst = Standard_True;
180 Standard_Integer aPxLeft = 0;
181 Standard_Integer aPxTop = 460;
182 Standard_Integer aPxWidth = 409;
183 Standard_Integer aPxHeight = 409;
184 if (thePxWidth != 0 && thePxHeight != 0)
188 aPxWidth = thePxWidth;
189 aPxHeight = thePxHeight;
194 // Create the Graphic device
196 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
197 if (VT_GetWindow().IsNull())
199 // Create the Graphic device and the window
200 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
202 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
203 Handle(WNT_WClass)::DownCast (WClass()),
208 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
211 if (GetG3dDevice().IsNull()) GetG3dDevice() =
212 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
213 if (VT_GetWindow().IsNull())
215 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
221 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
225 Handle(V3d_Viewer) a3DViewer, a3DCollector;
226 // Viewer and View creation
228 TCollection_ExtendedString NameOfWindow("Visu3D");
230 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
231 NameOfWindow = TCollection_ExtendedString("Collector");
232 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
233 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
234 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
235 Handle(NIS_View) aView =
236 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
237 if ( aView.IsNull() ) {
238 // Handle (V3d_View) V = a3DViewer->CreateView();
239 aView = new NIS_View (a3DViewer, VT_GetWindow());
240 ViewerTest::CurrentView(aView);
241 TheNISContext()->AttachView (aView);
243 Handle(V3d_View) a3DViewCol;
244 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
247 if ( ViewerTest::GetAISContext().IsNull() ) {
248 Handle(AIS_InteractiveContext) C =
249 new AIS_InteractiveContext(a3DViewer,a3DCollector);
250 ViewerTest::SetAISContext(C);
253 // Setup for X11 or NT
255 // Viewer and View creation
257 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
259 Handle (V3d_View) V = ViewerTest::CurrentView();
261 V->SetDegenerateModeOn();
263 DegenerateMode = V->DegenerateModeIsOn();
265 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
267 V->SetZClippingDepth(0.5);
268 V->SetZClippingWidth(ZCLIPWIDTH/2.);
269 a3DViewer->SetDefaultLights();
270 a3DViewer->SetLightOn();
273 #if TCL_MAJOR_VERSION < 8
274 Tk_CreateFileHandler((void*)ConnectionNumber(display),
275 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
277 Tk_CreateFileHandler(ConnectionNumber(display),
278 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
282 isFirst = Standard_False;
284 VT_GetWindow()->Map();
287 //==============================================================================
289 //purpose : Create the window viewer and initialize all the global variable
290 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
291 //==============================================================================
293 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
295 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
296 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
297 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
298 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
299 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
303 //==============================================================================
304 //function : ProcessKeyPress
305 //purpose : Handle KeyPress event from a CString
306 //==============================================================================
308 static void ProcessKeyPress( char *buf_ret )
310 //cout << "KeyPress" << endl;
311 const Handle(V3d_View) aView = ViewerTest::CurrentView();
312 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
313 // Letter in alphabetic order
315 if ( !strcasecmp(buf_ret, "A") ) {
317 aView->SetProj(V3d_XposYnegZpos);
319 else if ( !strcasecmp(buf_ret, "D") ) {
323 else if ( !strcasecmp(buf_ret, "F") ) {
325 if (aNisView.IsNull())
328 aNisView->FitAll3d();
330 else if ( !strcasecmp(buf_ret, "H") ) {
332 cout << "HLR" << endl;
334 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
335 else aView->SetDegenerateModeOn();
336 DegenerateMode = aView->DegenerateModeIsOn();
338 ViewerTest::CurrentView()->SetDegenerateModeOff();
341 else if ( !strcasecmp(buf_ret, "D") ) {
345 else if ( !strcasecmp(buf_ret, "S") ) {
347 cout << "passage en mode 1 (shading pour les shapes)" << endl;
349 ViewerTest::CurrentView()->SetDegenerateModeOn();
351 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
352 if(Ctx->NbCurrents()==0 ||
353 Ctx->NbSelected()==0)
354 Ctx->SetDisplayMode(AIS_Shaded);
356 if(Ctx->HasOpenedContext()){
357 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
358 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
361 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
362 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
364 Ctx->UpdateCurrentViewer();
367 else if ( !strcasecmp(buf_ret, "U") ) {
369 cout<<"passage au mode par defaut"<<endl;
371 ViewerTest::CurrentView()->SetDegenerateModeOn();
373 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
374 if(Ctx->NbCurrents()==0 ||
375 Ctx->NbSelected()==0)
376 Ctx->SetDisplayMode(AIS_WireFrame);
378 if(Ctx->HasOpenedContext()){
379 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
380 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
383 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
384 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
386 Ctx->UpdateCurrentViewer();
390 else if ( !strcasecmp(buf_ret, "T") ) {
392 aView->SetProj(V3d_Zpos);
394 else if ( !strcasecmp(buf_ret, "B") ) {
396 aView->SetProj(V3d_Zneg);
398 else if ( !strcasecmp(buf_ret, "L") ) {
400 aView->SetProj(V3d_Xneg);
402 else if ( !strcasecmp(buf_ret, "R") ) {
404 aView->SetProj(V3d_Xpos);
407 else if ( !strcasecmp(buf_ret, "W") ) {
410 ViewerTest::CurrentView()->SetDegenerateModeOn();
412 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
414 ViewerTest::CurrentView()->SetDegenerateModeOn();
416 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
417 if(Ctx->NbCurrents()==0 ||
418 Ctx->NbSelected()==0)
419 Ctx->SetDisplayMode(AIS_WireFrame);
421 if(Ctx->HasOpenedContext()){
422 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
423 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
426 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
427 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
429 Ctx->UpdateCurrentViewer();
432 else if ( !strcasecmp(buf_ret, "Z") ) {
436 cout << "ZClipping OFF" << endl;
439 aView->SetZClippingType(V3d_OFF);
443 cout << "ZClipping ON" << endl;
446 aView->SetZClippingType(V3d_FRONT);
450 else if ( !strcasecmp(buf_ret, ",") ) {
451 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
455 else if ( !strcasecmp(buf_ret, ".") ) {
456 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
460 Standard_Integer Num = atoi(buf_ret);
462 ViewerTest::StandardModeActivation(Num);
466 //==============================================================================
467 //function : ProcessExpose
468 //purpose : Redraw the View on an Expose Event
469 //==============================================================================
471 static void ProcessExpose( )
472 { //cout << "Expose" << endl;
473 ViewerTest::CurrentView()->Redraw();
476 //==============================================================================
477 //function : ProcessConfigure
478 //purpose : Resize the View on an Configure Event
479 //==============================================================================
481 static void ProcessConfigure()
483 Handle(V3d_View) V = ViewerTest::CurrentView();
489 //==============================================================================
490 //function : ProcessButton1Press
492 //==============================================================================
494 static Standard_Boolean ProcessButton1Press(
497 Standard_Boolean pick,
498 Standard_Boolean shift )
500 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
502 Standard_Real X, Y, Z;
504 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
506 Draw::Set(argv[1], X);
507 Draw::Set(argv[2], Y);
508 Draw::Set(argv[3], Z);}
519 //==============================================================================
520 //function : ProcessButton3Press
521 //purpose : Start Rotation
522 //==============================================================================
524 static void ProcessButton3Press()
528 ViewerTest::CurrentView()->SetDegenerateModeOn();
529 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
532 //==============================================================================
533 //function : ProcessButtonRelease
534 //purpose : Start Rotation
535 //==============================================================================
537 static void ProcessButtonRelease()
543 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
547 ViewerTest::CurrentView()->SetDegenerateModeOff();
551 //==============================================================================
552 //function : ProcessZClipMotion
554 //==============================================================================
556 void ProcessZClipMotion()
558 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
559 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
560 static Standard_Real CurZPos = 0.;
562 //Quantity_Length VDX, VDY;
563 //a3DView->Size(VDX,VDY);
564 //Standard_Real VDZ = a3DView->ZSize();
565 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
567 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
569 // Front = Depth + width/2.
570 Standard_Real D = 0.5;
571 Standard_Real W = 0.1;
577 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
579 a3DView->SetZClippingType(V3d_OFF);
580 a3DView->SetZClippingDepth(D);
581 a3DView->SetZClippingWidth(W);
582 a3DView->SetZClippingType(V3d_FRONT);
586 X_ButtonPress = X_Motion;
587 Y_ButtonPress = Y_Motion;
591 //==============================================================================
592 //function : ProcessControlButton1Motion
594 //==============================================================================
596 static void ProcessControlButton1Motion()
598 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
600 X_ButtonPress = X_Motion;
601 Y_ButtonPress = Y_Motion;
604 //==============================================================================
605 //function : ProcessControlButton2Motion
607 //==============================================================================
609 static void ProcessControlButton2Motion()
611 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
612 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
614 dy = -dy; // Xwindow Y axis is from top to Bottom
616 ViewerTest::CurrentView()->Panning( dx, dy );
618 X_ButtonPress = X_Motion;
619 Y_ButtonPress = Y_Motion;
622 //==============================================================================
623 //function : ProcessControlButton3Motion
625 //==============================================================================
627 static void ProcessControlButton3Motion()
629 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
632 //==============================================================================
633 //function : ProcessPointerMotion
635 //==============================================================================
637 static void ProcessMotion()
639 //pre-hilights detected objects at mouse position
641 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
642 EM->MoveTo(X_Motion, Y_Motion);
646 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
648 Xpix = X_Motion;Ypix=Y_Motion;
651 //==============================================================================
653 //purpose : Switch to an Axonometric view
655 //==============================================================================
657 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
658 { if ( ViewerTest::CurrentView().IsNull() ) {
659 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
660 // VInit(di, argc, argv);
663 ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
668 //==============================================================================
670 //purpose : Switch to a Top View
672 //==============================================================================
674 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
677 if ( ViewerTest::CurrentView().IsNull() ) {
678 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
680 // VInit(di, , argv);
683 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
688 //==============================================================================
690 //purpose : Dsiplay help on viewer Keyboead and mouse commands
692 //==============================================================================
694 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
697 di << "Q : Quit the application" << "\n";
699 di << "========================="<<"\n";
700 di << "F : FitAll" << "\n";
701 di << "T : TopView" << "\n";
702 di << "A : AxonometricView" << "\n";
703 di << "R : ResetView" << "\n";
705 di << "========================="<<"\n";
706 di << "S : Shading" << "\n";
707 di << "W : Wireframe" << "\n";
708 di << "H : HidelLineRemoval" << "\n";
710 di << "========================="<<"\n";
711 di << "Selection mode "<<"\n";
712 di << "0 : Shape" <<"\n";
713 di << "1 : Vertex" <<"\n";
714 di << "2 : Edge" <<"\n";
715 di << "3 : Wire" <<"\n";
716 di << "4 : Face" <<"\n";
717 di << "5 : Shell" <<"\n";
718 di << "6 : Solid" <<"\n";
719 di << "7 : Compound" <<"\n";
721 di << "=========================="<<"\n";
722 di << "D : Remove Selected Object"<<"\n";
723 di << "=========================="<<"\n";
728 Standard_Boolean IsDragged = Standard_False;
730 Standard_Integer xx1, yy1, xx2, yy2;
731 //the first and last point in viewer co-ordinates
733 Standard_Boolean DragFirst;
738 static Standard_Boolean Ppick = 0;
739 static Standard_Integer Pargc = 0;
740 static const char** Pargv = NULL;
743 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
748 if ( !ViewerTest::CurrentView().IsNull() ) {
750 WPARAM fwKeys = wParam;
755 IsDragged = Standard_False;
758 HDC hdc = GetDC( hwnd );
759 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
760 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
761 SetROP2( hdc, R2_NOT );
762 Rectangle( hdc, xx1, yy1, xx2, yy2 );
763 ReleaseDC( hwnd, hdc );
765 const Handle(ViewerTest_EventManager) EM =
766 ViewerTest::CurrentEventManager();
767 if ( fwKeys & MK_SHIFT )
768 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
769 max( xx1, xx2 ), min( yy1, yy2 ));
771 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
772 max( xx1, xx2 ), min( yy1, yy2 ));
774 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
777 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
779 IsDragged = Standard_True;
780 DragFirst = Standard_True;
781 xx1 = LOWORD(lParam);
782 yy1 = HIWORD(lParam);
784 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
791 HDC hdc = GetDC( hwnd );
793 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
794 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
795 SetROP2( hdc, R2_NOT );
798 Rectangle( hdc, xx1, yy1, xx2, yy2 );
800 DragFirst = Standard_False;
801 xx2 = LOWORD(lParam);
802 yy2 = HIWORD(lParam);
804 Rectangle( hdc, xx1, yy1, xx2, yy2 );
806 SelectObject( hdc, anObj );
808 ReleaseDC( hwnd, hdc );
811 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
815 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
819 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
823 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
828 /*static Standard_Boolean Ppick = 0;
829 static Standard_Integer Pargc = 0;
830 static char** Pargv = NULL;*/
834 if ( !ViewerTest::CurrentView().IsNull() ) {
839 // do not destroy the window - just hide it!
840 VT_GetWindow()->Unmap();
843 //cout << "\t WM_PAINT" << endl;
844 BeginPaint(hwnd, &ps);
850 //cout << "\t WM_SIZE" << endl;
855 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
857 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
859 c[0] = (char) wParam;
868 //cout << "\t WM_xBUTTONUP" << endl;
870 ProcessButtonRelease();
877 //cout << "\t WM_xBUTTONDOWN" << endl;
878 WPARAM fwKeys = wParam;
882 X_ButtonPress = LOWORD(lParam);
883 Y_ButtonPress = HIWORD(lParam);
885 if ( Msg == WM_LBUTTONDOWN) {
886 if(fwKeys & MK_CONTROL) {
887 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
889 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
891 else if ( Msg == WM_RBUTTONDOWN ) {
893 ProcessButton3Press( );
900 //cout << "\t WM_MOUSEMOVE" << endl;
901 WPARAM fwKeys = wParam;
902 X_Motion = LOWORD(lParam);
903 Y_Motion = HIWORD(lParam);
906 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
908 X_ButtonPress = LOWORD(lParam);
909 Y_ButtonPress = HIWORD(lParam);
911 if ( fwKeys & MK_RBUTTON ) {
913 ProcessButton3Press();
917 if ( fwKeys & MK_CONTROL ) {
918 if ( fwKeys & MK_LBUTTON ) {
919 ProcessControlButton1Motion();
921 else if ( fwKeys & MK_MBUTTON ||
922 ((fwKeys&MK_LBUTTON) &&
923 (fwKeys&MK_RBUTTON) ) ){
924 ProcessControlButton2Motion();
926 else if ( fwKeys & MK_RBUTTON ) {
927 ProcessControlButton3Motion();
931 else if ( fwKeys & MK_SHIFT ) {
932 if ( fwKeys & MK_MBUTTON ||
933 ((fwKeys&MK_LBUTTON) &&
934 (fwKeys&MK_RBUTTON) ) ) {
935 cout << "ProcessZClipMotion()" << endl;
936 ProcessZClipMotion();
941 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
942 ProcessZClipMotion();
951 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
956 return DefWindowProc( hwnd, Msg, wParam, lParam );
962 //==============================================================================
963 //function : ViewerMainLoop
964 //purpose : Get a Event on the view and dispatch it
965 //==============================================================================
968 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
971 //cout << "No yet implemented on WNT" << endl;
972 /*static Standard_Boolean Ppick = 0;
973 static Standard_Integer Pargc = 0;
974 static char** Pargv = NULL;*/
976 //Ppick = (argc > 0)? -1 : 0;
977 Ppick = (argc > 0)? 1 : 0;
985 cout << "Start picking" << endl;
987 //while ( Ppick == -1 ) {
988 while ( Ppick == 1 ) {
989 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
990 if (GetMessage(&msg, NULL, 0, 0) ) {
991 TranslateMessage(&msg);
992 DispatchMessage(&msg);
996 cout << "Picking done" << endl;
1005 int min( int a, int b )
1013 int max( int a, int b )
1021 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1023 { Standard_Boolean pick = argc > 0;
1027 static XEvent report;
1029 XNextEvent( display, &report );
1030 // cout << "rep type = " << report.type << endl;
1031 // cout << "rep button = " << report.xbutton.button << endl;
1033 switch ( report.type ) {
1039 case ConfigureNotify:
1050 XComposeStatus status_in_out;
1052 ret_len = XLookupString( ( XKeyEvent *)&report ,
1053 (char *) buf_ret , 10 ,
1054 &ks_ret , &status_in_out ) ;
1057 buf_ret[ret_len] = '\0' ;
1060 ProcessKeyPress( buf_ret);
1065 // cout << "ButtonPress" << endl;
1067 X_ButtonPress = report.xbutton.x;
1068 Y_ButtonPress = report.xbutton.y;
1070 if ( report.xbutton.button == Button1 )
1071 if( report.xbutton.state & ControlMask )
1072 pick = ProcessButton1Press( argc, argv, pick,
1073 ( report.xbutton.state & ShiftMask) );
1076 IsDragged = Standard_True;
1077 xx1 = X_ButtonPress;
1078 yy1 = Y_ButtonPress;
1079 DragFirst = Standard_True;
1081 else if ( report.xbutton.button == Button3 )
1083 ProcessButton3Press();
1088 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1089 // cout << IsDragged << endl;
1090 // cout << DragFirst << endl;
1096 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1097 GC gc = XCreateGC( display, aWindow, 0, 0 );
1098 // XSetFunction( display, gc, GXinvert );
1099 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1102 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1103 if( aContext.IsNull() )
1105 cout << "The context is null. Please use vinit before createmesh" << endl;
1109 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1110 if( report.xbutton.button==1 )
1114 aContext->ShiftSelect();
1115 // cout << "shift select" << endl;
1120 // cout << "select" << endl;
1125 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1126 max( xx1, xx2 ), max( yy1, yy2 ),
1127 ViewerTest::CurrentView());
1128 // cout << "shift select" << endl;
1132 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1133 max( xx1, xx2 ), max( yy1, yy2 ),
1134 ViewerTest::CurrentView() );
1135 // cout << "select" << endl;
1138 ProcessButtonRelease();
1140 IsDragged = Standard_False;
1143 ProcessButtonRelease();
1150 X_Motion = report.xmotion.x;
1151 Y_Motion = report.xmotion.y;
1155 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1156 GC gc = XCreateGC( display, aWindow, 0, 0 );
1157 XSetFunction( display, gc, GXinvert );
1160 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1164 DragFirst = Standard_False;
1166 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1167 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1172 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1174 // remove all the ButtonMotionMask
1175 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1177 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1178 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1180 Quantity_Length VDX, VDY;
1182 ViewerTest::CurrentView()->Size(VDX,VDY);
1183 Standard_Real VDZ =0 ;
1184 VDZ = ViewerTest::CurrentView()->ZSize();
1186 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1187 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1189 Quantity_Length dx = 0 ;
1190 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1194 dx = dx / VDX * VDZ;
1198 // Front = Depth + width/2.
1199 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1200 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1202 ViewerTest::CurrentView()->Redraw();
1206 if ( report.xmotion.state & ControlMask ) {
1207 if ( report.xmotion.state & Button1Mask ) {
1208 ProcessControlButton1Motion();
1210 else if ( report.xmotion.state & Button2Mask ) {
1211 ProcessControlButton2Motion();
1213 else if ( report.xmotion.state & Button3Mask ) {
1214 ProcessControlButton3Motion();
1229 //==============================================================================
1230 //function : VProcessEvents
1231 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1232 // event in the Viewer window
1233 //==============================================================================
1235 static void VProcessEvents(ClientData,int)
1237 //cout << "VProcessEvents" << endl;
1240 while (XPending(display)) {
1241 ViewerMainLoop( 0, NULL);
1246 //==============================================================================
1247 //function : OSWindowSetup
1248 //purpose : Setup for the X11 window to be able to cath the event
1249 //==============================================================================
1252 static void OSWindowSetup()
1257 Window window = VT_GetWindow()->XWindow();
1259 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1260 display = (Display * ) theDisplay;
1261 // display = (Display *)GetG3dDevice()->XDisplay();
1263 XSynchronize(display, 1);
1265 VT_GetWindow()->Map();
1267 // X11 : For keyboard on SUN
1269 wmhints.flags = InputHint;
1272 XSetWMHints( display, window, &wmhints);
1274 XSelectInput( display, window, ExposureMask | KeyPressMask |
1275 ButtonPressMask | ButtonReleaseMask |
1276 StructureNotifyMask |
1278 Button1MotionMask | Button2MotionMask |
1282 XSynchronize(display, 0);
1291 //==============================================================================
1294 //purpose : Fitall, no DRAW arguments
1295 //Draw arg : No args
1296 //==============================================================================
1298 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1300 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1301 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1302 if (V.IsNull() == Standard_False) {
1304 } else if (aView.IsNull() == Standard_False) {
1310 //==============================================================================
1312 //purpose : ZFitall, no DRAW arguments
1313 //Draw arg : No args
1314 //==============================================================================
1316 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1318 Handle(V3d_View) V = ViewerTest::CurrentView();
1319 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1322 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1324 Handle(V3d_View) V = ViewerTest::CurrentView();
1325 if ( !V.IsNull() ) V->Redraw(); return 0;
1329 //==============================================================================
1331 //purpose : Remove all the object from the viewer
1332 //Draw arg : No args
1333 //==============================================================================
1335 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1337 Handle(V3d_View) V = ViewerTest::CurrentView();
1339 ViewerTest::Clear();
1343 //==============================================================================
1346 //==============================================================================
1348 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1349 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1352 di << argv[0] << "Invalid number of arguments" << "\n";
1356 while (ViewerMainLoop( argc, argv)) {
1364 //==============================================================================
1365 //function : InitViewerTest
1366 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1367 //==============================================================================
1369 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1371 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1372 ViewerTest::SetAISContext(context);
1373 viewer->InitActiveViews();
1374 Handle(V3d_View) view = viewer->ActiveView();
1375 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1376 ViewerTest::ResetEventManager();
1377 Handle(Aspect_GraphicDevice) device = viewer->Device();
1378 Handle(Aspect_Window) window = view->Window();
1381 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1382 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1384 static int first = 1;
1386 #if TCL_MAJOR_VERSION < 8
1387 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1388 TK_READABLE, VProcessEvents, (ClientData) 0);
1390 Tk_CreateFileHandler(ConnectionNumber(display),
1391 TK_READABLE, VProcessEvents, (ClientData) 0);
1399 //==============================================================================
1401 //purpose : Load image as background
1402 //==============================================================================
1404 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1406 if (argc < 2 || argc > 3)
1408 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1409 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1413 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1414 if(AISContext.IsNull())
1416 di << "use 'vinit' command before " << argv[0] << "\n";
1420 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1423 const char* szType = argv[2];
1424 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1425 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1426 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1427 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1430 di << "Wrong fill type : " << szType << "\n";
1431 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1436 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1437 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1442 //==============================================================================
1443 //function : VSetBgMode
1444 //purpose : Change background image fill type
1445 //==============================================================================
1447 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1451 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1452 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1456 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1457 if(AISContext.IsNull())
1459 di << "use 'vinit' command before " << argv[0] << "\n";
1463 Aspect_FillMethod aFillType;
1466 const char* szType = argv[1];
1467 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1468 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1469 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1470 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1473 di << "Wrong fill type : " << szType << "\n";
1474 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1479 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1480 V3dView->SetBgImageStyle(aFillType, Standard_True);
1485 //==============================================================================
1486 //function : VSetGradientBg
1487 //purpose : Mount gradient background
1488 //==============================================================================
1489 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1493 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1494 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1495 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1496 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1500 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1501 if(AISContext.IsNull())
1503 di << "use 'vinit' command before " << argv[0] << "\n";
1509 Standard_Real R1 = atof(argv[1])/255.;
1510 Standard_Real G1 = atof(argv[2])/255.;
1511 Standard_Real B1 = atof(argv[3])/255.;
1512 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1514 Standard_Real R2 = atof(argv[4])/255.;
1515 Standard_Real G2 = atof(argv[5])/255.;
1516 Standard_Real B2 = atof(argv[6])/255.;
1518 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1519 int aType = atoi(argv[7]);
1520 if( aType < 0 || aType > 8 )
1522 di << "Wrong fill type " << "\n";
1523 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1524 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1528 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1530 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1531 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1537 //==============================================================================
1538 //function : VSetGradientBgMode
1539 //purpose : Change gradient background fill style
1540 //==============================================================================
1541 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1545 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1546 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1547 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1551 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1552 if(AISContext.IsNull())
1554 di << "use 'vinit' command before " << argv[0] << "\n";
1559 int aType = atoi(argv[1]);
1560 if( aType < 0 || aType > 8 )
1562 di << "Wrong fill type " << "\n";
1563 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1564 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1568 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1570 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1571 V3dView->SetBgGradientStyle( aMethod, 1 );
1577 //==============================================================================
1578 //function : VSetColorBg
1579 //purpose : Set color background
1580 //==============================================================================
1581 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1585 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1586 di << "R,G,B = [0..255]" << "\n";
1590 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1591 if(AISContext.IsNull())
1593 di << "use 'vinit' command before " << argv[0] << "\n";
1599 Standard_Real R = atof(argv[1])/255.;
1600 Standard_Real G = atof(argv[2])/255.;
1601 Standard_Real B = atof(argv[3])/255.;
1602 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1604 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1605 V3dView->SetBackgroundColor( aColor );
1612 //==============================================================================
1614 //purpose : View Scaling
1615 //==============================================================================
1617 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1619 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1620 if ( V3dView.IsNull() ) return 1;
1623 di << argv[0] << "Invalid number of arguments" << "\n";
1626 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1629 //==============================================================================
1630 //function : VTestZBuffTrihedron
1631 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1632 //==============================================================================
1634 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1636 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1637 if ( V3dView.IsNull() ) return 1;
1639 V3dView->ZBufferTriedronSetup();
1642 // Set up default trihedron parameters
1643 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1647 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1648 const char* aPosType = argv[1];
1650 if ( strcmp(aPosType, "center") == 0 )
1652 aPosition = Aspect_TOTP_CENTER;
1654 if (strcmp(aPosType, "left_lower") == 0)
1656 aPosition = Aspect_TOTP_LEFT_LOWER;
1658 if (strcmp(aPosType, "left_upper") == 0)
1660 aPosition = Aspect_TOTP_LEFT_UPPER;
1662 if (strcmp(aPosType, "right_lower") == 0)
1664 aPosition = Aspect_TOTP_RIGHT_LOWER;
1666 if (strcmp(aPosType, "right_upper") == 0)
1668 aPosition = Aspect_TOTP_RIGHT_UPPER;
1671 di << argv[1] << " Invalid type of alignment" << "\n";
1672 di << "Must be one of [ center, left_lower," << "\n";
1673 di << "left_upper, right_lower, right_upper ]" << "\n";
1677 Standard_Real R = atof(argv[2])/255.;
1678 Standard_Real G = atof(argv[3])/255.;
1679 Standard_Real B = atof(argv[4])/255.;
1680 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1682 Standard_Real aScale = atof(argv[5]);
1686 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1690 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1691 const char* aPresType = argv[6];
1693 if ( strcmp(aPresType, "wireframe") == 0 )
1695 aPresentation = V3d_WIREFRAME;
1697 if (strcmp(aPresType, "zbuffer") == 0)
1699 aPresentation = V3d_ZBUFFER;
1702 di << argv[6] << " Invalid type of visualization" << "\n";
1703 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1707 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1711 di << argv[0] << " Invalid number of arguments" << "\n";
1720 //==============================================================================
1721 //function : VRotate
1722 //purpose : Camera Rotating
1723 //==============================================================================
1725 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1726 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1727 if ( V3dView.IsNull() ) {
1732 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1734 } else if ( argc == 7 ) {
1735 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1738 di << argv[0] << " Invalid number of arguments" << "\n";
1743 //==============================================================================
1745 //purpose : View zoom in / out (relative to current zoom)
1746 //==============================================================================
1748 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1749 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1750 if ( V3dView.IsNull() ) {
1755 Standard_Real coef = atof(argv[1]);
1756 if ( coef <= 0.0 ) {
1757 di << argv[1] << "Invalid value" << "\n";
1760 V3dView->SetZoom( atof(argv[1]) );
1763 di << argv[0] << " Invalid number of arguments" << "\n";
1768 //==============================================================================
1770 //purpose : View panning (in pixels)
1771 //==============================================================================
1773 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1774 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1775 if ( V3dView.IsNull() ) return 1;
1778 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1781 di << argv[0] << " Invalid number of arguments" << "\n";
1787 //==============================================================================
1788 //function : VExport
1789 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1790 //==============================================================================
1792 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1794 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1795 if (V3dView.IsNull())
1800 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1804 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1805 TCollection_AsciiString aFormatStr;
1807 TCollection_AsciiString aFileName (argv[1]);
1808 Standard_Integer aLen = aFileName.Length();
1812 aFormatStr = TCollection_AsciiString (argv[2]);
1816 if (aFileName.Value (aLen - 2) == '.')
1818 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1820 else if (aFileName.Value (aLen - 3) == '.')
1822 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1826 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1832 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1836 aFormatStr.UpperCase();
1837 if (aFormatStr == "PS")
1838 anExpFormat = Graphic3d_EF_PostScript;
1839 else if (aFormatStr == "EPS")
1840 anExpFormat = Graphic3d_EF_EnhPostScript;
1841 else if (aFormatStr == "TEX")
1842 anExpFormat = Graphic3d_EF_TEX;
1843 else if (aFormatStr == "PDF")
1844 anExpFormat = Graphic3d_EF_PDF;
1845 else if (aFormatStr == "SVG")
1846 anExpFormat = Graphic3d_EF_SVG;
1847 else if (aFormatStr == "PGF")
1848 anExpFormat = Graphic3d_EF_PGF;
1849 else if (aFormatStr == "EMF")
1850 anExpFormat = Graphic3d_EF_EMF;
1853 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1857 if (!V3dView->View()->Export (argv[1], anExpFormat))
1859 std::cout << "Export failed!\n";
1865 //==============================================================================
1866 //function : VColorScale
1867 //purpose : representation color scale
1868 //==============================================================================
1869 #include <V3d_ColorScale.hxx>
1871 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1873 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1875 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1879 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1880 if(aContext.IsNull()) {
1881 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1885 Standard_Real minRange = 0. , maxRange = 100. ;
1887 Standard_Integer numIntervals = 10 ;
1888 Standard_Real textHeight = 16. ;
1889 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1890 Standard_Real X = 0., Y = 0. ;
1896 minRange = atof( argv[1] );
1897 maxRange = atof( argv[2] );
1898 numIntervals = atoi( argv[3] );
1901 textHeight = atof( argv[4] );
1903 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1906 X = atof( argv[6] );
1907 Y = atof( argv[7] );
1910 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1911 if ( curView.IsNull( ) )
1913 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1914 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1915 if( ! aCS.IsNull( ) )
1917 aCS->SetPosition( X , Y );
1918 aCS->SetHeight( 0.95) ;
1919 aCS->SetTextHeight( textHeight );
1920 aCS->SetRange( minRange , maxRange );
1921 aCS->SetNumberOfIntervals( numIntervals );
1922 aCS->SetLabelPosition( position );
1923 if( !curView->ColorScaleIsDisplayed() )
1924 curView->ColorScaleDisplay( );
1929 //==============================================================================
1930 //function : VGraduatedTrihedron
1931 //purpose : Displays a graduated trihedron
1932 //==============================================================================
1934 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
1936 const char *str = arg;
1939 unsigned short c1 = *str++;
1940 unsigned short c2 = *str++;
1941 if (!c1 || !c2) break;
1942 name += (Standard_ExtCharacter)((c1 << 8) | c2);
1946 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1949 if (argc != 2 && argc < 5)
1951 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
1952 di<<"Usage: type help "<<argv[0]<<"\n";
1953 return 1; //TCL_ERROR
1956 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
1958 // Create 3D view if it doesn't exist
1959 if ( aV3dView.IsNull() )
1961 ViewerTest::ViewerInit();
1962 aV3dView = ViewerTest::CurrentView();
1963 if( aV3dView.IsNull() )
1965 di << "Error: Cannot create a 3D view\n";
1966 return 1; //TCL_ERROR
1970 // Erase (==0) or display (!=0)
1971 const int display = atoi(argv[1]);
1976 TCollection_AsciiString font;
1978 font.AssignCat("Courier");
1980 font.AssignCat(argv[5]);
1982 // Text is multibyte
1983 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
1986 TCollection_ExtendedString xname, yname, zname;
1991 AddMultibyteString(xname, argv[2]);
1992 AddMultibyteString(yname, argv[3]);
1993 AddMultibyteString(zname, argv[4]);
2009 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2010 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2011 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2012 Standard_True/*drawgrid*/,
2013 Standard_True/*drawaxes*/,
2014 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2015 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2016 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2017 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2018 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2019 Quantity_NOC_WHITE/*gridcolor*/,
2020 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2021 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2024 aV3dView->GraduatedTrihedronErase();
2026 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2032 //==============================================================================
2033 //function : VPrintView
2034 //purpose : Test printing algorithm, print the view to image file with given
2035 // width and height. Printing implemented only for WNT.
2036 //==============================================================================
2037 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2041 di << "Printing implemented only for wnt!\n";
2045 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2046 Handle(V3d_View) aView = NULL;
2047 aContextAIS = ViewerTest::GetAISContext();
2048 if (!aContextAIS.IsNull())
2050 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2051 Vwr->InitActiveViews();
2052 if(Vwr->MoreActiveViews())
2053 aView = Vwr->ActiveView();
2059 di << "Call vinit before!\n";
2064 di << "Use: " << argv[0];
2065 di << " width height filename [print algo=0]\n";
2066 di << "width, height of the intermediate buffer for operation\n";
2067 di << "algo : {0|1}\n";
2068 di << " 0 - stretch algorithm\n";
2069 di << " 1 - tile algorithm\n";
2070 di << "test printing algorithms into an intermediate buffer\n";
2071 di << "with saving output to an image file\n";
2075 // get the input params
2076 Standard_Integer aWidth = atoi (argv[1]);
2077 Standard_Integer aHeight = atoi (argv[2]);
2078 Standard_Integer aMode = 0;
2079 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2081 aMode = atoi (argv[4]);
2083 // check the input parameters
2084 if (aWidth <= 0 || aHeight <= 0)
2086 di << "Width and height must be positive values!\n";
2089 if (aMode != 0 && aMode != 1)
2092 Image_CRawBufferData aRawBuffer;
2093 HDC anDC = CreateCompatibleDC(0);
2095 // define compatible bitmap
2096 BITMAPINFO aBitmapData;
2097 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2098 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2099 aBitmapData.bmiHeader.biWidth = aWidth ;
2100 aBitmapData.bmiHeader.biHeight = aHeight;
2101 aBitmapData.bmiHeader.biPlanes = 1;
2102 aBitmapData.bmiHeader.biBitCount = 24;
2103 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2104 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2105 aBitmapData.bmiHeader.biClrUsed = 0;
2106 aBitmapData.bmiHeader.biClrImportant = 0;
2107 aBitmapData.bmiHeader.biCompression = BI_RGB;
2108 aBitmapData.bmiHeader.biSizeImage = 0;
2110 // Create Device Independent Bitmap
2111 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2112 &aRawBuffer.dataPtr, NULL, 0);
2113 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2115 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2116 if (aRawBuffer.dataPtr != 0)
2119 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2121 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2123 // succesfully printed into an intermediate buffer
2126 Handle(Image_PixMap) anImageBitmap =
2127 new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr,
2129 aWidth*3 + aWidth%4, 24, 0);
2130 isSaved = anImageBitmap->Dump(aFileName.ToCString());
2134 di << "Print operation failed due to printing errors or\n";
2135 di << "insufficient memory available\n";
2136 di << "Please, try to use smaller dimensions for this test\n";
2137 di << "command, as it allocates intermediate buffer for storing\n";
2138 di << "the result\n";
2143 di << "Can't allocate memory for intermediate buffer\n";
2144 di << "Please use smaller dimensions\n";
2149 SelectObject (anDC, anOldBitmap);
2150 DeleteObject (aMemoryBitmap);
2156 di << "Save to file operation failed. This operation may fail\n";
2157 di << "if you don't have enough available memory, then you can\n";
2158 di << "use smaller dimensions for the output file\n";
2167 //==============================================================================
2168 //function : VZLayer
2169 //purpose : Test z layer operations for v3d viewer
2170 //==============================================================================
2171 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2173 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2174 if (aContextAIS.IsNull())
2176 di << "Call vinit before!\n";
2181 di << "Use: vzlayer " << argv[0];
2182 di << " add/del/get [id]\n";
2183 di << " add - add new z layer to viewer and print its id\n";
2184 di << " del - del z layer by its id\n";
2185 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2186 di << "id - the layer identificator value defined when removing z layer\n";
2190 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2191 if (aViewer.IsNull())
2193 di << "No active viewer!\n";
2197 // perform operation
2198 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2201 Standard_Integer aNewId;
2202 if (!aViewer->AddZLayer (aNewId))
2204 di << "Impossible to add new z layer!\n";
2208 di << "New z layer added with index: " << aNewId << "\n";
2210 else if (anOp == "del")
2214 di << "Please also provide as argument id of z layer to remove\n";
2218 Standard_Integer aDelId = atoi (argv[2]);
2219 if (!aViewer->RemoveZLayer (aDelId))
2221 di << "Impossible to remove the z layer or invalid id!\n";
2225 di << "Z layer " << aDelId << " has been removed\n";
2227 else if (anOp == "get")
2229 TColStd_SequenceOfInteger anIds;
2230 aViewer->GetAllZLayers (anIds);
2231 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2233 di << anIds.Value (aSeqIdx) << " ";
2240 di << "Invalid operation, please use { add / del / get }\n";
2247 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2249 // this class provides a presentation of text item in v3d view under-/overlayer
2250 class V3d_TextItem : public Visual3d_LayerItem
2255 DEFINE_STANDARD_RTTI(V3d_TextItem)
2258 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2259 const Standard_Real theX1,
2260 const Standard_Real theY1,
2261 const Standard_Real theHeight,
2262 const TCollection_AsciiString& theFontName,
2263 const Quantity_Color& theColor,
2264 const Quantity_Color& theSubtitleColor,
2265 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2266 const Handle(Visual3d_Layer)& theLayer);
2269 Standard_EXPORT void RedrawLayerPrs();
2275 Standard_Real myHeight;
2276 TCollection_AsciiString myText;
2277 TCollection_AsciiString myFontName;
2278 Quantity_Color myColor;
2279 Quantity_Color mySubtitleColor;
2280 Aspect_TypeOfDisplayText myType;
2281 Handle(Visual3d_Layer) myLayer;
2285 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2286 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2288 // create and add to display the text item
2289 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2290 const Standard_Real theX1,
2291 const Standard_Real theY1,
2292 const Standard_Real theHeight,
2293 const TCollection_AsciiString& theFontName,
2294 const Quantity_Color& theColor,
2295 const Quantity_Color& theSubtitleColor,
2296 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2297 const Handle(Visual3d_Layer)& theLayer)
2298 : myX1 (theX1), myY1 (theY1),
2300 myHeight (theHeight),
2303 mySubtitleColor (theSubtitleColor),
2304 myType (theTypeOfDisplay),
2305 myFontName (theFontName)
2307 if (!myLayer.IsNull ())
2308 myLayer->AddLayerItem (this);
2312 void V3d_TextItem::RedrawLayerPrs ()
2314 if (myLayer.IsNull ())
2317 myLayer->SetColor (myColor);
2318 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2319 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2322 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2324 // The Visual3d_LayerItem line item for "vlayerline" command
2325 // it provides a presentation of line with user-defined
2326 // linewidth, linetype and transparency.
2327 class V3d_LineItem : public Visual3d_LayerItem
2331 DEFINE_STANDARD_RTTI(V3d_LineItem)
2334 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2335 Standard_Real X2, Standard_Real Y2,
2336 V3d_LayerMgrPointer theLayerMgr,
2337 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2338 Standard_Real theWidth = 0.5,
2339 Standard_Real theTransp = 1.0);
2342 Standard_EXPORT void RedrawLayerPrs();
2346 Standard_Real myX1, myY1, myX2, myY2;
2347 Standard_Real myWidth;
2348 Standard_Real myTransparency;
2349 Aspect_TypeOfLine myType;
2350 V3d_LayerMgrPointer myLayerMgr;
2353 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2354 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2356 // default constructor for line item
2357 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2358 Standard_Real X2, Standard_Real Y2,
2359 V3d_LayerMgrPointer theLayerMgr,
2360 Aspect_TypeOfLine theType,
2361 Standard_Real theWidth,
2362 Standard_Real theTransp) :
2363 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2364 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2366 if (myLayerMgr && myLayerMgr->Overlay())
2367 myLayerMgr->Overlay()->AddLayerItem (this);
2371 void V3d_LineItem::RedrawLayerPrs ()
2373 Handle (Visual3d_Layer) aOverlay;
2376 aOverlay = myLayerMgr->Overlay();
2378 if (!aOverlay.IsNull())
2380 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2381 aOverlay->SetColor(aColor);
2382 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2383 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2384 aOverlay->BeginPolyline();
2385 aOverlay->AddVertex(myX1, myY1);
2386 aOverlay->AddVertex(myX2, myY2);
2387 aOverlay->ClosePrimitive();
2391 //=============================================================================
2392 //function : VLayerLine
2393 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2394 // : linewidth, transparency coefficient
2395 //============================================================================
2396 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2398 // get the active view
2399 Handle(V3d_View) aView = ViewerTest::CurrentView();
2402 di << "Call vinit before!\n";
2407 di << "Use: " << argv[0];
2408 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2409 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2410 di << " 0 - solid \n";
2411 di << " 1 - dashed \n";
2412 di << " 2 - dot \n";
2413 di << " 3 - dashdot\n";
2414 di << " transparency : { 0.0 - 1.0 } \n";
2415 di << " 0.0 - transparent\n";
2416 di << " 1.0 - visible \n";
2420 // get the input params
2421 Standard_Real X1 = atof(argv[1]);
2422 Standard_Real Y1 = atof(argv[2]);
2423 Standard_Real X2 = atof(argv[3]);
2424 Standard_Real Y2 = atof(argv[4]);
2426 Standard_Real aWidth = 0.5;
2427 Standard_Integer aType = 0;
2428 Standard_Real aTransparency = 1.0;
2432 aWidth = atof(argv[5]);
2436 aType = (Standard_Integer) atoi(argv[6]);
2441 aTransparency = atof(argv[7]);
2442 if (aTransparency < 0 || aTransparency > 1.0)
2443 aTransparency = 1.0;
2446 // select appropriate line type
2447 Aspect_TypeOfLine aLineType;
2451 aLineType = Aspect_TOL_DASH;
2455 aLineType = Aspect_TOL_DOT;
2459 aLineType = Aspect_TOL_DOTDASH;
2463 aLineType = Aspect_TOL_SOLID;
2466 // replace layer manager
2467 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2468 aView->SetLayerMgr(aMgr);
2471 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2477 aView->MustBeResized();
2483 //=======================================================================
2484 //function : VOverlayText
2485 //purpose : Test text displaying in view overlay
2486 //=======================================================================
2487 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2489 // get the active view
2490 Handle(V3d_View) aView = ViewerTest::CurrentView();
2493 di << "No active view. Please call vinit.\n";
2496 else if (argc < 4 || argc > 13)
2498 di << "Use: " << argv[0];
2499 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2500 di << "[background_color: R G B]\n";
2501 di << " height - pixel height of the text (default=10.0)\n";
2502 di << " font_name - name of font (default=courier)\n";
2503 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2504 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2505 di << " background_color- R G B values used for subtitle and decal text\n";
2506 di << "(default=255.0 255.0 255.0)\n";
2510 TCollection_AsciiString aText (argv[1]);
2511 Standard_Real aPosX = atof(argv[2]);
2512 Standard_Real aPosY = atof(argv[3]);
2513 Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
2516 TCollection_AsciiString aFontName = "Courier";
2518 aFontName = TCollection_AsciiString (argv[5]);
2521 Quantity_Parameter aColorRed = 1.0;
2522 Quantity_Parameter aColorGreen = 1.0;
2523 Quantity_Parameter aColorBlue = 1.0;
2526 aColorRed = atof (argv[6])/255.;
2527 aColorGreen = atof (argv[7])/255.;
2528 aColorBlue = atof (argv[8])/255.;
2532 TCollection_AsciiString aDispStr;
2534 aDispStr = TCollection_AsciiString (argv[9]);
2536 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2537 if (aDispStr.IsEqual ("subtitle"))
2538 aTextType = Aspect_TODT_SUBTITLE;
2539 else if (aDispStr.IsEqual ("decal"))
2540 aTextType = Aspect_TODT_DEKALE;
2541 else if (aDispStr.IsEqual ("blend"))
2542 aTextType = Aspect_TODT_BLEND;
2545 Quantity_Parameter aSubRed = 1.0;
2546 Quantity_Parameter aSubGreen = 1.0;
2547 Quantity_Parameter aSubBlue = 1.0;
2550 aSubRed = atof (argv[10])/255.;
2551 aSubGreen = atof (argv[11])/255.;
2552 aSubBlue = atof (argv[12])/255.;
2555 // check fo current overlay
2556 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2557 if (anOverlay.IsNull ())
2559 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2560 anOverlay = aMgr->Overlay ();
2561 aView->SetLayerMgr (aMgr);
2564 Quantity_Color aTextColor (aColorRed, aColorGreen,
2565 aColorBlue, Quantity_TOC_RGB);
2566 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2567 aSubBlue, Quantity_TOC_RGB);
2570 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2571 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2574 aView->MustBeResized();
2580 //==============================================================================
2583 //==============================================================================
2585 static int VGrid (Draw_Interpretor& theDI,
2586 Standard_Integer theArgNb,
2587 const char** theArgVec)
2589 // get the active view
2590 Handle(V3d_View) aView = ViewerTest::CurrentView();
2591 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2592 if (aView.IsNull() || aViewer.IsNull())
2594 std::cerr << "No active view. Please call vinit.\n";
2598 Aspect_GridType aType = aViewer->GridType();
2599 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2601 Standard_Integer anIter = 1;
2602 for (; anIter < theArgNb; ++anIter)
2604 const char* aValue = theArgVec[anIter];
2607 aType = Aspect_GT_Rectangular;
2609 else if (*aValue == 'c')
2611 aType = Aspect_GT_Circular;
2613 else if (*aValue == 'l')
2615 aMode = Aspect_GDM_Lines;
2617 else if (*aValue == 'p')
2619 aMode = Aspect_GDM_Points;
2621 else if (strcmp (aValue, "off" ) == 0)
2623 aViewer->DeactivateGrid();
2632 Standard_Integer aTail = (theArgNb - anIter);
2635 aViewer->ActivateGrid (aType, aMode);
2638 else if (aTail != 2 && aTail != 5)
2640 std::cerr << "Incorrect arguments number! Usage:\n"
2641 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2645 Quantity_Length anOriginX, anOriginY;
2646 Quantity_PlaneAngle aRotAngle;
2647 if (aType == Aspect_GT_Rectangular)
2649 Quantity_Length aRStepX, aRStepY;
2650 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2652 anOriginX = atof (theArgVec[anIter++]);
2653 anOriginY = atof (theArgVec[anIter++]);
2656 aRStepX = atof (theArgVec[anIter++]);
2657 aRStepY = atof (theArgVec[anIter++]);
2658 aRotAngle = atof (theArgVec[anIter++]);
2660 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2661 aViewer->ActivateGrid (aType, aMode);
2663 else if (aType == Aspect_GT_Circular)
2665 Quantity_Length aRadiusStep;
2666 Standard_Integer aDivisionNumber;
2667 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2669 anOriginX = atof (theArgVec[anIter++]);
2670 anOriginY = atof (theArgVec[anIter++]);
2673 aRadiusStep = atof (theArgVec[anIter++]);
2674 aDivisionNumber = atof (theArgVec[anIter++]);
2675 aRotAngle = atof (theArgVec[anIter++]);
2678 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2679 aViewer->ActivateGrid (aType, aMode);
2685 //=======================================================================
2686 //function : ViewerCommands
2688 //=======================================================================
2690 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
2693 const char *group = "ZeViewer";
2694 theCommands.Add("vinit" ,
2695 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
2696 __FILE__,VInit,group);
2697 theCommands.Add("vhelp" ,
2698 "vhelp : display help on the viewer commands",
2699 __FILE__,VHelp,group);
2700 theCommands.Add("vtop" ,
2701 "vtop or <T> : Top view" ,
2702 __FILE__,VTop,group);
2703 theCommands.Add("vaxo" ,
2704 " vaxo or <A> : Axonometric view ",
2705 __FILE__,VAxo,group);
2706 theCommands.Add("vpick" ,
2707 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
2709 theCommands.Add("vfit" ,
2710 "vfit or <F> : vfit",
2711 __FILE__,VFit,group);
2712 theCommands.Add("vzfit" ,
2714 __FILE__,VZFit,group);
2715 theCommands.Add("vrepaint",
2716 "vrepaint : vrepaint, force redraw",
2717 __FILE__,VRepaint,group);
2718 theCommands.Add("vclear",
2720 __FILE__,VClear,group);
2721 theCommands.Add("vsetbg",
2722 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
2723 __FILE__,VSetBg,group);
2724 theCommands.Add("vsetbgmode",
2725 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
2726 __FILE__,VSetBgMode,group);
2727 theCommands.Add("vsetgradientbg",
2728 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
2729 __FILE__,VSetGradientBg,group);
2730 theCommands.Add("vsetgrbgmode",
2731 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
2732 __FILE__,VSetGradientBgMode,group);
2733 theCommands.Add("vsetcolorbg",
2734 "vsetcolorbg : vsetcolorbg r g b : Set background color",
2735 __FILE__,VSetColorBg,group);
2736 theCommands.Add("vscale",
2737 "vscale : vscale X Y Z",
2738 __FILE__,VScale,group);
2739 theCommands.Add("vzbufftrihedron",
2740 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
2741 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
2742 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
2743 __FILE__,VTestZBuffTrihedron,group);
2744 theCommands.Add("vrotate",
2745 "vrotate : vrotate AX AY AZ [X Y Z]",
2746 __FILE__,VRotate,group);
2747 theCommands.Add("vzoom",
2748 "vzoom : vzoom coef",
2749 __FILE__,VZoom,group);
2750 theCommands.Add("vpan",
2751 "vpan : vpan dx dy",
2752 __FILE__,VPan,group);
2753 theCommands.Add("vexport",
2754 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
2755 " : exports the view to a vector file of a given format"
2756 " : notice that EMF format requires patched gl2ps",
2757 __FILE__,VExport,group);
2758 theCommands.Add("vcolorscale",
2759 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
2760 __FILE__,VColorScale,group);
2761 theCommands.Add("vgraduatedtrihedron",
2762 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
2763 __FILE__,VGraduatedTrihedron,group);
2764 theCommands.Add("vprintview" ,
2765 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
2766 __FILE__,VPrintView,group);
2767 theCommands.Add("vzlayer",
2768 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
2769 __FILE__,VZLayer,group);
2770 theCommands.Add("voverlaytext",
2771 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
2772 " : height - pixel height of the text (default=10.0)"
2773 " : font_name - name of font (default=courier)"
2774 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
2775 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
2776 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
2777 __FILE__,VOverlayText,group);
2778 theCommands.Add("vlayerline",
2779 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
2780 __FILE__,VLayerLine,group);
2781 theCommands.Add ("vgrid",
2782 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
2783 " : Mode - rectangular or circular"
2784 " : Type - lines or points",
2785 __FILE__, VGrid, group);