2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
33 #include <V3d_Plane.ixx>
34 #include <Viewer_BadValue.hxx>
36 #include <Graphic3d_Group.hxx>
37 #include <Graphic3d_ArrayOfQuadrangles.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
43 V3d_Plane::V3d_Plane(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D)
45 Viewer_BadValue_Raise_if( sqrt(A*A + B*B + C*C) <= 0., "V3d_Plane::V3d_Plane, bad plane coefficients");
47 MyPlane = new Visual3d_ClipPlane(A,B,C,D) ;
52 void V3d_Plane::SetPlane(const Standard_Real A, const Standard_Real B, const Standard_Real C, const Standard_Real D)
54 Viewer_BadValue_Raise_if( sqrt(A*A + B*B + C*C) <= 0., "V3d_Plane::SetPlane, bad plane coefficients");
56 MyPlane->SetPlane(A,B,C,D) ;
61 void V3d_Plane::Display(const Handle(V3d_View)& aView,
62 const Quantity_Color& aColor)
64 Handle(V3d_Viewer) theViewer = aView->Viewer();
65 if (!MyGraphicStructure.IsNull())
66 MyGraphicStructure->Clear();
68 MyGraphicStructure = new Graphic3d_Structure(theViewer->Viewer());
69 Handle(Graphic3d_Group) group = new Graphic3d_Group(MyGraphicStructure);
70 Handle(Graphic3d_AspectFillArea3d) aspect = new Graphic3d_AspectFillArea3d();
71 Graphic3d_MaterialAspect plastic(Graphic3d_NOM_PLASTIC);
72 plastic.SetColor(aColor);
73 plastic.SetTransparency(0.5);
74 aView->SetTransparency(Standard_True);
75 aspect->SetFrontMaterial(plastic);
76 aspect->SetInteriorStyle (Aspect_IS_HATCH);
77 aspect->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE);
78 MyGraphicStructure->SetPrimitivesAspect(aspect);
80 const Standard_ShortReal size = (Standard_ShortReal)(0.5*theViewer->DefaultViewSize());
81 const Standard_ShortReal offset = size/5000.F;
83 Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4);
84 aPrims->AddVertex(-size,-size,offset);
85 aPrims->AddVertex(-size, size,offset);
86 aPrims->AddVertex( size, size,offset);
87 aPrims->AddVertex( size,-size,offset);
88 group->AddPrimitiveArray(aPrims);
90 MyGraphicStructure->Display(0);
94 void V3d_Plane::Erase()
96 if (!MyGraphicStructure.IsNull()) MyGraphicStructure->Erase();
99 void V3d_Plane::Plane(Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D) const
101 MyPlane->Plane(A,B,C,D) ;
104 Handle(Visual3d_ClipPlane) V3d_Plane::Plane()const
109 Standard_Boolean V3d_Plane::IsDisplayed() const
111 if( MyGraphicStructure.IsNull() ) return Standard_False;
112 return MyGraphicStructure->IsDisplayed();
115 void V3d_Plane::Update()
117 if( !MyGraphicStructure.IsNull() ) {
118 TColStd_Array2OfReal matrix(1,4,1,4);
119 Standard_Real A,B,C,D;
120 MyPlane->Plane(A,B,C,D) ;
121 gp_Pln plan(A,B,C,D);
123 trsf.SetTransformation(plan.Position());
125 for (Standard_Integer i=1; i<=3; i++){
126 for (Standard_Integer j=1; j<=4; j++){
127 matrix.SetValue(i,j,trsf.Value(i,j));
130 matrix.SetValue(4,1,0.);
131 matrix.SetValue(4,2,0.);
132 matrix.SetValue(4,3,0.);
133 matrix.SetValue(4,4,1.);
134 MyGraphicStructure->SetTransform(matrix,Graphic3d_TOC_REPLACE);