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