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>
22 IMPLEMENT_STANDARD_RTTIEXT(V3d_Plane,Standard_Transient)
24 // =======================================================================
25 // function : V3d_Plane
27 // =======================================================================
28 V3d_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)))
37 // =======================================================================
38 // function : V3d_Plane
40 // =======================================================================
41 void V3d_Plane::SetPlane (const Standard_Real theA,
42 const Standard_Real theB,
43 const Standard_Real theC,
44 const Standard_Real theD)
46 myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
53 // =======================================================================
56 // =======================================================================
57 void V3d_Plane::Display (const Handle(V3d_View)& theView,
58 const Quantity_Color& theColor)
60 Handle(V3d_Viewer) aViewer = theView->Viewer();
61 if (!myGraphicStructure.IsNull())
63 myGraphicStructure->Clear();
66 myGraphicStructure = new Graphic3d_Structure (aViewer->StructureManager());
67 Handle(Graphic3d_Group) aGroup = myGraphicStructure->NewGroup();
68 Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d();
69 Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC);
70 aPlastic.SetColor (theColor);
71 aPlastic.SetTransparency (0.5);
72 anAsp->SetFrontMaterial (aPlastic);
73 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
74 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE));
75 aGroup->SetGroupPrimitivesAspect (anAsp);
77 const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize());
78 const Standard_ShortReal anOffset = aSize/5000.0f;
80 Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
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);
87 myGraphicStructure->SetDisplayPriority (0);
88 myGraphicStructure->Display();
92 // =======================================================================
95 // =======================================================================
96 void V3d_Plane::Erase()
98 if (!myGraphicStructure.IsNull())
100 myGraphicStructure->Erase();
104 // =======================================================================
107 // =======================================================================
108 void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
110 const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
111 theA = anEquation[0];
112 theB = anEquation[1];
113 theC = anEquation[2];
114 theD = anEquation[3];
117 // =======================================================================
118 // function : IsDisplayed
120 // =======================================================================
121 Standard_Boolean V3d_Plane::IsDisplayed() const
123 if (myGraphicStructure.IsNull())
125 return Standard_False;
128 return myGraphicStructure->IsDisplayed();
131 // =======================================================================
134 // =======================================================================
135 void V3d_Plane::Update()
137 if (myGraphicStructure.IsNull())
142 const gp_Pln aGeomPln = myPlane->ToPlane();
144 aTransform.SetTransformation (aGeomPln.Position());
146 myGraphicStructure->SetTransformation (new Geom_Transformation (aTransform));