0022590: Migration to FreeImage - revision of Xw and WNT packages
[occt.git] / src / ViewerTest / ViewerTest_Tool.cxx
1 // Created on: 1998-10-15
2 // Created by: Denis PASCAL
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
21
22 #ifdef WNT
23 #include <windows.h>
24 #endif
25
26 #include <ViewerTest_Tool.ixx>
27
28 #include <V3d_View.hxx>
29 #include <AIS_InteractiveContext.hxx>
30 #include <ViewerTest.hxx>
31 #include <string.h>
32 #include <Draw_Interpretor.hxx>
33 #include <Draw.hxx>
34 #include <Draw_Appli.hxx>
35 #include <DBRep.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <V3d_Viewer.hxx>
38 #include <V3d_View.hxx>
39 #include <V3d.hxx>
40 #include <AIS_DisplayMode.hxx>
41 #include <TColStd_MapOfInteger.hxx>
42 #include <AIS_MapOfInteractive.hxx>
43 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
44 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_EventManager.hxx>
46 #include <Draw_Window.hxx>
47 #include <AIS_ListIteratorOfListOfInteractive.hxx>
48 #include <AIS_ListOfInteractive.hxx>
49 #include <Aspect_Window.hxx>
50 #include <Aspect_DisplayConnection.hxx>
51 #include <Graphic3d.hxx>
52 #include <Graphic3d_GraphicDriver.hxx>
53
54 #if defined(_WIN32) || defined(__WIN32__)
55 #include <WNT_WClass.hxx>
56 #include <WNT_Window.hxx>
57 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
58 #include <Cocoa_Window.hxx>
59 #else
60 #include <X11/Xlib.h>
61 #include <X11/Xutil.h>
62 #include <Xw_Window.hxx>
63 #endif
64
65 //==============================================================================
66 //  GLOBAL VARIABLES
67 //==============================================================================
68 #define ZCLIPWIDTH 1.
69
70 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
71 {
72   static Handle(Aspect_DisplayConnection) aDisplayConnection;
73   static Standard_Boolean isFirst = Standard_True;
74   if (isFirst)
75   {
76     aDisplayConnection = new Aspect_DisplayConnection();
77     isFirst = Standard_False;
78   }
79   return aDisplayConnection;
80 }
81
82 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
83
84 //=======================================================================
85 //function : MakeViewer
86 //purpose  :
87 //=======================================================================
88
89 Handle(V3d_Viewer) ViewerTest_Tool::MakeViewer (const Standard_CString theTitle)
90 {
91 #if defined(_WIN32) || defined(__WIN32__)
92   Handle(Aspect_Window) window = new WNT_Window (theTitle,
93                                                  Handle(WNT_WClass)::DownCast (ViewerTest::WClass()),
94                                                  WS_OVERLAPPEDWINDOW, 0, 460, 409, 409, Quantity_NOC_BLACK);
95 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
96   Handle(Aspect_Window) window = new Cocoa_Window (theTitle, 0, 460, 409, 409);
97 #else
98   Handle(Aspect_Window) window = new Xw_Window (GetDisplayConnection(), theTitle, 0, 460, 409, 409);
99 #endif
100   window->SetVirtual (Draw_VirtualWindows);
101   window->Map();
102
103   // Viewer
104   Handle(Graphic3d_GraphicDriver) aDriver = Graphic3d::InitGraphicDriver (GetDisplayConnection());
105   TCollection_ExtendedString NameOfWindow("Visu3D");
106   Handle(V3d_Viewer) a3DViewer = new V3d_Viewer(aDriver,NameOfWindow.ToExtString());
107
108   a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
109   a3DViewer->SetDefaultLights();
110   a3DViewer->SetLightOn();
111
112   // View
113   Handle (V3d_View) V = a3DViewer->CreateView();
114   V->SetWindow(window);
115   V->SetZClippingDepth(0.5);
116   V->SetZClippingWidth(ZCLIPWIDTH/2.);
117
118   return a3DViewer;
119 }
120
121 //=======================================================================
122 //function : MakeContext
123 //purpose  :
124 //=======================================================================
125
126 Handle(AIS_InteractiveContext)  ViewerTest_Tool::MakeContext (const Standard_CString title)
127 {
128   return new AIS_InteractiveContext (MakeViewer(title));
129 }
130
131
132
133 //=======================================================================
134 //function : InitViewerTest
135 //purpose  :
136 //=======================================================================
137
138 // ********* next method is defined in ViewerTest_ViewerCommands.hxx ****
139 extern void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)&);
140 // **********************************************************************
141
142 void  ViewerTest_Tool::InitViewerTest (const Handle(AIS_InteractiveContext)& context)
143 {
144   ViewerTest_InitViewerTest (context);
145 }
146