0023654: Problem with displaying vertices in OCC view after closing all OCC views...
[occt.git] / src / Graphic3d / Graphic3d_GraphicDriver.cxx
1 // Created on: 1997-01-28
2 // Created by: CAL
3 // Copyright (c) 1997-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 //              11/97 ; CAL : retrait de la dependance avec math
22
23
24 //-Version  
25
26 //-Design Declaration des variables specifiques aux Drivers
27
28 //-Warning  Un driver encapsule les Pex, Phigs et OpenGl drivers
29
30 //-References 
31
32 //-Language C++ 2.0
33
34 //-Declarations
35
36 // for the class
37 #include <Graphic3d_GraphicDriver.ixx>
38
39 #include <Aspect_DriverDefinitionError.hxx>
40
41 //-Aliases
42
43 //-Global data definitions
44
45 //-Constructors
46
47 Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Standard_CString AShrName) {
48
49   SetTrace (0);
50   MySharedLibrary.SetName (AShrName);
51   myDeviceLostFlag = Standard_False;
52
53   //if (! MySharedLibrary.DlOpen (OSD_RTLD_LAZY))
54   //Aspect_DriverDefinitionError::Raise (MySharedLibrary.DlError ());
55
56 }
57
58 //-Methods, in order
59
60 Standard_Integer Graphic3d_GraphicDriver::Light (const Graphic3d_CLight& ACLight, const Standard_Boolean Update) {
61
62   static Standard_Integer NbLights = 1;
63   Standard_Boolean Result;
64
65   Result = Update ? ACLight.LightId : NbLights++;
66   return Result;
67
68 }
69
70 //-Internal methods, in order
71
72 void Graphic3d_GraphicDriver::PrintBoolean (const Standard_CString AComment, const Standard_Boolean AValue) const {
73
74   cout << "\t" << AComment << " : "
75     << (AValue ? "True" : "False") << "\n";
76   cout << flush;
77
78 }
79
80 void Graphic3d_GraphicDriver::PrintCGroup (const Graphic3d_CGroup& ACGroup, const Standard_Integer AField) const {
81
82   if (AField) {
83     cout << "\tstruct id " << ACGroup.Struct->Id << "\n";
84     cout << "\tgroup\n";
85     cout << flush;
86   }
87
88 }
89
90 void Graphic3d_GraphicDriver::PrintCLight (const Graphic3d_CLight& ACLight, const Standard_Integer AField) const {
91
92   if (AField) {
93     cout << "\tws id " << ACLight.WsId << ", "
94       << "view id " << ACLight.ViewId << "\n";
95     switch (ACLight.LightType) {
96     case 0 :
97       cout << "\tlight type : ambient\n";
98       break;
99     case 1 :
100       cout << "\tlight type : directional\n";
101       break;
102     case 2 :
103       cout << "\tlight type : positional\n";
104       break;
105     case 3 :
106       cout << "\tlight type : spot\n";
107       break;
108     default :
109       cout << "\tlight type : undefined, error\n";
110       break;
111     }
112     cout << flush;
113   }
114
115 }
116
117 void Graphic3d_GraphicDriver::PrintCPick (const Graphic3d_CPick& ACPick, const Standard_Integer AField) const {
118
119   if (AField) {
120     cout << "\tws id " << ACPick.WsId
121       << " view id " << ACPick.ViewId << "\n";
122     cout << "\twindow id " << ACPick.DefWindow.XWindow << "\n";
123     cout << "\tposition " << ACPick.x << " , " << ACPick.y << "\n";
124     cout << flush;
125   }
126
127 }
128
129 void Graphic3d_GraphicDriver::PrintCStructure (const Graphic3d_CStructure& ACStructure, const Standard_Integer AField) const {
130
131   if (AField) {
132     cout << "\tstruct id " << ACStructure.Id << "\n";
133     cout << flush;
134   }
135
136 }
137
138 void Graphic3d_GraphicDriver::PrintCView (const Graphic3d_CView& ACView, const Standard_Integer AField) const {
139
140   if (AField) {
141     cout << "\tws id " << ACView.WsId << ", "
142       << "view id " << ACView.ViewId << "\n";
143     cout << "\tXwindow id " << ACView.DefWindow.XWindow << ", "
144       << "activity " << ACView.Active << "\n";
145     cout << flush;
146   }
147
148 }
149
150 void Graphic3d_GraphicDriver::PrintFunction (const Standard_CString AFunc) const {
151
152   cout << AFunc << "\n";
153   cout << flush;
154
155 }
156
157 void Graphic3d_GraphicDriver::PrintInteger (const Standard_CString AComment, const Standard_Integer AValue) const {
158
159   cout << "\t" << AComment << " : " << AValue << "\n";
160   cout << flush;
161
162 }
163
164 void Graphic3d_GraphicDriver::PrintIResult (const Standard_CString AFunc, const Standard_Integer AResult) const {
165
166   cout << AFunc << " = " << AResult << "\n";
167   cout << flush;
168
169 }
170
171 void Graphic3d_GraphicDriver::PrintMatrix (const Standard_CString AComment, const TColStd_Array2OfReal& AMatrix) const {
172
173   Standard_Integer lr, ur, lc, uc;
174   Standard_Integer i, j;
175
176   lr = AMatrix.LowerRow ();
177   ur = AMatrix.UpperRow ();
178   lc = AMatrix.LowerCol ();
179   uc = AMatrix.UpperCol ();
180
181   if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
182     Graphic3d_TransformError::Raise
183     ("PrintMatrix : not a 4x4 matrix");
184
185   cout << "\t" << AComment << " :\n";
186   for (i=lr; i<=ur; i++) {
187     for (j=lc; j<=uc; j++) {
188       cout << AMatrix (i, j) << " ";
189     }
190     cout << "\n";
191   }
192   cout << flush;
193
194 }
195
196 void Graphic3d_GraphicDriver::PrintShortReal (const Standard_CString AComment, const Standard_ShortReal AValue) const {
197
198   cout << "\t" << AComment << " : " << AValue << "\n";
199   cout << flush;
200
201 }
202
203 void Graphic3d_GraphicDriver::PrintString (const Standard_CString AComment, const Standard_CString AString) const {
204
205   cout << "\t" << AComment << " : " << AString << "\n";
206   cout << flush;
207
208 }
209
210 void Graphic3d_GraphicDriver::SetTrace (const Standard_Integer ALevel) {
211
212   MyTraceLevel = ALevel;
213
214 }
215
216 Standard_Integer Graphic3d_GraphicDriver::Trace () const {
217
218   return MyTraceLevel;
219
220 }
221
222 const Handle(Aspect_DisplayConnection)& Graphic3d_GraphicDriver::GetDisplayConnection() const
223 {
224   return myDisplayConnection;
225 }
226
227 Standard_Boolean Graphic3d_GraphicDriver::IsDeviceLost() const
228 {
229   return myDeviceLostFlag;
230 }
231
232 void Graphic3d_GraphicDriver::ResetDeviceLostFlag()
233 {
234   myDeviceLostFlag = Standard_False;
235 }