1 // Created on: 2013-07-12
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_ClipPlane.hxx>
18 #include <Graphic3d_AspectFillArea3d.hxx>
20 #include <Standard_Atomic.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
26 static volatile Standard_Integer THE_CLIP_PLANE_COUNTER = 0;
28 static Handle(Graphic3d_AspectFillArea3d) defaultAspect()
30 Graphic3d_MaterialAspect aMaterial (Graphic3d_NameOfMaterial_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 (Quantity_NOC_GRAY20);
37 anAspect->SetFaceCulling (Graphic3d_TypeOfBackfacingModel_DoubleSided);
42 // =======================================================================
43 // function : Graphic3d_ClipPlane
45 // =======================================================================
46 Graphic3d_ClipPlane::Graphic3d_ClipPlane()
47 : myAspect (defaultAspect()),
49 myPlane (0.0, 0.0, 1.0, 0.0),
50 myEquation (0.0, 0.0, 1.0, 0.0),
51 myEquationRev(0.0, 0.0,-1.0, 0.0),
53 myFlags (Graphic3d_CappingFlags_None),
56 myIsOn (Standard_True),
57 myIsCapping (Standard_False)
62 // =======================================================================
63 // function : Graphic3d_ClipPlane
65 // =======================================================================
66 Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_Vec4d& theEquation)
67 : myAspect (defaultAspect()),
69 myPlane (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()),
70 myEquation (theEquation),
71 myEquationRev(0.0, 0.0,-1.0, 0.0),
73 myFlags (Graphic3d_CappingFlags_None),
76 myIsOn (Standard_True),
77 myIsCapping (Standard_False)
80 updateInversedPlane();
83 // =======================================================================
84 // function : Graphic3d_ClipPlane
86 // =======================================================================
87 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther)
88 : Standard_Transient(theOther),
89 myAspect (defaultAspect()),
91 myPlane (theOther.myPlane),
92 myEquation (theOther.myEquation),
93 myEquationRev(theOther.myEquationRev),
95 myFlags (theOther.myFlags),
98 myIsOn (theOther.myIsOn),
99 myIsCapping (theOther.myIsCapping)
102 *myAspect = *theOther.CappingAspect();
105 // =======================================================================
106 // function : Graphic3d_ClipPlane
108 // =======================================================================
109 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
110 : myAspect (defaultAspect()),
114 myFlags (Graphic3d_CappingFlags_None),
117 myIsOn (Standard_True),
118 myIsCapping (Standard_False)
120 thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
121 updateInversedPlane();
125 // =======================================================================
126 // function : SetEquation
128 // =======================================================================
129 void Graphic3d_ClipPlane::SetEquation (const Graphic3d_Vec4d& theEquation)
131 myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w());
132 myEquation = theEquation;
133 updateInversedPlane();
137 // =======================================================================
138 // function : SetPlane
140 // =======================================================================
141 void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
144 thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
145 updateInversedPlane();
149 // =======================================================================
152 // =======================================================================
153 void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
155 if (myPrevInChain != NULL)
157 throw Standard_ProgramError ("Graphic3d_ClipPlane::SetOn() - undefined operation for a plane in Union");
162 // =======================================================================
163 // function : SetCapping
165 // =======================================================================
166 void Graphic3d_ClipPlane::SetCapping (const Standard_Boolean theIsOn)
168 myIsCapping = theIsOn;
171 // =======================================================================
174 // =======================================================================
175 Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const
177 return new Graphic3d_ClipPlane(*this);
180 // =======================================================================
181 // function : SetCappingColor
183 // =======================================================================
184 void Graphic3d_ClipPlane::SetCappingColor (const Quantity_Color& theColor)
186 myAspect->SetInteriorColor (theColor);
187 myAspect->ChangeFrontMaterial().SetColor (theColor);
191 // =======================================================================
192 // function : SetCappingMaterial
194 // =======================================================================
195 void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat)
197 myAspect->SetFrontMaterial (theMat);
198 if (myAspect->FrontMaterial().MaterialType() != Graphic3d_MATERIAL_ASPECT)
200 myAspect->SetInteriorColor (theMat.Color());
205 // =======================================================================
206 // function : SetCappingTexture
208 // =======================================================================
209 void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture)
211 if (!theTexture.IsNull())
213 myAspect->SetTextureMapOn();
214 Handle(Graphic3d_TextureSet) aTextureSet = myAspect->TextureSet();
215 if (aTextureSet.IsNull() || aTextureSet->Size() != 1)
217 aTextureSet = new Graphic3d_TextureSet (theTexture);
221 aTextureSet->SetFirst (theTexture);
223 myAspect->SetTextureSet (aTextureSet);
227 myAspect->SetTextureMapOff();
228 myAspect->SetTextureSet (Handle(Graphic3d_TextureSet)());
233 // =======================================================================
234 // function : SetCappingHatch
236 // =======================================================================
237 void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle)
239 myAspect->SetHatchStyle (theStyle);
243 // =======================================================================
244 // function : SetCappingCustomHatch
246 // =======================================================================
247 void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle)
249 myAspect->SetHatchStyle (theStyle);
253 // =======================================================================
254 // function : SetCappingHatchOn
256 // =======================================================================
257 void Graphic3d_ClipPlane::SetCappingHatchOn()
259 myAspect->SetInteriorStyle (Aspect_IS_HATCH);
263 // =======================================================================
264 // function : SetCappingHatchOff
266 // =======================================================================
267 void Graphic3d_ClipPlane::SetCappingHatchOff()
269 myAspect->SetInteriorStyle (Aspect_IS_SOLID);
273 // =======================================================================
274 // function : SetCappingAspect
276 // =======================================================================
277 void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect)
279 myAspect = theAspect;
283 // =======================================================================
284 // function : setCappingFlag
286 // =======================================================================
287 void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag)
295 myFlags &= ~(theFlag);
300 // =======================================================================
303 // =======================================================================
304 void Graphic3d_ClipPlane::makeId()
306 myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
307 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
310 // =======================================================================
311 // function : updateChainLen
313 // =======================================================================
314 void Graphic3d_ClipPlane::updateChainLen()
316 myChainLenFwd = !myNextInChain.IsNull() ? (myNextInChain->myChainLenFwd + 1) : 1;
317 if (myPrevInChain != NULL)
319 myPrevInChain->updateChainLen();
323 // =======================================================================
324 // function : SetChainNextPlane
326 // =======================================================================
327 void Graphic3d_ClipPlane::SetChainNextPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
330 if (!myNextInChain.IsNull())
332 myNextInChain->myPrevInChain = NULL;
334 myNextInChain = thePlane;
335 if (!myNextInChain.IsNull())
337 myNextInChain->myPrevInChain = this;
342 // =======================================================================
343 // function : DumpJson
345 // =======================================================================
346 void Graphic3d_ClipPlane::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
348 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
350 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, this)
352 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspect.get())
353 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myNextInChain.get())
354 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myPrevInChain)
356 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myId)
358 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPlane)
360 OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "Equation", 4, myEquation.x(), myEquation.y(), myEquation.z(), myEquation.w())
361 OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "EquationRev", 4, myEquationRev.x(), myEquationRev.y(), myEquationRev.z(), myEquationRev.w())
363 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myChainLenFwd)
364 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myFlags)
365 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myEquationMod)
366 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAspectMod)
367 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsOn)
368 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsCapping)