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 | |
17 | #define IMP020200 //GG Add Transformation() method |
18 | |
19 | #include <Prs3d_Presentation.ixx> |
20 | #include <TColStd_Array2OfReal.hxx> |
21 | #include <Graphic3d_Structure.hxx> |
22 | #include <Aspect_TypeOfHighlightMethod.hxx> |
23 | #include <gp_Pnt.hxx> |
24 | #include <gp_Dir.hxx> |
25 | #include <gp_Ax1.hxx> |
26 | #include <gp_Trsf.hxx> |
27 | #include <gp_Vec.hxx> |
28 | #include <Standard_Real.hxx> |
29 | #include <Aspect_InteriorStyle.hxx> |
30 | #include <Aspect_TypeOfLine.hxx> |
31 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
32 | #include <Aspect_PolygonOffsetMode.hxx> |
33 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
34 | #include <Graphic3d_NameOfMaterial.hxx> |
35 | #include <Graphic3d_AspectFillArea3d.hxx> |
36 | |
37 | |
38 | static void MakeGraphicTrsf (const Handle(Geom_Transformation)& aGeomTrsf, |
39 | TColStd_Array2OfReal& Array){ |
40 | for (Standard_Integer i=1; i<=3; i++){ |
41 | for (Standard_Integer j=1; j<=4; j++){ |
42 | Array.SetValue(i,j,aGeomTrsf->Value(i,j)); |
43 | } |
44 | } |
45 | Array.SetValue(4,1,0.); |
46 | Array.SetValue(4,2,0.); |
47 | Array.SetValue(4,3,0.); |
48 | Array.SetValue(4,4,1.); |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : Prs3d_Presentation |
53 | //purpose : |
54 | //======================================================================= |
55 | Prs3d_Presentation::Prs3d_Presentation |
56 | (const Handle(Graphic3d_StructureManager)& aViewer, |
57 | const Standard_Boolean Init): |
58 | Graphic3d_Structure(aViewer) |
59 | { |
60 | if (Init) { |
61 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS); |
62 | Quantity_Color Col; |
63 | // Ceci permet de recuperer la couleur associee |
64 | // au materiau defini par defaut. |
65 | //POP pour K4L |
66 | Col = aMat.AmbientColor (); |
67 | // Col = aMat.Color (); |
68 | |
69 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
70 | // It is necessary to set default polygon offsets for a new presentation |
71 | Handle(Graphic3d_AspectFillArea3d) aDefAspect = |
72 | new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, |
73 | Col, |
74 | Col, |
75 | Aspect_TOL_SOLID, |
76 | 1.0, |
77 | Graphic3d_NOM_BRASS, |
78 | Graphic3d_NOM_BRASS); |
79 | aDefAspect->SetPolygonOffsets( Aspect_POM_Fill, 1., 0. ); |
80 | SetPrimitivesAspect( aDefAspect ); |
81 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
82 | } |
83 | |
84 | // myStruct = Handle(Graphic3d_Structure)::DownCast(This ()); |
85 | // myCurrentGroup = new Graphic3d_Group(myStruct); |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : Highlight |
90 | //purpose : |
91 | //======================================================================= |
92 | void Prs3d_Presentation::Highlight() |
93 | { |
94 | SetHighlightColor(Quantity_Color(Quantity_NOC_GRAY99)); |
95 | Aspect_TypeOfHighlightMethod Method = Aspect_TOHM_COLOR; |
96 | Graphic3d_Structure::Highlight(Method); |
97 | } |
98 | |
99 | //======================================================================= |
100 | //function : Color |
101 | //purpose : |
102 | //======================================================================= |
103 | void Prs3d_Presentation::Color(const Quantity_NameOfColor aColor) |
104 | { |
105 | SetHighlightColor(Quantity_Color(aColor)); |
106 | Graphic3d_Structure::Highlight(Aspect_TOHM_COLOR); |
107 | } |
108 | |
109 | //======================================================================= |
110 | //function : BoundBox |
111 | //purpose : |
112 | //======================================================================= |
113 | void Prs3d_Presentation::BoundBox() |
114 | { |
115 | SetHighlightColor(Quantity_Color(Quantity_NOC_GRAY99)); |
116 | Graphic3d_Structure::Highlight(Aspect_TOHM_BOUNDBOX); |
117 | } |
118 | |
119 | |
120 | //======================================================================= |
121 | //function : SetShadingAspect |
122 | //purpose : |
123 | //======================================================================= |
124 | void Prs3d_Presentation::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) |
125 | { |
126 | SetPrimitivesAspect(aShadingAspect->Aspect()); |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : IsPickable |
131 | //purpose : |
132 | //======================================================================= |
133 | Standard_Boolean Prs3d_Presentation::IsPickable () const |
134 | { |
135 | return Graphic3d_Structure::IsSelectable(); |
136 | } |
137 | |
138 | //======================================================================= |
139 | //function : SetPickable |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | void Prs3d_Presentation::SetPickable() |
144 | { |
145 | SetPick(Standard_True); |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : SetUnPickable |
150 | //purpose : |
151 | //======================================================================= |
152 | void Prs3d_Presentation::SetUnPickable() |
153 | { |
154 | SetPick(Standard_False); |
155 | } |
156 | |
157 | //======================================================================= |
158 | //function : Transform |
159 | //purpose : |
160 | //======================================================================= |
161 | |
162 | void Prs3d_Presentation::Transform(const Handle(Geom_Transformation)& aTransformation) |
163 | { |
164 | TColStd_Array2OfReal Array (1,4,1,4); |
165 | MakeGraphicTrsf(aTransformation, Array); |
166 | SetTransform(Array, Graphic3d_TOC_REPLACE); |
167 | } |
168 | |
169 | #ifdef IMP020200 |
170 | //======================================================================= |
171 | //function : Transformation |
172 | //purpose : |
173 | //======================================================================= |
174 | |
175 | Handle(Geom_Transformation) Prs3d_Presentation::Transformation() const { |
176 | TColStd_Array2OfReal matrix(1,4,1,4); |
177 | |
178 | Graphic3d_Structure::Transform(matrix); |
179 | |
180 | gp_Trsf trsf; |
181 | trsf.SetValues( |
182 | matrix.Value(1,1),matrix.Value(1,2),matrix.Value(1,3),matrix.Value(1,4), |
183 | matrix.Value(2,1),matrix.Value(2,2),matrix.Value(2,3),matrix.Value(2,4), |
184 | matrix.Value(3,1),matrix.Value(3,2),matrix.Value(3,3),matrix.Value(3,4), |
185 | 0.001,0.0001); |
186 | Handle(Geom_Transformation) gtrsf = new Geom_Transformation(trsf); |
187 | |
188 | return gtrsf; |
189 | } |
190 | #endif |
191 | |
192 | //======================================================================= |
193 | //function : Place |
194 | //purpose : |
195 | //======================================================================= |
196 | void Prs3d_Presentation::Place (const Quantity_Length X, |
197 | const Quantity_Length Y, |
198 | const Quantity_Length Z) |
199 | { |
200 | Handle(Geom_Transformation) aTransformation = new Geom_Transformation; |
201 | aTransformation->SetTranslation(gp_Vec(X,Y,Z)); |
202 | TColStd_Array2OfReal Array (1,4,1,4); |
203 | MakeGraphicTrsf(aTransformation, Array); |
204 | SetTransform(Array, Graphic3d_TOC_REPLACE); |
205 | } |
206 | |
207 | //======================================================================= |
208 | //function : Multiply |
209 | //purpose : |
210 | //======================================================================= |
211 | void Prs3d_Presentation::Multiply(const Handle(Geom_Transformation)& aTransformation) |
212 | { |
213 | TColStd_Array2OfReal Array (1,4,1,4); |
214 | MakeGraphicTrsf(aTransformation, Array); |
215 | SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE); |
216 | } |
217 | |
218 | //======================================================================= |
219 | //function : Move |
220 | //purpose : |
221 | //======================================================================= |
222 | void Prs3d_Presentation::Move (const Quantity_Length X, |
223 | const Quantity_Length Y, |
224 | const Quantity_Length Z) |
225 | { |
226 | Handle(Geom_Transformation) aTransformation = new Geom_Transformation; |
227 | aTransformation->SetTranslation(gp_Vec(X,Y,Z)); |
228 | TColStd_Array2OfReal Array (1,4,1,4); |
229 | MakeGraphicTrsf(aTransformation, Array); |
230 | SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE); |
231 | } |
232 | |
233 | |
234 | //======================================================================= |
235 | //function : Clear |
236 | //purpose : |
237 | //======================================================================= |
238 | void Prs3d_Presentation::Clear(const Standard_Boolean WithDestruction) |
239 | { |
240 | Graphic3d_Structure::Clear(WithDestruction); |
241 | // myCurrentGroup.Nullify(); |
242 | myCurrentGroup = NULL; |
243 | |
244 | } |
245 | |
246 | |
247 | //======================================================================= |
248 | //function : Connect |
249 | //purpose : |
250 | //======================================================================= |
251 | void Prs3d_Presentation::Connect |
252 | ( const Handle(Prs3d_Presentation)& aPresentation) |
253 | { |
254 | Graphic3d_Structure::Connect(aPresentation, Graphic3d_TOC_DESCENDANT); |
255 | } |
256 | |
257 | |
258 | //======================================================================= |
259 | //function : Remove |
260 | //purpose : |
261 | //======================================================================= |
262 | void Prs3d_Presentation::Remove (const Handle(Prs3d_Presentation)& aPresentation) |
263 | { |
264 | Disconnect(aPresentation); |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : RemoveAll |
269 | //purpose : |
270 | //======================================================================= |
271 | void Prs3d_Presentation::RemoveAll () |
272 | { |
273 | DisconnectAll(Graphic3d_TOC_DESCENDANT); |
274 | } |
275 | |
276 | |
277 | //======================================================================= |
278 | //function : CurrentGroup |
279 | //purpose : |
280 | //======================================================================= |
281 | Handle(Graphic3d_Group) Prs3d_Presentation::CurrentGroup () const |
282 | { |
283 | if(myCurrentGroup.IsNull()){ |
284 | void *ptr = (void*) this; |
285 | Prs3d_Presentation* p = (Prs3d_Presentation *)ptr; |
286 | p->NewGroup(); |
287 | } |
288 | return myCurrentGroup; |
289 | } |
290 | |
291 | |
292 | //======================================================================= |
293 | //function : NewGroup |
294 | //purpose : |
295 | //======================================================================= |
296 | Handle(Graphic3d_Group) Prs3d_Presentation::NewGroup () |
297 | { |
298 | myCurrentGroup = new Graphic3d_Group(this); |
299 | return myCurrentGroup; |
300 | } |
301 | |
302 | //======================================================================= |
303 | //function : Display |
304 | //purpose : |
305 | //======================================================================= |
306 | void Prs3d_Presentation::Display () |
307 | { |
308 | Graphic3d_Structure::Display(); |
309 | } |
310 | |
311 | |
312 | //======================================================================= |
313 | //function : Compute |
314 | //purpose : |
315 | //======================================================================= |
316 | |
317 | Handle(Graphic3d_Structure) Prs3d_Presentation:: |
318 | Compute(const Handle(Graphic3d_DataStructureManager)& /*aProjector*/) |
319 | { |
320 | return this; |
321 | } |
322 | |
323 | //======================================================================= |
324 | //function : Compute |
325 | //purpose : |
326 | //======================================================================= |
327 | |
328 | void Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruct, |
329 | Handle_Graphic3d_Structure& aStruct) |
330 | { |
331 | Graphic3d_Structure::Compute(aDataStruct,aStruct ); |
332 | } |
333 | |
334 | //======================================================================= |
335 | //function : Compute |
336 | //purpose : |
337 | //======================================================================= |
338 | |
339 | Handle_Graphic3d_Structure Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruc, |
340 | const TColStd_Array2OfReal& anArray) |
341 | { |
342 | return Graphic3d_Structure::Compute(aDataStruc,anArray); |
343 | } |
344 | |
345 | //======================================================================= |
346 | //function : Compute |
347 | //purpose : |
348 | //======================================================================= |
349 | |
350 | void Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruc, |
351 | const TColStd_Array2OfReal& anArray, |
352 | Handle_Graphic3d_Structure& aStruc) |
353 | { |
354 | Graphic3d_Structure::Compute(aDataStruc,anArray,aStruc); |
355 | } |