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