0024070: OpenGL capped object-level clipping planes
[occt.git] / src / V3d / V3d_Plane.cxx
CommitLineData
b311480e 1// Created by: GG
2// Copyright (c) 1991-1999 Matra Datavision
4269bd1b 3// Copyright (c) 1999-2013 OPEN CASCADE SAS
b311480e 4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (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 S.A.S., 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
4269bd1b 20#include <V3d_Plane.hxx>
4952a30a 21#include <Graphic3d_Group.hxx>
4952a30a 22#include <Graphic3d_AspectFillArea3d.hxx>
4269bd1b 23#include <Graphic3d_ArrayOfQuadrangles.hxx>
4952a30a 24#include <gp_Pln.hxx>
25
4269bd1b 26IMPLEMENT_STANDARD_HANDLE(V3d_Plane, MMgt_TShared)
27IMPLEMENT_STANDARD_RTTIEXT(V3d_Plane, MMgt_TShared)
28
29// =======================================================================
30// function : V3d_Plane
31// purpose :
32// =======================================================================
33V3d_Plane::V3d_Plane (const Standard_Real theA,
34 const Standard_Real theB,
35 const Standard_Real theC,
36 const Standard_Real theD)
37: myGraphicStructure(),
38 myPlane (new Graphic3d_ClipPlane (gp_Pln (theA, theB, theC, theD)))
b8ddfc2f 39{
7fd59977 40}
41
4269bd1b 42// =======================================================================
43// function : V3d_Plane
44// purpose :
45// =======================================================================
46void V3d_Plane::SetPlane (const Standard_Real theA,
47 const Standard_Real theB,
48 const Standard_Real theC,
49 const Standard_Real theD)
b8ddfc2f 50{
4269bd1b 51 myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
52 if (IsDisplayed())
53 {
7fd59977 54 Update();
4269bd1b 55 }
7fd59977 56}
57
4269bd1b 58// =======================================================================
59// function : Display
60// purpose :
61// =======================================================================
62void V3d_Plane::Display (const Handle(V3d_View)& theView,
63 const Quantity_Color& theColor)
b8ddfc2f 64{
4269bd1b 65 Handle(V3d_Viewer) aViewer = theView->Viewer();
66 if (!myGraphicStructure.IsNull())
67 {
68 myGraphicStructure->Clear();
69 }
b8ddfc2f 70
4269bd1b 71 myGraphicStructure = new Graphic3d_Structure (aViewer->Viewer());
72 Handle(Graphic3d_Group) aGroup = new Graphic3d_Group (myGraphicStructure);
73 Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d();
74 Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC);
75 aPlastic.SetColor (theColor);
76 aPlastic.SetTransparency (0.5);
77 theView->SetTransparency (Standard_True);
78 anAsp->SetFrontMaterial (aPlastic);
79 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
80 anAsp->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE);
81 myGraphicStructure->SetPrimitivesAspect (anAsp);
82
83 const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize());
84 const Standard_ShortReal anOffset = aSize/5000.0f;
b8ddfc2f 85
86 Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
4269bd1b 87 aPrims->AddVertex (-aSize,-aSize, anOffset);
88 aPrims->AddVertex (-aSize, aSize, anOffset);
89 aPrims->AddVertex ( aSize, aSize, anOffset);
90 aPrims->AddVertex ( aSize,-aSize, anOffset);
91 aGroup->AddPrimitiveArray(aPrims);
b8ddfc2f 92
4269bd1b 93 myGraphicStructure->Display(0);
b8ddfc2f 94 Update();
7fd59977 95}
96
4269bd1b 97// =======================================================================
98// function : Erase
99// purpose :
100// =======================================================================
b8ddfc2f 101void V3d_Plane::Erase()
102{
4269bd1b 103 if (!myGraphicStructure.IsNull())
104 {
105 myGraphicStructure->Erase();
106 }
7fd59977 107}
108
4269bd1b 109// =======================================================================
110// function : Plane
111// purpose :
112// =======================================================================
113void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
b8ddfc2f 114{
4269bd1b 115 const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
116 theA = anEquation[0];
117 theB = anEquation[1];
118 theC = anEquation[2];
119 theD = anEquation[3];
7fd59977 120}
121
4269bd1b 122// =======================================================================
123// function : IsDisplayed
124// purpose :
125// =======================================================================
b8ddfc2f 126Standard_Boolean V3d_Plane::IsDisplayed() const
127{
4269bd1b 128 if (myGraphicStructure.IsNull())
129 {
130 return Standard_False;
131 }
132
133 return myGraphicStructure->IsDisplayed();
7fd59977 134}
135
4269bd1b 136// =======================================================================
137// function : Update
138// purpose :
139// =======================================================================
b8ddfc2f 140void V3d_Plane::Update()
141{
4269bd1b 142 if(!myGraphicStructure.IsNull())
143 {
144 TColStd_Array2OfReal aMatrix (1, 4, 1, 4);
145 Standard_Real theA, theB, theC, theD;
146 this->Plane(theA, theB, theC, theD);
147 gp_Pln aGeomPln (theA, theB, theC, theD);
148 gp_Trsf aTransform;
149 aTransform.SetTransformation (aGeomPln.Position());
150 aTransform.Invert();
151 for (Standard_Integer i = 1; i <= 3; i++)
152 {
153 for (Standard_Integer j = 1; j <= 4; j++)
154 {
155 aMatrix.SetValue (i, j, aTransform.Value (i,j));
7fd59977 156 }
157 }
4269bd1b 158
159 aMatrix.SetValue (4,1,0.);
160 aMatrix.SetValue (4,2,0.);
161 aMatrix.SetValue (4,3,0.);
162 aMatrix.SetValue (4,4,1.);
163 myGraphicStructure->SetTransform (aMatrix, Graphic3d_TOC_REPLACE);
7fd59977 164 }
165}