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