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> |
42cf5bc1 |
38 | #include <Quantity_Color.hxx> |
39 | #include <Standard_MultiplyDefined.hxx> |
40 | #include <Standard_TypeMismatch.hxx> |
7fd59977 |
41 | #include <V3d.hxx> |
42cf5bc1 |
42 | #include <V3d_BadValue.hxx> |
42cf5bc1 |
43 | #include <V3d_Light.hxx> |
44 | #include <V3d_UnMapped.hxx> |
45 | #include <V3d_View.hxx> |
46 | #include <V3d_Viewer.hxx> |
c357e426 |
47 | |
48 | //============================================================================= |
49 | //function : SetLightOn |
50 | //purpose : |
51 | //============================================================================= |
52 | void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight) |
53 | { |
6a24c6de |
54 | if (!myActiveLights.Contains (theLight)) |
c357e426 |
55 | { |
6a24c6de |
56 | myActiveLights.Append (theLight); |
c357e426 |
57 | UpdateLights(); |
7fd59977 |
58 | } |
59 | } |
60 | |
c357e426 |
61 | //============================================================================= |
62 | //function : SetLightOff |
63 | //purpose : |
64 | //============================================================================= |
65 | void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight) |
66 | { |
9775fa61 |
67 | if (MyViewer->IsGlobalLight (theLight)) |
68 | throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global"); |
6a24c6de |
69 | myActiveLights.Remove (theLight); |
c357e426 |
70 | UpdateLights(); |
7fd59977 |
71 | } |
72 | |
c357e426 |
73 | //============================================================================= |
74 | //function : IsActiveLight |
75 | //purpose : |
76 | //============================================================================= |
77 | Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const |
78 | { |
6a24c6de |
79 | return !theLight.IsNull() |
80 | && myActiveLights.Contains (theLight); |
7fd59977 |
81 | } |
82 | |
c357e426 |
83 | //============================================================================= |
84 | //function : SetLightOn |
85 | //purpose : |
86 | //============================================================================= |
87 | void V3d_View::SetLightOn() |
88 | { |
6a24c6de |
89 | for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next()) |
c357e426 |
90 | { |
6a24c6de |
91 | if (!myActiveLights.Contains (aDefLightIter.Value())) |
c357e426 |
92 | { |
6a24c6de |
93 | myActiveLights.Append (aDefLightIter.Value()); |
7fd59977 |
94 | } |
95 | } |
c357e426 |
96 | UpdateLights(); |
7fd59977 |
97 | } |
98 | |
c357e426 |
99 | //============================================================================= |
100 | //function : SetLightOff |
101 | //purpose : |
102 | //============================================================================= |
103 | void V3d_View::SetLightOff() |
104 | { |
6a24c6de |
105 | for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();) |
c357e426 |
106 | { |
6a24c6de |
107 | if (!MyViewer->IsGlobalLight (anActiveLightIter.Value())) |
c357e426 |
108 | { |
6a24c6de |
109 | myActiveLights.Remove (anActiveLightIter); |
7fd59977 |
110 | } |
111 | else |
c357e426 |
112 | { |
6a24c6de |
113 | anActiveLightIter.Next(); |
c357e426 |
114 | } |
7fd59977 |
115 | } |
c357e426 |
116 | UpdateLights(); |
7fd59977 |
117 | } |
118 | |
c357e426 |
119 | //============================================================================= |
120 | //function : IfMoreLights |
121 | //purpose : |
122 | //============================================================================= |
123 | Standard_Boolean V3d_View::IfMoreLights() const |
124 | { |
6a24c6de |
125 | return myActiveLights.Extent() < LightLimit(); |
c357e426 |
126 | } |
7fd59977 |
127 | |
c357e426 |
128 | //======================================================================= |
129 | //function : LightLimit |
130 | //purpose : |
131 | //======================================================================= |
132 | Standard_Integer V3d_View::LightLimit() const |
133 | { |
134 | return Viewer()->Driver()->InquireLightLimit(); |
7fd59977 |
135 | } |
4269bd1b |
136 | |
137 | //======================================================================= |
138 | //function : AddClipPlane |
139 | //purpose : |
140 | //======================================================================= |
141 | void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
142 | { |
3202bf1e |
143 | Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes(); |
144 | if (aSeqOfPlanes.IsNull()) |
145 | { |
146 | aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane(); |
147 | } |
b88b0cf7 |
148 | else |
149 | { |
150 | for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next()) |
151 | { |
152 | const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value(); |
153 | if (aPlane == thePlane) |
154 | { |
155 | // plane is already defined in view |
156 | return; |
157 | } |
158 | } |
159 | } |
3202bf1e |
160 | |
161 | aSeqOfPlanes->Append (thePlane); |
c357e426 |
162 | SetClipPlanes (aSeqOfPlanes); |
4269bd1b |
163 | } |
164 | |
165 | //======================================================================= |
166 | //function : RemoveClipPlane |
167 | //purpose : |
168 | //======================================================================= |
169 | void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
170 | { |
3202bf1e |
171 | Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes(); |
172 | if (aSeqOfPlanes.IsNull()) |
173 | { |
174 | return; |
175 | } |
176 | |
177 | for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt(*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next()) |
51b10cd4 |
178 | { |
179 | const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value(); |
180 | if (aPlane != thePlane) |
181 | continue; |
182 | |
3202bf1e |
183 | aSeqOfPlanes->Remove (aPlaneIt); |
c357e426 |
184 | SetClipPlanes (aSeqOfPlanes); |
4269bd1b |
185 | return; |
51b10cd4 |
186 | } |
4269bd1b |
187 | } |
188 | |
189 | //======================================================================= |
190 | //function : SetClipPlanes |
191 | //purpose : |
192 | //======================================================================= |
3202bf1e |
193 | void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) |
4269bd1b |
194 | { |
c357e426 |
195 | myView->SetClipPlanes (thePlanes); |
4269bd1b |
196 | } |
197 | |
198 | //======================================================================= |
3202bf1e |
199 | //function : ClipPlanes |
4269bd1b |
200 | //purpose : |
201 | //======================================================================= |
3202bf1e |
202 | const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const |
4269bd1b |
203 | { |
c357e426 |
204 | return myView->ClipPlanes(); |
205 | } |
206 | |
207 | //======================================================================= |
208 | //function : PlaneLimit |
209 | //purpose : |
210 | //======================================================================= |
211 | Standard_Integer V3d_View::PlaneLimit() const |
212 | { |
213 | return Viewer()->Driver()->InquirePlaneLimit(); |
4269bd1b |
214 | } |