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