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