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_ExportFormat.hxx>
33 #include <ViewerTest.hxx>
34 #include <ViewerTest_EventManager.hxx>
35 #include <Visual3d_View.hxx>
36 #include <Visual3d_ViewManager.hxx>
37 #include <V3d_LayerMgr.hxx>
38 #include <NIS_View.hxx>
39 #include <NIS_Triangulated.hxx>
40 #include <NIS_InteractiveContext.hxx>
41 #include <AIS_InteractiveContext.hxx>
42 #include <Draw_Interpretor.hxx>
44 #include <Draw_Appli.hxx>
45 #include <Aspect_PrintAlgo.hxx>
46 #include <Image_PixMap.hxx>
47 #include <TColStd_SequenceOfInteger.hxx>
48 #include <Visual3d_LayerItem.hxx>
49 #include <V3d_LayerMgr.hxx>
50 #include <V3d_LayerMgrPointer.hxx>
51 #include <Aspect_TypeOfLine.hxx>
57 #include <Visual3d_Layer.hxx>
60 #include <Graphic3d_GraphicDevice.hxx>
61 #include <Xw_GraphicDevice.hxx>
62 #include <Xw_WindowQuality.hxx>
63 #include <Xw_Window.hxx>
64 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
65 #include <X11/Xutil.h>
70 #include <Graphic3d_WNTGraphicDevice.hxx>
71 #include <WNT_WClass.hxx>
72 #include <WNT_Window.hxx>
74 #define _CRT_SECURE_NO_DEPRECATE
75 #pragma warning (disable:4996)
81 //==============================================================================
83 //==============================================================================
84 // VIEWER GLOBAL VARIABLES
85 //==============================================================================
87 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
89 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
90 extern const Handle(NIS_InteractiveContext)& TheNISContext();
93 static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
94 static Handle(Graphic3d_WNTGraphicDevice) GD;
98 static Handle(WNT_Window)& VT_GetWindow() {
99 static Handle(WNT_Window) WNTWin;
104 static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
105 static Handle(Graphic3d_GraphicDevice) GD;
108 static Handle(Xw_Window)& VT_GetWindow(){
109 static Handle(Xw_Window) XWWin;
112 static Display *display;
114 static void VProcessEvents(ClientData,int);
118 static Standard_Boolean DegenerateMode = Standard_True;
121 #define ZCLIPWIDTH 1.
123 static void OSWindowSetup();
125 //==============================================================================
126 // EVENT GLOBAL VARIABLES
127 //==============================================================================
129 static int Start_Rot = 0;
130 static int ZClipIsOn = 0;
131 static int X_Motion= 0,Y_Motion=0; // Current cursor position
132 static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
135 //==============================================================================
138 static LRESULT WINAPI ViewerWindowProc(
143 static LRESULT WINAPI AdvViewerWindowProc(
151 //==============================================================================
154 //==============================================================================
156 const Handle(MMgt_TShared)& ViewerTest::WClass()
158 static Handle(MMgt_TShared) theWClass;
160 if (theWClass.IsNull()) {
161 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
162 CS_VREDRAW | CS_HREDRAW, 0, 0,
163 ::LoadCursor (NULL, IDC_ARROW));
169 //==============================================================================
170 //function : ViewerInit
171 //purpose : Create the window viewer and initialize all the global variable
172 //==============================================================================
174 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
175 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
177 static Standard_Boolean isFirst = Standard_True;
179 Standard_Integer aPxLeft = 0;
180 Standard_Integer aPxTop = 460;
181 Standard_Integer aPxWidth = 409;
182 Standard_Integer aPxHeight = 409;
183 if (thePxWidth != 0 && thePxHeight != 0)
187 aPxWidth = thePxWidth;
188 aPxHeight = thePxHeight;
193 // Create the Graphic device
195 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
196 if (VT_GetWindow().IsNull())
198 // Create the Graphic device and the window
199 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
201 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
202 Handle(WNT_WClass)::DownCast (WClass()),
207 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
210 if (GetG3dDevice().IsNull()) GetG3dDevice() =
211 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
212 if (VT_GetWindow().IsNull())
214 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
220 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
224 Handle(V3d_Viewer) a3DViewer, a3DCollector;
225 // Viewer and View creation
227 TCollection_ExtendedString NameOfWindow("Visu3D");
229 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
230 NameOfWindow = TCollection_ExtendedString("Collector");
231 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
232 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
233 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
234 Handle(NIS_View) aView =
235 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
236 if ( aView.IsNull() ) {
237 // Handle (V3d_View) V = a3DViewer->CreateView();
238 aView = new NIS_View (a3DViewer, VT_GetWindow());
239 ViewerTest::CurrentView(aView);
240 TheNISContext()->AttachView (aView);
242 Handle(V3d_View) a3DViewCol;
243 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
246 if ( ViewerTest::GetAISContext().IsNull() ) {
247 Handle(AIS_InteractiveContext) C =
248 new AIS_InteractiveContext(a3DViewer,a3DCollector);
249 ViewerTest::SetAISContext(C);
252 // Setup for X11 or NT
254 // Viewer and View creation
256 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
258 Handle (V3d_View) V = ViewerTest::CurrentView();
260 V->SetDegenerateModeOn();
262 DegenerateMode = V->DegenerateModeIsOn();
264 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
266 V->SetZClippingDepth(0.5);
267 V->SetZClippingWidth(ZCLIPWIDTH/2.);
268 a3DViewer->SetDefaultLights();
269 a3DViewer->SetLightOn();
272 #if TCL_MAJOR_VERSION < 8
273 Tk_CreateFileHandler((void*)ConnectionNumber(display),
274 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
276 Tk_CreateFileHandler(ConnectionNumber(display),
277 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
281 isFirst = Standard_False;
283 VT_GetWindow()->Map();
286 //==============================================================================
288 //purpose : Create the window viewer and initialize all the global variable
289 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
290 //==============================================================================
292 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
294 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
295 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
296 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
297 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
298 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
302 //==============================================================================
303 //function : ProcessKeyPress
304 //purpose : Handle KeyPress event from a CString
305 //==============================================================================
307 static void ProcessKeyPress( char *buf_ret )
309 //cout << "KeyPress" << endl;
310 const Handle(V3d_View) aView = ViewerTest::CurrentView();
311 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
312 // Letter in alphabetic order
314 if ( !strcasecmp(buf_ret, "A") ) {
316 aView->SetProj(V3d_XposYnegZpos);
318 else if ( !strcasecmp(buf_ret, "D") ) {
322 else if ( !strcasecmp(buf_ret, "F") ) {
324 if (aNisView.IsNull())
327 aNisView->FitAll3d();
329 else if ( !strcasecmp(buf_ret, "H") ) {
331 cout << "HLR" << endl;
333 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
334 else aView->SetDegenerateModeOn();
335 DegenerateMode = aView->DegenerateModeIsOn();
337 ViewerTest::CurrentView()->SetDegenerateModeOff();
340 else if ( !strcasecmp(buf_ret, "D") ) {
344 else if ( !strcasecmp(buf_ret, "S") ) {
346 cout << "passage en mode 1 (shading pour les shapes)" << endl;
348 ViewerTest::CurrentView()->SetDegenerateModeOn();
350 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
351 if(Ctx->NbCurrents()==0 ||
352 Ctx->NbSelected()==0)
353 Ctx->SetDisplayMode(AIS_Shaded);
355 if(Ctx->HasOpenedContext()){
356 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
357 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
360 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
361 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
363 Ctx->UpdateCurrentViewer();
366 else if ( !strcasecmp(buf_ret, "U") ) {
368 cout<<"passage au mode par defaut"<<endl;
370 ViewerTest::CurrentView()->SetDegenerateModeOn();
372 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
373 if(Ctx->NbCurrents()==0 ||
374 Ctx->NbSelected()==0)
375 Ctx->SetDisplayMode(AIS_WireFrame);
377 if(Ctx->HasOpenedContext()){
378 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
379 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
382 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
383 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
385 Ctx->UpdateCurrentViewer();
389 else if ( !strcasecmp(buf_ret, "T") ) {
391 aView->SetProj(V3d_Zpos);
393 else if ( !strcasecmp(buf_ret, "B") ) {
395 aView->SetProj(V3d_Zneg);
397 else if ( !strcasecmp(buf_ret, "L") ) {
399 aView->SetProj(V3d_Xneg);
401 else if ( !strcasecmp(buf_ret, "R") ) {
403 aView->SetProj(V3d_Xpos);
406 else if ( !strcasecmp(buf_ret, "W") ) {
409 ViewerTest::CurrentView()->SetDegenerateModeOn();
411 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
413 ViewerTest::CurrentView()->SetDegenerateModeOn();
415 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
416 if(Ctx->NbCurrents()==0 ||
417 Ctx->NbSelected()==0)
418 Ctx->SetDisplayMode(AIS_WireFrame);
420 if(Ctx->HasOpenedContext()){
421 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
422 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
425 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
426 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
428 Ctx->UpdateCurrentViewer();
431 else if ( !strcasecmp(buf_ret, "Z") ) {
435 cout << "ZClipping OFF" << endl;
438 aView->SetZClippingType(V3d_OFF);
442 cout << "ZClipping ON" << endl;
445 aView->SetZClippingType(V3d_FRONT);
449 else if ( !strcasecmp(buf_ret, ",") ) {
450 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
454 else if ( !strcasecmp(buf_ret, ".") ) {
455 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
459 Standard_Integer Num = atoi(buf_ret);
461 ViewerTest::StandardModeActivation(Num);
465 //==============================================================================
466 //function : ProcessExpose
467 //purpose : Redraw the View on an Expose Event
468 //==============================================================================
470 static void ProcessExpose( )
471 { //cout << "Expose" << endl;
472 ViewerTest::CurrentView()->Redraw();
475 //==============================================================================
476 //function : ProcessConfigure
477 //purpose : Resize the View on an Configure Event
478 //==============================================================================
480 static void ProcessConfigure()
482 Handle(V3d_View) V = ViewerTest::CurrentView();
488 //==============================================================================
489 //function : ProcessButton1Press
491 //==============================================================================
493 static Standard_Boolean ProcessButton1Press(
496 Standard_Boolean pick,
497 Standard_Boolean shift )
499 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
501 Standard_Real X, Y, Z;
503 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
505 Draw::Set(argv[1], X);
506 Draw::Set(argv[2], Y);
507 Draw::Set(argv[3], Z);}
518 //==============================================================================
519 //function : ProcessButton3Press
520 //purpose : Start Rotation
521 //==============================================================================
523 static void ProcessButton3Press()
527 ViewerTest::CurrentView()->SetDegenerateModeOn();
528 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
531 //==============================================================================
532 //function : ProcessButtonRelease
533 //purpose : Start Rotation
534 //==============================================================================
536 static void ProcessButtonRelease()
542 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
546 ViewerTest::CurrentView()->SetDegenerateModeOff();
550 //==============================================================================
551 //function : ProcessZClipMotion
553 //==============================================================================
555 void ProcessZClipMotion()
557 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
558 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
559 static Standard_Real CurZPos = 0.;
561 //Quantity_Length VDX, VDY;
562 //a3DView->Size(VDX,VDY);
563 //Standard_Real VDZ = a3DView->ZSize();
564 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
566 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
568 // Front = Depth + width/2.
569 Standard_Real D = 0.5;
570 Standard_Real W = 0.1;
576 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
578 a3DView->SetZClippingType(V3d_OFF);
579 a3DView->SetZClippingDepth(D);
580 a3DView->SetZClippingWidth(W);
581 a3DView->SetZClippingType(V3d_FRONT);
585 X_ButtonPress = X_Motion;
586 Y_ButtonPress = Y_Motion;
590 //==============================================================================
591 //function : ProcessControlButton1Motion
593 //==============================================================================
595 static void ProcessControlButton1Motion()
597 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
599 X_ButtonPress = X_Motion;
600 Y_ButtonPress = Y_Motion;
603 //==============================================================================
604 //function : ProcessControlButton2Motion
606 //==============================================================================
608 static void ProcessControlButton2Motion()
610 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
611 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
613 dy = -dy; // Xwindow Y axis is from top to Bottom
615 ViewerTest::CurrentView()->Panning( dx, dy );
617 X_ButtonPress = X_Motion;
618 Y_ButtonPress = Y_Motion;
621 //==============================================================================
622 //function : ProcessControlButton3Motion
624 //==============================================================================
626 static void ProcessControlButton3Motion()
628 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
631 //==============================================================================
632 //function : ProcessPointerMotion
634 //==============================================================================
636 static void ProcessMotion()
638 //pre-hilights detected objects at mouse position
640 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
641 EM->MoveTo(X_Motion, Y_Motion);
645 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
647 Xpix = X_Motion;Ypix=Y_Motion;
650 //==============================================================================
652 //purpose : Switch to an Axonometric view
654 //==============================================================================
656 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
657 { if ( ViewerTest::CurrentView().IsNull() ) {
658 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
659 // VInit(di, argc, argv);
662 ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
667 //==============================================================================
669 //purpose : Switch to a Top View
671 //==============================================================================
673 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
676 if ( ViewerTest::CurrentView().IsNull() ) {
677 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
679 // VInit(di, , argv);
682 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
687 //==============================================================================
689 //purpose : Dsiplay help on viewer Keyboead and mouse commands
691 //==============================================================================
693 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
696 di << "Q : Quit the application" << "\n";
698 di << "========================="<<"\n";
699 di << "F : FitAll" << "\n";
700 di << "T : TopView" << "\n";
701 di << "A : AxonometricView" << "\n";
702 di << "R : ResetView" << "\n";
704 di << "========================="<<"\n";
705 di << "S : Shading" << "\n";
706 di << "W : Wireframe" << "\n";
707 di << "H : HidelLineRemoval" << "\n";
709 di << "========================="<<"\n";
710 di << "Selection mode "<<"\n";
711 di << "0 : Shape" <<"\n";
712 di << "1 : Vertex" <<"\n";
713 di << "2 : Edge" <<"\n";
714 di << "3 : Wire" <<"\n";
715 di << "4 : Face" <<"\n";
716 di << "5 : Shell" <<"\n";
717 di << "6 : Solid" <<"\n";
718 di << "7 : Compound" <<"\n";
720 di << "=========================="<<"\n";
721 di << "D : Remove Selected Object"<<"\n";
722 di << "=========================="<<"\n";
727 Standard_Boolean IsDragged = Standard_False;
729 Standard_Integer xx1, yy1, xx2, yy2;
730 //the first and last point in viewer co-ordinates
732 Standard_Boolean DragFirst;
737 static Standard_Boolean Ppick = 0;
738 static Standard_Integer Pargc = 0;
739 static const char** Pargv = NULL;
742 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
747 if ( !ViewerTest::CurrentView().IsNull() ) {
749 WPARAM fwKeys = wParam;
754 IsDragged = Standard_False;
757 HDC hdc = GetDC( hwnd );
758 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
759 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
760 SetROP2( hdc, R2_NOT );
761 Rectangle( hdc, xx1, yy1, xx2, yy2 );
762 ReleaseDC( hwnd, hdc );
764 const Handle(ViewerTest_EventManager) EM =
765 ViewerTest::CurrentEventManager();
766 if ( fwKeys & MK_SHIFT )
767 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
768 max( xx1, xx2 ), min( yy1, yy2 ));
770 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
771 max( xx1, xx2 ), min( yy1, yy2 ));
773 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
776 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
778 IsDragged = Standard_True;
779 DragFirst = Standard_True;
780 xx1 = LOWORD(lParam);
781 yy1 = HIWORD(lParam);
783 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
790 HDC hdc = GetDC( hwnd );
792 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
793 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
794 SetROP2( hdc, R2_NOT );
797 Rectangle( hdc, xx1, yy1, xx2, yy2 );
799 DragFirst = Standard_False;
800 xx2 = LOWORD(lParam);
801 yy2 = HIWORD(lParam);
803 Rectangle( hdc, xx1, yy1, xx2, yy2 );
805 SelectObject( hdc, anObj );
807 ReleaseDC( hwnd, hdc );
810 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
814 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
818 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
822 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
827 /*static Standard_Boolean Ppick = 0;
828 static Standard_Integer Pargc = 0;
829 static char** Pargv = NULL;*/
833 if ( !ViewerTest::CurrentView().IsNull() ) {
838 // do not destroy the window - just hide it!
839 VT_GetWindow()->Unmap();
842 //cout << "\t WM_PAINT" << endl;
843 BeginPaint(hwnd, &ps);
849 //cout << "\t WM_SIZE" << endl;
854 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
856 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
858 c[0] = (char) wParam;
867 //cout << "\t WM_xBUTTONUP" << endl;
869 ProcessButtonRelease();
876 //cout << "\t WM_xBUTTONDOWN" << endl;
877 WPARAM fwKeys = wParam;
881 X_ButtonPress = LOWORD(lParam);
882 Y_ButtonPress = HIWORD(lParam);
884 if ( Msg == WM_LBUTTONDOWN) {
885 if(fwKeys & MK_CONTROL) {
886 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
888 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
890 else if ( Msg == WM_RBUTTONDOWN ) {
892 ProcessButton3Press( );
899 //cout << "\t WM_MOUSEMOVE" << endl;
900 WPARAM fwKeys = wParam;
901 X_Motion = LOWORD(lParam);
902 Y_Motion = HIWORD(lParam);
905 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
907 X_ButtonPress = LOWORD(lParam);
908 Y_ButtonPress = HIWORD(lParam);
910 if ( fwKeys & MK_RBUTTON ) {
912 ProcessButton3Press();
916 if ( fwKeys & MK_CONTROL ) {
917 if ( fwKeys & MK_LBUTTON ) {
918 ProcessControlButton1Motion();
920 else if ( fwKeys & MK_MBUTTON ||
921 ((fwKeys&MK_LBUTTON) &&
922 (fwKeys&MK_RBUTTON) ) ){
923 ProcessControlButton2Motion();
925 else if ( fwKeys & MK_RBUTTON ) {
926 ProcessControlButton3Motion();
930 else if ( fwKeys & MK_SHIFT ) {
931 if ( fwKeys & MK_MBUTTON ||
932 ((fwKeys&MK_LBUTTON) &&
933 (fwKeys&MK_RBUTTON) ) ) {
934 cout << "ProcessZClipMotion()" << endl;
935 ProcessZClipMotion();
940 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
941 ProcessZClipMotion();
950 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
955 return DefWindowProc( hwnd, Msg, wParam, lParam );
961 //==============================================================================
962 //function : ViewerMainLoop
963 //purpose : Get a Event on the view and dispatch it
964 //==============================================================================
967 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
970 //cout << "No yet implemented on WNT" << endl;
971 /*static Standard_Boolean Ppick = 0;
972 static Standard_Integer Pargc = 0;
973 static char** Pargv = NULL;*/
975 //Ppick = (argc > 0)? -1 : 0;
976 Ppick = (argc > 0)? 1 : 0;
984 cout << "Start picking" << endl;
986 //while ( Ppick == -1 ) {
987 while ( Ppick == 1 ) {
988 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
989 if (GetMessage(&msg, NULL, 0, 0) ) {
990 TranslateMessage(&msg);
991 DispatchMessage(&msg);
995 cout << "Picking done" << endl;
1004 int min( int a, int b )
1012 int max( int a, int b )
1020 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1022 { Standard_Boolean pick = argc > 0;
1026 static XEvent report;
1028 XNextEvent( display, &report );
1029 // cout << "rep type = " << report.type << endl;
1030 // cout << "rep button = " << report.xbutton.button << endl;
1032 switch ( report.type ) {
1038 case ConfigureNotify:
1049 XComposeStatus status_in_out;
1051 ret_len = XLookupString( ( XKeyEvent *)&report ,
1052 (char *) buf_ret , 10 ,
1053 &ks_ret , &status_in_out ) ;
1056 buf_ret[ret_len] = '\0' ;
1059 ProcessKeyPress( buf_ret);
1064 // cout << "ButtonPress" << endl;
1066 X_ButtonPress = report.xbutton.x;
1067 Y_ButtonPress = report.xbutton.y;
1069 if ( report.xbutton.button == Button1 )
1070 if( report.xbutton.state & ControlMask )
1071 pick = ProcessButton1Press( argc, argv, pick,
1072 ( report.xbutton.state & ShiftMask) );
1075 IsDragged = Standard_True;
1076 xx1 = X_ButtonPress;
1077 yy1 = Y_ButtonPress;
1078 DragFirst = Standard_True;
1080 else if ( report.xbutton.button == Button3 )
1082 ProcessButton3Press();
1087 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1088 // cout << IsDragged << endl;
1089 // cout << DragFirst << endl;
1095 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1096 GC gc = XCreateGC( display, aWindow, 0, 0 );
1097 // XSetFunction( display, gc, GXinvert );
1098 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1101 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1102 if( aContext.IsNull() )
1104 cout << "The context is null. Please use vinit before createmesh" << endl;
1108 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1109 if( report.xbutton.button==1 )
1113 aContext->ShiftSelect();
1114 // cout << "shift select" << endl;
1119 // cout << "select" << endl;
1124 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1125 max( xx1, xx2 ), max( yy1, yy2 ),
1126 ViewerTest::CurrentView());
1127 // cout << "shift select" << endl;
1131 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1132 max( xx1, xx2 ), max( yy1, yy2 ),
1133 ViewerTest::CurrentView() );
1134 // cout << "select" << endl;
1137 ProcessButtonRelease();
1139 IsDragged = Standard_False;
1142 ProcessButtonRelease();
1149 X_Motion = report.xmotion.x;
1150 Y_Motion = report.xmotion.y;
1154 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1155 GC gc = XCreateGC( display, aWindow, 0, 0 );
1156 XSetFunction( display, gc, GXinvert );
1159 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1163 DragFirst = Standard_False;
1165 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1166 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1171 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1173 // remove all the ButtonMotionMask
1174 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1176 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1177 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1179 Quantity_Length VDX, VDY;
1181 ViewerTest::CurrentView()->Size(VDX,VDY);
1182 Standard_Real VDZ =0 ;
1183 VDZ = ViewerTest::CurrentView()->ZSize();
1185 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1186 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1188 Quantity_Length dx = 0 ;
1189 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1193 dx = dx / VDX * VDZ;
1197 // Front = Depth + width/2.
1198 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1199 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1201 ViewerTest::CurrentView()->Redraw();
1205 if ( report.xmotion.state & ControlMask ) {
1206 if ( report.xmotion.state & Button1Mask ) {
1207 ProcessControlButton1Motion();
1209 else if ( report.xmotion.state & Button2Mask ) {
1210 ProcessControlButton2Motion();
1212 else if ( report.xmotion.state & Button3Mask ) {
1213 ProcessControlButton3Motion();
1228 //==============================================================================
1229 //function : VProcessEvents
1230 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1231 // event in the Viewer window
1232 //==============================================================================
1234 static void VProcessEvents(ClientData,int)
1236 //cout << "VProcessEvents" << endl;
1239 while (XPending(display)) {
1240 ViewerMainLoop( 0, NULL);
1245 //==============================================================================
1246 //function : OSWindowSetup
1247 //purpose : Setup for the X11 window to be able to cath the event
1248 //==============================================================================
1251 static void OSWindowSetup()
1256 Window window = VT_GetWindow()->XWindow();
1258 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1259 display = (Display * ) theDisplay;
1260 // display = (Display *)GetG3dDevice()->XDisplay();
1262 XSynchronize(display, 1);
1264 VT_GetWindow()->Map();
1266 // X11 : For keyboard on SUN
1268 wmhints.flags = InputHint;
1271 XSetWMHints( display, window, &wmhints);
1273 XSelectInput( display, window, ExposureMask | KeyPressMask |
1274 ButtonPressMask | ButtonReleaseMask |
1275 StructureNotifyMask |
1277 Button1MotionMask | Button2MotionMask |
1281 XSynchronize(display, 0);
1290 //==============================================================================
1293 //purpose : Fitall, no DRAW arguments
1294 //Draw arg : No args
1295 //==============================================================================
1297 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1299 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1300 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1301 if (V.IsNull() == Standard_False) {
1303 } else if (aView.IsNull() == Standard_False) {
1309 //==============================================================================
1311 //purpose : ZFitall, no DRAW arguments
1312 //Draw arg : No args
1313 //==============================================================================
1315 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1317 Handle(V3d_View) V = ViewerTest::CurrentView();
1318 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1321 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1323 Handle(V3d_View) V = ViewerTest::CurrentView();
1324 if ( !V.IsNull() ) V->Redraw(); return 0;
1328 //==============================================================================
1330 //purpose : Remove all the object from the viewer
1331 //Draw arg : No args
1332 //==============================================================================
1334 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1336 Handle(V3d_View) V = ViewerTest::CurrentView();
1338 ViewerTest::Clear();
1342 //==============================================================================
1345 //==============================================================================
1347 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1348 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1351 di << argv[0] << "Invalid number of arguments" << "\n";
1355 while (ViewerMainLoop( argc, argv)) {
1363 //==============================================================================
1364 //function : InitViewerTest
1365 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1366 //==============================================================================
1368 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1370 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1371 ViewerTest::SetAISContext(context);
1372 viewer->InitActiveViews();
1373 Handle(V3d_View) view = viewer->ActiveView();
1374 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1375 ViewerTest::ResetEventManager();
1376 Handle(Aspect_GraphicDevice) device = viewer->Device();
1377 Handle(Aspect_Window) window = view->Window();
1380 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1381 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1383 static int first = 1;
1385 #if TCL_MAJOR_VERSION < 8
1386 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1387 TK_READABLE, VProcessEvents, (ClientData) 0);
1389 Tk_CreateFileHandler(ConnectionNumber(display),
1390 TK_READABLE, VProcessEvents, (ClientData) 0);
1398 //==============================================================================
1400 //purpose : Load image as background
1401 //==============================================================================
1403 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1405 if (argc < 2 || argc > 3)
1407 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1408 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1412 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1413 if(AISContext.IsNull())
1415 di << "use 'vinit' command before " << argv[0] << "\n";
1419 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1422 const char* szType = argv[2];
1423 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1424 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1425 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1426 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1429 di << "Wrong fill type : " << szType << "\n";
1430 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1435 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1436 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1441 //==============================================================================
1442 //function : VSetBgMode
1443 //purpose : Change background image fill type
1444 //==============================================================================
1446 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1450 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1451 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1455 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1456 if(AISContext.IsNull())
1458 di << "use 'vinit' command before " << argv[0] << "\n";
1462 Aspect_FillMethod aFillType;
1465 const char* szType = argv[1];
1466 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1467 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1468 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1469 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1472 di << "Wrong fill type : " << szType << "\n";
1473 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1478 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1479 V3dView->SetBgImageStyle(aFillType, Standard_True);
1484 //==============================================================================
1485 //function : VSetGradientBg
1486 //purpose : Mount gradient background
1487 //==============================================================================
1488 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1492 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1493 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1494 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1495 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1499 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1500 if(AISContext.IsNull())
1502 di << "use 'vinit' command before " << argv[0] << "\n";
1508 Standard_Real R1 = atof(argv[1])/255.;
1509 Standard_Real G1 = atof(argv[2])/255.;
1510 Standard_Real B1 = atof(argv[3])/255.;
1511 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1513 Standard_Real R2 = atof(argv[4])/255.;
1514 Standard_Real G2 = atof(argv[5])/255.;
1515 Standard_Real B2 = atof(argv[6])/255.;
1517 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1518 int aType = atoi(argv[7]);
1519 if( aType < 0 || aType > 8 )
1521 di << "Wrong fill type " << "\n";
1522 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1523 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1527 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1529 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1530 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1536 //==============================================================================
1537 //function : VSetGradientBgMode
1538 //purpose : Change gradient background fill style
1539 //==============================================================================
1540 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1544 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1545 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1546 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1550 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1551 if(AISContext.IsNull())
1553 di << "use 'vinit' command before " << argv[0] << "\n";
1558 int aType = atoi(argv[1]);
1559 if( aType < 0 || aType > 8 )
1561 di << "Wrong fill type " << "\n";
1562 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1563 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1567 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1569 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1570 V3dView->SetBgGradientStyle( aMethod, 1 );
1576 //==============================================================================
1577 //function : VSetColorBg
1578 //purpose : Set color background
1579 //==============================================================================
1580 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1584 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1585 di << "R,G,B = [0..255]" << "\n";
1589 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1590 if(AISContext.IsNull())
1592 di << "use 'vinit' command before " << argv[0] << "\n";
1598 Standard_Real R = atof(argv[1])/255.;
1599 Standard_Real G = atof(argv[2])/255.;
1600 Standard_Real B = atof(argv[3])/255.;
1601 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1603 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1604 V3dView->SetBackgroundColor( aColor );
1611 //==============================================================================
1613 //purpose : View Scaling
1614 //==============================================================================
1616 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1618 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1619 if ( V3dView.IsNull() ) return 1;
1622 di << argv[0] << "Invalid number of arguments" << "\n";
1625 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1628 //==============================================================================
1629 //function : VTestZBuffTrihedron
1630 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1631 //==============================================================================
1633 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1635 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1636 if ( V3dView.IsNull() ) return 1;
1638 V3dView->ZBufferTriedronSetup();
1641 // Set up default trihedron parameters
1642 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1646 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1647 const char* aPosType = argv[1];
1649 if ( strcmp(aPosType, "center") == 0 )
1651 aPosition = Aspect_TOTP_CENTER;
1653 if (strcmp(aPosType, "left_lower") == 0)
1655 aPosition = Aspect_TOTP_LEFT_LOWER;
1657 if (strcmp(aPosType, "left_upper") == 0)
1659 aPosition = Aspect_TOTP_LEFT_UPPER;
1661 if (strcmp(aPosType, "right_lower") == 0)
1663 aPosition = Aspect_TOTP_RIGHT_LOWER;
1665 if (strcmp(aPosType, "right_upper") == 0)
1667 aPosition = Aspect_TOTP_RIGHT_UPPER;
1670 di << argv[1] << " Invalid type of alignment" << "\n";
1671 di << "Must be one of [ center, left_lower," << "\n";
1672 di << "left_upper, right_lower, right_upper ]" << "\n";
1676 Standard_Real R = atof(argv[2])/255.;
1677 Standard_Real G = atof(argv[3])/255.;
1678 Standard_Real B = atof(argv[4])/255.;
1679 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1681 Standard_Real aScale = atof(argv[5]);
1685 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1689 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1690 const char* aPresType = argv[6];
1692 if ( strcmp(aPresType, "wireframe") == 0 )
1694 aPresentation = V3d_WIREFRAME;
1696 if (strcmp(aPresType, "zbuffer") == 0)
1698 aPresentation = V3d_ZBUFFER;
1701 di << argv[6] << " Invalid type of visualization" << "\n";
1702 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1706 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1710 di << argv[0] << " Invalid number of arguments" << "\n";
1719 //==============================================================================
1720 //function : VRotate
1721 //purpose : Camera Rotating
1722 //==============================================================================
1724 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1725 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1726 if ( V3dView.IsNull() ) {
1731 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1733 } else if ( argc == 7 ) {
1734 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1737 di << argv[0] << " Invalid number of arguments" << "\n";
1742 //==============================================================================
1744 //purpose : View zoom in / out (relative to current zoom)
1745 //==============================================================================
1747 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1748 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1749 if ( V3dView.IsNull() ) {
1754 Standard_Real coef = atof(argv[1]);
1755 if ( coef <= 0.0 ) {
1756 di << argv[1] << "Invalid value" << "\n";
1759 V3dView->SetZoom( atof(argv[1]) );
1762 di << argv[0] << " Invalid number of arguments" << "\n";
1767 //==============================================================================
1769 //purpose : View panning (in pixels)
1770 //==============================================================================
1772 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1773 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1774 if ( V3dView.IsNull() ) return 1;
1777 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1780 di << argv[0] << " Invalid number of arguments" << "\n";
1786 //==============================================================================
1787 //function : VExport
1788 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1789 //==============================================================================
1791 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1793 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1794 if (V3dView.IsNull())
1799 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1803 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1804 TCollection_AsciiString aFormatStr;
1806 TCollection_AsciiString aFileName (argv[1]);
1807 Standard_Integer aLen = aFileName.Length();
1811 aFormatStr = TCollection_AsciiString (argv[2]);
1815 if (aFileName.Value (aLen - 2) == '.')
1817 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1819 else if (aFileName.Value (aLen - 3) == '.')
1821 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1825 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1831 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1835 aFormatStr.UpperCase();
1836 if (aFormatStr == "PS")
1837 anExpFormat = Graphic3d_EF_PostScript;
1838 else if (aFormatStr == "EPS")
1839 anExpFormat = Graphic3d_EF_EnhPostScript;
1840 else if (aFormatStr == "TEX")
1841 anExpFormat = Graphic3d_EF_TEX;
1842 else if (aFormatStr == "PDF")
1843 anExpFormat = Graphic3d_EF_PDF;
1844 else if (aFormatStr == "SVG")
1845 anExpFormat = Graphic3d_EF_SVG;
1846 else if (aFormatStr == "PGF")
1847 anExpFormat = Graphic3d_EF_PGF;
1848 else if (aFormatStr == "EMF")
1849 anExpFormat = Graphic3d_EF_EMF;
1852 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1856 if (!V3dView->View()->Export (argv[1], anExpFormat))
1858 std::cout << "Export failed!\n";
1864 //==============================================================================
1865 //function : VColorScale
1866 //purpose : representation color scale
1867 //==============================================================================
1868 #include <V3d_ColorScale.hxx>
1870 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1872 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1874 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1878 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1879 if(aContext.IsNull()) {
1880 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1884 Standard_Real minRange = 0. , maxRange = 100. ;
1886 Standard_Integer numIntervals = 10 ;
1887 Standard_Real textHeight = 16. ;
1888 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1889 Standard_Real X = 0., Y = 0. ;
1895 minRange = atof( argv[1] );
1896 maxRange = atof( argv[2] );
1897 numIntervals = atoi( argv[3] );
1900 textHeight = atof( argv[4] );
1902 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1905 X = atof( argv[6] );
1906 Y = atof( argv[7] );
1909 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1910 if ( curView.IsNull( ) )
1912 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1913 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1914 if( ! aCS.IsNull( ) )
1916 aCS->SetPosition( X , Y );
1917 aCS->SetHeight( 0.95) ;
1918 aCS->SetTextHeight( textHeight );
1919 aCS->SetRange( minRange , maxRange );
1920 aCS->SetNumberOfIntervals( numIntervals );
1921 aCS->SetLabelPosition( position );
1922 if( !curView->ColorScaleIsDisplayed() )
1923 curView->ColorScaleDisplay( );
1928 //==============================================================================
1929 //function : VGraduatedTrihedron
1930 //purpose : Displays a graduated trihedron
1931 //==============================================================================
1933 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
1935 const char *str = arg;
1938 unsigned short c1 = *str++;
1939 unsigned short c2 = *str++;
1940 if (!c1 || !c2) break;
1941 name += (Standard_ExtCharacter)((c1 << 8) | c2);
1945 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1948 if (argc != 2 && argc < 5)
1950 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
1951 di<<"Usage: type help "<<argv[0]<<"\n";
1952 return 1; //TCL_ERROR
1955 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
1957 // Create 3D view if it doesn't exist
1958 if ( aV3dView.IsNull() )
1960 ViewerTest::ViewerInit();
1961 aV3dView = ViewerTest::CurrentView();
1962 if( aV3dView.IsNull() )
1964 di << "Error: Cannot create a 3D view\n";
1965 return 1; //TCL_ERROR
1969 // Erase (==0) or display (!=0)
1970 const int display = atoi(argv[1]);
1975 TCollection_AsciiString font;
1977 font.AssignCat("Courier");
1979 font.AssignCat(argv[5]);
1981 // Text is multibyte
1982 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
1985 TCollection_ExtendedString xname, yname, zname;
1990 AddMultibyteString(xname, argv[2]);
1991 AddMultibyteString(yname, argv[3]);
1992 AddMultibyteString(zname, argv[4]);
2008 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2009 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2010 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2011 Standard_True/*drawgrid*/,
2012 Standard_True/*drawaxes*/,
2013 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2014 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2015 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2016 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2017 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2018 Quantity_NOC_WHITE/*gridcolor*/,
2019 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2020 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2023 aV3dView->GraduatedTrihedronErase();
2025 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2031 //==============================================================================
2032 //function : VPrintView
2033 //purpose : Test printing algorithm, print the view to image file with given
2034 // width and height. Printing implemented only for WNT.
2035 //==============================================================================
2036 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2040 di << "Printing implemented only for wnt!\n";
2044 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2045 Handle(V3d_View) aView = NULL;
2046 aContextAIS = ViewerTest::GetAISContext();
2047 if (!aContextAIS.IsNull())
2049 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2050 Vwr->InitActiveViews();
2051 if(Vwr->MoreActiveViews())
2052 aView = Vwr->ActiveView();
2058 di << "Call vinit before!\n";
2063 di << "Use: " << argv[0];
2064 di << " width height filename [print algo=0]\n";
2065 di << "width, height of the intermediate buffer for operation\n";
2066 di << "algo : {0|1}\n";
2067 di << " 0 - stretch algorithm\n";
2068 di << " 1 - tile algorithm\n";
2069 di << "test printing algorithms into an intermediate buffer\n";
2070 di << "with saving output to an image file\n";
2074 // get the input params
2075 Standard_Integer aWidth = atoi (argv[1]);
2076 Standard_Integer aHeight = atoi (argv[2]);
2077 Standard_Integer aMode = 0;
2078 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2080 aMode = atoi (argv[4]);
2082 // check the input parameters
2083 if (aWidth <= 0 || aHeight <= 0)
2085 di << "Width and height must be positive values!\n";
2088 if (aMode != 0 && aMode != 1)
2091 Image_CRawBufferData aRawBuffer;
2092 HDC anDC = CreateCompatibleDC(0);
2094 // define compatible bitmap
2095 BITMAPINFO aBitmapData;
2096 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2097 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2098 aBitmapData.bmiHeader.biWidth = aWidth ;
2099 aBitmapData.bmiHeader.biHeight = aHeight;
2100 aBitmapData.bmiHeader.biPlanes = 1;
2101 aBitmapData.bmiHeader.biBitCount = 24;
2102 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2103 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2104 aBitmapData.bmiHeader.biClrUsed = 0;
2105 aBitmapData.bmiHeader.biClrImportant = 0;
2106 aBitmapData.bmiHeader.biCompression = BI_RGB;
2107 aBitmapData.bmiHeader.biSizeImage = 0;
2109 // Create Device Independent Bitmap
2110 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2111 &aRawBuffer.dataPtr, NULL, 0);
2112 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2114 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2115 if (aRawBuffer.dataPtr != 0)
2118 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2120 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2122 // succesfully printed into an intermediate buffer
2125 Handle(Image_PixMap) anImageBitmap =
2126 new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr,
2128 aWidth*3 + aWidth%4, 24, 0);
2129 isSaved = anImageBitmap->Dump(aFileName.ToCString());
2133 di << "Print operation failed due to printing errors or\n";
2134 di << "insufficient memory available\n";
2135 di << "Please, try to use smaller dimensions for this test\n";
2136 di << "command, as it allocates intermediate buffer for storing\n";
2137 di << "the result\n";
2142 di << "Can't allocate memory for intermediate buffer\n";
2143 di << "Please use smaller dimensions\n";
2148 SelectObject (anDC, anOldBitmap);
2149 DeleteObject (aMemoryBitmap);
2155 di << "Save to file operation failed. This operation may fail\n";
2156 di << "if you don't have enough available memory, then you can\n";
2157 di << "use smaller dimensions for the output file\n";
2166 //==============================================================================
2167 //function : VZLayer
2168 //purpose : Test z layer operations for v3d viewer
2169 //==============================================================================
2170 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2172 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2173 if (aContextAIS.IsNull())
2175 di << "Call vinit before!\n";
2180 di << "Use: vzlayer " << argv[0];
2181 di << " add/del/get [id]\n";
2182 di << " add - add new z layer to viewer and print its id\n";
2183 di << " del - del z layer by its id\n";
2184 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2185 di << "id - the layer identificator value defined when removing z layer\n";
2189 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2190 if (aViewer.IsNull())
2192 di << "No active viewer!\n";
2196 // perform operation
2197 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2200 Standard_Integer aNewId;
2201 if (!aViewer->AddZLayer (aNewId))
2203 di << "Impossible to add new z layer!\n";
2207 di << "New z layer added with index: " << aNewId << "\n";
2209 else if (anOp == "del")
2213 di << "Please also provide as argument id of z layer to remove\n";
2217 Standard_Integer aDelId = atoi (argv[2]);
2218 if (!aViewer->RemoveZLayer (aDelId))
2220 di << "Impossible to remove the z layer or invalid id!\n";
2224 di << "Z layer " << aDelId << " has been removed\n";
2226 else if (anOp == "get")
2228 TColStd_SequenceOfInteger anIds;
2229 aViewer->GetAllZLayers (anIds);
2230 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2232 di << anIds.Value (aSeqIdx) << " ";
2239 di << "Invalid operation, please use { add / del / get }\n";
2246 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2248 // this class provides a presentation of text item in v3d view under-/overlayer
2249 class V3d_TextItem : public Visual3d_LayerItem
2254 DEFINE_STANDARD_RTTI(V3d_TextItem)
2257 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2258 const Standard_Real theX1,
2259 const Standard_Real theY1,
2260 const Standard_Real theHeight,
2261 const TCollection_AsciiString& theFontName,
2262 const Quantity_Color& theColor,
2263 const Quantity_Color& theSubtitleColor,
2264 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2265 const Handle(Visual3d_Layer)& theLayer);
2268 Standard_EXPORT void RedrawLayerPrs();
2274 Standard_Real myHeight;
2275 TCollection_AsciiString myText;
2276 TCollection_AsciiString myFontName;
2277 Quantity_Color myColor;
2278 Quantity_Color mySubtitleColor;
2279 Aspect_TypeOfDisplayText myType;
2280 Handle(Visual3d_Layer) myLayer;
2284 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2285 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2287 // create and add to display the text item
2288 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2289 const Standard_Real theX1,
2290 const Standard_Real theY1,
2291 const Standard_Real theHeight,
2292 const TCollection_AsciiString& theFontName,
2293 const Quantity_Color& theColor,
2294 const Quantity_Color& theSubtitleColor,
2295 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2296 const Handle(Visual3d_Layer)& theLayer)
2297 : myX1 (theX1), myY1 (theY1),
2299 myHeight (theHeight),
2302 mySubtitleColor (theSubtitleColor),
2303 myType (theTypeOfDisplay),
2304 myFontName (theFontName)
2306 if (!myLayer.IsNull ())
2307 myLayer->AddLayerItem (this);
2311 void V3d_TextItem::RedrawLayerPrs ()
2313 if (myLayer.IsNull ())
2316 myLayer->SetColor (myColor);
2317 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2318 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2321 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2323 // The Visual3d_LayerItem line item for "vlayerline" command
2324 // it provides a presentation of line with user-defined
2325 // linewidth, linetype and transparency.
2326 class V3d_LineItem : public Visual3d_LayerItem
2330 DEFINE_STANDARD_RTTI(V3d_LineItem)
2333 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2334 Standard_Real X2, Standard_Real Y2,
2335 V3d_LayerMgrPointer theLayerMgr,
2336 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2337 Standard_Real theWidth = 0.5,
2338 Standard_Real theTransp = 1.0);
2341 Standard_EXPORT void RedrawLayerPrs();
2345 Standard_Real myX1, myY1, myX2, myY2;
2346 Standard_Real myWidth;
2347 Standard_Real myTransparency;
2348 Aspect_TypeOfLine myType;
2349 V3d_LayerMgrPointer myLayerMgr;
2352 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2353 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2355 // default constructor for line item
2356 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2357 Standard_Real X2, Standard_Real Y2,
2358 V3d_LayerMgrPointer theLayerMgr,
2359 Aspect_TypeOfLine theType,
2360 Standard_Real theWidth,
2361 Standard_Real theTransp) :
2362 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2363 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2365 if (myLayerMgr && myLayerMgr->Overlay())
2366 myLayerMgr->Overlay()->AddLayerItem (this);
2370 void V3d_LineItem::RedrawLayerPrs ()
2372 Handle (Visual3d_Layer) aOverlay;
2375 aOverlay = myLayerMgr->Overlay();
2377 if (!aOverlay.IsNull())
2379 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2380 aOverlay->SetColor(aColor);
2381 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2382 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2383 aOverlay->BeginPolyline();
2384 aOverlay->AddVertex(myX1, myY1);
2385 aOverlay->AddVertex(myX2, myY2);
2386 aOverlay->ClosePrimitive();
2390 //=============================================================================
2391 //function : VLayerLine
2392 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2393 // : linewidth, transparency coefficient
2394 //============================================================================
2395 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2397 // get the active view
2398 Handle(V3d_View) aView = ViewerTest::CurrentView();
2401 di << "Call vinit before!\n";
2406 di << "Use: " << argv[0];
2407 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2408 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2409 di << " 0 - solid \n";
2410 di << " 1 - dashed \n";
2411 di << " 2 - dot \n";
2412 di << " 3 - dashdot\n";
2413 di << " transparency : { 0.0 - 1.0 } \n";
2414 di << " 0.0 - transparent\n";
2415 di << " 1.0 - visible \n";
2419 // get the input params
2420 Standard_Real X1 = atof(argv[1]);
2421 Standard_Real Y1 = atof(argv[2]);
2422 Standard_Real X2 = atof(argv[3]);
2423 Standard_Real Y2 = atof(argv[4]);
2425 Standard_Real aWidth = 0.5;
2426 Standard_Integer aType = 0;
2427 Standard_Real aTransparency = 1.0;
2431 aWidth = atof(argv[5]);
2435 aType = (Standard_Integer) atoi(argv[6]);
2440 aTransparency = atof(argv[7]);
2441 if (aTransparency < 0 || aTransparency > 1.0)
2442 aTransparency = 1.0;
2445 // select appropriate line type
2446 Aspect_TypeOfLine aLineType;
2450 aLineType = Aspect_TOL_DASH;
2454 aLineType = Aspect_TOL_DOT;
2458 aLineType = Aspect_TOL_DOTDASH;
2462 aLineType = Aspect_TOL_SOLID;
2465 // replace layer manager
2466 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2467 aView->SetLayerMgr(aMgr);
2470 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2476 aView->MustBeResized();
2482 //=======================================================================
2483 //function : VOverlayText
2484 //purpose : Test text displaying in view overlay
2485 //=======================================================================
2486 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2488 // get the active view
2489 Handle(V3d_View) aView = ViewerTest::CurrentView();
2492 di << "No active view. Please call vinit.\n";
2495 else if (argc < 4 || argc > 13)
2497 di << "Use: " << argv[0];
2498 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2499 di << "[background_color: R G B]\n";
2500 di << " height - pixel height of the text (default=10.0)\n";
2501 di << " font_name - name of font (default=courier)\n";
2502 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2503 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2504 di << " background_color- R G B values used for subtitle and decal text\n";
2505 di << "(default=255.0 255.0 255.0)\n";
2509 TCollection_AsciiString aText (argv[1]);
2510 Standard_Real aPosX = atof(argv[2]);
2511 Standard_Real aPosY = atof(argv[3]);
2512 Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
2515 TCollection_AsciiString aFontName = "Courier";
2517 aFontName = TCollection_AsciiString (argv[5]);
2520 Quantity_Parameter aColorRed = 1.0;
2521 Quantity_Parameter aColorGreen = 1.0;
2522 Quantity_Parameter aColorBlue = 1.0;
2525 aColorRed = atof (argv[6])/255.;
2526 aColorGreen = atof (argv[7])/255.;
2527 aColorBlue = atof (argv[8])/255.;
2531 TCollection_AsciiString aDispStr;
2533 aDispStr = TCollection_AsciiString (argv[9]);
2535 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2536 if (aDispStr.IsEqual ("subtitle"))
2537 aTextType = Aspect_TODT_SUBTITLE;
2538 else if (aDispStr.IsEqual ("decal"))
2539 aTextType = Aspect_TODT_DEKALE;
2540 else if (aDispStr.IsEqual ("blend"))
2541 aTextType = Aspect_TODT_BLEND;
2544 Quantity_Parameter aSubRed = 1.0;
2545 Quantity_Parameter aSubGreen = 1.0;
2546 Quantity_Parameter aSubBlue = 1.0;
2549 aSubRed = atof (argv[10])/255.;
2550 aSubGreen = atof (argv[11])/255.;
2551 aSubBlue = atof (argv[12])/255.;
2554 // check fo current overlay
2555 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2556 if (anOverlay.IsNull ())
2558 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2559 anOverlay = aMgr->Overlay ();
2560 aView->SetLayerMgr (aMgr);
2563 Quantity_Color aTextColor (aColorRed, aColorGreen,
2564 aColorBlue, Quantity_TOC_RGB);
2565 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2566 aSubBlue, Quantity_TOC_RGB);
2569 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2570 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2573 aView->MustBeResized();
2579 //=======================================================================
2580 //function : ViewerCommands
2582 //=======================================================================
2584 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
2587 const char *group = "ZeViewer";
2588 theCommands.Add("vinit" ,
2589 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
2590 __FILE__,VInit,group);
2591 theCommands.Add("vhelp" ,
2592 "vhelp : display help on the viewer commands",
2593 __FILE__,VHelp,group);
2594 theCommands.Add("vtop" ,
2595 "vtop or <T> : Top view" ,
2596 __FILE__,VTop,group);
2597 theCommands.Add("vaxo" ,
2598 " vaxo or <A> : Axonometric view ",
2599 __FILE__,VAxo,group);
2600 theCommands.Add("vpick" ,
2601 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
2603 theCommands.Add("vfit" ,
2604 "vfit or <F> : vfit",
2605 __FILE__,VFit,group);
2606 theCommands.Add("vzfit" ,
2608 __FILE__,VZFit,group);
2609 theCommands.Add("vrepaint",
2610 "vrepaint : vrepaint, force redraw",
2611 __FILE__,VRepaint,group);
2612 theCommands.Add("vclear",
2614 __FILE__,VClear,group);
2615 theCommands.Add("vsetbg",
2616 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
2617 __FILE__,VSetBg,group);
2618 theCommands.Add("vsetbgmode",
2619 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
2620 __FILE__,VSetBgMode,group);
2621 theCommands.Add("vsetgradientbg",
2622 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
2623 __FILE__,VSetGradientBg,group);
2624 theCommands.Add("vsetgrbgmode",
2625 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
2626 __FILE__,VSetGradientBgMode,group);
2627 theCommands.Add("vsetcolorbg",
2628 "vsetcolorbg : vsetcolorbg r g b : Set background color",
2629 __FILE__,VSetColorBg,group);
2630 theCommands.Add("vscale",
2631 "vscale : vscale X Y Z",
2632 __FILE__,VScale,group);
2633 theCommands.Add("vzbufftrihedron",
2634 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
2635 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
2636 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
2637 __FILE__,VTestZBuffTrihedron,group);
2638 theCommands.Add("vrotate",
2639 "vrotate : vrotate AX AY AZ [X Y Z]",
2640 __FILE__,VRotate,group);
2641 theCommands.Add("vzoom",
2642 "vzoom : vzoom coef",
2643 __FILE__,VZoom,group);
2644 theCommands.Add("vpan",
2645 "vpan : vpan dx dy",
2646 __FILE__,VPan,group);
2647 theCommands.Add("vexport",
2648 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
2649 " : exports the view to a vector file of a given format"
2650 " : notice that EMF format requires patched gl2ps",
2651 __FILE__,VExport,group);
2652 theCommands.Add("vcolorscale",
2653 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
2654 __FILE__,VColorScale,group);
2655 theCommands.Add("vgraduatedtrihedron",
2656 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
2657 __FILE__,VGraduatedTrihedron,group);
2658 theCommands.Add("vprintview" ,
2659 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
2660 __FILE__,VPrintView,group);
2661 theCommands.Add("vzlayer",
2662 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
2663 __FILE__,VZLayer,group);
2664 theCommands.Add("voverlaytext",
2665 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
2666 " : height - pixel height of the text (default=10.0)"
2667 " : font_name - name of font (default=courier)"
2668 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
2669 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
2670 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
2671 __FILE__,VOverlayText,group);
2672 theCommands.Add("vlayerline",
2673 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
2674 __FILE__,VLayerLine,group);