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