0028107: Visualization - provide a flexible interface to set custom hatch styles
[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()
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// =======================================================================
63Graphic3d_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// =======================================================================
80Graphic3d_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// =======================================================================
99Graphic3d_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// =======================================================================
116void 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// =======================================================================
127void 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// =======================================================================
141void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
142{
143 myIsOn = theIsOn;
144}
145
146// =======================================================================
147// function : SetCapping
148// purpose :
149// =======================================================================
150void Graphic3d_ClipPlane::SetCapping (const Standard_Boolean theIsOn)
151{
152 myIsCapping = theIsOn;
153}
154
4269bd1b 155// =======================================================================
156// function : Clone
157// purpose :
158// =======================================================================
159Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const
160{
161 return new Graphic3d_ClipPlane(*this);
162}
163
164// =======================================================================
165// function : SetCappingMaterial
166// purpose :
167// =======================================================================
168void 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// =======================================================================
179void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture)
180{
3e05329c 181 myAspect->SetTextureMap (theTexture);
182 if (!theTexture.IsNull())
183 {
184 myAspect->SetTextureMapOn();
185 }
186 else
187 {
188 myAspect->SetTextureMapOff();
189 }
190 ++myAspectMod;
4269bd1b 191}
192
193// =======================================================================
194// function : SetCappingHatch
195// purpose :
196// =======================================================================
197void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle)
198{
3e05329c 199 myAspect->SetHatchStyle (theStyle);
200 ++myAspectMod;
4269bd1b 201}
202
640d5fe2 203// =======================================================================
204// function : SetCappingCustomHatch
205// purpose :
206// =======================================================================
207void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle)
208{
209 myAspect->SetHatchStyle (theStyle);
210 ++myAspectMod;
211}
212
4269bd1b 213// =======================================================================
214// function : SetCappingHatchOn
215// purpose :
216// =======================================================================
217void Graphic3d_ClipPlane::SetCappingHatchOn()
218{
3e05329c 219 myAspect->SetInteriorStyle (Aspect_IS_HATCH);
220 ++myAspectMod;
4269bd1b 221}
222
223// =======================================================================
224// function : SetCappingHatchOff
225// purpose :
226// =======================================================================
227void Graphic3d_ClipPlane::SetCappingHatchOff()
228{
3e05329c 229 myAspect->SetInteriorStyle (Aspect_IS_SOLID);
230 ++myAspectMod;
4269bd1b 231}
232
233// =======================================================================
3e05329c 234// function : SetCappingAspect
4269bd1b 235// purpose :
236// =======================================================================
3e05329c 237void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect)
4269bd1b 238{
3e05329c 239 myAspect = theAspect;
240 ++myAspectMod;
4269bd1b 241}
242
243// =======================================================================
3e05329c 244// function : setCappingFlag
4269bd1b 245// purpose :
246// =======================================================================
3e05329c 247void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag)
4269bd1b 248{
3e05329c 249 if (theToUse)
b2fbf11a 250 {
3e05329c 251 myFlags |= theFlag;
b2fbf11a 252 }
253 else
254 {
3e05329c 255 myFlags &= ~(theFlag);
b2fbf11a 256 }
3e05329c 257 ++myAspectMod;
258}
259
260// =======================================================================
261// function : makeId
262// purpose :
263// =======================================================================
264void Graphic3d_ClipPlane::makeId()
265{
266 myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
267 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
4269bd1b 268}