0024637: Visualization - clean up implementation of rendering in immediate mode
[occt.git] / src / Prs3d / Prs3d_Presentation.cxx
CommitLineData
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
38static 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
679ecdee 53//purpose :
7fd59977 54//=======================================================================
679ecdee 55Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager)& theViewer,
56 const Standard_Boolean theToInit)
57: Graphic3d_Structure (theViewer)
7fd59977 58{
679ecdee 59 if (!theToInit)
60 {
61 return;
7fd59977 62 }
63
679ecdee 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//=======================================================================
83Prs3d_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);
7fd59977 100}
101
102//=======================================================================
103//function : Highlight
104//purpose :
105//=======================================================================
106void 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//=======================================================================
117void 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//=======================================================================
127void 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//=======================================================================
138void Prs3d_Presentation::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect)
139{
140 SetPrimitivesAspect(aShadingAspect->Aspect());
141}
142
143//=======================================================================
144//function : IsPickable
145//purpose :
146//=======================================================================
147Standard_Boolean Prs3d_Presentation::IsPickable () const
148{
149 return Graphic3d_Structure::IsSelectable();
150}
151
152//=======================================================================
153//function : SetPickable
154//purpose :
155//=======================================================================
156
157void Prs3d_Presentation::SetPickable()
158{
159 SetPick(Standard_True);
160}
161
162//=======================================================================
163//function : SetUnPickable
164//purpose :
165//=======================================================================
166void Prs3d_Presentation::SetUnPickable()
167{
168 SetPick(Standard_False);
169}
170
171//=======================================================================
172//function : Transform
173//purpose :
174//=======================================================================
175
176void 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
189Handle(Geom_Transformation) Prs3d_Presentation::Transformation() const {
190TColStd_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//=======================================================================
210void 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//=======================================================================
225void 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//=======================================================================
236void 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//=======================================================================
249//function : Clear
250//purpose :
251//=======================================================================
252void Prs3d_Presentation::Clear(const Standard_Boolean WithDestruction)
253{
254 Graphic3d_Structure::Clear(WithDestruction);
255 // myCurrentGroup.Nullify();
256 myCurrentGroup = NULL;
257
258}
259
260
261//=======================================================================
262//function : Connect
263//purpose :
264//=======================================================================
265void Prs3d_Presentation::Connect
266 ( const Handle(Prs3d_Presentation)& aPresentation)
267{
268 Graphic3d_Structure::Connect(aPresentation, Graphic3d_TOC_DESCENDANT);
269}
270
271
272//=======================================================================
273//function : Remove
274//purpose :
275//=======================================================================
276void Prs3d_Presentation::Remove (const Handle(Prs3d_Presentation)& aPresentation)
277{
278 Disconnect(aPresentation);
279}
280
281//=======================================================================
282//function : RemoveAll
283//purpose :
284//=======================================================================
285void Prs3d_Presentation::RemoveAll ()
286{
287 DisconnectAll(Graphic3d_TOC_DESCENDANT);
288}
289
290
291//=======================================================================
292//function : CurrentGroup
293//purpose :
294//=======================================================================
295Handle(Graphic3d_Group) Prs3d_Presentation::CurrentGroup () const
296{
297 if(myCurrentGroup.IsNull()){
298 void *ptr = (void*) this;
299 Prs3d_Presentation* p = (Prs3d_Presentation *)ptr;
300 p->NewGroup();
301 }
302 return myCurrentGroup;
303}
304
305
306//=======================================================================
307//function : NewGroup
308//purpose :
309//=======================================================================
310Handle(Graphic3d_Group) Prs3d_Presentation::NewGroup ()
311{
312 myCurrentGroup = new Graphic3d_Group(this);
313 return myCurrentGroup;
314}
315
316//=======================================================================
317//function : Display
318//purpose :
319//=======================================================================
320void Prs3d_Presentation::Display ()
321{
322 Graphic3d_Structure::Display();
323}
324
325
326//=======================================================================
327//function : Compute
328//purpose :
329//=======================================================================
330
331Handle(Graphic3d_Structure) Prs3d_Presentation::
332 Compute(const Handle(Graphic3d_DataStructureManager)& /*aProjector*/)
333{
334 return this;
335}
336
337//=======================================================================
338//function : Compute
339//purpose :
340//=======================================================================
341
342void Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruct,
343 Handle_Graphic3d_Structure& aStruct)
344{
345 Graphic3d_Structure::Compute(aDataStruct,aStruct );
346}
347
348//=======================================================================
349//function : Compute
350//purpose :
351//=======================================================================
352
353Handle_Graphic3d_Structure Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruc,
354 const TColStd_Array2OfReal& anArray)
355{
356 return Graphic3d_Structure::Compute(aDataStruc,anArray);
357}
358
359//=======================================================================
360//function : Compute
361//purpose :
362//=======================================================================
363
364void Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruc,
365 const TColStd_Array2OfReal& anArray,
366 Handle_Graphic3d_Structure& aStruc)
367{
368 Graphic3d_Structure::Compute(aDataStruc,anArray,aStruc);
369}