0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / Graphic3d / Graphic3d_ClipPlane.cxx
1 // Created on: 2013-07-12
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <Graphic3d_ClipPlane.hxx>
17 #include <Graphic3d_AspectFillArea3d.hxx>
18 #include <gp_Pln.hxx>
19 #include <Standard_Atomic.hxx>
20
21 IMPLEMENT_STANDARD_HANDLE(Graphic3d_ClipPlane, Standard_Transient)
22 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane, Standard_Transient)
23
24 namespace
25 {
26   static volatile Standard_Integer THE_CLIP_PLANE_COUNTER = 0;
27 };
28
29 // =======================================================================
30 // function : Graphic3d_ClipPlane
31 // purpose  :
32 // =======================================================================
33 Graphic3d_ClipPlane::Graphic3d_ClipPlane()
34 : myEquation (0.0, 0.0, 1.0, 0.0),
35   myIsOn (Standard_True),
36   myIsCapping (Standard_False),
37   myMaterial (Graphic3d_NOM_DEFAULT),
38   myTexture (NULL),
39   myHatch (Aspect_HS_HORIZONTAL),
40   myHatchOn (Standard_False),
41   myId(),
42   myEquationMod(0),
43   myAspectMod(0)
44 {
45   MakeId();
46 }
47
48 // =======================================================================
49 // function : Graphic3d_ClipPlane
50 // purpose  :
51 // =======================================================================
52 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
53 : myEquation (theEquation),
54   myIsOn (Standard_True),
55   myIsCapping (Standard_False),
56   myMaterial (Graphic3d_NOM_DEFAULT),
57   myTexture (NULL),
58   myHatch (Aspect_HS_HORIZONTAL),
59   myHatchOn (Standard_False),
60   myId(),
61   myEquationMod(0),
62   myAspectMod(0)
63 {
64   MakeId();
65 }
66
67 // =======================================================================
68 // function : Graphic3d_ClipPlane
69 // purpose  :
70 // =======================================================================
71 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther)
72 : myEquation (theOther.myEquation),
73   myIsOn (theOther.myIsOn),
74   myIsCapping (theOther.myIsCapping),
75   myMaterial (theOther.myMaterial),
76   myTexture (theOther.myTexture),
77   myHatch (theOther.myHatch),
78   myHatchOn (theOther.myHatchOn),
79   myId(),
80   myEquationMod (0),
81   myAspectMod (0)
82 {
83   MakeId();
84 }
85
86 // =======================================================================
87 // function : Graphic3d_ClipPlane
88 // purpose  :
89 // =======================================================================
90 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
91 : myEquation (),
92   myIsOn (Standard_True),
93   myIsCapping (Standard_False),
94   myMaterial (Graphic3d_NOM_DEFAULT),
95   myTexture (NULL),
96   myHatch (Aspect_HS_HORIZONTAL),
97   myHatchOn (Standard_False),
98   myId(),
99   myEquationMod(0),
100   myAspectMod(0)
101 {
102   MakeId();
103   SetEquation (thePlane);
104 }
105
106 // =======================================================================
107 // function : SetEquation
108 // purpose  :
109 // =======================================================================
110 void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
111 {
112   myEquation = theEquation;
113   myEquationMod++;
114 }
115
116 // =======================================================================
117 // function : SetPlane
118 // purpose  :
119 // =======================================================================
120 void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
121 {
122   thePlane.Coefficients (myEquation[0],
123                          myEquation[1],
124                          myEquation[2],
125                          myEquation[3]);
126   myEquationMod++;
127 }
128
129 // =======================================================================
130 // function : SetOn
131 // purpose  :
132 // =======================================================================
133 void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
134 {
135   myIsOn = theIsOn;
136 }
137
138 // =======================================================================
139 // function : SetCapping
140 // purpose  :
141 // =======================================================================
142 void Graphic3d_ClipPlane::SetCapping (const Standard_Boolean theIsOn)
143 {
144   myIsCapping = theIsOn;
145 }
146
147 // =======================================================================
148 // function : ToPlane
149 // purpose  :
150 // =======================================================================
151 gp_Pln Graphic3d_ClipPlane::ToPlane() const
152 {
153   return gp_Pln (myEquation[0],
154                  myEquation[1],
155                  myEquation[2],
156                  myEquation[3]);
157 }
158
159 // =======================================================================
160 // function : Clone
161 // purpose  :
162 // =======================================================================
163 Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const
164 {
165   return new Graphic3d_ClipPlane(*this);
166 }
167
168 // =======================================================================
169 // function : SetCappingMaterial
170 // purpose  :
171 // =======================================================================
172 void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat)
173 {
174   myMaterial = theMat;
175   myAspectMod++;
176 }
177
178 // =======================================================================
179 // function : SetCappingTexture
180 // purpose  :
181 // =======================================================================
182 void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture)
183 {
184   myTexture = theTexture;
185   myAspectMod++;
186 }
187
188 // =======================================================================
189 // function : SetCappingHatch
190 // purpose  :
191 // =======================================================================
192 void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle)
193 {
194   myHatch = theStyle;
195   myAspectMod++;
196 }
197
198 // =======================================================================
199 // function : SetCappingHatchOn
200 // purpose  :
201 // =======================================================================
202 void Graphic3d_ClipPlane::SetCappingHatchOn()
203 {
204   myHatchOn = Standard_True;
205   myAspectMod++;
206 }
207
208 // =======================================================================
209 // function : SetCappingHatchOff
210 // purpose  :
211 // =======================================================================
212 void Graphic3d_ClipPlane::SetCappingHatchOff()
213 {
214   myHatchOn = Standard_False;
215   myAspectMod++;
216 }
217
218 // =======================================================================
219 // function : MakeId
220 // purpose  :
221 // =======================================================================
222 void Graphic3d_ClipPlane::MakeId()
223 {
224   myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
225        + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
226 }
227
228 // =======================================================================
229 // function : CappingAspect
230 // purpose  :
231 // =======================================================================
232 Handle(Graphic3d_AspectFillArea3d) Graphic3d_ClipPlane::CappingAspect() const
233 {
234   Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
235   anAspect->SetDistinguishOff();
236   anAspect->SetFrontMaterial (myMaterial);
237   anAspect->SetTextureMap (myTexture);
238   anAspect->SetHatchStyle (myHatch);
239   anAspect->SetInteriorStyle (myHatchOn ? Aspect_IS_HATCH : Aspect_IS_SOLID);
240   anAspect->SetInteriorColor (myMaterial.Color());
241   if (!myTexture.IsNull())
242     anAspect->SetTextureMapOn();
243   else
244     anAspect->SetTextureMapOff();
245
246   return anAspect;
247 }