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>
18 #include <Graphic3d_Group.hxx>
19 #include <Graphic3d_AspectFillArea3d.hxx>
20 #include <Graphic3d_ArrayOfQuadrangles.hxx>
22 #include <V3d_Viewer.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(V3d_Plane,Standard_Transient)
26 // =======================================================================
27 // function : V3d_Plane
29 // =======================================================================
30 V3d_Plane::V3d_Plane (const Standard_Real theA,
31 const Standard_Real theB,
32 const Standard_Real theC,
33 const Standard_Real theD)
34 : myGraphicStructure(),
35 myPlane (new Graphic3d_ClipPlane (gp_Pln (theA, theB, theC, theD)))
39 // =======================================================================
40 // function : V3d_Plane
42 // =======================================================================
43 void V3d_Plane::SetPlane (const Standard_Real theA,
44 const Standard_Real theB,
45 const Standard_Real theC,
46 const Standard_Real theD)
48 myPlane->SetEquation (gp_Pln (theA, theB, theC, theD));
55 // =======================================================================
58 // =======================================================================
59 void V3d_Plane::Display (const Handle(V3d_View)& theView,
60 const Quantity_Color& theColor)
62 Handle(V3d_Viewer) aViewer = theView->Viewer();
63 if (!myGraphicStructure.IsNull())
65 myGraphicStructure->Clear();
68 myGraphicStructure = new Graphic3d_Structure (aViewer->StructureManager());
69 Handle(Graphic3d_Group) aGroup = myGraphicStructure->NewGroup();
70 Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d();
71 Graphic3d_MaterialAspect aPlastic (Graphic3d_NameOfMaterial_Plastified);
72 aPlastic.SetColor (theColor);
73 aPlastic.SetTransparency (0.5);
74 anAsp->SetFrontMaterial (aPlastic);
75 anAsp->SetInteriorStyle (Aspect_IS_HATCH);
76 anAsp->SetHatchStyle (new Graphic3d_HatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE));
77 aGroup->SetGroupPrimitivesAspect (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->SetDisplayPriority (Graphic3d_DisplayPriority_Bottom);
90 myGraphicStructure->Display();
94 // =======================================================================
97 // =======================================================================
98 void V3d_Plane::Erase()
100 if (!myGraphicStructure.IsNull())
102 myGraphicStructure->Erase();
106 // =======================================================================
109 // =======================================================================
110 void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const
112 const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation();
113 theA = anEquation[0];
114 theB = anEquation[1];
115 theC = anEquation[2];
116 theD = anEquation[3];
119 // =======================================================================
120 // function : IsDisplayed
122 // =======================================================================
123 Standard_Boolean V3d_Plane::IsDisplayed() const
125 if (myGraphicStructure.IsNull())
127 return Standard_False;
130 return myGraphicStructure->IsDisplayed();
133 // =======================================================================
136 // =======================================================================
137 void V3d_Plane::Update()
139 if (myGraphicStructure.IsNull())
144 const gp_Pln aGeomPln = myPlane->ToPlane();
146 aTransform.SetTransformation (aGeomPln.Position());
148 myGraphicStructure->SetTransformation (new TopLoc_Datum3D (aTransform));