Integration of OCCT 6.5.0 from SVN
[occt.git] / src / ViewerTest / ViewerTest_ViewerCommands.cxx
CommitLineData
7fd59977 1// File: ViewerTest_ViewerCommands.cxx
2// Created: Tue Sep 1 10:28:35 1998
3// Author: Robert COUBLANC
4// <rob@robox.paris1.matra-dtv.fr>
5
6// Robert Boehne 30 May 2000 : Dec Osf
7
8#ifdef HAVE_CONFIG_H
9# include <config.h>
10#endif
11
12#ifdef WNT
13#include <windows.h>
14#endif
15
16#include <Graphic3d_ExportFormat.hxx>
17#include <ViewerTest.hxx>
18#include <ViewerTest_EventManager.hxx>
19#include <Visual3d_View.hxx>
20#include <NIS_View.hxx>
21#include <NIS_Triangulated.hxx>
22#include <NIS_InteractiveContext.hxx>
23#include <AIS_InteractiveContext.hxx>
24#include <Draw_Interpretor.hxx>
25#include <Draw.hxx>
26#include <Draw_Appli.hxx>
27
28#ifndef WNT
29#include <Graphic3d_GraphicDevice.hxx>
30#include <Xw_GraphicDevice.hxx>
31#include <Xw_WindowQuality.hxx>
32#include <Xw_Window.hxx>
33#include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
34#include <X11/Xutil.h>
35#include <tk.h>
36
37#else
38
39#include <Graphic3d_WNTGraphicDevice.hxx>
40#include <WNT_WClass.hxx>
41#include <WNT_Window.hxx>
42
43#define _CRT_SECURE_NO_DEPRECATE
44#pragma warning (disable:4996)
45
46#endif
47
48#define OCC120
49
50//==============================================================================
51
52//==============================================================================
53// VIEWER GLOBAL VARIABLES
54//==============================================================================
55
56Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
57
58Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
59extern const Handle(NIS_InteractiveContext)& TheNISContext();
60
61#ifdef WNT
62static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
63 static Handle(Graphic3d_WNTGraphicDevice) GD;
64 return GD;
65}
66
67static Handle(WNT_Window)& VT_GetWindow() {
68 static Handle(WNT_Window) WNTWin;
69 return WNTWin;
70}
71
72#else
73static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
74 static Handle(Graphic3d_GraphicDevice) GD;
75 return GD;
76}
77static Handle(Xw_Window)& VT_GetWindow(){
78 static Handle(Xw_Window) XWWin;
79 return XWWin;
80}
81static Display *display;
82
83static void VProcessEvents(ClientData,int);
84#endif
85
86#ifdef OCC120
87static Standard_Boolean DegenerateMode = Standard_True;
88#endif
89
90#define ZCLIPWIDTH 1.
91
92static void OSWindowSetup();
93
94//==============================================================================
95// EVENT GLOBAL VARIABLES
96//==============================================================================
97
98static int Start_Rot = 0;
99static int ZClipIsOn = 0;
100static int X_Motion= 0,Y_Motion=0; // Current cursor position
101static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
102
103
104//==============================================================================
105
106#ifdef WNT
107static LRESULT WINAPI ViewerWindowProc(
108 HWND hwnd,
109 UINT uMsg,
110 WPARAM wParam,
111 LPARAM lParam );
112static LRESULT WINAPI AdvViewerWindowProc(
113 HWND hwnd,
114 UINT uMsg,
115 WPARAM wParam,
116 LPARAM lParam );
117#endif
118
119
120//==============================================================================
121//function : WClass
122//purpose :
123//==============================================================================
124
125const Handle(MMgt_TShared)& ViewerTest::WClass()
126{
127 static Handle(MMgt_TShared) theWClass;
128#ifdef WNT
129 if (theWClass.IsNull()) {
130 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
131 CS_VREDRAW | CS_HREDRAW, 0, 0,
132 ::LoadCursor (NULL, IDC_ARROW));
133 }
134#endif
135 return theWClass;
136}
137
138//==============================================================================
139//function : ViewerInit
140//purpose : Create the window viewer and initialize all the global variable
141//==============================================================================
142
143void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
144 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
145{
146 static Standard_Boolean isFirst = Standard_True;
147
148 Standard_Integer aPxLeft = 0;
149 Standard_Integer aPxTop = 460;
150 Standard_Integer aPxWidth = 409;
151 Standard_Integer aPxHeight = 409;
152 if (thePxWidth != 0 && thePxHeight != 0)
153 {
154 aPxLeft = thePxLeft;
155 aPxTop = thePxTop;
156 aPxWidth = thePxWidth;
157 aPxHeight = thePxHeight;
158 }
159
160 if (isFirst)
161 {
162 // Create the Graphic device
163#ifdef WNT
164 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
165 if (VT_GetWindow().IsNull())
166 {
167 // Create the Graphic device and the window
168 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
169
170 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
171 Handle(WNT_WClass)::DownCast (WClass()),
172 WS_OVERLAPPEDWINDOW,
173 aPxLeft, aPxTop,
174 aPxWidth, aPxHeight,
175 Quantity_NOC_BLACK);
176 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
177 }
178#else
179 if (GetG3dDevice().IsNull()) GetG3dDevice() =
180 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
181 if (VT_GetWindow().IsNull())
182 {
183 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
184 "Test3d",
185 aPxLeft, aPxTop,
186 aPxWidth, aPxHeight,
187 Xw_WQ_3DQUALITY,
188 Quantity_NOC_BLACK);
189 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
190 }
191#endif
192
193 Handle(V3d_Viewer) a3DViewer, a3DCollector;
194 // Viewer and View creation
195
196 TCollection_ExtendedString NameOfWindow("Visu3D");
197
198 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
199 NameOfWindow = TCollection_ExtendedString("Collector");
200 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
201 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
202 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
203 Handle(NIS_View) aView =
204 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
205 if ( aView.IsNull() ) {
206 // Handle (V3d_View) V = a3DViewer->CreateView();
207 aView = new NIS_View (a3DViewer, VT_GetWindow());
208 ViewerTest::CurrentView(aView);
209 TheNISContext()->AttachView (aView);
210 }
211 Handle(V3d_View) a3DViewCol;
212 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
213
214 // AIS setup
215 if ( ViewerTest::GetAISContext().IsNull() ) {
216 Handle(AIS_InteractiveContext) C =
217 new AIS_InteractiveContext(a3DViewer,a3DCollector);
218 ViewerTest::SetAISContext(C);
219 }
220
221 // Setup for X11 or NT
222 OSWindowSetup();
223 // Viewer and View creation
224
225 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
226
227 Handle (V3d_View) V = ViewerTest::CurrentView();
228
229 V->SetDegenerateModeOn();
230#ifdef OCC120
231 DegenerateMode = V->DegenerateModeIsOn();
232#endif
233 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
234
235 V->SetZClippingDepth(0.5);
236 V->SetZClippingWidth(ZCLIPWIDTH/2.);
237 a3DViewer->SetDefaultLights();
238 a3DViewer->SetLightOn();
239
240#ifndef WNT
241#if TCL_MAJOR_VERSION < 8
242 Tk_CreateFileHandler((void*)ConnectionNumber(display),
243 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
244#else
245 Tk_CreateFileHandler(ConnectionNumber(display),
246 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
247#endif
248#endif
249
250 isFirst = Standard_False;
251 }
252 VT_GetWindow()->Map();
253}
254
255//==============================================================================
256//function : Vinit
257//purpose : Create the window viewer and initialize all the global variable
258// Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
259//==============================================================================
260
261static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
262{
263 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
264 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
265 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
266 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
267 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
268 return 0;
269}
270
271//==============================================================================
272//function : ProcessKeyPress
273//purpose : Handle KeyPress event from a CString
274//==============================================================================
275
276static void ProcessKeyPress( char *buf_ret )
277{
278 //cout << "KeyPress" << endl;
279 const Handle(V3d_View) aView = ViewerTest::CurrentView();
280 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
281 // Letter in alphabetic order
282
283 if ( !strcasecmp(buf_ret, "A") ) {
284 // AXO
285 aView->SetProj(V3d_XposYnegZpos);
286 }
287 else if ( !strcasecmp(buf_ret, "D") ) {
288 // Reset
289 aView->Reset();
290 }
291 else if ( !strcasecmp(buf_ret, "F") ) {
292 // FitAll
293 if (aNisView.IsNull())
294 aView->FitAll();
295 else
296 aNisView->FitAll3d();
297 }
298 else if ( !strcasecmp(buf_ret, "H") ) {
299 // HLR
300 cout << "HLR" << endl;
301#ifdef OCC120
302 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
303 else aView->SetDegenerateModeOn();
304 DegenerateMode = aView->DegenerateModeIsOn();
305#else
306 ViewerTest::CurrentView()->SetDegenerateModeOff();
307#endif
308 }
309 else if ( !strcasecmp(buf_ret, "D") ) {
310 // Reset
311 aView->Reset();
312 }
313 else if ( !strcasecmp(buf_ret, "S") ) {
314 // SHADING
315 cout << "passage en mode 1 (shading pour les shapes)" << endl;
316#ifndef OCC120
317 ViewerTest::CurrentView()->SetDegenerateModeOn();
318#endif
319 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
320 if(Ctx->NbCurrents()==0 ||
321 Ctx->NbSelected()==0)
322 Ctx->SetDisplayMode(AIS_Shaded);
323 else{
324 if(Ctx->HasOpenedContext()){
325 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
326 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
327 }
328 else{
329 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
330 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
331 }
332 Ctx->UpdateCurrentViewer();
333 }
334 }
335 else if ( !strcasecmp(buf_ret, "U") ) {
336 // SHADING
337 cout<<"passage au mode par defaut"<<endl;
338#ifndef OCC120
339 ViewerTest::CurrentView()->SetDegenerateModeOn();
340#endif
341 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
342 if(Ctx->NbCurrents()==0 ||
343 Ctx->NbSelected()==0)
344 Ctx->SetDisplayMode(AIS_WireFrame);
345 else{
346 if(Ctx->HasOpenedContext()){
347 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
348 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
349 }
350 else{
351 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
352 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
353 }
354 Ctx->UpdateCurrentViewer();
355 }
356
357 }
358 else if ( !strcasecmp(buf_ret, "T") ) {
359 // Top
360 aView->SetProj(V3d_Zpos);
361 }
362 else if ( !strcasecmp(buf_ret, "B") ) {
363 // Top
364 aView->SetProj(V3d_Zneg);
365 }
366 else if ( !strcasecmp(buf_ret, "L") ) {
367 // Top
368 aView->SetProj(V3d_Xneg);
369 }
370 else if ( !strcasecmp(buf_ret, "R") ) {
371 // Top
372 aView->SetProj(V3d_Xpos);
373 }
374
375 else if ( !strcasecmp(buf_ret, "W") ) {
376 // WIREFRAME
377#ifndef OCC120
378 ViewerTest::CurrentView()->SetDegenerateModeOn();
379#endif
380 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
381#ifndef OCC120
382 ViewerTest::CurrentView()->SetDegenerateModeOn();
383#endif
384 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
385 if(Ctx->NbCurrents()==0 ||
386 Ctx->NbSelected()==0)
387 Ctx->SetDisplayMode(AIS_WireFrame);
388 else{
389 if(Ctx->HasOpenedContext()){
390 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
391 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
392 }
393 else{
394 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
395 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
396 }
397 Ctx->UpdateCurrentViewer();
398 }
399 }
400 else if ( !strcasecmp(buf_ret, "Z") ) {
401 // ZCLIP
402
403 if ( ZClipIsOn ) {
404 cout << "ZClipping OFF" << endl;
405 ZClipIsOn = 0;
406
407 aView->SetZClippingType(V3d_OFF);
408 aView->Redraw();
409 }
410 else {
411 cout << "ZClipping ON" << endl;
412 ZClipIsOn = 1;
413
414 aView->SetZClippingType(V3d_FRONT);
415 aView->Redraw();
416 }
417 }
418 else if ( !strcasecmp(buf_ret, ",") ) {
419 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
420
421
422 }
423 else if ( !strcasecmp(buf_ret, ".") ) {
424 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
425 }
426 // Number
427 else{
428 Standard_Integer Num = atoi(buf_ret);
429 if(Num>=0 && Num<=7)
430 ViewerTest::StandardModeActivation(Num);
431 }
432}
433
434//==============================================================================
435//function : ProcessExpose
436//purpose : Redraw the View on an Expose Event
437//==============================================================================
438
439static void ProcessExpose( )
440{ //cout << "Expose" << endl;
441 ViewerTest::CurrentView()->Redraw();
442}
443
444//==============================================================================
445//function : ProcessConfigure
446//purpose : Resize the View on an Configure Event
447//==============================================================================
448
449static void ProcessConfigure()
450{
451 Handle(V3d_View) V = ViewerTest::CurrentView();
452 V->MustBeResized();
453 V->Update();
454 V->Redraw();
455}
456
457//==============================================================================
458//function : ProcessButton1Press
459//purpose : Picking
460//==============================================================================
461
462static Standard_Boolean ProcessButton1Press(
463 Standard_Integer ,
464 const char** argv,
465 Standard_Boolean pick,
466 Standard_Boolean shift )
467{
468 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
469 if ( pick ) {
470 Standard_Real X, Y, Z;
471
472 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
473
474 Draw::Set(argv[1], X);
475 Draw::Set(argv[2], Y);
476 Draw::Set(argv[3], Z);}
477
478 if(shift)
479 EM->ShiftSelect();
480 else
481 EM->Select();
482
483 pick = 0;
484 return pick;
485}
486
487//==============================================================================
488//function : ProcessButton3Press
489//purpose : Start Rotation
490//==============================================================================
491
492static void ProcessButton3Press()
493
494{ // Start rotation
495 Start_Rot = 1;
496 ViewerTest::CurrentView()->SetDegenerateModeOn();
497 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
498
499}
500//==============================================================================
501//function : ProcessButtonRelease
502//purpose : Start Rotation
503//==============================================================================
504
505static void ProcessButtonRelease()
506
507{ // End rotation
508#ifdef OCC120
509 if (Start_Rot) {
510 Start_Rot = 0;
511 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
512 }
513#else
514 Start_Rot = 0;
515 ViewerTest::CurrentView()->SetDegenerateModeOff();
516#endif
517}
518
519//==============================================================================
520//function : ProcessZClipMotion
521//purpose : Zoom
522//==============================================================================
523
524void ProcessZClipMotion()
525{
526 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
527 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
528 static Standard_Real CurZPos = 0.;
529
530 //Quantity_Length VDX, VDY;
531 //a3DView->Size(VDX,VDY);
532 //Standard_Real VDZ = a3DView->ZSize();
533 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
534
535 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
536
537 // Front = Depth + width/2.
538 Standard_Real D = 0.5;
539 Standard_Real W = 0.1;
540
541 CurZPos += (dx);
542
543 D += CurZPos;
544
545 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
546
547 a3DView->SetZClippingType(V3d_OFF);
548 a3DView->SetZClippingDepth(D);
549 a3DView->SetZClippingWidth(W);
550 a3DView->SetZClippingType(V3d_FRONT);
551
552 a3DView->Redraw();
553
554 X_ButtonPress = X_Motion;
555 Y_ButtonPress = Y_Motion;
556 }
557}
558
559//==============================================================================
560//function : ProcessControlButton1Motion
561//purpose : Zoom
562//==============================================================================
563
564static void ProcessControlButton1Motion()
565{
566 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
567
568 X_ButtonPress = X_Motion;
569 Y_ButtonPress = Y_Motion;
570}
571
572//==============================================================================
573//function : ProcessControlButton2Motion
574//purpose : Pann
575//==============================================================================
576
577static void ProcessControlButton2Motion()
578{
579 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
580 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
581
582 dy = -dy; // Xwindow Y axis is from top to Bottom
583
584 ViewerTest::CurrentView()->Panning( dx, dy );
585
586 X_ButtonPress = X_Motion;
587 Y_ButtonPress = Y_Motion;
588}
589
590//==============================================================================
591//function : ProcessControlButton3Motion
592//purpose : Rotation
593//==============================================================================
594
595static void ProcessControlButton3Motion()
596{
597 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
598}
599
600//==============================================================================
601//function : ProcessPointerMotion
602//purpose : Rotation
603//==============================================================================
604
605static void ProcessMotion()
606{
607 //pre-hilights detected objects at mouse position
608
609 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
610 EM->MoveTo(X_Motion, Y_Motion);
611}
612
613
614void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
615{
616 Xpix = X_Motion;Ypix=Y_Motion;
617}
618
619//==============================================================================
620//function : VAxo
621//purpose : Switch to an Axonometric view
622//Draw arg : No args
623//==============================================================================
624
625static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
626{ if ( ViewerTest::CurrentView().IsNull() ) {
627 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
628 // VInit(di, argc, argv);
629}
630
631ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
632
633return 0;
634}
635
636//==============================================================================
637//function : VTop
638//purpose : Switch to a Top View
639//Draw arg : No args
640//==============================================================================
641
642static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
643{
644
645 if ( ViewerTest::CurrentView().IsNull() ) {
646 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
647
648 // VInit(di, , argv);
649 }
650
651 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
652 return 0;
653
654}
655
656//==============================================================================
657//function : VHelp
658//purpose : Dsiplay help on viewer Keyboead and mouse commands
659//Draw arg : No args
660//==============================================================================
661
662static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
663{
664
665 di << "Q : Quit the application" << "\n";
666
667 di << "========================="<<"\n";
668 di << "F : FitAll" << "\n";
669 di << "T : TopView" << "\n";
670 di << "A : AxonometricView" << "\n";
671 di << "R : ResetView" << "\n";
672
673 di << "========================="<<"\n";
674 di << "S : Shading" << "\n";
675 di << "W : Wireframe" << "\n";
676 di << "H : HidelLineRemoval" << "\n";
677
678 di << "========================="<<"\n";
679 di << "Selection mode "<<"\n";
680 di << "0 : Shape" <<"\n";
681 di << "1 : Vertex" <<"\n";
682 di << "2 : Edge" <<"\n";
683 di << "3 : Wire" <<"\n";
684 di << "4 : Face" <<"\n";
685 di << "5 : Shell" <<"\n";
686 di << "6 : Solid" <<"\n";
687 di << "7 : Compound" <<"\n";
688
689 di << "=========================="<<"\n";
690 di << "D : Remove Selected Object"<<"\n";
691 di << "=========================="<<"\n";
692
693 return 0;
694}
695
696Standard_Boolean IsDragged = Standard_False;
697
698Standard_Integer xx1, yy1, xx2, yy2;
699//the first and last point in viewer co-ordinates
700
701Standard_Boolean DragFirst;
702
703
704#ifdef WNT
705
706static Standard_Boolean Ppick = 0;
707static Standard_Integer Pargc = 0;
708static const char** Pargv = NULL;
709
710
711static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
712 UINT Msg,
713 WPARAM wParam,
714 LPARAM lParam )
715{
716 if ( !ViewerTest::CurrentView().IsNull() ) {
717
718 WPARAM fwKeys = wParam;
719
720 switch( Msg ) {
721
722 case WM_LBUTTONUP:
723 IsDragged = Standard_False;
724 if( !DragFirst )
725 {
726 HDC hdc = GetDC( hwnd );
727 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
728 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
729 SetROP2( hdc, R2_NOT );
730 Rectangle( hdc, xx1, yy1, xx2, yy2 );
731 ReleaseDC( hwnd, hdc );
732
733 const Handle(ViewerTest_EventManager) EM =
734 ViewerTest::CurrentEventManager();
735 if ( fwKeys & MK_SHIFT )
736 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
737 max( xx1, xx2 ), min( yy1, yy2 ));
738 else
739 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
740 max( xx1, xx2 ), min( yy1, yy2 ));
741 }
742 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
743
744 case WM_LBUTTONDOWN:
745 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
746 {
747 IsDragged = Standard_True;
748 DragFirst = Standard_True;
749 xx1 = LOWORD(lParam);
750 yy1 = HIWORD(lParam);
751 }
752 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
753
754 break;
755
756 case WM_MOUSEMOVE:
757 if( IsDragged )
758 {
759 HDC hdc = GetDC( hwnd );
760
761 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
762 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
763 SetROP2( hdc, R2_NOT );
764
765 if( !DragFirst )
766 Rectangle( hdc, xx1, yy1, xx2, yy2 );
767
768 DragFirst = Standard_False;
769 xx2 = LOWORD(lParam);
770 yy2 = HIWORD(lParam);
771
772 Rectangle( hdc, xx1, yy1, xx2, yy2 );
773
774 SelectObject( hdc, anObj );
775
776 ReleaseDC( hwnd, hdc );
777 }
778 else
779 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
780 break;
781
782 default:
783 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
784 }
785 return 0;
786 }
787 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
788}
789
790
791static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
792 UINT Msg,
793 WPARAM wParam,
794 LPARAM lParam )
795{
796 /*static Standard_Boolean Ppick = 0;
797 static Standard_Integer Pargc = 0;
798 static char** Pargv = NULL;*/
799
800 static int Up = 1;
801
802 if ( !ViewerTest::CurrentView().IsNull() ) {
803 PAINTSTRUCT ps;
804
805 switch( Msg ) {
806 case WM_CLOSE:
807 // do not destroy the window - just hide it!
808 VT_GetWindow()->Unmap();
809 return 0;
810 case WM_PAINT:
811 //cout << "\t WM_PAINT" << endl;
812 BeginPaint(hwnd, &ps);
813 EndPaint(hwnd, &ps);
814 ProcessExpose();
815 break;
816
817 case WM_SIZE:
818 //cout << "\t WM_SIZE" << endl;
819 ProcessConfigure();
820 break;
821
822 case WM_KEYDOWN:
823 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
824
825 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
826 char c[2];
827 c[0] = (char) wParam;
828 c[1] = '\0';
829 ProcessKeyPress( c);
830 }
831 break;
832
833 case WM_LBUTTONUP:
834 case WM_MBUTTONUP:
835 case WM_RBUTTONUP:
836 //cout << "\t WM_xBUTTONUP" << endl;
837 Up = 1;
838 ProcessButtonRelease();
839 break;
840
841 case WM_LBUTTONDOWN:
842 case WM_MBUTTONDOWN:
843 case WM_RBUTTONDOWN:
844 {
845 //cout << "\t WM_xBUTTONDOWN" << endl;
846 WPARAM fwKeys = wParam;
847
848 Up = 0;
849
850 X_ButtonPress = LOWORD(lParam);
851 Y_ButtonPress = HIWORD(lParam);
852
853 if ( Msg == WM_LBUTTONDOWN) {
854 if(fwKeys & MK_CONTROL) {
855 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
856 } else
857 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
858 }
859 else if ( Msg == WM_RBUTTONDOWN ) {
860 // Start rotation
861 ProcessButton3Press( );
862 }
863 }
864 break;
865
866 case WM_MOUSEMOVE:
867 {
868 //cout << "\t WM_MOUSEMOVE" << endl;
869 WPARAM fwKeys = wParam;
870 X_Motion = LOWORD(lParam);
871 Y_Motion = HIWORD(lParam);
872
873 if ( Up &&
874 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
875 Up = 0;
876 X_ButtonPress = LOWORD(lParam);
877 Y_ButtonPress = HIWORD(lParam);
878
879 if ( fwKeys & MK_RBUTTON ) {
880 // Start rotation
881 ProcessButton3Press();
882 }
883 }
884
885 if ( fwKeys & MK_CONTROL ) {
886 if ( fwKeys & MK_LBUTTON ) {
887 ProcessControlButton1Motion();
888 }
889 else if ( fwKeys & MK_MBUTTON ||
890 ((fwKeys&MK_LBUTTON) &&
891 (fwKeys&MK_RBUTTON) ) ){
892 ProcessControlButton2Motion();
893 }
894 else if ( fwKeys & MK_RBUTTON ) {
895 ProcessControlButton3Motion();
896 }
897 }
898#ifdef BUG
899 else if ( fwKeys & MK_SHIFT ) {
900 if ( fwKeys & MK_MBUTTON ||
901 ((fwKeys&MK_LBUTTON) &&
902 (fwKeys&MK_RBUTTON) ) ) {
903 cout << "ProcessZClipMotion()" << endl;
904 ProcessZClipMotion();
905 }
906 }
907#endif
908 else
909 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
910 ProcessZClipMotion();
911 }
912 else {
913 ProcessMotion();
914 }
915 }
916 break;
917
918 default:
919 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
920 }
921 return 0L;
922 }
923
924 return DefWindowProc( hwnd, Msg, wParam, lParam );
925}
926
927
928
929
930//==============================================================================
931//function : ViewerMainLoop
932//purpose : Get a Event on the view and dispatch it
933//==============================================================================
934
935
936static int ViewerMainLoop(Standard_Integer argc, const char** argv)
937{
938
939 //cout << "No yet implemented on WNT" << endl;
940 /*static Standard_Boolean Ppick = 0;
941 static Standard_Integer Pargc = 0;
942 static char** Pargv = NULL;*/
943
944 //Ppick = (argc > 0)? -1 : 0;
945 Ppick = (argc > 0)? 1 : 0;
946 Pargc = argc;
947 Pargv = argv;
948
949 if ( Ppick ) {
950 MSG msg;
951 msg.wParam = 1;
952
953 cout << "Start picking" << endl;
954
955 //while ( Ppick == -1 ) {
956 while ( Ppick == 1 ) {
957 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
958 if (GetMessage(&msg, NULL, 0, 0) ) {
959 TranslateMessage(&msg);
960 DispatchMessage(&msg);
961 }
962 }
963
964 cout << "Picking done" << endl;
965 }
966
967 return Ppick;
968}
969
970
971#else
972
973int min( int a, int b )
974{
975 if( a<b )
976 return a;
977 else
978 return b;
979}
980
981int max( int a, int b )
982{
983 if( a>b )
984 return a;
985 else
986 return b;
987}
988
989int ViewerMainLoop(Standard_Integer argc, const char** argv)
990
991{ Standard_Boolean pick = argc > 0;
992
993// X11 Event loop
994
995static XEvent report;
996
997XNextEvent( display, &report );
998// cout << "rep type = " << report.type << endl;
999// cout << "rep button = " << report.xbutton.button << endl;
1000
1001switch ( report.type ) {
1002 case Expose:
1003 {
1004 ProcessExpose();
1005 }
1006 break;
1007 case ConfigureNotify:
1008 {
1009 ProcessConfigure();
1010 }
1011 break;
1012 case KeyPress:
1013 {
1014
1015 KeySym ks_ret ;
1016 char buf_ret[11] ;
1017 int ret_len ;
1018 XComposeStatus status_in_out;
1019
1020 ret_len = XLookupString( ( XKeyEvent *)&report ,
1021 (char *) buf_ret , 10 ,
1022 &ks_ret , &status_in_out ) ;
1023
1024
1025 buf_ret[ret_len] = '\0' ;
1026
1027 if ( ret_len ) {
1028 ProcessKeyPress( buf_ret);
1029 }
1030 }
1031 break;
1032 case ButtonPress:
1033 // cout << "ButtonPress" << endl;
1034 {
1035 X_ButtonPress = report.xbutton.x;
1036 Y_ButtonPress = report.xbutton.y;
1037
1038 if ( report.xbutton.button == Button1 )
1039 if( report.xbutton.state & ControlMask )
1040 pick = ProcessButton1Press( argc, argv, pick,
1041 ( report.xbutton.state & ShiftMask) );
1042 else
1043 {
1044 IsDragged = Standard_True;
1045 xx1 = X_ButtonPress;
1046 yy1 = Y_ButtonPress;
1047 DragFirst = Standard_True;
1048 }
1049 else if ( report.xbutton.button == Button3 )
1050 // Start rotation
1051 ProcessButton3Press();
1052 }
1053 break;
1054 case ButtonRelease:
1055 {
1056 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1057 // cout << IsDragged << endl;
1058 // cout << DragFirst << endl;
1059
1060 if( IsDragged )
1061 {
1062 if( !DragFirst )
1063 {
1064 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1065 GC gc = XCreateGC( display, aWindow, 0, 0 );
1066 // XSetFunction( display, gc, GXinvert );
1067 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1068 }
1069
1070 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1071 if( aContext.IsNull() )
1072 {
1073 cout << "The context is null. Please use vinit before createmesh" << endl;
1074 return 0;
1075 }
1076
1077 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1078 if( report.xbutton.button==1 )
1079 if( DragFirst )
1080 if( ShiftPressed )
1081 {
1082 aContext->ShiftSelect();
1083 // cout << "shift select" << endl;
1084 }
1085 else
1086 {
1087 aContext->Select();
1088 // cout << "select" << endl;
1089 }
1090 else
1091 if( ShiftPressed )
1092 {
1093 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1094 max( xx1, xx2 ), max( yy1, yy2 ),
1095 ViewerTest::CurrentView());
1096 // cout << "shift select" << endl;
1097 }
1098 else
1099 {
1100 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1101 max( xx1, xx2 ), max( yy1, yy2 ),
1102 ViewerTest::CurrentView() );
1103 // cout << "select" << endl;
1104 }
1105 else
1106 ProcessButtonRelease();
1107
1108 IsDragged = Standard_False;
1109 }
1110 else
1111 ProcessButtonRelease();
1112 }
1113 break;
1114 case MotionNotify:
1115 {
1116 // XEvent dummy;
1117
1118 X_Motion = report.xmotion.x;
1119 Y_Motion = report.xmotion.y;
1120
1121 if( IsDragged )
1122 {
1123 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1124 GC gc = XCreateGC( display, aWindow, 0, 0 );
1125 XSetFunction( display, gc, GXinvert );
1126
1127 if( !DragFirst )
1128 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1129
1130 xx2 = X_Motion;
1131 yy2 = Y_Motion;
1132 DragFirst = Standard_False;
1133
1134 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1135 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1136 }
1137 else
1138 {
1139
1140 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1141
1142 // remove all the ButtonMotionMask
1143 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1144
1145 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1146 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1147
1148 Quantity_Length VDX, VDY;
1149
1150 ViewerTest::CurrentView()->Size(VDX,VDY);
1151 Standard_Real VDZ =0 ;
1152 VDZ = ViewerTest::CurrentView()->ZSize();
1153
1154 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1155 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1156
1157 Quantity_Length dx = 0 ;
1158 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1159
1160 cout << dx << endl;
1161
1162 dx = dx / VDX * VDZ;
1163
1164 cout << dx << endl;
1165
1166 // Front = Depth + width/2.
1167 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1168 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1169
1170 ViewerTest::CurrentView()->Redraw();
1171 }
1172 }
1173
1174 if ( report.xmotion.state & ControlMask ) {
1175 if ( report.xmotion.state & Button1Mask ) {
1176 ProcessControlButton1Motion();
1177 }
1178 else if ( report.xmotion.state & Button2Mask ) {
1179 ProcessControlButton2Motion();
1180 }
1181 else if ( report.xmotion.state & Button3Mask ) {
1182 ProcessControlButton3Motion();
1183 }
1184 }
1185 else {
1186 ProcessMotion();
1187 }
1188 }
1189 }
1190 break;
1191}
1192
1193
1194return pick;
1195}
1196
1197//==============================================================================
1198//function : VProcessEvents
1199//purpose : call by Tk_CreateFileHandler() to be able to manage the
1200// event in the Viewer window
1201//==============================================================================
1202
1203static void VProcessEvents(ClientData,int)
1204{
1205 //cout << "VProcessEvents" << endl;
1206
1207 // test for X Event
1208 while (XPending(display)) {
1209 ViewerMainLoop( 0, NULL);
1210 }
1211}
1212#endif
1213
1214//==============================================================================
1215//function : OSWindowSetup
1216//purpose : Setup for the X11 window to be able to cath the event
1217//==============================================================================
1218
1219
1220static void OSWindowSetup()
1221{
1222#ifndef WNT
1223 // X11
1224
1225 Window window = VT_GetWindow()->XWindow();
1226
1227 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1228 display = (Display * ) theDisplay;
1229 // display = (Display *)GetG3dDevice()->XDisplay();
1230
1231 XSynchronize(display, 1);
1232
1233 VT_GetWindow()->Map();
1234
1235 // X11 : For keyboard on SUN
1236 XWMHints wmhints;
1237 wmhints.flags = InputHint;
1238 wmhints.input = 1;
1239
1240 XSetWMHints( display, window, &wmhints);
1241
1242 XSelectInput( display, window, ExposureMask | KeyPressMask |
1243 ButtonPressMask | ButtonReleaseMask |
1244 StructureNotifyMask |
1245 PointerMotionMask |
1246 Button1MotionMask | Button2MotionMask |
1247 Button3MotionMask
1248 );
1249
1250 XSynchronize(display, 0);
1251
1252#else
1253 // WNT
1254#endif
1255
1256}
1257
1258
1259//==============================================================================
1260//function : VFit
1261
1262//purpose : Fitall, no DRAW arguments
1263//Draw arg : No args
1264//==============================================================================
1265
1266static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1267{
1268 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1269 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1270 if (V.IsNull() == Standard_False) {
1271 V->FitAll3d();
1272 } else if (aView.IsNull() == Standard_False) {
1273 aView->FitAll();
1274 }
1275 return 0;
1276}
1277
1278//==============================================================================
1279//function : VZFit
1280//purpose : ZFitall, no DRAW arguments
1281//Draw arg : No args
1282//==============================================================================
1283
1284static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1285{
1286 Handle(V3d_View) V = ViewerTest::CurrentView();
1287 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1288
1289
1290static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1291{
1292 Handle(V3d_View) V = ViewerTest::CurrentView();
1293 if ( !V.IsNull() ) V->Redraw(); return 0;
1294}
1295
1296
1297//==============================================================================
1298//function : VClear
1299//purpose : Remove all the object from the viewer
1300//Draw arg : No args
1301//==============================================================================
1302
1303static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1304{
1305 Handle(V3d_View) V = ViewerTest::CurrentView();
1306 if(!V.IsNull())
1307 ViewerTest::Clear();
1308 return 0;
1309}
1310
1311//==============================================================================
1312//function : VPick
1313//purpose :
1314//==============================================================================
1315
1316static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1317{ if (ViewerTest::CurrentView().IsNull() ) return 1;
1318
1319if ( argc < 4 ) {
1320 di << argv[0] << "Invalid number of arguments" << "\n";
1321 return 1;
1322}
1323
1324while (ViewerMainLoop( argc, argv)) {
1325}
1326
1327return 0;
1328}
1329
1330
1331
1332//==============================================================================
1333//function : InitViewerTest
1334//purpose : initialisation de toutes les variables static de ViewerTest (dp)
1335//==============================================================================
1336
1337void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1338{
1339 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1340 ViewerTest::SetAISContext(context);
1341 viewer->InitActiveViews();
1342 Handle(V3d_View) view = viewer->ActiveView();
1343 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1344 ViewerTest::ResetEventManager();
1345 Handle(Aspect_GraphicDevice) device = viewer->Device();
1346 Handle(Aspect_Window) window = view->Window();
1347#ifndef WNT
1348 // X11
1349 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1350 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1351 OSWindowSetup();
1352 static int first = 1;
1353 if ( first ) {
1354#if TCL_MAJOR_VERSION < 8
1355 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1356 TK_READABLE, VProcessEvents, (ClientData) 0);
1357#else
1358 Tk_CreateFileHandler(ConnectionNumber(display),
1359 TK_READABLE, VProcessEvents, (ClientData) 0);
1360#endif
1361 first = 0;
1362 }
1363#endif
1364}
1365
1366
1367//==============================================================================
1368//function : VSetBg
1369//purpose : Load image as background
1370//==============================================================================
1371
1372static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1373{
1374 if (argc < 2 || argc > 3)
1375 {
1376 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
1377 return 1;
1378 }
1379
1380 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1381 if(AISContext.IsNull())
1382 {
1383 di << "use 'vinit' command before " << argv[0] << "\n";
1384 return 1;
1385 }
1386
1387 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1388 if (argc == 3)
1389 {
1390 const char* szType = argv[2];
1391 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1392 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1393 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1394 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1395 else
1396 {
1397 di << "Wrong fill type : " << szType << "\n";
1398 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1399 return 1;
1400 }
1401 }
1402
1403 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1404 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1405
1406 return 0;
1407}
1408
1409//==============================================================================
1410//function : VSetGradientBg
1411//purpose : Mount gradient background
1412//==============================================================================
1413static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1414{
1415 if (argc != 8 )
1416 {
1417 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1418 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1419 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1420 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1421 return 1;
1422 }
1423
1424 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1425 if(AISContext.IsNull())
1426 {
1427 di << "use 'vinit' command before " << argv[0] << "\n";
1428 return 1;
1429 }
1430 if (argc == 8)
1431 {
1432
1433 Standard_Real R1 = atof(argv[1])/255.;
1434 Standard_Real G1 = atof(argv[2])/255.;
1435 Standard_Real B1 = atof(argv[3])/255.;
1436 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1437
1438 Standard_Real R2 = atof(argv[4])/255.;
1439 Standard_Real G2 = atof(argv[5])/255.;
1440 Standard_Real B2 = atof(argv[6])/255.;
1441
1442 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1443 int aType = atoi(argv[7]);
1444 if( aType < 0 || aType > 8 )
1445 {
1446 di << "Wrong fill type " << "\n";
1447 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1448 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1449 return 1;
1450 }
1451
1452 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1453
1454 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1455 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1456 }
1457
1458 return 0;
1459}
1460
1461//==============================================================================
1462//function : VScale
1463//purpose : View Scaling
1464//==============================================================================
1465
1466static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1467{
1468 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1469 if ( V3dView.IsNull() ) return 1;
1470
1471 if ( argc != 4 ) {
1472 di << argv[0] << "Invalid number of arguments" << "\n";
1473 return 1;
1474 }
1475 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1476 return 0;
1477}
1478//==============================================================================
1479//function : VTestZBuffTrihedron
1480//purpose : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view
1481//==============================================================================
1482
1483static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1484{
1485 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1486 if ( V3dView.IsNull() ) return 1;
1487
1488 // Set up default trihedron parameters
1489 V3dView->ZBufferTriedronSetup();
1490 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1491 V3dView->ZFitAll();
1492 return 0;
1493}
1494
1495//==============================================================================
1496//function : VRotate
1497//purpose : Camera Rotating
1498//==============================================================================
1499
1500static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1501 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1502 if ( V3dView.IsNull() ) {
1503 return 1;
1504 }
1505
1506 if ( argc == 4 ) {
1507 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1508 return 0;
1509 } else if ( argc == 7 ) {
1510 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1511 return 0;
1512 } else {
1513 di << argv[0] << " Invalid number of arguments" << "\n";
1514 return 1;
1515 }
1516}
1517
1518//==============================================================================
1519//function : VZoom
1520//purpose : View zoom in / out (relative to current zoom)
1521//==============================================================================
1522
1523static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1524 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1525 if ( V3dView.IsNull() ) {
1526 return 1;
1527 }
1528
1529 if ( argc == 2 ) {
1530 Standard_Real coef = atof(argv[1]);
1531 if ( coef <= 0.0 ) {
1532 di << argv[1] << "Invalid value" << "\n";
1533 return 1;
1534 }
1535 V3dView->SetZoom( atof(argv[1]) );
1536 return 0;
1537 } else {
1538 di << argv[0] << " Invalid number of arguments" << "\n";
1539 return 1;
1540 }
1541}
1542
1543//==============================================================================
1544//function : VPan
1545//purpose : View panning (in pixels)
1546//==============================================================================
1547
1548static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1549 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1550 if ( V3dView.IsNull() ) return 1;
1551
1552 if ( argc == 3 ) {
1553 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1554 return 0;
1555 } else {
1556 di << argv[0] << " Invalid number of arguments" << "\n";
1557 return 1;
1558 }
1559}
1560
1561
1562//==============================================================================
1563//function : VExport
1564//purpose : Export teh view to a vector graphic format (PS, EMF, PDF)
1565//==============================================================================
1566
1567static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1568{
1569 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1570 if ( V3dView.IsNull() ) return 1;
1571
1572 if ( argc != 3 ) {
1573 di << argv[0] << "Invalid number of arguments" << "\n";
1574 return 1;
1575 }
1576
1577 TCollection_AsciiString aFormat( argv[2] );
1578 aFormat.UpperCase();
1579 Graphic3d_ExportFormat exFormat;
1580 if ( aFormat == "PS" )
1581 exFormat = Graphic3d_EF_PostScript;
1582 if ( aFormat == "EPS" )
1583 exFormat = Graphic3d_EF_EnhPostScript;
1584 if ( aFormat == "TEX" )
1585 exFormat = Graphic3d_EF_TEX;
1586 if ( aFormat == "PDF" )
1587 exFormat = Graphic3d_EF_PDF;
1588 if ( aFormat == "SVG" )
1589 exFormat = Graphic3d_EF_SVG;
1590 if ( aFormat == "PGF" )
1591 exFormat = Graphic3d_EF_PGF;
1592 V3dView->View()->Export( argv[1], exFormat );
1593 return 0;
1594}
1595
1596//==============================================================================
1597//function : VColorScale
1598//purpose : representation color scale
1599//==============================================================================
1600#include <V3d_ColorScale.hxx>
1601
1602static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1603{
1604 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1605 {
1606 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1607 return 1;
1608 }
1609
1610 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1611 if(aContext.IsNull()) {
1612 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1613 return -1;
1614 }
1615
1616 Standard_Real minRange = 0. , maxRange = 100. ;
1617
1618 Standard_Integer numIntervals = 10 ;
1619 Standard_Real textHeight = 16. ;
1620 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1621 Standard_Real X = 0., Y = 0. ;
1622
1623 if ( argc < 9 )
1624 {
1625 if( argc > 3 )
1626 {
1627 minRange = atof( argv[1] );
1628 maxRange = atof( argv[2] );
1629 numIntervals = atoi( argv[3] );
1630 }
1631 if ( argc > 4 )
1632 textHeight = atof( argv[4] );
1633 if ( argc > 5 )
1634 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1635 if ( argc > 7 )
1636 {
1637 X = atof( argv[6] );
1638 Y = atof( argv[7] );
1639 }
1640 }
1641 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1642 if ( curView.IsNull( ) )
1643 return 1;
1644 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1645 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1646 if( ! aCS.IsNull( ) )
1647 {
1648 aCS->SetPosition( X , Y );
1649 aCS->SetHeight( 0.95) ;
1650 aCS->SetTextHeight( textHeight );
1651 aCS->SetRange( minRange , maxRange );
1652 aCS->SetNumberOfIntervals( numIntervals );
1653 aCS->SetLabelPosition( position );
1654 if( !curView->ColorScaleIsDisplayed() )
1655 curView->ColorScaleDisplay( );
1656 }
1657 return 0;
1658}
1659
1660//==============================================================================
1661//function : VGraduatedTrihedron
1662//purpose : Displays a graduated trihedron
1663//==============================================================================
1664static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1665{
1666 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1667 if (V3dView.IsNull())
1668 return 1;
1669
1670 if (argc < 2)
1671 {
1672 di << argv[0] << " Invalid number of arguments" << "\n";
1673 return 1;
1674 }
1675
1676 Standard_CString xname = "X (mm)";
1677 Standard_CString yname = "Y (mm)";
1678 Standard_CString zname = "Z (mm)";
1679
1680 if (argc > 2)
1681 {
1682 if (argc != 5)
1683 {
1684 di << argv[0] << " Define all X, Y and Z axes names, please" << "\n";
1685 return 1;
1686 }
1687 xname = argv[2];
1688 yname = argv[3];
1689 zname = argv[4];
1690 }
1691
1692 int display = atoi(argv[1]);
1693 if (display)
1694 V3dView->GraduatedTrihedronDisplay(xname, yname, zname,
1695 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
1696 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
1697 Standard_True/*drawgrid*/,
1698 Standard_True/*drawaxes*/,
1699 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
1700 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
1701 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
1702 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
1703 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/);
1704 else
1705 V3dView->GraduatedTrihedronErase();
1706
1707 ViewerTest::GetAISContext()->UpdateCurrentViewer();
1708 V3dView->Redraw();
1709 return 0;
1710}
1711
1712//=======================================================================
1713//function : ViewerCommands
1714//purpose :
1715//=======================================================================
1716
1717void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
1718{
1719
1720 const char *group = "ZeViewer";
1721 theCommands.Add("vinit" ,
1722 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
1723 __FILE__,VInit,group);
1724 theCommands.Add("vhelp" ,
1725 "vhelp : display help on the viewer commands",
1726 __FILE__,VHelp,group);
1727 theCommands.Add("vtop" ,
1728 "vtop or <T> : Top view" ,
1729 __FILE__,VTop,group);
1730 theCommands.Add("vaxo" ,
1731 " vaxo or <A> : Axonometric view ",
1732 __FILE__,VAxo,group);
1733 theCommands.Add("vpick" ,
1734 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
1735 VPick,group);
1736 theCommands.Add("vfit" ,
1737 "vfit or <F> : vfit",
1738 __FILE__,VFit,group);
1739 theCommands.Add("vzfit" ,
1740 "vzfit",
1741 __FILE__,VZFit,group);
1742 theCommands.Add("vrepaint",
1743 "vrepaint : vrepaint, force redraw",
1744 __FILE__,VRepaint,group);
1745 theCommands.Add("vclear",
1746 "vclear : vclear",
1747 __FILE__,VClear,group);
1748 theCommands.Add("vsetbg",
1749 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
1750 __FILE__,VSetBg,group);
1751 theCommands.Add("vsetgradientbg",
1752 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
1753 __FILE__,VSetGradientBg,group);
1754 theCommands.Add("vscale",
1755 "vscale : vscale X Y Z",
1756 __FILE__,VScale,group);
1757 theCommands.Add("vzbufftrihedron",
1758 "vzbufftrihedron : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view",
1759 __FILE__,VTestZBuffTrihedron,group);
1760 theCommands.Add("vrotate",
1761 "vrotate : vrotate AX AY AZ [X Y Z]",
1762 __FILE__,VRotate,group);
1763 theCommands.Add("vzoom",
1764 "vzoom : vzoom coef",
1765 __FILE__,VZoom,group);
1766 theCommands.Add("vpan",
1767 "vpan : vpan dx dy",
1768 __FILE__,VPan,group);
1769 theCommands.Add("vexport",
1770 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGV } : exports the view to a vector file of a given format",
1771 __FILE__,VExport,group);
1772 theCommands.Add("vcolorscale",
1773 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
1774 __FILE__,VColorScale,group);
1775 theCommands.Add("vgraduatedtrihedron",
1776 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname]",
1777 __FILE__,VGraduatedTrihedron,group);
1778}