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