0024752: Visualization - inherit OpenGl_Group from Graphic3d_Group
[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//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
4269bd1b 16#include <V3d_Plane.hxx>
4952a30a 17#include <Graphic3d_Group.hxx>
4952a30a 18#include <Graphic3d_AspectFillArea3d.hxx>
4269bd1b 19#include <Graphic3d_ArrayOfQuadrangles.hxx>
4952a30a 20#include <gp_Pln.hxx>
21
4269bd1b 22IMPLEMENT_STANDARD_HANDLE(V3d_Plane, MMgt_TShared)
23IMPLEMENT_STANDARD_RTTIEXT(V3d_Plane, MMgt_TShared)
24
25// =======================================================================
26// function : V3d_Plane
27// purpose :
28// =======================================================================
29V3d_Plane::V3d_Plane (const Standard_Real theA,
30 const Standard_Real theB,
31 const Standard_Real theC,
32 const Standard_Real theD)
33: myGraphicStructure(),
34 myPlane (new Graphic3d_ClipPlane (gp_Pln (theA, theB, theC, theD)))
b8ddfc2f 35{
7fd59977 36}
37
4269bd1b 38// =======================================================================
39// function : V3d_Plane
40// purpose :
41// =======================================================================
42void V3d_Plane::SetPlane (const Standard_Real theA,
43 const Standard_Real theB,
44 const Standard_Real theC,
45 const Standard_Real theD)
b8ddfc2f 46{
4269bd1b 47 myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
48 if (IsDisplayed())
49 {
7fd59977 50 Update();
4269bd1b 51 }
7fd59977 52}
53
4269bd1b 54// =======================================================================
55// function : Display
56// purpose :
57// =======================================================================
58void V3d_Plane::Display (const Handle(V3d_View)& theView,
59 const Quantity_Color& theColor)
b8ddfc2f 60{
4269bd1b 61 Handle(V3d_Viewer) aViewer = theView->Viewer();
62 if (!myGraphicStructure.IsNull())
63 {
64 myGraphicStructure->Clear();
65 }
b8ddfc2f 66
4269bd1b 67 myGraphicStructure = new Graphic3d_Structure (aViewer->Viewer());
b64d84be 68 Handle(Graphic3d_Group) aGroup = myGraphicStructure->NewGroup();
69 Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d();
4269bd1b 70 Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC);
71 aPlastic.SetColor (theColor);
72 aPlastic.SetTransparency (0.5);
73 theView->SetTransparency (Standard_True);
74 anAsp->SetFrontMaterial (aPlastic);
75 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
76 anAsp->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE);
77 myGraphicStructure->SetPrimitivesAspect (anAsp);
78
79 const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize());
80 const Standard_ShortReal anOffset = aSize/5000.0f;
b8ddfc2f 81
82 Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
4269bd1b 83 aPrims->AddVertex (-aSize,-aSize, anOffset);
84 aPrims->AddVertex (-aSize, aSize, anOffset);
85 aPrims->AddVertex ( aSize, aSize, anOffset);
86 aPrims->AddVertex ( aSize,-aSize, anOffset);
87 aGroup->AddPrimitiveArray(aPrims);
b8ddfc2f 88
4269bd1b 89 myGraphicStructure->Display(0);
b8ddfc2f 90 Update();
7fd59977 91}
92
4269bd1b 93// =======================================================================
94// function : Erase
95// purpose :
96// =======================================================================
b8ddfc2f 97void V3d_Plane::Erase()
98{
4269bd1b 99 if (!myGraphicStructure.IsNull())
100 {
101 myGraphicStructure->Erase();
102 }
7fd59977 103}
104
4269bd1b 105// =======================================================================
106// function : Plane
107// purpose :
108// =======================================================================
109void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
b8ddfc2f 110{
4269bd1b 111 const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
112 theA = anEquation[0];
113 theB = anEquation[1];
114 theC = anEquation[2];
115 theD = anEquation[3];
7fd59977 116}
117
4269bd1b 118// =======================================================================
119// function : IsDisplayed
120// purpose :
121// =======================================================================
b8ddfc2f 122Standard_Boolean V3d_Plane::IsDisplayed() const
123{
4269bd1b 124 if (myGraphicStructure.IsNull())
125 {
126 return Standard_False;
127 }
128
129 return myGraphicStructure->IsDisplayed();
7fd59977 130}
131
4269bd1b 132// =======================================================================
133// function : Update
134// purpose :
135// =======================================================================
b8ddfc2f 136void V3d_Plane::Update()
137{
4269bd1b 138 if(!myGraphicStructure.IsNull())
139 {
140 TColStd_Array2OfReal aMatrix (1, 4, 1, 4);
141 Standard_Real theA, theB, theC, theD;
142 this->Plane(theA, theB, theC, theD);
143 gp_Pln aGeomPln (theA, theB, theC, theD);
144 gp_Trsf aTransform;
145 aTransform.SetTransformation (aGeomPln.Position());
146 aTransform.Invert();
147 for (Standard_Integer i = 1; i <= 3; i++)
148 {
149 for (Standard_Integer j = 1; j <= 4; j++)
150 {
151 aMatrix.SetValue (i, j, aTransform.Value (i,j));
7fd59977 152 }
153 }
4269bd1b 154
155 aMatrix.SetValue (4,1,0.);
156 aMatrix.SetValue (4,2,0.);
157 aMatrix.SetValue (4,3,0.);
158 aMatrix.SetValue (4,4,1.);
159 myGraphicStructure->SetTransform (aMatrix, Graphic3d_TOC_REPLACE);
7fd59977 160 }
161}