b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | // Modified: 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets |
16 | |
42cf5bc1 |
17 | #include <Aspect_InteriorStyle.hxx> |
18 | #include <Aspect_PolygonOffsetMode.hxx> |
7fd59977 |
19 | #include <Aspect_TypeOfHighlightMethod.hxx> |
42cf5bc1 |
20 | #include <Aspect_TypeOfLine.hxx> |
21 | #include <Geom_Transformation.hxx> |
7fd59977 |
22 | #include <gp_Ax1.hxx> |
42cf5bc1 |
23 | #include <gp_Dir.hxx> |
24 | #include <gp_Pnt.hxx> |
7fd59977 |
25 | #include <gp_Trsf.hxx> |
26 | #include <gp_Vec.hxx> |
42cf5bc1 |
27 | #include <Graphic3d_AspectFillArea3d.hxx> |
28 | #include <Graphic3d_DataStructureManager.hxx> |
29 | #include <Graphic3d_Group.hxx> |
30 | #include <Graphic3d_NameOfMaterial.hxx> |
31 | #include <Graphic3d_Structure.hxx> |
32 | #include <Graphic3d_StructureManager.hxx> |
33 | #include <Prs3d_Presentation.hxx> |
34 | #include <Prs3d_Root.hxx> |
35 | #include <Prs3d_ShadingAspect.hxx> |
7fd59977 |
36 | #include <Standard_Real.hxx> |
42cf5bc1 |
37 | #include <Standard_Type.hxx> |
38 | #include <TColStd_Array2OfReal.hxx> |
39 | |
92efcf78 |
40 | IMPLEMENT_STANDARD_RTTIEXT(Prs3d_Presentation,Graphic3d_Structure) |
41 | |
7fd59977 |
42 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 |
43 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 |
44 | static void MakeGraphicTrsf (const Handle(Geom_Transformation)& aGeomTrsf, |
45 | TColStd_Array2OfReal& Array){ |
46 | for (Standard_Integer i=1; i<=3; i++){ |
47 | for (Standard_Integer j=1; j<=4; j++){ |
48 | Array.SetValue(i,j,aGeomTrsf->Value(i,j)); |
49 | } |
50 | } |
51 | Array.SetValue(4,1,0.); |
52 | Array.SetValue(4,2,0.); |
53 | Array.SetValue(4,3,0.); |
54 | Array.SetValue(4,4,1.); |
55 | } |
56 | |
57 | //======================================================================= |
58 | //function : Prs3d_Presentation |
679ecdee |
59 | //purpose : |
7fd59977 |
60 | //======================================================================= |
679ecdee |
61 | Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager)& theViewer, |
62 | const Standard_Boolean theToInit) |
63 | : Graphic3d_Structure (theViewer) |
7fd59977 |
64 | { |
679ecdee |
65 | if (!theToInit) |
66 | { |
67 | return; |
7fd59977 |
68 | } |
69 | |
679ecdee |
70 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS); |
71 | Quantity_Color aColor = aMat.AmbientColor(); |
72 | // It is necessary to set default polygon offsets for a new presentation |
73 | Handle(Graphic3d_AspectFillArea3d) aDefAspect = |
74 | new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, |
75 | aColor, |
76 | aColor, |
77 | Aspect_TOL_SOLID, |
78 | 1.0, |
79 | Graphic3d_NOM_BRASS, |
80 | Graphic3d_NOM_BRASS); |
81 | aDefAspect->SetPolygonOffsets (Aspect_POM_Fill, 1.0f, 0.0f); |
82 | SetPrimitivesAspect (aDefAspect); |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : Prs3d_Presentation |
87 | //purpose : |
88 | //======================================================================= |
89 | Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager)& theViewer, |
90 | const Handle(Prs3d_Presentation)& thePrs) |
91 | : Graphic3d_Structure (theViewer, thePrs) |
92 | { |
93 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS); |
94 | Quantity_Color aColor = aMat.AmbientColor(); |
95 | // It is necessary to set default polygon offsets for a new presentation |
96 | Handle(Graphic3d_AspectFillArea3d) aDefAspect = |
97 | new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, |
98 | aColor, |
99 | aColor, |
100 | Aspect_TOL_SOLID, |
101 | 1.0, |
102 | Graphic3d_NOM_BRASS, |
103 | Graphic3d_NOM_BRASS); |
104 | aDefAspect->SetPolygonOffsets (Aspect_POM_Fill, 1.0f, 0.0f); |
105 | SetPrimitivesAspect (aDefAspect); |
7fd59977 |
106 | } |
107 | |
7fd59977 |
108 | //======================================================================= |
109 | //function : SetShadingAspect |
110 | //purpose : |
111 | //======================================================================= |
112 | void Prs3d_Presentation::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) |
113 | { |
114 | SetPrimitivesAspect(aShadingAspect->Aspect()); |
115 | } |
116 | |
7fd59977 |
117 | //======================================================================= |
118 | //function : Transform |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | void Prs3d_Presentation::Transform(const Handle(Geom_Transformation)& aTransformation) |
123 | { |
124 | TColStd_Array2OfReal Array (1,4,1,4); |
125 | MakeGraphicTrsf(aTransformation, Array); |
126 | SetTransform(Array, Graphic3d_TOC_REPLACE); |
127 | } |
128 | |
7fd59977 |
129 | //======================================================================= |
130 | //function : Transformation |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | Handle(Geom_Transformation) Prs3d_Presentation::Transformation() const { |
135 | TColStd_Array2OfReal matrix(1,4,1,4); |
136 | |
137 | Graphic3d_Structure::Transform(matrix); |
138 | |
139 | gp_Trsf trsf; |
140 | trsf.SetValues( |
141 | matrix.Value(1,1),matrix.Value(1,2),matrix.Value(1,3),matrix.Value(1,4), |
142 | matrix.Value(2,1),matrix.Value(2,2),matrix.Value(2,3),matrix.Value(2,4), |
7a8c6a36 |
143 | matrix.Value(3,1),matrix.Value(3,2),matrix.Value(3,3),matrix.Value(3,4)); |
7fd59977 |
144 | Handle(Geom_Transformation) gtrsf = new Geom_Transformation(trsf); |
145 | |
146 | return gtrsf; |
147 | } |
7fd59977 |
148 | |
149 | //======================================================================= |
150 | //function : Place |
151 | //purpose : |
152 | //======================================================================= |
153 | void Prs3d_Presentation::Place (const Quantity_Length X, |
154 | const Quantity_Length Y, |
155 | const Quantity_Length Z) |
156 | { |
157 | Handle(Geom_Transformation) aTransformation = new Geom_Transformation; |
158 | aTransformation->SetTranslation(gp_Vec(X,Y,Z)); |
159 | TColStd_Array2OfReal Array (1,4,1,4); |
160 | MakeGraphicTrsf(aTransformation, Array); |
161 | SetTransform(Array, Graphic3d_TOC_REPLACE); |
162 | } |
163 | |
164 | //======================================================================= |
165 | //function : Multiply |
166 | //purpose : |
167 | //======================================================================= |
168 | void Prs3d_Presentation::Multiply(const Handle(Geom_Transformation)& aTransformation) |
169 | { |
170 | TColStd_Array2OfReal Array (1,4,1,4); |
171 | MakeGraphicTrsf(aTransformation, Array); |
172 | SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE); |
173 | } |
174 | |
175 | //======================================================================= |
176 | //function : Move |
177 | //purpose : |
178 | //======================================================================= |
179 | void Prs3d_Presentation::Move (const Quantity_Length X, |
180 | const Quantity_Length Y, |
181 | const Quantity_Length Z) |
182 | { |
183 | Handle(Geom_Transformation) aTransformation = new Geom_Transformation; |
184 | aTransformation->SetTranslation(gp_Vec(X,Y,Z)); |
185 | TColStd_Array2OfReal Array (1,4,1,4); |
186 | MakeGraphicTrsf(aTransformation, Array); |
187 | SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE); |
188 | } |
189 | |
7fd59977 |
190 | //======================================================================= |
191 | //function : Connect |
192 | //purpose : |
193 | //======================================================================= |
194 | void Prs3d_Presentation::Connect |
195 | ( const Handle(Prs3d_Presentation)& aPresentation) |
196 | { |
197 | Graphic3d_Structure::Connect(aPresentation, Graphic3d_TOC_DESCENDANT); |
198 | } |
199 | |
200 | |
201 | //======================================================================= |
202 | //function : Remove |
203 | //purpose : |
204 | //======================================================================= |
205 | void Prs3d_Presentation::Remove (const Handle(Prs3d_Presentation)& aPresentation) |
206 | { |
207 | Disconnect(aPresentation); |
208 | } |
209 | |
210 | //======================================================================= |
211 | //function : RemoveAll |
212 | //purpose : |
213 | //======================================================================= |
214 | void Prs3d_Presentation::RemoveAll () |
215 | { |
216 | DisconnectAll(Graphic3d_TOC_DESCENDANT); |
217 | } |
218 | |
219 | |
220 | //======================================================================= |
221 | //function : CurrentGroup |
222 | //purpose : |
223 | //======================================================================= |
224 | Handle(Graphic3d_Group) Prs3d_Presentation::CurrentGroup () const |
225 | { |
b64d84be |
226 | if (Groups().IsEmpty()) |
227 | { |
228 | return const_cast<Prs3d_Presentation* >(this)->NewGroup(); |
7fd59977 |
229 | } |
b64d84be |
230 | return Groups().Last(); |
7fd59977 |
231 | } |
232 | |
7fd59977 |
233 | //======================================================================= |
234 | //function : Compute |
235 | //purpose : |
236 | //======================================================================= |
237 | |
238 | Handle(Graphic3d_Structure) Prs3d_Presentation:: |
239 | Compute(const Handle(Graphic3d_DataStructureManager)& /*aProjector*/) |
240 | { |
241 | return this; |
242 | } |
243 | |
244 | //======================================================================= |
245 | //function : Compute |
246 | //purpose : |
247 | //======================================================================= |
248 | |
857ffd5e |
249 | void Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruct, |
250 | Handle(Graphic3d_Structure)& aStruct) |
7fd59977 |
251 | { |
252 | Graphic3d_Structure::Compute(aDataStruct,aStruct ); |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : Compute |
257 | //purpose : |
258 | //======================================================================= |
259 | |
857ffd5e |
260 | Handle(Graphic3d_Structure) Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruc, |
7fd59977 |
261 | const TColStd_Array2OfReal& anArray) |
262 | { |
263 | return Graphic3d_Structure::Compute(aDataStruc,anArray); |
264 | } |
265 | |
266 | //======================================================================= |
267 | //function : Compute |
268 | //purpose : |
269 | //======================================================================= |
270 | |
857ffd5e |
271 | void Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruc, |
7fd59977 |
272 | const TColStd_Array2OfReal& anArray, |
857ffd5e |
273 | Handle(Graphic3d_Structure)& aStruc) |
7fd59977 |
274 | { |
275 | Graphic3d_Structure::Compute(aDataStruc,anArray,aStruc); |
276 | } |