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_GraphicDriver.hxx>
34 #include <Graphic3d_ExportFormat.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_EventManager.hxx>
37 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
38 #include <Visual3d_View.hxx>
39 #include <Visual3d_ViewManager.hxx>
40 #include <V3d_LayerMgr.hxx>
41 #include <NIS_View.hxx>
42 #include <NIS_Triangulated.hxx>
43 #include <NIS_InteractiveContext.hxx>
44 #include <AIS_InteractiveContext.hxx>
45 #include <Draw_Interpretor.hxx>
47 #include <Draw_Appli.hxx>
48 #include <Aspect_PrintAlgo.hxx>
49 #include <Image_AlienPixMap.hxx>
50 #include <OSD_Timer.hxx>
51 #include <TColStd_SequenceOfInteger.hxx>
52 #include <TColStd_HSequenceOfReal.hxx>
53 #include <TColgp_Array1OfPnt2d.hxx>
54 #include <Visual3d_LayerItem.hxx>
55 #include <V3d_LayerMgr.hxx>
56 #include <V3d_LayerMgrPointer.hxx>
57 #include <Aspect_TypeOfLine.hxx>
58 #include <Image_Diff.hxx>
59 #include <Aspect_DisplayConnection.hxx>
60 #include <Graphic3d.hxx>
66 #include <Visual3d_Layer.hxx>
69 #if defined(_WIN32) || defined(__WIN32__)
70 #include <WNT_WClass.hxx>
71 #include <WNT_Window.hxx>
74 #define _CRT_SECURE_NO_DEPRECATE
75 #pragma warning (disable:4996)
77 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
78 #include <Cocoa_Window.hxx>
81 #include <Xw_WindowQuality.hxx>
82 #include <Xw_Window.hxx>
83 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
84 #include <X11/Xutil.h>
88 //==============================================================================
90 //==============================================================================
91 // VIEWER GLOBAL VARIABLES
92 //==============================================================================
94 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
96 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
97 extern const Handle(NIS_InteractiveContext)& TheNISContext();
98 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
100 #if defined(_WIN32) || defined(__WIN32__)
101 static Handle(WNT_Window)& VT_GetWindow() {
102 static Handle(WNT_Window) WNTWin;
105 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
106 static Handle(Cocoa_Window)& VT_GetWindow()
108 static Handle(Cocoa_Window) aWindow;
111 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
113 static Handle(Xw_Window)& VT_GetWindow(){
114 static Handle(Xw_Window) XWWin;
117 static Display *display;
119 static void VProcessEvents(ClientData,int);
122 static Handle(Graphic3d_GraphicDriver)& GetGraphicDriver()
124 static Handle(Graphic3d_GraphicDriver) aGraphicDriver;
125 return aGraphicDriver;
128 static Standard_Boolean DegenerateMode = Standard_True;
130 #define ZCLIPWIDTH 1.
132 static void OSWindowSetup();
134 //==============================================================================
135 // EVENT GLOBAL VARIABLES
136 //==============================================================================
138 static int Start_Rot = 0;
139 static int ZClipIsOn = 0;
140 int X_Motion = 0; // Current cursor position
142 int X_ButtonPress = 0; // Last ButtonPress position
143 int Y_ButtonPress = 0;
144 Standard_Boolean IsDragged = Standard_False;
145 Standard_Boolean DragFirst;
147 //==============================================================================
150 static LRESULT WINAPI ViewerWindowProc(
155 static LRESULT WINAPI AdvViewerWindowProc(
163 //==============================================================================
166 //==============================================================================
168 const Handle(MMgt_TShared)& ViewerTest::WClass()
170 static Handle(MMgt_TShared) theWClass;
171 #if defined(_WIN32) || defined(__WIN32__)
172 if (theWClass.IsNull())
174 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
175 CS_VREDRAW | CS_HREDRAW, 0, 0,
176 ::LoadCursor (NULL, IDC_ARROW));
182 //==============================================================================
183 //function : ViewerInit
184 //purpose : Create the window viewer and initialize all the global variable
185 //==============================================================================
187 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
188 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
190 static Standard_Boolean isFirst = Standard_True;
192 // Default position and dimension of the viewer window.
193 // Note that left top corner is set to be sufficiently small to have
194 // window fit in the small screens (actual for remote desktops, see #23003).
195 // The position corresponds to the window's client area, thus some
196 // gap is added for window frame to be visible.
197 Standard_Integer aPxLeft = 20;
198 Standard_Integer aPxTop = 40;
199 Standard_Integer aPxWidth = 409;
200 Standard_Integer aPxHeight = 409;
201 if (thePxWidth != 0 && thePxHeight != 0)
205 aPxWidth = thePxWidth;
206 aPxHeight = thePxHeight;
211 Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
212 if (GetGraphicDriver().IsNull())
214 GetGraphicDriver() = Graphic3d::InitGraphicDriver (aDisplayConnection);
216 #if defined(_WIN32) || defined(__WIN32__)
217 if (VT_GetWindow().IsNull())
219 VT_GetWindow() = new WNT_Window ("Test3d",
220 Handle(WNT_WClass)::DownCast (WClass()),
226 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
227 if (VT_GetWindow().IsNull())
229 VT_GetWindow() = new Cocoa_Window ("Test3d",
231 aPxWidth, aPxHeight);
232 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
235 if (VT_GetWindow().IsNull())
237 VT_GetWindow() = new Xw_Window (aDisplayConnection,
244 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
246 Handle(V3d_Viewer) a3DViewer, a3DCollector;
247 // Viewer and View creation
249 TCollection_ExtendedString NameOfWindow("Visu3D");
251 a3DViewer = new V3d_Viewer(GetGraphicDriver(), NameOfWindow.ToExtString());
252 NameOfWindow = TCollection_ExtendedString("Collector");
253 a3DCollector = new V3d_Viewer(GetGraphicDriver(), NameOfWindow.ToExtString());
254 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
255 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
256 Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
259 //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
260 aView = new NIS_View (a3DViewer, VT_GetWindow());
261 ViewerTest::CurrentView(aView);
262 TheNISContext()->AttachView (aView);
266 if ( ViewerTest::GetAISContext().IsNull() ) {
267 Handle(AIS_InteractiveContext) C =
268 new AIS_InteractiveContext(a3DViewer,a3DCollector);
269 ViewerTest::SetAISContext(C);
272 // Setup for X11 or NT
274 // Viewer and View creation
276 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
278 Handle (V3d_View) V = ViewerTest::CurrentView();
280 V->SetDegenerateModeOn();
281 DegenerateMode = V->DegenerateModeIsOn();
282 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
284 V->SetZClippingDepth(0.5);
285 V->SetZClippingWidth(ZCLIPWIDTH/2.);
286 a3DViewer->SetDefaultLights();
287 a3DViewer->SetLightOn();
289 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
290 #if TCL_MAJOR_VERSION < 8
291 Tk_CreateFileHandler((void*)ConnectionNumber(display),
292 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
294 Tk_CreateFileHandler(ConnectionNumber(display),
295 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
299 isFirst = Standard_False;
302 VT_GetWindow()->Map();
303 ViewerTest::CurrentView()->Redraw();
306 //==============================================================================
308 //purpose : Create the window viewer and initialize all the global variable
309 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
310 //==============================================================================
312 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
314 Standard_Integer aPxLeft = (argc > 1) ? Draw::Atoi (argv[1]) : 0;
315 Standard_Integer aPxTop = (argc > 2) ? Draw::Atoi (argv[2]) : 0;
316 Standard_Integer aPxWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
317 Standard_Integer aPxHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
318 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
322 //==============================================================================
323 //function : VT_ProcessKeyPress
324 //purpose : Handle KeyPress event from a CString
325 //==============================================================================
326 void VT_ProcessKeyPress (const char* buf_ret)
328 //cout << "KeyPress" << endl;
329 const Handle(V3d_View) aView = ViewerTest::CurrentView();
330 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
331 // Letter in alphabetic order
333 if ( !strcasecmp(buf_ret, "A") ) {
335 aView->SetProj(V3d_XposYnegZpos);
337 else if ( !strcasecmp(buf_ret, "D") ) {
341 else if ( !strcasecmp(buf_ret, "F") ) {
343 if (aNisView.IsNull())
346 aNisView->FitAll3d();
348 else if ( !strcasecmp(buf_ret, "H") ) {
350 cout << "HLR" << endl;
352 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
353 else aView->SetDegenerateModeOn();
354 DegenerateMode = aView->DegenerateModeIsOn();
356 else if ( !strcasecmp(buf_ret, "S") ) {
358 cout << "passage en mode 1 (shading pour les shapes)" << endl;
360 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
361 if(Ctx->NbCurrents()==0 ||
362 Ctx->NbSelected()==0)
363 Ctx->SetDisplayMode(AIS_Shaded);
365 if(Ctx->HasOpenedContext()){
366 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
367 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
370 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
371 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
373 Ctx->UpdateCurrentViewer();
376 else if ( !strcasecmp(buf_ret, "U") ) {
377 // Unset display mode
378 cout<<"passage au mode par defaut"<<endl;
380 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
381 if(Ctx->NbCurrents()==0 ||
382 Ctx->NbSelected()==0)
383 Ctx->SetDisplayMode(AIS_WireFrame);
385 if(Ctx->HasOpenedContext()){
386 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
387 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
390 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
391 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
393 Ctx->UpdateCurrentViewer();
397 else if ( !strcasecmp(buf_ret, "T") ) {
399 aView->SetProj(V3d_Zpos);
401 else if ( !strcasecmp(buf_ret, "B") ) {
403 aView->SetProj(V3d_Zneg);
405 else if ( !strcasecmp(buf_ret, "L") ) {
407 aView->SetProj(V3d_Xneg);
409 else if ( !strcasecmp(buf_ret, "R") ) {
411 aView->SetProj(V3d_Xpos);
414 else if ( !strcasecmp(buf_ret, "W") ) {
416 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
417 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
418 if(Ctx->NbCurrents()==0 ||
419 Ctx->NbSelected()==0)
420 Ctx->SetDisplayMode(AIS_WireFrame);
422 if(Ctx->HasOpenedContext()){
423 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
424 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
427 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
428 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
430 Ctx->UpdateCurrentViewer();
433 else if ( !strcasecmp(buf_ret, "Z") ) {
437 cout << "ZClipping OFF" << endl;
440 aView->SetZClippingType(V3d_OFF);
444 cout << "ZClipping ON" << endl;
447 aView->SetZClippingType(V3d_FRONT);
451 else if ( !strcasecmp(buf_ret, ",") ) {
452 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
456 else if ( !strcasecmp(buf_ret, ".") ) {
457 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
461 Standard_Integer Num = Draw::Atoi(buf_ret);
463 ViewerTest::StandardModeActivation(Num);
467 //==============================================================================
468 //function : VT_ProcessExpose
469 //purpose : Redraw the View on an Expose Event
470 //==============================================================================
471 void VT_ProcessExpose()
473 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
474 if (!aView3d.IsNull())
480 //==============================================================================
481 //function : VT_ProcessConfigure
482 //purpose : Resize the View on an Configure Event
483 //==============================================================================
484 void VT_ProcessConfigure()
486 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
487 if (aView3d.IsNull())
492 aView3d->MustBeResized();
497 //==============================================================================
498 //function : VT_ProcessButton1Press
500 //==============================================================================
501 Standard_Boolean VT_ProcessButton1Press(
504 Standard_Boolean pick,
505 Standard_Boolean shift)
507 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
509 Standard_Real X, Y, Z;
511 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
513 Draw::Set(argv[1], X);
514 Draw::Set(argv[2], Y);
515 Draw::Set(argv[3], Z);}
526 //==============================================================================
527 //function : VT_ProcessButton1Release
528 //purpose : End selecting
529 //==============================================================================
530 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
534 IsDragged = Standard_False;
535 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
538 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
539 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
543 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
544 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
549 //==============================================================================
550 //function : VT_ProcessButton3Press
551 //purpose : Start Rotation
552 //==============================================================================
553 void VT_ProcessButton3Press()
556 ViewerTest::CurrentView()->SetDegenerateModeOn();
557 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
560 //==============================================================================
561 //function : VT_ProcessButton3Release
562 //purpose : End rotation
563 //==============================================================================
564 void VT_ProcessButton3Release()
569 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
573 //==============================================================================
574 //function : ProcessZClipMotion
576 //==============================================================================
578 void ProcessZClipMotion()
580 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
581 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
582 static Standard_Real CurZPos = 0.;
584 //Quantity_Length VDX, VDY;
585 //a3DView->Size(VDX,VDY);
586 //Standard_Real VDZ = a3DView->ZSize();
587 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
589 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
591 // Front = Depth + width/2.
592 Standard_Real D = 0.5;
593 Standard_Real W = 0.1;
599 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
601 a3DView->SetZClippingType(V3d_OFF);
602 a3DView->SetZClippingDepth(D);
603 a3DView->SetZClippingWidth(W);
604 a3DView->SetZClippingType(V3d_FRONT);
608 X_ButtonPress = X_Motion;
609 Y_ButtonPress = Y_Motion;
613 //==============================================================================
614 //function : ProcessControlButton1Motion
616 //==============================================================================
618 static void ProcessControlButton1Motion()
620 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
622 X_ButtonPress = X_Motion;
623 Y_ButtonPress = Y_Motion;
626 //==============================================================================
627 //function : VT_ProcessControlButton2Motion
629 //==============================================================================
630 void VT_ProcessControlButton2Motion()
632 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
633 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
635 dy = -dy; // Xwindow Y axis is from top to Bottom
637 ViewerTest::CurrentView()->Panning( dx, dy );
639 X_ButtonPress = X_Motion;
640 Y_ButtonPress = Y_Motion;
643 //==============================================================================
644 //function : VT_ProcessControlButton3Motion
646 //==============================================================================
647 void VT_ProcessControlButton3Motion()
651 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
655 //==============================================================================
656 //function : VT_ProcessMotion
658 //==============================================================================
659 void VT_ProcessMotion()
661 //pre-hilights detected objects at mouse position
663 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
664 EM->MoveTo(X_Motion, Y_Motion);
668 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
670 Xpix = X_Motion;Ypix=Y_Motion;
673 //==============================================================================
674 //function : ViewProject: implements VAxo, VTop, VLeft, ...
675 //purpose : Switches to an axonometric, top, left and other views
676 //==============================================================================
678 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
680 if ( ViewerTest::CurrentView().IsNull() )
682 di<<"Call vinit before this command, please"<<"\n";
686 ViewerTest::CurrentView()->SetProj(ori);
690 //==============================================================================
692 //purpose : Switch to an Axonometric view
694 //==============================================================================
696 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
698 return ViewProject(di, V3d_XposYnegZpos);
701 //==============================================================================
703 //purpose : Switch to a Top View
705 //==============================================================================
707 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
709 return ViewProject(di, V3d_Zpos);
712 //==============================================================================
714 //purpose : Switch to a Bottom View
716 //==============================================================================
718 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
720 return ViewProject(di, V3d_Zneg);
723 //==============================================================================
725 //purpose : Switch to a Left View
727 //==============================================================================
729 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
731 return ViewProject(di, V3d_Ypos);
734 //==============================================================================
736 //purpose : Switch to a Right View
738 //==============================================================================
740 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
742 return ViewProject(di, V3d_Yneg);
745 //==============================================================================
747 //purpose : Switch to a Front View
749 //==============================================================================
751 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
753 return ViewProject(di, V3d_Xpos);
756 //==============================================================================
758 //purpose : Switch to a Back View
760 //==============================================================================
762 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
764 return ViewProject(di, V3d_Xneg);
767 //==============================================================================
769 //purpose : Dsiplay help on viewer Keyboead and mouse commands
771 //==============================================================================
773 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
776 di << "Q : Quit the application" << "\n";
778 di << "========================="<<"\n";
779 di << "F : FitAll" << "\n";
780 di << "T : TopView" << "\n";
781 di << "B : BottomView" << "\n";
782 di << "R : RightView" << "\n";
783 di << "L : LeftView" << "\n";
784 di << "A : AxonometricView" << "\n";
785 di << "D : ResetView" << "\n";
787 di << "========================="<<"\n";
788 di << "S : Shading" << "\n";
789 di << "W : Wireframe" << "\n";
790 di << "H : HidelLineRemoval" << "\n";
791 di << "U : Unset display mode" << "\n";
793 di << "========================="<<"\n";
794 di << "Selection mode "<<"\n";
795 di << "0 : Shape" <<"\n";
796 di << "1 : Vertex" <<"\n";
797 di << "2 : Edge" <<"\n";
798 di << "3 : Wire" <<"\n";
799 di << "4 : Face" <<"\n";
800 di << "5 : Shell" <<"\n";
801 di << "6 : Solid" <<"\n";
802 di << "7 : Compound" <<"\n";
804 di << "========================="<<"\n";
805 di << "Z : Switch Z clipping On/Off" << "\n";
806 di << ", : Hilight next detected" << "\n";
807 di << ". : Hilight previous detected" << "\n";
814 static Standard_Boolean Ppick = 0;
815 static Standard_Integer Pargc = 0;
816 static const char** Pargv = NULL;
819 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
824 if ( !ViewerTest::CurrentView().IsNull() ) {
826 WPARAM fwKeys = wParam;
831 IsDragged = Standard_False;
834 HDC hdc = GetDC( hwnd );
835 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
836 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
837 SetROP2( hdc, R2_NOT );
838 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
839 ReleaseDC( hwnd, hdc );
841 const Handle(ViewerTest_EventManager) EM =
842 ViewerTest::CurrentEventManager();
843 if ( fwKeys & MK_SHIFT )
844 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
845 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
847 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
848 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
850 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
853 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
855 IsDragged = Standard_True;
856 DragFirst = Standard_True;
857 X_ButtonPress = LOWORD(lParam);
858 Y_ButtonPress = HIWORD(lParam);
860 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
867 HDC hdc = GetDC( hwnd );
869 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
870 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
871 SetROP2( hdc, R2_NOT );
874 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
876 DragFirst = Standard_False;
877 X_Motion = LOWORD(lParam);
878 Y_Motion = HIWORD(lParam);
880 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
882 SelectObject( hdc, anObj );
884 ReleaseDC( hwnd, hdc );
887 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
891 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
895 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
899 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
904 /*static Standard_Boolean Ppick = 0;
905 static Standard_Integer Pargc = 0;
906 static char** Pargv = NULL;*/
910 if ( !ViewerTest::CurrentView().IsNull() ) {
915 // do not destroy the window - just hide it!
916 VT_GetWindow()->Unmap();
919 BeginPaint(hwnd, &ps);
925 VT_ProcessConfigure();
929 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
932 c[0] = (char) wParam;
934 VT_ProcessKeyPress (c);
942 VT_ProcessButton3Release();
949 WPARAM fwKeys = wParam;
953 X_ButtonPress = LOWORD(lParam);
954 Y_ButtonPress = HIWORD(lParam);
956 if (Msg == WM_LBUTTONDOWN)
958 if (fwKeys & MK_CONTROL)
960 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
964 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
967 else if (Msg == WM_RBUTTONDOWN)
970 VT_ProcessButton3Press();
977 //cout << "\t WM_MOUSEMOVE" << endl;
978 WPARAM fwKeys = wParam;
979 X_Motion = LOWORD(lParam);
980 Y_Motion = HIWORD(lParam);
983 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
985 X_ButtonPress = LOWORD(lParam);
986 Y_ButtonPress = HIWORD(lParam);
988 if ( fwKeys & MK_RBUTTON ) {
990 VT_ProcessButton3Press();
994 if ( fwKeys & MK_CONTROL ) {
995 if ( fwKeys & MK_LBUTTON ) {
996 ProcessControlButton1Motion();
998 else if ( fwKeys & MK_MBUTTON ||
999 ((fwKeys&MK_LBUTTON) &&
1000 (fwKeys&MK_RBUTTON) ) ){
1001 VT_ProcessControlButton2Motion();
1003 else if ( fwKeys & MK_RBUTTON ) {
1004 VT_ProcessControlButton3Motion();
1008 else if ( fwKeys & MK_SHIFT ) {
1009 if ( fwKeys & MK_MBUTTON ||
1010 ((fwKeys&MK_LBUTTON) &&
1011 (fwKeys&MK_RBUTTON) ) ) {
1012 cout << "ProcessZClipMotion()" << endl;
1013 ProcessZClipMotion();
1018 if ((fwKeys & MK_MBUTTON
1019 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1021 ProcessZClipMotion();
1031 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1036 return DefWindowProc( hwnd, Msg, wParam, lParam );
1042 //==============================================================================
1043 //function : ViewerMainLoop
1044 //purpose : Get a Event on the view and dispatch it
1045 //==============================================================================
1048 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1051 //cout << "No yet implemented on WNT" << endl;
1052 /*static Standard_Boolean Ppick = 0;
1053 static Standard_Integer Pargc = 0;
1054 static char** Pargv = NULL;*/
1056 //Ppick = (argc > 0)? -1 : 0;
1057 Ppick = (argc > 0)? 1 : 0;
1065 cout << "Start picking" << endl;
1067 //while ( Ppick == -1 ) {
1068 while ( Ppick == 1 ) {
1069 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
1070 if (GetMessage(&msg, NULL, 0, 0) ) {
1071 TranslateMessage(&msg);
1072 DispatchMessage(&msg);
1076 cout << "Picking done" << endl;
1082 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
1084 int min( int a, int b )
1092 int max( int a, int b )
1100 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1102 { Standard_Boolean pick = argc > 0;
1106 static XEvent report;
1108 XNextEvent( display, &report );
1109 // cout << "rep type = " << report.type << endl;
1110 // cout << "rep button = " << report.xbutton.button << endl;
1112 switch ( report.type ) {
1118 case ConfigureNotify:
1120 VT_ProcessConfigure();
1129 XComposeStatus status_in_out;
1131 ret_len = XLookupString( ( XKeyEvent *)&report ,
1132 (char *) buf_ret , 10 ,
1133 &ks_ret , &status_in_out ) ;
1136 buf_ret[ret_len] = '\0' ;
1140 VT_ProcessKeyPress (buf_ret);
1145 // cout << "ButtonPress" << endl;
1147 X_ButtonPress = report.xbutton.x;
1148 Y_ButtonPress = report.xbutton.y;
1150 if (report.xbutton.button == Button1)
1152 if (report.xbutton.state & ControlMask)
1154 pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
1158 IsDragged = Standard_True;
1159 X_ButtonPress = X_ButtonPress;
1160 Y_ButtonPress = Y_ButtonPress;
1161 DragFirst = Standard_True;
1164 else if (report.xbutton.button == Button3)
1167 VT_ProcessButton3Press();
1173 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1174 // cout << IsDragged << endl;
1175 // cout << DragFirst << endl;
1181 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1182 GC gc = XCreateGC( display, aWindow, 0, 0 );
1183 // XSetFunction( display, gc, GXinvert );
1184 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1187 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1188 if( aContext.IsNull() )
1190 cout << "The context is null. Please use vinit before createmesh" << endl;
1194 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1195 if( report.xbutton.button==1 )
1199 aContext->ShiftSelect();
1200 // cout << "shift select" << endl;
1205 // cout << "select" << endl;
1210 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1211 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1212 ViewerTest::CurrentView());
1213 // cout << "shift select" << endl;
1217 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1218 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1219 ViewerTest::CurrentView() );
1220 // cout << "select" << endl;
1223 VT_ProcessButton3Release();
1225 IsDragged = Standard_False;
1228 VT_ProcessButton3Release();
1235 X_Motion = report.xmotion.x;
1236 Y_Motion = report.xmotion.y;
1240 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1241 GC gc = XCreateGC( display, aWindow, 0, 0 );
1242 XSetFunction( display, gc, GXinvert );
1245 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1247 X_Motion = X_Motion;
1248 Y_Motion = Y_Motion;
1249 DragFirst = Standard_False;
1251 //cout << "draw rect : " << X_Motion << ", " << Y_Motion << endl;
1252 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1257 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1259 // remove all the ButtonMotionMask
1260 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1262 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1263 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1265 Quantity_Length VDX, VDY;
1267 ViewerTest::CurrentView()->Size(VDX,VDY);
1268 Standard_Real VDZ =0 ;
1269 VDZ = ViewerTest::CurrentView()->ZSize();
1271 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1272 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1274 Quantity_Length dx = 0 ;
1275 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1279 dx = dx / VDX * VDZ;
1283 // Front = Depth + width/2.
1284 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1285 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1287 ViewerTest::CurrentView()->Redraw();
1291 if ( report.xmotion.state & ControlMask ) {
1292 if ( report.xmotion.state & Button1Mask ) {
1293 ProcessControlButton1Motion();
1295 else if ( report.xmotion.state & Button2Mask ) {
1296 VT_ProcessControlButton2Motion();
1298 else if ( report.xmotion.state & Button3Mask ) {
1299 VT_ProcessControlButton3Motion();
1315 //==============================================================================
1316 //function : VProcessEvents
1317 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1318 // event in the Viewer window
1319 //==============================================================================
1321 static void VProcessEvents(ClientData,int)
1323 //cout << "VProcessEvents" << endl;
1326 while (XPending(display)) {
1327 ViewerMainLoop( 0, NULL);
1332 //==============================================================================
1333 //function : OSWindowSetup
1334 //purpose : Setup for the X11 window to be able to cath the event
1335 //==============================================================================
1338 static void OSWindowSetup()
1340 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1343 Window window = VT_GetWindow()->XWindow();
1345 display = GetGraphicDriver()->GetDisplayConnection()->GetDisplay();
1346 // display = (Display *)GetG3dDevice()->XDisplay();
1348 XSynchronize(display, 1);
1350 VT_GetWindow()->Map();
1352 // X11 : For keyboard on SUN
1354 wmhints.flags = InputHint;
1357 XSetWMHints( display, window, &wmhints);
1359 XSelectInput( display, window, ExposureMask | KeyPressMask |
1360 ButtonPressMask | ButtonReleaseMask |
1361 StructureNotifyMask |
1363 Button1MotionMask | Button2MotionMask |
1367 XSynchronize(display, 0);
1376 //==============================================================================
1379 //purpose : Fitall, no DRAW arguments
1380 //Draw arg : No args
1381 //==============================================================================
1383 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1385 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1386 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1387 if (V.IsNull() == Standard_False) {
1389 } else if (aView.IsNull() == Standard_False) {
1395 //==============================================================================
1397 //purpose : ZFitall, no DRAW arguments
1398 //Draw arg : No args
1399 //==============================================================================
1401 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1403 Handle(V3d_View) V = ViewerTest::CurrentView();
1404 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1407 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1409 Handle(V3d_View) V = ViewerTest::CurrentView();
1410 if ( !V.IsNull() ) V->Redraw(); return 0;
1414 //==============================================================================
1416 //purpose : Remove all the object from the viewer
1417 //Draw arg : No args
1418 //==============================================================================
1420 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1422 Handle(V3d_View) V = ViewerTest::CurrentView();
1424 ViewerTest::Clear();
1428 //==============================================================================
1431 //==============================================================================
1433 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1434 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1437 di << argv[0] << "Invalid number of arguments" << "\n";
1441 while (ViewerMainLoop( argc, argv)) {
1447 //==============================================================================
1448 //function : InitViewerTest
1449 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1450 //==============================================================================
1452 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1454 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1455 ViewerTest::SetAISContext(context);
1456 viewer->InitActiveViews();
1457 Handle(V3d_View) view = viewer->ActiveView();
1458 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1459 ViewerTest::ResetEventManager();
1460 Handle(Aspect_Window) window = view->Window();
1461 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1463 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1464 GetGraphicDriver() = viewer->Driver();
1466 static int first = 1;
1468 #if TCL_MAJOR_VERSION < 8
1469 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1470 TK_READABLE, VProcessEvents, (ClientData) 0);
1472 Tk_CreateFileHandler(ConnectionNumber(display),
1473 TK_READABLE, VProcessEvents, (ClientData) 0);
1480 //==============================================================================
1482 //purpose : Load image as background
1483 //==============================================================================
1485 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1487 if (argc < 2 || argc > 3)
1489 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1490 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1494 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1495 if(AISContext.IsNull())
1497 di << "use 'vinit' command before " << argv[0] << "\n";
1501 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1504 const char* szType = argv[2];
1505 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1506 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1507 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1508 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1511 di << "Wrong fill type : " << szType << "\n";
1512 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1517 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1518 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1523 //==============================================================================
1524 //function : VSetBgMode
1525 //purpose : Change background image fill type
1526 //==============================================================================
1528 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1532 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1533 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1537 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1538 if(AISContext.IsNull())
1540 di << "use 'vinit' command before " << argv[0] << "\n";
1544 Aspect_FillMethod aFillType;
1547 const char* szType = argv[1];
1548 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1549 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1550 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1551 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1554 di << "Wrong fill type : " << szType << "\n";
1555 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1560 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1561 V3dView->SetBgImageStyle(aFillType, Standard_True);
1566 //==============================================================================
1567 //function : VSetGradientBg
1568 //purpose : Mount gradient background
1569 //==============================================================================
1570 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1574 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1575 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1576 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1577 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1581 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1582 if(AISContext.IsNull())
1584 di << "use 'vinit' command before " << argv[0] << "\n";
1590 Standard_Real R1 = Draw::Atof(argv[1])/255.;
1591 Standard_Real G1 = Draw::Atof(argv[2])/255.;
1592 Standard_Real B1 = Draw::Atof(argv[3])/255.;
1593 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1595 Standard_Real R2 = Draw::Atof(argv[4])/255.;
1596 Standard_Real G2 = Draw::Atof(argv[5])/255.;
1597 Standard_Real B2 = Draw::Atof(argv[6])/255.;
1599 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1600 int aType = Draw::Atoi(argv[7]);
1601 if( aType < 0 || aType > 8 )
1603 di << "Wrong fill type " << "\n";
1604 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1605 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1609 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1611 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1612 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1618 //==============================================================================
1619 //function : VSetGradientBgMode
1620 //purpose : Change gradient background fill style
1621 //==============================================================================
1622 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1626 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1627 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1628 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1632 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1633 if(AISContext.IsNull())
1635 di << "use 'vinit' command before " << argv[0] << "\n";
1640 int aType = Draw::Atoi(argv[1]);
1641 if( aType < 0 || aType > 8 )
1643 di << "Wrong fill type " << "\n";
1644 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1645 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1649 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1651 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1652 V3dView->SetBgGradientStyle( aMethod, 1 );
1658 //==============================================================================
1659 //function : VSetColorBg
1660 //purpose : Set color background
1661 //==============================================================================
1662 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1666 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1667 di << "R,G,B = [0..255]" << "\n";
1671 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1672 if(AISContext.IsNull())
1674 di << "use 'vinit' command before " << argv[0] << "\n";
1680 Standard_Real R = Draw::Atof(argv[1])/255.;
1681 Standard_Real G = Draw::Atof(argv[2])/255.;
1682 Standard_Real B = Draw::Atof(argv[3])/255.;
1683 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1685 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1686 V3dView->SetBackgroundColor( aColor );
1693 //==============================================================================
1695 //purpose : View Scaling
1696 //==============================================================================
1698 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1700 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1701 if ( V3dView.IsNull() ) return 1;
1704 di << argv[0] << "Invalid number of arguments" << "\n";
1707 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1710 //==============================================================================
1711 //function : VTestZBuffTrihedron
1712 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1713 //==============================================================================
1715 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1717 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1718 if ( V3dView.IsNull() ) return 1;
1720 V3dView->ZBufferTriedronSetup();
1723 // Set up default trihedron parameters
1724 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1728 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1729 const char* aPosType = argv[1];
1731 if ( strcmp(aPosType, "center") == 0 )
1733 aPosition = Aspect_TOTP_CENTER;
1735 if (strcmp(aPosType, "left_lower") == 0)
1737 aPosition = Aspect_TOTP_LEFT_LOWER;
1739 if (strcmp(aPosType, "left_upper") == 0)
1741 aPosition = Aspect_TOTP_LEFT_UPPER;
1743 if (strcmp(aPosType, "right_lower") == 0)
1745 aPosition = Aspect_TOTP_RIGHT_LOWER;
1747 if (strcmp(aPosType, "right_upper") == 0)
1749 aPosition = Aspect_TOTP_RIGHT_UPPER;
1752 di << argv[1] << " Invalid type of alignment" << "\n";
1753 di << "Must be one of [ center, left_lower," << "\n";
1754 di << "left_upper, right_lower, right_upper ]" << "\n";
1758 Standard_Real R = Draw::Atof(argv[2])/255.;
1759 Standard_Real G = Draw::Atof(argv[3])/255.;
1760 Standard_Real B = Draw::Atof(argv[4])/255.;
1761 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1763 Standard_Real aScale = Draw::Atof(argv[5]);
1767 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1771 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1772 const char* aPresType = argv[6];
1774 if ( strcmp(aPresType, "wireframe") == 0 )
1776 aPresentation = V3d_WIREFRAME;
1778 if (strcmp(aPresType, "zbuffer") == 0)
1780 aPresentation = V3d_ZBUFFER;
1783 di << argv[6] << " Invalid type of visualization" << "\n";
1784 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1788 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1792 di << argv[0] << " Invalid number of arguments" << "\n";
1801 //==============================================================================
1802 //function : VRotate
1803 //purpose : Camera Rotating
1804 //==============================================================================
1806 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1807 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1808 if ( V3dView.IsNull() ) {
1813 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1815 } else if ( argc == 7 ) {
1816 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Draw::Atof(argv[6]) );
1819 di << argv[0] << " Invalid number of arguments" << "\n";
1824 //==============================================================================
1826 //purpose : View zoom in / out (relative to current zoom)
1827 //==============================================================================
1829 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1830 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1831 if ( V3dView.IsNull() ) {
1836 Standard_Real coef = Draw::Atof(argv[1]);
1837 if ( coef <= 0.0 ) {
1838 di << argv[1] << "Invalid value" << "\n";
1841 V3dView->SetZoom( Draw::Atof(argv[1]) );
1844 di << argv[0] << " Invalid number of arguments" << "\n";
1849 //==============================================================================
1851 //purpose : View panning (in pixels)
1852 //==============================================================================
1854 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1855 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1856 if ( V3dView.IsNull() ) return 1;
1859 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
1862 di << argv[0] << " Invalid number of arguments" << "\n";
1868 //==============================================================================
1869 //function : VExport
1870 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
1871 //==============================================================================
1873 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1875 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1876 if (V3dView.IsNull())
1881 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
1885 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1886 TCollection_AsciiString aFormatStr;
1888 TCollection_AsciiString aFileName (argv[1]);
1889 Standard_Integer aLen = aFileName.Length();
1893 aFormatStr = TCollection_AsciiString (argv[2]);
1897 if (aFileName.Value (aLen - 2) == '.')
1899 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1901 else if (aFileName.Value (aLen - 3) == '.')
1903 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1907 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1913 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1917 aFormatStr.UpperCase();
1918 if (aFormatStr == "PS")
1919 anExpFormat = Graphic3d_EF_PostScript;
1920 else if (aFormatStr == "EPS")
1921 anExpFormat = Graphic3d_EF_EnhPostScript;
1922 else if (aFormatStr == "TEX")
1923 anExpFormat = Graphic3d_EF_TEX;
1924 else if (aFormatStr == "PDF")
1925 anExpFormat = Graphic3d_EF_PDF;
1926 else if (aFormatStr == "SVG")
1927 anExpFormat = Graphic3d_EF_SVG;
1928 else if (aFormatStr == "PGF")
1929 anExpFormat = Graphic3d_EF_PGF;
1930 else if (aFormatStr == "EMF")
1931 anExpFormat = Graphic3d_EF_EMF;
1934 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1938 if (!V3dView->View()->Export (argv[1], anExpFormat))
1940 std::cout << "Export failed!\n";
1946 //==============================================================================
1947 //function : VColorScale
1948 //purpose : representation color scale
1949 //==============================================================================
1950 #include <V3d_ColorScale.hxx>
1952 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1954 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1956 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1960 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1961 if(aContext.IsNull()) {
1962 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1966 Standard_Real minRange = 0. , maxRange = 100. ;
1968 Standard_Integer numIntervals = 10 ;
1969 Standard_Integer textHeight = 16;
1970 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1971 Standard_Real X = 0., Y = 0. ;
1977 minRange = Draw::Atof( argv[1] );
1978 maxRange = Draw::Atof( argv[2] );
1979 numIntervals = Draw::Atoi( argv[3] );
1982 textHeight = Draw::Atoi( argv[4] );
1984 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
1987 X = Draw::Atof( argv[6] );
1988 Y = Draw::Atof( argv[7] );
1991 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1992 if ( curView.IsNull( ) )
1994 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1995 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1996 if( ! aCS.IsNull( ) )
1998 aCS->SetPosition( X , Y );
1999 aCS->SetHeight( 0.95) ;
2000 aCS->SetTextHeight( textHeight );
2001 aCS->SetRange( minRange , maxRange );
2002 aCS->SetNumberOfIntervals( numIntervals );
2003 aCS->SetLabelPosition( position );
2004 if( !curView->ColorScaleIsDisplayed() )
2005 curView->ColorScaleDisplay( );
2010 //==============================================================================
2011 //function : VGraduatedTrihedron
2012 //purpose : Displays a graduated trihedron
2013 //==============================================================================
2015 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2017 const char *str = arg;
2020 unsigned short c1 = *str++;
2021 unsigned short c2 = *str++;
2022 if (!c1 || !c2) break;
2023 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2027 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2030 if (argc != 2 && argc < 5)
2032 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2033 di<<"Usage: type help "<<argv[0]<<"\n";
2034 return 1; //TCL_ERROR
2037 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2039 // Create 3D view if it doesn't exist
2040 if ( aV3dView.IsNull() )
2042 ViewerTest::ViewerInit();
2043 aV3dView = ViewerTest::CurrentView();
2044 if( aV3dView.IsNull() )
2046 di << "Error: Cannot create a 3D view\n";
2047 return 1; //TCL_ERROR
2051 // Erase (==0) or display (!=0)
2052 const int display = Draw::Atoi(argv[1]);
2057 TCollection_AsciiString font;
2059 font.AssignCat("Courier");
2061 font.AssignCat(argv[5]);
2063 // Text is multibyte
2064 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
2067 TCollection_ExtendedString xname, yname, zname;
2072 AddMultibyteString(xname, argv[2]);
2073 AddMultibyteString(yname, argv[3]);
2074 AddMultibyteString(zname, argv[4]);
2090 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2091 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2092 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2093 Standard_True/*drawgrid*/,
2094 Standard_True/*drawaxes*/,
2095 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2096 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2097 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2098 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2099 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2100 Quantity_NOC_WHITE/*gridcolor*/,
2101 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2102 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2105 aV3dView->GraduatedTrihedronErase();
2107 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2113 //==============================================================================
2114 //function : VPrintView
2115 //purpose : Test printing algorithm, print the view to image file with given
2116 // width and height. Printing implemented only for WNT.
2117 //==============================================================================
2118 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2122 di << "Printing implemented only for wnt!\n";
2126 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2127 Handle(V3d_View) aView = NULL;
2128 aContextAIS = ViewerTest::GetAISContext();
2129 if (!aContextAIS.IsNull())
2131 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2132 Vwr->InitActiveViews();
2133 if(Vwr->MoreActiveViews())
2134 aView = Vwr->ActiveView();
2140 di << "Call vinit before!\n";
2145 di << "Use: " << argv[0];
2146 di << " width height filename [print algo=0]\n";
2147 di << "width, height of the intermediate buffer for operation\n";
2148 di << "algo : {0|1}\n";
2149 di << " 0 - stretch algorithm\n";
2150 di << " 1 - tile algorithm\n";
2151 di << "test printing algorithms into an intermediate buffer\n";
2152 di << "with saving output to an image file\n";
2156 // get the input params
2157 Standard_Integer aWidth = Draw::Atoi (argv[1]);
2158 Standard_Integer aHeight = Draw::Atoi (argv[2]);
2159 Standard_Integer aMode = 0;
2160 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2162 aMode = Draw::Atoi (argv[4]);
2164 // check the input parameters
2165 if (aWidth <= 0 || aHeight <= 0)
2167 di << "Width and height must be positive values!\n";
2170 if (aMode != 0 && aMode != 1)
2173 // define compatible bitmap
2174 HDC anDC = CreateCompatibleDC(0);
2175 BITMAPINFO aBitmapData;
2176 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2177 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2178 aBitmapData.bmiHeader.biWidth = aWidth ;
2179 aBitmapData.bmiHeader.biHeight = aHeight;
2180 aBitmapData.bmiHeader.biPlanes = 1;
2181 aBitmapData.bmiHeader.biBitCount = 24;
2182 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2183 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2184 aBitmapData.bmiHeader.biClrUsed = 0;
2185 aBitmapData.bmiHeader.biClrImportant = 0;
2186 aBitmapData.bmiHeader.biCompression = BI_RGB;
2187 aBitmapData.bmiHeader.biSizeImage = 0;
2189 // Create Device Independent Bitmap
2190 void* aBitsOut = NULL;
2191 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2192 &aBitsOut, NULL, 0);
2193 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2195 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2196 if (aBitsOut != NULL)
2199 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2201 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2203 // succesfully printed into an intermediate buffer
2206 Image_PixMap aWrapper;
2207 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2208 aWrapper.SetTopDown (false);
2210 Image_AlienPixMap anImageBitmap;
2211 anImageBitmap.InitCopy (aWrapper);
2212 isSaved = anImageBitmap.Save (aFileName);
2216 di << "Print operation failed due to printing errors or\n";
2217 di << "insufficient memory available\n";
2218 di << "Please, try to use smaller dimensions for this test\n";
2219 di << "command, as it allocates intermediate buffer for storing\n";
2220 di << "the result\n";
2225 di << "Can't allocate memory for intermediate buffer\n";
2226 di << "Please use smaller dimensions\n";
2231 SelectObject (anDC, anOldBitmap);
2232 DeleteObject (aMemoryBitmap);
2238 di << "Save to file operation failed. This operation may fail\n";
2239 di << "if you don't have enough available memory, then you can\n";
2240 di << "use smaller dimensions for the output file\n";
2249 //==============================================================================
2250 //function : VZLayer
2251 //purpose : Test z layer operations for v3d viewer
2252 //==============================================================================
2253 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2255 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2256 if (aContextAIS.IsNull())
2258 di << "Call vinit before!\n";
2263 di << "Use: vzlayer " << argv[0];
2264 di << " add/del/get [id]\n";
2265 di << " add - add new z layer to viewer and print its id\n";
2266 di << " del - del z layer by its id\n";
2267 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2268 di << "id - the layer identificator value defined when removing z layer\n";
2272 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2273 if (aViewer.IsNull())
2275 di << "No active viewer!\n";
2279 // perform operation
2280 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2283 Standard_Integer aNewId;
2284 if (!aViewer->AddZLayer (aNewId))
2286 di << "Impossible to add new z layer!\n";
2290 di << "New z layer added with index: " << aNewId << "\n";
2292 else if (anOp == "del")
2296 di << "Please also provide as argument id of z layer to remove\n";
2300 Standard_Integer aDelId = Draw::Atoi (argv[2]);
2301 if (!aViewer->RemoveZLayer (aDelId))
2303 di << "Impossible to remove the z layer or invalid id!\n";
2307 di << "Z layer " << aDelId << " has been removed\n";
2309 else if (anOp == "get")
2311 TColStd_SequenceOfInteger anIds;
2312 aViewer->GetAllZLayers (anIds);
2313 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2315 di << anIds.Value (aSeqIdx) << " ";
2322 di << "Invalid operation, please use { add / del / get }\n";
2329 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2331 // this class provides a presentation of text item in v3d view under-/overlayer
2332 class V3d_TextItem : public Visual3d_LayerItem
2337 DEFINE_STANDARD_RTTI(V3d_TextItem)
2340 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2341 const Standard_Real theX1,
2342 const Standard_Real theY1,
2343 const Standard_Real theHeight,
2344 const TCollection_AsciiString& theFontName,
2345 const Quantity_Color& theColor,
2346 const Quantity_Color& theSubtitleColor,
2347 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2348 const Handle(Visual3d_Layer)& theLayer);
2351 Standard_EXPORT void RedrawLayerPrs();
2357 Standard_Real myHeight;
2358 TCollection_AsciiString myText;
2359 TCollection_AsciiString myFontName;
2360 Quantity_Color myColor;
2361 Quantity_Color mySubtitleColor;
2362 Aspect_TypeOfDisplayText myType;
2363 Handle(Visual3d_Layer) myLayer;
2367 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2368 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2370 // create and add to display the text item
2371 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2372 const Standard_Real theX1,
2373 const Standard_Real theY1,
2374 const Standard_Real theHeight,
2375 const TCollection_AsciiString& theFontName,
2376 const Quantity_Color& theColor,
2377 const Quantity_Color& theSubtitleColor,
2378 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2379 const Handle(Visual3d_Layer)& theLayer)
2380 : myX1 (theX1), myY1 (theY1),
2382 myHeight (theHeight),
2385 mySubtitleColor (theSubtitleColor),
2386 myType (theTypeOfDisplay),
2387 myFontName (theFontName)
2389 if (!myLayer.IsNull ())
2390 myLayer->AddLayerItem (this);
2394 void V3d_TextItem::RedrawLayerPrs ()
2396 if (myLayer.IsNull ())
2399 myLayer->SetColor (myColor);
2400 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2401 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2404 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2406 // The Visual3d_LayerItem line item for "vlayerline" command
2407 // it provides a presentation of line with user-defined
2408 // linewidth, linetype and transparency.
2409 class V3d_LineItem : public Visual3d_LayerItem
2413 DEFINE_STANDARD_RTTI(V3d_LineItem)
2416 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2417 Standard_Real X2, Standard_Real Y2,
2418 V3d_LayerMgrPointer theLayerMgr,
2419 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2420 Standard_Real theWidth = 0.5,
2421 Standard_Real theTransp = 1.0);
2424 Standard_EXPORT void RedrawLayerPrs();
2428 Standard_Real myX1, myY1, myX2, myY2;
2429 Standard_Real myWidth;
2430 Standard_Real myTransparency;
2431 Aspect_TypeOfLine myType;
2432 V3d_LayerMgrPointer myLayerMgr;
2435 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2436 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2438 // default constructor for line item
2439 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2440 Standard_Real X2, Standard_Real Y2,
2441 V3d_LayerMgrPointer theLayerMgr,
2442 Aspect_TypeOfLine theType,
2443 Standard_Real theWidth,
2444 Standard_Real theTransp) :
2445 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2446 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2448 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
2449 myLayerMgr->Overlay()->AddLayerItem (this);
2453 void V3d_LineItem::RedrawLayerPrs ()
2455 Handle (Visual3d_Layer) aOverlay;
2458 aOverlay = myLayerMgr->Overlay();
2460 if (!aOverlay.IsNull())
2462 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2463 aOverlay->SetColor(aColor);
2464 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2465 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2466 aOverlay->BeginPolyline();
2467 aOverlay->AddVertex(myX1, myY1);
2468 aOverlay->AddVertex(myX2, myY2);
2469 aOverlay->ClosePrimitive();
2473 //=============================================================================
2474 //function : VLayerLine
2475 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2476 // : linewidth, transparency coefficient
2477 //============================================================================
2478 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2480 // get the active view
2481 Handle(V3d_View) aView = ViewerTest::CurrentView();
2484 di << "Call vinit before!\n";
2489 di << "Use: " << argv[0];
2490 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2491 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2492 di << " 0 - solid \n";
2493 di << " 1 - dashed \n";
2494 di << " 2 - dot \n";
2495 di << " 3 - dashdot\n";
2496 di << " transparency : { 0.0 - 1.0 } \n";
2497 di << " 0.0 - transparent\n";
2498 di << " 1.0 - visible \n";
2502 // get the input params
2503 Standard_Real X1 = Draw::Atof(argv[1]);
2504 Standard_Real Y1 = Draw::Atof(argv[2]);
2505 Standard_Real X2 = Draw::Atof(argv[3]);
2506 Standard_Real Y2 = Draw::Atof(argv[4]);
2508 Standard_Real aWidth = 0.5;
2509 Standard_Integer aType = 0;
2510 Standard_Real aTransparency = 1.0;
2514 aWidth = Draw::Atof(argv[5]);
2518 aType = (Standard_Integer) Draw::Atoi(argv[6]);
2523 aTransparency = Draw::Atof(argv[7]);
2524 if (aTransparency < 0 || aTransparency > 1.0)
2525 aTransparency = 1.0;
2528 // select appropriate line type
2529 Aspect_TypeOfLine aLineType;
2533 aLineType = Aspect_TOL_DASH;
2537 aLineType = Aspect_TOL_DOT;
2541 aLineType = Aspect_TOL_DOTDASH;
2545 aLineType = Aspect_TOL_SOLID;
2548 // replace layer manager
2549 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2550 aView->SetLayerMgr(aMgr);
2553 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2559 aView->MustBeResized();
2565 //=======================================================================
2566 //function : VOverlayText
2567 //purpose : Test text displaying in view overlay
2568 //=======================================================================
2569 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2571 // get the active view
2572 Handle(V3d_View) aView = ViewerTest::CurrentView();
2575 di << "No active view. Please call vinit.\n";
2578 else if (argc < 4 || argc > 13)
2580 di << "Use: " << argv[0];
2581 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2582 di << "[background_color: R G B]\n";
2583 di << " height - pixel height of the text (default=10.0)\n";
2584 di << " font_name - name of font (default=courier)\n";
2585 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2586 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2587 di << " background_color- R G B values used for subtitle and decal text\n";
2588 di << "(default=255.0 255.0 255.0)\n";
2592 TCollection_AsciiString aText (argv[1]);
2593 Standard_Real aPosX = Draw::Atof(argv[2]);
2594 Standard_Real aPosY = Draw::Atof(argv[3]);
2595 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
2598 TCollection_AsciiString aFontName = "Courier";
2600 aFontName = TCollection_AsciiString (argv[5]);
2603 Quantity_Parameter aColorRed = 1.0;
2604 Quantity_Parameter aColorGreen = 1.0;
2605 Quantity_Parameter aColorBlue = 1.0;
2608 aColorRed = Draw::Atof (argv[6])/255.;
2609 aColorGreen = Draw::Atof (argv[7])/255.;
2610 aColorBlue = Draw::Atof (argv[8])/255.;
2614 TCollection_AsciiString aDispStr;
2616 aDispStr = TCollection_AsciiString (argv[9]);
2618 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2619 if (aDispStr.IsEqual ("subtitle"))
2620 aTextType = Aspect_TODT_SUBTITLE;
2621 else if (aDispStr.IsEqual ("decal"))
2622 aTextType = Aspect_TODT_DEKALE;
2623 else if (aDispStr.IsEqual ("blend"))
2624 aTextType = Aspect_TODT_BLEND;
2627 Quantity_Parameter aSubRed = 1.0;
2628 Quantity_Parameter aSubGreen = 1.0;
2629 Quantity_Parameter aSubBlue = 1.0;
2632 aSubRed = Draw::Atof (argv[10])/255.;
2633 aSubGreen = Draw::Atof (argv[11])/255.;
2634 aSubBlue = Draw::Atof (argv[12])/255.;
2637 // check fo current overlay
2638 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2639 if (anOverlay.IsNull ())
2641 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2642 anOverlay = aMgr->Overlay ();
2643 aView->SetLayerMgr (aMgr);
2646 Quantity_Color aTextColor (aColorRed, aColorGreen,
2647 aColorBlue, Quantity_TOC_RGB);
2648 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2649 aSubBlue, Quantity_TOC_RGB);
2652 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2653 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2656 aView->MustBeResized();
2662 //==============================================================================
2665 //==============================================================================
2667 static int VGrid (Draw_Interpretor& theDI,
2668 Standard_Integer theArgNb,
2669 const char** theArgVec)
2671 // get the active view
2672 Handle(V3d_View) aView = ViewerTest::CurrentView();
2673 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2674 if (aView.IsNull() || aViewer.IsNull())
2676 std::cerr << "No active view. Please call vinit.\n";
2680 Aspect_GridType aType = aViewer->GridType();
2681 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2683 Standard_Integer anIter = 1;
2684 for (; anIter < theArgNb; ++anIter)
2686 const char* aValue = theArgVec[anIter];
2689 aType = Aspect_GT_Rectangular;
2691 else if (*aValue == 'c')
2693 aType = Aspect_GT_Circular;
2695 else if (*aValue == 'l')
2697 aMode = Aspect_GDM_Lines;
2699 else if (*aValue == 'p')
2701 aMode = Aspect_GDM_Points;
2703 else if (strcmp (aValue, "off" ) == 0)
2705 aViewer->DeactivateGrid();
2714 Standard_Integer aTail = (theArgNb - anIter);
2717 aViewer->ActivateGrid (aType, aMode);
2720 else if (aTail != 2 && aTail != 5)
2722 std::cerr << "Incorrect arguments number! Usage:\n"
2723 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2727 Quantity_Length anOriginX, anOriginY;
2728 Quantity_PlaneAngle aRotAngle;
2729 if (aType == Aspect_GT_Rectangular)
2731 Quantity_Length aRStepX, aRStepY;
2732 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2734 anOriginX = Draw::Atof (theArgVec[anIter++]);
2735 anOriginY = Draw::Atof (theArgVec[anIter++]);
2738 aRStepX = Draw::Atof (theArgVec[anIter++]);
2739 aRStepY = Draw::Atof (theArgVec[anIter++]);
2740 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2742 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2743 aViewer->ActivateGrid (aType, aMode);
2745 else if (aType == Aspect_GT_Circular)
2747 Quantity_Length aRadiusStep;
2748 Standard_Integer aDivisionNumber;
2749 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2751 anOriginX = Draw::Atof (theArgVec[anIter++]);
2752 anOriginY = Draw::Atof (theArgVec[anIter++]);
2755 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
2756 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
2757 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2760 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2761 aViewer->ActivateGrid (aType, aMode);
2767 //==============================================================================
2770 //==============================================================================
2772 static int VFps (Draw_Interpretor& theDI,
2773 Standard_Integer theArgNb,
2774 const char** theArgVec)
2776 // get the active view
2777 Handle(V3d_View) aView = ViewerTest::CurrentView();
2780 std::cerr << "No active view. Please call vinit.\n";
2784 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
2787 std::cerr << "Incorrect arguments!\n";
2791 // the time is meaningless for first call
2792 // due to async OpenGl rendering
2795 // redraw view in loop to estimate average values
2798 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2804 const Standard_Real aTime = aTimer.ElapsedTime();
2805 aTimer.OSD_Chronometer::Show (aCpu);
2807 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2808 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2810 // return statistics
2811 theDI << "FPS: " << aFpsAver << "\n"
2812 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2818 //==============================================================================
2821 //==============================================================================
2823 static int VVbo (Draw_Interpretor& theDI,
2824 Standard_Integer theArgNb,
2825 const char** theArgVec)
2828 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2829 if (aContextAIS.IsNull())
2831 std::cerr << "No active view. Please call vinit.\n";
2835 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
2837 if (aDriver.IsNull())
2839 std::cerr << "Graphic driver not available.\n";
2845 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2847 std::cerr << "Wrong number of arguments.\n";
2851 aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
2855 //==============================================================================
2856 //function : VMemGpu
2858 //==============================================================================
2860 static int VMemGpu (Draw_Interpretor& theDI,
2861 Standard_Integer theArgNb,
2862 const char** theArgVec)
2865 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2866 if (aContextAIS.IsNull())
2868 std::cerr << "No active view. Please call vinit.\n";
2872 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
2874 if (aDriver.IsNull())
2876 std::cerr << "Graphic driver not available.\n";
2880 Standard_Size aFreeBytes = 0;
2881 TCollection_AsciiString anInfo;
2882 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
2884 std::cerr << "Information not available.\n";
2888 if (theArgNb > 1 && *theArgVec[1] == 'f')
2890 theDI << Standard_Real (aFreeBytes);
2900 // ==============================================================================
2901 // function : VReadPixel
2903 // ==============================================================================
2904 static int VReadPixel (Draw_Interpretor& theDI,
2905 Standard_Integer theArgNb,
2906 const char** theArgVec)
2908 // get the active view
2909 Handle(V3d_View) aView = ViewerTest::CurrentView();
2912 std::cerr << "No active view. Please call vinit.\n";
2915 else if (theArgNb < 3)
2917 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
2921 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2922 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
2924 Standard_Integer aWidth, aHeight;
2925 aView->Window()->Size (aWidth, aHeight);
2926 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
2927 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
2928 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
2930 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
2934 Standard_Boolean toShowName = Standard_False;
2935 Standard_Boolean toShowHls = Standard_False;
2936 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
2938 TCollection_AsciiString aParam (theArgVec[anIter]);
2939 if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb")))
2941 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2942 aBufferType = Graphic3d_BT_RGB;
2944 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
2946 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2947 aBufferType = Graphic3d_BT_RGB;
2948 toShowHls = Standard_True;
2950 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
2952 aFormat = Image_PixMap::ImgRGBF;
2953 aBufferType = Graphic3d_BT_RGB;
2955 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
2957 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2958 aBufferType = Graphic3d_BT_RGBA;
2960 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
2962 aFormat = Image_PixMap::ImgRGBAF;
2963 aBufferType = Graphic3d_BT_RGBA;
2965 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
2967 aFormat = Image_PixMap::ImgGrayF;
2968 aBufferType = Graphic3d_BT_Depth;
2970 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
2972 toShowName = Standard_True;
2976 Image_PixMap anImage;
2977 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
2979 std::cerr << "Image allocation failed\n";
2982 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
2984 std::cerr << "Image dump failed\n";
2988 Quantity_Parameter anAlpha;
2989 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
2992 if (aBufferType == Graphic3d_BT_RGBA)
2994 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
2998 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3003 switch (aBufferType)
3006 case Graphic3d_BT_RGB:
3010 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3014 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3018 case Graphic3d_BT_RGBA:
3020 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3023 case Graphic3d_BT_Depth:
3025 theDI << aColor.Red() << "\n";
3034 //==============================================================================
3035 //function : VDiffImage
3036 //purpose : The draw-command compares two images.
3037 //==============================================================================
3039 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3043 theDI << "Not enough arguments.\n";
3048 const char* anImgPathRef = theArgVec[1];
3049 const char* anImgPathNew = theArgVec[2];
3051 // get string tolerance and check its validity
3052 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
3053 if (aTolColor < 0.0)
3055 if (aTolColor > 1.0)
3058 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
3059 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
3061 // image file of difference
3062 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3064 // compare the images
3065 Image_Diff aComparer;
3066 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3071 aComparer.SetColorTolerance (aTolColor);
3072 aComparer.SetBorderFilterOn (isBorderFilterOn);
3073 Standard_Integer aDiffColorsNb = aComparer.Compare();
3074 theDI << aDiffColorsNb << "\n";
3076 // save image of difference
3077 if (aDiffImagePath != NULL)
3079 aComparer.SaveDiffImage (aDiffImagePath);
3085 //=======================================================================
3086 //function : VSelect
3087 //purpose : Emulates different types of selection by mouse:
3088 // 1) single click selection
3089 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
3090 // 3) selection with polygon having corners at
3091 // pixel positions (x1,y1),...,(xn,yn)
3092 // 4) any of these selections with shift button pressed
3093 //=======================================================================
3094 static Standard_Integer VSelect (Draw_Interpretor& di,
3095 Standard_Integer argc,
3100 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
3104 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
3105 if(myAIScontext.IsNull())
3107 di << "use 'vinit' command before " << argv[0] << "\n";
3110 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
3111 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
3112 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
3115 if(isShiftSelection)
3116 aCurrentEventManager->ShiftSelect();
3118 aCurrentEventManager->Select();
3122 if(isShiftSelection)
3123 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3125 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3129 Standard_Integer anUpper = 0;
3131 if(isShiftSelection)
3132 anUpper = (argc-1)/2;
3135 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
3137 for(Standard_Integer i=1;i<=anUpper;++i)
3138 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
3140 if(isShiftSelection)
3141 aCurrentEventManager->ShiftSelect(aPolyline);
3143 aCurrentEventManager->Select(aPolyline);
3148 //=======================================================================
3149 //function : VMoveTo
3150 //purpose : Emulates cursor movement to defined pixel position
3151 //=======================================================================
3152 static Standard_Integer VMoveTo (Draw_Interpretor& di,
3153 Standard_Integer argc,
3158 di << "Usage : " << argv[0] << " x y" << "\n";
3162 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3163 if(aContext.IsNull())
3165 di << "use 'vinit' command before " << argv[0] << "\n";
3168 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
3172 //=======================================================================
3173 //function : VViewParams
3174 //purpose : Gets or sets AIS View characteristics
3175 //=======================================================================
3176 static Standard_Integer VViewParams (Draw_Interpretor& di,
3177 Standard_Integer argc,
3180 if ( argc != 1 && argc != 13)
3182 di << "Usage : " << argv[0] << "\n";
3185 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
3186 if ( anAISView.IsNull () )
3188 di << "use 'vinit' command before " << argv[0] << "\n";
3192 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
3193 Standard_Real anAISViewCenterCoordinateX = 0.0;
3194 Standard_Real anAISViewCenterCoordinateY = 0.0;
3195 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3196 Standard_Real anAISViewProjX = 0.0;
3197 Standard_Real anAISViewProjY = 0.0;
3198 Standard_Real anAISViewProjZ = 0.0;
3199 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3200 Standard_Real anAISViewUpX = 0.0;
3201 Standard_Real anAISViewUpY = 0.0;
3202 Standard_Real anAISViewUpZ = 0.0;
3203 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3204 Standard_Real anAISViewAtX = 0.0;
3205 Standard_Real anAISViewAtY = 0.0;
3206 Standard_Real anAISViewAtZ = 0.0;
3207 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3208 di << "Scale of current view: " << anAISViewScale << "\n";
3209 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
3210 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
3211 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
3212 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
3216 Quantity_Factor anAISViewScale = atof (argv [1]);
3217 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
3218 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
3219 Standard_Real anAISViewProjX = atof (argv [4]);
3220 Standard_Real anAISViewProjY = atof (argv [5]);
3221 Standard_Real anAISViewProjZ = atof (argv [6]);
3222 Standard_Real anAISViewUpX = atof (argv [7]);
3223 Standard_Real anAISViewUpY = atof (argv [8]);
3224 Standard_Real anAISViewUpZ = atof (argv [9]);
3225 Standard_Real anAISViewAtX = atof (argv [10]);
3226 Standard_Real anAISViewAtY = atof (argv [11]);
3227 Standard_Real anAISViewAtZ = atof (argv [12]);
3228 anAISView -> V3d_View::SetScale (anAISViewScale);
3229 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3230 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3231 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3232 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3237 //=======================================================================
3238 //function : VChangeSelected
3239 //purpose : Adds the shape to selection or remove one from it
3240 //=======================================================================
3241 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
3242 Standard_Integer argc,
3247 di<<"Usage : " << argv[0] << " shape \n";
3251 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3252 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3253 TCollection_AsciiString aName(argv[1]);
3254 Handle(AIS_InteractiveObject) anAISObject;
3256 if(!aMap.IsBound2(aName))
3258 di<<"Use 'vdisplay' before";
3263 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
3264 if(anAISObject.IsNull()){
3265 di<<"No interactive object \n";
3269 if(aContext->HasOpenedContext())
3271 aContext->AddOrRemoveSelected(anAISObject);
3275 aContext->AddOrRemoveCurrentObject(anAISObject);
3281 //=======================================================================
3282 //function : VZClipping
3283 //purpose : Gets or sets ZClipping mode, width and depth
3284 //=======================================================================
3285 static Standard_Integer VZClipping (Draw_Interpretor& di,
3286 Standard_Integer argc,
3291 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3292 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3295 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3296 if(aContext.IsNull())
3298 di << "use 'vinit' command before " << argv[0] << "\n";
3301 Handle(V3d_View) aView = ViewerTest::CurrentView();
3302 V3d_TypeOfZclipping aZClippingMode;
3305 TCollection_AsciiString aZClippingModeString;
3306 Quantity_Length aDepth, aWidth;
3307 aZClippingMode = aView->ZClipping(aDepth, aWidth);
3308 switch (aZClippingMode)
3311 aZClippingModeString.Copy("OFF");
3314 aZClippingModeString.Copy("BACK");
3317 aZClippingModeString.Copy("FRONT");
3320 aZClippingModeString.Copy("SLICE");
3323 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
3326 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
3327 << "ZClipping depth = " << aDepth << "\n"
3328 << "ZClipping width = " << aWidth << "\n";
3334 Standard_Integer aStatus = 0;
3335 if ( strcmp (argv [1], "OFF") == 0 ) {
3337 aZClippingMode = V3d_OFF;
3339 if ( strcmp (argv [1], "BACK") == 0 ) {
3341 aZClippingMode = V3d_BACK;
3343 if ( strcmp (argv [1], "FRONT") == 0 ) {
3345 aZClippingMode = V3d_FRONT;
3347 if ( strcmp (argv [1], "SLICE") == 0 ) {
3349 aZClippingMode = V3d_SLICE;
3353 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3354 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3357 aView->SetZClippingType(aZClippingMode);
3361 Quantity_Length aDepth = 0., aWidth = 1.;
3364 aDepth = atof(argv[1]);
3365 aWidth = atof(argv[2]);
3369 aDepth = atof(argv[2]);
3370 aWidth = atof(argv[3]);
3373 if(aDepth<0. || aDepth>1.)
3375 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3376 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3379 if(aWidth<0. || aWidth>1.)
3381 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3382 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3386 aView->SetZClippingDepth(aDepth);
3387 aView->SetZClippingWidth(aWidth);
3394 //=======================================================================
3395 //function : VNbSelected
3396 //purpose : Returns number of selected objects
3397 //=======================================================================
3398 static Standard_Integer VNbSelected (Draw_Interpretor& di,
3399 Standard_Integer argc,
3404 di << "Usage : " << argv[0] << "\n";
3407 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3408 if(aContext.IsNull())
3410 di << "use 'vinit' command before " << argv[0] << "\n";
3413 di << aContext->NbSelected() << "\n";
3417 //=======================================================================
3418 //function : VAntialiasing
3419 //purpose : Switches altialiasing on or off
3420 //=======================================================================
3421 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
3422 Standard_Integer argc,
3427 di << "Usage : " << argv[0] << " [1|0]" << "\n";
3431 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3432 if(aContext.IsNull())
3434 di << "use 'vinit' command before " << argv[0] << "\n";
3438 Handle(V3d_View) aView = ViewerTest::CurrentView();
3440 if((argc == 2) && (atof(argv[1]) == 0))
3441 aView->SetAntialiasingOff();
3443 aView->SetAntialiasingOn();
3448 //=======================================================================
3449 //function : VPurgeDisplay
3450 //purpose : Switches altialiasing on or off
3451 //=======================================================================
3452 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
3453 Standard_Integer argc,
3458 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
3461 Standard_Boolean isCollectorToo = Standard_False;
3464 isCollectorToo = (atoi(argv [1]) != 0);
3466 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3467 if (aContext.IsNull())
3469 di << "use 'vinit' command before " << argv[0] << "\n";
3472 aContext->CloseAllContexts(Standard_False);
3473 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
3477 //=======================================================================
3478 //function : VSetViewSize
3480 //=======================================================================
3481 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
3482 Standard_Integer argc,
3485 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3486 if(aContext.IsNull())
3488 di << "use 'vinit' command before " << argv[0] << "\n";
3493 di<<"Usage : " << argv[0] << " Size\n";
3496 Standard_Real aSize = atof(argv[1]);
3499 di<<"Bad Size value : " << aSize << "\n";
3503 Handle(V3d_View) aView = ViewerTest::CurrentView();
3504 aView->SetSize(aSize);
3508 //=======================================================================
3509 //function : VMoveView
3511 //=======================================================================
3512 static Standard_Integer VMoveView (Draw_Interpretor& di,
3513 Standard_Integer argc,
3516 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3517 if(aContext.IsNull())
3519 di << "use 'vinit' command before " << argv[0] << "\n";
3522 if(argc < 4 || argc > 5)
3524 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3527 Standard_Real Dx = atof(argv[1]);
3528 Standard_Real Dy = atof(argv[2]);
3529 Standard_Real Dz = atof(argv[3]);
3530 Standard_Boolean aStart = Standard_True;
3533 aStart = (atoi(argv[4]) > 0);
3536 Handle(V3d_View) aView = ViewerTest::CurrentView();
3537 aView->Move(Dx,Dy,Dz,aStart);
3541 //=======================================================================
3542 //function : VTranslateView
3544 //=======================================================================
3545 static Standard_Integer VTranslateView (Draw_Interpretor& di,
3546 Standard_Integer argc,
3549 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3550 if(aContext.IsNull())
3552 di << "use 'vinit' command before " << argv[0] << "\n";
3555 if(argc < 4 || argc > 5)
3557 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3560 Standard_Real Dx = atof(argv[1]);
3561 Standard_Real Dy = atof(argv[2]);
3562 Standard_Real Dz = atof(argv[3]);
3563 Standard_Boolean aStart = Standard_True;
3566 aStart = (atoi(argv[4]) > 0);
3569 Handle(V3d_View) aView = ViewerTest::CurrentView();
3570 aView->Translate(Dx,Dy,Dz,aStart);
3574 //=======================================================================
3575 //function : VTurnView
3577 //=======================================================================
3578 static Standard_Integer VTurnView (Draw_Interpretor& di,
3579 Standard_Integer argc,
3582 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3583 if(aContext.IsNull()) {
3584 di << "use 'vinit' command before " << argv[0] << "\n";
3587 if(argc < 4 || argc > 5){
3588 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
3591 Standard_Real Ax = atof(argv[1]);
3592 Standard_Real Ay = atof(argv[2]);
3593 Standard_Real Az = atof(argv[3]);
3594 Standard_Boolean aStart = Standard_True;
3597 aStart = (atoi(argv[4]) > 0);
3600 Handle(V3d_View) aView = ViewerTest::CurrentView();
3601 aView->Turn(Ax,Ay,Az,aStart);
3605 //=======================================================================
3606 //function : ViewerCommands
3608 //=======================================================================
3610 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3613 const char *group = "ZeViewer";
3614 theCommands.Add("vinit" ,
3615 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3616 __FILE__,VInit,group);
3617 theCommands.Add("vhelp" ,
3618 "vhelp : display help on the viewer commands",
3619 __FILE__,VHelp,group);
3620 theCommands.Add("vtop" ,
3621 "vtop or <T> : Top view" ,
3622 __FILE__,VTop,group);
3623 theCommands.Add("vbottom" ,
3624 "vbottom : Bottom view" ,
3625 __FILE__,VBottom,group);
3626 theCommands.Add("vleft" ,
3627 "vleft : Left view" ,
3628 __FILE__,VLeft,group);
3629 theCommands.Add("vright" ,
3630 "vright : Right view" ,
3631 __FILE__,VRight,group);
3632 theCommands.Add("vaxo" ,
3633 " vaxo or <A> : Axonometric view ",
3634 __FILE__,VAxo,group);
3635 theCommands.Add("vfront" ,
3636 "vfront : Front view" ,
3637 __FILE__,VFront,group);
3638 theCommands.Add("vback" ,
3639 "vback : Back view" ,
3640 __FILE__,VBack,group);
3641 theCommands.Add("vpick" ,
3642 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
3644 theCommands.Add("vfit" ,
3645 "vfit or <F> : vfit",
3646 __FILE__,VFit,group);
3647 theCommands.Add("vzfit" ,
3649 __FILE__,VZFit,group);
3650 theCommands.Add("vrepaint",
3651 "vrepaint : vrepaint, force redraw",
3652 __FILE__,VRepaint,group);
3653 theCommands.Add("vclear",
3655 __FILE__,VClear,group);
3656 theCommands.Add("vsetbg",
3657 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
3658 __FILE__,VSetBg,group);
3659 theCommands.Add("vsetbgmode",
3660 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
3661 __FILE__,VSetBgMode,group);
3662 theCommands.Add("vsetgradientbg",
3663 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
3664 __FILE__,VSetGradientBg,group);
3665 theCommands.Add("vsetgrbgmode",
3666 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
3667 __FILE__,VSetGradientBgMode,group);
3668 theCommands.Add("vsetcolorbg",
3669 "vsetcolorbg : vsetcolorbg r g b : Set background color",
3670 __FILE__,VSetColorBg,group);
3671 theCommands.Add("vscale",
3672 "vscale : vscale X Y Z",
3673 __FILE__,VScale,group);
3674 theCommands.Add("vzbufftrihedron",
3675 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3676 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3677 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
3678 __FILE__,VTestZBuffTrihedron,group);
3679 theCommands.Add("vrotate",
3680 "vrotate : vrotate AX AY AZ [X Y Z]",
3681 __FILE__,VRotate,group);
3682 theCommands.Add("vzoom",
3683 "vzoom : vzoom coef",
3684 __FILE__,VZoom,group);
3685 theCommands.Add("vpan",
3686 "vpan : vpan dx dy",
3687 __FILE__,VPan,group);
3688 theCommands.Add("vexport",
3689 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3690 " : exports the view to a vector file of a given format"
3691 " : notice that EMF format requires patched gl2ps",
3692 __FILE__,VExport,group);
3693 theCommands.Add("vcolorscale",
3694 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3695 __FILE__,VColorScale,group);
3696 theCommands.Add("vgraduatedtrihedron",
3697 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
3698 __FILE__,VGraduatedTrihedron,group);
3699 theCommands.Add("vprintview" ,
3700 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3701 __FILE__,VPrintView,group);
3702 theCommands.Add("vzlayer",
3703 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3704 __FILE__,VZLayer,group);
3705 theCommands.Add("voverlaytext",
3706 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
3707 " : height - pixel height of the text (default=10.0)"
3708 " : font_name - name of font (default=courier)"
3709 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
3710 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
3711 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
3712 __FILE__,VOverlayText,group);
3713 theCommands.Add("vlayerline",
3714 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
3715 __FILE__,VLayerLine,group);
3716 theCommands.Add ("vgrid",
3717 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
3718 " : Mode - rectangular or circular"
3719 " : Type - lines or points",
3720 __FILE__, VGrid, group);
3721 theCommands.Add ("vfps",
3722 "vfps [framesNb=100] : estimate average frame rate for active view",
3723 __FILE__, VFps, group);
3724 theCommands.Add ("vvbo",
3725 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
3726 __FILE__, VVbo, group);
3727 theCommands.Add ("vmemgpu",
3728 "vmemgpu [f]: print system-dependent GPU memory information if available;"
3729 " with f option returns free memory in bytes",
3730 __FILE__, VMemGpu, group);
3731 theCommands.Add ("vreadpixel",
3732 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
3733 " : Read pixel value for active view",
3734 __FILE__, VReadPixel, group);
3735 theCommands.Add("diffimage",
3736 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
3737 __FILE__, VDiffImage, group);
3738 theCommands.Add ("vselect",
3739 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
3740 "- emulates different types of selection:\n"
3741 "- 1) single click selection\n"
3742 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
3743 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
3744 "- 4) any of these selections with shift button pressed",
3745 __FILE__, VSelect, group);
3746 theCommands.Add ("vmoveto",
3748 "- emulates cursor movement to pixel postion (x,y)",
3749 __FILE__, VMoveTo, group);
3750 theCommands.Add("vviewparams",
3751 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
3752 "- gets or sets current view characteristics",
3753 __FILE__,VViewParams, group);
3754 theCommands.Add("vchangeselected",
3755 "vchangeselected shape"
3756 "- adds to shape to selection or remove one from it",
3757 __FILE__, VChangeSelected, group);
3758 theCommands.Add("vzclipping",
3759 "vzclipping [mode] [depth width]\n"
3760 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
3761 "- gets or sets ZClipping mode, width and depth",
3762 __FILE__,VZClipping,group);
3763 theCommands.Add ("vnbselected",
3764 "vnbselected", __FILE__, VNbSelected, group);
3765 theCommands.Add("vantialiasing",
3766 "vantialiasing 1|0",
3767 __FILE__,VAntialiasing,group);
3768 theCommands.Add ("vpurgedisplay",
3769 "vpurgedisplay [CollectorToo = 0|1]"
3770 "- removes structures which don't belong to objects displayed in neutral point",
3771 __FILE__, VPurgeDisplay, group);
3772 theCommands.Add("vsetviewsize",
3773 "vsetviewsize size",
3774 __FILE__,VSetViewSize,group);
3775 theCommands.Add("vmoveview",
3776 "vmoveview Dx Dy Dz [Start = 1|0]",
3777 __FILE__,VMoveView,group);
3778 theCommands.Add("vtranslateview",
3779 "vtranslateview Dx Dy Dz [Start = 1|0)]",
3780 __FILE__,VTranslateView,group);
3781 theCommands.Add("vturnview",
3782 "vturnview Ax Ay Az [Start = 1|0]",
3783 __FILE__,VTurnView,group);