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 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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 | /*********************************************************************** |
7fd59977 |
15 | FONCTION : |
16 | ---------- |
17 | Classe V3d_View_2.cxx : |
7fd59977 |
18 | HISTORIQUE DES MODIFICATIONS : |
19 | -------------------------------- |
20 | 00-09-92 : GG ; Creation. |
21 | 24-12-97 : FMN ; Suppression de GEOMLITE |
7fd59977 |
22 | 23-11-00 : GG ; Add IsActiveLight() and IsActivePlane() methods |
7fd59977 |
23 | ************************************************************************/ |
7fd59977 |
24 | /* |
25 | * Includes |
26 | */ |
27 | |
42cf5bc1 |
28 | #include <Aspect_GradientBackground.hxx> |
29 | #include <Aspect_Grid.hxx> |
30 | #include <Aspect_Window.hxx> |
31 | #include <Bnd_Box.hxx> |
32 | #include <gp_Ax3.hxx> |
33 | #include <gp_Dir.hxx> |
34 | #include <Graphic3d_Group.hxx> |
c357e426 |
35 | #include <Graphic3d_GraphicDriver.hxx> |
42cf5bc1 |
36 | #include <Graphic3d_Structure.hxx> |
37 | #include <Graphic3d_TextureEnv.hxx> |
38 | #include <Graphic3d_Vector.hxx> |
39 | #include <Quantity_Color.hxx> |
40 | #include <Standard_MultiplyDefined.hxx> |
41 | #include <Standard_TypeMismatch.hxx> |
7fd59977 |
42 | #include <V3d.hxx> |
42cf5bc1 |
43 | #include <V3d_BadValue.hxx> |
42cf5bc1 |
44 | #include <V3d_Light.hxx> |
45 | #include <V3d_UnMapped.hxx> |
46 | #include <V3d_View.hxx> |
47 | #include <V3d_Viewer.hxx> |
c357e426 |
48 | |
49 | //============================================================================= |
50 | //function : SetLightOn |
51 | //purpose : |
52 | //============================================================================= |
53 | void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight) |
54 | { |
55 | if (!MyActiveLights.Contains (theLight)) |
56 | { |
57 | V3d_BadValue_Raise_if (MyActiveLights.Extent() >= LightLimit(), |
58 | "V3d_View::SetLightOn, " |
59 | "too many lights"); |
60 | MyActiveLights.Append (theLight); |
61 | UpdateLights(); |
7fd59977 |
62 | } |
63 | } |
64 | |
c357e426 |
65 | //============================================================================= |
66 | //function : SetLightOff |
67 | //purpose : |
68 | //============================================================================= |
69 | void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight) |
70 | { |
71 | Standard_TypeMismatch_Raise_if (MyViewer->IsGlobalLight (theLight), |
72 | "V3d_View::SetLightOff, " |
73 | "the light is global"); |
74 | MyActiveLights.Remove (theLight); |
75 | UpdateLights(); |
7fd59977 |
76 | } |
77 | |
c357e426 |
78 | //============================================================================= |
79 | //function : IsActiveLight |
80 | //purpose : |
81 | //============================================================================= |
82 | Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const |
83 | { |
84 | if (theLight.IsNull()) |
85 | { |
86 | return Standard_False; |
87 | } |
88 | return MyActiveLights.Contains(theLight); |
7fd59977 |
89 | } |
90 | |
c357e426 |
91 | //============================================================================= |
92 | //function : SetLightOn |
93 | //purpose : |
94 | //============================================================================= |
95 | void V3d_View::SetLightOn() |
96 | { |
97 | for (MyViewer->InitDefinedLights(); MyViewer->MoreDefinedLights(); MyViewer->NextDefinedLights()) |
98 | { |
99 | if (!MyActiveLights.Contains (MyViewer->DefinedLight())) |
100 | { |
101 | MyActiveLights.Append (MyViewer->DefinedLight()); |
7fd59977 |
102 | } |
103 | } |
c357e426 |
104 | UpdateLights(); |
7fd59977 |
105 | } |
106 | |
c357e426 |
107 | //============================================================================= |
108 | //function : SetLightOff |
109 | //purpose : |
110 | //============================================================================= |
111 | void V3d_View::SetLightOff() |
112 | { |
7fd59977 |
113 | InitActiveLights(); |
c357e426 |
114 | while(MoreActiveLights()) |
115 | { |
116 | if (!MyViewer->IsGlobalLight (ActiveLight())) |
117 | { |
118 | MyActiveLights.Remove (ActiveLight()); |
7fd59977 |
119 | } |
120 | else |
c357e426 |
121 | { |
7fd59977 |
122 | NextActiveLights(); |
c357e426 |
123 | } |
7fd59977 |
124 | } |
c357e426 |
125 | UpdateLights(); |
7fd59977 |
126 | } |
127 | |
c357e426 |
128 | //============================================================================= |
129 | //function : InitActiveLights |
130 | //purpose : |
131 | //============================================================================= |
132 | void V3d_View::InitActiveLights() |
133 | { |
134 | myActiveLightsIterator.Initialize(MyActiveLights); |
7fd59977 |
135 | } |
c357e426 |
136 | |
137 | //============================================================================= |
138 | //function : MoreActiveLights |
139 | //purpose : |
140 | //============================================================================= |
141 | Standard_Boolean V3d_View::MoreActiveLights() const |
142 | { |
7fd59977 |
143 | return myActiveLightsIterator.More(); |
144 | } |
c357e426 |
145 | |
146 | //============================================================================= |
147 | //function : NextActiveLights |
148 | //purpose : |
149 | //============================================================================= |
150 | void V3d_View::NextActiveLights() |
151 | { |
7fd59977 |
152 | myActiveLightsIterator.Next(); |
153 | } |
7fd59977 |
154 | |
c357e426 |
155 | //============================================================================= |
156 | //function : ActiveLight |
157 | //purpose : |
158 | //============================================================================= |
159 | Handle(V3d_Light) V3d_View::ActiveLight() const |
160 | { |
161 | return (Handle(V3d_Light)&)(myActiveLightsIterator.Value()); |
162 | } |
163 | |
164 | //============================================================================= |
165 | //function : IfMoreLights |
166 | //purpose : |
167 | //============================================================================= |
168 | Standard_Boolean V3d_View::IfMoreLights() const |
169 | { |
170 | return MyActiveLights.Extent() < LightLimit(); |
171 | } |
7fd59977 |
172 | |
c357e426 |
173 | //======================================================================= |
174 | //function : LightLimit |
175 | //purpose : |
176 | //======================================================================= |
177 | Standard_Integer V3d_View::LightLimit() const |
178 | { |
179 | return Viewer()->Driver()->InquireLightLimit(); |
7fd59977 |
180 | } |
4269bd1b |
181 | |
182 | //======================================================================= |
183 | //function : AddClipPlane |
184 | //purpose : |
185 | //======================================================================= |
186 | void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
187 | { |
c357e426 |
188 | Graphic3d_SequenceOfHClipPlane aSeqOfPlanes = GetClipPlanes(); |
189 | aSeqOfPlanes.Append (thePlane); |
190 | SetClipPlanes (aSeqOfPlanes); |
4269bd1b |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : RemoveClipPlane |
195 | //purpose : |
196 | //======================================================================= |
197 | void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
198 | { |
c357e426 |
199 | Graphic3d_SequenceOfHClipPlane aSeqOfPlanes = GetClipPlanes(); |
51b10cd4 |
200 | Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (aSeqOfPlanes); |
201 | for (; aPlaneIt.More(); aPlaneIt.Next()) |
202 | { |
203 | const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value(); |
204 | if (aPlane != thePlane) |
205 | continue; |
206 | |
207 | aSeqOfPlanes.Remove (aPlaneIt); |
c357e426 |
208 | SetClipPlanes (aSeqOfPlanes); |
4269bd1b |
209 | return; |
51b10cd4 |
210 | } |
4269bd1b |
211 | } |
212 | |
213 | //======================================================================= |
214 | //function : SetClipPlanes |
215 | //purpose : |
216 | //======================================================================= |
51b10cd4 |
217 | void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) |
4269bd1b |
218 | { |
c357e426 |
219 | myView->SetClipPlanes (thePlanes); |
4269bd1b |
220 | } |
221 | |
222 | //======================================================================= |
223 | //function : GetClipPlanes |
224 | //purpose : |
225 | //======================================================================= |
51b10cd4 |
226 | const Graphic3d_SequenceOfHClipPlane& V3d_View::GetClipPlanes() const |
4269bd1b |
227 | { |
c357e426 |
228 | return myView->ClipPlanes(); |
229 | } |
230 | |
231 | //======================================================================= |
232 | //function : PlaneLimit |
233 | //purpose : |
234 | //======================================================================= |
235 | Standard_Integer V3d_View::PlaneLimit() const |
236 | { |
237 | return Viewer()->Driver()->InquirePlaneLimit(); |
4269bd1b |
238 | } |