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
8 // under the terms of the GNU Lesser General Public 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>
22 IMPLEMENT_STANDARD_HANDLE(V3d_Plane, MMgt_TShared)
23 IMPLEMENT_STANDARD_RTTIEXT(V3d_Plane, MMgt_TShared)
25 // =======================================================================
26 // function : V3d_Plane
28 // =======================================================================
29 V3d_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)))
38 // =======================================================================
39 // function : V3d_Plane
41 // =======================================================================
42 void V3d_Plane::SetPlane (const Standard_Real theA,
43 const Standard_Real theB,
44 const Standard_Real theC,
45 const Standard_Real theD)
47 myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
54 // =======================================================================
57 // =======================================================================
58 void V3d_Plane::Display (const Handle(V3d_View)& theView,
59 const Quantity_Color& theColor)
61 Handle(V3d_Viewer) aViewer = theView->Viewer();
62 if (!myGraphicStructure.IsNull())
64 myGraphicStructure->Clear();
67 myGraphicStructure = new Graphic3d_Structure (aViewer->Viewer());
68 Handle(Graphic3d_Group) aGroup = new Graphic3d_Group (myGraphicStructure);
69 Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d();
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);
79 const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize());
80 const Standard_ShortReal anOffset = aSize/5000.0f;
82 Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
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);
89 myGraphicStructure->Display(0);
93 // =======================================================================
96 // =======================================================================
97 void V3d_Plane::Erase()
99 if (!myGraphicStructure.IsNull())
101 myGraphicStructure->Erase();
105 // =======================================================================
108 // =======================================================================
109 void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
111 const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
112 theA = anEquation[0];
113 theB = anEquation[1];
114 theC = anEquation[2];
115 theD = anEquation[3];
118 // =======================================================================
119 // function : IsDisplayed
121 // =======================================================================
122 Standard_Boolean V3d_Plane::IsDisplayed() const
124 if (myGraphicStructure.IsNull())
126 return Standard_False;
129 return myGraphicStructure->IsDisplayed();
132 // =======================================================================
135 // =======================================================================
136 void V3d_Plane::Update()
138 if(!myGraphicStructure.IsNull())
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);
145 aTransform.SetTransformation (aGeomPln.Position());
147 for (Standard_Integer i = 1; i <= 3; i++)
149 for (Standard_Integer j = 1; j <= 4; j++)
151 aMatrix.SetValue (i, j, aTransform.Value (i,j));
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);