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