2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2013 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 <V3d_Plane.hxx>
17 #include <Graphic3d_Group.hxx>
18 #include <Graphic3d_AspectFillArea3d.hxx>
19 #include <Graphic3d_ArrayOfQuadrangles.hxx>
23 // =======================================================================
24 // function : V3d_Plane
26 // =======================================================================
27 V3d_Plane::V3d_Plane (const Standard_Real theA,
28 const Standard_Real theB,
29 const Standard_Real theC,
30 const Standard_Real theD)
31 : myGraphicStructure(),
32 myPlane (new Graphic3d_ClipPlane (gp_Pln (theA, theB, theC, theD)))
36 // =======================================================================
37 // function : V3d_Plane
39 // =======================================================================
40 void V3d_Plane::SetPlane (const Standard_Real theA,
41 const Standard_Real theB,
42 const Standard_Real theC,
43 const Standard_Real theD)
45 myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
52 // =======================================================================
55 // =======================================================================
56 void V3d_Plane::Display (const Handle(V3d_View)& theView,
57 const Quantity_Color& theColor)
59 Handle(V3d_Viewer) aViewer = theView->Viewer();
60 if (!myGraphicStructure.IsNull())
62 myGraphicStructure->Clear();
65 myGraphicStructure = new Graphic3d_Structure (aViewer->Viewer());
66 Handle(Graphic3d_Group) aGroup = myGraphicStructure->NewGroup();
67 Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d();
68 Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC);
69 aPlastic.SetColor (theColor);
70 aPlastic.SetTransparency (0.5);
71 anAsp->SetFrontMaterial (aPlastic);
72 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
73 anAsp->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE);
74 myGraphicStructure->SetPrimitivesAspect (anAsp);
76 const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize());
77 const Standard_ShortReal anOffset = aSize/5000.0f;
79 Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
80 aPrims->AddVertex (-aSize,-aSize, anOffset);
81 aPrims->AddVertex (-aSize, aSize, anOffset);
82 aPrims->AddVertex ( aSize, aSize, anOffset);
83 aPrims->AddVertex ( aSize,-aSize, anOffset);
84 aGroup->AddPrimitiveArray(aPrims);
86 myGraphicStructure->SetDisplayPriority (0);
87 myGraphicStructure->Display();
91 // =======================================================================
94 // =======================================================================
95 void V3d_Plane::Erase()
97 if (!myGraphicStructure.IsNull())
99 myGraphicStructure->Erase();
103 // =======================================================================
106 // =======================================================================
107 void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
109 const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
110 theA = anEquation[0];
111 theB = anEquation[1];
112 theC = anEquation[2];
113 theD = anEquation[3];
116 // =======================================================================
117 // function : IsDisplayed
119 // =======================================================================
120 Standard_Boolean V3d_Plane::IsDisplayed() const
122 if (myGraphicStructure.IsNull())
124 return Standard_False;
127 return myGraphicStructure->IsDisplayed();
130 // =======================================================================
133 // =======================================================================
134 void V3d_Plane::Update()
136 if(!myGraphicStructure.IsNull())
138 TColStd_Array2OfReal aMatrix (1, 4, 1, 4);
139 Standard_Real theA, theB, theC, theD;
140 this->Plane(theA, theB, theC, theD);
141 gp_Pln aGeomPln (theA, theB, theC, theD);
143 aTransform.SetTransformation (aGeomPln.Position());
145 for (Standard_Integer i = 1; i <= 3; i++)
147 for (Standard_Integer j = 1; j <= 4; j++)
149 aMatrix.SetValue (i, j, aTransform.Value (i,j));
153 aMatrix.SetValue (4,1,0.);
154 aMatrix.SetValue (4,2,0.);
155 aMatrix.SetValue (4,3,0.);
156 aMatrix.SetValue (4,4,1.);
157 myGraphicStructure->SetTransform (aMatrix, Graphic3d_TOC_REPLACE);