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 <AIS_Shape.hxx>
33 #include <AIS_Drawer.hxx>
34 #include <AIS_InteractiveObject.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_GraphicDriver.hxx>
40 #include <Graphic3d_ExportFormat.hxx>
41 #include <Graphic3d_NameOfTextureEnv.hxx>
42 #include <Graphic3d_TextureEnv.hxx>
43 #include <Graphic3d_TextureParams.hxx>
44 #include <Graphic3d_TypeOfTextureFilter.hxx>
45 #include <ViewerTest.hxx>
46 #include <ViewerTest_EventManager.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <Visual3d_View.hxx>
49 #include <Visual3d_ViewManager.hxx>
50 #include <V3d_LayerMgr.hxx>
51 #include <NIS_View.hxx>
52 #include <NIS_Triangulated.hxx>
53 #include <NIS_InteractiveContext.hxx>
54 #include <AIS_InteractiveContext.hxx>
55 #include <Draw_Interpretor.hxx>
57 #include <Draw_Appli.hxx>
58 #include <Aspect_PrintAlgo.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <OSD_Timer.hxx>
61 #include <TColStd_SequenceOfInteger.hxx>
62 #include <TColStd_HSequenceOfReal.hxx>
63 #include <TColgp_Array1OfPnt2d.hxx>
64 #include <Visual3d_LayerItem.hxx>
65 #include <V3d_LayerMgr.hxx>
66 #include <V3d_LayerMgrPointer.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
70 #include <Graphic3d.hxx>
76 #include <Visual3d_Layer.hxx>
79 #if defined(_WIN32) || defined(__WIN32__)
80 #include <WNT_WClass.hxx>
81 #include <WNT_Window.hxx>
84 #define _CRT_SECURE_NO_DEPRECATE
85 #pragma warning (disable:4996)
87 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
88 #include <Cocoa_Window.hxx>
91 #include <Xw_WindowQuality.hxx>
92 #include <Xw_Window.hxx>
93 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
94 #include <X11/Xutil.h>
98 //==============================================================================
100 //==============================================================================
101 // VIEWER GLOBAL VARIABLES
102 //==============================================================================
104 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
106 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
107 extern const Handle(NIS_InteractiveContext)& TheNISContext();
108 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
110 #if defined(_WIN32) || defined(__WIN32__)
111 static Handle(WNT_Window)& VT_GetWindow() {
112 static Handle(WNT_Window) WNTWin;
115 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
116 static Handle(Cocoa_Window)& VT_GetWindow()
118 static Handle(Cocoa_Window) aWindow;
121 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
123 static Handle(Xw_Window)& VT_GetWindow(){
124 static Handle(Xw_Window) XWWin;
127 static Display *display;
129 static void VProcessEvents(ClientData,int);
132 static Handle(Graphic3d_GraphicDriver)& GetGraphicDriver()
134 static Handle(Graphic3d_GraphicDriver) aGraphicDriver;
135 return aGraphicDriver;
138 static Standard_Boolean MyHLRIsOn = Standard_False;
140 #define ZCLIPWIDTH 1.
142 static void OSWindowSetup();
144 //==============================================================================
145 // EVENT GLOBAL VARIABLES
146 //==============================================================================
148 static int Start_Rot = 0;
149 static int ZClipIsOn = 0;
150 int X_Motion = 0; // Current cursor position
152 int X_ButtonPress = 0; // Last ButtonPress position
153 int Y_ButtonPress = 0;
154 Standard_Boolean IsDragged = Standard_False;
155 Standard_Boolean DragFirst;
157 //==============================================================================
160 static LRESULT WINAPI ViewerWindowProc(
165 static LRESULT WINAPI AdvViewerWindowProc(
173 //==============================================================================
176 //==============================================================================
178 const Handle(MMgt_TShared)& ViewerTest::WClass()
180 static Handle(MMgt_TShared) theWClass;
181 #if defined(_WIN32) || defined(__WIN32__)
182 if (theWClass.IsNull())
184 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
185 CS_VREDRAW | CS_HREDRAW, 0, 0,
186 ::LoadCursor (NULL, IDC_ARROW));
192 //==============================================================================
193 //function : ViewerInit
194 //purpose : Create the window viewer and initialize all the global variable
195 //==============================================================================
197 void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
198 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
200 static Standard_Boolean isFirst = Standard_True;
202 // Default position and dimension of the viewer window.
203 // Note that left top corner is set to be sufficiently small to have
204 // window fit in the small screens (actual for remote desktops, see #23003).
205 // The position corresponds to the window's client area, thus some
206 // gap is added for window frame to be visible.
207 Standard_Integer aPxLeft = 20;
208 Standard_Integer aPxTop = 40;
209 Standard_Integer aPxWidth = 409;
210 Standard_Integer aPxHeight = 409;
211 if (thePxWidth != 0 && thePxHeight != 0)
215 aPxWidth = thePxWidth;
216 aPxHeight = thePxHeight;
221 Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
222 if (GetGraphicDriver().IsNull())
224 GetGraphicDriver() = Graphic3d::InitGraphicDriver (aDisplayConnection);
226 #if defined(_WIN32) || defined(__WIN32__)
227 if (VT_GetWindow().IsNull())
229 VT_GetWindow() = new WNT_Window ("Test3d",
230 Handle(WNT_WClass)::DownCast (WClass()),
236 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
237 if (VT_GetWindow().IsNull())
239 VT_GetWindow() = new Cocoa_Window ("Test3d",
241 aPxWidth, aPxHeight);
242 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
245 if (VT_GetWindow().IsNull())
247 VT_GetWindow() = new Xw_Window (aDisplayConnection,
254 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
256 Handle(V3d_Viewer) a3DViewer, a3DCollector;
257 // Viewer and View creation
259 TCollection_ExtendedString NameOfWindow("Visu3D");
261 a3DViewer = new V3d_Viewer(GetGraphicDriver(), NameOfWindow.ToExtString());
262 NameOfWindow = TCollection_ExtendedString("Collector");
263 a3DCollector = new V3d_Viewer(GetGraphicDriver(), NameOfWindow.ToExtString());
264 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
265 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
266 Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
269 //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
270 aView = new NIS_View (a3DViewer, VT_GetWindow());
271 ViewerTest::CurrentView(aView);
272 TheNISContext()->AttachView (aView);
276 if ( ViewerTest::GetAISContext().IsNull() ) {
277 Handle(AIS_InteractiveContext) C =
278 new AIS_InteractiveContext(a3DViewer,a3DCollector);
279 ViewerTest::SetAISContext(C);
282 // Setup for X11 or NT
284 // Viewer and View creation
286 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
288 Handle (V3d_View) V = ViewerTest::CurrentView();
289 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
291 V->SetZClippingDepth(0.5);
292 V->SetZClippingWidth(ZCLIPWIDTH/2.);
293 a3DViewer->SetDefaultLights();
294 a3DViewer->SetLightOn();
296 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
297 #if TCL_MAJOR_VERSION < 8
298 Tk_CreateFileHandler((void*)ConnectionNumber(display),
299 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
301 Tk_CreateFileHandler(ConnectionNumber(display),
302 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
306 isFirst = Standard_False;
309 VT_GetWindow()->Map();
310 ViewerTest::CurrentView()->Redraw();
313 //==============================================================================
315 //purpose : Create the window viewer and initialize all the global variable
316 // Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
317 //==============================================================================
319 static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
321 Standard_Integer aPxLeft = (argc > 1) ? Draw::Atoi (argv[1]) : 0;
322 Standard_Integer aPxTop = (argc > 2) ? Draw::Atoi (argv[2]) : 0;
323 Standard_Integer aPxWidth = (argc > 3) ? Draw::Atoi (argv[3]) : 0;
324 Standard_Integer aPxHeight = (argc > 4) ? Draw::Atoi (argv[4]) : 0;
325 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
329 //==============================================================================
331 //purpose : hidden lines removal algorithm
332 //==============================================================================
334 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
336 if (ViewerTest::CurrentView().IsNull())
338 di << argv[0] << ": Call vinit before this command, please.\n";
344 di << argv[0] << ": Wrong number of command arguments.\n"
345 << "Type help " << argv[0] << " for more information.\n";
349 Standard_Boolean isHLROn =
350 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
352 if (isHLROn == MyHLRIsOn)
358 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
363 //==============================================================================
364 //function : VHLRType
365 //purpose : change type of using HLR algorithm
366 //==============================================================================
368 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
370 if (ViewerTest::CurrentView().IsNull())
372 di << argv[0] << ": Call vinit before this command, please.\n";
378 di << argv[0] << ": Wrong number of command arguments.\n"
379 << "Type help " << argv[0] << " for more information.\n";
383 Prs3d_TypeOfHLR aTypeOfHLR =
384 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
388 AIS_ListOfInteractive aListOfShapes;
389 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
390 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
391 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
392 anIter.More(); anIter.Next())
394 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
397 if (aShape->TypeOfHLR() != aTypeOfHLR)
398 aShape->SetTypeOfHLR (aTypeOfHLR);
402 ViewerTest::CurrentView()->Update();
407 for (Standard_Integer i = 2; i < argc; ++i)
409 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
410 TCollection_AsciiString aName (argv[i]);
412 if (!aMap.IsBound2 (aName))
414 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
417 Handle(AIS_Shape) anAISObject =
418 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
419 if (anAISObject.IsNull())
421 anAISObject->SetTypeOfHLR (aTypeOfHLR);
423 anAISObject->Redisplay();
425 ViewerTest::CurrentView()->Update();
431 //==============================================================================
432 //function : VT_ProcessKeyPress
433 //purpose : Handle KeyPress event from a CString
434 //==============================================================================
435 void VT_ProcessKeyPress (const char* buf_ret)
437 //cout << "KeyPress" << endl;
438 const Handle(V3d_View) aView = ViewerTest::CurrentView();
439 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
440 // Letter in alphabetic order
442 if ( !strcasecmp(buf_ret, "A") ) {
444 aView->SetProj(V3d_XposYnegZpos);
446 else if ( !strcasecmp(buf_ret, "D") ) {
450 else if ( !strcasecmp(buf_ret, "F") ) {
452 if (aNisView.IsNull())
455 aNisView->FitAll3d();
457 else if ( !strcasecmp(buf_ret, "H") ) {
459 cout << "HLR" << endl;
460 aView->SetComputedMode (!aView->ComputedMode());
461 MyHLRIsOn = aView->ComputedMode();
463 else if ( !strcasecmp(buf_ret, "P") ) {
465 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
466 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
467 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
469 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
470 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
472 AIS_ListOfInteractive aListOfShapes;
473 aContext->DisplayedObjects(aListOfShapes);
474 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
475 anIter.More(); anIter.Next())
477 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
480 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
481 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
483 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
489 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
491 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
494 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
495 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
497 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
502 aContext->UpdateCurrentViewer();
505 else if ( !strcasecmp(buf_ret, "S") ) {
507 cout << "passage en mode 1 (shading pour les shapes)" << endl;
509 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
510 if(Ctx->NbCurrents()==0 ||
511 Ctx->NbSelected()==0)
512 Ctx->SetDisplayMode(AIS_Shaded);
514 if(Ctx->HasOpenedContext()){
515 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
516 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
519 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
520 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
522 Ctx->UpdateCurrentViewer();
525 else if ( !strcasecmp(buf_ret, "U") ) {
526 // Unset display mode
527 cout<<"passage au mode par defaut"<<endl;
529 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
530 if(Ctx->NbCurrents()==0 ||
531 Ctx->NbSelected()==0)
532 Ctx->SetDisplayMode(AIS_WireFrame);
534 if(Ctx->HasOpenedContext()){
535 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
536 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
539 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
540 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
542 Ctx->UpdateCurrentViewer();
546 else if ( !strcasecmp(buf_ret, "T") ) {
548 aView->SetProj(V3d_Zpos);
550 else if ( !strcasecmp(buf_ret, "B") ) {
552 aView->SetProj(V3d_Zneg);
554 else if ( !strcasecmp(buf_ret, "L") ) {
556 aView->SetProj(V3d_Xneg);
558 else if ( !strcasecmp(buf_ret, "R") ) {
560 aView->SetProj(V3d_Xpos);
563 else if ( !strcasecmp(buf_ret, "W") ) {
565 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
566 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
567 if(Ctx->NbCurrents()==0 ||
568 Ctx->NbSelected()==0)
569 Ctx->SetDisplayMode(AIS_WireFrame);
571 if(Ctx->HasOpenedContext()){
572 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
573 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
576 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
577 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
579 Ctx->UpdateCurrentViewer();
582 else if ( !strcasecmp(buf_ret, "Z") ) {
586 cout << "ZClipping OFF" << endl;
589 aView->SetZClippingType(V3d_OFF);
593 cout << "ZClipping ON" << endl;
596 aView->SetZClippingType(V3d_FRONT);
600 else if ( !strcasecmp(buf_ret, ",") ) {
601 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
605 else if ( !strcasecmp(buf_ret, ".") ) {
606 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
610 Standard_Integer Num = Draw::Atoi(buf_ret);
612 ViewerTest::StandardModeActivation(Num);
616 //==============================================================================
617 //function : VT_ProcessExpose
618 //purpose : Redraw the View on an Expose Event
619 //==============================================================================
620 void VT_ProcessExpose()
622 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
623 if (!aView3d.IsNull())
629 //==============================================================================
630 //function : VT_ProcessConfigure
631 //purpose : Resize the View on an Configure Event
632 //==============================================================================
633 void VT_ProcessConfigure()
635 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
636 if (aView3d.IsNull())
641 aView3d->MustBeResized();
646 //==============================================================================
647 //function : VT_ProcessButton1Press
649 //==============================================================================
650 Standard_Boolean VT_ProcessButton1Press(
653 Standard_Boolean pick,
654 Standard_Boolean shift)
656 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
658 Standard_Real X, Y, Z;
660 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
662 Draw::Set(argv[1], X);
663 Draw::Set(argv[2], Y);
664 Draw::Set(argv[3], Z);}
675 //==============================================================================
676 //function : VT_ProcessButton1Release
677 //purpose : End selecting
678 //==============================================================================
679 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
683 IsDragged = Standard_False;
684 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
687 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
688 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
692 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
693 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
698 //==============================================================================
699 //function : VT_ProcessButton3Press
700 //purpose : Start Rotation
701 //==============================================================================
702 void VT_ProcessButton3Press()
707 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
709 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
712 //==============================================================================
713 //function : VT_ProcessButton3Release
714 //purpose : End rotation
715 //==============================================================================
716 void VT_ProcessButton3Release()
723 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
728 //==============================================================================
729 //function : ProcessZClipMotion
731 //==============================================================================
733 void ProcessZClipMotion()
735 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
736 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
737 static Standard_Real CurZPos = 0.;
739 //Quantity_Length VDX, VDY;
740 //a3DView->Size(VDX,VDY);
741 //Standard_Real VDZ = a3DView->ZSize();
742 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
744 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
746 // Front = Depth + width/2.
747 Standard_Real D = 0.5;
748 Standard_Real W = 0.1;
754 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
756 a3DView->SetZClippingType(V3d_OFF);
757 a3DView->SetZClippingDepth(D);
758 a3DView->SetZClippingWidth(W);
759 a3DView->SetZClippingType(V3d_FRONT);
763 X_ButtonPress = X_Motion;
764 Y_ButtonPress = Y_Motion;
768 //==============================================================================
769 //function : ProcessControlButton1Motion
771 //==============================================================================
773 static void ProcessControlButton1Motion()
775 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
777 X_ButtonPress = X_Motion;
778 Y_ButtonPress = Y_Motion;
781 //==============================================================================
782 //function : VT_ProcessControlButton2Motion
784 //==============================================================================
785 void VT_ProcessControlButton2Motion()
787 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
788 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
790 dy = -dy; // Xwindow Y axis is from top to Bottom
792 ViewerTest::CurrentView()->Panning( dx, dy );
794 X_ButtonPress = X_Motion;
795 Y_ButtonPress = Y_Motion;
798 //==============================================================================
799 //function : VT_ProcessControlButton3Motion
801 //==============================================================================
802 void VT_ProcessControlButton3Motion()
806 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
810 //==============================================================================
811 //function : VT_ProcessMotion
813 //==============================================================================
814 void VT_ProcessMotion()
816 //pre-hilights detected objects at mouse position
818 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
819 EM->MoveTo(X_Motion, Y_Motion);
823 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
825 Xpix = X_Motion;Ypix=Y_Motion;
828 //==============================================================================
829 //function : ViewProject: implements VAxo, VTop, VLeft, ...
830 //purpose : Switches to an axonometric, top, left and other views
831 //==============================================================================
833 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
835 if ( ViewerTest::CurrentView().IsNull() )
837 di<<"Call vinit before this command, please"<<"\n";
841 ViewerTest::CurrentView()->SetProj(ori);
845 //==============================================================================
847 //purpose : Switch to an Axonometric view
849 //==============================================================================
851 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
853 return ViewProject(di, V3d_XposYnegZpos);
856 //==============================================================================
858 //purpose : Switch to a Top View
860 //==============================================================================
862 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
864 return ViewProject(di, V3d_Zpos);
867 //==============================================================================
869 //purpose : Switch to a Bottom View
871 //==============================================================================
873 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
875 return ViewProject(di, V3d_Zneg);
878 //==============================================================================
880 //purpose : Switch to a Left View
882 //==============================================================================
884 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
886 return ViewProject(di, V3d_Ypos);
889 //==============================================================================
891 //purpose : Switch to a Right View
893 //==============================================================================
895 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
897 return ViewProject(di, V3d_Yneg);
900 //==============================================================================
902 //purpose : Switch to a Front View
904 //==============================================================================
906 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
908 return ViewProject(di, V3d_Xpos);
911 //==============================================================================
913 //purpose : Switch to a Back View
915 //==============================================================================
917 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
919 return ViewProject(di, V3d_Xneg);
922 //==============================================================================
924 //purpose : Dsiplay help on viewer Keyboead and mouse commands
926 //==============================================================================
928 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
931 di << "Q : Quit the application" << "\n";
933 di << "========================="<<"\n";
934 di << "F : FitAll" << "\n";
935 di << "T : TopView" << "\n";
936 di << "B : BottomView" << "\n";
937 di << "R : RightView" << "\n";
938 di << "L : LeftView" << "\n";
939 di << "A : AxonometricView" << "\n";
940 di << "D : ResetView" << "\n";
942 di << "========================="<<"\n";
943 di << "S : Shading" << "\n";
944 di << "W : Wireframe" << "\n";
945 di << "H : HidelLineRemoval" << "\n";
946 di << "U : Unset display mode" << "\n";
948 di << "========================="<<"\n";
949 di << "Selection mode "<<"\n";
950 di << "0 : Shape" <<"\n";
951 di << "1 : Vertex" <<"\n";
952 di << "2 : Edge" <<"\n";
953 di << "3 : Wire" <<"\n";
954 di << "4 : Face" <<"\n";
955 di << "5 : Shell" <<"\n";
956 di << "6 : Solid" <<"\n";
957 di << "7 : Compound" <<"\n";
959 di << "========================="<<"\n";
960 di << "Z : Switch Z clipping On/Off" << "\n";
961 di << ", : Hilight next detected" << "\n";
962 di << ". : Hilight previous detected" << "\n";
969 static Standard_Boolean Ppick = 0;
970 static Standard_Integer Pargc = 0;
971 static const char** Pargv = NULL;
974 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
979 if ( !ViewerTest::CurrentView().IsNull() ) {
981 WPARAM fwKeys = wParam;
986 IsDragged = Standard_False;
989 HDC hdc = GetDC( hwnd );
990 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
991 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
992 SetROP2( hdc, R2_NOT );
993 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
994 ReleaseDC( hwnd, hdc );
996 const Handle(ViewerTest_EventManager) EM =
997 ViewerTest::CurrentEventManager();
998 if ( fwKeys & MK_SHIFT )
999 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1000 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1002 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1003 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
1005 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1007 case WM_LBUTTONDOWN:
1008 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1010 IsDragged = Standard_True;
1011 DragFirst = Standard_True;
1012 X_ButtonPress = LOWORD(lParam);
1013 Y_ButtonPress = HIWORD(lParam);
1015 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1022 HDC hdc = GetDC( hwnd );
1024 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1025 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1026 SetROP2( hdc, R2_NOT );
1029 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1031 DragFirst = Standard_False;
1032 X_Motion = LOWORD(lParam);
1033 Y_Motion = HIWORD(lParam);
1035 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1037 SelectObject( hdc, anObj );
1039 ReleaseDC( hwnd, hdc );
1042 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1046 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1050 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1054 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1059 /*static Standard_Boolean Ppick = 0;
1060 static Standard_Integer Pargc = 0;
1061 static char** Pargv = NULL;*/
1065 if ( !ViewerTest::CurrentView().IsNull() ) {
1070 // do not destroy the window - just hide it!
1071 VT_GetWindow()->Unmap();
1074 BeginPaint(hwnd, &ps);
1075 EndPaint(hwnd, &ps);
1080 VT_ProcessConfigure();
1084 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1087 c[0] = (char) wParam;
1089 VT_ProcessKeyPress (c);
1097 VT_ProcessButton3Release();
1100 case WM_LBUTTONDOWN:
1101 case WM_MBUTTONDOWN:
1102 case WM_RBUTTONDOWN:
1104 WPARAM fwKeys = wParam;
1108 X_ButtonPress = LOWORD(lParam);
1109 Y_ButtonPress = HIWORD(lParam);
1111 if (Msg == WM_LBUTTONDOWN)
1113 if (fwKeys & MK_CONTROL)
1115 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1119 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1122 else if (Msg == WM_RBUTTONDOWN)
1125 VT_ProcessButton3Press();
1132 //cout << "\t WM_MOUSEMOVE" << endl;
1133 WPARAM fwKeys = wParam;
1134 X_Motion = LOWORD(lParam);
1135 Y_Motion = HIWORD(lParam);
1138 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1140 X_ButtonPress = LOWORD(lParam);
1141 Y_ButtonPress = HIWORD(lParam);
1143 if ( fwKeys & MK_RBUTTON ) {
1145 VT_ProcessButton3Press();
1149 if ( fwKeys & MK_CONTROL ) {
1150 if ( fwKeys & MK_LBUTTON ) {
1151 ProcessControlButton1Motion();
1153 else if ( fwKeys & MK_MBUTTON ||
1154 ((fwKeys&MK_LBUTTON) &&
1155 (fwKeys&MK_RBUTTON) ) ){
1156 VT_ProcessControlButton2Motion();
1158 else if ( fwKeys & MK_RBUTTON ) {
1159 VT_ProcessControlButton3Motion();
1163 else if ( fwKeys & MK_SHIFT ) {
1164 if ( fwKeys & MK_MBUTTON ||
1165 ((fwKeys&MK_LBUTTON) &&
1166 (fwKeys&MK_RBUTTON) ) ) {
1167 cout << "ProcessZClipMotion()" << endl;
1168 ProcessZClipMotion();
1173 if ((fwKeys & MK_MBUTTON
1174 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1176 ProcessZClipMotion();
1186 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1191 return DefWindowProc( hwnd, Msg, wParam, lParam );
1197 //==============================================================================
1198 //function : ViewerMainLoop
1199 //purpose : Get a Event on the view and dispatch it
1200 //==============================================================================
1203 static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1206 //cout << "No yet implemented on WNT" << endl;
1207 /*static Standard_Boolean Ppick = 0;
1208 static Standard_Integer Pargc = 0;
1209 static char** Pargv = NULL;*/
1211 //Ppick = (argc > 0)? -1 : 0;
1212 Ppick = (argc > 0)? 1 : 0;
1220 cout << "Start picking" << endl;
1222 //while ( Ppick == -1 ) {
1223 while ( Ppick == 1 ) {
1224 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
1225 if (GetMessage(&msg, NULL, 0, 0) ) {
1226 TranslateMessage(&msg);
1227 DispatchMessage(&msg);
1231 cout << "Picking done" << endl;
1237 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
1239 int min( int a, int b )
1247 int max( int a, int b )
1255 int ViewerMainLoop(Standard_Integer argc, const char** argv)
1257 { Standard_Boolean pick = argc > 0;
1261 static XEvent report;
1263 XNextEvent( display, &report );
1264 // cout << "rep type = " << report.type << endl;
1265 // cout << "rep button = " << report.xbutton.button << endl;
1267 switch ( report.type ) {
1273 case ConfigureNotify:
1275 VT_ProcessConfigure();
1284 XComposeStatus status_in_out;
1286 ret_len = XLookupString( ( XKeyEvent *)&report ,
1287 (char *) buf_ret , 10 ,
1288 &ks_ret , &status_in_out ) ;
1291 buf_ret[ret_len] = '\0' ;
1295 VT_ProcessKeyPress (buf_ret);
1300 // cout << "ButtonPress" << endl;
1302 X_ButtonPress = report.xbutton.x;
1303 Y_ButtonPress = report.xbutton.y;
1305 if (report.xbutton.button == Button1)
1307 if (report.xbutton.state & ControlMask)
1309 pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
1313 IsDragged = Standard_True;
1314 DragFirst = Standard_True;
1317 else if (report.xbutton.button == Button3)
1320 VT_ProcessButton3Press();
1326 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1327 // cout << IsDragged << endl;
1328 // cout << DragFirst << endl;
1334 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1335 GC gc = XCreateGC( display, aWindow, 0, 0 );
1336 // XSetFunction( display, gc, GXinvert );
1337 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1340 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1341 if( aContext.IsNull() )
1343 cout << "The context is null. Please use vinit before createmesh" << endl;
1347 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1348 if( report.xbutton.button==1 )
1352 aContext->ShiftSelect();
1353 // cout << "shift select" << endl;
1358 // cout << "select" << endl;
1363 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1364 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1365 ViewerTest::CurrentView());
1366 // cout << "shift select" << endl;
1370 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1371 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1372 ViewerTest::CurrentView() );
1373 // cout << "select" << endl;
1376 VT_ProcessButton3Release();
1378 IsDragged = Standard_False;
1381 VT_ProcessButton3Release();
1388 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1389 GC gc = XCreateGC( display, aWindow, 0, 0 );
1390 XSetFunction( display, gc, GXinvert );
1393 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1395 X_Motion = report.xmotion.x;
1396 Y_Motion = report.xmotion.y;
1397 DragFirst = Standard_False;
1399 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
1403 X_Motion = report.xmotion.x;
1404 Y_Motion = report.xmotion.y;
1406 // remove all the ButtonMotionMask
1407 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1409 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1410 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1412 Quantity_Length VDX, VDY;
1414 ViewerTest::CurrentView()->Size(VDX,VDY);
1415 Standard_Real VDZ =0 ;
1416 VDZ = ViewerTest::CurrentView()->ZSize();
1418 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1419 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1421 Quantity_Length dx = 0 ;
1422 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1426 dx = dx / VDX * VDZ;
1430 // Front = Depth + width/2.
1431 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1432 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1434 ViewerTest::CurrentView()->Redraw();
1438 if ( report.xmotion.state & ControlMask ) {
1439 if ( report.xmotion.state & Button1Mask ) {
1440 ProcessControlButton1Motion();
1442 else if ( report.xmotion.state & Button2Mask ) {
1443 VT_ProcessControlButton2Motion();
1445 else if ( report.xmotion.state & Button3Mask ) {
1446 VT_ProcessControlButton3Motion();
1462 //==============================================================================
1463 //function : VProcessEvents
1464 //purpose : call by Tk_CreateFileHandler() to be able to manage the
1465 // event in the Viewer window
1466 //==============================================================================
1468 static void VProcessEvents(ClientData,int)
1470 //cout << "VProcessEvents" << endl;
1473 while (XPending(display)) {
1474 ViewerMainLoop( 0, NULL);
1479 //==============================================================================
1480 //function : OSWindowSetup
1481 //purpose : Setup for the X11 window to be able to cath the event
1482 //==============================================================================
1485 static void OSWindowSetup()
1487 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1490 Window window = VT_GetWindow()->XWindow();
1492 display = GetGraphicDriver()->GetDisplayConnection()->GetDisplay();
1493 // display = (Display *)GetG3dDevice()->XDisplay();
1495 XSynchronize(display, 1);
1497 VT_GetWindow()->Map();
1499 // X11 : For keyboard on SUN
1501 wmhints.flags = InputHint;
1504 XSetWMHints( display, window, &wmhints);
1506 XSelectInput( display, window, ExposureMask | KeyPressMask |
1507 ButtonPressMask | ButtonReleaseMask |
1508 StructureNotifyMask |
1510 Button1MotionMask | Button2MotionMask |
1514 XSynchronize(display, 0);
1523 //==============================================================================
1526 //purpose : Fitall, no DRAW arguments
1527 //Draw arg : No args
1528 //==============================================================================
1530 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1532 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1533 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1534 if (V.IsNull() == Standard_False) {
1536 } else if (aView.IsNull() == Standard_False) {
1542 //==============================================================================
1544 //purpose : ZFitall, no DRAW arguments
1545 //Draw arg : No args
1546 //==============================================================================
1548 static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1550 Handle(V3d_View) V = ViewerTest::CurrentView();
1551 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1554 static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1556 Handle(V3d_View) V = ViewerTest::CurrentView();
1557 if ( !V.IsNull() ) V->Redraw(); return 0;
1561 //==============================================================================
1563 //purpose : Remove all the object from the viewer
1564 //Draw arg : No args
1565 //==============================================================================
1567 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1569 Handle(V3d_View) V = ViewerTest::CurrentView();
1571 ViewerTest::Clear();
1575 //==============================================================================
1578 //==============================================================================
1580 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1581 { if (ViewerTest::CurrentView().IsNull() ) return 1;
1584 di << argv[0] << "Invalid number of arguments" << "\n";
1588 while (ViewerMainLoop( argc, argv)) {
1594 //==============================================================================
1595 //function : InitViewerTest
1596 //purpose : initialisation de toutes les variables static de ViewerTest (dp)
1597 //==============================================================================
1599 void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1601 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1602 ViewerTest::SetAISContext(context);
1603 viewer->InitActiveViews();
1604 Handle(V3d_View) view = viewer->ActiveView();
1605 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1606 ViewerTest::ResetEventManager();
1607 Handle(Aspect_Window) window = view->Window();
1608 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1610 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1611 GetGraphicDriver() = viewer->Driver();
1613 static int first = 1;
1615 #if TCL_MAJOR_VERSION < 8
1616 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1617 TK_READABLE, VProcessEvents, (ClientData) 0);
1619 Tk_CreateFileHandler(ConnectionNumber(display),
1620 TK_READABLE, VProcessEvents, (ClientData) 0);
1627 //==============================================================================
1629 //purpose : Load image as background
1630 //==============================================================================
1632 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1634 if (argc < 2 || argc > 3)
1636 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1637 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1641 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1642 if(AISContext.IsNull())
1644 di << "use 'vinit' command before " << argv[0] << "\n";
1648 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1651 const char* szType = argv[2];
1652 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1653 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1654 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1655 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1658 di << "Wrong fill type : " << szType << "\n";
1659 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1664 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1665 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1670 //==============================================================================
1671 //function : VSetBgMode
1672 //purpose : Change background image fill type
1673 //==============================================================================
1675 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1679 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1680 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1684 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1685 if(AISContext.IsNull())
1687 di << "use 'vinit' command before " << argv[0] << "\n";
1691 Aspect_FillMethod aFillType;
1694 const char* szType = argv[1];
1695 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1696 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1697 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1698 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1701 di << "Wrong fill type : " << szType << "\n";
1702 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1707 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1708 V3dView->SetBgImageStyle(aFillType, Standard_True);
1713 //==============================================================================
1714 //function : VSetGradientBg
1715 //purpose : Mount gradient background
1716 //==============================================================================
1717 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1721 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1722 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1723 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1724 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1728 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1729 if(AISContext.IsNull())
1731 di << "use 'vinit' command before " << argv[0] << "\n";
1737 Standard_Real R1 = Draw::Atof(argv[1])/255.;
1738 Standard_Real G1 = Draw::Atof(argv[2])/255.;
1739 Standard_Real B1 = Draw::Atof(argv[3])/255.;
1740 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1742 Standard_Real R2 = Draw::Atof(argv[4])/255.;
1743 Standard_Real G2 = Draw::Atof(argv[5])/255.;
1744 Standard_Real B2 = Draw::Atof(argv[6])/255.;
1746 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1747 int aType = Draw::Atoi(argv[7]);
1748 if( aType < 0 || aType > 8 )
1750 di << "Wrong fill type " << "\n";
1751 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1752 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1756 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1758 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1759 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1765 //==============================================================================
1766 //function : VSetGradientBgMode
1767 //purpose : Change gradient background fill style
1768 //==============================================================================
1769 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1773 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1774 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1775 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1779 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1780 if(AISContext.IsNull())
1782 di << "use 'vinit' command before " << argv[0] << "\n";
1787 int aType = Draw::Atoi(argv[1]);
1788 if( aType < 0 || aType > 8 )
1790 di << "Wrong fill type " << "\n";
1791 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1792 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1796 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1798 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1799 V3dView->SetBgGradientStyle( aMethod, 1 );
1805 //==============================================================================
1806 //function : VSetColorBg
1807 //purpose : Set color background
1808 //==============================================================================
1809 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1813 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1814 di << "R,G,B = [0..255]" << "\n";
1818 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1819 if(AISContext.IsNull())
1821 di << "use 'vinit' command before " << argv[0] << "\n";
1827 Standard_Real R = Draw::Atof(argv[1])/255.;
1828 Standard_Real G = Draw::Atof(argv[2])/255.;
1829 Standard_Real B = Draw::Atof(argv[3])/255.;
1830 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1832 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1833 V3dView->SetBackgroundColor( aColor );
1840 //==============================================================================
1842 //purpose : View Scaling
1843 //==============================================================================
1845 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1847 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1848 if ( V3dView.IsNull() ) return 1;
1851 di << argv[0] << "Invalid number of arguments" << "\n";
1854 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1857 //==============================================================================
1858 //function : VTestZBuffTrihedron
1859 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
1860 //==============================================================================
1862 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1864 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1865 if ( V3dView.IsNull() ) return 1;
1867 V3dView->ZBufferTriedronSetup();
1870 // Set up default trihedron parameters
1871 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1875 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1876 const char* aPosType = argv[1];
1878 if ( strcmp(aPosType, "center") == 0 )
1880 aPosition = Aspect_TOTP_CENTER;
1882 if (strcmp(aPosType, "left_lower") == 0)
1884 aPosition = Aspect_TOTP_LEFT_LOWER;
1886 if (strcmp(aPosType, "left_upper") == 0)
1888 aPosition = Aspect_TOTP_LEFT_UPPER;
1890 if (strcmp(aPosType, "right_lower") == 0)
1892 aPosition = Aspect_TOTP_RIGHT_LOWER;
1894 if (strcmp(aPosType, "right_upper") == 0)
1896 aPosition = Aspect_TOTP_RIGHT_UPPER;
1899 di << argv[1] << " Invalid type of alignment" << "\n";
1900 di << "Must be one of [ center, left_lower," << "\n";
1901 di << "left_upper, right_lower, right_upper ]" << "\n";
1905 Standard_Real R = Draw::Atof(argv[2])/255.;
1906 Standard_Real G = Draw::Atof(argv[3])/255.;
1907 Standard_Real B = Draw::Atof(argv[4])/255.;
1908 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1910 Standard_Real aScale = Draw::Atof(argv[5]);
1914 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1918 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1919 const char* aPresType = argv[6];
1921 if ( strcmp(aPresType, "wireframe") == 0 )
1923 aPresentation = V3d_WIREFRAME;
1925 if (strcmp(aPresType, "zbuffer") == 0)
1927 aPresentation = V3d_ZBUFFER;
1930 di << argv[6] << " Invalid type of visualization" << "\n";
1931 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1935 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1939 di << argv[0] << " Invalid number of arguments" << "\n";
1948 //==============================================================================
1949 //function : VRotate
1950 //purpose : Camera Rotating
1951 //==============================================================================
1953 static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1954 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1955 if ( V3dView.IsNull() ) {
1960 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
1962 } else if ( argc == 7 ) {
1963 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]) );
1966 di << argv[0] << " Invalid number of arguments" << "\n";
1971 //==============================================================================
1973 //purpose : View zoom in / out (relative to current zoom)
1974 //==============================================================================
1976 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1977 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1978 if ( V3dView.IsNull() ) {
1983 Standard_Real coef = Draw::Atof(argv[1]);
1984 if ( coef <= 0.0 ) {
1985 di << argv[1] << "Invalid value" << "\n";
1988 V3dView->SetZoom( Draw::Atof(argv[1]) );
1991 di << argv[0] << " Invalid number of arguments" << "\n";
1996 //==============================================================================
1998 //purpose : View panning (in pixels)
1999 //==============================================================================
2001 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2002 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2003 if ( V3dView.IsNull() ) return 1;
2006 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
2009 di << argv[0] << " Invalid number of arguments" << "\n";
2015 //==============================================================================
2016 //function : VExport
2017 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
2018 //==============================================================================
2020 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2022 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2023 if (V3dView.IsNull())
2028 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
2032 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2033 TCollection_AsciiString aFormatStr;
2035 TCollection_AsciiString aFileName (argv[1]);
2036 Standard_Integer aLen = aFileName.Length();
2040 aFormatStr = TCollection_AsciiString (argv[2]);
2044 if (aFileName.Value (aLen - 2) == '.')
2046 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2048 else if (aFileName.Value (aLen - 3) == '.')
2050 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2054 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2060 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2064 aFormatStr.UpperCase();
2065 if (aFormatStr == "PS")
2066 anExpFormat = Graphic3d_EF_PostScript;
2067 else if (aFormatStr == "EPS")
2068 anExpFormat = Graphic3d_EF_EnhPostScript;
2069 else if (aFormatStr == "TEX")
2070 anExpFormat = Graphic3d_EF_TEX;
2071 else if (aFormatStr == "PDF")
2072 anExpFormat = Graphic3d_EF_PDF;
2073 else if (aFormatStr == "SVG")
2074 anExpFormat = Graphic3d_EF_SVG;
2075 else if (aFormatStr == "PGF")
2076 anExpFormat = Graphic3d_EF_PGF;
2077 else if (aFormatStr == "EMF")
2078 anExpFormat = Graphic3d_EF_EMF;
2081 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2085 if (!V3dView->View()->Export (argv[1], anExpFormat))
2087 std::cout << "Export failed!\n";
2093 //==============================================================================
2094 //function : VColorScale
2095 //purpose : representation color scale
2096 //==============================================================================
2097 #include <V3d_ColorScale.hxx>
2099 static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2101 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2103 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2107 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2108 if(aContext.IsNull()) {
2109 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2113 Standard_Real minRange = 0. , maxRange = 100. ;
2115 Standard_Integer numIntervals = 10 ;
2116 Standard_Integer textHeight = 16;
2117 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2118 Standard_Real X = 0., Y = 0. ;
2124 minRange = Draw::Atof( argv[1] );
2125 maxRange = Draw::Atof( argv[2] );
2126 numIntervals = Draw::Atoi( argv[3] );
2129 textHeight = Draw::Atoi( argv[4] );
2131 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
2134 X = Draw::Atof( argv[6] );
2135 Y = Draw::Atof( argv[7] );
2138 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2139 if ( curView.IsNull( ) )
2141 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2142 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2143 if( ! aCS.IsNull( ) )
2145 aCS->SetPosition( X , Y );
2146 aCS->SetHeight( 0.95) ;
2147 aCS->SetTextHeight( textHeight );
2148 aCS->SetRange( minRange , maxRange );
2149 aCS->SetNumberOfIntervals( numIntervals );
2150 aCS->SetLabelPosition( position );
2151 if( !curView->ColorScaleIsDisplayed() )
2152 curView->ColorScaleDisplay( );
2157 //==============================================================================
2158 //function : VGraduatedTrihedron
2159 //purpose : Displays a graduated trihedron
2160 //==============================================================================
2162 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2164 const char *str = arg;
2167 unsigned short c1 = *str++;
2168 unsigned short c2 = *str++;
2169 if (!c1 || !c2) break;
2170 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2174 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2177 if (argc != 2 && argc < 5)
2179 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2180 di<<"Usage: type help "<<argv[0]<<"\n";
2181 return 1; //TCL_ERROR
2184 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2186 // Create 3D view if it doesn't exist
2187 if ( aV3dView.IsNull() )
2189 ViewerTest::ViewerInit();
2190 aV3dView = ViewerTest::CurrentView();
2191 if( aV3dView.IsNull() )
2193 di << "Error: Cannot create a 3D view\n";
2194 return 1; //TCL_ERROR
2198 // Erase (==0) or display (!=0)
2199 const int display = Draw::Atoi(argv[1]);
2204 TCollection_AsciiString font;
2206 font.AssignCat("Courier");
2208 font.AssignCat(argv[5]);
2210 // Text is multibyte
2211 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
2214 TCollection_ExtendedString xname, yname, zname;
2219 AddMultibyteString(xname, argv[2]);
2220 AddMultibyteString(yname, argv[3]);
2221 AddMultibyteString(zname, argv[4]);
2237 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2238 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2239 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2240 Standard_True/*drawgrid*/,
2241 Standard_True/*drawaxes*/,
2242 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2243 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2244 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2245 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2246 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2247 Quantity_NOC_WHITE/*gridcolor*/,
2248 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2249 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2252 aV3dView->GraduatedTrihedronErase();
2254 ViewerTest::GetAISContext()->UpdateCurrentViewer();
2260 //==============================================================================
2261 //function : VPrintView
2262 //purpose : Test printing algorithm, print the view to image file with given
2263 // width and height. Printing implemented only for WNT.
2264 //==============================================================================
2265 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
2269 di << "Printing implemented only for wnt!\n";
2273 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2274 Handle(V3d_View) aView = NULL;
2275 aContextAIS = ViewerTest::GetAISContext();
2276 if (!aContextAIS.IsNull())
2278 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2279 Vwr->InitActiveViews();
2280 if(Vwr->MoreActiveViews())
2281 aView = Vwr->ActiveView();
2287 di << "Call vinit before!\n";
2292 di << "Use: " << argv[0];
2293 di << " width height filename [print algo=0]\n";
2294 di << "width, height of the intermediate buffer for operation\n";
2295 di << "algo : {0|1}\n";
2296 di << " 0 - stretch algorithm\n";
2297 di << " 1 - tile algorithm\n";
2298 di << "test printing algorithms into an intermediate buffer\n";
2299 di << "with saving output to an image file\n";
2303 // get the input params
2304 Standard_Integer aWidth = Draw::Atoi (argv[1]);
2305 Standard_Integer aHeight = Draw::Atoi (argv[2]);
2306 Standard_Integer aMode = 0;
2307 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2309 aMode = Draw::Atoi (argv[4]);
2311 // check the input parameters
2312 if (aWidth <= 0 || aHeight <= 0)
2314 di << "Width and height must be positive values!\n";
2317 if (aMode != 0 && aMode != 1)
2320 // define compatible bitmap
2321 HDC anDC = CreateCompatibleDC(0);
2322 BITMAPINFO aBitmapData;
2323 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2324 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2325 aBitmapData.bmiHeader.biWidth = aWidth ;
2326 aBitmapData.bmiHeader.biHeight = aHeight;
2327 aBitmapData.bmiHeader.biPlanes = 1;
2328 aBitmapData.bmiHeader.biBitCount = 24;
2329 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2330 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2331 aBitmapData.bmiHeader.biClrUsed = 0;
2332 aBitmapData.bmiHeader.biClrImportant = 0;
2333 aBitmapData.bmiHeader.biCompression = BI_RGB;
2334 aBitmapData.bmiHeader.biSizeImage = 0;
2336 // Create Device Independent Bitmap
2337 void* aBitsOut = NULL;
2338 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2339 &aBitsOut, NULL, 0);
2340 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2342 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2343 if (aBitsOut != NULL)
2346 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2348 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2350 // succesfully printed into an intermediate buffer
2353 Image_PixMap aWrapper;
2354 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2355 aWrapper.SetTopDown (false);
2357 Image_AlienPixMap anImageBitmap;
2358 anImageBitmap.InitCopy (aWrapper);
2359 isSaved = anImageBitmap.Save (aFileName);
2363 di << "Print operation failed due to printing errors or\n";
2364 di << "insufficient memory available\n";
2365 di << "Please, try to use smaller dimensions for this test\n";
2366 di << "command, as it allocates intermediate buffer for storing\n";
2367 di << "the result\n";
2372 di << "Can't allocate memory for intermediate buffer\n";
2373 di << "Please use smaller dimensions\n";
2378 SelectObject (anDC, anOldBitmap);
2379 DeleteObject (aMemoryBitmap);
2385 di << "Save to file operation failed. This operation may fail\n";
2386 di << "if you don't have enough available memory, then you can\n";
2387 di << "use smaller dimensions for the output file\n";
2396 //==============================================================================
2397 //function : VZLayer
2398 //purpose : Test z layer operations for v3d viewer
2399 //==============================================================================
2400 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2402 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2403 if (aContextAIS.IsNull())
2405 di << "Call vinit before!\n";
2410 di << "Use: vzlayer " << argv[0];
2411 di << " add/del/get [id]\n";
2412 di << " add - add new z layer to viewer and print its id\n";
2413 di << " del - del z layer by its id\n";
2414 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2415 di << "id - the layer identificator value defined when removing z layer\n";
2419 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2420 if (aViewer.IsNull())
2422 di << "No active viewer!\n";
2426 // perform operation
2427 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2430 Standard_Integer aNewId;
2431 if (!aViewer->AddZLayer (aNewId))
2433 di << "Impossible to add new z layer!\n";
2437 di << "New z layer added with index: " << aNewId << "\n";
2439 else if (anOp == "del")
2443 di << "Please also provide as argument id of z layer to remove\n";
2447 Standard_Integer aDelId = Draw::Atoi (argv[2]);
2448 if (!aViewer->RemoveZLayer (aDelId))
2450 di << "Impossible to remove the z layer or invalid id!\n";
2454 di << "Z layer " << aDelId << " has been removed\n";
2456 else if (anOp == "get")
2458 TColStd_SequenceOfInteger anIds;
2459 aViewer->GetAllZLayers (anIds);
2460 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2462 di << anIds.Value (aSeqIdx) << " ";
2469 di << "Invalid operation, please use { add / del / get }\n";
2476 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2478 // this class provides a presentation of text item in v3d view under-/overlayer
2479 class V3d_TextItem : public Visual3d_LayerItem
2484 DEFINE_STANDARD_RTTI(V3d_TextItem)
2487 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2488 const Standard_Real theX1,
2489 const Standard_Real theY1,
2490 const Standard_Real theHeight,
2491 const TCollection_AsciiString& theFontName,
2492 const Quantity_Color& theColor,
2493 const Quantity_Color& theSubtitleColor,
2494 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2495 const Handle(Visual3d_Layer)& theLayer);
2498 Standard_EXPORT void RedrawLayerPrs();
2504 Standard_Real myHeight;
2505 TCollection_AsciiString myText;
2506 TCollection_AsciiString myFontName;
2507 Quantity_Color myColor;
2508 Quantity_Color mySubtitleColor;
2509 Aspect_TypeOfDisplayText myType;
2510 Handle(Visual3d_Layer) myLayer;
2514 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2515 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2517 // create and add to display the text item
2518 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2519 const Standard_Real theX1,
2520 const Standard_Real theY1,
2521 const Standard_Real theHeight,
2522 const TCollection_AsciiString& theFontName,
2523 const Quantity_Color& theColor,
2524 const Quantity_Color& theSubtitleColor,
2525 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2526 const Handle(Visual3d_Layer)& theLayer)
2527 : myX1 (theX1), myY1 (theY1),
2529 myHeight (theHeight),
2532 mySubtitleColor (theSubtitleColor),
2533 myType (theTypeOfDisplay),
2534 myFontName (theFontName)
2536 if (!myLayer.IsNull ())
2537 myLayer->AddLayerItem (this);
2541 void V3d_TextItem::RedrawLayerPrs ()
2543 if (myLayer.IsNull ())
2546 myLayer->SetColor (myColor);
2547 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2548 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2551 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2553 // The Visual3d_LayerItem line item for "vlayerline" command
2554 // it provides a presentation of line with user-defined
2555 // linewidth, linetype and transparency.
2556 class V3d_LineItem : public Visual3d_LayerItem
2560 DEFINE_STANDARD_RTTI(V3d_LineItem)
2563 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2564 Standard_Real X2, Standard_Real Y2,
2565 V3d_LayerMgrPointer theLayerMgr,
2566 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2567 Standard_Real theWidth = 0.5,
2568 Standard_Real theTransp = 1.0);
2571 Standard_EXPORT void RedrawLayerPrs();
2575 Standard_Real myX1, myY1, myX2, myY2;
2576 Standard_Real myWidth;
2577 Standard_Real myTransparency;
2578 Aspect_TypeOfLine myType;
2579 V3d_LayerMgrPointer myLayerMgr;
2582 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2583 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2585 // default constructor for line item
2586 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2587 Standard_Real X2, Standard_Real Y2,
2588 V3d_LayerMgrPointer theLayerMgr,
2589 Aspect_TypeOfLine theType,
2590 Standard_Real theWidth,
2591 Standard_Real theTransp) :
2592 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2593 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2595 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
2596 myLayerMgr->Overlay()->AddLayerItem (this);
2600 void V3d_LineItem::RedrawLayerPrs ()
2602 Handle (Visual3d_Layer) aOverlay;
2605 aOverlay = myLayerMgr->Overlay();
2607 if (!aOverlay.IsNull())
2609 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2610 aOverlay->SetColor(aColor);
2611 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2612 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2613 aOverlay->BeginPolyline();
2614 aOverlay->AddVertex(myX1, myY1);
2615 aOverlay->AddVertex(myX2, myY2);
2616 aOverlay->ClosePrimitive();
2620 //=============================================================================
2621 //function : VLayerLine
2622 //purpose : Draws line in the v3d view layer with given attributes: linetype,
2623 // : linewidth, transparency coefficient
2624 //============================================================================
2625 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2627 // get the active view
2628 Handle(V3d_View) aView = ViewerTest::CurrentView();
2631 di << "Call vinit before!\n";
2636 di << "Use: " << argv[0];
2637 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2638 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2639 di << " 0 - solid \n";
2640 di << " 1 - dashed \n";
2641 di << " 2 - dot \n";
2642 di << " 3 - dashdot\n";
2643 di << " transparency : { 0.0 - 1.0 } \n";
2644 di << " 0.0 - transparent\n";
2645 di << " 1.0 - visible \n";
2649 // get the input params
2650 Standard_Real X1 = Draw::Atof(argv[1]);
2651 Standard_Real Y1 = Draw::Atof(argv[2]);
2652 Standard_Real X2 = Draw::Atof(argv[3]);
2653 Standard_Real Y2 = Draw::Atof(argv[4]);
2655 Standard_Real aWidth = 0.5;
2656 Standard_Integer aType = 0;
2657 Standard_Real aTransparency = 1.0;
2661 aWidth = Draw::Atof(argv[5]);
2665 aType = (Standard_Integer) Draw::Atoi(argv[6]);
2670 aTransparency = Draw::Atof(argv[7]);
2671 if (aTransparency < 0 || aTransparency > 1.0)
2672 aTransparency = 1.0;
2675 // select appropriate line type
2676 Aspect_TypeOfLine aLineType;
2680 aLineType = Aspect_TOL_DASH;
2684 aLineType = Aspect_TOL_DOT;
2688 aLineType = Aspect_TOL_DOTDASH;
2692 aLineType = Aspect_TOL_SOLID;
2695 // replace layer manager
2696 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2697 aView->SetLayerMgr(aMgr);
2700 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2706 aView->MustBeResized();
2712 //=======================================================================
2713 //function : VOverlayText
2714 //purpose : Test text displaying in view overlay
2715 //=======================================================================
2716 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2718 // get the active view
2719 Handle(V3d_View) aView = ViewerTest::CurrentView();
2722 di << "No active view. Please call vinit.\n";
2725 else if (argc < 4 || argc > 13)
2727 di << "Use: " << argv[0];
2728 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2729 di << "[background_color: R G B]\n";
2730 di << " height - pixel height of the text (default=10.0)\n";
2731 di << " font_name - name of font (default=courier)\n";
2732 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2733 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2734 di << " background_color- R G B values used for subtitle and decal text\n";
2735 di << "(default=255.0 255.0 255.0)\n";
2739 TCollection_AsciiString aText (argv[1]);
2740 Standard_Real aPosX = Draw::Atof(argv[2]);
2741 Standard_Real aPosY = Draw::Atof(argv[3]);
2742 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
2745 TCollection_AsciiString aFontName = "Courier";
2747 aFontName = TCollection_AsciiString (argv[5]);
2750 Quantity_Parameter aColorRed = 1.0;
2751 Quantity_Parameter aColorGreen = 1.0;
2752 Quantity_Parameter aColorBlue = 1.0;
2755 aColorRed = Draw::Atof (argv[6])/255.;
2756 aColorGreen = Draw::Atof (argv[7])/255.;
2757 aColorBlue = Draw::Atof (argv[8])/255.;
2761 TCollection_AsciiString aDispStr;
2763 aDispStr = TCollection_AsciiString (argv[9]);
2765 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2766 if (aDispStr.IsEqual ("subtitle"))
2767 aTextType = Aspect_TODT_SUBTITLE;
2768 else if (aDispStr.IsEqual ("decal"))
2769 aTextType = Aspect_TODT_DEKALE;
2770 else if (aDispStr.IsEqual ("blend"))
2771 aTextType = Aspect_TODT_BLEND;
2774 Quantity_Parameter aSubRed = 1.0;
2775 Quantity_Parameter aSubGreen = 1.0;
2776 Quantity_Parameter aSubBlue = 1.0;
2779 aSubRed = Draw::Atof (argv[10])/255.;
2780 aSubGreen = Draw::Atof (argv[11])/255.;
2781 aSubBlue = Draw::Atof (argv[12])/255.;
2784 // check fo current overlay
2785 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2786 if (anOverlay.IsNull ())
2788 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2789 anOverlay = aMgr->Overlay ();
2790 aView->SetLayerMgr (aMgr);
2793 Quantity_Color aTextColor (aColorRed, aColorGreen,
2794 aColorBlue, Quantity_TOC_RGB);
2795 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2796 aSubBlue, Quantity_TOC_RGB);
2799 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2800 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2803 aView->MustBeResized();
2809 //==============================================================================
2812 //==============================================================================
2814 static int VGrid (Draw_Interpretor& theDI,
2815 Standard_Integer theArgNb,
2816 const char** theArgVec)
2818 // get the active view
2819 Handle(V3d_View) aView = ViewerTest::CurrentView();
2820 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2821 if (aView.IsNull() || aViewer.IsNull())
2823 std::cerr << "No active view. Please call vinit.\n";
2827 Aspect_GridType aType = aViewer->GridType();
2828 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2830 Standard_Integer anIter = 1;
2831 for (; anIter < theArgNb; ++anIter)
2833 const char* aValue = theArgVec[anIter];
2836 aType = Aspect_GT_Rectangular;
2838 else if (*aValue == 'c')
2840 aType = Aspect_GT_Circular;
2842 else if (*aValue == 'l')
2844 aMode = Aspect_GDM_Lines;
2846 else if (*aValue == 'p')
2848 aMode = Aspect_GDM_Points;
2850 else if (strcmp (aValue, "off" ) == 0)
2852 aViewer->DeactivateGrid();
2861 Standard_Integer aTail = (theArgNb - anIter);
2864 aViewer->ActivateGrid (aType, aMode);
2867 else if (aTail != 2 && aTail != 5)
2869 std::cerr << "Incorrect arguments number! Usage:\n"
2870 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2874 Quantity_Length anOriginX, anOriginY;
2875 Quantity_PlaneAngle aRotAngle;
2876 if (aType == Aspect_GT_Rectangular)
2878 Quantity_Length aRStepX, aRStepY;
2879 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2881 anOriginX = Draw::Atof (theArgVec[anIter++]);
2882 anOriginY = Draw::Atof (theArgVec[anIter++]);
2885 aRStepX = Draw::Atof (theArgVec[anIter++]);
2886 aRStepY = Draw::Atof (theArgVec[anIter++]);
2887 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2889 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2890 aViewer->ActivateGrid (aType, aMode);
2892 else if (aType == Aspect_GT_Circular)
2894 Quantity_Length aRadiusStep;
2895 Standard_Integer aDivisionNumber;
2896 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2898 anOriginX = Draw::Atof (theArgVec[anIter++]);
2899 anOriginY = Draw::Atof (theArgVec[anIter++]);
2902 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
2903 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
2904 aRotAngle = Draw::Atof (theArgVec[anIter++]);
2907 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2908 aViewer->ActivateGrid (aType, aMode);
2914 //==============================================================================
2917 //==============================================================================
2919 static int VFps (Draw_Interpretor& theDI,
2920 Standard_Integer theArgNb,
2921 const char** theArgVec)
2923 // get the active view
2924 Handle(V3d_View) aView = ViewerTest::CurrentView();
2927 std::cerr << "No active view. Please call vinit.\n";
2931 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
2934 std::cerr << "Incorrect arguments!\n";
2938 // the time is meaningless for first call
2939 // due to async OpenGl rendering
2942 // redraw view in loop to estimate average values
2945 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2951 const Standard_Real aTime = aTimer.ElapsedTime();
2952 aTimer.OSD_Chronometer::Show (aCpu);
2954 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2955 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2957 // return statistics
2958 theDI << "FPS: " << aFpsAver << "\n"
2959 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2965 //==============================================================================
2968 //==============================================================================
2970 static int VVbo (Draw_Interpretor& theDI,
2971 Standard_Integer theArgNb,
2972 const char** theArgVec)
2975 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2976 if (aContextAIS.IsNull())
2978 std::cerr << "No active view. Please call vinit.\n";
2982 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
2984 if (aDriver.IsNull())
2986 std::cerr << "Graphic driver not available.\n";
2992 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2994 std::cerr << "Wrong number of arguments.\n";
2998 aDriver->EnableVBO (Draw::Atoi(theArgVec[1]) != 0);
3002 //==============================================================================
3003 //function : VMemGpu
3005 //==============================================================================
3007 static int VMemGpu (Draw_Interpretor& theDI,
3008 Standard_Integer theArgNb,
3009 const char** theArgVec)
3012 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3013 if (aContextAIS.IsNull())
3015 std::cerr << "No active view. Please call vinit.\n";
3019 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
3021 if (aDriver.IsNull())
3023 std::cerr << "Graphic driver not available.\n";
3027 Standard_Size aFreeBytes = 0;
3028 TCollection_AsciiString anInfo;
3029 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
3031 std::cerr << "Information not available.\n";
3035 if (theArgNb > 1 && *theArgVec[1] == 'f')
3037 theDI << Standard_Real (aFreeBytes);
3047 // ==============================================================================
3048 // function : VReadPixel
3050 // ==============================================================================
3051 static int VReadPixel (Draw_Interpretor& theDI,
3052 Standard_Integer theArgNb,
3053 const char** theArgVec)
3055 // get the active view
3056 Handle(V3d_View) aView = ViewerTest::CurrentView();
3059 std::cerr << "No active view. Please call vinit.\n";
3062 else if (theArgNb < 3)
3064 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
3068 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3069 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
3071 Standard_Integer aWidth, aHeight;
3072 aView->Window()->Size (aWidth, aHeight);
3073 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
3074 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
3075 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
3077 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
3081 Standard_Boolean toShowName = Standard_False;
3082 Standard_Boolean toShowHls = Standard_False;
3083 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
3085 TCollection_AsciiString aParam (theArgVec[anIter]);
3086 if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb")))
3088 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3089 aBufferType = Graphic3d_BT_RGB;
3091 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
3093 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
3094 aBufferType = Graphic3d_BT_RGB;
3095 toShowHls = Standard_True;
3097 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
3099 aFormat = Image_PixMap::ImgRGBF;
3100 aBufferType = Graphic3d_BT_RGB;
3102 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
3104 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
3105 aBufferType = Graphic3d_BT_RGBA;
3107 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
3109 aFormat = Image_PixMap::ImgRGBAF;
3110 aBufferType = Graphic3d_BT_RGBA;
3112 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
3114 aFormat = Image_PixMap::ImgGrayF;
3115 aBufferType = Graphic3d_BT_Depth;
3117 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
3119 toShowName = Standard_True;
3123 Image_PixMap anImage;
3124 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
3126 std::cerr << "Image allocation failed\n";
3129 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
3131 std::cerr << "Image dump failed\n";
3135 Quantity_Parameter anAlpha;
3136 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
3139 if (aBufferType == Graphic3d_BT_RGBA)
3141 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3145 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3150 switch (aBufferType)
3153 case Graphic3d_BT_RGB:
3157 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3161 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3165 case Graphic3d_BT_RGBA:
3167 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3170 case Graphic3d_BT_Depth:
3172 theDI << aColor.Red() << "\n";
3181 //==============================================================================
3182 //function : VDiffImage
3183 //purpose : The draw-command compares two images.
3184 //==============================================================================
3186 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3190 theDI << "Not enough arguments.\n";
3195 const char* anImgPathRef = theArgVec[1];
3196 const char* anImgPathNew = theArgVec[2];
3198 // get string tolerance and check its validity
3199 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
3200 if (aTolColor < 0.0)
3202 if (aTolColor > 1.0)
3205 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
3206 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
3208 // image file of difference
3209 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3211 // compare the images
3212 Image_Diff aComparer;
3213 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3218 aComparer.SetColorTolerance (aTolColor);
3219 aComparer.SetBorderFilterOn (isBorderFilterOn);
3220 Standard_Integer aDiffColorsNb = aComparer.Compare();
3221 theDI << aDiffColorsNb << "\n";
3223 // save image of difference
3224 if (aDiffImagePath != NULL)
3226 aComparer.SaveDiffImage (aDiffImagePath);
3232 //=======================================================================
3233 //function : VSelect
3234 //purpose : Emulates different types of selection by mouse:
3235 // 1) single click selection
3236 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
3237 // 3) selection with polygon having corners at
3238 // pixel positions (x1,y1),...,(xn,yn)
3239 // 4) any of these selections with shift button pressed
3240 //=======================================================================
3241 static Standard_Integer VSelect (Draw_Interpretor& di,
3242 Standard_Integer argc,
3247 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
3251 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
3252 if(myAIScontext.IsNull())
3254 di << "use 'vinit' command before " << argv[0] << "\n";
3257 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
3258 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
3259 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
3262 if(isShiftSelection)
3263 aCurrentEventManager->ShiftSelect();
3265 aCurrentEventManager->Select();
3269 if(isShiftSelection)
3270 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3272 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
3276 Standard_Integer anUpper = 0;
3278 if(isShiftSelection)
3279 anUpper = (argc-1)/2;
3282 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
3284 for(Standard_Integer i=1;i<=anUpper;++i)
3285 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
3287 if(isShiftSelection)
3288 aCurrentEventManager->ShiftSelect(aPolyline);
3290 aCurrentEventManager->Select(aPolyline);
3295 //=======================================================================
3296 //function : VMoveTo
3297 //purpose : Emulates cursor movement to defined pixel position
3298 //=======================================================================
3299 static Standard_Integer VMoveTo (Draw_Interpretor& di,
3300 Standard_Integer argc,
3305 di << "Usage : " << argv[0] << " x y" << "\n";
3309 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3310 if(aContext.IsNull())
3312 di << "use 'vinit' command before " << argv[0] << "\n";
3315 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
3319 //=======================================================================
3320 //function : VViewParams
3321 //purpose : Gets or sets AIS View characteristics
3322 //=======================================================================
3323 static Standard_Integer VViewParams (Draw_Interpretor& di,
3324 Standard_Integer argc,
3327 if ( argc != 1 && argc != 13)
3329 di << "Usage : " << argv[0] << "\n";
3332 Handle (V3d_View) anAISView = ViewerTest::CurrentView ();
3333 if ( anAISView.IsNull () )
3335 di << "use 'vinit' command before " << argv[0] << "\n";
3339 Quantity_Factor anAISViewScale = anAISView -> V3d_View::Scale ();
3340 Standard_Real anAISViewCenterCoordinateX = 0.0;
3341 Standard_Real anAISViewCenterCoordinateY = 0.0;
3342 anAISView -> V3d_View::Center (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3343 Standard_Real anAISViewProjX = 0.0;
3344 Standard_Real anAISViewProjY = 0.0;
3345 Standard_Real anAISViewProjZ = 0.0;
3346 anAISView -> V3d_View::Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3347 Standard_Real anAISViewUpX = 0.0;
3348 Standard_Real anAISViewUpY = 0.0;
3349 Standard_Real anAISViewUpZ = 0.0;
3350 anAISView -> V3d_View::Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3351 Standard_Real anAISViewAtX = 0.0;
3352 Standard_Real anAISViewAtY = 0.0;
3353 Standard_Real anAISViewAtZ = 0.0;
3354 anAISView -> V3d_View::At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3355 di << "Scale of current view: " << anAISViewScale << "\n";
3356 di << "Center on X : "<< anAISViewCenterCoordinateX << "; on Y: " << anAISViewCenterCoordinateY << "\n";
3357 di << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
3358 di << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
3359 di << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
3363 Quantity_Factor anAISViewScale = atof (argv [1]);
3364 Standard_Real anAISViewCenterCoordinateX = atof (argv [2]);
3365 Standard_Real anAISViewCenterCoordinateY = atof (argv [3]);
3366 Standard_Real anAISViewProjX = atof (argv [4]);
3367 Standard_Real anAISViewProjY = atof (argv [5]);
3368 Standard_Real anAISViewProjZ = atof (argv [6]);
3369 Standard_Real anAISViewUpX = atof (argv [7]);
3370 Standard_Real anAISViewUpY = atof (argv [8]);
3371 Standard_Real anAISViewUpZ = atof (argv [9]);
3372 Standard_Real anAISViewAtX = atof (argv [10]);
3373 Standard_Real anAISViewAtY = atof (argv [11]);
3374 Standard_Real anAISViewAtZ = atof (argv [12]);
3375 anAISView -> V3d_View::SetScale (anAISViewScale);
3376 anAISView -> V3d_View::SetCenter (anAISViewCenterCoordinateX, anAISViewCenterCoordinateY);
3377 anAISView -> V3d_View::SetAt (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
3378 anAISView -> V3d_View::SetProj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
3379 anAISView -> V3d_View::SetUp (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
3384 //=======================================================================
3385 //function : VChangeSelected
3386 //purpose : Adds the shape to selection or remove one from it
3387 //=======================================================================
3388 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
3389 Standard_Integer argc,
3394 di<<"Usage : " << argv[0] << " shape \n";
3398 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3399 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
3400 TCollection_AsciiString aName(argv[1]);
3401 Handle(AIS_InteractiveObject) anAISObject;
3403 if(!aMap.IsBound2(aName))
3405 di<<"Use 'vdisplay' before";
3410 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
3411 if(anAISObject.IsNull()){
3412 di<<"No interactive object \n";
3416 if(aContext->HasOpenedContext())
3418 aContext->AddOrRemoveSelected(anAISObject);
3422 aContext->AddOrRemoveCurrentObject(anAISObject);
3428 //=======================================================================
3429 //function : VZClipping
3430 //purpose : Gets or sets ZClipping mode, width and depth
3431 //=======================================================================
3432 static Standard_Integer VZClipping (Draw_Interpretor& di,
3433 Standard_Integer argc,
3438 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3439 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3442 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3443 if(aContext.IsNull())
3445 di << "use 'vinit' command before " << argv[0] << "\n";
3448 Handle(V3d_View) aView = ViewerTest::CurrentView();
3449 V3d_TypeOfZclipping aZClippingMode;
3452 TCollection_AsciiString aZClippingModeString;
3453 Quantity_Length aDepth, aWidth;
3454 aZClippingMode = aView->ZClipping(aDepth, aWidth);
3455 switch (aZClippingMode)
3458 aZClippingModeString.Copy("OFF");
3461 aZClippingModeString.Copy("BACK");
3464 aZClippingModeString.Copy("FRONT");
3467 aZClippingModeString.Copy("SLICE");
3470 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
3473 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
3474 << "ZClipping depth = " << aDepth << "\n"
3475 << "ZClipping width = " << aWidth << "\n";
3481 Standard_Integer aStatus = 0;
3482 if ( strcmp (argv [1], "OFF") == 0 ) {
3484 aZClippingMode = V3d_OFF;
3486 if ( strcmp (argv [1], "BACK") == 0 ) {
3488 aZClippingMode = V3d_BACK;
3490 if ( strcmp (argv [1], "FRONT") == 0 ) {
3492 aZClippingMode = V3d_FRONT;
3494 if ( strcmp (argv [1], "SLICE") == 0 ) {
3496 aZClippingMode = V3d_SLICE;
3500 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3501 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3504 aView->SetZClippingType(aZClippingMode);
3508 Quantity_Length aDepth = 0., aWidth = 1.;
3511 aDepth = atof(argv[1]);
3512 aWidth = atof(argv[2]);
3516 aDepth = atof(argv[2]);
3517 aWidth = atof(argv[3]);
3520 if(aDepth<0. || aDepth>1.)
3522 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3523 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3526 if(aWidth<0. || aWidth>1.)
3528 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
3529 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
3533 aView->SetZClippingDepth(aDepth);
3534 aView->SetZClippingWidth(aWidth);
3541 //=======================================================================
3542 //function : VNbSelected
3543 //purpose : Returns number of selected objects
3544 //=======================================================================
3545 static Standard_Integer VNbSelected (Draw_Interpretor& di,
3546 Standard_Integer argc,
3551 di << "Usage : " << argv[0] << "\n";
3554 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3555 if(aContext.IsNull())
3557 di << "use 'vinit' command before " << argv[0] << "\n";
3560 di << aContext->NbSelected() << "\n";
3564 //=======================================================================
3565 //function : VAntialiasing
3566 //purpose : Switches altialiasing on or off
3567 //=======================================================================
3568 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
3569 Standard_Integer argc,
3574 di << "Usage : " << argv[0] << " [1|0]" << "\n";
3578 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3579 if(aContext.IsNull())
3581 di << "use 'vinit' command before " << argv[0] << "\n";
3585 Handle(V3d_View) aView = ViewerTest::CurrentView();
3587 if((argc == 2) && (atof(argv[1]) == 0))
3588 aView->SetAntialiasingOff();
3590 aView->SetAntialiasingOn();
3595 //=======================================================================
3596 //function : VPurgeDisplay
3597 //purpose : Switches altialiasing on or off
3598 //=======================================================================
3599 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
3600 Standard_Integer argc,
3605 di << "Usage : " << argv[0] << " [CollectorToo = 0|1]" << "\n";
3608 Standard_Boolean isCollectorToo = Standard_False;
3611 isCollectorToo = (atoi(argv [1]) != 0);
3613 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3614 if (aContext.IsNull())
3616 di << "use 'vinit' command before " << argv[0] << "\n";
3619 aContext->CloseAllContexts(Standard_False);
3620 di << aContext->PurgeDisplay(isCollectorToo) << "\n";
3624 //=======================================================================
3625 //function : VSetViewSize
3627 //=======================================================================
3628 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
3629 Standard_Integer argc,
3632 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3633 if(aContext.IsNull())
3635 di << "use 'vinit' command before " << argv[0] << "\n";
3640 di<<"Usage : " << argv[0] << " Size\n";
3643 Standard_Real aSize = atof(argv[1]);
3646 di<<"Bad Size value : " << aSize << "\n";
3650 Handle(V3d_View) aView = ViewerTest::CurrentView();
3651 aView->SetSize(aSize);
3655 //=======================================================================
3656 //function : VMoveView
3658 //=======================================================================
3659 static Standard_Integer VMoveView (Draw_Interpretor& di,
3660 Standard_Integer argc,
3663 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3664 if(aContext.IsNull())
3666 di << "use 'vinit' command before " << argv[0] << "\n";
3669 if(argc < 4 || argc > 5)
3671 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3674 Standard_Real Dx = atof(argv[1]);
3675 Standard_Real Dy = atof(argv[2]);
3676 Standard_Real Dz = atof(argv[3]);
3677 Standard_Boolean aStart = Standard_True;
3680 aStart = (atoi(argv[4]) > 0);
3683 Handle(V3d_View) aView = ViewerTest::CurrentView();
3684 aView->Move(Dx,Dy,Dz,aStart);
3688 //=======================================================================
3689 //function : VTranslateView
3691 //=======================================================================
3692 static Standard_Integer VTranslateView (Draw_Interpretor& di,
3693 Standard_Integer argc,
3696 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3697 if(aContext.IsNull())
3699 di << "use 'vinit' command before " << argv[0] << "\n";
3702 if(argc < 4 || argc > 5)
3704 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
3707 Standard_Real Dx = atof(argv[1]);
3708 Standard_Real Dy = atof(argv[2]);
3709 Standard_Real Dz = atof(argv[3]);
3710 Standard_Boolean aStart = Standard_True;
3713 aStart = (atoi(argv[4]) > 0);
3716 Handle(V3d_View) aView = ViewerTest::CurrentView();
3717 aView->Translate(Dx,Dy,Dz,aStart);
3721 //=======================================================================
3722 //function : VTurnView
3724 //=======================================================================
3725 static Standard_Integer VTurnView (Draw_Interpretor& di,
3726 Standard_Integer argc,
3729 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3730 if(aContext.IsNull()) {
3731 di << "use 'vinit' command before " << argv[0] << "\n";
3734 if(argc < 4 || argc > 5){
3735 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
3738 Standard_Real Ax = atof(argv[1]);
3739 Standard_Real Ay = atof(argv[2]);
3740 Standard_Real Az = atof(argv[3]);
3741 Standard_Boolean aStart = Standard_True;
3744 aStart = (atoi(argv[4]) > 0);
3747 Handle(V3d_View) aView = ViewerTest::CurrentView();
3748 aView->Turn(Ax,Ay,Az,aStart);
3752 //==============================================================================
3753 //function : VTextureEnv
3754 //purpose : ENables or disables environment mapping
3755 //==============================================================================
3756 class OCC_TextureEnv : public Graphic3d_TextureEnv
3759 OCC_TextureEnv(const Standard_CString FileName);
3760 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
3761 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
3762 const Standard_Boolean theModulateFlag,
3763 const Graphic3d_TypeOfTextureFilter theFilter,
3764 const Standard_ShortReal theXScale,
3765 const Standard_ShortReal theYScale,
3766 const Standard_ShortReal theXShift,
3767 const Standard_ShortReal theYShift,
3768 const Standard_ShortReal theAngle);
3769 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
3771 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
3772 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
3773 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
3775 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
3776 : Graphic3d_TextureEnv(theFileName)
3780 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
3781 : Graphic3d_TextureEnv(theTexId)
3785 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
3786 const Standard_Boolean theModulateFlag,
3787 const Graphic3d_TypeOfTextureFilter theFilter,
3788 const Standard_ShortReal theXScale,
3789 const Standard_ShortReal theYScale,
3790 const Standard_ShortReal theXShift,
3791 const Standard_ShortReal theYShift,
3792 const Standard_ShortReal theAngle)
3794 myParams->SetRepeat (theRepeatFlag);
3795 myParams->SetModulate (theModulateFlag);
3796 myParams->SetFilter (theFilter);
3797 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
3798 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
3799 myParams->SetRotation (theAngle);
3802 static int VTextureEnv (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3804 // get the active view
3805 Handle(V3d_View) aView = ViewerTest::CurrentView();
3808 std::cerr << "No active view. Please call vinit.\n";
3812 // Checking the input arguments
3813 Standard_Boolean anEnableFlag = Standard_False;
3814 Standard_Boolean isOk = theArgNb >= 2;
3817 TCollection_AsciiString anEnableOpt(theArgVec[1]);
3818 anEnableFlag = anEnableOpt.IsEqual("on");
3819 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
3823 isOk = (theArgNb == 3 || theArgNb == 11);
3826 TCollection_AsciiString aTextureOpt(theArgVec[2]);
3827 isOk = (!aTextureOpt.IsIntegerValue() ||
3828 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
3830 if (isOk && theArgNb == 11)
3832 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
3833 aModulateOpt(theArgVec[4]),
3834 aFilterOpt (theArgVec[5]),
3835 aSScaleOpt (theArgVec[6]),
3836 aTScaleOpt (theArgVec[7]),
3837 aSTransOpt (theArgVec[8]),
3838 aTTransOpt (theArgVec[9]),
3839 anAngleOpt (theArgVec[10]);
3840 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
3841 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
3842 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
3843 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
3844 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
3845 anAngleOpt.IsRealValue());
3852 std::cerr << "Usage :" << std::endl;
3853 std::cerr << theArgVec[0] << " off" << std::endl;
3854 std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
3860 TCollection_AsciiString aTextureOpt(theArgVec[2]);
3861 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
3862 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
3863 new OCC_TextureEnv(theArgVec[2]);
3867 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
3868 aTexEnv->SetTextureParameters(
3869 aRepeatOpt. IsEqual("repeat"),
3870 aModulateOpt.IsEqual("modulate"),
3871 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
3872 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
3873 Graphic3d_TOTF_TRILINEAR,
3874 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
3875 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
3876 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
3877 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
3878 (Standard_ShortReal)Draw::Atof(theArgVec[10])
3881 aView->SetTextureEnv(aTexEnv);
3882 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
3884 else // Disabling environment mapping
3886 aView->SetSurfaceDetail(V3d_TEX_NONE);
3887 Handle(Graphic3d_TextureEnv) aTexture;
3888 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
3895 //=======================================================================
3896 //function : ViewerCommands
3898 //=======================================================================
3900 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3903 const char *group = "ZeViewer";
3904 theCommands.Add("vinit" ,
3905 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3906 __FILE__,VInit,group);
3907 theCommands.Add("vhelp" ,
3908 "vhelp : display help on the viewer commands",
3909 __FILE__,VHelp,group);
3910 theCommands.Add("vtop" ,
3911 "vtop or <T> : Top view" ,
3912 __FILE__,VTop,group);
3913 theCommands.Add("vbottom" ,
3914 "vbottom : Bottom view" ,
3915 __FILE__,VBottom,group);
3916 theCommands.Add("vleft" ,
3917 "vleft : Left view" ,
3918 __FILE__,VLeft,group);
3919 theCommands.Add("vright" ,
3920 "vright : Right view" ,
3921 __FILE__,VRight,group);
3922 theCommands.Add("vaxo" ,
3923 " vaxo or <A> : Axonometric view ",
3924 __FILE__,VAxo,group);
3925 theCommands.Add("vfront" ,
3926 "vfront : Front view" ,
3927 __FILE__,VFront,group);
3928 theCommands.Add("vback" ,
3929 "vback : Back view" ,
3930 __FILE__,VBack,group);
3931 theCommands.Add("vpick" ,
3932 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
3934 theCommands.Add("vfit" ,
3935 "vfit or <F> : vfit",
3936 __FILE__,VFit,group);
3937 theCommands.Add("vzfit" ,
3939 __FILE__,VZFit,group);
3940 theCommands.Add("vrepaint",
3941 "vrepaint : vrepaint, force redraw",
3942 __FILE__,VRepaint,group);
3943 theCommands.Add("vclear",
3945 __FILE__,VClear,group);
3946 theCommands.Add("vsetbg",
3947 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
3948 __FILE__,VSetBg,group);
3949 theCommands.Add("vsetbgmode",
3950 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
3951 __FILE__,VSetBgMode,group);
3952 theCommands.Add("vsetgradientbg",
3953 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
3954 __FILE__,VSetGradientBg,group);
3955 theCommands.Add("vsetgrbgmode",
3956 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
3957 __FILE__,VSetGradientBgMode,group);
3958 theCommands.Add("vsetcolorbg",
3959 "vsetcolorbg : vsetcolorbg r g b : Set background color",
3960 __FILE__,VSetColorBg,group);
3961 theCommands.Add("vscale",
3962 "vscale : vscale X Y Z",
3963 __FILE__,VScale,group);
3964 theCommands.Add("vzbufftrihedron",
3965 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3966 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3967 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
3968 __FILE__,VTestZBuffTrihedron,group);
3969 theCommands.Add("vrotate",
3970 "vrotate : vrotate AX AY AZ [X Y Z]",
3971 __FILE__,VRotate,group);
3972 theCommands.Add("vzoom",
3973 "vzoom : vzoom coef",
3974 __FILE__,VZoom,group);
3975 theCommands.Add("vpan",
3976 "vpan : vpan dx dy",
3977 __FILE__,VPan,group);
3978 theCommands.Add("vexport",
3979 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3980 " : exports the view to a vector file of a given format"
3981 " : notice that EMF format requires patched gl2ps",
3982 __FILE__,VExport,group);
3983 theCommands.Add("vcolorscale",
3984 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3985 __FILE__,VColorScale,group);
3986 theCommands.Add("vgraduatedtrihedron",
3987 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
3988 __FILE__,VGraduatedTrihedron,group);
3989 theCommands.Add("vprintview" ,
3990 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3991 __FILE__,VPrintView,group);
3992 theCommands.Add("vzlayer",
3993 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3994 __FILE__,VZLayer,group);
3995 theCommands.Add("voverlaytext",
3996 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
3997 " : height - pixel height of the text (default=10.0)"
3998 " : font_name - name of font (default=courier)"
3999 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
4000 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
4001 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
4002 __FILE__,VOverlayText,group);
4003 theCommands.Add("vlayerline",
4004 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
4005 __FILE__,VLayerLine,group);
4006 theCommands.Add ("vgrid",
4007 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
4008 " : Mode - rectangular or circular"
4009 " : Type - lines or points",
4010 __FILE__, VGrid, group);
4011 theCommands.Add ("vfps",
4012 "vfps [framesNb=100] : estimate average frame rate for active view",
4013 __FILE__, VFps, group);
4014 theCommands.Add ("vvbo",
4015 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
4016 __FILE__, VVbo, group);
4017 theCommands.Add ("vmemgpu",
4018 "vmemgpu [f]: print system-dependent GPU memory information if available;"
4019 " with f option returns free memory in bytes",
4020 __FILE__, VMemGpu, group);
4021 theCommands.Add ("vreadpixel",
4022 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
4023 " : Read pixel value for active view",
4024 __FILE__, VReadPixel, group);
4025 theCommands.Add("diffimage",
4026 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
4027 __FILE__, VDiffImage, group);
4028 theCommands.Add ("vselect",
4029 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
4030 "- emulates different types of selection:\n"
4031 "- 1) single click selection\n"
4032 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
4033 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
4034 "- 4) any of these selections with shift button pressed",
4035 __FILE__, VSelect, group);
4036 theCommands.Add ("vmoveto",
4038 "- emulates cursor movement to pixel postion (x,y)",
4039 __FILE__, VMoveTo, group);
4040 theCommands.Add("vviewparams",
4041 "vviewparams [scale center_X center_Y proj_X proj_Y proj_Z up_X up_Y up_Z at_X at_Y at_Z]"
4042 "- gets or sets current view characteristics",
4043 __FILE__,VViewParams, group);
4044 theCommands.Add("vchangeselected",
4045 "vchangeselected shape"
4046 "- adds to shape to selection or remove one from it",
4047 __FILE__, VChangeSelected, group);
4048 theCommands.Add("vzclipping",
4049 "vzclipping [mode] [depth width]\n"
4050 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
4051 "- gets or sets ZClipping mode, width and depth",
4052 __FILE__,VZClipping,group);
4053 theCommands.Add ("vnbselected",
4054 "vnbselected", __FILE__, VNbSelected, group);
4055 theCommands.Add("vantialiasing",
4056 "vantialiasing 1|0",
4057 __FILE__,VAntialiasing,group);
4058 theCommands.Add ("vpurgedisplay",
4059 "vpurgedisplay [CollectorToo = 0|1]"
4060 "- removes structures which don't belong to objects displayed in neutral point",
4061 __FILE__, VPurgeDisplay, group);
4062 theCommands.Add("vsetviewsize",
4063 "vsetviewsize size",
4064 __FILE__,VSetViewSize,group);
4065 theCommands.Add("vmoveview",
4066 "vmoveview Dx Dy Dz [Start = 1|0]",
4067 __FILE__,VMoveView,group);
4068 theCommands.Add("vtranslateview",
4069 "vtranslateview Dx Dy Dz [Start = 1|0)]",
4070 __FILE__,VTranslateView,group);
4071 theCommands.Add("vturnview",
4072 "vturnview Ax Ay Az [Start = 1|0]",
4073 __FILE__,VTurnView,group);
4074 theCommands.Add("vtextureenv",
4075 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
4076 "or user-defined file and optionally applying texture mapping parameters\n"
4078 " vtextureenv off - disables environment mapping\n"
4079 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
4080 " std_texture = (0..7)\n"
4081 " rep = {clamp|repeat}\n"
4082 " mod = {decal|modulate}\n"
4083 " flt = {nearest|bilinear|trilinear}\n"
4084 " ss, st - scale factors for s and t texture coordinates\n"
4085 " ts, tt - translation for s and t texture coordinates\n"
4086 " rot - texture rotation angle in degrees",
4087 __FILE__, VTextureEnv, group);
4088 theCommands.Add("vhlr" ,
4089 "is_enabled={on|off}"
4090 " - Hidden line removal algorithm:"
4091 " - is_enabled: if is on HLR algorithm is applied\n",
4092 __FILE__,VHLR,group);
4093 theCommands.Add("vhlrtype" ,
4094 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
4095 " - Changes the type of HLR algorithm using for shapes."
4096 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
4097 " if equals to polyalgo, polygonal HLR algorithm is applied."
4098 "If shapes are not given HLR algoithm of given type is applied"
4099 " to all shapes in the view\n",
4100 __FILE__,VHLRType,group);