Correction of compilation problem
[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>
25289ec1 20#include <Visual3d_ViewManager.hxx>
21#include <V3d_LayerMgr.hxx>
7fd59977 22#include <NIS_View.hxx>
23#include <NIS_Triangulated.hxx>
24#include <NIS_InteractiveContext.hxx>
25#include <AIS_InteractiveContext.hxx>
26#include <Draw_Interpretor.hxx>
27#include <Draw.hxx>
28#include <Draw_Appli.hxx>
7edf74fd
A
29#include <Aspect_PrintAlgo.hxx>
30#include <Image_PixMap.hxx>
59f45b7c 31#include <TColStd_SequenceOfInteger.hxx>
20637bd2 32#include <Visual3d_LayerItem.hxx>
33#include <V3d_LayerMgr.hxx>
34#include <V3d_LayerMgrPointer.hxx>
35#include <Aspect_TypeOfLine.hxx>
7fd59977 36
25289ec1 37#ifdef WNT
38#undef DrawText
39#endif
40
41#include <Visual3d_Layer.hxx>
42
7fd59977 43#ifndef WNT
44#include <Graphic3d_GraphicDevice.hxx>
45#include <Xw_GraphicDevice.hxx>
46#include <Xw_WindowQuality.hxx>
47#include <Xw_Window.hxx>
48#include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
49#include <X11/Xutil.h>
50#include <tk.h>
51
52#else
53
54#include <Graphic3d_WNTGraphicDevice.hxx>
55#include <WNT_WClass.hxx>
56#include <WNT_Window.hxx>
57
58#define _CRT_SECURE_NO_DEPRECATE
59#pragma warning (disable:4996)
60
61#endif
62
63#define OCC120
64
65//==============================================================================
66
67//==============================================================================
68// VIEWER GLOBAL VARIABLES
69//==============================================================================
70
71Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
72
73Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
74extern const Handle(NIS_InteractiveContext)& TheNISContext();
75
76#ifdef WNT
77static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
78 static Handle(Graphic3d_WNTGraphicDevice) GD;
79 return GD;
80}
81
82static Handle(WNT_Window)& VT_GetWindow() {
83 static Handle(WNT_Window) WNTWin;
84 return WNTWin;
85}
86
87#else
88static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
89 static Handle(Graphic3d_GraphicDevice) GD;
90 return GD;
91}
92static Handle(Xw_Window)& VT_GetWindow(){
93 static Handle(Xw_Window) XWWin;
94 return XWWin;
95}
96static Display *display;
97
98static void VProcessEvents(ClientData,int);
99#endif
100
101#ifdef OCC120
102static Standard_Boolean DegenerateMode = Standard_True;
103#endif
104
105#define ZCLIPWIDTH 1.
106
107static void OSWindowSetup();
108
109//==============================================================================
110// EVENT GLOBAL VARIABLES
111//==============================================================================
112
113static int Start_Rot = 0;
114static int ZClipIsOn = 0;
115static int X_Motion= 0,Y_Motion=0; // Current cursor position
116static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
117
118
119//==============================================================================
120
121#ifdef WNT
122static LRESULT WINAPI ViewerWindowProc(
123 HWND hwnd,
124 UINT uMsg,
125 WPARAM wParam,
126 LPARAM lParam );
127static LRESULT WINAPI AdvViewerWindowProc(
128 HWND hwnd,
129 UINT uMsg,
130 WPARAM wParam,
131 LPARAM lParam );
132#endif
133
134
135//==============================================================================
136//function : WClass
137//purpose :
138//==============================================================================
139
140const Handle(MMgt_TShared)& ViewerTest::WClass()
141{
142 static Handle(MMgt_TShared) theWClass;
143#ifdef WNT
144 if (theWClass.IsNull()) {
145 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
146 CS_VREDRAW | CS_HREDRAW, 0, 0,
147 ::LoadCursor (NULL, IDC_ARROW));
148 }
149#endif
150 return theWClass;
151}
152
153//==============================================================================
154//function : ViewerInit
155//purpose : Create the window viewer and initialize all the global variable
156//==============================================================================
157
158void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_Integer thePxTop,
159 const Standard_Integer thePxWidth, const Standard_Integer thePxHeight)
160{
161 static Standard_Boolean isFirst = Standard_True;
162
163 Standard_Integer aPxLeft = 0;
164 Standard_Integer aPxTop = 460;
165 Standard_Integer aPxWidth = 409;
166 Standard_Integer aPxHeight = 409;
167 if (thePxWidth != 0 && thePxHeight != 0)
168 {
169 aPxLeft = thePxLeft;
170 aPxTop = thePxTop;
171 aPxWidth = thePxWidth;
172 aPxHeight = thePxHeight;
173 }
174
175 if (isFirst)
176 {
177 // Create the Graphic device
178#ifdef WNT
179 if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
180 if (VT_GetWindow().IsNull())
181 {
182 // Create the Graphic device and the window
183 Handle(WNT_GraphicDevice) g_Device = new WNT_GraphicDevice();
184
185 VT_GetWindow() = new WNT_Window (g_Device, "Test3d",
186 Handle(WNT_WClass)::DownCast (WClass()),
187 WS_OVERLAPPEDWINDOW,
188 aPxLeft, aPxTop,
189 aPxWidth, aPxHeight,
190 Quantity_NOC_BLACK);
191 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
192 }
193#else
194 if (GetG3dDevice().IsNull()) GetG3dDevice() =
195 new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
196 if (VT_GetWindow().IsNull())
197 {
198 VT_GetWindow() = new Xw_Window (GetG3dDevice(),
199 "Test3d",
200 aPxLeft, aPxTop,
201 aPxWidth, aPxHeight,
202 Xw_WQ_3DQUALITY,
203 Quantity_NOC_BLACK);
204 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
205 }
206#endif
207
208 Handle(V3d_Viewer) a3DViewer, a3DCollector;
209 // Viewer and View creation
210
211 TCollection_ExtendedString NameOfWindow("Visu3D");
212
213 a3DViewer = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
214 NameOfWindow = TCollection_ExtendedString("Collector");
215 a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
216 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
217 a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
218 Handle(NIS_View) aView =
219 Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
220 if ( aView.IsNull() ) {
221 // Handle (V3d_View) V = a3DViewer->CreateView();
222 aView = new NIS_View (a3DViewer, VT_GetWindow());
223 ViewerTest::CurrentView(aView);
224 TheNISContext()->AttachView (aView);
225 }
226 Handle(V3d_View) a3DViewCol;
227 if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
228
229 // AIS setup
230 if ( ViewerTest::GetAISContext().IsNull() ) {
231 Handle(AIS_InteractiveContext) C =
232 new AIS_InteractiveContext(a3DViewer,a3DCollector);
233 ViewerTest::SetAISContext(C);
234 }
235
236 // Setup for X11 or NT
237 OSWindowSetup();
238 // Viewer and View creation
239
240 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
241
242 Handle (V3d_View) V = ViewerTest::CurrentView();
243
244 V->SetDegenerateModeOn();
245#ifdef OCC120
246 DegenerateMode = V->DegenerateModeIsOn();
247#endif
248 // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
249
250 V->SetZClippingDepth(0.5);
251 V->SetZClippingWidth(ZCLIPWIDTH/2.);
252 a3DViewer->SetDefaultLights();
253 a3DViewer->SetLightOn();
254
255#ifndef WNT
256#if TCL_MAJOR_VERSION < 8
257 Tk_CreateFileHandler((void*)ConnectionNumber(display),
258 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
259#else
260 Tk_CreateFileHandler(ConnectionNumber(display),
261 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
262#endif
263#endif
264
265 isFirst = Standard_False;
266 }
267 VT_GetWindow()->Map();
268}
269
270//==============================================================================
271//function : Vinit
272//purpose : Create the window viewer and initialize all the global variable
273// Use Tk_CreateFileHandler on UNIX to cath the X11 Viewer event
274//==============================================================================
275
276static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv)
277{
278 Standard_Integer aPxLeft = (argc > 1) ? atoi (argv[1]) : 0;
279 Standard_Integer aPxTop = (argc > 2) ? atoi (argv[2]) : 0;
280 Standard_Integer aPxWidth = (argc > 3) ? atoi (argv[3]) : 0;
281 Standard_Integer aPxHeight = (argc > 4) ? atoi (argv[4]) : 0;
282 ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight);
283 return 0;
284}
285
286//==============================================================================
287//function : ProcessKeyPress
288//purpose : Handle KeyPress event from a CString
289//==============================================================================
290
291static void ProcessKeyPress( char *buf_ret )
292{
293 //cout << "KeyPress" << endl;
294 const Handle(V3d_View) aView = ViewerTest::CurrentView();
295 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
296 // Letter in alphabetic order
297
298 if ( !strcasecmp(buf_ret, "A") ) {
299 // AXO
300 aView->SetProj(V3d_XposYnegZpos);
301 }
302 else if ( !strcasecmp(buf_ret, "D") ) {
303 // Reset
304 aView->Reset();
305 }
306 else if ( !strcasecmp(buf_ret, "F") ) {
307 // FitAll
308 if (aNisView.IsNull())
309 aView->FitAll();
310 else
311 aNisView->FitAll3d();
312 }
313 else if ( !strcasecmp(buf_ret, "H") ) {
314 // HLR
315 cout << "HLR" << endl;
316#ifdef OCC120
317 if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
318 else aView->SetDegenerateModeOn();
319 DegenerateMode = aView->DegenerateModeIsOn();
320#else
321 ViewerTest::CurrentView()->SetDegenerateModeOff();
322#endif
323 }
324 else if ( !strcasecmp(buf_ret, "D") ) {
325 // Reset
326 aView->Reset();
327 }
328 else if ( !strcasecmp(buf_ret, "S") ) {
329 // SHADING
330 cout << "passage en mode 1 (shading pour les shapes)" << endl;
331#ifndef OCC120
332 ViewerTest::CurrentView()->SetDegenerateModeOn();
333#endif
334 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
335 if(Ctx->NbCurrents()==0 ||
336 Ctx->NbSelected()==0)
337 Ctx->SetDisplayMode(AIS_Shaded);
338 else{
339 if(Ctx->HasOpenedContext()){
340 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
341 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
342 }
343 else{
344 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
345 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
346 }
347 Ctx->UpdateCurrentViewer();
348 }
349 }
350 else if ( !strcasecmp(buf_ret, "U") ) {
351 // SHADING
352 cout<<"passage au mode par defaut"<<endl;
353#ifndef OCC120
354 ViewerTest::CurrentView()->SetDegenerateModeOn();
355#endif
356 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
357 if(Ctx->NbCurrents()==0 ||
358 Ctx->NbSelected()==0)
359 Ctx->SetDisplayMode(AIS_WireFrame);
360 else{
361 if(Ctx->HasOpenedContext()){
362 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
363 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
364 }
365 else{
366 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
367 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
368 }
369 Ctx->UpdateCurrentViewer();
370 }
371
372 }
373 else if ( !strcasecmp(buf_ret, "T") ) {
374 // Top
375 aView->SetProj(V3d_Zpos);
376 }
377 else if ( !strcasecmp(buf_ret, "B") ) {
378 // Top
379 aView->SetProj(V3d_Zneg);
380 }
381 else if ( !strcasecmp(buf_ret, "L") ) {
382 // Top
383 aView->SetProj(V3d_Xneg);
384 }
385 else if ( !strcasecmp(buf_ret, "R") ) {
386 // Top
387 aView->SetProj(V3d_Xpos);
388 }
389
390 else if ( !strcasecmp(buf_ret, "W") ) {
391 // WIREFRAME
392#ifndef OCC120
393 ViewerTest::CurrentView()->SetDegenerateModeOn();
394#endif
395 cout << "passage en mode 0 (filaire pour les shapes)" << endl;
396#ifndef OCC120
397 ViewerTest::CurrentView()->SetDegenerateModeOn();
398#endif
399 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
400 if(Ctx->NbCurrents()==0 ||
401 Ctx->NbSelected()==0)
402 Ctx->SetDisplayMode(AIS_WireFrame);
403 else{
404 if(Ctx->HasOpenedContext()){
405 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
406 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
407 }
408 else{
409 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
410 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
411 }
412 Ctx->UpdateCurrentViewer();
413 }
414 }
415 else if ( !strcasecmp(buf_ret, "Z") ) {
416 // ZCLIP
417
418 if ( ZClipIsOn ) {
419 cout << "ZClipping OFF" << endl;
420 ZClipIsOn = 0;
421
422 aView->SetZClippingType(V3d_OFF);
423 aView->Redraw();
424 }
425 else {
426 cout << "ZClipping ON" << endl;
427 ZClipIsOn = 1;
428
429 aView->SetZClippingType(V3d_FRONT);
430 aView->Redraw();
431 }
432 }
433 else if ( !strcasecmp(buf_ret, ",") ) {
434 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
435
436
437 }
438 else if ( !strcasecmp(buf_ret, ".") ) {
439 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
440 }
441 // Number
442 else{
443 Standard_Integer Num = atoi(buf_ret);
444 if(Num>=0 && Num<=7)
445 ViewerTest::StandardModeActivation(Num);
446 }
447}
448
449//==============================================================================
450//function : ProcessExpose
451//purpose : Redraw the View on an Expose Event
452//==============================================================================
453
454static void ProcessExpose( )
455{ //cout << "Expose" << endl;
456 ViewerTest::CurrentView()->Redraw();
457}
458
459//==============================================================================
460//function : ProcessConfigure
461//purpose : Resize the View on an Configure Event
462//==============================================================================
463
464static void ProcessConfigure()
465{
466 Handle(V3d_View) V = ViewerTest::CurrentView();
467 V->MustBeResized();
468 V->Update();
469 V->Redraw();
470}
471
472//==============================================================================
473//function : ProcessButton1Press
474//purpose : Picking
475//==============================================================================
476
477static Standard_Boolean ProcessButton1Press(
478 Standard_Integer ,
479 const char** argv,
480 Standard_Boolean pick,
481 Standard_Boolean shift )
482{
483 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
484 if ( pick ) {
485 Standard_Real X, Y, Z;
486
487 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
488
489 Draw::Set(argv[1], X);
490 Draw::Set(argv[2], Y);
491 Draw::Set(argv[3], Z);}
492
493 if(shift)
494 EM->ShiftSelect();
495 else
496 EM->Select();
497
498 pick = 0;
499 return pick;
500}
501
502//==============================================================================
503//function : ProcessButton3Press
504//purpose : Start Rotation
505//==============================================================================
506
507static void ProcessButton3Press()
508
509{ // Start rotation
510 Start_Rot = 1;
511 ViewerTest::CurrentView()->SetDegenerateModeOn();
512 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
513
514}
515//==============================================================================
516//function : ProcessButtonRelease
517//purpose : Start Rotation
518//==============================================================================
519
520static void ProcessButtonRelease()
521
522{ // End rotation
523#ifdef OCC120
524 if (Start_Rot) {
525 Start_Rot = 0;
526 if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
527 }
528#else
529 Start_Rot = 0;
530 ViewerTest::CurrentView()->SetDegenerateModeOff();
531#endif
532}
533
534//==============================================================================
535//function : ProcessZClipMotion
536//purpose : Zoom
537//==============================================================================
538
539void ProcessZClipMotion()
540{
541 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
542 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
543 static Standard_Real CurZPos = 0.;
544
545 //Quantity_Length VDX, VDY;
546 //a3DView->Size(VDX,VDY);
547 //Standard_Real VDZ = a3DView->ZSize();
548 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
549
550 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
551
552 // Front = Depth + width/2.
553 Standard_Real D = 0.5;
554 Standard_Real W = 0.1;
555
556 CurZPos += (dx);
557
558 D += CurZPos;
559
560 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
561
562 a3DView->SetZClippingType(V3d_OFF);
563 a3DView->SetZClippingDepth(D);
564 a3DView->SetZClippingWidth(W);
565 a3DView->SetZClippingType(V3d_FRONT);
566
567 a3DView->Redraw();
568
569 X_ButtonPress = X_Motion;
570 Y_ButtonPress = Y_Motion;
571 }
572}
573
574//==============================================================================
575//function : ProcessControlButton1Motion
576//purpose : Zoom
577//==============================================================================
578
579static void ProcessControlButton1Motion()
580{
581 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
582
583 X_ButtonPress = X_Motion;
584 Y_ButtonPress = Y_Motion;
585}
586
587//==============================================================================
588//function : ProcessControlButton2Motion
589//purpose : Pann
590//==============================================================================
591
592static void ProcessControlButton2Motion()
593{
594 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
595 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
596
597 dy = -dy; // Xwindow Y axis is from top to Bottom
598
599 ViewerTest::CurrentView()->Panning( dx, dy );
600
601 X_ButtonPress = X_Motion;
602 Y_ButtonPress = Y_Motion;
603}
604
605//==============================================================================
606//function : ProcessControlButton3Motion
607//purpose : Rotation
608//==============================================================================
609
610static void ProcessControlButton3Motion()
611{
612 if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
613}
614
615//==============================================================================
616//function : ProcessPointerMotion
617//purpose : Rotation
618//==============================================================================
619
620static void ProcessMotion()
621{
622 //pre-hilights detected objects at mouse position
623
624 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
625 EM->MoveTo(X_Motion, Y_Motion);
626}
627
628
629void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
630{
631 Xpix = X_Motion;Ypix=Y_Motion;
632}
633
634//==============================================================================
635//function : VAxo
636//purpose : Switch to an Axonometric view
637//Draw arg : No args
638//==============================================================================
639
640static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
641{ if ( ViewerTest::CurrentView().IsNull() ) {
642 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
643 // VInit(di, argc, argv);
644}
645
646ViewerTest::CurrentView()->SetProj(V3d_XposYnegZpos);
647
648return 0;
649}
650
651//==============================================================================
652//function : VTop
653//purpose : Switch to a Top View
654//Draw arg : No args
655//==============================================================================
656
657static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
658{
659
660 if ( ViewerTest::CurrentView().IsNull() ) {
661 di<<"La commande vinit n'a pas ete appele avant"<<"\n";
662
663 // VInit(di, , argv);
664 }
665
666 ViewerTest::CurrentView()->SetProj(V3d_Zpos);
667 return 0;
668
669}
670
671//==============================================================================
672//function : VHelp
673//purpose : Dsiplay help on viewer Keyboead and mouse commands
674//Draw arg : No args
675//==============================================================================
676
677static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
678{
679
680 di << "Q : Quit the application" << "\n";
681
682 di << "========================="<<"\n";
683 di << "F : FitAll" << "\n";
684 di << "T : TopView" << "\n";
685 di << "A : AxonometricView" << "\n";
686 di << "R : ResetView" << "\n";
687
688 di << "========================="<<"\n";
689 di << "S : Shading" << "\n";
690 di << "W : Wireframe" << "\n";
691 di << "H : HidelLineRemoval" << "\n";
692
693 di << "========================="<<"\n";
694 di << "Selection mode "<<"\n";
695 di << "0 : Shape" <<"\n";
696 di << "1 : Vertex" <<"\n";
697 di << "2 : Edge" <<"\n";
698 di << "3 : Wire" <<"\n";
699 di << "4 : Face" <<"\n";
700 di << "5 : Shell" <<"\n";
701 di << "6 : Solid" <<"\n";
702 di << "7 : Compound" <<"\n";
703
704 di << "=========================="<<"\n";
705 di << "D : Remove Selected Object"<<"\n";
706 di << "=========================="<<"\n";
707
708 return 0;
709}
710
711Standard_Boolean IsDragged = Standard_False;
712
713Standard_Integer xx1, yy1, xx2, yy2;
714//the first and last point in viewer co-ordinates
715
716Standard_Boolean DragFirst;
717
718
719#ifdef WNT
720
721static Standard_Boolean Ppick = 0;
722static Standard_Integer Pargc = 0;
723static const char** Pargv = NULL;
724
725
726static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
727 UINT Msg,
728 WPARAM wParam,
729 LPARAM lParam )
730{
731 if ( !ViewerTest::CurrentView().IsNull() ) {
732
733 WPARAM fwKeys = wParam;
734
735 switch( Msg ) {
736
737 case WM_LBUTTONUP:
738 IsDragged = Standard_False;
739 if( !DragFirst )
740 {
741 HDC hdc = GetDC( hwnd );
742 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
743 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
744 SetROP2( hdc, R2_NOT );
745 Rectangle( hdc, xx1, yy1, xx2, yy2 );
746 ReleaseDC( hwnd, hdc );
747
748 const Handle(ViewerTest_EventManager) EM =
749 ViewerTest::CurrentEventManager();
750 if ( fwKeys & MK_SHIFT )
751 EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
752 max( xx1, xx2 ), min( yy1, yy2 ));
753 else
754 EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
755 max( xx1, xx2 ), min( yy1, yy2 ));
756 }
757 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
758
759 case WM_LBUTTONDOWN:
760 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
761 {
762 IsDragged = Standard_True;
763 DragFirst = Standard_True;
764 xx1 = LOWORD(lParam);
765 yy1 = HIWORD(lParam);
766 }
767 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
768
769 break;
770
771 case WM_MOUSEMOVE:
772 if( IsDragged )
773 {
774 HDC hdc = GetDC( hwnd );
775
776 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
777 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
778 SetROP2( hdc, R2_NOT );
779
780 if( !DragFirst )
781 Rectangle( hdc, xx1, yy1, xx2, yy2 );
782
783 DragFirst = Standard_False;
784 xx2 = LOWORD(lParam);
785 yy2 = HIWORD(lParam);
786
787 Rectangle( hdc, xx1, yy1, xx2, yy2 );
788
789 SelectObject( hdc, anObj );
790
791 ReleaseDC( hwnd, hdc );
792 }
793 else
794 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
795 break;
796
797 default:
798 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
799 }
800 return 0;
801 }
802 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
803}
804
805
806static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
807 UINT Msg,
808 WPARAM wParam,
809 LPARAM lParam )
810{
811 /*static Standard_Boolean Ppick = 0;
812 static Standard_Integer Pargc = 0;
813 static char** Pargv = NULL;*/
814
815 static int Up = 1;
816
817 if ( !ViewerTest::CurrentView().IsNull() ) {
818 PAINTSTRUCT ps;
819
820 switch( Msg ) {
821 case WM_CLOSE:
822 // do not destroy the window - just hide it!
823 VT_GetWindow()->Unmap();
824 return 0;
825 case WM_PAINT:
826 //cout << "\t WM_PAINT" << endl;
827 BeginPaint(hwnd, &ps);
828 EndPaint(hwnd, &ps);
829 ProcessExpose();
830 break;
831
832 case WM_SIZE:
833 //cout << "\t WM_SIZE" << endl;
834 ProcessConfigure();
835 break;
836
837 case WM_KEYDOWN:
838 //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
839
840 if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
841 char c[2];
842 c[0] = (char) wParam;
843 c[1] = '\0';
844 ProcessKeyPress( c);
845 }
846 break;
847
848 case WM_LBUTTONUP:
849 case WM_MBUTTONUP:
850 case WM_RBUTTONUP:
851 //cout << "\t WM_xBUTTONUP" << endl;
852 Up = 1;
853 ProcessButtonRelease();
854 break;
855
856 case WM_LBUTTONDOWN:
857 case WM_MBUTTONDOWN:
858 case WM_RBUTTONDOWN:
859 {
860 //cout << "\t WM_xBUTTONDOWN" << endl;
861 WPARAM fwKeys = wParam;
862
863 Up = 0;
864
865 X_ButtonPress = LOWORD(lParam);
866 Y_ButtonPress = HIWORD(lParam);
867
868 if ( Msg == WM_LBUTTONDOWN) {
869 if(fwKeys & MK_CONTROL) {
870 Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
871 } else
872 ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
873 }
874 else if ( Msg == WM_RBUTTONDOWN ) {
875 // Start rotation
876 ProcessButton3Press( );
877 }
878 }
879 break;
880
881 case WM_MOUSEMOVE:
882 {
883 //cout << "\t WM_MOUSEMOVE" << endl;
884 WPARAM fwKeys = wParam;
885 X_Motion = LOWORD(lParam);
886 Y_Motion = HIWORD(lParam);
887
888 if ( Up &&
889 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
890 Up = 0;
891 X_ButtonPress = LOWORD(lParam);
892 Y_ButtonPress = HIWORD(lParam);
893
894 if ( fwKeys & MK_RBUTTON ) {
895 // Start rotation
896 ProcessButton3Press();
897 }
898 }
899
900 if ( fwKeys & MK_CONTROL ) {
901 if ( fwKeys & MK_LBUTTON ) {
902 ProcessControlButton1Motion();
903 }
904 else if ( fwKeys & MK_MBUTTON ||
905 ((fwKeys&MK_LBUTTON) &&
906 (fwKeys&MK_RBUTTON) ) ){
907 ProcessControlButton2Motion();
908 }
909 else if ( fwKeys & MK_RBUTTON ) {
910 ProcessControlButton3Motion();
911 }
912 }
913#ifdef BUG
914 else if ( fwKeys & MK_SHIFT ) {
915 if ( fwKeys & MK_MBUTTON ||
916 ((fwKeys&MK_LBUTTON) &&
917 (fwKeys&MK_RBUTTON) ) ) {
918 cout << "ProcessZClipMotion()" << endl;
919 ProcessZClipMotion();
920 }
921 }
922#endif
923 else
924 if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
925 ProcessZClipMotion();
926 }
927 else {
928 ProcessMotion();
929 }
930 }
931 break;
932
933 default:
934 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
935 }
936 return 0L;
937 }
938
939 return DefWindowProc( hwnd, Msg, wParam, lParam );
940}
941
942
943
944
945//==============================================================================
946//function : ViewerMainLoop
947//purpose : Get a Event on the view and dispatch it
948//==============================================================================
949
950
951static int ViewerMainLoop(Standard_Integer argc, const char** argv)
952{
953
954 //cout << "No yet implemented on WNT" << endl;
955 /*static Standard_Boolean Ppick = 0;
956 static Standard_Integer Pargc = 0;
957 static char** Pargv = NULL;*/
958
959 //Ppick = (argc > 0)? -1 : 0;
960 Ppick = (argc > 0)? 1 : 0;
961 Pargc = argc;
962 Pargv = argv;
963
964 if ( Ppick ) {
965 MSG msg;
966 msg.wParam = 1;
967
968 cout << "Start picking" << endl;
969
970 //while ( Ppick == -1 ) {
971 while ( Ppick == 1 ) {
972 // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
973 if (GetMessage(&msg, NULL, 0, 0) ) {
974 TranslateMessage(&msg);
975 DispatchMessage(&msg);
976 }
977 }
978
979 cout << "Picking done" << endl;
980 }
981
982 return Ppick;
983}
984
985
986#else
987
988int min( int a, int b )
989{
990 if( a<b )
991 return a;
992 else
993 return b;
994}
995
996int max( int a, int b )
997{
998 if( a>b )
999 return a;
1000 else
1001 return b;
1002}
1003
1004int ViewerMainLoop(Standard_Integer argc, const char** argv)
1005
1006{ Standard_Boolean pick = argc > 0;
1007
1008// X11 Event loop
1009
1010static XEvent report;
1011
1012XNextEvent( display, &report );
1013// cout << "rep type = " << report.type << endl;
1014// cout << "rep button = " << report.xbutton.button << endl;
1015
1016switch ( report.type ) {
1017 case Expose:
1018 {
1019 ProcessExpose();
1020 }
1021 break;
1022 case ConfigureNotify:
1023 {
1024 ProcessConfigure();
1025 }
1026 break;
1027 case KeyPress:
1028 {
1029
1030 KeySym ks_ret ;
1031 char buf_ret[11] ;
1032 int ret_len ;
1033 XComposeStatus status_in_out;
1034
1035 ret_len = XLookupString( ( XKeyEvent *)&report ,
1036 (char *) buf_ret , 10 ,
1037 &ks_ret , &status_in_out ) ;
1038
1039
1040 buf_ret[ret_len] = '\0' ;
1041
1042 if ( ret_len ) {
1043 ProcessKeyPress( buf_ret);
1044 }
1045 }
1046 break;
1047 case ButtonPress:
1048 // cout << "ButtonPress" << endl;
1049 {
1050 X_ButtonPress = report.xbutton.x;
1051 Y_ButtonPress = report.xbutton.y;
1052
1053 if ( report.xbutton.button == Button1 )
1054 if( report.xbutton.state & ControlMask )
1055 pick = ProcessButton1Press( argc, argv, pick,
1056 ( report.xbutton.state & ShiftMask) );
1057 else
1058 {
1059 IsDragged = Standard_True;
1060 xx1 = X_ButtonPress;
1061 yy1 = Y_ButtonPress;
1062 DragFirst = Standard_True;
1063 }
1064 else if ( report.xbutton.button == Button3 )
1065 // Start rotation
1066 ProcessButton3Press();
1067 }
1068 break;
1069 case ButtonRelease:
1070 {
1071 // cout<<"relachement du bouton "<<(report.xbutton.button==3 ? "3": "on s'en fout") <<endl;
1072 // cout << IsDragged << endl;
1073 // cout << DragFirst << endl;
1074
1075 if( IsDragged )
1076 {
1077 if( !DragFirst )
1078 {
1079 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1080 GC gc = XCreateGC( display, aWindow, 0, 0 );
1081 // XSetFunction( display, gc, GXinvert );
1082 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1083 }
1084
1085 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1086 if( aContext.IsNull() )
1087 {
1088 cout << "The context is null. Please use vinit before createmesh" << endl;
1089 return 0;
1090 }
1091
1092 Standard_Boolean ShiftPressed = ( report.xbutton.state & ShiftMask );
1093 if( report.xbutton.button==1 )
1094 if( DragFirst )
1095 if( ShiftPressed )
1096 {
1097 aContext->ShiftSelect();
1098 // cout << "shift select" << endl;
1099 }
1100 else
1101 {
1102 aContext->Select();
1103 // cout << "select" << endl;
1104 }
1105 else
1106 if( ShiftPressed )
1107 {
1108 aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
1109 max( xx1, xx2 ), max( yy1, yy2 ),
1110 ViewerTest::CurrentView());
1111 // cout << "shift select" << endl;
1112 }
1113 else
1114 {
1115 aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
1116 max( xx1, xx2 ), max( yy1, yy2 ),
1117 ViewerTest::CurrentView() );
1118 // cout << "select" << endl;
1119 }
1120 else
1121 ProcessButtonRelease();
1122
1123 IsDragged = Standard_False;
1124 }
1125 else
1126 ProcessButtonRelease();
1127 }
1128 break;
1129 case MotionNotify:
1130 {
1131 // XEvent dummy;
1132
1133 X_Motion = report.xmotion.x;
1134 Y_Motion = report.xmotion.y;
1135
1136 if( IsDragged )
1137 {
1138 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
1139 GC gc = XCreateGC( display, aWindow, 0, 0 );
1140 XSetFunction( display, gc, GXinvert );
1141
1142 if( !DragFirst )
1143 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1144
1145 xx2 = X_Motion;
1146 yy2 = Y_Motion;
1147 DragFirst = Standard_False;
1148
1149 //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
1150 XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
1151 }
1152 else
1153 {
1154
1155 //cout << "MotionNotify " << X_Motion << "," << Y_Motion << endl;
1156
1157 // remove all the ButtonMotionMask
1158 while( XCheckMaskEvent( display, ButtonMotionMask, &report) ) ;
1159
1160 if ( ZClipIsOn && report.xmotion.state & ShiftMask ) {
1161 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1162
1163 Quantity_Length VDX, VDY;
1164
1165 ViewerTest::CurrentView()->Size(VDX,VDY);
1166 Standard_Real VDZ =0 ;
1167 VDZ = ViewerTest::CurrentView()->ZSize();
1168
1169 // printf("%lf,%lf,%lf\n", VDX, VDY, VDZ);
1170 printf("%f,%f,%f\n", VDX, VDY, VDZ);
1171
1172 Quantity_Length dx = 0 ;
1173 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1174
1175 cout << dx << endl;
1176
1177 dx = dx / VDX * VDZ;
1178
1179 cout << dx << endl;
1180
1181 // Front = Depth + width/2.
1182 //ViewerTest::CurrentView()->SetZClippingDepth(dx);
1183 //ViewerTest::CurrentView()->SetZClippingWidth(0.);
1184
1185 ViewerTest::CurrentView()->Redraw();
1186 }
1187 }
1188
1189 if ( report.xmotion.state & ControlMask ) {
1190 if ( report.xmotion.state & Button1Mask ) {
1191 ProcessControlButton1Motion();
1192 }
1193 else if ( report.xmotion.state & Button2Mask ) {
1194 ProcessControlButton2Motion();
1195 }
1196 else if ( report.xmotion.state & Button3Mask ) {
1197 ProcessControlButton3Motion();
1198 }
1199 }
1200 else {
1201 ProcessMotion();
1202 }
1203 }
1204 }
1205 break;
1206}
1207
1208
1209return pick;
1210}
1211
1212//==============================================================================
1213//function : VProcessEvents
1214//purpose : call by Tk_CreateFileHandler() to be able to manage the
1215// event in the Viewer window
1216//==============================================================================
1217
1218static void VProcessEvents(ClientData,int)
1219{
1220 //cout << "VProcessEvents" << endl;
1221
1222 // test for X Event
1223 while (XPending(display)) {
1224 ViewerMainLoop( 0, NULL);
1225 }
1226}
1227#endif
1228
1229//==============================================================================
1230//function : OSWindowSetup
1231//purpose : Setup for the X11 window to be able to cath the event
1232//==============================================================================
1233
1234
1235static void OSWindowSetup()
1236{
1237#ifndef WNT
1238 // X11
1239
1240 Window window = VT_GetWindow()->XWindow();
1241
1242 Standard_Address theDisplay = GetG3dDevice()->XDisplay();
1243 display = (Display * ) theDisplay;
1244 // display = (Display *)GetG3dDevice()->XDisplay();
1245
1246 XSynchronize(display, 1);
1247
1248 VT_GetWindow()->Map();
1249
1250 // X11 : For keyboard on SUN
1251 XWMHints wmhints;
1252 wmhints.flags = InputHint;
1253 wmhints.input = 1;
1254
1255 XSetWMHints( display, window, &wmhints);
1256
1257 XSelectInput( display, window, ExposureMask | KeyPressMask |
1258 ButtonPressMask | ButtonReleaseMask |
1259 StructureNotifyMask |
1260 PointerMotionMask |
1261 Button1MotionMask | Button2MotionMask |
1262 Button3MotionMask
1263 );
1264
1265 XSynchronize(display, 0);
1266
1267#else
1268 // WNT
1269#endif
1270
1271}
1272
1273
1274//==============================================================================
1275//function : VFit
1276
1277//purpose : Fitall, no DRAW arguments
1278//Draw arg : No args
1279//==============================================================================
1280
1281static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
1282{
1283 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1284 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
1285 if (V.IsNull() == Standard_False) {
1286 V->FitAll3d();
1287 } else if (aView.IsNull() == Standard_False) {
1288 aView->FitAll();
1289 }
1290 return 0;
1291}
1292
1293//==============================================================================
1294//function : VZFit
1295//purpose : ZFitall, no DRAW arguments
1296//Draw arg : No args
1297//==============================================================================
1298
1299static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
1300{
1301 Handle(V3d_View) V = ViewerTest::CurrentView();
1302 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
1303
1304
1305static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
1306{
1307 Handle(V3d_View) V = ViewerTest::CurrentView();
1308 if ( !V.IsNull() ) V->Redraw(); return 0;
1309}
1310
1311
1312//==============================================================================
1313//function : VClear
1314//purpose : Remove all the object from the viewer
1315//Draw arg : No args
1316//==============================================================================
1317
1318static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
1319{
1320 Handle(V3d_View) V = ViewerTest::CurrentView();
1321 if(!V.IsNull())
1322 ViewerTest::Clear();
1323 return 0;
1324}
1325
1326//==============================================================================
1327//function : VPick
1328//purpose :
1329//==============================================================================
1330
1331static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1332{ if (ViewerTest::CurrentView().IsNull() ) return 1;
1333
1334if ( argc < 4 ) {
1335 di << argv[0] << "Invalid number of arguments" << "\n";
1336 return 1;
1337}
1338
1339while (ViewerMainLoop( argc, argv)) {
1340}
1341
1342return 0;
1343}
1344
1345
1346
1347//==============================================================================
1348//function : InitViewerTest
1349//purpose : initialisation de toutes les variables static de ViewerTest (dp)
1350//==============================================================================
1351
1352void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
1353{
1354 Handle(V3d_Viewer) viewer = context->CurrentViewer();
1355 ViewerTest::SetAISContext(context);
1356 viewer->InitActiveViews();
1357 Handle(V3d_View) view = viewer->ActiveView();
1358 if (viewer->MoreActiveViews()) ViewerTest::CurrentView(view);
1359 ViewerTest::ResetEventManager();
1360 Handle(Aspect_GraphicDevice) device = viewer->Device();
1361 Handle(Aspect_Window) window = view->Window();
1362#ifndef WNT
1363 // X11
1364 VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
1365 GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
1366 OSWindowSetup();
1367 static int first = 1;
1368 if ( first ) {
1369#if TCL_MAJOR_VERSION < 8
1370 Tk_CreateFileHandler((void*)ConnectionNumber(display),
1371 TK_READABLE, VProcessEvents, (ClientData) 0);
1372#else
1373 Tk_CreateFileHandler(ConnectionNumber(display),
1374 TK_READABLE, VProcessEvents, (ClientData) 0);
1375#endif
1376 first = 0;
1377 }
1378#endif
1379}
1380
1381
1382//==============================================================================
1383//function : VSetBg
1384//purpose : Load image as background
1385//==============================================================================
1386
1387static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1388{
1389 if (argc < 2 || argc > 3)
1390 {
1391 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
f8b2ed36 1392 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
7fd59977 1393 return 1;
1394 }
1395
1396 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1397 if(AISContext.IsNull())
1398 {
1399 di << "use 'vinit' command before " << argv[0] << "\n";
1400 return 1;
1401 }
1402
1403 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
1404 if (argc == 3)
1405 {
1406 const char* szType = argv[2];
1407 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1408 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1409 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1410 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1411 else
1412 {
1413 di << "Wrong fill type : " << szType << "\n";
1414 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1415 return 1;
1416 }
1417 }
1418
1419 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1420 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
1421
1422 return 0;
1423}
1424
f8b2ed36 1425//==============================================================================
1426//function : VSetBgMode
1427//purpose : Change background image fill type
1428//==============================================================================
1429
1430static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1431{
1432 if (argc != 2)
1433 {
1434 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
1435 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1436 return 1;
1437 }
1438
1439 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1440 if(AISContext.IsNull())
1441 {
1442 di << "use 'vinit' command before " << argv[0] << "\n";
1443 return 1;
1444 }
1445
1446 Aspect_FillMethod aFillType;
1447 if (argc == 2)
1448 {
1449 const char* szType = argv[1];
1450 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
1451 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
1452 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
1453 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
1454 else
1455 {
1456 di << "Wrong fill type : " << szType << "\n";
1457 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
1458 return 1;
1459 }
1460 }
1461
1462 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1463 V3dView->SetBgImageStyle(aFillType, Standard_True);
1464
1465 return 0;
1466}
1467
7fd59977 1468//==============================================================================
1469//function : VSetGradientBg
1470//purpose : Mount gradient background
1471//==============================================================================
1472static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1473{
1474 if (argc != 8 )
1475 {
1476 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
1477 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
1478 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1479 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1480 return 1;
1481 }
1482
1483 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1484 if(AISContext.IsNull())
1485 {
1486 di << "use 'vinit' command before " << argv[0] << "\n";
1487 return 1;
1488 }
1489 if (argc == 8)
1490 {
1491
1492 Standard_Real R1 = atof(argv[1])/255.;
1493 Standard_Real G1 = atof(argv[2])/255.;
1494 Standard_Real B1 = atof(argv[3])/255.;
1495 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
1496
1497 Standard_Real R2 = atof(argv[4])/255.;
1498 Standard_Real G2 = atof(argv[5])/255.;
1499 Standard_Real B2 = atof(argv[6])/255.;
1500
1501 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
1502 int aType = atoi(argv[7]);
1503 if( aType < 0 || aType > 8 )
1504 {
1505 di << "Wrong fill type " << "\n";
1506 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1507 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1508 return 1;
1509 }
1510
1511 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1512
1513 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1514 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
1515 }
1516
1517 return 0;
1518}
1519
f8b2ed36 1520//==============================================================================
1521//function : VSetGradientBgMode
1522//purpose : Change gradient background fill style
1523//==============================================================================
1524static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1525{
1526 if (argc != 2 )
1527 {
1528 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
1529 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1530 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1531 return 1;
1532 }
1533
1534 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1535 if(AISContext.IsNull())
1536 {
1537 di << "use 'vinit' command before " << argv[0] << "\n";
1538 return 1;
1539 }
1540 if (argc == 2)
1541 {
1542 int aType = atoi(argv[1]);
1543 if( aType < 0 || aType > 8 )
1544 {
1545 di << "Wrong fill type " << "\n";
1546 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
1547 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
1548 return 1;
1549 }
1550
1551 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
1552
1553 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1554 V3dView->SetBgGradientStyle( aMethod, 1 );
1555 }
1556
1557 return 0;
1558}
1559
1560//==============================================================================
1561//function : VSetColorBg
1562//purpose : Set color background
1563//==============================================================================
1564static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1565{
1566 if (argc != 4 )
1567 {
1568 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
1569 di << "R,G,B = [0..255]" << "\n";
1570 return 1;
1571 }
1572
1573 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
1574 if(AISContext.IsNull())
1575 {
1576 di << "use 'vinit' command before " << argv[0] << "\n";
1577 return 1;
1578 }
1579 if (argc == 4)
1580 {
1581
1582 Standard_Real R = atof(argv[1])/255.;
1583 Standard_Real G = atof(argv[2])/255.;
1584 Standard_Real B = atof(argv[3])/255.;
1585 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
1586
1587 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1588 V3dView->SetBackgroundColor( aColor );
1589 V3dView->Update();
1590 }
1591
1592 return 0;
1593}
1594
7fd59977 1595//==============================================================================
1596//function : VScale
1597//purpose : View Scaling
1598//==============================================================================
1599
1600static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1601{
1602 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1603 if ( V3dView.IsNull() ) return 1;
1604
1605 if ( argc != 4 ) {
1606 di << argv[0] << "Invalid number of arguments" << "\n";
1607 return 1;
1608 }
1609 V3dView->SetAxialScale( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1610 return 0;
1611}
1612//==============================================================================
1613//function : VTestZBuffTrihedron
1614//purpose : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view
1615//==============================================================================
1616
1617static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1618{
1619 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1620 if ( V3dView.IsNull() ) return 1;
1621
1622 // Set up default trihedron parameters
1623 V3dView->ZBufferTriedronSetup();
1624 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
1625 V3dView->ZFitAll();
1626 return 0;
1627}
1628
1629//==============================================================================
1630//function : VRotate
1631//purpose : Camera Rotating
1632//==============================================================================
1633
1634static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1635 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1636 if ( V3dView.IsNull() ) {
1637 return 1;
1638 }
1639
1640 if ( argc == 4 ) {
1641 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]) );
1642 return 0;
1643 } else if ( argc == 7 ) {
1644 V3dView->Rotate( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]), atof(argv[6]) );
1645 return 0;
1646 } else {
1647 di << argv[0] << " Invalid number of arguments" << "\n";
1648 return 1;
1649 }
1650}
1651
1652//==============================================================================
1653//function : VZoom
1654//purpose : View zoom in / out (relative to current zoom)
1655//==============================================================================
1656
1657static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1658 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1659 if ( V3dView.IsNull() ) {
1660 return 1;
1661 }
1662
1663 if ( argc == 2 ) {
1664 Standard_Real coef = atof(argv[1]);
1665 if ( coef <= 0.0 ) {
1666 di << argv[1] << "Invalid value" << "\n";
1667 return 1;
1668 }
1669 V3dView->SetZoom( atof(argv[1]) );
1670 return 0;
1671 } else {
1672 di << argv[0] << " Invalid number of arguments" << "\n";
1673 return 1;
1674 }
1675}
1676
1677//==============================================================================
1678//function : VPan
1679//purpose : View panning (in pixels)
1680//==============================================================================
1681
1682static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
1683 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
1684 if ( V3dView.IsNull() ) return 1;
1685
1686 if ( argc == 3 ) {
1687 V3dView->Pan( atoi(argv[1]), atoi(argv[2]) );
1688 return 0;
1689 } else {
1690 di << argv[0] << " Invalid number of arguments" << "\n";
1691 return 1;
1692 }
1693}
1694
1695
1696//==============================================================================
1697//function : VExport
5cedc27f 1698//purpose : Export the view to a vector graphic format (PS, EMF, PDF)
7fd59977 1699//==============================================================================
1700
1701static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1702{
1703 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
5cedc27f
K
1704 if (V3dView.IsNull())
1705 return 1;
7fd59977 1706
5cedc27f
K
1707 if (argc == 1)
1708 {
1709 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
7fd59977 1710 return 1;
1711 }
1712
5cedc27f
K
1713 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
1714 TCollection_AsciiString aFormatStr;
1715
1716 TCollection_AsciiString aFileName (argv[1]);
1717 Standard_Integer aLen = aFileName.Length();
1718
1719 if (argc > 2)
1720 {
1721 aFormatStr = TCollection_AsciiString (argv[2]);
1722 }
1723 else if (aLen >= 4)
1724 {
1725 if (aFileName.Value (aLen - 2) == '.')
1726 {
1727 aFormatStr = aFileName.SubString (aLen - 1, aLen);
1728 }
1729 else if (aFileName.Value (aLen - 3) == '.')
1730 {
1731 aFormatStr = aFileName.SubString (aLen - 2, aLen);
1732 }
1733 else
1734 {
1735 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1736 return 1;
1737 }
1738 }
1739 else
1740 {
1741 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
1742 return 1;
1743 }
1744
1745 aFormatStr.UpperCase();
1746 if (aFormatStr == "PS")
1747 anExpFormat = Graphic3d_EF_PostScript;
1748 else if (aFormatStr == "EPS")
1749 anExpFormat = Graphic3d_EF_EnhPostScript;
1750 else if (aFormatStr == "TEX")
1751 anExpFormat = Graphic3d_EF_TEX;
1752 else if (aFormatStr == "PDF")
1753 anExpFormat = Graphic3d_EF_PDF;
1754 else if (aFormatStr == "SVG")
1755 anExpFormat = Graphic3d_EF_SVG;
1756 else if (aFormatStr == "PGF")
1757 anExpFormat = Graphic3d_EF_PGF;
1758 else if (aFormatStr == "EMF")
1759 anExpFormat = Graphic3d_EF_EMF;
1760 else
1761 {
1762 std::cout << "Invalid export format '" << aFormatStr << "'\n";
1763 return 1;
1764 }
1765
1766 if (!V3dView->View()->Export (argv[1], anExpFormat))
1767 {
1768 std::cout << "Export failed!\n";
1769 return 1;
1770 }
7fd59977 1771 return 0;
1772}
1773
1774//==============================================================================
1775//function : VColorScale
1776//purpose : representation color scale
1777//==============================================================================
1778#include <V3d_ColorScale.hxx>
1779
1780static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
1781{
1782 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
1783 {
1784 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
1785 return 1;
1786 }
1787
1788 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1789 if(aContext.IsNull()) {
1790 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
1791 return -1;
1792 }
1793
1794 Standard_Real minRange = 0. , maxRange = 100. ;
1795
1796 Standard_Integer numIntervals = 10 ;
1797 Standard_Real textHeight = 16. ;
1798 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
1799 Standard_Real X = 0., Y = 0. ;
1800
1801 if ( argc < 9 )
1802 {
1803 if( argc > 3 )
1804 {
1805 minRange = atof( argv[1] );
1806 maxRange = atof( argv[2] );
1807 numIntervals = atoi( argv[3] );
1808 }
1809 if ( argc > 4 )
1810 textHeight = atof( argv[4] );
1811 if ( argc > 5 )
1812 position = (Aspect_TypeOfColorScalePosition)atoi( argv[5] );
1813 if ( argc > 7 )
1814 {
1815 X = atof( argv[6] );
1816 Y = atof( argv[7] );
1817 }
1818 }
1819 Handle(V3d_View) curView = ViewerTest::CurrentView( );
1820 if ( curView.IsNull( ) )
1821 return 1;
1822 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
1823 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
1824 if( ! aCS.IsNull( ) )
1825 {
1826 aCS->SetPosition( X , Y );
1827 aCS->SetHeight( 0.95) ;
1828 aCS->SetTextHeight( textHeight );
1829 aCS->SetRange( minRange , maxRange );
1830 aCS->SetNumberOfIntervals( numIntervals );
1831 aCS->SetLabelPosition( position );
1832 if( !curView->ColorScaleIsDisplayed() )
1833 curView->ColorScaleDisplay( );
1834 }
1835 return 0;
1836}
1837
1838//==============================================================================
1839//function : VGraduatedTrihedron
1840//purpose : Displays a graduated trihedron
1841//==============================================================================
13a22457
S
1842
1843static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
1844{
1845 const char *str = arg;
1846 while (*str)
1847 {
1848 unsigned short c1 = *str++;
1849 unsigned short c2 = *str++;
1850 if (!c1 || !c2) break;
1851 name += (Standard_ExtCharacter)((c1 << 8) | c2);
1852 }
1853}
1854
7fd59977 1855static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1856{
13a22457
S
1857 // Check arguments
1858 if (argc != 2 && argc < 5)
1859 {
1860 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
1861 di<<"Usage: type help "<<argv[0]<<"\n";
1862 return 1; //TCL_ERROR
1863 }
7fd59977 1864
13a22457
S
1865 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
1866
1867 // Create 3D view if it doesn't exist
1868 if ( aV3dView.IsNull() )
7fd59977 1869 {
13a22457
S
1870 ViewerTest::ViewerInit();
1871 aV3dView = ViewerTest::CurrentView();
1872 if( aV3dView.IsNull() )
1873 {
1874 di << "Error: Cannot create a 3D view\n";
1875 return 1; //TCL_ERROR
1876 }
7fd59977 1877 }
1878
13a22457
S
1879 // Erase (==0) or display (!=0)
1880 const int display = atoi(argv[1]);
7fd59977 1881
13a22457 1882 if (display)
7fd59977 1883 {
13a22457
S
1884 // Text font
1885 TCollection_AsciiString font;
1886 if (argc < 6)
1887 font.AssignCat("Courier");
1888 else
1889 font.AssignCat(argv[5]);
1890
1891 // Text is multibyte
1892 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (atoi(argv[6]) != 0);
1893
1894 // Set axis names
1895 TCollection_ExtendedString xname, yname, zname;
1896 if (argc >= 5)
1897 {
1898 if (isMultibyte)
7fd59977 1899 {
13a22457
S
1900 AddMultibyteString(xname, argv[2]);
1901 AddMultibyteString(yname, argv[3]);
1902 AddMultibyteString(zname, argv[4]);
7fd59977 1903 }
13a22457
S
1904 else
1905 {
1906 xname += argv[2];
1907 yname += argv[3];
1908 zname += argv[4];
1909 }
1910 }
1911 else
1912 {
1913 xname += "X (mm)";
1914 yname += "Y (mm)";
1915 zname += "Z (mm)";
1916 }
7fd59977 1917
13a22457
S
1918 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
1919 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
1920 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
1921 Standard_True/*drawgrid*/,
1922 Standard_True/*drawaxes*/,
1923 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
1924 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
1925 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
1926 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
1927 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
1928 Quantity_NOC_WHITE/*gridcolor*/,
1929 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
1930 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
1931 }
7fd59977 1932 else
13a22457 1933 aV3dView->GraduatedTrihedronErase();
7fd59977 1934
1935 ViewerTest::GetAISContext()->UpdateCurrentViewer();
13a22457
S
1936 aV3dView->Redraw();
1937
7fd59977 1938 return 0;
1939}
1940
7edf74fd
A
1941//==============================================================================
1942//function : VPrintView
1943//purpose : Test printing algorithm, print the view to image file with given
1944// width and height. Printing implemented only for WNT.
1945//==============================================================================
1946static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
1947 const char** argv)
1948{
1949#ifndef WNT
1950 di << "Printing implemented only for wnt!\n";
1951 return 1;
1952#else
1953
1954 Handle(AIS_InteractiveContext) aContextAIS = NULL;
1955 Handle(V3d_View) aView = NULL;
1956 aContextAIS = ViewerTest::GetAISContext();
1957 if (!aContextAIS.IsNull())
1958 {
1959 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
1960 Vwr->InitActiveViews();
1961 if(Vwr->MoreActiveViews())
1962 aView = Vwr->ActiveView();
1963 }
1964
1965 // check for errors
1966 if (aView.IsNull())
1967 {
1968 di << "Call vinit before!\n";
1969 return 1;
1970 }
1971 else if (argc < 4)
1972 {
1973 di << "Use: " << argv[0];
1974 di << " width height filename [print algo=0]\n";
1975 di << "width, height of the intermediate buffer for operation\n";
1976 di << "algo : {0|1}\n";
1977 di << " 0 - stretch algorithm\n";
1978 di << " 1 - tile algorithm\n";
1979 di << "test printing algorithms into an intermediate buffer\n";
1980 di << "with saving output to an image file\n";
1981 return 1;
1982 }
1983
1984 // get the input params
1985 Standard_Integer aWidth = atoi (argv[1]);
1986 Standard_Integer aHeight = atoi (argv[2]);
1987 Standard_Integer aMode = 0;
1988 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
1989 if (argc==5)
1990 aMode = atoi (argv[4]);
1991
1992 // check the input parameters
1993 if (aWidth <= 0 || aHeight <= 0)
1994 {
1995 di << "Width and height must be positive values!\n";
1996 return 1;
1997 }
1998 if (aMode != 0 && aMode != 1)
1999 aMode = 0;
2000
2001 Image_CRawBufferData aRawBuffer;
2002 HDC anDC = CreateCompatibleDC(0);
2003
2004 // define compatible bitmap
2005 BITMAPINFO aBitmapData;
2006 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
2007 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
2008 aBitmapData.bmiHeader.biWidth = aWidth ;
2009 aBitmapData.bmiHeader.biHeight = aHeight;
2010 aBitmapData.bmiHeader.biPlanes = 1;
2011 aBitmapData.bmiHeader.biBitCount = 24;
2012 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
2013 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
2014 aBitmapData.bmiHeader.biClrUsed = 0;
2015 aBitmapData.bmiHeader.biClrImportant = 0;
2016 aBitmapData.bmiHeader.biCompression = BI_RGB;
2017 aBitmapData.bmiHeader.biSizeImage = 0;
2018
2019 // Create Device Independent Bitmap
2020 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
2021 &aRawBuffer.dataPtr, NULL, 0);
2022 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
2023
2024 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
2025 if (aRawBuffer.dataPtr != 0)
2026 {
2027 if (aMode == 0)
2028 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
2029 else
2030 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
2031
2032 // succesfully printed into an intermediate buffer
2033 if (isPrinted)
2034 {
2035 Handle(Image_PixMap) anImageBitmap =
2036 new Image_PixMap ((Standard_PByte)aRawBuffer.dataPtr,
2037 aWidth, aHeight,
2038 aWidth*3 + aWidth%4, 24, 0);
2039 isSaved = anImageBitmap->Dump(aFileName.ToCString());
2040 }
2041 else
2042 {
2043 di << "Print operation failed due to printing errors or\n";
2044 di << "insufficient memory available\n";
2045 di << "Please, try to use smaller dimensions for this test\n";
2046 di << "command, as it allocates intermediate buffer for storing\n";
2047 di << "the result\n";
2048 }
2049 }
2050 else
2051 {
2052 di << "Can't allocate memory for intermediate buffer\n";
2053 di << "Please use smaller dimensions\n";
2054 }
2055
2056 if (aMemoryBitmap)
2057 {
2058 SelectObject (anDC, anOldBitmap);
2059 DeleteObject (aMemoryBitmap);
2060 DeleteDC(anDC);
2061 }
2062
2063 if (!isSaved)
2064 {
2065 di << "Save to file operation failed. This operation may fail\n";
2066 di << "if you don't have enough available memory, then you can\n";
2067 di << "use smaller dimensions for the output file\n";
2068 return 1;
2069 }
2070
2071 return 0;
2072
2073#endif
2074}
2075
59f45b7c 2076//==============================================================================
2077//function : VZLayer
2078//purpose : Test z layer operations for v3d viewer
2079//==============================================================================
2080static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2081{
2082 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
2083 if (aContextAIS.IsNull())
2084 {
2085 di << "Call vinit before!\n";
2086 return 1;
2087 }
2088 else if (argc < 2)
2089 {
2090 di << "Use: vzlayer " << argv[0];
2091 di << " add/del/get [id]\n";
2092 di << " add - add new z layer to viewer and print its id\n";
2093 di << " del - del z layer by its id\n";
2094 di << " get - print sequence of z layers in increasing order of their overlay level\n";
2095 di << "id - the layer identificator value defined when removing z layer\n";
2096 return 1;
2097 }
2098
2099 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
2100 if (aViewer.IsNull())
2101 {
2102 di << "No active viewer!\n";
2103 return 1;
2104 }
2105
2106 // perform operation
2107 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
2108 if (anOp == "add")
2109 {
2110 Standard_Integer aNewId;
2111 if (!aViewer->AddZLayer (aNewId))
2112 {
2113 di << "Impossible to add new z layer!\n";
2114 return 1;
2115 }
2116
2117 di << "New z layer added with index: " << aNewId << "\n";
2118 }
2119 else if (anOp == "del")
2120 {
2121 if (argc < 3)
2122 {
2123 di << "Please also provide as argument id of z layer to remove\n";
2124 return 1;
2125 }
2126
2127 Standard_Integer aDelId = atoi (argv[2]);
2128 if (!aViewer->RemoveZLayer (aDelId))
2129 {
2130 di << "Impossible to remove the z layer or invalid id!\n";
2131 return 1;
2132 }
2133
2134 di << "Z layer " << aDelId << " has been removed\n";
2135 }
2136 else if (anOp == "get")
2137 {
2138 TColStd_SequenceOfInteger anIds;
2139 aViewer->GetAllZLayers (anIds);
2140 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
2141 {
2142 di << anIds.Value (aSeqIdx) << " ";
2143 }
2144
2145 di << "\n";
2146 }
2147 else
2148 {
2149 di << "Invalid operation, please use { add / del / get }\n";
2150 return 1;
2151 }
2152
2153 return 0;
2154}
2155
25289ec1 2156DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2157
2158// this class provides a presentation of text item in v3d view under-/overlayer
2159class V3d_TextItem : public Visual3d_LayerItem
2160{
2161public:
2162
2163 // CASCADE RTTI
2164 DEFINE_STANDARD_RTTI(V3d_TextItem)
2165
2166 // constructor
2167 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
2168 const Standard_Real theX1,
2169 const Standard_Real theY1,
2170 const Standard_Real theHeight,
2171 const TCollection_AsciiString& theFontName,
2172 const Quantity_Color& theColor,
2173 const Quantity_Color& theSubtitleColor,
2174 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2175 const Handle(Visual3d_Layer)& theLayer);
2176
2177 // redraw method
2178 Standard_EXPORT void RedrawLayerPrs();
2179
2180private:
2181
2182 Standard_Real myX1;
2183 Standard_Real myY1;
2184 Standard_Real myHeight;
2185 TCollection_AsciiString myText;
2186 TCollection_AsciiString myFontName;
2187 Quantity_Color myColor;
2188 Quantity_Color mySubtitleColor;
2189 Aspect_TypeOfDisplayText myType;
2190 Handle(Visual3d_Layer) myLayer;
2191
2192};
2193
2194IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
2195IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
2196
2197// create and add to display the text item
2198V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
2199 const Standard_Real theX1,
2200 const Standard_Real theY1,
2201 const Standard_Real theHeight,
2202 const TCollection_AsciiString& theFontName,
2203 const Quantity_Color& theColor,
2204 const Quantity_Color& theSubtitleColor,
2205 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
2206 const Handle(Visual3d_Layer)& theLayer)
2207 : myX1 (theX1), myY1 (theY1),
2208 myText (theText),
2209 myHeight (theHeight),
2210 myLayer (theLayer),
2211 myColor (theColor),
2212 mySubtitleColor (theSubtitleColor),
2213 myType (theTypeOfDisplay),
2214 myFontName (theFontName)
2215{
2216 if (!myLayer.IsNull ())
2217 myLayer->AddLayerItem (this);
2218}
2219
2220// render item
2221void V3d_TextItem::RedrawLayerPrs ()
2222{
2223 if (myLayer.IsNull ())
2224 return;
2225
2226 myLayer->SetColor (myColor);
2227 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
2228 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
2229}
2230
20637bd2 2231DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2232
2233// The Visual3d_LayerItem line item for "vlayerline" command
2234// it provides a presentation of line with user-defined
2235// linewidth, linetype and transparency.
2236class V3d_LineItem : public Visual3d_LayerItem
2237{
2238public:
2239 // CASCADE RTTI
2240 DEFINE_STANDARD_RTTI(V3d_LineItem)
2241
2242 // constructor
2243 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2244 Standard_Real X2, Standard_Real Y2,
2245 V3d_LayerMgrPointer theLayerMgr,
2246 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
2247 Standard_Real theWidth = 0.5,
2248 Standard_Real theTransp = 1.0);
2249
2250 // redraw method
2251 Standard_EXPORT void RedrawLayerPrs();
2252
2253private:
2254
2255 Standard_Real myX1, myY1, myX2, myY2;
2256 Standard_Real myWidth;
2257 Standard_Real myTransparency;
2258 Aspect_TypeOfLine myType;
2259 V3d_LayerMgrPointer myLayerMgr;
2260};
2261
2262IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
2263IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
2264
2265// default constructor for line item
2266V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
2267 Standard_Real X2, Standard_Real Y2,
2268 V3d_LayerMgrPointer theLayerMgr,
2269 Aspect_TypeOfLine theType,
2270 Standard_Real theWidth,
2271 Standard_Real theTransp) :
2272 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
2273 myType(theType), myWidth(theWidth), myTransparency(theTransp)
2274{
2275 if (myLayerMgr && myLayerMgr->Overlay())
2276 myLayerMgr->Overlay()->AddLayerItem (this);
2277}
2278
2279// render line
2280void V3d_LineItem::RedrawLayerPrs ()
2281{
2282 Handle (Visual3d_Layer) aOverlay;
2283
2284 if (myLayerMgr)
2285 aOverlay = myLayerMgr->Overlay();
2286
2287 if (!aOverlay.IsNull())
2288 {
2289 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
2290 aOverlay->SetColor(aColor);
2291 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
2292 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
2293 aOverlay->BeginPolyline();
2294 aOverlay->AddVertex(myX1, myY1);
2295 aOverlay->AddVertex(myX2, myY2);
2296 aOverlay->ClosePrimitive();
2297 }
2298}
2299
2300//=============================================================================
2301//function : VLayerLine
2302//purpose : Draws line in the v3d view layer with given attributes: linetype,
2303// : linewidth, transparency coefficient
2304//============================================================================
2305static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2306{
2307 // get the active view
2308 Handle(V3d_View) aView = ViewerTest::CurrentView();
2309 if (aView.IsNull())
2310 {
2311 di << "Call vinit before!\n";
2312 return 1;
2313 }
2314 else if (argc < 5)
2315 {
2316 di << "Use: " << argv[0];
2317 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
2318 di << " linetype : { 0 | 1 | 2 | 3 } \n";
2319 di << " 0 - solid \n";
2320 di << " 1 - dashed \n";
2321 di << " 2 - dot \n";
2322 di << " 3 - dashdot\n";
2323 di << " transparency : { 0.0 - 1.0 } \n";
2324 di << " 0.0 - transparent\n";
2325 di << " 1.0 - visible \n";
2326 return 1;
2327 }
2328
2329 // get the input params
2330 Standard_Real X1 = atof(argv[1]);
2331 Standard_Real Y1 = atof(argv[2]);
2332 Standard_Real X2 = atof(argv[3]);
2333 Standard_Real Y2 = atof(argv[4]);
2334
2335 Standard_Real aWidth = 0.5;
2336 Standard_Integer aType = 0;
2337 Standard_Real aTransparency = 1.0;
2338
2339 // has width
2340 if (argc > 5)
2341 aWidth = atof(argv[5]);
2342
2343 // has type
2344 if (argc > 6)
2345 aType = (Standard_Integer) atoi(argv[6]);
2346
2347 // has transparency
2348 if (argc > 7)
2349 {
2350 aTransparency = atof(argv[7]);
2351 if (aTransparency < 0 || aTransparency > 1.0)
2352 aTransparency = 1.0;
2353 }
2354
2355 // select appropriate line type
2356 Aspect_TypeOfLine aLineType;
2357 switch (aType)
2358 {
2359 case 1:
2360 aLineType = Aspect_TOL_DASH;
2361 break;
2362
2363 case 2:
2364 aLineType = Aspect_TOL_DOT;
2365 break;
2366
2367 case 3:
2368 aLineType = Aspect_TOL_DOTDASH;
2369 break;
2370
2371 default:
2372 aLineType = Aspect_TOL_SOLID;
2373 }
2374
2375 // replace layer manager
2376 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
2377 aView->SetLayerMgr(aMgr);
2378
2379 // add line item
2380 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
2381 aMgr.operator->(),
2382 aLineType, aWidth,
2383 aTransparency);
2384
2385 // update view
2386 aView->MustBeResized();
2387 aView->Redraw();
2388
2389 return 0;
2390}
2391
25289ec1 2392//=======================================================================
2393//function : VOverlayText
2394//purpose : Test text displaying in view overlay
2395//=======================================================================
2396static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
2397{
2398 // get the active view
2399 Handle(V3d_View) aView = ViewerTest::CurrentView();
2400 if (aView.IsNull())
2401 {
2402 di << "No active view. Please call vinit.\n";
2403 return 1;
2404 }
2405 else if (argc < 4 || argc > 13)
2406 {
2407 di << "Use: " << argv[0];
2408 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
2409 di << "[background_color: R G B]\n";
2410 di << " height - pixel height of the text (default=10.0)\n";
2411 di << " font_name - name of font (default=courier)\n";
2412 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
2413 di << " display_type = {normal/subtitle/decal/blend}, (default=normal)\n";
2414 di << " background_color- R G B values used for subtitle and decal text\n";
2415 di << "(default=255.0 255.0 255.0)\n";
2416 return 1;
2417 }
2418
2419 TCollection_AsciiString aText (argv[1]);
2420 Standard_Real aPosX = atof(argv[2]);
2421 Standard_Real aPosY = atof(argv[3]);
2422 Standard_Real aHeight = (argc >= 5) ? atof (argv[4]) : 10.0;
2423
2424 // font name
2425 TCollection_AsciiString aFontName = "Courier";
2426 if (argc >= 6)
2427 aFontName = TCollection_AsciiString (argv[5]);
2428
2429 // text colors
2430 Quantity_Parameter aColorRed = 1.0;
2431 Quantity_Parameter aColorGreen = 1.0;
2432 Quantity_Parameter aColorBlue = 1.0;
2433 if (argc >= 9)
2434 {
2435 aColorRed = atof (argv[6])/255.;
2436 aColorGreen = atof (argv[7])/255.;
2437 aColorBlue = atof (argv[8])/255.;
2438 }
2439
2440 // display type
2441 TCollection_AsciiString aDispStr;
2442 if (argc >= 10)
2443 aDispStr = TCollection_AsciiString (argv[9]);
2444
2445 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
2446 if (aDispStr.IsEqual ("subtitle"))
2447 aTextType = Aspect_TODT_SUBTITLE;
2448 else if (aDispStr.IsEqual ("decal"))
2449 aTextType = Aspect_TODT_DEKALE;
2450 else if (aDispStr.IsEqual ("blend"))
2451 aTextType = Aspect_TODT_BLEND;
2452
2453 // subtitle color
2454 Quantity_Parameter aSubRed = 1.0;
2455 Quantity_Parameter aSubGreen = 1.0;
2456 Quantity_Parameter aSubBlue = 1.0;
2457 if (argc == 13)
2458 {
2459 aSubRed = atof (argv[10])/255.;
2460 aSubGreen = atof (argv[11])/255.;
2461 aSubBlue = atof (argv[12])/255.;
2462 }
2463
2464 // check fo current overlay
2465 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
2466 if (anOverlay.IsNull ())
2467 {
2468 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
2469 anOverlay = aMgr->Overlay ();
2470 aView->SetLayerMgr (aMgr);
2471 }
2472
2473 Quantity_Color aTextColor (aColorRed, aColorGreen,
2474 aColorBlue, Quantity_TOC_RGB);
2475 Quantity_Color aSubtColor (aSubRed, aSubGreen,
2476 aSubBlue, Quantity_TOC_RGB);
2477
2478 // add text item
2479 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
2480 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
2481
2482 // update view
2483 aView->MustBeResized();
2484 aView->Redraw();
2485
2486 return 0;
2487}
2488
7fd59977 2489//=======================================================================
2490//function : ViewerCommands
2491//purpose :
2492//=======================================================================
2493
2494void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
2495{
2496
2497 const char *group = "ZeViewer";
2498 theCommands.Add("vinit" ,
2499 "vinit : vinit [leftPx topPx widthPx heightPx] : Create the Viewer window",
2500 __FILE__,VInit,group);
2501 theCommands.Add("vhelp" ,
2502 "vhelp : display help on the viewer commands",
2503 __FILE__,VHelp,group);
2504 theCommands.Add("vtop" ,
2505 "vtop or <T> : Top view" ,
2506 __FILE__,VTop,group);
2507 theCommands.Add("vaxo" ,
2508 " vaxo or <A> : Axonometric view ",
2509 __FILE__,VAxo,group);
2510 theCommands.Add("vpick" ,
2511 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
2512 VPick,group);
2513 theCommands.Add("vfit" ,
2514 "vfit or <F> : vfit",
2515 __FILE__,VFit,group);
2516 theCommands.Add("vzfit" ,
2517 "vzfit",
2518 __FILE__,VZFit,group);
2519 theCommands.Add("vrepaint",
2520 "vrepaint : vrepaint, force redraw",
2521 __FILE__,VRepaint,group);
2522 theCommands.Add("vclear",
2523 "vclear : vclear",
2524 __FILE__,VClear,group);
2525 theCommands.Add("vsetbg",
2526 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
2527 __FILE__,VSetBg,group);
f8b2ed36 2528 theCommands.Add("vsetbgmode",
2529 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
2530 __FILE__,VSetBgMode,group);
7fd59977 2531 theCommands.Add("vsetgradientbg",
f8b2ed36 2532 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7fd59977 2533 __FILE__,VSetGradientBg,group);
f8b2ed36 2534 theCommands.Add("vsetgrbgmode",
2535 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
2536 __FILE__,VSetGradientBgMode,group);
2537 theCommands.Add("vsetcolorbg",
2538 "vsetcolorbg : vsetcolorbg r g b : Set background color",
2539 __FILE__,VSetColorBg,group);
7fd59977 2540 theCommands.Add("vscale",
2541 "vscale : vscale X Y Z",
2542 __FILE__,VScale,group);
2543 theCommands.Add("vzbufftrihedron",
2544 "vzbufftrihedron : Displays a V3d_ZBUFFER'ed trihedron at the bottom left corner of the view",
2545 __FILE__,VTestZBuffTrihedron,group);
2546 theCommands.Add("vrotate",
2547 "vrotate : vrotate AX AY AZ [X Y Z]",
2548 __FILE__,VRotate,group);
2549 theCommands.Add("vzoom",
2550 "vzoom : vzoom coef",
2551 __FILE__,VZoom,group);
2552 theCommands.Add("vpan",
2553 "vpan : vpan dx dy",
2554 __FILE__,VPan,group);
2555 theCommands.Add("vexport",
5cedc27f
K
2556 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
2557 " : exports the view to a vector file of a given format"
2558 " : notice that EMF format requires patched gl2ps",
7fd59977 2559 __FILE__,VExport,group);
2560 theCommands.Add("vcolorscale",
2561 "vcolorscale : vcolorscale [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = 2 X = 0 Y = 0]: draw color scale",
2562 __FILE__,VColorScale,group);
2563 theCommands.Add("vgraduatedtrihedron",
13a22457 2564 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
7fd59977 2565 __FILE__,VGraduatedTrihedron,group);
7edf74fd
A
2566 theCommands.Add("vprintview" ,
2567 "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
2568 __FILE__,VPrintView,group);
59f45b7c 2569 theCommands.Add("vzlayer",
2570 "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids",
2571 __FILE__,VZLayer,group);
25289ec1 2572 theCommands.Add("voverlaytext",
2573 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
2574 " : height - pixel height of the text (default=10.0)"
2575 " : font_name - name of font (default=courier)"
2576 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
2577 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
2578 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
2579 __FILE__,VOverlayText,group);
20637bd2 2580 theCommands.Add("vlayerline",
2581 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
2582 __FILE__,VLayerLine,group);
7fd59977 2583}