b311480e |
1 | // Created by: GG |
2 | // Copyright (c) 1991-1999 Matra Datavision |
4269bd1b |
3 | // Copyright (c) 1999-2013 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
4269bd1b |
16 | #include <V3d_Plane.hxx> |
4952a30a |
17 | #include <Graphic3d_Group.hxx> |
4952a30a |
18 | #include <Graphic3d_AspectFillArea3d.hxx> |
4269bd1b |
19 | #include <Graphic3d_ArrayOfQuadrangles.hxx> |
4952a30a |
20 | #include <gp_Pln.hxx> |
21 | |
4269bd1b |
22 | // ======================================================================= |
23 | // function : V3d_Plane |
24 | // purpose : |
25 | // ======================================================================= |
26 | V3d_Plane::V3d_Plane (const Standard_Real theA, |
27 | const Standard_Real theB, |
28 | const Standard_Real theC, |
29 | const Standard_Real theD) |
30 | : myGraphicStructure(), |
31 | myPlane (new Graphic3d_ClipPlane (gp_Pln (theA, theB, theC, theD))) |
b8ddfc2f |
32 | { |
7fd59977 |
33 | } |
34 | |
4269bd1b |
35 | // ======================================================================= |
36 | // function : V3d_Plane |
37 | // purpose : |
38 | // ======================================================================= |
39 | void V3d_Plane::SetPlane (const Standard_Real theA, |
40 | const Standard_Real theB, |
41 | const Standard_Real theC, |
42 | const Standard_Real theD) |
b8ddfc2f |
43 | { |
4269bd1b |
44 | myPlane->SetEquation (gp_Pln (theA, theB, theC, theD)); |
45 | if (IsDisplayed()) |
46 | { |
7fd59977 |
47 | Update(); |
4269bd1b |
48 | } |
7fd59977 |
49 | } |
50 | |
4269bd1b |
51 | // ======================================================================= |
52 | // function : Display |
53 | // purpose : |
54 | // ======================================================================= |
55 | void V3d_Plane::Display (const Handle(V3d_View)& theView, |
56 | const Quantity_Color& theColor) |
b8ddfc2f |
57 | { |
4269bd1b |
58 | Handle(V3d_Viewer) aViewer = theView->Viewer(); |
59 | if (!myGraphicStructure.IsNull()) |
60 | { |
61 | myGraphicStructure->Clear(); |
62 | } |
b8ddfc2f |
63 | |
c357e426 |
64 | myGraphicStructure = new Graphic3d_Structure (aViewer->StructureManager()); |
b64d84be |
65 | Handle(Graphic3d_Group) aGroup = myGraphicStructure->NewGroup(); |
66 | Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d(); |
4269bd1b |
67 | Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC); |
68 | aPlastic.SetColor (theColor); |
69 | aPlastic.SetTransparency (0.5); |
4269bd1b |
70 | anAsp->SetFrontMaterial (aPlastic); |
71 | anAsp->SetInteriorStyle (Aspect_IS_HATCH); |
72 | anAsp->SetHatchStyle (Aspect_HS_GRID_DIAGONAL_WIDE); |
73 | myGraphicStructure->SetPrimitivesAspect (anAsp); |
74 | |
75 | const Standard_ShortReal aSize = (Standard_ShortReal)(0.5*aViewer->DefaultViewSize()); |
76 | const Standard_ShortReal anOffset = aSize/5000.0f; |
b8ddfc2f |
77 | |
78 | Handle(Graphic3d_ArrayOfQuadrangles) aPrims = new Graphic3d_ArrayOfQuadrangles(4); |
4269bd1b |
79 | aPrims->AddVertex (-aSize,-aSize, anOffset); |
80 | aPrims->AddVertex (-aSize, aSize, anOffset); |
81 | aPrims->AddVertex ( aSize, aSize, anOffset); |
82 | aPrims->AddVertex ( aSize,-aSize, anOffset); |
83 | aGroup->AddPrimitiveArray(aPrims); |
b8ddfc2f |
84 | |
a1954302 |
85 | myGraphicStructure->SetDisplayPriority (0); |
86 | myGraphicStructure->Display(); |
b8ddfc2f |
87 | Update(); |
7fd59977 |
88 | } |
89 | |
4269bd1b |
90 | // ======================================================================= |
91 | // function : Erase |
92 | // purpose : |
93 | // ======================================================================= |
b8ddfc2f |
94 | void V3d_Plane::Erase() |
95 | { |
4269bd1b |
96 | if (!myGraphicStructure.IsNull()) |
97 | { |
98 | myGraphicStructure->Erase(); |
99 | } |
7fd59977 |
100 | } |
101 | |
4269bd1b |
102 | // ======================================================================= |
103 | // function : Plane |
104 | // purpose : |
105 | // ======================================================================= |
106 | void V3d_Plane::Plane (Standard_Real& theA, Standard_Real& theB, Standard_Real& theC, Standard_Real& theD) const |
b8ddfc2f |
107 | { |
4269bd1b |
108 | const Graphic3d_ClipPlane::Equation& anEquation = myPlane->GetEquation(); |
109 | theA = anEquation[0]; |
110 | theB = anEquation[1]; |
111 | theC = anEquation[2]; |
112 | theD = anEquation[3]; |
7fd59977 |
113 | } |
114 | |
4269bd1b |
115 | // ======================================================================= |
116 | // function : IsDisplayed |
117 | // purpose : |
118 | // ======================================================================= |
b8ddfc2f |
119 | Standard_Boolean V3d_Plane::IsDisplayed() const |
120 | { |
4269bd1b |
121 | if (myGraphicStructure.IsNull()) |
122 | { |
123 | return Standard_False; |
124 | } |
125 | |
126 | return myGraphicStructure->IsDisplayed(); |
7fd59977 |
127 | } |
128 | |
4269bd1b |
129 | // ======================================================================= |
130 | // function : Update |
131 | // purpose : |
132 | // ======================================================================= |
b8ddfc2f |
133 | void V3d_Plane::Update() |
134 | { |
4269bd1b |
135 | if(!myGraphicStructure.IsNull()) |
136 | { |
137 | TColStd_Array2OfReal aMatrix (1, 4, 1, 4); |
138 | Standard_Real theA, theB, theC, theD; |
139 | this->Plane(theA, theB, theC, theD); |
140 | gp_Pln aGeomPln (theA, theB, theC, theD); |
141 | gp_Trsf aTransform; |
142 | aTransform.SetTransformation (aGeomPln.Position()); |
143 | aTransform.Invert(); |
144 | for (Standard_Integer i = 1; i <= 3; i++) |
145 | { |
146 | for (Standard_Integer j = 1; j <= 4; j++) |
147 | { |
148 | aMatrix.SetValue (i, j, aTransform.Value (i,j)); |
7fd59977 |
149 | } |
150 | } |
4269bd1b |
151 | |
152 | aMatrix.SetValue (4,1,0.); |
153 | aMatrix.SetValue (4,2,0.); |
154 | aMatrix.SetValue (4,3,0.); |
155 | aMatrix.SetValue (4,4,1.); |
156 | myGraphicStructure->SetTransform (aMatrix, Graphic3d_TOC_REPLACE); |
7fd59977 |
157 | } |
158 | } |