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