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