4269bd1b |
1 | // Created on: 2013-07-12 |
2 | // Created by: Anton POLETAEV |
d5f74e42 |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
4269bd1b |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
4269bd1b |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
4269bd1b |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
4269bd1b |
15 | |
16 | #include <Graphic3d_ClipPlane.hxx> |
3e05329c |
17 | |
4269bd1b |
18 | #include <Graphic3d_AspectFillArea3d.hxx> |
19 | #include <gp_Pln.hxx> |
20 | #include <Standard_Atomic.hxx> |
21 | |
92efcf78 |
22 | IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient) |
23 | |
4269bd1b |
24 | namespace |
25 | { |
26 | static volatile Standard_Integer THE_CLIP_PLANE_COUNTER = 0; |
3e05329c |
27 | |
28 | static Handle(Graphic3d_AspectFillArea3d) defaultAspect() |
29 | { |
30 | const Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT); |
31 | Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); |
32 | anAspect->SetDistinguishOff(); |
33 | anAspect->SetFrontMaterial (aMaterial); |
34 | anAspect->SetHatchStyle (Aspect_HS_HORIZONTAL); |
35 | anAspect->SetInteriorStyle (Aspect_IS_SOLID); |
36 | anAspect->SetInteriorColor (aMaterial.Color()); |
37 | anAspect->SetSuppressBackFaces (false); |
38 | return anAspect; |
39 | } |
a3f6f591 |
40 | } |
4269bd1b |
41 | |
42 | // ======================================================================= |
43 | // function : Graphic3d_ClipPlane |
44 | // purpose : |
45 | // ======================================================================= |
46 | Graphic3d_ClipPlane::Graphic3d_ClipPlane() |
7c3ef2f7 |
47 | : myAspect (defaultAspect()), |
25c35042 |
48 | myPrevInChain(NULL), |
7c3ef2f7 |
49 | myPlane (0.0, 0.0, 1.0, 0.0), |
50 | myEquation (0.0, 0.0, 1.0, 0.0), |
25c35042 |
51 | myEquationRev(0.0, 0.0,-1.0, 0.0), |
52 | myChainLenFwd(1), |
7c3ef2f7 |
53 | myFlags (Graphic3d_CappingFlags_None), |
4269bd1b |
54 | myEquationMod(0), |
7c3ef2f7 |
55 | myAspectMod (0), |
56 | myIsOn (Standard_True), |
57 | myIsCapping (Standard_False) |
4269bd1b |
58 | { |
3e05329c |
59 | makeId(); |
4269bd1b |
60 | } |
61 | |
62 | // ======================================================================= |
63 | // function : Graphic3d_ClipPlane |
64 | // purpose : |
65 | // ======================================================================= |
25c35042 |
66 | Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_Vec4d& theEquation) |
7c3ef2f7 |
67 | : myAspect (defaultAspect()), |
25c35042 |
68 | myPrevInChain(NULL), |
7c3ef2f7 |
69 | myPlane (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()), |
70 | myEquation (theEquation), |
25c35042 |
71 | myEquationRev(0.0, 0.0,-1.0, 0.0), |
72 | myChainLenFwd(1), |
7c3ef2f7 |
73 | myFlags (Graphic3d_CappingFlags_None), |
4269bd1b |
74 | myEquationMod(0), |
7c3ef2f7 |
75 | myAspectMod (0), |
76 | myIsOn (Standard_True), |
77 | myIsCapping (Standard_False) |
4269bd1b |
78 | { |
3e05329c |
79 | makeId(); |
25c35042 |
80 | updateInversedPlane(); |
4269bd1b |
81 | } |
82 | |
83 | // ======================================================================= |
84 | // function : Graphic3d_ClipPlane |
85 | // purpose : |
86 | // ======================================================================= |
87 | Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther) |
a9b30f0a |
88 | : Standard_Transient(theOther), |
7c3ef2f7 |
89 | myAspect (defaultAspect()), |
25c35042 |
90 | myPrevInChain(NULL), |
7c3ef2f7 |
91 | myPlane (theOther.myPlane), |
92 | myEquation (theOther.myEquation), |
25c35042 |
93 | myEquationRev(theOther.myEquationRev), |
94 | myChainLenFwd(1), |
7c3ef2f7 |
95 | myFlags (theOther.myFlags), |
96 | myEquationMod(0), |
97 | myAspectMod (0), |
98 | myIsOn (theOther.myIsOn), |
99 | myIsCapping (theOther.myIsCapping) |
4269bd1b |
100 | { |
3e05329c |
101 | makeId(); |
102 | *myAspect = *theOther.CappingAspect(); |
4269bd1b |
103 | } |
104 | |
105 | // ======================================================================= |
106 | // function : Graphic3d_ClipPlane |
107 | // purpose : |
108 | // ======================================================================= |
109 | Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane) |
7c3ef2f7 |
110 | : myAspect (defaultAspect()), |
25c35042 |
111 | myPrevInChain(NULL), |
7c3ef2f7 |
112 | myPlane (thePlane), |
25c35042 |
113 | myChainLenFwd(1), |
7c3ef2f7 |
114 | myFlags (Graphic3d_CappingFlags_None), |
4269bd1b |
115 | myEquationMod(0), |
7c3ef2f7 |
116 | myAspectMod (0), |
117 | myIsOn (Standard_True), |
118 | myIsCapping (Standard_False) |
4269bd1b |
119 | { |
7c3ef2f7 |
120 | thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]); |
25c35042 |
121 | updateInversedPlane(); |
3e05329c |
122 | makeId(); |
4269bd1b |
123 | } |
124 | |
125 | // ======================================================================= |
126 | // function : SetEquation |
127 | // purpose : |
128 | // ======================================================================= |
25c35042 |
129 | void Graphic3d_ClipPlane::SetEquation (const Graphic3d_Vec4d& theEquation) |
4269bd1b |
130 | { |
7c3ef2f7 |
131 | myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()); |
4269bd1b |
132 | myEquation = theEquation; |
25c35042 |
133 | updateInversedPlane(); |
4269bd1b |
134 | myEquationMod++; |
135 | } |
136 | |
137 | // ======================================================================= |
138 | // function : SetPlane |
139 | // purpose : |
140 | // ======================================================================= |
141 | void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane) |
142 | { |
7c3ef2f7 |
143 | myPlane = thePlane; |
25c35042 |
144 | thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]); |
145 | updateInversedPlane(); |
4269bd1b |
146 | myEquationMod++; |
147 | } |
148 | |
149 | // ======================================================================= |
150 | // function : SetOn |
151 | // purpose : |
152 | // ======================================================================= |
153 | void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn) |
154 | { |
25c35042 |
155 | if (myPrevInChain != NULL) |
156 | { |
157 | throw Standard_ProgramError ("Graphic3d_ClipPlane::SetOn() - undefined operation for a plane in Union"); |
158 | } |
4269bd1b |
159 | myIsOn = theIsOn; |
160 | } |
161 | |
162 | // ======================================================================= |
163 | // function : SetCapping |
164 | // purpose : |
165 | // ======================================================================= |
166 | void Graphic3d_ClipPlane::SetCapping (const Standard_Boolean theIsOn) |
167 | { |
168 | myIsCapping = theIsOn; |
169 | } |
170 | |
4269bd1b |
171 | // ======================================================================= |
172 | // function : Clone |
173 | // purpose : |
174 | // ======================================================================= |
175 | Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const |
176 | { |
177 | return new Graphic3d_ClipPlane(*this); |
178 | } |
179 | |
180 | // ======================================================================= |
181 | // function : SetCappingMaterial |
182 | // purpose : |
183 | // ======================================================================= |
184 | void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat) |
185 | { |
3e05329c |
186 | myAspect->SetFrontMaterial (theMat); |
187 | myAspect->SetInteriorColor (theMat.Color()); |
188 | ++myAspectMod; |
4269bd1b |
189 | } |
190 | |
191 | // ======================================================================= |
192 | // function : SetCappingTexture |
193 | // purpose : |
194 | // ======================================================================= |
195 | void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture) |
196 | { |
3e05329c |
197 | if (!theTexture.IsNull()) |
198 | { |
199 | myAspect->SetTextureMapOn(); |
cc8cbabe |
200 | Handle(Graphic3d_TextureSet) aTextureSet = myAspect->TextureSet(); |
201 | if (aTextureSet.IsNull() || aTextureSet->Size() != 1) |
202 | { |
203 | aTextureSet = new Graphic3d_TextureSet (theTexture); |
204 | } |
205 | else |
206 | { |
207 | aTextureSet->SetFirst (theTexture); |
208 | } |
209 | myAspect->SetTextureSet (aTextureSet); |
3e05329c |
210 | } |
211 | else |
212 | { |
213 | myAspect->SetTextureMapOff(); |
cc8cbabe |
214 | myAspect->SetTextureSet (Handle(Graphic3d_TextureSet)()); |
3e05329c |
215 | } |
216 | ++myAspectMod; |
4269bd1b |
217 | } |
218 | |
219 | // ======================================================================= |
220 | // function : SetCappingHatch |
221 | // purpose : |
222 | // ======================================================================= |
223 | void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle) |
224 | { |
3e05329c |
225 | myAspect->SetHatchStyle (theStyle); |
226 | ++myAspectMod; |
4269bd1b |
227 | } |
228 | |
640d5fe2 |
229 | // ======================================================================= |
230 | // function : SetCappingCustomHatch |
231 | // purpose : |
232 | // ======================================================================= |
233 | void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle) |
234 | { |
235 | myAspect->SetHatchStyle (theStyle); |
236 | ++myAspectMod; |
237 | } |
238 | |
4269bd1b |
239 | // ======================================================================= |
240 | // function : SetCappingHatchOn |
241 | // purpose : |
242 | // ======================================================================= |
243 | void Graphic3d_ClipPlane::SetCappingHatchOn() |
244 | { |
3e05329c |
245 | myAspect->SetInteriorStyle (Aspect_IS_HATCH); |
246 | ++myAspectMod; |
4269bd1b |
247 | } |
248 | |
249 | // ======================================================================= |
250 | // function : SetCappingHatchOff |
251 | // purpose : |
252 | // ======================================================================= |
253 | void Graphic3d_ClipPlane::SetCappingHatchOff() |
254 | { |
3e05329c |
255 | myAspect->SetInteriorStyle (Aspect_IS_SOLID); |
256 | ++myAspectMod; |
4269bd1b |
257 | } |
258 | |
259 | // ======================================================================= |
3e05329c |
260 | // function : SetCappingAspect |
4269bd1b |
261 | // purpose : |
262 | // ======================================================================= |
3e05329c |
263 | void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) |
4269bd1b |
264 | { |
3e05329c |
265 | myAspect = theAspect; |
266 | ++myAspectMod; |
4269bd1b |
267 | } |
268 | |
269 | // ======================================================================= |
3e05329c |
270 | // function : setCappingFlag |
4269bd1b |
271 | // purpose : |
272 | // ======================================================================= |
3e05329c |
273 | void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag) |
4269bd1b |
274 | { |
3e05329c |
275 | if (theToUse) |
b2fbf11a |
276 | { |
3e05329c |
277 | myFlags |= theFlag; |
b2fbf11a |
278 | } |
279 | else |
280 | { |
3e05329c |
281 | myFlags &= ~(theFlag); |
b2fbf11a |
282 | } |
3e05329c |
283 | ++myAspectMod; |
284 | } |
285 | |
286 | // ======================================================================= |
287 | // function : makeId |
288 | // purpose : |
289 | // ======================================================================= |
290 | void Graphic3d_ClipPlane::makeId() |
291 | { |
292 | myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name() |
293 | + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER)); |
4269bd1b |
294 | } |
25c35042 |
295 | |
296 | // ======================================================================= |
297 | // function : updateChainLen |
298 | // purpose : |
299 | // ======================================================================= |
300 | void Graphic3d_ClipPlane::updateChainLen() |
301 | { |
302 | myChainLenFwd = !myNextInChain.IsNull() ? (myNextInChain->myChainLenFwd + 1) : 1; |
303 | if (myPrevInChain != NULL) |
304 | { |
305 | myPrevInChain->updateChainLen(); |
306 | } |
307 | } |
308 | |
309 | // ======================================================================= |
310 | // function : SetChainNextPlane |
311 | // purpose : |
312 | // ======================================================================= |
313 | void Graphic3d_ClipPlane::SetChainNextPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
314 | { |
315 | ++myEquationMod; |
316 | if (!myNextInChain.IsNull()) |
317 | { |
318 | myNextInChain->myPrevInChain = NULL; |
319 | } |
320 | myNextInChain = thePlane; |
321 | if (!myNextInChain.IsNull()) |
322 | { |
323 | myNextInChain->myPrevInChain = this; |
324 | } |
325 | updateChainLen(); |
326 | } |