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