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()), |
48 | myPlane (0.0, 0.0, 1.0, 0.0), |
49 | myEquation (0.0, 0.0, 1.0, 0.0), |
50 | myFlags (Graphic3d_CappingFlags_None), |
4269bd1b |
51 | myEquationMod(0), |
7c3ef2f7 |
52 | myAspectMod (0), |
53 | myIsOn (Standard_True), |
54 | myIsCapping (Standard_False) |
4269bd1b |
55 | { |
3e05329c |
56 | makeId(); |
4269bd1b |
57 | } |
58 | |
59 | // ======================================================================= |
60 | // function : Graphic3d_ClipPlane |
61 | // purpose : |
62 | // ======================================================================= |
63 | Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation) |
7c3ef2f7 |
64 | : myAspect (defaultAspect()), |
65 | myPlane (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()), |
66 | myEquation (theEquation), |
67 | myFlags (Graphic3d_CappingFlags_None), |
4269bd1b |
68 | myEquationMod(0), |
7c3ef2f7 |
69 | myAspectMod (0), |
70 | myIsOn (Standard_True), |
71 | myIsCapping (Standard_False) |
4269bd1b |
72 | { |
3e05329c |
73 | makeId(); |
4269bd1b |
74 | } |
75 | |
76 | // ======================================================================= |
77 | // function : Graphic3d_ClipPlane |
78 | // purpose : |
79 | // ======================================================================= |
80 | Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther) |
a9b30f0a |
81 | : Standard_Transient(theOther), |
7c3ef2f7 |
82 | myAspect (defaultAspect()), |
83 | myPlane (theOther.myPlane), |
84 | myEquation (theOther.myEquation), |
85 | myFlags (theOther.myFlags), |
86 | myEquationMod(0), |
87 | myAspectMod (0), |
88 | myIsOn (theOther.myIsOn), |
89 | myIsCapping (theOther.myIsCapping) |
4269bd1b |
90 | { |
3e05329c |
91 | makeId(); |
92 | *myAspect = *theOther.CappingAspect(); |
4269bd1b |
93 | } |
94 | |
95 | // ======================================================================= |
96 | // function : Graphic3d_ClipPlane |
97 | // purpose : |
98 | // ======================================================================= |
99 | Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane) |
7c3ef2f7 |
100 | : myAspect (defaultAspect()), |
101 | myPlane (thePlane), |
102 | myFlags (Graphic3d_CappingFlags_None), |
4269bd1b |
103 | myEquationMod(0), |
7c3ef2f7 |
104 | myAspectMod (0), |
105 | myIsOn (Standard_True), |
106 | myIsCapping (Standard_False) |
4269bd1b |
107 | { |
7c3ef2f7 |
108 | thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]); |
3e05329c |
109 | makeId(); |
4269bd1b |
110 | } |
111 | |
112 | // ======================================================================= |
113 | // function : SetEquation |
114 | // purpose : |
115 | // ======================================================================= |
116 | void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation) |
117 | { |
7c3ef2f7 |
118 | myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()); |
4269bd1b |
119 | myEquation = theEquation; |
120 | myEquationMod++; |
121 | } |
122 | |
123 | // ======================================================================= |
124 | // function : SetPlane |
125 | // purpose : |
126 | // ======================================================================= |
127 | void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane) |
128 | { |
7c3ef2f7 |
129 | myPlane = thePlane; |
4269bd1b |
130 | thePlane.Coefficients (myEquation[0], |
131 | myEquation[1], |
132 | myEquation[2], |
133 | myEquation[3]); |
134 | myEquationMod++; |
135 | } |
136 | |
137 | // ======================================================================= |
138 | // function : SetOn |
139 | // purpose : |
140 | // ======================================================================= |
141 | void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn) |
142 | { |
143 | myIsOn = theIsOn; |
144 | } |
145 | |
146 | // ======================================================================= |
147 | // function : SetCapping |
148 | // purpose : |
149 | // ======================================================================= |
150 | void Graphic3d_ClipPlane::SetCapping (const Standard_Boolean theIsOn) |
151 | { |
152 | myIsCapping = theIsOn; |
153 | } |
154 | |
4269bd1b |
155 | // ======================================================================= |
156 | // function : Clone |
157 | // purpose : |
158 | // ======================================================================= |
159 | Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const |
160 | { |
161 | return new Graphic3d_ClipPlane(*this); |
162 | } |
163 | |
164 | // ======================================================================= |
165 | // function : SetCappingMaterial |
166 | // purpose : |
167 | // ======================================================================= |
168 | void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat) |
169 | { |
3e05329c |
170 | myAspect->SetFrontMaterial (theMat); |
171 | myAspect->SetInteriorColor (theMat.Color()); |
172 | ++myAspectMod; |
4269bd1b |
173 | } |
174 | |
175 | // ======================================================================= |
176 | // function : SetCappingTexture |
177 | // purpose : |
178 | // ======================================================================= |
179 | void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture) |
180 | { |
3e05329c |
181 | if (!theTexture.IsNull()) |
182 | { |
183 | myAspect->SetTextureMapOn(); |
cc8cbabe |
184 | Handle(Graphic3d_TextureSet) aTextureSet = myAspect->TextureSet(); |
185 | if (aTextureSet.IsNull() || aTextureSet->Size() != 1) |
186 | { |
187 | aTextureSet = new Graphic3d_TextureSet (theTexture); |
188 | } |
189 | else |
190 | { |
191 | aTextureSet->SetFirst (theTexture); |
192 | } |
193 | myAspect->SetTextureSet (aTextureSet); |
3e05329c |
194 | } |
195 | else |
196 | { |
197 | myAspect->SetTextureMapOff(); |
cc8cbabe |
198 | myAspect->SetTextureSet (Handle(Graphic3d_TextureSet)()); |
3e05329c |
199 | } |
200 | ++myAspectMod; |
4269bd1b |
201 | } |
202 | |
203 | // ======================================================================= |
204 | // function : SetCappingHatch |
205 | // purpose : |
206 | // ======================================================================= |
207 | void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle) |
208 | { |
3e05329c |
209 | myAspect->SetHatchStyle (theStyle); |
210 | ++myAspectMod; |
4269bd1b |
211 | } |
212 | |
640d5fe2 |
213 | // ======================================================================= |
214 | // function : SetCappingCustomHatch |
215 | // purpose : |
216 | // ======================================================================= |
217 | void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle) |
218 | { |
219 | myAspect->SetHatchStyle (theStyle); |
220 | ++myAspectMod; |
221 | } |
222 | |
4269bd1b |
223 | // ======================================================================= |
224 | // function : SetCappingHatchOn |
225 | // purpose : |
226 | // ======================================================================= |
227 | void Graphic3d_ClipPlane::SetCappingHatchOn() |
228 | { |
3e05329c |
229 | myAspect->SetInteriorStyle (Aspect_IS_HATCH); |
230 | ++myAspectMod; |
4269bd1b |
231 | } |
232 | |
233 | // ======================================================================= |
234 | // function : SetCappingHatchOff |
235 | // purpose : |
236 | // ======================================================================= |
237 | void Graphic3d_ClipPlane::SetCappingHatchOff() |
238 | { |
3e05329c |
239 | myAspect->SetInteriorStyle (Aspect_IS_SOLID); |
240 | ++myAspectMod; |
4269bd1b |
241 | } |
242 | |
243 | // ======================================================================= |
3e05329c |
244 | // function : SetCappingAspect |
4269bd1b |
245 | // purpose : |
246 | // ======================================================================= |
3e05329c |
247 | void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) |
4269bd1b |
248 | { |
3e05329c |
249 | myAspect = theAspect; |
250 | ++myAspectMod; |
4269bd1b |
251 | } |
252 | |
253 | // ======================================================================= |
3e05329c |
254 | // function : setCappingFlag |
4269bd1b |
255 | // purpose : |
256 | // ======================================================================= |
3e05329c |
257 | void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag) |
4269bd1b |
258 | { |
3e05329c |
259 | if (theToUse) |
b2fbf11a |
260 | { |
3e05329c |
261 | myFlags |= theFlag; |
b2fbf11a |
262 | } |
263 | else |
264 | { |
3e05329c |
265 | myFlags &= ~(theFlag); |
b2fbf11a |
266 | } |
3e05329c |
267 | ++myAspectMod; |
268 | } |
269 | |
270 | // ======================================================================= |
271 | // function : makeId |
272 | // purpose : |
273 | // ======================================================================= |
274 | void Graphic3d_ClipPlane::makeId() |
275 | { |
276 | myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name() |
277 | + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER)); |
4269bd1b |
278 | } |