1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 // Modified: 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets
17 #define IMP020200 //GG Add Transformation() method
19 #include <Prs3d_Presentation.ixx>
20 #include <TColStd_Array2OfReal.hxx>
21 #include <Graphic3d_Structure.hxx>
22 #include <Aspect_TypeOfHighlightMethod.hxx>
26 #include <gp_Trsf.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>
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));
45 Array.SetValue(4,1,0.);
46 Array.SetValue(4,2,0.);
47 Array.SetValue(4,3,0.);
48 Array.SetValue(4,4,1.);
51 //=======================================================================
52 //function : Prs3d_Presentation
54 //=======================================================================
55 Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager)& theViewer,
56 const Standard_Boolean theToInit)
57 : Graphic3d_Structure (theViewer)
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,
75 aDefAspect->SetPolygonOffsets (Aspect_POM_Fill, 1.0f, 0.0f);
76 SetPrimitivesAspect (aDefAspect);
79 //=======================================================================
80 //function : Prs3d_Presentation
82 //=======================================================================
83 Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager)& theViewer,
84 const Handle(Prs3d_Presentation)& thePrs)
85 : Graphic3d_Structure (theViewer, thePrs)
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,
98 aDefAspect->SetPolygonOffsets (Aspect_POM_Fill, 1.0f, 0.0f);
99 SetPrimitivesAspect (aDefAspect);
102 //=======================================================================
103 //function : Highlight
105 //=======================================================================
106 void Prs3d_Presentation::Highlight()
108 SetHighlightColor(Quantity_Color(Quantity_NOC_GRAY99));
109 Aspect_TypeOfHighlightMethod Method = Aspect_TOHM_COLOR;
110 Graphic3d_Structure::Highlight(Method);
113 //=======================================================================
116 //=======================================================================
117 void Prs3d_Presentation::Color(const Quantity_NameOfColor aColor)
119 SetHighlightColor(Quantity_Color(aColor));
120 Graphic3d_Structure::Highlight(Aspect_TOHM_COLOR);
123 //=======================================================================
124 //function : BoundBox
126 //=======================================================================
127 void Prs3d_Presentation::BoundBox()
129 SetHighlightColor(Quantity_Color(Quantity_NOC_GRAY99));
130 Graphic3d_Structure::Highlight(Aspect_TOHM_BOUNDBOX);
134 //=======================================================================
135 //function : SetShadingAspect
137 //=======================================================================
138 void Prs3d_Presentation::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect)
140 SetPrimitivesAspect(aShadingAspect->Aspect());
143 //=======================================================================
144 //function : IsPickable
146 //=======================================================================
147 Standard_Boolean Prs3d_Presentation::IsPickable () const
149 return Graphic3d_Structure::IsSelectable();
152 //=======================================================================
153 //function : SetPickable
155 //=======================================================================
157 void Prs3d_Presentation::SetPickable()
159 SetPick(Standard_True);
162 //=======================================================================
163 //function : SetUnPickable
165 //=======================================================================
166 void Prs3d_Presentation::SetUnPickable()
168 SetPick(Standard_False);
171 //=======================================================================
172 //function : Transform
174 //=======================================================================
176 void Prs3d_Presentation::Transform(const Handle(Geom_Transformation)& aTransformation)
178 TColStd_Array2OfReal Array (1,4,1,4);
179 MakeGraphicTrsf(aTransformation, Array);
180 SetTransform(Array, Graphic3d_TOC_REPLACE);
184 //=======================================================================
185 //function : Transformation
187 //=======================================================================
189 Handle(Geom_Transformation) Prs3d_Presentation::Transformation() const {
190 TColStd_Array2OfReal matrix(1,4,1,4);
192 Graphic3d_Structure::Transform(matrix);
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),
200 Handle(Geom_Transformation) gtrsf = new Geom_Transformation(trsf);
206 //=======================================================================
209 //=======================================================================
210 void Prs3d_Presentation::Place (const Quantity_Length X,
211 const Quantity_Length Y,
212 const Quantity_Length Z)
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);
221 //=======================================================================
222 //function : Multiply
224 //=======================================================================
225 void Prs3d_Presentation::Multiply(const Handle(Geom_Transformation)& aTransformation)
227 TColStd_Array2OfReal Array (1,4,1,4);
228 MakeGraphicTrsf(aTransformation, Array);
229 SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE);
232 //=======================================================================
235 //=======================================================================
236 void Prs3d_Presentation::Move (const Quantity_Length X,
237 const Quantity_Length Y,
238 const Quantity_Length Z)
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);
247 //=======================================================================
250 //=======================================================================
251 void Prs3d_Presentation::Connect
252 ( const Handle(Prs3d_Presentation)& aPresentation)
254 Graphic3d_Structure::Connect(aPresentation, Graphic3d_TOC_DESCENDANT);
258 //=======================================================================
261 //=======================================================================
262 void Prs3d_Presentation::Remove (const Handle(Prs3d_Presentation)& aPresentation)
264 Disconnect(aPresentation);
267 //=======================================================================
268 //function : RemoveAll
270 //=======================================================================
271 void Prs3d_Presentation::RemoveAll ()
273 DisconnectAll(Graphic3d_TOC_DESCENDANT);
277 //=======================================================================
278 //function : CurrentGroup
280 //=======================================================================
281 Handle(Graphic3d_Group) Prs3d_Presentation::CurrentGroup () const
283 if (Groups().IsEmpty())
285 return const_cast<Prs3d_Presentation* >(this)->NewGroup();
287 return Groups().Last();
290 //=======================================================================
293 //=======================================================================
295 Handle(Graphic3d_Structure) Prs3d_Presentation::
296 Compute(const Handle(Graphic3d_DataStructureManager)& /*aProjector*/)
301 //=======================================================================
304 //=======================================================================
306 void Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruct,
307 Handle_Graphic3d_Structure& aStruct)
309 Graphic3d_Structure::Compute(aDataStruct,aStruct );
312 //=======================================================================
315 //=======================================================================
317 Handle_Graphic3d_Structure Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruc,
318 const TColStd_Array2OfReal& anArray)
320 return Graphic3d_Structure::Compute(aDataStruc,anArray);
323 //=======================================================================
326 //=======================================================================
328 void Prs3d_Presentation::Compute(const Handle_Graphic3d_DataStructureManager& aDataStruc,
329 const TColStd_Array2OfReal& anArray,
330 Handle_Graphic3d_Structure& aStruc)
332 Graphic3d_Structure::Compute(aDataStruc,anArray,aStruc);