973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
973c2be1 |
5 | // This library is free software; you can redistribute it and / or modify it |
6 | // under the terms of the GNU Lesser General Public version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | /*********************************************************************** |
15 | |
16 | FONCTION : |
17 | ---------- |
18 | Classe V3d_Viewer : |
19 | |
20 | HISTORIQUE DES MODIFICATIONS : |
21 | -------------------------------- |
22 | 00-09-92 : GG ; Creation. |
23 | 15-11-97 : FMN ; Ajout texture mapping |
24 | 02-02-98 : FMN ; Mise a niveau WNT |
25 | 23-02-98 : FMN ; Remplacement PI par Standard_PI |
26 | 16-07-98 : CAL ; S3892. Ajout grilles 3d. |
27 | |
28 | ************************************************************************/ |
29 | |
b8ddfc2f |
30 | //GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor() and DefaultBackgroundColor() methods |
7fd59977 |
31 | |
32 | #define IMP240100 //GG |
33 | // Initalize grid echo fields |
34 | |
35 | /*----------------------------------------------------------------------*/ |
36 | /* |
37 | * Includes |
38 | */ |
39 | |
40 | #include <V3d.hxx> |
41 | #include <Visual3d_View.hxx> |
42 | #include <Visual3d_Light.hxx> |
43 | #include <V3d_Viewer.ixx> |
44 | #include <V3d_View.hxx> |
6942f04a |
45 | #include <V3d_BadValue.hxx> |
7fd59977 |
46 | #include <V3d_OrthographicView.hxx> |
47 | #include <V3d_PerspectiveView.hxx> |
7fd59977 |
48 | |
49 | /*----------------------------------------------------------------------*/ |
50 | |
51 | //-Constructor: |
6942f04a |
52 | V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver, |
53 | const Standard_ExtString theName, |
54 | const Standard_CString theDomain, |
55 | const Standard_Real theViewSize, |
56 | const V3d_TypeOfOrientation theViewProj, |
57 | const Quantity_NameOfColor theViewBackground, |
58 | const V3d_TypeOfVisualization theVisualization, |
59 | const V3d_TypeOfShadingModel theShadingModel, |
60 | const V3d_TypeOfUpdate theUpdateMode, |
61 | const Standard_Boolean theComputedMode, |
62 | const Standard_Boolean theDefaultComputedMode, |
63 | const V3d_TypeOfSurfaceDetail theSurfaceDetail) |
64 | :myNextCount (-1), |
65 | myDriver (theDriver), |
66 | myName (TCollection_ExtendedString (theName)), |
67 | myDomain (TCollection_AsciiString (theDomain)), |
7fd59977 |
68 | MyDefinedViews(), |
69 | MyActiveViews(), |
70 | MyDefinedLights(), |
71 | MyActiveLights(), |
7fd59977 |
72 | myActiveViewsIterator(), |
73 | myDefinedViewsIterator(), |
74 | myActiveLightsIterator(), |
75 | myDefinedLightsIterator(), |
6942f04a |
76 | myComputedMode (theComputedMode), |
77 | myDefaultComputedMode (theDefaultComputedMode), |
78 | myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))), |
79 | myDisplayPlane (Standard_False), |
80 | myDisplayPlaneLength (theViewSize) |
7fd59977 |
81 | #ifdef IMP240100 |
6942f04a |
82 | ,myGridEcho (Standard_True), myGridEchoStructure(), myGridEchoGroup() |
7fd59977 |
83 | #endif |
84 | { |
6942f04a |
85 | MyViewer = new Visual3d_ViewManager (theDriver); |
7fd59977 |
86 | // san (16/09/2010): It has been decided to turn depth test ON |
87 | // by default, as this is important for new font rendering |
88 | // (without it, there are numerous texture rendering artefacts) |
89 | MyViewer->SetZBufferAuto (Standard_False); |
6942f04a |
90 | SetUpdateMode (theUpdateMode); |
91 | SetDefaultViewSize (theViewSize); |
92 | SetDefaultViewProj (theViewProj); |
93 | SetDefaultBackgroundColor (theViewBackground); |
94 | SetDefaultVisualization (theVisualization); |
95 | SetDefaultShadingModel (theShadingModel); |
96 | SetDefaultSurfaceDetail (theSurfaceDetail); |
97 | SetDefaultAngle (M_PI / 2.); |
98 | SetDefaultTypeOfView (V3d_ORTHOGRAPHIC); |
7fd59977 |
99 | |
100 | Quantity_Color Color1 (Quantity_NOC_GRAY50); |
101 | Quantity_Color Color2 (Quantity_NOC_GRAY70); |
102 | // Quantity_Color White (Quantity_NOC_WHITE); |
6942f04a |
103 | myRGrid = new V3d_RectangularGrid (this, Color1, Color2); |
104 | myCGrid = new V3d_CircularGrid (this, Color1, Color2); |
7fd59977 |
105 | myGridType = Aspect_GT_Rectangular; |
106 | } |
107 | |
108 | //-Methods, in order |
109 | |
110 | |
111 | Handle(V3d_View) V3d_Viewer::CreateView () { |
112 | if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC) |
113 | return new V3d_OrthographicView(this); |
114 | else |
115 | return new V3d_PerspectiveView(this); |
116 | } |
117 | |
118 | void V3d_Viewer::SetViewOn( ) { |
119 | |
120 | for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){ |
121 | SetViewOn(ActiveView());}; |
122 | } |
123 | |
7fd59977 |
124 | void V3d_Viewer::SetViewOff( ) { |
125 | |
126 | for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){ |
127 | SetViewOff(ActiveView());}; |
128 | } |
129 | |
130 | void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) { |
131 | |
132 | Handle(Visual3d_View) MyView = TheView->View() ; |
133 | if( MyView->IsDefined() && !IsActive(TheView)) { |
134 | MyActiveViews.Append(TheView) ; |
135 | MyView->Activate(); |
136 | for (InitActiveLights();MoreActiveLights();NextActiveLights()){ |
137 | TheView->SetLightOn(ActiveLight());} |
138 | // Grid |
139 | TheView->SetGrid (myPrivilegedPlane, Grid ()); |
140 | TheView->SetGridActivity (Grid ()->IsActive ()); |
141 | // Update |
142 | MyView->Redraw() ; |
143 | } |
144 | } |
145 | |
146 | void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) { |
147 | |
148 | Handle(Visual3d_View) MyView =TheView->View(); |
149 | if( MyView->IsDefined() && IsActive(TheView) ) { |
150 | MyActiveViews.Remove(TheView); |
151 | MyView->Deactivate() ; |
152 | } |
153 | } |
154 | |
155 | Standard_Boolean V3d_Viewer::ComputedMode() const { |
156 | return myComputedMode; |
157 | } |
158 | |
159 | Standard_Boolean V3d_Viewer::DefaultComputedMode() const { |
160 | return myDefaultComputedMode; |
161 | } |
162 | |
163 | void V3d_Viewer::Update() { |
164 | |
165 | MyViewer->Update(); |
166 | } |
167 | |
168 | void V3d_Viewer::Redraw()const { |
169 | |
170 | MyViewer->Redraw(); |
171 | } |
172 | |
173 | void V3d_Viewer::Remove() { |
174 | |
175 | MyViewer->Remove(); |
176 | } |
177 | |
178 | void V3d_Viewer::Erase() const { |
179 | |
180 | MyViewer->Erase(); |
181 | } |
182 | |
183 | void V3d_Viewer::UnHighlight() const { |
184 | |
185 | //FMN MyViewer->UnHighlight(); |
186 | } |
187 | |
188 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) { |
189 | Standard_Real V1 = v1 ; |
190 | Standard_Real V2 = v2 ; |
191 | Standard_Real V3 = v3 ; |
192 | |
193 | if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ; |
194 | if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ; |
195 | if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ; |
196 | |
197 | Quantity_Color C(V1,V2,V3,Type) ; |
7fd59977 |
198 | SetDefaultBackgroundColor(C); |
7fd59977 |
199 | } |
200 | |
b8ddfc2f |
201 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) |
202 | { |
7fd59977 |
203 | Quantity_Color C(Name) ; |
7fd59977 |
204 | SetDefaultBackgroundColor(C); |
7fd59977 |
205 | } |
206 | |
b8ddfc2f |
207 | void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) |
208 | { |
7fd59977 |
209 | MyBackground.SetColor(Color) ; |
210 | } |
7fd59977 |
211 | |
212 | void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1, |
213 | const Quantity_NameOfColor Name2, |
214 | const Aspect_GradientFillMethod FillStyle){ |
215 | |
216 | Quantity_Color C1(Name1) ; |
217 | Quantity_Color C2(Name2) ; |
218 | MyGradientBackground.SetColors(C1, C2, FillStyle); |
219 | |
220 | } |
221 | |
222 | void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1, |
223 | const Quantity_Color& Color2, |
224 | const Aspect_GradientFillMethod FillStyle ){ |
225 | |
226 | MyGradientBackground.SetColors(Color1, Color2, FillStyle); |
227 | |
228 | } |
229 | |
230 | |
231 | void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) { |
232 | |
6942f04a |
233 | V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size"); |
7fd59977 |
234 | MyViewSize = Size ; |
235 | } |
236 | |
237 | void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) { |
238 | |
239 | MyViewProj = Orientation ; |
240 | } |
241 | |
242 | void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) { |
243 | |
244 | MyVisualization = Type ; |
245 | } |
246 | void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) { |
247 | MyViewer->SetZBufferAuto (Automatic); |
248 | } |
249 | Standard_Boolean V3d_Viewer::ZBufferManagment() const { |
250 | return MyViewer->ZBufferAuto(); |
251 | } |
252 | |
253 | void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) { |
254 | |
255 | MyShadingModel = Type ; |
256 | } |
257 | |
258 | void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) { |
259 | |
260 | MySurfaceDetail = Type ; |
261 | } |
262 | |
263 | void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) { |
264 | MyDefaultAngle = Angle; |
265 | } |
266 | |
267 | void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) { |
268 | MyDefaultTypeOfView = Type;} |
269 | |
270 | |
271 | void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) { |
272 | |
273 | MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ; |
274 | } |
275 | |
b8ddfc2f |
276 | void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const |
277 | { |
7fd59977 |
278 | Quantity_Color C = DefaultBackgroundColor(); |
7fd59977 |
279 | C.Values(V1,V2,V3,Type) ; |
280 | } |
281 | |
b8ddfc2f |
282 | Quantity_Color V3d_Viewer::DefaultBackgroundColor() const |
283 | { |
7fd59977 |
284 | return MyBackground.Color() ; |
285 | } |
7fd59977 |
286 | |
b8ddfc2f |
287 | void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const |
288 | { |
7fd59977 |
289 | MyGradientBackground.Colors(Color1,Color2); |
290 | } |
291 | |
292 | Standard_Real V3d_Viewer::DefaultViewSize() const { |
293 | return MyViewSize ; |
294 | } |
295 | |
296 | V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const { |
297 | return MyViewProj ; |
298 | } |
299 | |
300 | V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const { |
301 | return MyVisualization ; |
302 | } |
303 | |
304 | V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const { |
305 | return MyShadingModel ; |
306 | } |
307 | |
308 | V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const { |
309 | return MySurfaceDetail ; |
310 | } |
311 | |
312 | Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const { |
313 | return MyDefaultAngle; |
314 | } |
315 | |
316 | V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const { |
317 | |
318 | V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ; |
319 | return Mode ; |
320 | } |
321 | |
322 | Standard_Boolean V3d_Viewer::IfMoreViews() const { |
323 | Standard_Boolean TheStatus = Standard_False ; |
324 | |
325 | #ifdef NEW |
326 | if( MyActiveViews->Length() < Visual3d_View::Limit() ) |
327 | #endif /*NEW*/ |
328 | TheStatus = Standard_True ; |
329 | return TheStatus ; |
330 | } |
331 | |
332 | Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const { |
333 | return MyViewer ; |
334 | } |
335 | |
336 | Aspect_Background V3d_Viewer::GetBackgroundColor() const { |
337 | return MyBackground ; |
338 | } |
339 | |
340 | Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const { |
341 | return MyGradientBackground; |
342 | } |
343 | |
344 | void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) { |
345 | |
346 | MyDefinedViews.Append(TheView); |
347 | IncrCount(); |
348 | } |
349 | |
350 | void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) { |
351 | |
352 | MyActiveViews.Remove(TheView); |
353 | MyDefinedViews.Remove(TheView); |
354 | } |
355 | |
59f45b7c |
356 | //======================================================================= |
357 | //function : AddZLayer |
358 | //purpose : |
359 | //======================================================================= |
360 | |
361 | Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId) |
362 | { |
363 | return MyViewer->AddZLayer (theLayerId); |
364 | } |
365 | |
366 | //======================================================================= |
367 | //function : RemoveZLayer |
368 | //purpose : |
369 | //======================================================================= |
370 | |
371 | Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId) |
372 | { |
373 | return MyViewer->RemoveZLayer (theLayerId); |
374 | } |
375 | |
376 | //======================================================================= |
377 | //function : GetAllZLayers |
378 | //purpose : |
379 | //======================================================================= |
380 | |
381 | void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const |
382 | { |
383 | MyViewer->GetAllZLayers (theLayerSeq); |
384 | } |
6942f04a |
385 | |
386 | //======================================================================= |
387 | //function : Domain |
388 | //purpose : |
389 | //======================================================================= |
390 | |
391 | Standard_CString V3d_Viewer::Domain() const |
392 | { |
393 | return myDomain.ToCString(); |
394 | } |
395 | |
396 | //======================================================================= |
397 | //function : Driver |
398 | //purpose : |
399 | //======================================================================= |
400 | |
401 | const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const |
402 | { |
403 | return myDriver; |
404 | } |
405 | |
406 | //======================================================================= |
407 | //function : NextName |
408 | //purpose : |
409 | //======================================================================= |
410 | |
411 | Standard_ExtString V3d_Viewer::NextName() const |
412 | { |
413 | TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString()); |
414 | aNextName.AssignCat (TCollection_ExtendedString (myNextCount)); |
415 | |
416 | return aNextName.ToExtString(); |
417 | } |
418 | |
419 | //======================================================================= |
420 | //function : IncrCount |
421 | //purpose : |
422 | //======================================================================= |
423 | |
424 | void V3d_Viewer::IncrCount() |
425 | { |
426 | myNextCount++; |
973c2be1 |
427 | } |