CR23684: TCollection_HExtendedString::String() returns a copy instead of const reference
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
CommitLineData
b311480e 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
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22// Robert Boehne 30 May 2000 : Dec Osf
23
24#ifdef HAVE_CONFIG_H
25# include <config.h>
26#endif
27
28#ifdef WNT
29#include <windows.h>
30#endif
31
2bd4c032 32#include <Graphic3d_AspectMarker3d.hxx>
208e6839 33#include <Graphic3d_GraphicDriver.hxx>
7fd59977 34#include <Graphic3d_ExportFormat.hxx>
35#include <ViewerTest.hxx>
36#include <ViewerTest_EventManager.hxx>
37#include <Visual3d_View.hxx>
25289ec1 38#include <Visual3d_ViewManager.hxx>
39#include <V3d_LayerMgr.hxx>
7fd59977 40#include <NIS_View.hxx>
41#include <NIS_Triangulated.hxx>
42#include <NIS_InteractiveContext.hxx>
43#include <AIS_InteractiveContext.hxx>
44#include <Draw_Interpretor.hxx>
45#include <Draw.hxx>
46#include <Draw_Appli.hxx>
7edf74fd 47#include <Aspect_PrintAlgo.hxx>
692613e5 48#include <Image_AlienPixMap.hxx>
208e6839 49#include <OSD_Timer.hxx>
59f45b7c 50#include <TColStd_SequenceOfInteger.hxx>
20637bd2 51#include <Visual3d_LayerItem.hxx>
52#include <V3d_LayerMgr.hxx>
53#include <V3d_LayerMgrPointer.hxx>
54#include <Aspect_TypeOfLine.hxx>
692613e5 55#include <Image_Diff.hxx>
7fd59977 56
25289ec1 57#ifdef WNT
58#undef DrawText
59#endif
60
61#include <Visual3d_Layer.hxx>
692613e5 62#include <cstdlib>
25289ec1 63
4fe56619 64#if defined(_WIN32) || defined(__WIN32__)
65 #include <Graphic3d_WNTGraphicDevice.hxx>
66 #include <WNT_WClass.hxx>
67 #include <WNT_Window.hxx>
68
69 #if defined(_MSC_VER)
70 #define _CRT_SECURE_NO_DEPRECATE
71 #pragma warning (disable:4996)
72 #endif
73#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
74 #include <Graphic3d_GraphicDevice.hxx>
75 #include <Cocoa_Window.hxx>
76 #include <tk.h>
7fd59977 77#else
4fe56619 78 #include <Graphic3d_GraphicDevice.hxx>
79 #include <Xw_GraphicDevice.hxx>
80 #include <Xw_WindowQuality.hxx>
81 #include <Xw_Window.hxx>
82 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
83 #include <X11/Xutil.h>
84 #include <tk.h>
7fd59977 85#endif
86
7fd59977 87//==============================================================================
88
89//==============================================================================
90// VIEWER GLOBAL VARIABLES
91//==============================================================================
92
93Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
94
95Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
96extern const Handle(NIS_InteractiveContext)& TheNISContext();
97
4fe56619 98#if defined(_WIN32) || defined(__WIN32__)
7fd59977 99static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
100 static Handle(Graphic3d_WNTGraphicDevice) GD;
101 return GD;
102}
103
104static Handle(WNT_Window)& VT_GetWindow() {
105 static Handle(WNT_Window) WNTWin;
106 return WNTWin;
107}
4fe56619 108#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
109static Handle(Graphic3d_GraphicDevice)& GetG3dDevice()
110{
111 static Handle(Graphic3d_GraphicDevice) aGraphicDevice;
112 return aGraphicDevice;
113}
114static Handle(Cocoa_Window)& VT_GetWindow()
115{
116 static Handle(Cocoa_Window) aWindow;
117 return aWindow;
118}
119extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
7fd59977 120#else
121static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
122 static Handle(Graphic3d_GraphicDevice) GD;
123 return GD;
124}
125static Handle(Xw_Window)& VT_GetWindow(){
126 static Handle(Xw_Window) XWWin;
127 return XWWin;
128}
129static Display *display;
130
131static void VProcessEvents(ClientData,int);
132#endif
133
7fd59977 134static Standard_Boolean DegenerateMode = Standard_True;
7fd59977 135
136#define ZCLIPWIDTH 1.
137
138static void OSWindowSetup();
139
140//==============================================================================
141// EVENT GLOBAL VARIABLES
142//==============================================================================
143
144static int Start_Rot = 0;
145static int ZClipIsOn = 0;
4fe56619 146int X_Motion = 0; // Current cursor position
147int Y_Motion = 0;
148int X_ButtonPress = 0; // Last ButtonPress position
149int Y_ButtonPress = 0;
150Standard_Boolean IsDragged = Standard_False;
151Standard_Boolean DragFirst;
7fd59977 152
153//==============================================================================
154
155#ifdef WNT
156static LRESULT WINAPI ViewerWindowProc(
157 HWND hwnd,
158 UINT uMsg,
159 WPARAM wParam,
160 LPARAM lParam );
161static LRESULT WINAPI AdvViewerWindowProc(
162 HWND hwnd,
163 UINT uMsg,
164 WPARAM wParam,
165 LPARAM lParam );
166#endif
167
168
169//==============================================================================
170//function : WClass
171//purpose :
172//==============================================================================
173
174const Handle(MMgt_TShared)& ViewerTest::WClass()
175{
176 static Handle(MMgt_TShared) theWClass;
4fe56619 177#if defined(_WIN32) || defined(__WIN32__)
178 if (theWClass.IsNull())
179 {
7fd59977 180 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
181 CS_VREDRAW | CS_HREDRAW, 0, 0,
182 ::LoadCursor (NULL, IDC_ARROW));
183 }
184#endif
185 return theWClass;
186}
187
188//==============================================================================
189//function : ViewerInit
190//purpose : Create the window viewer and initialize all the global variable
191//==============================================================================
192
193void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
194 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
195{
196 static Standard_Boolean isFirst = Standard_True;
197
8c3c9904 198 // Default position and dimension of the viewer window.
4fe56619 199 // Note that left top corner is set to be sufficiently small to have
8c3c9904 200 // window fit in the small screens (actual for remote desktops, see #23003).
4fe56619 201 // The position corresponds to the window's client area, thus some
8c3c9904 202 // gap is added for window frame to be visible.
203 Standard_Integer aPxLeft = 20;
204 Standard_Integer aPxTop = 40;
7fd59977 205 Standard_Integer aPxWidth = 409;
206 Standard_Integer aPxHeight = 409;
207 if (thePxWidth != 0 && thePxHeight != 0)
208 {
209 aPxLeft = thePxLeft;
210 aPxTop = thePxTop;
211 aPxWidth = thePxWidth;
212 aPxHeight = thePxHeight;
213 }
214
215 if (isFirst)
216 {
217 // Create the Graphic device
4fe56619 218#if defined(_WIN32) || defined(__WIN32__)
7fd59977 219 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
220 if (VT_GetWindow().IsNull())
221 {
222 // Create the Graphic device and the window
223 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
224
225 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
226 Handle(WNT_WClass)::DownCast (WClass()),
227 WS_OVERLAPPEDWINDOW,
228 aPxLeft, aPxTop,
229 aPxWidth, aPxHeight,
230 Quantity_NOC_BLACK);
4fe56619 231 }
232#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
233 if (GetG3dDevice().IsNull())
234 {
235 GetG3dDevice() = new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
236 }
237 if (VT_GetWindow().IsNull())
238 {
239 VT_GetWindow() = new Cocoa_Window ("Test3d",
240 aPxLeft, aPxTop,
241 aPxWidth, aPxHeight);
242 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
7fd59977 243 }
244#else
245 if (GetG3dDevice().IsNull()) GetG3dDevice() =
246 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
247 if (VT_GetWindow().IsNull())
248 {
249 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
250 "Test3d",
251 aPxLeft, aPxTop,
252 aPxWidth, aPxHeight,
253 Xw_WQ_3DQUALITY,
254 Quantity_NOC_BLACK);
7fd59977 255 }
256#endif
4fe56619 257 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
7fd59977 258
259 Handle(V3d_Viewer) a3DViewer, a3DCollector;
260 // Viewer and View creation
261
262 TCollection_ExtendedString NameOfWindow("Visu3D");
263
264 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
265 NameOfWindow = TCollection_ExtendedString("Collector");
266 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
267 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
268 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
5e27df78 269 Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
270 if (aView.IsNull())
271 {
272 //Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
7fd59977 273 aView = new NIS_View (a3DViewer, VT_GetWindow());
274 ViewerTest::CurrentView(aView);
275 TheNISContext()->AttachView (aView);
276 }
7fd59977 277
278 // AIS setup
279 if ( ViewerTest::GetAISContext().IsNull() ) {
280 Handle(AIS_InteractiveContext) C =
281 new AIS_InteractiveContext(a3DViewer,a3DCollector);
282 ViewerTest::SetAISContext(C);
283 }
284
285 // Setup for X11 or NT
286 OSWindowSetup();
287 // Viewer and View creation
288
289 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
290
291 Handle (V3d_View) V = ViewerTest::CurrentView();
292
293 V->SetDegenerateModeOn();
7fd59977 294 DegenerateMode = V->DegenerateModeIsOn();
7fd59977 295 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
296
297 V->SetZClippingDepth(0.5);
298 V->SetZClippingWidth(ZCLIPWIDTH/2.);
299 a3DViewer->SetDefaultLights();
300 a3DViewer->SetLightOn();
301
4fe56619 302 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
303 #if TCL_MAJOR_VERSION < 8
7fd59977 304 Tk_CreateFileHandler((void*)ConnectionNumber(display),
305 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 306 #else
7fd59977 307 Tk_CreateFileHandler(ConnectionNumber(display),
308 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
4fe56619 309 #endif
310 #endif
7fd59977 311
312 isFirst = Standard_False;
313 }
4fe56619 314
7fd59977 315 VT_GetWindow()->Map();
4fe56619 316 ViewerTest::CurrentView()->Redraw();
7fd59977 317}
318
319//==============================================================================
320//function : Vinit
321//purpose : Create the window viewer and initialize all the global variable
322// Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
323//==============================================================================
324
325static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
326{
327 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
328 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
329 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
330 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
331 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
332 return 0;
333}
334
335//==============================================================================
4fe56619 336//function : VT_ProcessKeyPress
7fd59977 337//purpose : Handle KeyPress event from a CString
338//==============================================================================
4fe56619 339void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 340{
341 //cout << "KeyPress" << endl;
342 const Handle(V3d_View) aView = ViewerTest::CurrentView();
343 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
344 // Letter in alphabetic order
345
346 if ( !strcasecmp(buf_ret, "A") ) {
347 // AXO
348 aView->SetProj(V3d_XposYnegZpos);
349 }
350 else if ( !strcasecmp(buf_ret, "D") ) {
351 // Reset
352 aView->Reset();
353 }
354 else if ( !strcasecmp(buf_ret, "F") ) {
355 // FitAll
356 if (aNisView.IsNull())
357 aView->FitAll();
358 else
359 aNisView->FitAll3d();
360 }
361 else if ( !strcasecmp(buf_ret, "H") ) {
362 // HLR
363 cout << "HLR" << endl;
4fe56619 364
7fd59977 365 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
366 else aView->SetDegenerateModeOn();
367 DegenerateMode = aView->DegenerateModeIsOn();
7fd59977 368 }
7fd59977 369 else if ( !strcasecmp(buf_ret, "S") ) {
370 // SHADING
371 cout << "passage en mode 1 (shading pour les shapes)" << endl;
4fe56619 372
7fd59977 373 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
374 if(Ctx->NbCurrents()==0 ||
375 Ctx->NbSelected()==0)
376 Ctx->SetDisplayMode(AIS_Shaded);
377 else{
378 if(Ctx->HasOpenedContext()){
379 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
380 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
381 }
382 else{
383 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
384 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
385 }
386 Ctx->UpdateCurrentViewer();
387 }
388 }
389 else if ( !strcasecmp(buf_ret, "U") ) {
41811896 390 // Unset display mode
7fd59977 391 cout<<"passage au mode par defaut"<<endl;
4fe56619 392
7fd59977 393 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
394 if(Ctx->NbCurrents()==0 ||
395 Ctx->NbSelected()==0)
396 Ctx->SetDisplayMode(AIS_WireFrame);
397 else{
398 if(Ctx->HasOpenedContext()){
399 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
400 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
401 }
402 else{
403 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
404 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
405 }
406 Ctx->UpdateCurrentViewer();
407 }
408
409 }
410 else if ( !strcasecmp(buf_ret, "T") ) {
411 // Top
412 aView->SetProj(V3d_Zpos);
413 }
414 else if ( !strcasecmp(buf_ret, "B") ) {
41811896 415 // Bottom
7fd59977 416 aView->SetProj(V3d_Zneg);
417 }
418 else if ( !strcasecmp(buf_ret, "L") ) {
41811896 419 // Left
7fd59977 420 aView->SetProj(V3d_Xneg);
421 }
422 else if ( !strcasecmp(buf_ret, "R") ) {
41811896 423 // Right
7fd59977 424 aView->SetProj(V3d_Xpos);
425 }
426
427 else if ( !strcasecmp(buf_ret, "W") ) {
428 // WIREFRAME
7fd59977 429 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
7fd59977 430 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
431 if(Ctx->NbCurrents()==0 ||
432 Ctx->NbSelected()==0)
433 Ctx->SetDisplayMode(AIS_WireFrame);
434 else{
435 if(Ctx->HasOpenedContext()){
436 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
437 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
438 }
439 else{
440 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
441 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
442 }
443 Ctx->UpdateCurrentViewer();
444 }
445 }
446 else if ( !strcasecmp(buf_ret, "Z") ) {
447 // ZCLIP
448
449 if ( ZClipIsOn ) {
450 cout << "ZClipping OFF" << endl;
451 ZClipIsOn = 0;
452
453 aView->SetZClippingType(V3d_OFF);
454 aView->Redraw();
455 }
456 else {
457 cout << "ZClipping ON" << endl;
458 ZClipIsOn = 1;
459
460 aView->SetZClippingType(V3d_FRONT);
461 aView->Redraw();
462 }
463 }
464 else if ( !strcasecmp(buf_ret, ",") ) {
465 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
466
467
468 }
469 else if ( !strcasecmp(buf_ret, ".") ) {
470 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
471 }
472 // Number
473 else{
474 Standard_Integer Num = atoi(buf_ret);
475 if(Num>=0 && Num<=7)
476 ViewerTest::StandardModeActivation(Num);
477 }
478}
479
480//==============================================================================
4fe56619 481//function : VT_ProcessExpose
7fd59977 482//purpose : Redraw the View on an Expose Event
483//==============================================================================
4fe56619 484void VT_ProcessExpose()
485{
486 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
487 if (!aView3d.IsNull())
488 {
489 aView3d->Redraw();
490 }
7fd59977 491}
492
493//==============================================================================
4fe56619 494//function : VT_ProcessConfigure
7fd59977 495//purpose : Resize the View on an Configure Event
496//==============================================================================
4fe56619 497void VT_ProcessConfigure()
7fd59977 498{
4fe56619 499 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
500 if (aView3d.IsNull())
501 {
502 return;
503 }
504
505 aView3d->MustBeResized();
506 aView3d->Update();
507 aView3d->Redraw();
7fd59977 508}
509
510//==============================================================================
4fe56619 511//function : VT_ProcessButton1Press
7fd59977 512//purpose : Picking
513//==============================================================================
4fe56619 514Standard_Boolean VT_ProcessButton1Press(
7fd59977 515 Standard_Integer ,
4fe56619 516 const char** argv,
7fd59977 517 Standard_Boolean pick,
4fe56619 518 Standard_Boolean shift)
7fd59977 519{
520 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
521 if ( pick ) {
522 Standard_Real X, Y, Z;
523
524 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
525
526 Draw::Set(argv[1], X);
527 Draw::Set(argv[2], Y);
528 Draw::Set(argv[3], Z);}
529
530 if(shift)
531 EM->ShiftSelect();
532 else
533 EM->Select();
534
535 pick = 0;
536 return pick;
537}
538
539//==============================================================================
4fe56619 540//function : VT_ProcessButton1Release
541//purpose : End selecting
7fd59977 542//==============================================================================
4fe56619 543void VT_ProcessButton1Release (Standard_Boolean theIsShift)
544{
545 if (IsDragged)
546 {
547 IsDragged = Standard_False;
548 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
549 if (theIsShift)
550 {
551 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
552 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
553 }
554 else
555 {
556 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
557 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
558 }
559 }
560}
7fd59977 561
4fe56619 562//==============================================================================
563//function : VT_ProcessButton3Press
564//purpose : Start Rotation
565//==============================================================================
566void VT_ProcessButton3Press()
567{
7fd59977 568 Start_Rot = 1;
569 ViewerTest::CurrentView()->SetDegenerateModeOn();
570 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 571}
4fe56619 572
7fd59977 573//==============================================================================
4fe56619 574//function : VT_ProcessButton3Release
575//purpose : End rotation
7fd59977 576//==============================================================================
4fe56619 577void VT_ProcessButton3Release()
578{
579 if (Start_Rot)
580 {
7fd59977 581 Start_Rot = 0;
582 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
583 }
7fd59977 584}
585
586//==============================================================================
587//function : ProcessZClipMotion
588//purpose : Zoom
589//==============================================================================
590
591void ProcessZClipMotion()
592{
593 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
594 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
595 static Standard_Real CurZPos = 0.;
596
597 //Quantity_Length VDX, VDY;
598 //a3DView->Size(VDX,VDY);
599 //Standard_Real VDZ = a3DView->ZSize();
600 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
601
602 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
603
604 // Front = Depth + width/2.
605 Standard_Real D = 0.5;
606 Standard_Real W = 0.1;
607
608 CurZPos += (dx);
609
610 D += CurZPos;
611
612 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
613
614 a3DView->SetZClippingType(V3d_OFF);
615 a3DView->SetZClippingDepth(D);
616 a3DView->SetZClippingWidth(W);
617 a3DView->SetZClippingType(V3d_FRONT);
618
619 a3DView->Redraw();
620
621 X_ButtonPress = X_Motion;
622 Y_ButtonPress = Y_Motion;
623 }
624}
625
626//==============================================================================
627//function : ProcessControlButton1Motion
628//purpose : Zoom
629//==============================================================================
630
631static void ProcessControlButton1Motion()
632{
633 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
634
635 X_ButtonPress = X_Motion;
636 Y_ButtonPress = Y_Motion;
637}
638
639//==============================================================================
4fe56619 640//function : VT_ProcessControlButton2Motion
641//purpose : Panning
7fd59977 642//==============================================================================
4fe56619 643void VT_ProcessControlButton2Motion()
7fd59977 644{
645 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
646 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
647
648 dy = -dy; // Xwindow Y axis is from top to Bottom
649
650 ViewerTest::CurrentView()->Panning( dx, dy );
651
652 X_ButtonPress = X_Motion;
653 Y_ButtonPress = Y_Motion;
654}
655
656//==============================================================================
4fe56619 657//function : VT_ProcessControlButton3Motion
7fd59977 658//purpose : Rotation
659//==============================================================================
4fe56619 660void VT_ProcessControlButton3Motion()
7fd59977 661{
4fe56619 662 if (Start_Rot)
663 {
664 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
665 }
7fd59977 666}
667
668//==============================================================================
4fe56619 669//function : VT_ProcessMotion
670//purpose :
7fd59977 671//==============================================================================
4fe56619 672void VT_ProcessMotion()
7fd59977 673{
674 //pre-hilights detected objects at mouse position
675
676 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
677 EM->MoveTo(X_Motion, Y_Motion);
678}
679
680
681void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
682{
683 Xpix = X_Motion;Ypix=Y_Motion;
684}
685
686//==============================================================================
44b8f2d6 687//function : ViewProject: implements VAxo, VTop, VLeft, ...
688//purpose : Switches to an axonometric, top, left and other views
689//==============================================================================
690
691static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
692{
4fe56619 693 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 694 {
695 di<<"Call vinit before this command, please"<<"\n";
696 return 1;
697 }
698
699 ViewerTest::CurrentView()->SetProj(ori);
700 return 0;
701}
702
703//==============================================================================
7fd59977 704//function : VAxo
705//purpose : Switch to an Axonometric view
706//Draw arg : No args
707//==============================================================================
708
709static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 710{
711 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 712}
713
714//==============================================================================
715//function : VTop
716//purpose : Switch to a Top View
717//Draw arg : No args
718//==============================================================================
719
720static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
721{
44b8f2d6 722 return ViewProject(di, V3d_Zpos);
723}
7fd59977 724
44b8f2d6 725//==============================================================================
726//function : VBottom
727//purpose : Switch to a Bottom View
728//Draw arg : No args
729//==============================================================================
7fd59977 730
44b8f2d6 731static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
732{
733 return ViewProject(di, V3d_Zneg);
734}
7fd59977 735
44b8f2d6 736//==============================================================================
737//function : VLeft
738//purpose : Switch to a Left View
739//Draw arg : No args
740//==============================================================================
741
742static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
743{
744 return ViewProject(di, V3d_Ypos);
745}
746
747//==============================================================================
748//function : VRight
749//purpose : Switch to a Right View
750//Draw arg : No args
751//==============================================================================
752
753static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
754{
755 return ViewProject(di, V3d_Yneg);
756}
7fd59977 757
44b8f2d6 758//==============================================================================
759//function : VFront
760//purpose : Switch to a Front View
761//Draw arg : No args
762//==============================================================================
763
764static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
765{
766 return ViewProject(di, V3d_Xpos);
767}
768
769//==============================================================================
770//function : VBack
771//purpose : Switch to a Back View
772//Draw arg : No args
773//==============================================================================
774
775static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
776{
777 return ViewProject(di, V3d_Xneg);
7fd59977 778}
779
780//==============================================================================
781//function : VHelp
782//purpose : Dsiplay help on viewer Keyboead and mouse commands
783//Draw arg : No args
784//==============================================================================
785
786static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
787{
788
789 di << "Q : Quit the application" << "\n";
790
791 di << "========================="<<"\n";
792 di << "F : FitAll" << "\n";
793 di << "T : TopView" << "\n";
41811896 794 di << "B : BottomView" << "\n";
795 di << "R : RightView" << "\n";
796 di << "L : LeftView" << "\n";
7fd59977 797 di << "A : AxonometricView" << "\n";
41811896 798 di << "D : ResetView" << "\n";
7fd59977 799
800 di << "========================="<<"\n";
801 di << "S : Shading" << "\n";
802 di << "W : Wireframe" << "\n";
803 di << "H : HidelLineRemoval" << "\n";
41811896 804 di << "U : Unset display mode" << "\n";
7fd59977 805
806 di << "========================="<<"\n";
807 di << "Selection mode "<<"\n";
808 di << "0 : Shape" <<"\n";
809 di << "1 : Vertex" <<"\n";
810 di << "2 : Edge" <<"\n";
811 di << "3 : Wire" <<"\n";
812 di << "4 : Face" <<"\n";
813 di << "5 : Shell" <<"\n";
814 di << "6 : Solid" <<"\n";
815 di << "7 : Compound" <<"\n";
816
41811896 817 di << "========================="<<"\n";
818 di << "Z : Switch Z clipping On/Off" << "\n";
819 di << ", : Hilight next detected" << "\n";
820 di << ". : Hilight previous detected" << "\n";
7fd59977 821
822 return 0;
823}
824
7fd59977 825#ifdef WNT
826
827static Standard_Boolean Ppick = 0;
828static Standard_Integer Pargc = 0;
829static const char** Pargv = NULL;
830
831
832static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
833 UINT Msg,
834 WPARAM wParam,
835 LPARAM lParam )
836{
837 if ( !ViewerTest::CurrentView().IsNull() ) {
838
839 WPARAM fwKeys = wParam;
840
841 switch( Msg ) {
842
843 case WM_LBUTTONUP:
844 IsDragged = Standard_False;
845 if( !DragFirst )
846 {
847 HDC hdc = GetDC( hwnd );
848 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
849 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
850 SetROP2( hdc, R2_NOT );
4fe56619 851 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 852 ReleaseDC( hwnd, hdc );
853
854 const Handle(ViewerTest_EventManager) EM =
855 ViewerTest::CurrentEventManager();
856 if ( fwKeys & MK_SHIFT )
4fe56619 857 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
858 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
7fd59977 859 else
4fe56619 860 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
861 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
7fd59977 862 }
863 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
864
865 case WM_LBUTTONDOWN:
866 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
867 {
868 IsDragged = Standard_True;
869 DragFirst = Standard_True;
4fe56619 870 X_ButtonPress = LOWORD(lParam);
871 Y_ButtonPress = HIWORD(lParam);
7fd59977 872 }
873 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
874
875 break;
876
877 case WM_MOUSEMOVE:
878 if( IsDragged )
879 {
880 HDC hdc = GetDC( hwnd );
881
882 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
883 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
884 SetROP2( hdc, R2_NOT );
885
886 if( !DragFirst )
4fe56619 887 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 888
889 DragFirst = Standard_False;
4fe56619 890 X_Motion = LOWORD(lParam);
891 Y_Motion = HIWORD(lParam);
7fd59977 892
4fe56619 893 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 894
895 SelectObject( hdc, anObj );
896
897 ReleaseDC( hwnd, hdc );
898 }
899 else
900 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
901 break;
902
903 default:
904 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
905 }
906 return 0;
907 }
908 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
909}
910
911
912static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
913 UINT Msg,
914 WPARAM wParam,
915 LPARAM lParam )
916{
917 /*static Standard_Boolean Ppick = 0;
918 static Standard_Integer Pargc = 0;
919 static char** Pargv = NULL;*/
920
921 static int Up = 1;
922
923 if ( !ViewerTest::CurrentView().IsNull() ) {
924 PAINTSTRUCT ps;
925
926 switch( Msg ) {
927 case WM_CLOSE:
928 // do not destroy the window - just hide it!
929 VT_GetWindow()->Unmap();
930 return 0;
931 case WM_PAINT:
7fd59977 932 BeginPaint(hwnd, &ps);
933 EndPaint(hwnd, &ps);
4fe56619 934 VT_ProcessExpose();
7fd59977 935 break;
936
937 case WM_SIZE:
4fe56619 938 VT_ProcessConfigure();
7fd59977 939 break;
940
941 case WM_KEYDOWN:
4fe56619 942 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
943 {
7fd59977 944 char c[2];
945 c[0] = (char) wParam;
946 c[1] = '\0';
4fe56619 947 VT_ProcessKeyPress (c);
7fd59977 948 }
949 break;
950
951 case WM_LBUTTONUP:
952 case WM_MBUTTONUP:
953 case WM_RBUTTONUP:
7fd59977 954 Up = 1;
4fe56619 955 VT_ProcessButton3Release();
7fd59977 956 break;
957
958 case WM_LBUTTONDOWN:
959 case WM_MBUTTONDOWN:
960 case WM_RBUTTONDOWN:
961 {
7fd59977 962 WPARAM fwKeys = wParam;
963
964 Up = 0;
965
966 X_ButtonPress = LOWORD(lParam);
967 Y_ButtonPress = HIWORD(lParam);
968
4fe56619 969 if (Msg == WM_LBUTTONDOWN)
970 {
971 if (fwKeys & MK_CONTROL)
972 {
973 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
974 }
975 else
976 {
977 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
978 }
7fd59977 979 }
4fe56619 980 else if (Msg == WM_RBUTTONDOWN)
981 {
7fd59977 982 // Start rotation
4fe56619 983 VT_ProcessButton3Press();
7fd59977 984 }
985 }
986 break;
987
988 case WM_MOUSEMOVE:
989 {
990 //cout << "\t WM_MOUSEMOVE" << endl;
991 WPARAM fwKeys = wParam;
992 X_Motion = LOWORD(lParam);
993 Y_Motion = HIWORD(lParam);
994
995 if ( Up &&
996 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
997 Up = 0;
998 X_ButtonPress = LOWORD(lParam);
999 Y_ButtonPress = HIWORD(lParam);
1000
1001 if ( fwKeys & MK_RBUTTON ) {
1002 // Start rotation
4fe56619 1003 VT_ProcessButton3Press();
7fd59977 1004 }
1005 }
1006
1007 if ( fwKeys & MK_CONTROL ) {
1008 if ( fwKeys & MK_LBUTTON ) {
1009 ProcessControlButton1Motion();
1010 }
1011 else if ( fwKeys & MK_MBUTTON ||
1012 ((fwKeys&MK_LBUTTON) &&
1013 (fwKeys&MK_RBUTTON) ) ){
4fe56619 1014 VT_ProcessControlButton2Motion();
7fd59977 1015 }
1016 else if ( fwKeys & MK_RBUTTON ) {
4fe56619 1017 VT_ProcessControlButton3Motion();
7fd59977 1018 }
1019 }
1020#ifdef BUG
1021 else if ( fwKeys & MK_SHIFT ) {
1022 if ( fwKeys & MK_MBUTTON ||
1023 ((fwKeys&MK_LBUTTON) &&
1024 (fwKeys&MK_RBUTTON) ) ) {
1025 cout << "ProcessZClipMotion()" << endl;
1026 ProcessZClipMotion();
1027 }
1028 }
1029#endif
1030 else
4fe56619 1031 if ((fwKeys & MK_MBUTTON
1032 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
1033 {
7fd59977 1034 ProcessZClipMotion();
1035 }
4fe56619 1036 else
1037 {
1038 VT_ProcessMotion();
7fd59977 1039 }
1040 }
1041 break;
1042
1043 default:
1044 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
1045 }
1046 return 0L;
1047 }
1048
1049 return DefWindowProc( hwnd, Msg, wParam, lParam );
1050}
1051
1052
1053
1054
1055//==============================================================================
1056//function : ViewerMainLoop
1057//purpose : Get a Event on the view and dispatch it
1058//==============================================================================
1059
1060
1061static int ViewerMainLoop(Standard_Integer argc, const char** argv)
1062{
1063
1064 //cout << "No yet implemented on WNT" << endl;
1065 /*static Standard_Boolean Ppick = 0;
1066 static Standard_Integer Pargc = 0;
1067 static char** Pargv = NULL;*/
1068
1069 //Ppick = (argc > 0)? -1 : 0;
1070 Ppick = (argc > 0)? 1 : 0;
1071 Pargc = argc;
1072 Pargv = argv;
1073
1074 if ( Ppick ) {
1075 MSG msg;
1076 msg.wParam = 1;
1077
1078 cout << "Start picking" << endl;
1079
1080 //while ( Ppick == -1 ) {
1081 while ( Ppick == 1 ) {
4fe56619 1082 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
7fd59977 1083 if (GetMessage(&msg, NULL, 0, 0) ) {
1084 TranslateMessage(&msg);
1085 DispatchMessage(&msg);
1086 }
1087 }
1088
1089 cout << "Picking done" << endl;
1090 }
1091
1092 return Ppick;
1093}
1094
4fe56619 1095#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 1096
1097int min( int a, int b )
1098{
1099 if( a<b )
1100 return a;
1101 else
1102 return b;
1103}
1104
1105int max( int a, int b )
1106{
1107 if( a>b )
1108 return a;
1109 else
1110 return b;
1111}
1112
1113int ViewerMainLoop(Standard_Integer argc, const char** argv)
1114
1115{ Standard_Boolean pick = argc > 0;
1116
1117// X11 Event loop
1118
1119static XEvent report;
1120
1121XNextEvent( display, &report );
1122// cout << "rep type = " << report.type << endl;
1123// cout << "rep button = " << report.xbutton.button << endl;
1124
1125switch ( report.type ) {
1126 case Expose:
1127 {
4fe56619 1128 VT_ProcessExpose();
7fd59977 1129 }
1130 break;
1131 case ConfigureNotify:
1132 {
4fe56619 1133 VT_ProcessConfigure();
7fd59977 1134 }
1135 break;
1136 case KeyPress:
1137 {
1138
1139 KeySym ks_ret ;
1140 char buf_ret[11] ;
1141 int ret_len ;
1142 XComposeStatus status_in_out;
1143
1144 ret_len = XLookupString( ( XKeyEvent *)&report ,
1145 (char *) buf_ret , 10 ,
1146 &ks_ret , &status_in_out ) ;
1147
1148
1149 buf_ret[ret_len] = '\0' ;
1150
4fe56619 1151 if (ret_len)
1152 {
1153 VT_ProcessKeyPress (buf_ret);
7fd59977 1154 }
1155 }
1156 break;
1157 case ButtonPress:
1158 // cout << "ButtonPress" << endl;
1159 {
1160 X_ButtonPress = report.xbutton.x;
1161 Y_ButtonPress = report.xbutton.y;
1162
4fe56619 1163 if (report.xbutton.button == Button1)
1164 {
1165 if (report.xbutton.state & ControlMask)
1166 {
1167 pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
1168 }
7fd59977 1169 else
1170 {
1171 IsDragged = Standard_True;
4fe56619 1172 X_ButtonPress = X_ButtonPress;
1173 Y_ButtonPress = Y_ButtonPress;
7fd59977 1174 DragFirst = Standard_True;
1175 }
4fe56619 1176 }
1177 else if (report.xbutton.button == Button3)
1178 {
7fd59977 1179 // Start rotation
4fe56619 1180 VT_ProcessButton3Press();
1181 }
7fd59977 1182 }
1183 break;
1184 case ButtonRelease:
1185 {
1186 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1187 // cout << IsDragged << endl;
1188 // cout << DragFirst << endl;
1189
1190 if( IsDragged )
1191 {
1192 if( !DragFirst )
1193 {
1194 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1195 GC gc = XCreateGC( display, aWindow, 0, 0 );
1196 // XSetFunction( display, gc, GXinvert );
4fe56619 1197 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
7fd59977 1198 }
1199
1200 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1201 if( aContext.IsNull() )
1202 {
1203 cout << "The context is null. Please use vinit before createmesh" << endl;
1204 return 0;
1205 }
1206
1207 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1208 if( report.xbutton.button==1 )
1209 if( DragFirst )
1210 if( ShiftPressed )
1211 {
1212 aContext->ShiftSelect();
1213 // cout << "shift select" << endl;
1214 }
1215 else
1216 {
1217 aContext->Select();
1218 // cout << "select" << endl;
1219 }
1220 else
1221 if( ShiftPressed )
1222 {
4fe56619 1223 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1224 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 1225 ViewerTest::CurrentView());
1226 // cout << "shift select" << endl;
1227 }
1228 else
1229 {
4fe56619 1230 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
1231 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 1232 ViewerTest::CurrentView() );
1233 // cout << "select" << endl;
1234 }
1235 else
4fe56619 1236 VT_ProcessButton3Release();
7fd59977 1237
1238 IsDragged = Standard_False;
1239 }
1240 else
4fe56619 1241 VT_ProcessButton3Release();
7fd59977 1242 }
1243 break;
1244 case MotionNotify:
1245 {
1246 // XEvent dummy;
1247
1248 X_Motion = report.xmotion.x;
1249 Y_Motion = report.xmotion.y;
1250
1251 if( IsDragged )
1252 {
1253 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1254 GC gc = XCreateGC( display, aWindow, 0, 0 );
1255 XSetFunction( display, gc, GXinvert );
1256
1257 if( !DragFirst )
4fe56619 1258 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
7fd59977 1259
4fe56619 1260 X_Motion = X_Motion;
1261 Y_Motion = Y_Motion;
7fd59977 1262 DragFirst = Standard_False;
1263
4fe56619 1264 //cout << "draw rect : " << X_Motion << ", " << Y_Motion << endl;
1265 XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
7fd59977 1266 }
1267 else
1268 {
1269
1270 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1271
1272 // remove all the ButtonMotionMask
1273 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1274
1275 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1276 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1277
1278 Quantity_Length VDX, VDY;
1279
1280 ViewerTest::CurrentView()->Size(VDX,VDY);
1281 Standard_Real VDZ =0 ;
1282 VDZ = ViewerTest::CurrentView()->ZSize();
1283
1284 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1285 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1286
1287 Quantity_Length dx = 0 ;
1288 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1289
1290 cout << dx << endl;
1291
1292 dx = dx / VDX * VDZ;
1293
1294 cout << dx << endl;
1295
1296 // Front = Depth + width/2.
1297 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1298 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1299
1300 ViewerTest::CurrentView()->Redraw();
1301 }
1302 }
1303
1304 if ( report.xmotion.state & ControlMask ) {
1305 if ( report.xmotion.state & Button1Mask ) {
1306 ProcessControlButton1Motion();
1307 }
1308 else if ( report.xmotion.state & Button2Mask ) {
4fe56619 1309 VT_ProcessControlButton2Motion();
7fd59977 1310 }
1311 else if ( report.xmotion.state & Button3Mask ) {
4fe56619 1312 VT_ProcessControlButton3Motion();
7fd59977 1313 }
1314 }
4fe56619 1315 else
1316 {
1317 VT_ProcessMotion();
7fd59977 1318 }
1319 }
1320 }
1321 break;
1322}
1323
1324
1325return pick;
1326}
1327
1328//==============================================================================
1329//function : VProcessEvents
1330//purpose : call by Tk_CreateFileHandler() to be able to manage the
1331// event in the Viewer window
1332//==============================================================================
1333
1334static void VProcessEvents(ClientData,int)
1335{
1336 //cout << "VProcessEvents" << endl;
1337
1338 // test for X Event
1339 while (XPending(display)) {
1340 ViewerMainLoop( 0, NULL);
1341 }
1342}
1343#endif
1344
1345//==============================================================================
1346//function : OSWindowSetup
1347//purpose : Setup for the X11 window to be able to cath the event
1348//==============================================================================
1349
1350
1351static void OSWindowSetup()
1352{
4fe56619 1353#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 1354 // X11
1355
1356 Window window = VT_GetWindow()->XWindow();
1357
1358 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1359 display = (Display * ) theDisplay;
1360 // display = (Display *)GetG3dDevice()->XDisplay();
1361
1362 XSynchronize(display, 1);
1363
1364 VT_GetWindow()->Map();
1365
1366 // X11 : For keyboard on SUN
1367 XWMHints wmhints;
1368 wmhints.flags = InputHint;
1369 wmhints.input = 1;
1370
1371 XSetWMHints( display, window, &wmhints);
1372
1373 XSelectInput( display, window, ExposureMask | KeyPressMask |
1374 ButtonPressMask | ButtonReleaseMask |
1375 StructureNotifyMask |
1376 PointerMotionMask |
1377 Button1MotionMask | Button2MotionMask |
1378 Button3MotionMask
1379 );
1380
1381 XSynchronize(display, 0);
1382
1383#else
1384 // WNT
1385#endif
1386
1387}
1388
1389
1390//==============================================================================
1391//function : VFit
1392
1393//purpose : Fitall, no DRAW arguments
1394//Draw arg : No args
1395//==============================================================================
1396
1397static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1398{
1399 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1400 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1401 if (V.IsNull() == Standard_False) {
1402 V->FitAll3d();
1403 } else if (aView.IsNull() == Standard_False) {
1404 aView->FitAll();
1405 }
1406 return 0;
1407}
1408
1409//==============================================================================
1410//function : VZFit
1411//purpose : ZFitall, no DRAW arguments
1412//Draw arg : No args
1413//==============================================================================
1414
1415static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1416{
1417 Handle(V3d_View) V = ViewerTest::CurrentView();
1418 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1419
1420
1421static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1422{
1423 Handle(V3d_View) V = ViewerTest::CurrentView();
1424 if ( !V.IsNull() ) V->Redraw(); return 0;
1425}
1426
1427
1428//==============================================================================
1429//function : VClear
1430//purpose : Remove all the object from the viewer
1431//Draw arg : No args
1432//==============================================================================
1433
1434static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1435{
1436 Handle(V3d_View) V = ViewerTest::CurrentView();
1437 if(!V.IsNull())
1438 ViewerTest::Clear();
1439 return 0;
1440}
1441
1442//==============================================================================
1443//function : VPick
1444//purpose :
1445//==============================================================================
1446
1447static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1448{ if (ViewerTest::CurrentView().IsNull() ) return 1;
1449
1450if ( argc < 4 ) {
1451 di << argv[0] << "Invalid number of arguments" << "\n";
1452 return 1;
1453}
1454
1455while (ViewerMainLoop( argc, argv)) {
1456}
1457
1458return 0;
1459}
1460
7fd59977 1461//==============================================================================
1462//function : InitViewerTest
1463//purpose : initialisation de toutes les variables static de ViewerTest (dp)
1464//==============================================================================
1465
1466void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1467{
1468 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1469 ViewerTest::SetAISContext(context);
1470 viewer->InitActiveViews();
1471 Handle(V3d_View) view = viewer->ActiveView();
1472 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1473 ViewerTest::ResetEventManager();
1474 Handle(Aspect_GraphicDevice) device = viewer->Device();
1475 Handle(Aspect_Window) window = view->Window();
4fe56619 1476#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 1477 // X11
1478 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1479 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1480 OSWindowSetup();
1481 static int first = 1;
1482 if ( first ) {
1483#if TCL_MAJOR_VERSION < 8
1484 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1485 TK_READABLE, VProcessEvents, (ClientData) 0);
1486#else
1487 Tk_CreateFileHandler(ConnectionNumber(display),
1488 TK_READABLE, VProcessEvents, (ClientData) 0);
1489#endif
1490 first = 0;
1491 }
1492#endif
1493}
1494
7fd59977 1495//==============================================================================
1496//function : VSetBg
1497//purpose : Load image as background
1498//==============================================================================
1499
1500static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1501{
1502 if (argc < 2 || argc > 3)
1503 {
1504 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
f8b2ed36 1505 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
7fd59977 1506 return 1;
1507 }
1508
1509 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1510 if(AISContext.IsNull())
1511 {
1512 di << "use 'vinit' command before " << argv[0] << "\n";
1513 return 1;
1514 }
1515
1516 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1517 if (argc == 3)
1518 {
1519 const char* szType = argv[2];
1520 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1521 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1522 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1523 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1524 else
1525 {
1526 di << "Wrong fill type : " << szType << "\n";
1527 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1528 return 1;
1529 }
1530 }
1531
1532 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1533 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1534
1535 return 0;
1536}
1537
1538//==============================================================================
f8b2ed36 1539//function : VSetBgMode
1540//purpose : Change background image fill type
1541//==============================================================================
1542
1543static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1544{
1545 if (argc != 2)
1546 {
1547 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1548 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1549 return 1;
1550 }
1551
1552 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1553 if(AISContext.IsNull())
1554 {
1555 di << "use 'vinit' command before " << argv[0] << "\n";
1556 return 1;
1557 }
1558
1559 Aspect_FillMethod aFillType;
1560 if (argc == 2)
1561 {
1562 const char* szType = argv[1];
1563 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1564 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1565 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1566 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1567 else
1568 {
1569 di << "Wrong fill type : " << szType << "\n";
1570 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1571 return 1;
1572 }
1573 }
1574
1575 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1576 V3dView->SetBgImageStyle(aFillType, Standard_True);
1577
1578 return 0;
1579}
1580
1581//==============================================================================
7fd59977 1582//function : VSetGradientBg
1583//purpose : Mount gradient background
1584//==============================================================================
1585static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1586{
1587 if (argc != 8 )
1588 {
1589 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1590 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1591 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1592 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1593 return 1;
1594 }
1595
1596 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1597 if(AISContext.IsNull())
1598 {
1599 di << "use 'vinit' command before " << argv[0] << "\n";
1600 return 1;
1601 }
1602 if (argc == 8)
1603 {
1604
1605 Standard_Real R1 = atof(argv[1])/255.;
1606 Standard_Real G1 = atof(argv[2])/255.;
1607 Standard_Real B1 = atof(argv[3])/255.;
1608 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1609
1610 Standard_Real R2 = atof(argv[4])/255.;
1611 Standard_Real G2 = atof(argv[5])/255.;
1612 Standard_Real B2 = atof(argv[6])/255.;
1613
1614 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1615 int aType = atoi(argv[7]);
1616 if( aType < 0 || aType > 8 )
1617 {
1618 di << "Wrong fill type " << "\n";
1619 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1620 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1621 return 1;
1622 }
1623
1624 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1625
1626 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1627 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1628 }
1629
1630 return 0;
1631}
1632
1633//==============================================================================
f8b2ed36 1634//function : VSetGradientBgMode
1635//purpose : Change gradient background fill style
1636//==============================================================================
1637static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1638{
1639 if (argc != 2 )
1640 {
1641 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1642 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1643 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1644 return 1;
1645 }
1646
1647 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1648 if(AISContext.IsNull())
1649 {
1650 di << "use 'vinit' command before " << argv[0] << "\n";
1651 return 1;
1652 }
1653 if (argc == 2)
1654 {
1655 int aType = atoi(argv[1]);
1656 if( aType < 0 || aType > 8 )
1657 {
1658 di << "Wrong fill type " << "\n";
1659 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1660 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1661 return 1;
1662 }
1663
1664 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1665
1666 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1667 V3dView->SetBgGradientStyle( aMethod, 1 );
1668 }
1669
1670 return 0;
1671}
1672
1673//==============================================================================
1674//function : VSetColorBg
1675//purpose : Set color background
1676//==============================================================================
1677static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1678{
1679 if (argc != 4 )
1680 {
1681 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1682 di << "R,G,B = [0..255]" << "\n";
1683 return 1;
1684 }
1685
1686 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1687 if(AISContext.IsNull())
1688 {
1689 di << "use 'vinit' command before " << argv[0] << "\n";
1690 return 1;
1691 }
1692 if (argc == 4)
1693 {
1694
1695 Standard_Real R = atof(argv[1])/255.;
1696 Standard_Real G = atof(argv[2])/255.;
1697 Standard_Real B = atof(argv[3])/255.;
1698 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1699
1700 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1701 V3dView->SetBackgroundColor( aColor );
1702 V3dView->Update();
1703 }
1704
1705 return 0;
1706}
1707
1708//==============================================================================
7fd59977 1709//function : VScale
1710//purpose : View Scaling
1711//==============================================================================
1712
1713static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1714{
1715 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1716 if ( V3dView.IsNull() ) return 1;
1717
1718 if ( argc != 4 ) {
1719 di << argv[0] << "Invalid number of arguments" << "\n";
1720 return 1;
1721 }
1722 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1723 return 0;
1724}
1725//==============================================================================
1726//function : VTestZBuffTrihedron
7c8a8fcc 1727//purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
7fd59977 1728//==============================================================================
1729
1730static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1731{
1732 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1733 if ( V3dView.IsNull() ) return 1;
1734
7fd59977 1735 V3dView->ZBufferTriedronSetup();
7c8a8fcc 1736
1737 if ( argc == 1 ) {
1738 // Set up default trihedron parameters
1739 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1740 } else
1741 if ( argc == 7 )
1742 {
1743 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
1744 const char* aPosType = argv[1];
1745
1746 if ( strcmp(aPosType, "center") == 0 )
1747 {
1748 aPosition = Aspect_TOTP_CENTER;
1749 } else
1750 if (strcmp(aPosType, "left_lower") == 0)
1751 {
1752 aPosition = Aspect_TOTP_LEFT_LOWER;
1753 } else
1754 if (strcmp(aPosType, "left_upper") == 0)
1755 {
1756 aPosition = Aspect_TOTP_LEFT_UPPER;
1757 } else
1758 if (strcmp(aPosType, "right_lower") == 0)
1759 {
1760 aPosition = Aspect_TOTP_RIGHT_LOWER;
1761 } else
1762 if (strcmp(aPosType, "right_upper") == 0)
1763 {
1764 aPosition = Aspect_TOTP_RIGHT_UPPER;
1765 } else
1766 {
1767 di << argv[1] << " Invalid type of alignment" << "\n";
1768 di << "Must be one of [ center, left_lower," << "\n";
1769 di << "left_upper, right_lower, right_upper ]" << "\n";
1770 return 1;
1771 }
1772
1773 Standard_Real R = atof(argv[2])/255.;
1774 Standard_Real G = atof(argv[3])/255.;
1775 Standard_Real B = atof(argv[4])/255.;
1776 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
1777
1778 Standard_Real aScale = atof(argv[5]);
1779
1780 if( aScale <= 0.0 )
1781 {
1782 di << argv[5] << " Invalid value. Must be > 0" << "\n";
1783 return 1;
1784 }
1785
1786 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
1787 const char* aPresType = argv[6];
1788
1789 if ( strcmp(aPresType, "wireframe") == 0 )
1790 {
1791 aPresentation = V3d_WIREFRAME;
1792 } else
1793 if (strcmp(aPresType, "zbuffer") == 0)
1794 {
1795 aPresentation = V3d_ZBUFFER;
1796 } else
1797 {
1798 di << argv[6] << " Invalid type of visualization" << "\n";
1799 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
1800 return 1;
1801 }
1802
1803 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
1804
1805 } else
1806 {
1807 di << argv[0] << " Invalid number of arguments" << "\n";
1808 return 1;
1809 }
1810
7fd59977 1811 V3dView->ZFitAll();
7c8a8fcc 1812
7fd59977 1813 return 0;
1814}
1815
1816//==============================================================================
1817//function : VRotate
1818//purpose : Camera Rotating
1819//==============================================================================
1820
1821static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1822 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1823 if ( V3dView.IsNull() ) {
1824 return 1;
1825 }
1826
1827 if ( argc == 4 ) {
1828 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1829 return 0;
1830 } else if ( argc == 7 ) {
1831 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1832 return 0;
1833 } else {
1834 di << argv[0] << " Invalid number of arguments" << "\n";
1835 return 1;
1836 }
1837}
1838
1839//==============================================================================
1840//function : VZoom
1841//purpose : View zoom in / out (relative to current zoom)
1842//==============================================================================
1843
1844static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1845 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1846 if ( V3dView.IsNull() ) {
1847 return 1;
1848 }
1849
1850 if ( argc == 2 ) {
1851 Standard_Real coef = atof(argv[1]);
1852 if ( coef <= 0.0 ) {
1853 di << argv[1] << "Invalid value" << "\n";
1854 return 1;
1855 }
1856 V3dView->SetZoom( atof(argv[1]) );
1857 return 0;
1858 } else {
1859 di << argv[0] << " Invalid number of arguments" << "\n";
1860 return 1;
1861 }
1862}
1863
1864//==============================================================================
1865//function : VPan
1866//purpose : View panning (in pixels)
1867//==============================================================================
1868
1869static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1870 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1871 if ( V3dView.IsNull() ) return 1;
1872
1873 if ( argc == 3 ) {
1874 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1875 return 0;
1876 } else {
1877 di << argv[0] << " Invalid number of arguments" << "\n";
1878 return 1;
1879 }
1880}
1881
1882
1883//==============================================================================
1884//function : VExport
5cedc27f 1885//purpose : Export the view to a vector graphic format (PS, EMF, PDF)
7fd59977 1886//==============================================================================
1887
1888static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1889{
1890 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
5cedc27f
K
1891 if (V3dView.IsNull())
1892 return 1;
7fd59977 1893
5cedc27f
K
1894 if (argc == 1)
1895 {
1896 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
7fd59977 1897 return 1;
1898 }
1899
5cedc27f
K
1900 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1901 TCollection_AsciiString aFormatStr;
1902
1903 TCollection_AsciiString aFileName (argv[1]);
1904 Standard_Integer aLen = aFileName.Length();
1905
1906 if (argc > 2)
1907 {
1908 aFormatStr = TCollection_AsciiString (argv[2]);
1909 }
1910 else if (aLen >= 4)
1911 {
1912 if (aFileName.Value (aLen - 2) == '.')
1913 {
1914 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1915 }
1916 else if (aFileName.Value (aLen - 3) == '.')
1917 {
1918 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1919 }
1920 else
1921 {
1922 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1923 return 1;
1924 }
1925 }
1926 else
1927 {
1928 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1929 return 1;
1930 }
1931
1932 aFormatStr.UpperCase();
1933 if (aFormatStr == "PS")
1934 anExpFormat = Graphic3d_EF_PostScript;
1935 else if (aFormatStr == "EPS")
1936 anExpFormat = Graphic3d_EF_EnhPostScript;
1937 else if (aFormatStr == "TEX")
1938 anExpFormat = Graphic3d_EF_TEX;
1939 else if (aFormatStr == "PDF")
1940 anExpFormat = Graphic3d_EF_PDF;
1941 else if (aFormatStr == "SVG")
1942 anExpFormat = Graphic3d_EF_SVG;
1943 else if (aFormatStr == "PGF")
1944 anExpFormat = Graphic3d_EF_PGF;
1945 else if (aFormatStr == "EMF")
1946 anExpFormat = Graphic3d_EF_EMF;
1947 else
1948 {
1949 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1950 return 1;
1951 }
1952
1953 if (!V3dView->View()->Export (argv[1], anExpFormat))
1954 {
1955 std::cout << "Export failed!\n";
1956 return 1;
1957 }
7fd59977 1958 return 0;
1959}
1960
1961//==============================================================================
1962//function : VColorScale
1963//purpose : representation color scale
1964//==============================================================================
1965#include <V3d_ColorScale.hxx>
1966
1967static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1968{
1969 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1970 {
1971 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1972 return 1;
1973 }
1974
1975 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1976 if(aContext.IsNull()) {
1977 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1978 return -1;
1979 }
1980
1981 Standard_Real minRange = 0. , maxRange = 100. ;
1982
1983 Standard_Integer numIntervals = 10 ;
208e6839 1984 Standard_Integer textHeight = 16;
7fd59977 1985 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1986 Standard_Real X = 0., Y = 0. ;
1987
1988 if ( argc < 9 )
1989 {
1990 if( argc > 3 )
1991 {
1992 minRange = atof( argv[1] );
1993 maxRange = atof( argv[2] );
1994 numIntervals = atoi( argv[3] );
1995 }
1996 if ( argc > 4 )
208e6839 1997 textHeight = atoi( argv[4] );
7fd59977 1998 if ( argc > 5 )
1999 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
2000 if ( argc > 7 )
2001 {
2002 X = atof( argv[6] );
2003 Y = atof( argv[7] );
2004 }
2005 }
2006 Handle(V3d_View) curView = ViewerTest::CurrentView( );
2007 if ( curView.IsNull( ) )
2008 return 1;
2009 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
2010 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
2011 if( ! aCS.IsNull( ) )
2012 {
2013 aCS->SetPosition( X , Y );
2014 aCS->SetHeight( 0.95) ;
2015 aCS->SetTextHeight( textHeight );
2016 aCS->SetRange( minRange , maxRange );
2017 aCS->SetNumberOfIntervals( numIntervals );
2018 aCS->SetLabelPosition( position );
2019 if( !curView->ColorScaleIsDisplayed() )
2020 curView->ColorScaleDisplay( );
2021 }
2022 return 0;
2023}
2024
2025//==============================================================================
2026//function : VGraduatedTrihedron
2027//purpose : Displays a graduated trihedron
2028//==============================================================================
13a22457
S
2029
2030static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
2031{
2032 const char *str = arg;
2033 while (*str)
2034 {
2035 unsigned short c1 = *str++;
2036 unsigned short c2 = *str++;
2037 if (!c1 || !c2) break;
2038 name += (Standard_ExtCharacter)((c1 << 8) | c2);
2039 }
2040}
2041
7fd59977 2042static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2043{
13a22457
S
2044 // Check arguments
2045 if (argc != 2 && argc < 5)
2046 {
2047 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
2048 di<<"Usage: type help "<<argv[0]<<"\n";
2049 return 1; //TCL_ERROR
2050 }
7fd59977 2051
13a22457
S
2052 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
2053
2054 // Create 3D view if it doesn't exist
2055 if ( aV3dView.IsNull() )
7fd59977 2056 {
4fe56619 2057 ViewerTest::ViewerInit();
13a22457
S
2058 aV3dView = ViewerTest::CurrentView();
2059 if( aV3dView.IsNull() )
2060 {
2061 di << "Error: Cannot create a 3D view\n";
2062 return 1; //TCL_ERROR
2063 }
7fd59977 2064 }
2065
13a22457
S
2066 // Erase (==0) or display (!=0)
2067 const int display = atoi(argv[1]);
7fd59977 2068
13a22457 2069 if (display)
7fd59977 2070 {
13a22457
S
2071 // Text font
2072 TCollection_AsciiString font;
2073 if (argc < 6)
2074 font.AssignCat("Courier");
2075 else
2076 font.AssignCat(argv[5]);
2077
2078 // Text is multibyte
2079 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
2080
2081 // Set axis names
2082 TCollection_ExtendedString xname, yname, zname;
2083 if (argc >= 5)
2084 {
2085 if (isMultibyte)
7fd59977 2086 {
13a22457
S
2087 AddMultibyteString(xname, argv[2]);
2088 AddMultibyteString(yname, argv[3]);
2089 AddMultibyteString(zname, argv[4]);
7fd59977 2090 }
13a22457
S
2091 else
2092 {
2093 xname += argv[2];
2094 yname += argv[3];
2095 zname += argv[4];
2096 }
2097 }
2098 else
2099 {
2100 xname += "X (mm)";
2101 yname += "Y (mm)";
2102 zname += "Z (mm)";
2103 }
7fd59977 2104
13a22457
S
2105 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
2106 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
2107 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
2108 Standard_True/*drawgrid*/,
2109 Standard_True/*drawaxes*/,
2110 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
2111 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
2112 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
2113 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
2114 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
2115 Quantity_NOC_WHITE/*gridcolor*/,
2116 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
2117 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
2118 }
7fd59977 2119 else
13a22457 2120 aV3dView->GraduatedTrihedronErase();
7fd59977 2121
2122 ViewerTest::GetAISContext()->UpdateCurrentViewer();
13a22457
S
2123 aV3dView->Redraw();
2124
7fd59977 2125 return 0;
2126}
2127
7edf74fd
A
2128//==============================================================================
2129//function : VPrintView
2130//purpose : Test printing algorithm, print the view to image file with given
2131// width and height. Printing implemented only for WNT.
2132//==============================================================================
4fe56619 2133static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
7edf74fd
A
2134 const char** argv)
2135{
2136#ifndef WNT
2137 di << "Printing implemented only for wnt!\n";
2138 return 1;
2139#else
2140
2141 Handle(AIS_InteractiveContext) aContextAIS = NULL;
2142 Handle(V3d_View) aView = NULL;
2143 aContextAIS = ViewerTest::GetAISContext();
2144 if (!aContextAIS.IsNull())
2145 {
2146 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
2147 Vwr->InitActiveViews();
2148 if(Vwr->MoreActiveViews())
2149 aView = Vwr->ActiveView();
2150 }
2151
2152 // check for errors
2153 if (aView.IsNull())
2154 {
2155 di << "Call vinit before!\n";
2156 return 1;
2157 }
2158 else if (argc < 4)
2159 {
2160 di << "Use: " << argv[0];
2161 di << " width height filename [print algo=0]\n";
2162 di << "width, height of the intermediate buffer for operation\n";
2163 di << "algo : {0|1}\n";
2164 di << " 0 - stretch algorithm\n";
2165 di << " 1 - tile algorithm\n";
2166 di << "test printing algorithms into an intermediate buffer\n";
2167 di << "with saving output to an image file\n";
2168 return 1;
2169 }
2170
2171 // get the input params
2172 Standard_Integer aWidth = atoi (argv[1]);
2173 Standard_Integer aHeight = atoi (argv[2]);
2174 Standard_Integer aMode = 0;
2175 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
2176 if (argc==5)
2177 aMode = atoi (argv[4]);
2178
2179 // check the input parameters
2180 if (aWidth <= 0 || aHeight <= 0)
2181 {
2182 di << "Width and height must be positive values!\n";
2183 return 1;
2184 }
2185 if (aMode != 0 && aMode != 1)
2186 aMode = 0;
2187
7edf74fd 2188 // define compatible bitmap
692613e5 2189 HDC anDC = CreateCompatibleDC(0);
7edf74fd
A
2190 BITMAPINFO aBitmapData;
2191 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2192 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2193 aBitmapData.bmiHeader.biWidth = aWidth ;
2194 aBitmapData.bmiHeader.biHeight = aHeight;
2195 aBitmapData.bmiHeader.biPlanes = 1;
2196 aBitmapData.bmiHeader.biBitCount = 24;
2197 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2198 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2199 aBitmapData.bmiHeader.biClrUsed = 0;
2200 aBitmapData.bmiHeader.biClrImportant = 0;
2201 aBitmapData.bmiHeader.biCompression = BI_RGB;
2202 aBitmapData.bmiHeader.biSizeImage = 0;
2203
2204 // Create Device Independent Bitmap
692613e5 2205 void* aBitsOut = NULL;
7edf74fd 2206 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
692613e5 2207 &aBitsOut, NULL, 0);
7edf74fd
A
2208 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2209
2210 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
692613e5 2211 if (aBitsOut != NULL)
4fe56619 2212 {
7edf74fd
A
2213 if (aMode == 0)
2214 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2215 else
2216 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2217
2218 // succesfully printed into an intermediate buffer
2219 if (isPrinted)
2220 {
692613e5 2221 Image_PixMap aWrapper;
2222 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
2223 aWrapper.SetTopDown (false);
2224
2225 Image_AlienPixMap anImageBitmap;
2226 anImageBitmap.InitCopy (aWrapper);
2227 isSaved = anImageBitmap.Save (aFileName);
7edf74fd
A
2228 }
2229 else
2230 {
2231 di << "Print operation failed due to printing errors or\n";
2232 di << "insufficient memory available\n";
2233 di << "Please, try to use smaller dimensions for this test\n";
2234 di << "command, as it allocates intermediate buffer for storing\n";
2235 di << "the result\n";
2236 }
2237 }
2238 else
2239 {
2240 di << "Can't allocate memory for intermediate buffer\n";
2241 di << "Please use smaller dimensions\n";
2242 }
2243
2244 if (aMemoryBitmap)
2245 {
2246 SelectObject (anDC, anOldBitmap);
2247 DeleteObject (aMemoryBitmap);
2248 DeleteDC(anDC);
2249 }
2250
2251 if (!isSaved)
2252 {
2253 di << "Save to file operation failed. This operation may fail\n";
2254 di << "if you don't have enough available memory, then you can\n";
2255 di << "use smaller dimensions for the output file\n";
2256 return 1;
2257 }
2258
2259 return 0;
2260
2261#endif
2262}
2263
59f45b7c 2264//==============================================================================
2265//function : VZLayer
2266//purpose : Test z layer operations for v3d viewer
2267//==============================================================================
2268static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2269{
2270 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2271 if (aContextAIS.IsNull())
2272 {
2273 di << "Call vinit before!\n";
2274 return 1;
2275 }
2276 else if (argc < 2)
2277 {
2278 di << "Use: vzlayer " << argv[0];
2279 di << " add/del/get [id]\n";
2280 di << " add - add new z layer to viewer and print its id\n";
2281 di << " del - del z layer by its id\n";
2282 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2283 di << "id - the layer identificator value defined when removing z layer\n";
2284 return 1;
2285 }
2286
2287 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2288 if (aViewer.IsNull())
2289 {
2290 di << "No active viewer!\n";
2291 return 1;
2292 }
2293
2294 // perform operation
2295 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2296 if (anOp == "add")
2297 {
2298 Standard_Integer aNewId;
2299 if (!aViewer->AddZLayer (aNewId))
2300 {
2301 di << "Impossible to add new z layer!\n";
2302 return 1;
2303 }
2304
2305 di << "New z layer added with index: " << aNewId << "\n";
2306 }
2307 else if (anOp == "del")
2308 {
2309 if (argc < 3)
2310 {
2311 di << "Please also provide as argument id of z layer to remove\n";
2312 return 1;
2313 }
2314
2315 Standard_Integer aDelId = atoi (argv[2]);
2316 if (!aViewer->RemoveZLayer (aDelId))
2317 {
2318 di << "Impossible to remove the z layer or invalid id!\n";
2319 return 1;
2320 }
2321
2322 di << "Z layer " << aDelId << " has been removed\n";
2323 }
2324 else if (anOp == "get")
2325 {
2326 TColStd_SequenceOfInteger anIds;
2327 aViewer->GetAllZLayers (anIds);
2328 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2329 {
2330 di << anIds.Value (aSeqIdx) << " ";
2331 }
2332
2333 di << "\n";
2334 }
2335 else
2336 {
2337 di << "Invalid operation, please use { add / del / get }\n";
2338 return 1;
2339 }
2340
2341 return 0;
2342}
2343
25289ec1 2344DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2345
2346// this class provides a presentation of text item in v3d view under-/overlayer
2347class V3d_TextItem : public Visual3d_LayerItem
2348{
2349public:
2350
2351 // CASCADE RTTI
2352 DEFINE_STANDARD_RTTI(V3d_TextItem)
2353
2354 // constructor
2355 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2356 const Standard_Real theX1,
2357 const Standard_Real theY1,
2358 const Standard_Real theHeight,
2359 const TCollection_AsciiString& theFontName,
2360 const Quantity_Color& theColor,
2361 const Quantity_Color& theSubtitleColor,
2362 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2363 const Handle(Visual3d_Layer)& theLayer);
2364
2365 // redraw method
2366 Standard_EXPORT void RedrawLayerPrs();
2367
2368private:
2369
2370 Standard_Real myX1;
2371 Standard_Real myY1;
2372 Standard_Real myHeight;
2373 TCollection_AsciiString myText;
2374 TCollection_AsciiString myFontName;
2375 Quantity_Color myColor;
2376 Quantity_Color mySubtitleColor;
2377 Aspect_TypeOfDisplayText myType;
2378 Handle(Visual3d_Layer) myLayer;
2379
2380};
2381
2382IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2383IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2384
2385// create and add to display the text item
2386V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2387 const Standard_Real theX1,
2388 const Standard_Real theY1,
2389 const Standard_Real theHeight,
2390 const TCollection_AsciiString& theFontName,
2391 const Quantity_Color& theColor,
2392 const Quantity_Color& theSubtitleColor,
2393 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2394 const Handle(Visual3d_Layer)& theLayer)
2395 : myX1 (theX1), myY1 (theY1),
2396 myText (theText),
2397 myHeight (theHeight),
2398 myLayer (theLayer),
2399 myColor (theColor),
2400 mySubtitleColor (theSubtitleColor),
2401 myType (theTypeOfDisplay),
2402 myFontName (theFontName)
2403{
2404 if (!myLayer.IsNull ())
2405 myLayer->AddLayerItem (this);
2406}
2407
2408// render item
2409void V3d_TextItem::RedrawLayerPrs ()
4fe56619 2410{
25289ec1 2411 if (myLayer.IsNull ())
2412 return;
2413
2414 myLayer->SetColor (myColor);
2415 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2416 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2417}
2418
20637bd2 2419DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2420
2421// The Visual3d_LayerItem line item for "vlayerline" command
4fe56619 2422// it provides a presentation of line with user-defined
20637bd2 2423// linewidth, linetype and transparency.
4fe56619 2424class V3d_LineItem : public Visual3d_LayerItem
20637bd2 2425{
2426public:
2427 // CASCADE RTTI
4fe56619 2428 DEFINE_STANDARD_RTTI(V3d_LineItem)
2429
20637bd2 2430 // constructor
2431 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2432 Standard_Real X2, Standard_Real Y2,
2433 V3d_LayerMgrPointer theLayerMgr,
2434 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2435 Standard_Real theWidth = 0.5,
2436 Standard_Real theTransp = 1.0);
2437
2438 // redraw method
2439 Standard_EXPORT void RedrawLayerPrs();
2440
2441private:
2442
2443 Standard_Real myX1, myY1, myX2, myY2;
2444 Standard_Real myWidth;
2445 Standard_Real myTransparency;
2446 Aspect_TypeOfLine myType;
2447 V3d_LayerMgrPointer myLayerMgr;
2448};
2449
2450IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2451IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2452
2453// default constructor for line item
4fe56619 2454V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
20637bd2 2455 Standard_Real X2, Standard_Real Y2,
2456 V3d_LayerMgrPointer theLayerMgr,
2457 Aspect_TypeOfLine theType,
2458 Standard_Real theWidth,
2459 Standard_Real theTransp) :
2460 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2461 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2462{
9e4c2fbb 2463 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
20637bd2 2464 myLayerMgr->Overlay()->AddLayerItem (this);
2465}
2466
2467// render line
2468void V3d_LineItem::RedrawLayerPrs ()
2469{
2470 Handle (Visual3d_Layer) aOverlay;
4fe56619 2471
20637bd2 2472 if (myLayerMgr)
2473 aOverlay = myLayerMgr->Overlay();
2474
2475 if (!aOverlay.IsNull())
2476 {
2477 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2478 aOverlay->SetColor(aColor);
2479 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2480 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2481 aOverlay->BeginPolyline();
2482 aOverlay->AddVertex(myX1, myY1);
2483 aOverlay->AddVertex(myX2, myY2);
2484 aOverlay->ClosePrimitive();
2485 }
2486}
2487
2488//=============================================================================
2489//function : VLayerLine
2490//purpose : Draws line in the v3d view layer with given attributes: linetype,
2491// : linewidth, transparency coefficient
2492//============================================================================
2493static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2494{
2495 // get the active view
2496 Handle(V3d_View) aView = ViewerTest::CurrentView();
2497 if (aView.IsNull())
2498 {
2499 di << "Call vinit before!\n";
2500 return 1;
2501 }
2502 else if (argc < 5)
2503 {
2504 di << "Use: " << argv[0];
2505 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2506 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2507 di << " 0 - solid \n";
2508 di << " 1 - dashed \n";
2509 di << " 2 - dot \n";
2510 di << " 3 - dashdot\n";
2511 di << " transparency : { 0.0 - 1.0 } \n";
2512 di << " 0.0 - transparent\n";
2513 di << " 1.0 - visible \n";
2514 return 1;
2515 }
2516
2517 // get the input params
2518 Standard_Real X1 = atof(argv[1]);
2519 Standard_Real Y1 = atof(argv[2]);
2520 Standard_Real X2 = atof(argv[3]);
2521 Standard_Real Y2 = atof(argv[4]);
2522
2523 Standard_Real aWidth = 0.5;
2524 Standard_Integer aType = 0;
2525 Standard_Real aTransparency = 1.0;
2526
2527 // has width
2528 if (argc > 5)
2529 aWidth = atof(argv[5]);
2530
2531 // has type
2532 if (argc > 6)
2533 aType = (Standard_Integer) atoi(argv[6]);
2534
2535 // has transparency
2536 if (argc > 7)
2537 {
2538 aTransparency = atof(argv[7]);
4fe56619 2539 if (aTransparency < 0 || aTransparency > 1.0)
20637bd2 2540 aTransparency = 1.0;
2541 }
2542
2543 // select appropriate line type
2544 Aspect_TypeOfLine aLineType;
2545 switch (aType)
2546 {
2547 case 1:
2548 aLineType = Aspect_TOL_DASH;
2549 break;
2550
2551 case 2:
2552 aLineType = Aspect_TOL_DOT;
2553 break;
2554
2555 case 3:
2556 aLineType = Aspect_TOL_DOTDASH;
2557 break;
2558
2559 default:
2560 aLineType = Aspect_TOL_SOLID;
2561 }
2562
2563 // replace layer manager
2564 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2565 aView->SetLayerMgr(aMgr);
2566
2567 // add line item
4fe56619 2568 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
20637bd2 2569 aMgr.operator->(),
4fe56619 2570 aLineType, aWidth,
20637bd2 2571 aTransparency);
2572
2573 // update view
2574 aView->MustBeResized();
2575 aView->Redraw();
2576
2577 return 0;
2578}
2579
25289ec1 2580//=======================================================================
2581//function : VOverlayText
2582//purpose : Test text displaying in view overlay
2583//=======================================================================
2584static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2585{
2586 // get the active view
2587 Handle(V3d_View) aView = ViewerTest::CurrentView();
2588 if (aView.IsNull())
2589 {
2590 di << "No active view. Please call vinit.\n";
2591 return 1;
2592 }
2593 else if (argc < 4 || argc > 13)
2594 {
2595 di << "Use: " << argv[0];
2596 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2597 di << "[background_color: R G B]\n";
2598 di << " height - pixel height of the text (default=10.0)\n";
2599 di << " font_name - name of font (default=courier)\n";
2600 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2601 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2602 di << " background_color- R G B values used for subtitle and decal text\n";
2603 di << "(default=255.0 255.0 255.0)\n";
2604 return 1;
2605 }
4fe56619 2606
25289ec1 2607 TCollection_AsciiString aText (argv[1]);
2608 Standard_Real aPosX = atof(argv[2]);
2609 Standard_Real aPosY = atof(argv[3]);
2610 Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
2611
2612 // font name
2613 TCollection_AsciiString aFontName = "Courier";
2614 if (argc >= 6)
2615 aFontName = TCollection_AsciiString (argv[5]);
2616
2617 // text colors
2618 Quantity_Parameter aColorRed = 1.0;
2619 Quantity_Parameter aColorGreen = 1.0;
2620 Quantity_Parameter aColorBlue = 1.0;
2621 if (argc >= 9)
2622 {
2623 aColorRed = atof (argv[6])/255.;
2624 aColorGreen = atof (argv[7])/255.;
2625 aColorBlue = atof (argv[8])/255.;
2626 }
2627
2628 // display type
2629 TCollection_AsciiString aDispStr;
2630 if (argc >= 10)
2631 aDispStr = TCollection_AsciiString (argv[9]);
2632
2633 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2634 if (aDispStr.IsEqual ("subtitle"))
2635 aTextType = Aspect_TODT_SUBTITLE;
2636 else if (aDispStr.IsEqual ("decal"))
2637 aTextType = Aspect_TODT_DEKALE;
2638 else if (aDispStr.IsEqual ("blend"))
2639 aTextType = Aspect_TODT_BLEND;
2640
2641 // subtitle color
2642 Quantity_Parameter aSubRed = 1.0;
2643 Quantity_Parameter aSubGreen = 1.0;
2644 Quantity_Parameter aSubBlue = 1.0;
2645 if (argc == 13)
2646 {
2647 aSubRed = atof (argv[10])/255.;
2648 aSubGreen = atof (argv[11])/255.;
2649 aSubBlue = atof (argv[12])/255.;
2650 }
2651
2652 // check fo current overlay
2653 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2654 if (anOverlay.IsNull ())
2655 {
2656 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2657 anOverlay = aMgr->Overlay ();
2658 aView->SetLayerMgr (aMgr);
2659 }
2660
4fe56619 2661 Quantity_Color aTextColor (aColorRed, aColorGreen,
25289ec1 2662 aColorBlue, Quantity_TOC_RGB);
4fe56619 2663 Quantity_Color aSubtColor (aSubRed, aSubGreen,
25289ec1 2664 aSubBlue, Quantity_TOC_RGB);
2665
2666 // add text item
2667 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2668 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2669
2670 // update view
2671 aView->MustBeResized();
2672 aView->Redraw();
2673
2674 return 0;
2675}
2676
2bd4c032 2677//==============================================================================
2678//function : VGrid
2679//purpose :
2680//==============================================================================
2681
2682static int VGrid (Draw_Interpretor& theDI,
2683 Standard_Integer theArgNb,
2684 const char** theArgVec)
2685{
2686 // get the active view
2687 Handle(V3d_View) aView = ViewerTest::CurrentView();
2688 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
2689 if (aView.IsNull() || aViewer.IsNull())
2690 {
2691 std::cerr << "No active view. Please call vinit.\n";
2692 return 1;
2693 }
2694
2695 Aspect_GridType aType = aViewer->GridType();
2696 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
2697
2698 Standard_Integer anIter = 1;
2699 for (; anIter < theArgNb; ++anIter)
2700 {
2701 const char* aValue = theArgVec[anIter];
2702 if (*aValue == 'r')
2703 {
2704 aType = Aspect_GT_Rectangular;
2705 }
2706 else if (*aValue == 'c')
2707 {
2708 aType = Aspect_GT_Circular;
2709 }
2710 else if (*aValue == 'l')
2711 {
2712 aMode = Aspect_GDM_Lines;
2713 }
2714 else if (*aValue == 'p')
2715 {
2716 aMode = Aspect_GDM_Points;
2717 }
2718 else if (strcmp (aValue, "off" ) == 0)
2719 {
2720 aViewer->DeactivateGrid();
2721 return 0;
2722 }
2723 else
2724 {
2725 break;
2726 }
2727 }
2728
2729 Standard_Integer aTail = (theArgNb - anIter);
2730 if (aTail == 0)
2731 {
2732 aViewer->ActivateGrid (aType, aMode);
2733 return 0;
2734 }
2735 else if (aTail != 2 && aTail != 5)
2736 {
2737 std::cerr << "Incorrect arguments number! Usage:\n"
2738 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
2739 return 1;
2740 }
2741
2742 Quantity_Length anOriginX, anOriginY;
2743 Quantity_PlaneAngle aRotAngle;
2744 if (aType == Aspect_GT_Rectangular)
2745 {
2746 Quantity_Length aRStepX, aRStepY;
2747 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2748
2749 anOriginX = atof (theArgVec[anIter++]);
2750 anOriginY = atof (theArgVec[anIter++]);
2751 if (aTail == 5)
2752 {
2753 aRStepX = atof (theArgVec[anIter++]);
2754 aRStepY = atof (theArgVec[anIter++]);
2755 aRotAngle = atof (theArgVec[anIter++]);
2756 }
2757 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
2758 aViewer->ActivateGrid (aType, aMode);
2759 }
2760 else if (aType == Aspect_GT_Circular)
2761 {
2762 Quantity_Length aRadiusStep;
2763 Standard_Integer aDivisionNumber;
2764 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2765
2766 anOriginX = atof (theArgVec[anIter++]);
2767 anOriginY = atof (theArgVec[anIter++]);
2768 if (aTail == 5)
2769 {
2770 aRadiusStep = atof (theArgVec[anIter++]);
208e6839 2771 aDivisionNumber = atoi (theArgVec[anIter++]);
2bd4c032 2772 aRotAngle = atof (theArgVec[anIter++]);
2773 }
2774
2775 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
2776 aViewer->ActivateGrid (aType, aMode);
2777 }
2778
2779 return 0;
2780}
2781
208e6839 2782//==============================================================================
2783//function : VFps
2784//purpose :
2785//==============================================================================
2786
2787static int VFps (Draw_Interpretor& theDI,
2788 Standard_Integer theArgNb,
2789 const char** theArgVec)
2790{
2791 // get the active view
2792 Handle(V3d_View) aView = ViewerTest::CurrentView();
2793 if (aView.IsNull())
2794 {
2795 std::cerr << "No active view. Please call vinit.\n";
2796 return 1;
2797 }
2798
2799 Standard_Integer aFramesNb = (theArgNb > 1) ? atoi(theArgVec[1]) : 100;
2800 if (aFramesNb <= 0)
2801 {
2802 std::cerr << "Incorrect arguments!\n";
2803 return 1;
2804 }
2805
2806 // the time is meaningless for first call
2807 // due to async OpenGl rendering
2808 aView->Redraw();
2809
2810 // redraw view in loop to estimate average values
2811 OSD_Timer aTimer;
2812 aTimer.Start();
2813 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
2814 {
2815 aView->Redraw();
2816 }
2817 aTimer.Stop();
2818 Standard_Real aCpu;
2819 const Standard_Real aTime = aTimer.ElapsedTime();
2820 aTimer.OSD_Chronometer::Show (aCpu);
2821
2822 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
2823 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
2824
2825 // return statistics
2826 theDI << "FPS: " << aFpsAver << "\n"
2827 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
2828
2829 return 0;
2830}
2831
2832
2833//==============================================================================
2834//function : VVbo
2835//purpose :
2836//==============================================================================
2837
2838static int VVbo (Draw_Interpretor& theDI,
2839 Standard_Integer theArgNb,
2840 const char** theArgVec)
2841{
2842 // get the context
2843 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2844 if (aContextAIS.IsNull())
2845 {
2846 std::cerr << "No active view. Please call vinit.\n";
2847 return 1;
2848 }
2849
2850 Handle(Graphic3d_GraphicDriver) aDriver =
2851 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2852 if (aDriver.IsNull())
2853 {
2854 std::cerr << "Graphic driver not available.\n";
2855 return 1;
2856 }
2857
2858 if (theArgNb < 2)
2859 {
2860 //theDI << "VBO: " << aDriver->ToUseVBO() << "\n";
2861 //return 0;
2862 std::cerr << "Wrong number of arguments.\n";
2863 return 1;
2864 }
2865
2866 aDriver->EnableVBO (atoi(theArgVec[1]) != 0);
2867 return 0;
2868}
2869
f0430952 2870//==============================================================================
2871//function : VMemGpu
2872//purpose :
2873//==============================================================================
2874
2875static int VMemGpu (Draw_Interpretor& theDI,
2876 Standard_Integer theArgNb,
2877 const char** theArgVec)
2878{
2879 // get the context
2880 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2881 if (aContextAIS.IsNull())
2882 {
2883 std::cerr << "No active view. Please call vinit.\n";
2884 return 1;
2885 }
2886
2887 Handle(Graphic3d_GraphicDriver) aDriver =
2888 Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver());
2889 if (aDriver.IsNull())
2890 {
2891 std::cerr << "Graphic driver not available.\n";
2892 return 1;
2893 }
2894
2895 Standard_Size aFreeBytes = 0;
2896 TCollection_AsciiString anInfo;
2897 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
2898 {
2899 std::cerr << "Information not available.\n";
2900 return 1;
2901 }
2902
2903 if (theArgNb > 1 && *theArgVec[1] == 'f')
2904 {
2905 theDI << Standard_Real (aFreeBytes);
2906 }
2907 else
2908 {
2909 theDI << anInfo;
2910 }
2911
2912 return 0;
2913}
2914
85e096c3 2915// ==============================================================================
2916// function : VReadPixel
2917// purpose :
2918// ==============================================================================
2919static int VReadPixel (Draw_Interpretor& theDI,
2920 Standard_Integer theArgNb,
2921 const char** theArgVec)
2922{
2923 // get the active view
2924 Handle(V3d_View) aView = ViewerTest::CurrentView();
2925 if (aView.IsNull())
2926 {
2927 std::cerr << "No active view. Please call vinit.\n";
2928 return 1;
2929 }
2930 else if (theArgNb < 3)
2931 {
2932 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
2933 return 1;
2934 }
2935
692613e5 2936 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2937 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
2938
85e096c3 2939 Standard_Integer aWidth, aHeight;
2940 aView->Window()->Size (aWidth, aHeight);
2941 const Standard_Integer anX = atoi (theArgVec[1]);
2942 const Standard_Integer anY = atoi (theArgVec[2]);
2943 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
2944 {
2945 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
2946 return 1;
2947 }
2948
2949 Standard_Boolean toShowName = Standard_False;
2950 Standard_Boolean toShowHls = Standard_False;
2951 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
2952 {
2953 TCollection_AsciiString aParam (theArgVec[anIter]);
2954 if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgb")))
2955 {
692613e5 2956 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2957 aBufferType = Graphic3d_BT_RGB;
85e096c3 2958 }
2959 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("hls")))
2960 {
692613e5 2961 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
2962 aBufferType = Graphic3d_BT_RGB;
85e096c3 2963 toShowHls = Standard_True;
2964 }
2965 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbf")))
2966 {
692613e5 2967 aFormat = Image_PixMap::ImgRGBF;
2968 aBufferType = Graphic3d_BT_RGB;
85e096c3 2969 }
2970 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgba")))
2971 {
692613e5 2972 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
2973 aBufferType = Graphic3d_BT_RGBA;
85e096c3 2974 }
2975 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("rgbaf")))
2976 {
692613e5 2977 aFormat = Image_PixMap::ImgRGBAF;
2978 aBufferType = Graphic3d_BT_RGBA;
85e096c3 2979 }
2980 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("depth")))
2981 {
692613e5 2982 aFormat = Image_PixMap::ImgGrayF;
2983 aBufferType = Graphic3d_BT_Depth;
85e096c3 2984 }
2985 else if (TCollection_AsciiString::ISSIMILAR (aParam, TCollection_AsciiString ("name")))
2986 {
2987 toShowName = Standard_True;
2988 }
2989 }
2990
692613e5 2991 Image_PixMap anImage;
2992 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
2993 {
2994 std::cerr << "Image allocation failed\n";
2995 return 1;
2996 }
2997 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
85e096c3 2998 {
2999 std::cerr << "Image dump failed\n";
3000 return 1;
3001 }
3002
3003 Quantity_Parameter anAlpha;
692613e5 3004 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
85e096c3 3005 if (toShowName)
3006 {
692613e5 3007 if (aBufferType == Graphic3d_BT_RGBA)
85e096c3 3008 {
3009 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
3010 }
3011 else
3012 {
3013 theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
3014 }
3015 }
3016 else
3017 {
3018 switch (aBufferType)
3019 {
3020 default:
692613e5 3021 case Graphic3d_BT_RGB:
85e096c3 3022 {
3023 if (toShowHls)
3024 {
3025 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
3026 }
3027 else
3028 {
3029 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
3030 }
3031 break;
3032 }
692613e5 3033 case Graphic3d_BT_RGBA:
85e096c3 3034 {
3035 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
3036 break;
3037 }
692613e5 3038 case Graphic3d_BT_Depth:
85e096c3 3039 {
3040 theDI << aColor.Red() << "\n";
3041 break;
3042 }
3043 }
3044 }
3045
3046 return 0;
3047}
3048
692613e5 3049//==============================================================================
3050//function : VDiffImage
3051//purpose : The draw-command compares two images.
3052//==============================================================================
3053
3054static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3055{
3056 if (theArgNb < 6)
3057 {
3058 theDI << "Not enough arguments.\n";
3059 return 1;
3060 }
3061
3062 // image file names
3063 const char* anImgPathRef = theArgVec[1];
3064 const char* anImgPathNew = theArgVec[2];
3065
3066 // get string tolerance and check its validity
3067 Standard_Real aTolColor = atof (theArgVec[3]);
3068 if (aTolColor < 0.0)
3069 aTolColor = 0.0;
3070 if (aTolColor > 1.0)
3071 aTolColor = 1.0;
3072
3073 Standard_Boolean toBlackWhite = (atoi (theArgVec[4]) == 1);
3074 Standard_Boolean isBorderFilterOn = (atoi (theArgVec[5]) == 1);
3075
3076 // image file of difference
3077 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
3078
3079 // compare the images
3080 Image_Diff aComparer;
3081 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
3082 {
3083 return 1;
3084 }
3085
3086 aComparer.SetColorTolerance (aTolColor);
3087 aComparer.SetBorderFilterOn (isBorderFilterOn);
3088 Standard_Integer aDiffColorsNb = aComparer.Compare();
3089 theDI << aDiffColorsNb << "\n";
3090
3091 // save image of difference
3092 if (aDiffImagePath != NULL)
3093 {
3094 aComparer.SaveDiffImage (aDiffImagePath);
3095 }
3096
3097 return 0;
3098}
3099
7fd59977 3100//=======================================================================
3101//function : ViewerCommands
3102//purpose :
3103//=======================================================================
3104
3105void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
3106{
3107
3108 const char *group = "ZeViewer";
3109 theCommands.Add("vinit" ,
3110 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
3111 __FILE__,VInit,group);
3112 theCommands.Add("vhelp" ,
3113 "vhelp : display help on the viewer commands",
3114 __FILE__,VHelp,group);
3115 theCommands.Add("vtop" ,
44b8f2d6 3116 "vtop or <T> : Top view" ,
7fd59977 3117 __FILE__,VTop,group);
44b8f2d6 3118 theCommands.Add("vbottom" ,
3119 "vbottom : Bottom view" ,
3120 __FILE__,VBottom,group);
3121 theCommands.Add("vleft" ,
3122 "vleft : Left view" ,
3123 __FILE__,VLeft,group);
3124 theCommands.Add("vright" ,
3125 "vright : Right view" ,
3126 __FILE__,VRight,group);
7fd59977 3127 theCommands.Add("vaxo" ,
3128 " vaxo or <A> : Axonometric view ",
3129 __FILE__,VAxo,group);
44b8f2d6 3130 theCommands.Add("vfront" ,
3131 "vfront : Front view" ,
3132 __FILE__,VFront,group);
3133 theCommands.Add("vback" ,
3134 "vback : Back view" ,
3135 __FILE__,VBack,group);
7fd59977 3136 theCommands.Add("vpick" ,
3137 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
3138 VPick,group);
3139 theCommands.Add("vfit" ,
3140 "vfit or <F> : vfit",
3141 __FILE__,VFit,group);
3142 theCommands.Add("vzfit" ,
3143 "vzfit",
3144 __FILE__,VZFit,group);
3145 theCommands.Add("vrepaint",
3146 "vrepaint : vrepaint, force redraw",
3147 __FILE__,VRepaint,group);
3148 theCommands.Add("vclear",
3149 "vclear : vclear",
3150 __FILE__,VClear,group);
3151 theCommands.Add("vsetbg",
3152 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
3153 __FILE__,VSetBg,group);
f8b2ed36 3154 theCommands.Add("vsetbgmode",
3155 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
3156 __FILE__,VSetBgMode,group);
7fd59977 3157 theCommands.Add("vsetgradientbg",
f8b2ed36 3158 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 3159 __FILE__,VSetGradientBg,group);
f8b2ed36 3160 theCommands.Add("vsetgrbgmode",
3161 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
3162 __FILE__,VSetGradientBgMode,group);
3163 theCommands.Add("vsetcolorbg",
3164 "vsetcolorbg : vsetcolorbg r g b : Set background color",
3165 __FILE__,VSetColorBg,group);
7fd59977 3166 theCommands.Add("vscale",
3167 "vscale : vscale X Y Z",
3168 __FILE__,VScale,group);
3169 theCommands.Add("vzbufftrihedron",
7c8a8fcc 3170 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
3171 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
3172 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
7fd59977 3173 __FILE__,VTestZBuffTrihedron,group);
3174 theCommands.Add("vrotate",
3175 "vrotate : vrotate AX AY AZ [X Y Z]",
3176 __FILE__,VRotate,group);
3177 theCommands.Add("vzoom",
3178 "vzoom : vzoom coef",
3179 __FILE__,VZoom,group);
3180 theCommands.Add("vpan",
3181 "vpan : vpan dx dy",
3182 __FILE__,VPan,group);
3183 theCommands.Add("vexport",
5cedc27f
K
3184 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
3185 " : exports the view to a vector file of a given format"
3186 " : notice that EMF format requires patched gl2ps",
7fd59977 3187 __FILE__,VExport,group);
3188 theCommands.Add("vcolorscale",
3189 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
3190 __FILE__,VColorScale,group);
3191 theCommands.Add("vgraduatedtrihedron",
13a22457 3192 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
7fd59977 3193 __FILE__,VGraduatedTrihedron,group);
7edf74fd
A
3194 theCommands.Add("vprintview" ,
3195 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
3196 __FILE__,VPrintView,group);
59f45b7c 3197 theCommands.Add("vzlayer",
3198 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
3199 __FILE__,VZLayer,group);
25289ec1 3200 theCommands.Add("voverlaytext",
3201 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
3202 " : height - pixel height of the text (default=10.0)"
3203 " : font_name - name of font (default=courier)"
3204 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
3205 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
3206 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
3207 __FILE__,VOverlayText,group);
20637bd2 3208 theCommands.Add("vlayerline",
3209 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
3210 __FILE__,VLayerLine,group);
2bd4c032 3211 theCommands.Add ("vgrid",
3212 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
3213 " : Mode - rectangular or circular"
3214 " : Type - lines or points",
3215 __FILE__, VGrid, group);
208e6839 3216 theCommands.Add ("vfps",
3217 "vfps [framesNb=100] : estimate average frame rate for active view",
3218 __FILE__, VFps, group);
3219 theCommands.Add ("vvbo",
3220 "vvbo {0|1} : turn VBO usage On/Off; affects only newly displayed objects",
3221 __FILE__, VVbo, group);
f0430952 3222 theCommands.Add ("vmemgpu",
3223 "vmemgpu [f]: print system-dependent GPU memory information if available;"
3224 " with f option returns free memory in bytes",
3225 __FILE__, VMemGpu, group);
85e096c3 3226 theCommands.Add ("vreadpixel",
3227 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
3228 " : Read pixel value for active view",
3229 __FILE__, VReadPixel, group);
692613e5 3230 theCommands.Add("diffimage",
3231 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
3232 __FILE__, VDiffImage, group);
7fd59977 3233}