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 | { |
61168418 |
30 | Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT); |
3e05329c |
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); |
61168418 |
36 | anAspect->SetInteriorColor (Quantity_NOC_GRAY20); |
3e05329c |
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 | |
61168418 |
180 | // ======================================================================= |
181 | // function : SetCappingColor |
182 | // purpose : |
183 | // ======================================================================= |
184 | void Graphic3d_ClipPlane::SetCappingColor (const Quantity_Color& theColor) |
185 | { |
186 | myAspect->SetInteriorColor (theColor); |
187 | myAspect->ChangeFrontMaterial().SetColor (theColor); |
188 | ++myAspectMod; |
189 | } |
190 | |
4269bd1b |
191 | // ======================================================================= |
192 | // function : SetCappingMaterial |
193 | // purpose : |
194 | // ======================================================================= |
195 | void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat) |
196 | { |
3e05329c |
197 | myAspect->SetFrontMaterial (theMat); |
61168418 |
198 | if (myAspect->FrontMaterial().MaterialType() != Graphic3d_MATERIAL_ASPECT) |
199 | { |
200 | myAspect->SetInteriorColor (theMat.Color()); |
201 | } |
3e05329c |
202 | ++myAspectMod; |
4269bd1b |
203 | } |
204 | |
205 | // ======================================================================= |
206 | // function : SetCappingTexture |
207 | // purpose : |
208 | // ======================================================================= |
209 | void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture) |
210 | { |
3e05329c |
211 | if (!theTexture.IsNull()) |
212 | { |
213 | myAspect->SetTextureMapOn(); |
cc8cbabe |
214 | Handle(Graphic3d_TextureSet) aTextureSet = myAspect->TextureSet(); |
215 | if (aTextureSet.IsNull() || aTextureSet->Size() != 1) |
216 | { |
217 | aTextureSet = new Graphic3d_TextureSet (theTexture); |
218 | } |
219 | else |
220 | { |
221 | aTextureSet->SetFirst (theTexture); |
222 | } |
223 | myAspect->SetTextureSet (aTextureSet); |
3e05329c |
224 | } |
225 | else |
226 | { |
227 | myAspect->SetTextureMapOff(); |
cc8cbabe |
228 | myAspect->SetTextureSet (Handle(Graphic3d_TextureSet)()); |
3e05329c |
229 | } |
230 | ++myAspectMod; |
4269bd1b |
231 | } |
232 | |
233 | // ======================================================================= |
234 | // function : SetCappingHatch |
235 | // purpose : |
236 | // ======================================================================= |
237 | void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle) |
238 | { |
3e05329c |
239 | myAspect->SetHatchStyle (theStyle); |
240 | ++myAspectMod; |
4269bd1b |
241 | } |
242 | |
640d5fe2 |
243 | // ======================================================================= |
244 | // function : SetCappingCustomHatch |
245 | // purpose : |
246 | // ======================================================================= |
247 | void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle) |
248 | { |
249 | myAspect->SetHatchStyle (theStyle); |
250 | ++myAspectMod; |
251 | } |
252 | |
4269bd1b |
253 | // ======================================================================= |
254 | // function : SetCappingHatchOn |
255 | // purpose : |
256 | // ======================================================================= |
257 | void Graphic3d_ClipPlane::SetCappingHatchOn() |
258 | { |
3e05329c |
259 | myAspect->SetInteriorStyle (Aspect_IS_HATCH); |
260 | ++myAspectMod; |
4269bd1b |
261 | } |
262 | |
263 | // ======================================================================= |
264 | // function : SetCappingHatchOff |
265 | // purpose : |
266 | // ======================================================================= |
267 | void Graphic3d_ClipPlane::SetCappingHatchOff() |
268 | { |
3e05329c |
269 | myAspect->SetInteriorStyle (Aspect_IS_SOLID); |
270 | ++myAspectMod; |
4269bd1b |
271 | } |
272 | |
273 | // ======================================================================= |
3e05329c |
274 | // function : SetCappingAspect |
4269bd1b |
275 | // purpose : |
276 | // ======================================================================= |
3e05329c |
277 | void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) |
4269bd1b |
278 | { |
3e05329c |
279 | myAspect = theAspect; |
280 | ++myAspectMod; |
4269bd1b |
281 | } |
282 | |
283 | // ======================================================================= |
3e05329c |
284 | // function : setCappingFlag |
4269bd1b |
285 | // purpose : |
286 | // ======================================================================= |
3e05329c |
287 | void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag) |
4269bd1b |
288 | { |
3e05329c |
289 | if (theToUse) |
b2fbf11a |
290 | { |
3e05329c |
291 | myFlags |= theFlag; |
b2fbf11a |
292 | } |
293 | else |
294 | { |
3e05329c |
295 | myFlags &= ~(theFlag); |
b2fbf11a |
296 | } |
3e05329c |
297 | ++myAspectMod; |
298 | } |
299 | |
300 | // ======================================================================= |
301 | // function : makeId |
302 | // purpose : |
303 | // ======================================================================= |
304 | void Graphic3d_ClipPlane::makeId() |
305 | { |
306 | myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name() |
307 | + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER)); |
4269bd1b |
308 | } |
25c35042 |
309 | |
310 | // ======================================================================= |
311 | // function : updateChainLen |
312 | // purpose : |
313 | // ======================================================================= |
314 | void Graphic3d_ClipPlane::updateChainLen() |
315 | { |
316 | myChainLenFwd = !myNextInChain.IsNull() ? (myNextInChain->myChainLenFwd + 1) : 1; |
317 | if (myPrevInChain != NULL) |
318 | { |
319 | myPrevInChain->updateChainLen(); |
320 | } |
321 | } |
322 | |
323 | // ======================================================================= |
324 | // function : SetChainNextPlane |
325 | // purpose : |
326 | // ======================================================================= |
327 | void Graphic3d_ClipPlane::SetChainNextPlane (const Handle(Graphic3d_ClipPlane)& thePlane) |
328 | { |
329 | ++myEquationMod; |
330 | if (!myNextInChain.IsNull()) |
331 | { |
332 | myNextInChain->myPrevInChain = NULL; |
333 | } |
334 | myNextInChain = thePlane; |
335 | if (!myNextInChain.IsNull()) |
336 | { |
337 | myNextInChain->myPrevInChain = this; |
338 | } |
339 | updateChainLen(); |
340 | } |
bc73b006 |
341 | |
342 | // ======================================================================= |
343 | // function : DumpJson |
344 | // purpose : |
345 | // ======================================================================= |
346 | void Graphic3d_ClipPlane::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
347 | { |
348 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
349 | |
350 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, this) |
351 | |
352 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspect.get()) |
353 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myNextInChain.get()) |
354 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myPrevInChain) |
355 | |
356 | OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myId) |
357 | |
358 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPlane) |
359 | |
360 | OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "Equation", 4, myEquation.x(), myEquation.y(), myEquation.z(), myEquation.w()) |
361 | OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "EquationRev", 4, myEquationRev.x(), myEquationRev.y(), myEquationRev.z(), myEquationRev.w()) |
362 | |
363 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myChainLenFwd) |
364 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myFlags) |
365 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myEquationMod) |
366 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAspectMod) |
367 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsOn) |
368 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsCapping) |
369 | } |