0024294: Access violation in AIS_InteractiveContext::MoveTo()
[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
233//==============================================================================
18d715bd 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}
484//==============================================================================
7fd59977 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
713//==============================================================================
4269bd1b 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
727//==============================================================================
18d715bd 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
818//==============================================================================
0a768f56 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
920//==============================================================================
18d715bd 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
1082static int VClose (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1083{
1084 if (theArgsNb < 2)
1085 {
1086 theDi << theArgVec[0] << ": incorrect number of command arguments.\n"
1087 << "Type help " << theArgVec[0] << " for more information.\n";
1088 return 1;
1089 }
1090
1091 if (ViewerTest_myViews.IsEmpty())
1092 {
1093 theDi << theArgVec[0] <<": there is no views to close.\n";
1094 return 0;
1095 }
1096
1097 TCollection_AsciiString anInputString(theArgVec[1]);
4269bd1b 1098
18d715bd 1099 // Create list to iterate and remove views from the map of views
1100 NCollection_List<TCollection_AsciiString> aViewList;
29cb310a 1101 if ( strcasecmp( anInputString.ToCString(), "ALL" ) == 0 )
18d715bd 1102 {
1103 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter(ViewerTest_myViews);
1104 anIter.More(); anIter.Next())
1105 {
1106 aViewList.Append(anIter.Key1());
1107 }
1108 }
1109 else
1110 {
1111 ViewerTest_Names aViewNames(anInputString);
1112 aViewList.Append(aViewNames.GetViewName());
1113 }
1114
1115 Standard_Boolean isContextRemoved = (theArgsNb == 3 && atoi(theArgVec[2])==1) ? Standard_False : Standard_True;
1116 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1117 anIter.More(); anIter.Next())
1118 {
1119 ViewerTest::RemoveView(anIter.Value(), isContextRemoved);
1120 }
1121
1122 return 0;
1123}
1124
1125//==============================================================================
1126//function : VActivate
1127//purpose : Activate the view defined by its ID
1128//==============================================================================
1129
1130static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1131{
1132 if (theArgsNb > 2)
1133 {
1134 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1135 << "Usage: " << theArgVec[0] << " ViewID\n";
1136 return 1;
1137 }
1138 if(theArgsNb == 1)
1139 {
1140 theDi.Eval("vviewlist");
1141 return 0;
1142 }
1143
1144 TCollection_AsciiString aNameString(theArgVec[1]);
29cb310a 1145 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
18d715bd 1146 {
1147 TCollection_AsciiString aTitle("3D View - ");
1148 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1149 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1150 Handle(V3d_View) anEmptyView;
1151#if defined(_WIN32) || defined(__WIN32__)
1152 Handle(WNT_Window) anEmptyWindow;
1153#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1154 Handle(Cocoa_Window) anEmptyWindow;
1155#else
1156 Handle(Xw_Window) anEmptyWindow;
1157#endif
1158 VT_GetWindow() = anEmptyWindow;
1159 ViewerTest::CurrentView (anEmptyView);
1160 ViewerTest::ResetEventManager();
1161 theDi << theArgVec[0] << ": all views are inactive\n";
1162 return 0;
1163 }
1164
1165 ViewerTest_Names aViewNames(aNameString);
1166
1167 // Check if this view exists in the viewer with the driver
1168 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1169 {
1170 theDi << "Wrong view name\n";
1171 return 1;
1172 }
1173
1174 // Check if it is active already
1175 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1176 {
1177 theDi << theArgVec[0] << ": the view is active already\n";
1178 return 0;
1179 }
1180
1181 ActivateView (aViewNames.GetViewName());
1182 return 0;
1183}
1184
1185//==============================================================================
1186//function : VViewList
1187//purpose : Print current list of views per viewer and graphic driver ID
1188// shared between viewers
1189//==============================================================================
1190
1191static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1192{
1193 if (theArgsNb > 2)
1194 {
1195 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
29cb310a 1196 << "Usage: " << theArgVec[0] << " name";
18d715bd 1197 return 1;
1198 }
1199 if (ViewerTest_myContexts.Size() < 1)
1200 return 0;
1201
18d715bd 1202 Standard_Boolean isTreeView =
29cb310a 1203 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
18d715bd 1204
1205 if (isTreeView)
1206 theDi << theArgVec[0] <<":\n";
1207
1208 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1209 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1210 {
1211 if (isTreeView)
1212 theDi << aDriverIter.Key1() << ":\n";
1213
1214 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1215 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1216 {
1217 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1218 {
1219 if (isTreeView)
1220 {
1221 TCollection_AsciiString aContextName(aContextIter.Key1());
1222 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1223 }
1224
1225 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1226 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1227 {
1228 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1229 {
1230 TCollection_AsciiString aViewName(aViewIter.Key1());
1231 if (isTreeView)
1232 {
1233 if (aViewIter.Value() == ViewerTest::CurrentView())
1234 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1235 else
1236 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1237 }
1238 else
1239 {
1240 theDi << aViewName << " ";
1241 }
1242 }
1243 }
1244 }
1245 }
1246 }
1247 return 0;
1248}
1249
1250//==============================================================================
4fe56619 1251//function : VT_ProcessKeyPress
7fd59977 1252//purpose : Handle KeyPress event from a CString
1253//==============================================================================
4fe56619 1254void VT_ProcessKeyPress (const char* buf_ret)
7fd59977 1255{
1256 //cout << "KeyPress" << endl;
1257 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1258 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1259 // Letter in alphabetic order
1260
b514beda 1261 if (!strcasecmp (buf_ret, "A"))
1262 {
7fd59977 1263 // AXO
1264 aView->SetProj(V3d_XposYnegZpos);
1265 }
b514beda 1266 else if (!strcasecmp (buf_ret, "D"))
1267 {
7fd59977 1268 // Reset
1269 aView->Reset();
1270 }
b514beda 1271 else if (!strcasecmp (buf_ret, "F"))
1272 {
7fd59977 1273 // FitAll
1274 if (aNisView.IsNull())
1275 aView->FitAll();
1276 else
1277 aNisView->FitAll3d();
1278 }
b514beda 1279 else if (!strcasecmp (buf_ret, "H"))
1280 {
7fd59977 1281 // HLR
1282 cout << "HLR" << endl;
de75ed09 1283 aView->SetComputedMode (!aView->ComputedMode());
1284 MyHLRIsOn = aView->ComputedMode();
7fd59977 1285 }
b514beda 1286 else if (!strcasecmp (buf_ret, "P"))
1287 {
0a768f56 1288 // Type of HLR
1289 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1290 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1291 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1292 else
1293 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1294 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1295 {
1296 AIS_ListOfInteractive aListOfShapes;
1297 aContext->DisplayedObjects(aListOfShapes);
1298 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1299 anIter.More(); anIter.Next())
1300 {
1301 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1302 if (aShape.IsNull())
1303 continue;
1304 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1305 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1306 else
1307 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1308 aShape->Redisplay();
1309 }
1310 }
1311 else
1312 {
1313 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1314 {
1315 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1316 if (aShape.IsNull())
1317 continue;
1318 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1319 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1320 else
1321 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1322 aShape->Redisplay();
1323 }
1324 }
1325
1326 aContext->UpdateCurrentViewer();
4269bd1b 1327
0a768f56 1328 }
b514beda 1329 else if (!strcasecmp (buf_ret, "S"))
1330 {
1331 std::cout << "setup Shaded display mode" << std::endl;
4fe56619 1332
7fd59977 1333 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1334 if(Ctx->NbCurrents()==0 ||
1335 Ctx->NbSelected()==0)
1336 Ctx->SetDisplayMode(AIS_Shaded);
1337 else{
1338 if(Ctx->HasOpenedContext()){
1339 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1340 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1341 }
1342 else{
1343 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1344 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1345 }
1346 Ctx->UpdateCurrentViewer();
1347 }
1348 }
b514beda 1349 else if (!strcasecmp (buf_ret, "U"))
1350 {
41811896 1351 // Unset display mode
b514beda 1352 std::cout << "reset display mode to defaults" << std::endl;
4fe56619 1353
7fd59977 1354 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1355 if(Ctx->NbCurrents()==0 ||
1356 Ctx->NbSelected()==0)
1357 Ctx->SetDisplayMode(AIS_WireFrame);
1358 else{
1359 if(Ctx->HasOpenedContext()){
1360 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1361 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1362 }
1363 else{
1364 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1365 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1366 }
1367 Ctx->UpdateCurrentViewer();
1368 }
1369
1370 }
b514beda 1371 else if (!strcasecmp (buf_ret, "T"))
1372 {
7fd59977 1373 // Top
1374 aView->SetProj(V3d_Zpos);
1375 }
b514beda 1376 else if (!strcasecmp (buf_ret, "B"))
1377 {
41811896 1378 // Bottom
7fd59977 1379 aView->SetProj(V3d_Zneg);
1380 }
b514beda 1381 else if (!strcasecmp (buf_ret, "L"))
1382 {
41811896 1383 // Left
7fd59977 1384 aView->SetProj(V3d_Xneg);
1385 }
b514beda 1386 else if (!strcasecmp (buf_ret, "R"))
1387 {
41811896 1388 // Right
7fd59977 1389 aView->SetProj(V3d_Xpos);
1390 }
b514beda 1391 else if (!strcasecmp (buf_ret, "W"))
1392 {
1393 std::cout << "setup WireFrame display mode" << std::endl;
7fd59977 1394 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1395 if(Ctx->NbCurrents()==0 ||
1396 Ctx->NbSelected()==0)
1397 Ctx->SetDisplayMode(AIS_WireFrame);
1398 else{
1399 if(Ctx->HasOpenedContext()){
1400 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1401 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1402 }
1403 else{
1404 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1405 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1406 }
1407 Ctx->UpdateCurrentViewer();
1408 }
1409 }
b514beda 1410 else if (!strcasecmp (buf_ret, "Z"))
1411 {
7fd59977 1412 // ZCLIP
7fd59977 1413 if ( ZClipIsOn ) {
1414 cout << "ZClipping OFF" << endl;
1415 ZClipIsOn = 0;
1416
1417 aView->SetZClippingType(V3d_OFF);
1418 aView->Redraw();
1419 }
1420 else {
1421 cout << "ZClipping ON" << endl;
1422 ZClipIsOn = 1;
1423
1424 aView->SetZClippingType(V3d_FRONT);
1425 aView->Redraw();
1426 }
1427 }
b514beda 1428 else if (!strcasecmp (buf_ret, ","))
1429 {
7fd59977 1430 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
7fd59977 1431 }
b514beda 1432 else if (!strcasecmp (buf_ret, "."))
1433 {
7fd59977 1434 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1435 }
b514beda 1436 else if (*buf_ret == THE_KEY_DELETE)
1437 {
1438 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1439 if (!aCtx.IsNull()
1440 && aCtx->NbCurrents() > 0
1441 && aCtx->NbSelected() > 0)
1442 {
1443 Draw_Interprete ("verase");
1444 }
1445 }
1446 else
1447 {
1448 // Number
91322f44 1449 Standard_Integer Num = Draw::Atoi(buf_ret);
7fd59977 1450 if(Num>=0 && Num<=7)
1451 ViewerTest::StandardModeActivation(Num);
1452 }
1453}
1454
1455//==============================================================================
4fe56619 1456//function : VT_ProcessExpose
7fd59977 1457//purpose : Redraw the View on an Expose Event
1458//==============================================================================
4fe56619 1459void VT_ProcessExpose()
1460{
1461 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1462 if (!aView3d.IsNull())
1463 {
1464 aView3d->Redraw();
1465 }
7fd59977 1466}
1467
1468//==============================================================================
4fe56619 1469//function : VT_ProcessConfigure
7fd59977 1470//purpose : Resize the View on an Configure Event
1471//==============================================================================
4fe56619 1472void VT_ProcessConfigure()
7fd59977 1473{
4fe56619 1474 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1475 if (aView3d.IsNull())
1476 {
1477 return;
1478 }
1479
1480 aView3d->MustBeResized();
1481 aView3d->Update();
1482 aView3d->Redraw();
7fd59977 1483}
1484
1485//==============================================================================
4fe56619 1486//function : VT_ProcessButton1Press
7fd59977 1487//purpose : Picking
1488//==============================================================================
4fe56619 1489Standard_Boolean VT_ProcessButton1Press(
7fd59977 1490 Standard_Integer ,
4fe56619 1491 const char** argv,
7fd59977 1492 Standard_Boolean pick,
4fe56619 1493 Standard_Boolean shift)
7fd59977 1494{
1495 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1496 if ( pick ) {
1497 Standard_Real X, Y, Z;
1498
1499 ViewerTest::CurrentView()->Convert(X_Motion, Y_Motion, X, Y, Z);
1500
1501 Draw::Set(argv[1], X);
1502 Draw::Set(argv[2], Y);
1503 Draw::Set(argv[3], Z);}
1504
1505 if(shift)
1506 EM->ShiftSelect();
1507 else
1508 EM->Select();
1509
1510 pick = 0;
1511 return pick;
1512}
1513
1514//==============================================================================
4fe56619 1515//function : VT_ProcessButton1Release
1516//purpose : End selecting
7fd59977 1517//==============================================================================
4fe56619 1518void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1519{
1520 if (IsDragged)
1521 {
1522 IsDragged = Standard_False;
1523 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1524 if (theIsShift)
1525 {
1526 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1527 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1528 }
1529 else
1530 {
1531 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1532 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1533 }
1534 }
1535}
7fd59977 1536
4fe56619 1537//==============================================================================
1538//function : VT_ProcessButton3Press
1539//purpose : Start Rotation
1540//==============================================================================
1541void VT_ProcessButton3Press()
1542{
7fd59977 1543 Start_Rot = 1;
de75ed09 1544 if (MyHLRIsOn)
1545 {
1546 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1547 }
7fd59977 1548 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
7fd59977 1549}
4fe56619 1550
7fd59977 1551//==============================================================================
4fe56619 1552//function : VT_ProcessButton3Release
1553//purpose : End rotation
7fd59977 1554//==============================================================================
4fe56619 1555void VT_ProcessButton3Release()
1556{
1557 if (Start_Rot)
1558 {
7fd59977 1559 Start_Rot = 0;
de75ed09 1560 if (MyHLRIsOn)
1561 {
1562 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1563 }
7fd59977 1564 }
7fd59977 1565}
1566
1567//==============================================================================
1568//function : ProcessZClipMotion
1569//purpose : Zoom
1570//==============================================================================
1571
1572void ProcessZClipMotion()
1573{
1574 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1575 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1576 static Standard_Real CurZPos = 0.;
1577
1578 //Quantity_Length VDX, VDY;
1579 //a3DView->Size(VDX,VDY);
1580 //Standard_Real VDZ = a3DView->ZSize();
1581 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1582
1583 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1584
1585 // Front = Depth + width/2.
1586 Standard_Real D = 0.5;
1587 Standard_Real W = 0.1;
1588
1589 CurZPos += (dx);
1590
1591 D += CurZPos;
1592
1593 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1594
1595 a3DView->SetZClippingType(V3d_OFF);
1596 a3DView->SetZClippingDepth(D);
1597 a3DView->SetZClippingWidth(W);
1598 a3DView->SetZClippingType(V3d_FRONT);
1599
1600 a3DView->Redraw();
1601
1602 X_ButtonPress = X_Motion;
1603 Y_ButtonPress = Y_Motion;
1604 }
1605}
1606
1607//==============================================================================
1608//function : ProcessControlButton1Motion
1609//purpose : Zoom
1610//==============================================================================
1611
1612static void ProcessControlButton1Motion()
1613{
1614 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1615
1616 X_ButtonPress = X_Motion;
1617 Y_ButtonPress = Y_Motion;
1618}
1619
1620//==============================================================================
4fe56619 1621//function : VT_ProcessControlButton2Motion
1622//purpose : Panning
7fd59977 1623//==============================================================================
4fe56619 1624void VT_ProcessControlButton2Motion()
7fd59977 1625{
1626 Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
1627 Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
1628
1629 dy = -dy; // Xwindow Y axis is from top to Bottom
1630
1631 ViewerTest::CurrentView()->Panning( dx, dy );
1632
1633 X_ButtonPress = X_Motion;
1634 Y_ButtonPress = Y_Motion;
1635}
1636
1637//==============================================================================
4fe56619 1638//function : VT_ProcessControlButton3Motion
7fd59977 1639//purpose : Rotation
1640//==============================================================================
4fe56619 1641void VT_ProcessControlButton3Motion()
7fd59977 1642{
4fe56619 1643 if (Start_Rot)
1644 {
1645 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1646 }
7fd59977 1647}
1648
1649//==============================================================================
4fe56619 1650//function : VT_ProcessMotion
1651//purpose :
7fd59977 1652//==============================================================================
4fe56619 1653void VT_ProcessMotion()
7fd59977 1654{
1655 //pre-hilights detected objects at mouse position
1656
1657 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1658 EM->MoveTo(X_Motion, Y_Motion);
1659}
1660
1661
1662void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1663{
1664 Xpix = X_Motion;Ypix=Y_Motion;
1665}
1666
1667//==============================================================================
44b8f2d6 1668//function : ViewProject: implements VAxo, VTop, VLeft, ...
1669//purpose : Switches to an axonometric, top, left and other views
1670//==============================================================================
1671
1672static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1673{
4fe56619 1674 if ( ViewerTest::CurrentView().IsNull() )
44b8f2d6 1675 {
1676 di<<"Call vinit before this command, please"<<"\n";
1677 return 1;
1678 }
1679
1680 ViewerTest::CurrentView()->SetProj(ori);
1681 return 0;
1682}
1683
1684//==============================================================================
7fd59977 1685//function : VAxo
1686//purpose : Switch to an Axonometric view
1687//Draw arg : No args
1688//==============================================================================
1689
1690static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
44b8f2d6 1691{
1692 return ViewProject(di, V3d_XposYnegZpos);
7fd59977 1693}
1694
1695//==============================================================================
1696//function : VTop
1697//purpose : Switch to a Top View
1698//Draw arg : No args
1699//==============================================================================
1700
1701static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1702{
44b8f2d6 1703 return ViewProject(di, V3d_Zpos);
1704}
7fd59977 1705
44b8f2d6 1706//==============================================================================
1707//function : VBottom
1708//purpose : Switch to a Bottom View
1709//Draw arg : No args
1710//==============================================================================
7fd59977 1711
44b8f2d6 1712static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1713{
1714 return ViewProject(di, V3d_Zneg);
1715}
7fd59977 1716
44b8f2d6 1717//==============================================================================
1718//function : VLeft
1719//purpose : Switch to a Left View
1720//Draw arg : No args
1721//==============================================================================
1722
1723static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1724{
1725 return ViewProject(di, V3d_Ypos);
1726}
1727
1728//==============================================================================
1729//function : VRight
1730//purpose : Switch to a Right View
1731//Draw arg : No args
1732//==============================================================================
1733
1734static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1735{
1736 return ViewProject(di, V3d_Yneg);
1737}
7fd59977 1738
44b8f2d6 1739//==============================================================================
1740//function : VFront
1741//purpose : Switch to a Front View
1742//Draw arg : No args
1743//==============================================================================
1744
1745static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1746{
1747 return ViewProject(di, V3d_Xpos);
1748}
1749
1750//==============================================================================
1751//function : VBack
1752//purpose : Switch to a Back View
1753//Draw arg : No args
1754//==============================================================================
1755
1756static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1757{
1758 return ViewProject(di, V3d_Xneg);
7fd59977 1759}
1760
1761//==============================================================================
1762//function : VHelp
1763//purpose : Dsiplay help on viewer Keyboead and mouse commands
1764//Draw arg : No args
1765//==============================================================================
1766
1767static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1768{
1769
1770 di << "Q : Quit the application" << "\n";
1771
1772 di << "========================="<<"\n";
1773 di << "F : FitAll" << "\n";
1774 di << "T : TopView" << "\n";
41811896 1775 di << "B : BottomView" << "\n";
1776 di << "R : RightView" << "\n";
1777 di << "L : LeftView" << "\n";
7fd59977 1778 di << "A : AxonometricView" << "\n";
41811896 1779 di << "D : ResetView" << "\n";
7fd59977 1780
1781 di << "========================="<<"\n";
1782 di << "S : Shading" << "\n";
1783 di << "W : Wireframe" << "\n";
1784 di << "H : HidelLineRemoval" << "\n";
41811896 1785 di << "U : Unset display mode" << "\n";
b514beda 1786 di << "Delete : Remove selection from viewer" << "\n";
7fd59977 1787
1788 di << "========================="<<"\n";
1789 di << "Selection mode "<<"\n";
1790 di << "0 : Shape" <<"\n";
1791 di << "1 : Vertex" <<"\n";
1792 di << "2 : Edge" <<"\n";
1793 di << "3 : Wire" <<"\n";
1794 di << "4 : Face" <<"\n";
1795 di << "5 : Shell" <<"\n";
1796 di << "6 : Solid" <<"\n";
1797 di << "7 : Compound" <<"\n";
1798
41811896 1799 di << "========================="<<"\n";
1800 di << "Z : Switch Z clipping On/Off" << "\n";
1801 di << ", : Hilight next detected" << "\n";
1802 di << ". : Hilight previous detected" << "\n";
7fd59977 1803
1804 return 0;
1805}
1806
7fd59977 1807#ifdef WNT
1808
1809static Standard_Boolean Ppick = 0;
1810static Standard_Integer Pargc = 0;
1811static const char** Pargv = NULL;
1812
1813
1814static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1815 UINT Msg,
1816 WPARAM wParam,
1817 LPARAM lParam )
1818{
18d715bd 1819 if (!ViewerTest_myViews.IsEmpty()) {
7fd59977 1820
1821 WPARAM fwKeys = wParam;
1822
1823 switch( Msg ) {
18d715bd 1824 case WM_CLOSE:
1825 {
1826 // Delete view from map of views
1827 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1828 return 0;
1829 }
1830 break;
1831 case WM_ACTIVATE:
1832 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1833 || ViewerTest::CurrentView().IsNull())
1834 {
1835 // Activate inactive window
1836 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1837 {
1838 ActivateView (FindViewIdByWindowHandle(hwnd));
1839 }
1840 }
1841 break;
7fd59977 1842 case WM_LBUTTONUP:
1843 IsDragged = Standard_False;
1844 if( !DragFirst )
1845 {
1846 HDC hdc = GetDC( hwnd );
7fd59977 1847 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1848 SetROP2( hdc, R2_NOT );
4fe56619 1849 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1850 ReleaseDC( hwnd, hdc );
1851
1852 const Handle(ViewerTest_EventManager) EM =
1853 ViewerTest::CurrentEventManager();
1854 if ( fwKeys & MK_SHIFT )
4fe56619 1855 EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1856 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
7fd59977 1857 else
4fe56619 1858 EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
1859 max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
7fd59977 1860 }
1861 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1862
1863 case WM_LBUTTONDOWN:
1864 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1865 {
1866 IsDragged = Standard_True;
1867 DragFirst = Standard_True;
4fe56619 1868 X_ButtonPress = LOWORD(lParam);
1869 Y_ButtonPress = HIWORD(lParam);
7fd59977 1870 }
1871 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1872
1873 break;
1874
1875 case WM_MOUSEMOVE:
1876 if( IsDragged )
1877 {
1878 HDC hdc = GetDC( hwnd );
1879
1880 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1881 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1882 SetROP2( hdc, R2_NOT );
1883
1884 if( !DragFirst )
4fe56619 1885 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1886
1887 DragFirst = Standard_False;
4fe56619 1888 X_Motion = LOWORD(lParam);
1889 Y_Motion = HIWORD(lParam);
7fd59977 1890
4fe56619 1891 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
7fd59977 1892
1893 SelectObject( hdc, anObj );
1894
1895 ReleaseDC( hwnd, hdc );
1896 }
1897 else
1898 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1899 break;
1900
1901 default:
1902 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1903 }
1904 return 0;
1905 }
1906 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1907}
1908
1909
1910static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1911 UINT Msg,
1912 WPARAM wParam,
1913 LPARAM lParam )
1914{
7fd59977 1915 static int Up = 1;
1916
1917 if ( !ViewerTest::CurrentView().IsNull() ) {
1918 PAINTSTRUCT ps;
1919
1920 switch( Msg ) {
7fd59977 1921 case WM_PAINT:
7fd59977 1922 BeginPaint(hwnd, &ps);
1923 EndPaint(hwnd, &ps);
4fe56619 1924 VT_ProcessExpose();
7fd59977 1925 break;
1926
1927 case WM_SIZE:
4fe56619 1928 VT_ProcessConfigure();
7fd59977 1929 break;
1930
1931 case WM_KEYDOWN:
4fe56619 1932 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
1933 {
7fd59977 1934 char c[2];
1935 c[0] = (char) wParam;
1936 c[1] = '\0';
b514beda 1937 if (wParam == VK_DELETE)
1938 {
1939 c[0] = THE_KEY_DELETE;
1940 }
4fe56619 1941 VT_ProcessKeyPress (c);
7fd59977 1942 }
1943 break;
1944
1945 case WM_LBUTTONUP:
1946 case WM_MBUTTONUP:
1947 case WM_RBUTTONUP:
7fd59977 1948 Up = 1;
4fe56619 1949 VT_ProcessButton3Release();
7fd59977 1950 break;
1951
1952 case WM_LBUTTONDOWN:
1953 case WM_MBUTTONDOWN:
1954 case WM_RBUTTONDOWN:
1955 {
7fd59977 1956 WPARAM fwKeys = wParam;
1957
1958 Up = 0;
1959
1960 X_ButtonPress = LOWORD(lParam);
1961 Y_ButtonPress = HIWORD(lParam);
1962
4fe56619 1963 if (Msg == WM_LBUTTONDOWN)
1964 {
1965 if (fwKeys & MK_CONTROL)
1966 {
1967 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1968 }
1969 else
1970 {
1971 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
1972 }
7fd59977 1973 }
4fe56619 1974 else if (Msg == WM_RBUTTONDOWN)
1975 {
7fd59977 1976 // Start rotation
4fe56619 1977 VT_ProcessButton3Press();
7fd59977 1978 }
1979 }
1980 break;
1981
1982 case WM_MOUSEMOVE:
1983 {
1984 //cout << "\t WM_MOUSEMOVE" << endl;
1985 WPARAM fwKeys = wParam;
1986 X_Motion = LOWORD(lParam);
1987 Y_Motion = HIWORD(lParam);
1988
1989 if ( Up &&
1990 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
1991 Up = 0;
1992 X_ButtonPress = LOWORD(lParam);
1993 Y_ButtonPress = HIWORD(lParam);
1994
1995 if ( fwKeys & MK_RBUTTON ) {
1996 // Start rotation
4fe56619 1997 VT_ProcessButton3Press();
7fd59977 1998 }
1999 }
2000
2001 if ( fwKeys & MK_CONTROL ) {
2002 if ( fwKeys & MK_LBUTTON ) {
2003 ProcessControlButton1Motion();
2004 }
2005 else if ( fwKeys & MK_MBUTTON ||
2006 ((fwKeys&MK_LBUTTON) &&
2007 (fwKeys&MK_RBUTTON) ) ){
4fe56619 2008 VT_ProcessControlButton2Motion();
7fd59977 2009 }
2010 else if ( fwKeys & MK_RBUTTON ) {
4fe56619 2011 VT_ProcessControlButton3Motion();
7fd59977 2012 }
2013 }
2014#ifdef BUG
2015 else if ( fwKeys & MK_SHIFT ) {
2016 if ( fwKeys & MK_MBUTTON ||
2017 ((fwKeys&MK_LBUTTON) &&
2018 (fwKeys&MK_RBUTTON) ) ) {
2019 cout << "ProcessZClipMotion()" << endl;
2020 ProcessZClipMotion();
2021 }
2022 }
2023#endif
08398024 2024 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2025 {
4fe56619 2026 if ((fwKeys & MK_MBUTTON
2027 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2028 {
7fd59977 2029 ProcessZClipMotion();
2030 }
4fe56619 2031 else
2032 {
2033 VT_ProcessMotion();
7fd59977 2034 }
08398024 2035 }
7fd59977 2036 }
2037 break;
2038
2039 default:
2040 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2041 }
2042 return 0L;
2043 }
2044
2045 return DefWindowProc( hwnd, Msg, wParam, lParam );
2046}
2047
2048
2049
2050
2051//==============================================================================
2052//function : ViewerMainLoop
2053//purpose : Get a Event on the view and dispatch it
2054//==============================================================================
2055
2056
8263fcd3 2057int ViewerMainLoop(Standard_Integer argc, const char** argv)
7fd59977 2058{
7fd59977 2059 Ppick = (argc > 0)? 1 : 0;
2060 Pargc = argc;
2061 Pargv = argv;
2062
2063 if ( Ppick ) {
2064 MSG msg;
2065 msg.wParam = 1;
2066
2067 cout << "Start picking" << endl;
2068
7fd59977 2069 while ( Ppick == 1 ) {
4fe56619 2070 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
7fd59977 2071 if (GetMessage(&msg, NULL, 0, 0) ) {
2072 TranslateMessage(&msg);
2073 DispatchMessage(&msg);
2074 }
2075 }
2076
2077 cout << "Picking done" << endl;
2078 }
2079
2080 return Ppick;
2081}
2082
4fe56619 2083#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
7fd59977 2084
2085int min( int a, int b )
2086{
2087 if( a<b )
2088 return a;
2089 else
2090 return b;
2091}
2092
2093int max( int a, int b )
2094{
2095 if( a>b )
2096 return a;
2097 else
2098 return b;
2099}
2100
2101int ViewerMainLoop(Standard_Integer argc, const char** argv)
2102
4269bd1b 2103{
18d715bd 2104 static XEvent aReport;
2105 Standard_Boolean pick = argc > 0;
2106 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2107 XNextEvent (aDisplay, &aReport);
7fd59977 2108
18d715bd 2109 // Handle event for the chosen display connection
2110 switch (aReport.type) {
2111 case ClientMessage:
2112 {
2113 if(aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2114 {
2115 // Close the window
2116 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2117 }
2118 }
2119 return 0;
2120 case FocusIn:
2121 {
2122 // Activate inactive view
2123 Window aWindow = GetWindowHandle(VT_GetWindow());
2124 if(aWindow != aReport.xfocus.window)
2125 {
2126 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2127 }
2128 }
2129 break;
7fd59977 2130 case Expose:
2131 {
4fe56619 2132 VT_ProcessExpose();
7fd59977 2133 }
2134 break;
2135 case ConfigureNotify:
2136 {
4fe56619 2137 VT_ProcessConfigure();
7fd59977 2138 }
2139 break;
2140 case KeyPress:
2141 {
2142
2143 KeySym ks_ret ;
2144 char buf_ret[11] ;
2145 int ret_len ;
2146 XComposeStatus status_in_out;
2147
18d715bd 2148 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
7fd59977 2149 (char *) buf_ret , 10 ,
2150 &ks_ret , &status_in_out ) ;
2151
2152
2153 buf_ret[ret_len] = '\0' ;
2154
4fe56619 2155 if (ret_len)
2156 {
2157 VT_ProcessKeyPress (buf_ret);
7fd59977 2158 }
2159 }
2160 break;
2161 case ButtonPress:
7fd59977 2162 {
18d715bd 2163 X_ButtonPress = aReport.xbutton.x;
2164 Y_ButtonPress = aReport.xbutton.y;
7fd59977 2165
18d715bd 2166 if (aReport.xbutton.button == Button1)
4fe56619 2167 {
18d715bd 2168 if (aReport.xbutton.state & ControlMask)
4fe56619 2169 {
18d715bd 2170 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
4fe56619 2171 }
7fd59977 2172 else
2173 {
2174 IsDragged = Standard_True;
7fd59977 2175 DragFirst = Standard_True;
2176 }
4fe56619 2177 }
18d715bd 2178 else if (aReport.xbutton.button == Button3)
4fe56619 2179 {
7fd59977 2180 // Start rotation
4fe56619 2181 VT_ProcessButton3Press();
2182 }
7fd59977 2183 }
2184 break;
2185 case ButtonRelease:
2186 {
7fd59977 2187 if( IsDragged )
2188 {
2189 if( !DragFirst )
2190 {
2191 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2192 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2193 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 2194 }
2195
2196 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2197 if( aContext.IsNull() )
2198 {
2199 cout << "The context is null. Please use vinit before createmesh" << endl;
2200 return 0;
2201 }
2202
18d715bd 2203 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2204 if( aReport.xbutton.button==1 )
7fd59977 2205 if( DragFirst )
2206 if( ShiftPressed )
2207 {
2208 aContext->ShiftSelect();
7fd59977 2209 }
2210 else
2211 {
2212 aContext->Select();
7fd59977 2213 }
2214 else
2215 if( ShiftPressed )
2216 {
4fe56619 2217 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2218 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2219 ViewerTest::CurrentView());
7fd59977 2220 }
2221 else
2222 {
4fe56619 2223 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2224 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
7fd59977 2225 ViewerTest::CurrentView() );
7fd59977 2226 }
2227 else
4fe56619 2228 VT_ProcessButton3Release();
7fd59977 2229
2230 IsDragged = Standard_False;
2231 }
2232 else
4fe56619 2233 VT_ProcessButton3Release();
7fd59977 2234 }
2235 break;
2236 case MotionNotify:
2237 {
08398024 2238 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2239 {
2240 break;
2241 }
7fd59977 2242 if( IsDragged )
2243 {
2244 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
18d715bd 2245 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2246 XSetFunction( aDisplay, gc, GXinvert );
7fd59977 2247
2248 if( !DragFirst )
18d715bd 2249 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 2250
18d715bd 2251 X_Motion = aReport.xmotion.x;
2252 Y_Motion = aReport.xmotion.y;
7fd59977 2253 DragFirst = Standard_False;
2254
18d715bd 2255 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 2256 }
2257 else
2258 {
18d715bd 2259 X_Motion = aReport.xmotion.x;
2260 Y_Motion = aReport.xmotion.y;
7fd59977 2261
18d715bd 2262 // remove all the ButtonMotionMaskr
2263 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
7fd59977 2264
18d715bd 2265 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
7fd59977 2266 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2267
2268 Quantity_Length VDX, VDY;
2269
2270 ViewerTest::CurrentView()->Size(VDX,VDY);
2271 Standard_Real VDZ =0 ;
2272 VDZ = ViewerTest::CurrentView()->ZSize();
2273
7fd59977 2274 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2275
2276 Quantity_Length dx = 0 ;
2277 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2278
2279 cout << dx << endl;
2280
2281 dx = dx / VDX * VDZ;
2282
2283 cout << dx << endl;
2284
7fd59977 2285 ViewerTest::CurrentView()->Redraw();
2286 }
2287 }
2288
18d715bd 2289 if ( aReport.xmotion.state & ControlMask ) {
2290 if ( aReport.xmotion.state & Button1Mask ) {
7fd59977 2291 ProcessControlButton1Motion();
2292 }
18d715bd 2293 else if ( aReport.xmotion.state & Button2Mask ) {
4fe56619 2294 VT_ProcessControlButton2Motion();
7fd59977 2295 }
18d715bd 2296 else if ( aReport.xmotion.state & Button3Mask ) {
4fe56619 2297 VT_ProcessControlButton3Motion();
7fd59977 2298 }
2299 }
4fe56619 2300 else
2301 {
2302 VT_ProcessMotion();
7fd59977 2303 }
2304 }
2305 }
2306 break;
2307}
7fd59977 2308return pick;
2309}
2310
2311//==============================================================================
2312//function : VProcessEvents
2313//purpose : call by Tk_CreateFileHandler() to be able to manage the
2314// event in the Viewer window
2315//==============================================================================
2316
2317static void VProcessEvents(ClientData,int)
2318{
18d715bd 2319 NCollection_Vector<int> anEventNumbers;
2320 // Get number of messages from every display
2321 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2322 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2323 {
2324 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
4269bd1b 2325 }
18d715bd 2326 // Handle events for every display
2327 int anEventIter = 0;
2328 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2329 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2330 {
4269bd1b 2331 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
18d715bd 2332 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2333 {
2334 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2335 int anEventResult = ViewerMainLoop( 0, NULL);
2336 // If window is closed or context was not found finish current event processing loop
2337 if (!anEventResult)
2338 return;
2339 }
7fd59977 2340 }
4269bd1b 2341
18d715bd 2342 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
4269bd1b 2343
7fd59977 2344}
2345#endif
2346
2347//==============================================================================
2348//function : OSWindowSetup
2349//purpose : Setup for the X11 window to be able to cath the event
2350//==============================================================================
2351
2352
2353static void OSWindowSetup()
2354{
4fe56619 2355#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2356 // X11
2357
2358 Window window = VT_GetWindow()->XWindow();
18d715bd 2359 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2360 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2361 XSynchronize(aDisplay, 1);
7fd59977 2362
2363 // X11 : For keyboard on SUN
2364 XWMHints wmhints;
2365 wmhints.flags = InputHint;
2366 wmhints.input = 1;
2367
18d715bd 2368 XSetWMHints( aDisplay, window, &wmhints);
7fd59977 2369
18d715bd 2370 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
7fd59977 2371 ButtonPressMask | ButtonReleaseMask |
2372 StructureNotifyMask |
2373 PointerMotionMask |
2374 Button1MotionMask | Button2MotionMask |
18d715bd 2375 Button3MotionMask | FocusChangeMask
7fd59977 2376 );
18d715bd 2377 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2378 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
7fd59977 2379
18d715bd 2380 XSynchronize(aDisplay, 0);
7fd59977 2381
2382#else
2383 // WNT
2384#endif
2385
2386}
2387
2388
2389//==============================================================================
2390//function : VFit
2391
2392//purpose : Fitall, no DRAW arguments
2393//Draw arg : No args
2394//==============================================================================
2395
2396static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2397{
2398 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2399 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2400 if (V.IsNull() == Standard_False) {
2401 V->FitAll3d();
2402 } else if (aView.IsNull() == Standard_False) {
2403 aView->FitAll();
2404 }
2405 return 0;
2406}
2407
2408//==============================================================================
2409//function : VZFit
2410//purpose : ZFitall, no DRAW arguments
2411//Draw arg : No args
2412//==============================================================================
2413
2414static int VZFit(Draw_Interpretor& , Standard_Integer , const char** )
2415{
2416 Handle(V3d_View) V = ViewerTest::CurrentView();
2417 if ( !V.IsNull() ) V->ZFitAll(); return 0; }
2418
2419
2420static int VRepaint(Draw_Interpretor& , Standard_Integer , const char** )
2421{
2422 Handle(V3d_View) V = ViewerTest::CurrentView();
2423 if ( !V.IsNull() ) V->Redraw(); return 0;
2424}
2425
2426
2427//==============================================================================
2428//function : VClear
2429//purpose : Remove all the object from the viewer
2430//Draw arg : No args
2431//==============================================================================
2432
2433static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2434{
2435 Handle(V3d_View) V = ViewerTest::CurrentView();
2436 if(!V.IsNull())
2437 ViewerTest::Clear();
2438 return 0;
2439}
2440
2441//==============================================================================
2442//function : VPick
2443//purpose :
2444//==============================================================================
2445
2446static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2447{ if (ViewerTest::CurrentView().IsNull() ) return 1;
2448
2449if ( argc < 4 ) {
2450 di << argv[0] << "Invalid number of arguments" << "\n";
2451 return 1;
2452}
2453
2454while (ViewerMainLoop( argc, argv)) {
2455}
2456
2457return 0;
2458}
2459
7fd59977 2460//==============================================================================
2461//function : InitViewerTest
2462//purpose : initialisation de toutes les variables static de ViewerTest (dp)
2463//==============================================================================
2464
18d715bd 2465void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& theContext)
7fd59977 2466{
18d715bd 2467 Handle(V3d_Viewer) aViewer = theContext->CurrentViewer();
2468 ViewerTest::SetAISContext(theContext);
2469 aViewer->InitActiveViews();
2470 Handle(V3d_View) aView = aViewer->ActiveView();
2471 if (aViewer->MoreActiveViews()) ViewerTest::CurrentView(aView);
7fd59977 2472 ViewerTest::ResetEventManager();
18d715bd 2473 Handle(Aspect_Window) aWindow = aView->Window();
4fe56619 2474#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 2475 // X11
18d715bd 2476 VT_GetWindow() = Handle(Xw_Window)::DownCast(aWindow);
7fd59977 2477 OSWindowSetup();
18d715bd 2478 static int aFirst = 1;
2479 if ( aFirst ) {
7fd59977 2480#if TCL_MAJOR_VERSION < 8
18d715bd 2481 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 2482 TK_READABLE, VProcessEvents, (ClientData) 0);
2483#else
18d715bd 2484 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
7fd59977 2485 TK_READABLE, VProcessEvents, (ClientData) 0);
2486#endif
18d715bd 2487 aFirst = 0;
7fd59977 2488 }
2489#endif
2490}
2491
7fd59977 2492//==============================================================================
2493//function : VSetBg
2494//purpose : Load image as background
2495//==============================================================================
2496
2497static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2498{
2499 if (argc < 2 || argc > 3)
2500 {
2501 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
f8b2ed36 2502 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
7fd59977 2503 return 1;
2504 }
2505
2506 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2507 if(AISContext.IsNull())
2508 {
2509 di << "use 'vinit' command before " << argv[0] << "\n";
2510 return 1;
2511 }
2512
2513 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2514 if (argc == 3)
2515 {
2516 const char* szType = argv[2];
2517 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2518 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2519 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2520 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2521 else
2522 {
2523 di << "Wrong fill type : " << szType << "\n";
2524 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2525 return 1;
2526 }
2527 }
2528
2529 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2530 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2531
2532 return 0;
2533}
2534
2535//==============================================================================
f8b2ed36 2536//function : VSetBgMode
2537//purpose : Change background image fill type
2538//==============================================================================
2539
2540static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2541{
2542 if (argc != 2)
2543 {
2544 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2545 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2546 return 1;
2547 }
2548
2549 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2550 if(AISContext.IsNull())
2551 {
2552 di << "use 'vinit' command before " << argv[0] << "\n";
2553 return 1;
2554 }
1d47d8d0 2555 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2556 const char* szType = argv[1];
2557 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2558 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2559 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2560 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2561 else
f8b2ed36 2562 {
1d47d8d0 2563 di << "Wrong fill type : " << szType << "\n";
2564 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2565 return 1;
f8b2ed36 2566 }
f8b2ed36 2567 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2568 V3dView->SetBgImageStyle(aFillType, Standard_True);
f8b2ed36 2569 return 0;
2570}
2571
2572//==============================================================================
7fd59977 2573//function : VSetGradientBg
2574//purpose : Mount gradient background
2575//==============================================================================
2576static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2577{
2578 if (argc != 8 )
2579 {
2580 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2581 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2582 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2583 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2584 return 1;
2585 }
2586
2587 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2588 if(AISContext.IsNull())
2589 {
2590 di << "use 'vinit' command before " << argv[0] << "\n";
2591 return 1;
2592 }
2593 if (argc == 8)
2594 {
2595
91322f44 2596 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2597 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2598 Standard_Real B1 = Draw::Atof(argv[3])/255.;
7fd59977 2599 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2600
91322f44 2601 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2602 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2603 Standard_Real B2 = Draw::Atof(argv[6])/255.;
7fd59977 2604
2605 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
91322f44 2606 int aType = Draw::Atoi(argv[7]);
7fd59977 2607 if( aType < 0 || aType > 8 )
2608 {
2609 di << "Wrong fill type " << "\n";
2610 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2611 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2612 return 1;
2613 }
2614
2615 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2616
2617 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2618 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2619 }
2620
2621 return 0;
2622}
2623
2624//==============================================================================
f8b2ed36 2625//function : VSetGradientBgMode
2626//purpose : Change gradient background fill style
2627//==============================================================================
2628static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2629{
2630 if (argc != 2 )
2631 {
2632 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2633 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2634 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2635 return 1;
2636 }
2637
2638 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2639 if(AISContext.IsNull())
2640 {
2641 di << "use 'vinit' command before " << argv[0] << "\n";
2642 return 1;
2643 }
2644 if (argc == 2)
2645 {
91322f44 2646 int aType = Draw::Atoi(argv[1]);
f8b2ed36 2647 if( aType < 0 || aType > 8 )
2648 {
2649 di << "Wrong fill type " << "\n";
2650 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2651 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2652 return 1;
2653 }
2654
2655 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2656
2657 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2658 V3dView->SetBgGradientStyle( aMethod, 1 );
2659 }
2660
2661 return 0;
2662}
2663
2664//==============================================================================
2665//function : VSetColorBg
2666//purpose : Set color background
2667//==============================================================================
2668static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2669{
2670 if (argc != 4 )
2671 {
2672 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2673 di << "R,G,B = [0..255]" << "\n";
2674 return 1;
2675 }
2676
2677 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2678 if(AISContext.IsNull())
2679 {
2680 di << "use 'vinit' command before " << argv[0] << "\n";
2681 return 1;
2682 }
2683 if (argc == 4)
2684 {
2685
91322f44 2686 Standard_Real R = Draw::Atof(argv[1])/255.;
2687 Standard_Real G = Draw::Atof(argv[2])/255.;
2688 Standard_Real B = Draw::Atof(argv[3])/255.;
f8b2ed36 2689 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2690
2691 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2692 V3dView->SetBackgroundColor( aColor );
2693 V3dView->Update();
2694 }
2695
2696 return 0;
2697}
2698
2699//==============================================================================
7fd59977 2700//function : VScale
2701//purpose : View Scaling
2702//==============================================================================
2703
2704static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2705{
2706 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2707 if ( V3dView.IsNull() ) return 1;
2708
2709 if ( argc != 4 ) {
2710 di << argv[0] << "Invalid number of arguments" << "\n";
2711 return 1;
2712 }
91322f44 2713 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 2714 return 0;
2715}
2716//==============================================================================
2717//function : VTestZBuffTrihedron
7c8a8fcc 2718//purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
7fd59977 2719//==============================================================================
2720
2721static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2722{
2723 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2724 if ( V3dView.IsNull() ) return 1;
2725
7fd59977 2726 V3dView->ZBufferTriedronSetup();
7c8a8fcc 2727
2728 if ( argc == 1 ) {
2729 // Set up default trihedron parameters
2730 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2731 } else
2732 if ( argc == 7 )
2733 {
2734 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2735 const char* aPosType = argv[1];
2736
2737 if ( strcmp(aPosType, "center") == 0 )
2738 {
2739 aPosition = Aspect_TOTP_CENTER;
2740 } else
2741 if (strcmp(aPosType, "left_lower") == 0)
2742 {
2743 aPosition = Aspect_TOTP_LEFT_LOWER;
2744 } else
2745 if (strcmp(aPosType, "left_upper") == 0)
2746 {
2747 aPosition = Aspect_TOTP_LEFT_UPPER;
2748 } else
2749 if (strcmp(aPosType, "right_lower") == 0)
2750 {
2751 aPosition = Aspect_TOTP_RIGHT_LOWER;
2752 } else
2753 if (strcmp(aPosType, "right_upper") == 0)
2754 {
2755 aPosition = Aspect_TOTP_RIGHT_UPPER;
2756 } else
2757 {
2758 di << argv[1] << " Invalid type of alignment" << "\n";
2759 di << "Must be one of [ center, left_lower," << "\n";
2760 di << "left_upper, right_lower, right_upper ]" << "\n";
2761 return 1;
2762 }
2763
91322f44 2764 Standard_Real R = Draw::Atof(argv[2])/255.;
2765 Standard_Real G = Draw::Atof(argv[3])/255.;
2766 Standard_Real B = Draw::Atof(argv[4])/255.;
7c8a8fcc 2767 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2768
91322f44 2769 Standard_Real aScale = Draw::Atof(argv[5]);
7c8a8fcc 2770
2771 if( aScale <= 0.0 )
2772 {
2773 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2774 return 1;
2775 }
2776
2777 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2778 const char* aPresType = argv[6];
2779
2780 if ( strcmp(aPresType, "wireframe") == 0 )
2781 {
2782 aPresentation = V3d_WIREFRAME;
2783 } else
2784 if (strcmp(aPresType, "zbuffer") == 0)
2785 {
2786 aPresentation = V3d_ZBUFFER;
2787 } else
2788 {
2789 di << argv[6] << " Invalid type of visualization" << "\n";
2790 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2791 return 1;
2792 }
2793
2794 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2795
2796 } else
2797 {
2798 di << argv[0] << " Invalid number of arguments" << "\n";
2799 return 1;
2800 }
2801
7fd59977 2802 V3dView->ZFitAll();
7c8a8fcc 2803
7fd59977 2804 return 0;
2805}
2806
2807//==============================================================================
2808//function : VRotate
2809//purpose : Camera Rotating
2810//==============================================================================
2811
2812static int VRotate( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2813 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2814 if ( V3dView.IsNull() ) {
2815 return 1;
2816 }
2817
2818 if ( argc == 4 ) {
91322f44 2819 V3dView->Rotate( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
7fd59977 2820 return 0;
2821 } else if ( argc == 7 ) {
91322f44 2822 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 2823 return 0;
2824 } else {
2825 di << argv[0] << " Invalid number of arguments" << "\n";
2826 return 1;
2827 }
2828}
2829
2830//==============================================================================
2831//function : VZoom
2832//purpose : View zoom in / out (relative to current zoom)
2833//==============================================================================
2834
2835static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2836 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2837 if ( V3dView.IsNull() ) {
2838 return 1;
2839 }
2840
2841 if ( argc == 2 ) {
91322f44 2842 Standard_Real coef = Draw::Atof(argv[1]);
7fd59977 2843 if ( coef <= 0.0 ) {
2844 di << argv[1] << "Invalid value" << "\n";
2845 return 1;
2846 }
91322f44 2847 V3dView->SetZoom( Draw::Atof(argv[1]) );
7fd59977 2848 return 0;
2849 } else {
2850 di << argv[0] << " Invalid number of arguments" << "\n";
2851 return 1;
2852 }
2853}
2854
2855//==============================================================================
2856//function : VPan
2857//purpose : View panning (in pixels)
2858//==============================================================================
2859
2860static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
2861 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2862 if ( V3dView.IsNull() ) return 1;
2863
2864 if ( argc == 3 ) {
91322f44 2865 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
7fd59977 2866 return 0;
2867 } else {
2868 di << argv[0] << " Invalid number of arguments" << "\n";
2869 return 1;
2870 }
2871}
2872
2873
2874//==============================================================================
2875//function : VExport
5cedc27f 2876//purpose : Export the view to a vector graphic format (PS, EMF, PDF)
7fd59977 2877//==============================================================================
2878
2879static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2880{
2881 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
5cedc27f
K
2882 if (V3dView.IsNull())
2883 return 1;
7fd59977 2884
5cedc27f
K
2885 if (argc == 1)
2886 {
2887 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
7fd59977 2888 return 1;
2889 }
2890
5cedc27f
K
2891 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
2892 TCollection_AsciiString aFormatStr;
2893
2894 TCollection_AsciiString aFileName (argv[1]);
2895 Standard_Integer aLen = aFileName.Length();
2896
2897 if (argc > 2)
2898 {
2899 aFormatStr = TCollection_AsciiString (argv[2]);
2900 }
2901 else if (aLen >= 4)
2902 {
2903 if (aFileName.Value (aLen - 2) == '.')
2904 {
2905 aFormatStr = aFileName.SubString (aLen - 1, aLen);
2906 }
2907 else if (aFileName.Value (aLen - 3) == '.')
2908 {
2909 aFormatStr = aFileName.SubString (aLen - 2, aLen);
2910 }
2911 else
2912 {
2913 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2914 return 1;
2915 }
2916 }
2917 else
2918 {
2919 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
2920 return 1;
2921 }
2922
2923 aFormatStr.UpperCase();
2924 if (aFormatStr == "PS")
2925 anExpFormat = Graphic3d_EF_PostScript;
2926 else if (aFormatStr == "EPS")
2927 anExpFormat = Graphic3d_EF_EnhPostScript;
2928 else if (aFormatStr == "TEX")
2929 anExpFormat = Graphic3d_EF_TEX;
2930 else if (aFormatStr == "PDF")
2931 anExpFormat = Graphic3d_EF_PDF;
2932 else if (aFormatStr == "SVG")
2933 anExpFormat = Graphic3d_EF_SVG;
2934 else if (aFormatStr == "PGF")
2935 anExpFormat = Graphic3d_EF_PGF;
2936 else if (aFormatStr == "EMF")
2937 anExpFormat = Graphic3d_EF_EMF;
2938 else
2939 {
2940 std::cout << "Invalid export format '" << aFormatStr << "'\n";
2941 return 1;
2942 }
2943
9753e6de 2944 try {
2945 if (!V3dView->View()->Export (argv[1], anExpFormat))
2946 {
2947 di << "Error: export of image to " << aFormatStr << " failed!\n";
2948 }
2949 }
2950 catch (Standard_Failure)
5cedc27f 2951 {
9753e6de 2952 di << "Error: export of image to " << aFormatStr << " failed";
2953 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
5cedc27f 2954 }
7fd59977 2955 return 0;
2956}
2957
2958//==============================================================================
2959//function : VColorScale
2960//purpose : representation color scale
2961//==============================================================================
2962#include <V3d_ColorScale.hxx>
2963
2964static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
2965{
2966 if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
2967 {
2968 di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0] " << "\n";
2969 return 1;
2970 }
2971
2972 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2973 if(aContext.IsNull()) {
2974 di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
2975 return -1;
2976 }
2977
2978 Standard_Real minRange = 0. , maxRange = 100. ;
2979
2980 Standard_Integer numIntervals = 10 ;
208e6839 2981 Standard_Integer textHeight = 16;
7fd59977 2982 Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
2983 Standard_Real X = 0., Y = 0. ;
2984
2985 if ( argc < 9 )
2986 {
2987 if( argc > 3 )
2988 {
91322f44 2989 minRange = Draw::Atof( argv[1] );
2990 maxRange = Draw::Atof( argv[2] );
2991 numIntervals = Draw::Atoi( argv[3] );
7fd59977 2992 }
2993 if ( argc > 4 )
91322f44 2994 textHeight = Draw::Atoi( argv[4] );
7fd59977 2995 if ( argc > 5 )
91322f44 2996 position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
7fd59977 2997 if ( argc > 7 )
2998 {
91322f44 2999 X = Draw::Atof( argv[6] );
3000 Y = Draw::Atof( argv[7] );
7fd59977 3001 }
3002 }
3003 Handle(V3d_View) curView = ViewerTest::CurrentView( );
3004 if ( curView.IsNull( ) )
3005 return 1;
3006 Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
3007 Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
3008 if( ! aCS.IsNull( ) )
3009 {
3010 aCS->SetPosition( X , Y );
3011 aCS->SetHeight( 0.95) ;
3012 aCS->SetTextHeight( textHeight );
3013 aCS->SetRange( minRange , maxRange );
3014 aCS->SetNumberOfIntervals( numIntervals );
3015 aCS->SetLabelPosition( position );
3016 if( !curView->ColorScaleIsDisplayed() )
3017 curView->ColorScaleDisplay( );
3018 }
3019 return 0;
3020}
3021
3022//==============================================================================
3023//function : VGraduatedTrihedron
3024//purpose : Displays a graduated trihedron
3025//==============================================================================
13a22457
S
3026
3027static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3028{
3029 const char *str = arg;
3030 while (*str)
3031 {
3032 unsigned short c1 = *str++;
3033 unsigned short c2 = *str++;
3034 if (!c1 || !c2) break;
3035 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3036 }
3037}
3038
7fd59977 3039static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3040{
13a22457
S
3041 // Check arguments
3042 if (argc != 2 && argc < 5)
3043 {
3044 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3045 di<<"Usage: type help "<<argv[0]<<"\n";
3046 return 1; //TCL_ERROR
3047 }
7fd59977 3048
13a22457
S
3049 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3050
3051 // Create 3D view if it doesn't exist
3052 if ( aV3dView.IsNull() )
7fd59977 3053 {
4fe56619 3054 ViewerTest::ViewerInit();
13a22457
S
3055 aV3dView = ViewerTest::CurrentView();
3056 if( aV3dView.IsNull() )
3057 {
3058 di << "Error: Cannot create a 3D view\n";
3059 return 1; //TCL_ERROR
3060 }
7fd59977 3061 }
3062
13a22457 3063 // Erase (==0) or display (!=0)
91322f44 3064 const int display = Draw::Atoi(argv[1]);
7fd59977 3065
13a22457 3066 if (display)
7fd59977 3067 {
13a22457
S
3068 // Text font
3069 TCollection_AsciiString font;
3070 if (argc < 6)
3071 font.AssignCat("Courier");
3072 else
3073 font.AssignCat(argv[5]);
3074
3075 // Text is multibyte
91322f44 3076 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
13a22457
S
3077
3078 // Set axis names
3079 TCollection_ExtendedString xname, yname, zname;
3080 if (argc >= 5)
3081 {
3082 if (isMultibyte)
7fd59977 3083 {
13a22457
S
3084 AddMultibyteString(xname, argv[2]);
3085 AddMultibyteString(yname, argv[3]);
3086 AddMultibyteString(zname, argv[4]);
7fd59977 3087 }
13a22457
S
3088 else
3089 {
3090 xname += argv[2];
3091 yname += argv[3];
3092 zname += argv[4];
3093 }
3094 }
3095 else
3096 {
3097 xname += "X (mm)";
3098 yname += "Y (mm)";
3099 zname += "Z (mm)";
3100 }
7fd59977 3101
13a22457
S
3102 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3103 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3104 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3105 Standard_True/*drawgrid*/,
3106 Standard_True/*drawaxes*/,
3107 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3108 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3109 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3110 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3111 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3112 Quantity_NOC_WHITE/*gridcolor*/,
3113 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3114 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3115 }
7fd59977 3116 else
13a22457 3117 aV3dView->GraduatedTrihedronErase();
7fd59977 3118
3119 ViewerTest::GetAISContext()->UpdateCurrentViewer();
13a22457
S
3120 aV3dView->Redraw();
3121
7fd59977 3122 return 0;
3123}
3124
7edf74fd
A
3125//==============================================================================
3126//function : VPrintView
3127//purpose : Test printing algorithm, print the view to image file with given
3128// width and height. Printing implemented only for WNT.
3129//==============================================================================
4fe56619 3130static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
7edf74fd
A
3131 const char** argv)
3132{
3133#ifndef WNT
3134 di << "Printing implemented only for wnt!\n";
3135 return 1;
3136#else
3137
3138 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3139 Handle(V3d_View) aView = NULL;
3140 aContextAIS = ViewerTest::GetAISContext();
3141 if (!aContextAIS.IsNull())
3142 {
3143 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3144 Vwr->InitActiveViews();
3145 if(Vwr->MoreActiveViews())
3146 aView = Vwr->ActiveView();
3147 }
3148
3149 // check for errors
3150 if (aView.IsNull())
3151 {
3152 di << "Call vinit before!\n";
3153 return 1;
3154 }
3155 else if (argc < 4)
3156 {
3157 di << "Use: " << argv[0];
3158 di << " width height filename [print algo=0]\n";
3159 di << "width, height of the intermediate buffer for operation\n";
3160 di << "algo : {0|1}\n";
3161 di << " 0 - stretch algorithm\n";
3162 di << " 1 - tile algorithm\n";
3163 di << "test printing algorithms into an intermediate buffer\n";
3164 di << "with saving output to an image file\n";
3165 return 1;
3166 }
3167
3168 // get the input params
91322f44 3169 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3170 Standard_Integer aHeight = Draw::Atoi (argv[2]);
7edf74fd
A
3171 Standard_Integer aMode = 0;
3172 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3173 if (argc==5)
91322f44 3174 aMode = Draw::Atoi (argv[4]);
7edf74fd
A
3175
3176 // check the input parameters
3177 if (aWidth <= 0 || aHeight <= 0)
3178 {
3179 di << "Width and height must be positive values!\n";
3180 return 1;
3181 }
3182 if (aMode != 0 && aMode != 1)
3183 aMode = 0;
3184
7edf74fd 3185 // define compatible bitmap
692613e5 3186 HDC anDC = CreateCompatibleDC(0);
7edf74fd
A
3187 BITMAPINFO aBitmapData;
3188 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3189 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3190 aBitmapData.bmiHeader.biWidth = aWidth ;
3191 aBitmapData.bmiHeader.biHeight = aHeight;
3192 aBitmapData.bmiHeader.biPlanes = 1;
3193 aBitmapData.bmiHeader.biBitCount = 24;
3194 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3195 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3196 aBitmapData.bmiHeader.biClrUsed = 0;
3197 aBitmapData.bmiHeader.biClrImportant = 0;
3198 aBitmapData.bmiHeader.biCompression = BI_RGB;
3199 aBitmapData.bmiHeader.biSizeImage = 0;
3200
3201 // Create Device Independent Bitmap
692613e5 3202 void* aBitsOut = NULL;
7edf74fd 3203 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
692613e5 3204 &aBitsOut, NULL, 0);
7edf74fd
A
3205 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3206
3207 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
692613e5 3208 if (aBitsOut != NULL)
4fe56619 3209 {
7edf74fd
A
3210 if (aMode == 0)
3211 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3212 else
3213 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_TILE);
3214
3215 // succesfully printed into an intermediate buffer
3216 if (isPrinted)
3217 {
692613e5 3218 Image_PixMap aWrapper;
3219 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3220 aWrapper.SetTopDown (false);
3221
3222 Image_AlienPixMap anImageBitmap;
3223 anImageBitmap.InitCopy (aWrapper);
3224 isSaved = anImageBitmap.Save (aFileName);
7edf74fd
A
3225 }
3226 else
3227 {
3228 di << "Print operation failed due to printing errors or\n";
3229 di << "insufficient memory available\n";
3230 di << "Please, try to use smaller dimensions for this test\n";
3231 di << "command, as it allocates intermediate buffer for storing\n";
3232 di << "the result\n";
3233 }
3234 }
3235 else
3236 {
3237 di << "Can't allocate memory for intermediate buffer\n";
3238 di << "Please use smaller dimensions\n";
3239 }
3240
3241 if (aMemoryBitmap)
3242 {
3243 SelectObject (anDC, anOldBitmap);
3244 DeleteObject (aMemoryBitmap);
3245 DeleteDC(anDC);
3246 }
3247
3248 if (!isSaved)
3249 {
3250 di << "Save to file operation failed. This operation may fail\n";
3251 di << "if you don't have enough available memory, then you can\n";
3252 di << "use smaller dimensions for the output file\n";
3253 return 1;
3254 }
3255
3256 return 0;
3257
3258#endif
3259}
3260
59f45b7c 3261//==============================================================================
3262//function : VZLayer
3263//purpose : Test z layer operations for v3d viewer
3264//==============================================================================
3265static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3266{
3267 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3268 if (aContextAIS.IsNull())
3269 {
3270 di << "Call vinit before!\n";
3271 return 1;
3272 }
3273 else if (argc < 2)
3274 {
3275 di << "Use: vzlayer " << argv[0];
3276 di << " add/del/get [id]\n";
3277 di << " add - add new z layer to viewer and print its id\n";
3278 di << " del - del z layer by its id\n";
3279 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3280 di << "id - the layer identificator value defined when removing z layer\n";
3281 return 1;
3282 }
3283
3284 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3285 if (aViewer.IsNull())
3286 {
3287 di << "No active viewer!\n";
3288 return 1;
3289 }
3290
3291 // perform operation
3292 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3293 if (anOp == "add")
3294 {
3295 Standard_Integer aNewId;
3296 if (!aViewer->AddZLayer (aNewId))
3297 {
3298 di << "Impossible to add new z layer!\n";
3299 return 1;
3300 }
3301
3302 di << "New z layer added with index: " << aNewId << "\n";
3303 }
3304 else if (anOp == "del")
3305 {
3306 if (argc < 3)
3307 {
3308 di << "Please also provide as argument id of z layer to remove\n";
3309 return 1;
3310 }
3311
91322f44 3312 Standard_Integer aDelId = Draw::Atoi (argv[2]);
59f45b7c