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