0024814: Avoid using explicit names of Handle classes
[occt.git] / src / Prs3d / Prs3d_Presentation.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
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 (const Handle(Graphic3d_StructureManager)& theViewer,
56                                         const Standard_Boolean                    theToInit)
57 : Graphic3d_Structure (theViewer)
58 {
59   if (!theToInit)
60   {
61     return;
62   }
63
64   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
65   Quantity_Color aColor = aMat.AmbientColor();
66   // It is necessary to set default polygon offsets for a new presentation
67   Handle(Graphic3d_AspectFillArea3d) aDefAspect =
68     new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
69                                     aColor,
70                                     aColor,
71                                     Aspect_TOL_SOLID,
72                                     1.0,
73                                     Graphic3d_NOM_BRASS,
74                                     Graphic3d_NOM_BRASS);
75   aDefAspect->SetPolygonOffsets (Aspect_POM_Fill, 1.0f, 0.0f);
76   SetPrimitivesAspect (aDefAspect);
77 }
78
79 //=======================================================================
80 //function : Prs3d_Presentation
81 //purpose  :
82 //=======================================================================
83 Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager)& theViewer,
84                                         const Handle(Prs3d_Presentation)&         thePrs)
85 : Graphic3d_Structure (theViewer, thePrs)
86 {
87   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
88   Quantity_Color aColor = aMat.AmbientColor();
89   // It is necessary to set default polygon offsets for a new presentation
90   Handle(Graphic3d_AspectFillArea3d) aDefAspect =
91     new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
92                                     aColor,
93                                     aColor,
94                                     Aspect_TOL_SOLID,
95                                     1.0,
96                                     Graphic3d_NOM_BRASS,
97                                     Graphic3d_NOM_BRASS);
98   aDefAspect->SetPolygonOffsets (Aspect_POM_Fill, 1.0f, 0.0f);
99   SetPrimitivesAspect (aDefAspect);
100 }
101
102 //=======================================================================
103 //function : Highlight
104 //purpose  : 
105 //=======================================================================
106 void Prs3d_Presentation::Highlight()
107 {
108   SetHighlightColor(Quantity_Color(Quantity_NOC_GRAY99));
109   Aspect_TypeOfHighlightMethod Method = Aspect_TOHM_COLOR;
110   Graphic3d_Structure::Highlight(Method);
111 }
112
113 //=======================================================================
114 //function : Color
115 //purpose  : 
116 //=======================================================================
117 void Prs3d_Presentation::Color(const Quantity_NameOfColor aColor) 
118 {
119   SetHighlightColor(Quantity_Color(aColor));
120   Graphic3d_Structure::Highlight(Aspect_TOHM_COLOR);
121 }
122
123 //=======================================================================
124 //function : BoundBox
125 //purpose  : 
126 //=======================================================================
127 void Prs3d_Presentation::BoundBox()
128
129   SetHighlightColor(Quantity_Color(Quantity_NOC_GRAY99));
130   Graphic3d_Structure::Highlight(Aspect_TOHM_BOUNDBOX);
131 }
132
133
134 //=======================================================================
135 //function : SetShadingAspect
136 //purpose  : 
137 //=======================================================================
138 void Prs3d_Presentation::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) 
139
140   SetPrimitivesAspect(aShadingAspect->Aspect());
141 }
142
143 //=======================================================================
144 //function : IsPickable
145 //purpose  : 
146 //=======================================================================
147 Standard_Boolean Prs3d_Presentation::IsPickable () const 
148 {
149   return Graphic3d_Structure::IsSelectable();
150 }
151
152 //=======================================================================
153 //function : SetPickable
154 //purpose  : 
155 //=======================================================================
156
157 void Prs3d_Presentation::SetPickable() 
158 {
159   SetPick(Standard_True);
160 }
161
162 //=======================================================================
163 //function : SetUnPickable
164 //purpose  : 
165 //=======================================================================
166 void Prs3d_Presentation::SetUnPickable() 
167 {
168   SetPick(Standard_False);
169 }
170
171 //=======================================================================
172 //function : Transform
173 //purpose  : 
174 //=======================================================================
175
176 void Prs3d_Presentation::Transform(const Handle(Geom_Transformation)& aTransformation) 
177 {
178   TColStd_Array2OfReal Array (1,4,1,4);
179   MakeGraphicTrsf(aTransformation, Array);
180   SetTransform(Array, Graphic3d_TOC_REPLACE);
181 }
182
183 #ifdef IMP020200
184 //=======================================================================
185 //function : Transformation
186 //purpose  : 
187 //=======================================================================
188
189 Handle(Geom_Transformation) Prs3d_Presentation::Transformation() const {
190 TColStd_Array2OfReal matrix(1,4,1,4);
191
192   Graphic3d_Structure::Transform(matrix);
193
194   gp_Trsf trsf;
195   trsf.SetValues(
196         matrix.Value(1,1),matrix.Value(1,2),matrix.Value(1,3),matrix.Value(1,4),
197         matrix.Value(2,1),matrix.Value(2,2),matrix.Value(2,3),matrix.Value(2,4),
198         matrix.Value(3,1),matrix.Value(3,2),matrix.Value(3,3),matrix.Value(3,4),
199         0.001,0.0001);  
200   Handle(Geom_Transformation) gtrsf = new Geom_Transformation(trsf); 
201
202   return gtrsf;
203 }
204 #endif
205
206 //=======================================================================
207 //function : Place
208 //purpose  : 
209 //=======================================================================
210 void Prs3d_Presentation::Place (const Quantity_Length X,
211                                 const Quantity_Length Y,
212                                 const Quantity_Length Z) 
213 {
214   Handle(Geom_Transformation) aTransformation = new Geom_Transformation;
215   aTransformation->SetTranslation(gp_Vec(X,Y,Z));
216   TColStd_Array2OfReal Array (1,4,1,4);
217   MakeGraphicTrsf(aTransformation, Array);
218   SetTransform(Array, Graphic3d_TOC_REPLACE);
219 }
220
221 //=======================================================================
222 //function : Multiply
223 //purpose  : 
224 //=======================================================================
225 void Prs3d_Presentation::Multiply(const Handle(Geom_Transformation)& aTransformation) 
226 {
227   TColStd_Array2OfReal Array (1,4,1,4);
228   MakeGraphicTrsf(aTransformation, Array);
229   SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE);
230 }
231
232 //=======================================================================
233 //function : Move
234 //purpose  : 
235 //=======================================================================
236 void Prs3d_Presentation::Move  (const Quantity_Length X,
237                                 const Quantity_Length Y,
238                                 const Quantity_Length Z) 
239 {
240   Handle(Geom_Transformation) aTransformation = new Geom_Transformation;
241   aTransformation->SetTranslation(gp_Vec(X,Y,Z));
242   TColStd_Array2OfReal Array (1,4,1,4);
243   MakeGraphicTrsf(aTransformation, Array);
244   SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE);
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 (Groups().IsEmpty())
284   {
285     return const_cast<Prs3d_Presentation* >(this)->NewGroup();
286   }
287   return Groups().Last();
288 }
289
290 //=======================================================================
291 //function : Compute
292 //purpose  : 
293 //=======================================================================
294
295 Handle(Graphic3d_Structure) Prs3d_Presentation::
296        Compute(const Handle(Graphic3d_DataStructureManager)& /*aProjector*/) 
297 {
298   return this;
299 }
300
301 //=======================================================================
302 //function : Compute
303 //purpose  : 
304 //=======================================================================
305
306 void Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruct, 
307                                  Handle(Graphic3d_Structure)& aStruct)
308 {
309  Graphic3d_Structure::Compute(aDataStruct,aStruct );
310 }
311
312 //=======================================================================
313 //function : Compute
314 //purpose  : 
315 //=======================================================================
316
317 Handle(Graphic3d_Structure) Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruc, 
318                                                        const TColStd_Array2OfReal& anArray)
319 {
320  return Graphic3d_Structure::Compute(aDataStruc,anArray);
321 }
322
323 //=======================================================================
324 //function : Compute
325 //purpose  : 
326 //=======================================================================
327
328 void Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruc,
329                                  const TColStd_Array2OfReal& anArray,
330                                  Handle(Graphic3d_Structure)& aStruc)
331 {
332  Graphic3d_Structure::Compute(aDataStruc,anArray,aStruc);
333 }