0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Graphic3d / Graphic3d_ClipPlane.cxx
CommitLineData
4269bd1b 1// Created on: 2013-07-12
2// Created by: Anton POLETAEV
3// Copyright (c) 2013 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 65 (the "License") You may not use the content of this file
7// except in compliance with the License Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file
9//
10// The Initial Developer of the Original Code is Open CASCADE SAS, having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License
19
20#include <Graphic3d_ClipPlane.hxx>
21#include <Graphic3d_AspectFillArea3d.hxx>
22#include <gp_Pln.hxx>
23#include <Standard_Atomic.hxx>
24
25IMPLEMENT_STANDARD_HANDLE(Graphic3d_ClipPlane, Standard_Transient)
26IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane, Standard_Transient)
27
28namespace
29{
30 static volatile Standard_Integer THE_CLIP_PLANE_COUNTER = 0;
31};
32
33// =======================================================================
34// function : Graphic3d_ClipPlane
35// purpose :
36// =======================================================================
37Graphic3d_ClipPlane::Graphic3d_ClipPlane()
38: myEquation (0.0, 0.0, 1.0, 0.0),
39 myIsOn (Standard_True),
40 myIsCapping (Standard_False),
41 myMaterial (Graphic3d_NOM_DEFAULT),
42 myTexture (NULL),
43 myHatch (Aspect_HS_HORIZONTAL),
44 myHatchOn (Standard_False),
45 myId(),
46 myEquationMod(0),
47 myAspectMod(0)
48{
49 MakeId();
50}
51
52// =======================================================================
53// function : Graphic3d_ClipPlane
54// purpose :
55// =======================================================================
56Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
57: myEquation (theEquation),
58 myIsOn (Standard_True),
59 myIsCapping (Standard_False),
60 myMaterial (Graphic3d_NOM_DEFAULT),
61 myTexture (NULL),
62 myHatch (Aspect_HS_HORIZONTAL),
63 myHatchOn (Standard_False),
64 myId(),
65 myEquationMod(0),
66 myAspectMod(0)
67{
68 MakeId();
69}
70
71// =======================================================================
72// function : Graphic3d_ClipPlane
73// purpose :
74// =======================================================================
75Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther)
76: myEquation (theOther.myEquation),
77 myIsOn (theOther.myIsOn),
78 myIsCapping (theOther.myIsCapping),
79 myMaterial (theOther.myMaterial),
80 myTexture (theOther.myTexture),
81 myHatch (theOther.myHatch),
82 myHatchOn (theOther.myHatchOn),
83 myId(),
84 myEquationMod (0),
85 myAspectMod (0)
86{
87 MakeId();
88}
89
90// =======================================================================
91// function : Graphic3d_ClipPlane
92// purpose :
93// =======================================================================
94Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
95: myEquation (),
96 myIsOn (Standard_True),
97 myIsCapping (Standard_False),
98 myMaterial (Graphic3d_NOM_DEFAULT),
99 myTexture (NULL),
100 myHatch (Aspect_HS_HORIZONTAL),
101 myHatchOn (Standard_False),
102 myId(),
103 myEquationMod(0),
104 myAspectMod(0)
105{
106 MakeId();
107 SetEquation (thePlane);
108}
109
110// =======================================================================
111// function : SetEquation
112// purpose :
113// =======================================================================
114void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
115{
116 myEquation = theEquation;
117 myEquationMod++;
118}
119
120// =======================================================================
121// function : SetPlane
122// purpose :
123// =======================================================================
124void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
125{
126 thePlane.Coefficients (myEquation[0],
127 myEquation[1],
128 myEquation[2],
129 myEquation[3]);
130 myEquationMod++;
131}
132
133// =======================================================================
134// function : SetOn
135// purpose :
136// =======================================================================
137void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
138{
139 myIsOn = theIsOn;
140}
141
142// =======================================================================
143// function : SetCapping
144// purpose :
145// =======================================================================
146void Graphic3d_ClipPlane::SetCapping (const Standard_Boolean theIsOn)
147{
148 myIsCapping = theIsOn;
149}
150
151// =======================================================================
152// function : ToPlane
153// purpose :
154// =======================================================================
155gp_Pln Graphic3d_ClipPlane::ToPlane() const
156{
157 return gp_Pln (myEquation[0],
158 myEquation[1],
159 myEquation[2],
160 myEquation[3]);
161}
162
163// =======================================================================
164// function : Clone
165// purpose :
166// =======================================================================
167Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const
168{
169 return new Graphic3d_ClipPlane(*this);
170}
171
172// =======================================================================
173// function : SetCappingMaterial
174// purpose :
175// =======================================================================
176void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat)
177{
178 myMaterial = theMat;
179 myAspectMod++;
180}
181
182// =======================================================================
183// function : SetCappingTexture
184// purpose :
185// =======================================================================
186void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture)
187{
188 myTexture = theTexture;
189 myAspectMod++;
190}
191
192// =======================================================================
193// function : SetCappingHatch
194// purpose :
195// =======================================================================
196void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle)
197{
198 myHatch = theStyle;
199 myAspectMod++;
200}
201
202// =======================================================================
203// function : SetCappingHatchOn
204// purpose :
205// =======================================================================
206void Graphic3d_ClipPlane::SetCappingHatchOn()
207{
208 myHatchOn = Standard_True;
209 myAspectMod++;
210}
211
212// =======================================================================
213// function : SetCappingHatchOff
214// purpose :
215// =======================================================================
216void Graphic3d_ClipPlane::SetCappingHatchOff()
217{
218 myHatchOn = Standard_False;
219 myAspectMod++;
220}
221
222// =======================================================================
223// function : MakeId
224// purpose :
225// =======================================================================
226void Graphic3d_ClipPlane::MakeId()
227{
228 myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
229 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
230}
231
232// =======================================================================
233// function : CappingAspect
234// purpose :
235// =======================================================================
236Handle(Graphic3d_AspectFillArea3d) Graphic3d_ClipPlane::CappingAspect() const
237{
238 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
239 anAspect->SetDistinguishOff();
240 anAspect->SetFrontMaterial (myMaterial);
241 anAspect->SetTextureMap (myTexture);
242 anAspect->SetHatchStyle (myHatch);
243 anAspect->SetInteriorStyle (myHatchOn ? Aspect_IS_HATCH : Aspect_IS_SOLID);
244 anAspect->SetInteriorColor (myMaterial.Color());
245 if (!myTexture.IsNull())
246 anAspect->SetTextureMapOn();
247 else
248 anAspect->SetTextureMapOff();
249
250 return anAspect;
251}