b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | /*********************************************************************** |
19 | |
20 | FONCTION : |
21 | ---------- |
22 | Classe V3d_Viewer : |
23 | |
24 | HISTORIQUE DES MODIFICATIONS : |
25 | -------------------------------- |
26 | 00-09-92 : GG ; Creation. |
27 | 15-11-97 : FMN ; Ajout texture mapping |
28 | 02-02-98 : FMN ; Mise a niveau WNT |
29 | 23-02-98 : FMN ; Remplacement PI par Standard_PI |
30 | 16-07-98 : CAL ; S3892. Ajout grilles 3d. |
31 | |
32 | ************************************************************************/ |
33 | |
b8ddfc2f |
34 | //GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor() and DefaultBackgroundColor() methods |
7fd59977 |
35 | |
36 | #define IMP240100 //GG |
37 | // Initalize grid echo fields |
38 | |
39 | /*----------------------------------------------------------------------*/ |
40 | /* |
41 | * Includes |
42 | */ |
43 | |
44 | #include <V3d.hxx> |
45 | #include <Visual3d_View.hxx> |
46 | #include <Visual3d_Light.hxx> |
47 | #include <V3d_Viewer.ixx> |
48 | #include <V3d_View.hxx> |
49 | #include <Viewer_BadValue.hxx> |
50 | #include <V3d_OrthographicView.hxx> |
51 | #include <V3d_PerspectiveView.hxx> |
52 | #ifdef WNT |
53 | #include <WNT_GraphicDevice.hxx> |
54 | #endif |
55 | |
56 | /*----------------------------------------------------------------------*/ |
57 | |
58 | //-Constructor: |
59 | V3d_Viewer::V3d_Viewer(const Handle(Aspect_GraphicDevice)& Device , const Standard_ExtString aName, const Standard_CString aDomain,const Standard_Real ViewSize , const V3d_TypeOfOrientation ViewProj , const Quantity_NameOfColor ViewBackground , const V3d_TypeOfVisualization Visualization , const V3d_TypeOfShadingModel ShadingModel , const V3d_TypeOfUpdate UpdateMode, const Standard_Boolean ComputedMode , const Standard_Boolean DefaultComputedMode , const V3d_TypeOfSurfaceDetail SurfaceDetail ) |
60 | :Viewer_Viewer(Device,aName,aDomain,-1), |
61 | MyDefinedViews(), |
62 | MyActiveViews(), |
63 | MyDefinedLights(), |
64 | MyActiveLights(), |
65 | MyDefinedPlanes(), |
66 | myActiveViewsIterator(), |
67 | myDefinedViewsIterator(), |
68 | myActiveLightsIterator(), |
69 | myDefinedLightsIterator(), |
70 | myDefinedPlanesIterator(), |
71 | myComputedMode(ComputedMode), |
72 | myDefaultComputedMode(DefaultComputedMode), |
73 | myPrivilegedPlane(gp_Ax3(gp_Pnt(0.,0.,0),gp_Dir(0.,0.,1.),gp_Dir(1.,0.,0.))), |
74 | myDisplayPlane(Standard_False), |
75 | myDisplayPlaneLength(ViewSize) |
76 | #ifdef IMP240100 |
77 | ,myGridEcho(Standard_True),myGridEchoStructure(),myGridEchoGroup() |
78 | #endif |
79 | { |
80 | |
81 | MyViewer = new Visual3d_ViewManager(Device) ; |
82 | // san (16/09/2010): It has been decided to turn depth test ON |
83 | // by default, as this is important for new font rendering |
84 | // (without it, there are numerous texture rendering artefacts) |
85 | MyViewer->SetZBufferAuto (Standard_False); |
86 | SetUpdateMode( UpdateMode ) ; |
87 | SetDefaultViewSize(ViewSize) ; |
88 | SetDefaultViewProj(ViewProj) ; |
89 | SetDefaultBackgroundColor(ViewBackground) ; |
90 | SetDefaultVisualization(Visualization) ; |
91 | SetDefaultShadingModel(ShadingModel) ; |
92 | SetDefaultSurfaceDetail(SurfaceDetail) ; |
c6541a0c |
93 | SetDefaultAngle(M_PI / 2.); |
7fd59977 |
94 | SetDefaultTypeOfView(V3d_ORTHOGRAPHIC); |
95 | |
96 | Quantity_Color Color1 (Quantity_NOC_GRAY50); |
97 | Quantity_Color Color2 (Quantity_NOC_GRAY70); |
98 | // Quantity_Color White (Quantity_NOC_WHITE); |
99 | myRGrid = new V3d_RectangularGrid(this,Color1,Color2); |
100 | myCGrid = new V3d_CircularGrid(this,Color1,Color2); |
101 | myGridType = Aspect_GT_Rectangular; |
102 | } |
103 | |
104 | //-Methods, in order |
105 | |
106 | |
107 | Handle(V3d_View) V3d_Viewer::CreateView () { |
108 | if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC) |
109 | return new V3d_OrthographicView(this); |
110 | else |
111 | return new V3d_PerspectiveView(this); |
112 | } |
113 | |
114 | void V3d_Viewer::SetViewOn( ) { |
115 | |
116 | for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){ |
117 | SetViewOn(ActiveView());}; |
118 | } |
119 | |
120 | Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() { |
121 | |
122 | return MyDefaultOrthographicView; |
123 | } |
124 | |
125 | Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () { |
126 | |
127 | return MyDefaultPerspectiveView; |
128 | } |
129 | |
130 | void V3d_Viewer::SetViewOff( ) { |
131 | |
132 | for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){ |
133 | SetViewOff(ActiveView());}; |
134 | } |
135 | |
136 | void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) { |
137 | |
138 | Handle(Visual3d_View) MyView = TheView->View() ; |
139 | if( MyView->IsDefined() && !IsActive(TheView)) { |
140 | MyActiveViews.Append(TheView) ; |
141 | MyView->Activate(); |
142 | for (InitActiveLights();MoreActiveLights();NextActiveLights()){ |
143 | TheView->SetLightOn(ActiveLight());} |
144 | // Grid |
145 | TheView->SetGrid (myPrivilegedPlane, Grid ()); |
146 | TheView->SetGridActivity (Grid ()->IsActive ()); |
147 | // Update |
148 | MyView->Redraw() ; |
149 | } |
150 | } |
151 | |
152 | void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) { |
153 | |
154 | Handle(Visual3d_View) MyView =TheView->View(); |
155 | if( MyView->IsDefined() && IsActive(TheView) ) { |
156 | MyActiveViews.Remove(TheView); |
157 | MyView->Deactivate() ; |
158 | } |
159 | } |
160 | |
161 | Standard_Boolean V3d_Viewer::ComputedMode() const { |
162 | return myComputedMode; |
163 | } |
164 | |
165 | Standard_Boolean V3d_Viewer::DefaultComputedMode() const { |
166 | return myDefaultComputedMode; |
167 | } |
168 | |
169 | void V3d_Viewer::Update() { |
170 | |
171 | MyViewer->Update(); |
172 | } |
173 | |
174 | void V3d_Viewer::Redraw()const { |
175 | |
176 | MyViewer->Redraw(); |
177 | } |
178 | |
179 | void V3d_Viewer::Remove() { |
180 | |
181 | MyViewer->Remove(); |
182 | } |
183 | |
184 | void V3d_Viewer::Erase() const { |
185 | |
186 | MyViewer->Erase(); |
187 | } |
188 | |
189 | void V3d_Viewer::UnHighlight() const { |
190 | |
191 | //FMN MyViewer->UnHighlight(); |
192 | } |
193 | |
194 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) { |
195 | Standard_Real V1 = v1 ; |
196 | Standard_Real V2 = v2 ; |
197 | Standard_Real V3 = v3 ; |
198 | |
199 | if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ; |
200 | if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ; |
201 | if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ; |
202 | |
203 | Quantity_Color C(V1,V2,V3,Type) ; |
7fd59977 |
204 | SetDefaultBackgroundColor(C); |
7fd59977 |
205 | } |
206 | |
b8ddfc2f |
207 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) |
208 | { |
7fd59977 |
209 | Quantity_Color C(Name) ; |
7fd59977 |
210 | SetDefaultBackgroundColor(C); |
7fd59977 |
211 | } |
212 | |
b8ddfc2f |
213 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) |
214 | { |
7fd59977 |
215 | MyBackground.SetColor(Color) ; |
216 | } |
7fd59977 |
217 | |
218 | void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1, |
219 | const Quantity_NameOfColor Name2, |
220 | const Aspect_GradientFillMethod FillStyle){ |
221 | |
222 | Quantity_Color C1(Name1) ; |
223 | Quantity_Color C2(Name2) ; |
224 | MyGradientBackground.SetColors(C1, C2, FillStyle); |
225 | |
226 | } |
227 | |
228 | void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1, |
229 | const Quantity_Color& Color2, |
230 | const Aspect_GradientFillMethod FillStyle ){ |
231 | |
232 | MyGradientBackground.SetColors(Color1, Color2, FillStyle); |
233 | |
234 | } |
235 | |
236 | |
237 | void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) { |
238 | |
239 | Viewer_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size"); |
240 | MyViewSize = Size ; |
241 | } |
242 | |
243 | void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) { |
244 | |
245 | MyViewProj = Orientation ; |
246 | } |
247 | |
248 | void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) { |
249 | |
250 | MyVisualization = Type ; |
251 | } |
252 | void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) { |
253 | MyViewer->SetZBufferAuto (Automatic); |
254 | } |
255 | Standard_Boolean V3d_Viewer::ZBufferManagment() const { |
256 | return MyViewer->ZBufferAuto(); |
257 | } |
258 | |
259 | void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) { |
260 | |
261 | MyShadingModel = Type ; |
262 | } |
263 | |
264 | void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) { |
265 | |
266 | MySurfaceDetail = Type ; |
267 | } |
268 | |
269 | void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) { |
270 | MyDefaultAngle = Angle; |
271 | } |
272 | |
273 | void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) { |
274 | MyDefaultTypeOfView = Type;} |
275 | |
276 | |
277 | void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) { |
278 | |
279 | MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ; |
280 | } |
281 | |
b8ddfc2f |
282 | void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const |
283 | { |
7fd59977 |
284 | Quantity_Color C = DefaultBackgroundColor(); |
7fd59977 |
285 | C.Values(V1,V2,V3,Type) ; |
286 | } |
287 | |
b8ddfc2f |
288 | Quantity_Color V3d_Viewer::DefaultBackgroundColor() const |
289 | { |
7fd59977 |
290 | return MyBackground.Color() ; |
291 | } |
7fd59977 |
292 | |
b8ddfc2f |
293 | void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const |
294 | { |
7fd59977 |
295 | MyGradientBackground.Colors(Color1,Color2); |
296 | } |
297 | |
298 | Standard_Real V3d_Viewer::DefaultViewSize() const { |
299 | return MyViewSize ; |
300 | } |
301 | |
302 | V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const { |
303 | return MyViewProj ; |
304 | } |
305 | |
306 | V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const { |
307 | return MyVisualization ; |
308 | } |
309 | |
310 | V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const { |
311 | return MyShadingModel ; |
312 | } |
313 | |
314 | V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const { |
315 | return MySurfaceDetail ; |
316 | } |
317 | |
318 | Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const { |
319 | return MyDefaultAngle; |
320 | } |
321 | |
322 | V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const { |
323 | |
324 | V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ; |
325 | return Mode ; |
326 | } |
327 | |
328 | Standard_Boolean V3d_Viewer::IfMoreViews() const { |
329 | Standard_Boolean TheStatus = Standard_False ; |
330 | |
331 | #ifdef NEW |
332 | if( MyActiveViews->Length() < Visual3d_View::Limit() ) |
333 | #endif /*NEW*/ |
334 | TheStatus = Standard_True ; |
335 | return TheStatus ; |
336 | } |
337 | |
338 | Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const { |
339 | return MyViewer ; |
340 | } |
341 | |
342 | Aspect_Background V3d_Viewer::GetBackgroundColor() const { |
343 | return MyBackground ; |
344 | } |
345 | |
346 | Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const { |
347 | return MyGradientBackground; |
348 | } |
349 | |
350 | void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) { |
351 | |
352 | MyDefinedViews.Append(TheView); |
353 | IncrCount(); |
354 | } |
355 | |
356 | void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) { |
357 | |
358 | MyActiveViews.Remove(TheView); |
359 | MyDefinedViews.Remove(TheView); |
360 | } |
361 | |
362 | void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) { |
363 | |
364 | MyDefinedPlanes.Append(ThePlane) ; |
365 | } |
366 | |
367 | void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) { |
368 | |
369 | MyDefinedPlanes.Remove(ThePlane); |
370 | } |
59f45b7c |
371 | |
372 | //======================================================================= |
373 | //function : AddZLayer |
374 | //purpose : |
375 | //======================================================================= |
376 | |
377 | Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId) |
378 | { |
379 | return MyViewer->AddZLayer (theLayerId); |
380 | } |
381 | |
382 | //======================================================================= |
383 | //function : RemoveZLayer |
384 | //purpose : |
385 | //======================================================================= |
386 | |
387 | Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId) |
388 | { |
389 | return MyViewer->RemoveZLayer (theLayerId); |
390 | } |
391 | |
392 | //======================================================================= |
393 | //function : GetAllZLayers |
394 | //purpose : |
395 | //======================================================================= |
396 | |
397 | void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const |
398 | { |
399 | MyViewer->GetAllZLayers (theLayerSeq); |
400 | } |