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