7390a93816ed2006c52116d36916088497e94493
[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 <Graphic3d_GraphicDevice.hxx>
37 #include <Xw_GraphicDevice.hxx>
38 #include <Xw_WindowQuality.hxx>
39 #include <Xw_Window.hxx>
40 #include <Graphic3d_GraphicDevice.hxx>
41 #include <Xw_GraphicDevice.hxx>
42 #include <Xw_WindowQuality.hxx>
43 #include <Xw_Window.hxx>
44 #include <TCollection_AsciiString.hxx>
45 #include <V3d_Viewer.hxx>
46 #include <V3d_View.hxx>
47 #include <V3d.hxx>
48 #include <AIS_DisplayMode.hxx>
49 #include <TColStd_MapOfInteger.hxx>
50 #include <AIS_MapOfInteractive.hxx>
51 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
52 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
53 #include <ViewerTest_EventManager.hxx>
54 #include <Draw_Window.hxx>
55 #include <AIS_ListIteratorOfListOfInteractive.hxx>
56 #include <AIS_ListOfInteractive.hxx>
57 #include <Aspect_Window.hxx>
58
59
60 #ifndef WNT
61 #include <X11/Xlib.h>
62 #include <X11/Xutil.h>
63 #else
64 #include <WNT_WClass.hxx>
65 #include <WNT_Window.hxx>
66 #include <Graphic3d_WNTGraphicDevice.hxx>
67 #endif
68
69
70
71
72
73 //==============================================================================
74 //  GLOBAL VARIABLES
75 //==============================================================================
76 #define ZCLIPWIDTH 1.
77
78 #ifdef WNT
79
80 static Handle(Graphic3d_WNTGraphicDevice) GetDevice() { 
81   static Handle(Graphic3d_WNTGraphicDevice) myDevice;
82   static int first = 1;
83   if ( first ) myDevice = new Graphic3d_WNTGraphicDevice();
84   first = 0;
85   return myDevice;
86 }
87
88 #else
89
90 static Handle(Graphic3d_GraphicDevice)& GetDevice() {
91   static Handle(Graphic3d_GraphicDevice) myDevice;
92   static int first = 1;
93   if ( first ) myDevice = new Graphic3d_GraphicDevice (getenv("DISPLAY"),Xw_TOM_READONLY);
94   first = 0;
95   return myDevice;
96 }
97
98 //static Display *display;
99
100 #endif
101
102
103 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
104
105 //=======================================================================
106 //function : MakeViewer
107 //purpose  : 
108 //=======================================================================
109
110 Handle(V3d_Viewer)  ViewerTest_Tool::MakeViewer (const Standard_CString title)
111 {
112
113   Handle(Aspect_Window) window;
114
115 #ifdef WNT
116
117   window = new WNT_Window (GetDevice(), 
118                            title, 
119                            Handle(WNT_WClass)::DownCast (ViewerTest::WClass()), 
120                            WS_OVERLAPPEDWINDOW,
121                            0,460,409,409,
122                            Quantity_NOC_BLACK);
123   window->Map();
124
125 #else 
126   window = new Xw_Window(GetDevice(), 
127                          title,
128                          0,460,409,409,
129                          Xw_WQ_3DQUALITY,
130                          Quantity_NOC_BLACK);
131 #endif
132   window->SetVirtual (Draw_VirtualWindows);
133
134   // Viewer
135
136   Handle(Aspect_GraphicDevice) theDevice = GetDevice();
137   TCollection_ExtendedString NameOfWindow("Visu3D");
138   Handle(V3d_Viewer) a3DViewer = new V3d_Viewer(theDevice,NameOfWindow.ToExtString());
139
140
141   a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);  
142   a3DViewer->SetDefaultLights();
143   a3DViewer->SetLightOn();  
144   
145   // View 
146   Handle (V3d_View) V = a3DViewer->CreateView();
147   V->SetDegenerateModeOn();
148   V->SetWindow(window);
149   V->SetZClippingDepth(0.5);
150   V->SetZClippingWidth(ZCLIPWIDTH/2.);
151
152   return a3DViewer;
153 }
154
155 //=======================================================================
156 //function : MakeContext
157 //purpose  : 
158 //=======================================================================
159
160 Handle(AIS_InteractiveContext)  ViewerTest_Tool::MakeContext (const Standard_CString title)
161 {
162   return new AIS_InteractiveContext (MakeViewer(title));
163 }
164
165
166
167 //=======================================================================
168 //function : InitViewerTest
169 //purpose  : 
170 //=======================================================================
171
172 // ********* next method is defined in ViewerTest_ViewerCommands.hxx ****
173 extern void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)&);
174 // **********************************************************************
175
176 void  ViewerTest_Tool::InitViewerTest (const Handle(AIS_InteractiveContext)& context)
177 {  
178   ViewerTest_InitViewerTest (context);
179
180