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