1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_VTKPrsShape.h"
21 #include <HYDROData_Entity.h>
22 #include <HYDROData_Channel.h>
23 #include <HYDROData_Document.h>
24 #include <HYDROData_DummyObject3D.h>
25 #include <HYDROData_Image.h>
26 #include <HYDROData_ImmersibleZone.h>
27 #include <HYDROData_BCPolygon.h>
28 #include <HYDROData_Obstacle.h>
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_Polyline3D.h>
31 #include <HYDROData_Profile.h>
32 #include <HYDROData_Region.h>
33 #include <HYDROData_Stream.h>
34 #include <HYDROData_Zone.h>
36 #include <BRepBuilderAPI_MakeEdge.hxx>
37 #include <BRepBuilderAPI_MakeWire.hxx>
38 #include <BRepBuilderAPI_MakeFace.hxx>
42 #include <Graphic3d_AspectFillArea3d.hxx>
43 #include <Graphic3d_MaterialAspect.hxx>
46 #include <TopoDS_Wire.hxx>
47 #include <TopoDS_Face.hxx>
49 #include <TopExp_Explorer.hxx>
51 #include <BRep_Builder.hxx>
53 #include <Precision.hxx>
55 #include <HYDROGUI_Actor.h>
56 #include <vtkScalarBarActor.h>
60 // Hard-coded value of shape deflection coefficient for VTK viewer
61 const double VTK_MIN_DEFLECTION = 0.001;
64 //=======================================================================
65 // name : HYDROGUI_VTKPrsShape
66 // Purpose : Constructor
67 //=======================================================================
68 HYDROGUI_VTKPrsShape::HYDROGUI_VTKPrsShape( const Handle(HYDROData_Entity)& theObject )
69 : HYDROGUI_VTKPrs( theObject ),
70 myDisplayMode( GEOM_Actor::eWireframe )
74 //=======================================================================
75 // name : HYDROGUI_VTKPrsShape
76 // Purpose : Destructor
77 //=======================================================================
78 HYDROGUI_VTKPrsShape::~HYDROGUI_VTKPrsShape()
82 //================================================================
85 //================================================================
86 void HYDROGUI_VTKPrsShape::compute()
88 HYDROGUI_VTKPrs::compute();
90 if ( !getObject().IsNull() )
94 if ( !myTopoShape.IsNull() )
96 HYDROGUI_Actor* anActor = getActor<HYDROGUI_Actor>(this);
97 anActor->SetShape( myTopoShape, VTK_MIN_DEFLECTION );
98 anActor->setDisplayMode( myDisplayMode );
99 anActor->setIO( getIO() );
105 void HYDROGUI_VTKPrsShape::buildShape()
107 Handle(HYDROData_Entity) anObject = getObject();
108 // Try to retrieve information from object
109 if ( !anObject.IsNull() )
111 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( anObject->Label() );
113 if ( anObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
115 Handle(HYDROData_ImmersibleZone) aZoneObj =
116 Handle(HYDROData_ImmersibleZone)::DownCast( anObject );
118 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
119 if ( !aZoneShape.IsNull() ) {
120 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
121 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
122 setFace( aZoneFace, false, false );
124 myTopoShape = aZoneShape;
128 QColor aFillingColor = aZoneObj->GetFillingColor();
129 QColor aBorderColor = aZoneObj->GetBorderColor();
131 //setFillingColor( aFillingColor, false, false );
132 //setBorderColor( aBorderColor, false, false );
134 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
136 Handle(HYDROData_PolylineXY) aPolyline =
137 Handle(HYDROData_PolylineXY)::DownCast( anObject );
139 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
141 if ( !aPolylineShape.IsNull() ) {
142 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
143 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
144 setWire( aPolylineWire, false, false );
146 myTopoShape = aPolylineShape;
147 myDisplayMode = GEOM_Actor::eWireframe;
151 //QColor aWireColor = aPolyline->GetWireColor();
152 //setBorderColor( aWireColor, false, false );
154 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
156 Handle(HYDROData_Polyline3D) aPolyline =
157 Handle(HYDROData_Polyline3D)::DownCast( anObject );
159 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
161 if ( !aPolylineShape.IsNull() ) {
162 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
163 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
164 setWire( aPolylineWire, false, false );
166 myTopoShape = aPolylineShape;
167 myDisplayMode = GEOM_Actor::eWireframe;
171 QColor aWireColor = aPolyline->GetBorderColor();
172 //setBorderColor( aWireColor, false, false );
174 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
176 Handle(HYDROData_Zone) aZone =
177 Handle(HYDROData_Zone)::DownCast( anObject );
179 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
181 setFace( aZoneFace, false, false );
182 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
184 // Red color for a zone with bathymetry conflict
185 //setFillingColor( Qt::red );
189 // Generate the filling color for zone
190 QStringList anObjectsNames;
192 HYDROData_SequenceOfObjects aRefObjects = aZone->GetObjects();
193 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
194 for ( ; anIter.More(); anIter.Next() )
196 Handle(HYDROData_Entity) aRefbject = anIter.Value();
197 if ( aRefbject.IsNull() )
200 QString aRefObjectName = aRefbject->GetName();
201 if ( aRefObjectName.isEmpty() )
204 anObjectsNames.append( aRefObjectName );
207 //setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
210 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
213 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
215 Handle(HYDROData_Profile) aProfile =
216 Handle(HYDROData_Profile)::DownCast( anObject );
218 TopoDS_Wire aProfileWire;
220 if ( aProfile->IsValid() ) {
221 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
223 if ( !aProfileShape.IsNull() &&
224 aProfileShape.ShapeType() == TopAbs_WIRE ) {
225 aProfileWire = TopoDS::Wire( aProfileShape );
229 setWire( aProfileWire, false, false );
231 QColor aWireColor = aProfile->GetBorderColor();
232 //setBorderColor( aWireColor, false, false );
234 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
235 anObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
236 anObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
238 Handle(HYDROData_Object) aGeomObject =
239 Handle(HYDROData_Object)::DownCast( anObject );
241 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
243 setShape( anObjShape, false, false );
245 QColor aFillingColor = aGeomObject->GetFillingColor();
246 QColor aBorderColor = aGeomObject->GetBorderColor();
248 //setFillingColor( aFillingColor, false, false );
249 //setBorderColor( aBorderColor, false, false );
251 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
253 Handle(HYDROData_DummyObject3D) anObject3D =
254 Handle(HYDROData_DummyObject3D)::DownCast( anObject );
255 TopoDS_Shape aShape3D = anObject3D->GetShape();
257 setShape( aShape3D, false, false );
259 QColor aFillingColor = anObject3D->GetFillingColor();
260 QColor aBorderColor = anObject3D->GetBorderColor();
262 //setFillingColor( aFillingColor, false, false );
263 //setBorderColor( aBorderColor, false, false );
265 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_BCPolygon) ) )
267 Handle(HYDROData_BCPolygon) aBCObj =
268 Handle(HYDROData_BCPolygon)::DownCast( anObject );
270 TopoDS_Shape aBCShape = aBCObj->GetTopShape();
271 if ( !aBCShape.IsNull() )
273 if ( aBCShape.ShapeType() == TopAbs_FACE )
275 TopoDS_Face aFace = TopoDS::Face( aBCShape );
276 setFace( aFace, false, false );
280 myTopoShape = aBCShape;
284 QColor aFillingColor = aBCObj->GetFillingColor();
285 QColor aBorderColor = aBCObj->GetBorderColor();
291 void HYDROGUI_VTKPrsShape::setWire( const TopoDS_Wire& theWire,
292 const bool theToDisplay,
293 const bool theIsUpdateViewer )
295 myTopoShape = theWire;
296 myDisplayMode = GEOM_Actor::eWireframe;
299 void HYDROGUI_VTKPrsShape::setFaces( const TopoDS_Compound& theWires,
300 const bool theToDisplay,
301 const bool theIsUpdateViewer )
303 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
304 TopoDS_Compound aCompound;
305 BRep_Builder aBuilder;
306 aBuilder.MakeCompound( aCompound );
308 for ( ; anExp.More(); anExp.Next() ) {
309 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
310 if ( aWire.IsNull() ) {
314 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
316 if( aMakeFace.IsDone() ) {
317 aBuilder.Add( aCompound, aMakeFace.Face() );
321 myTopoShape = aCompound;
322 //myDisplayMode = GEOM_Actor::eShading;
325 void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Wire& theWire,
326 const bool theToDisplay,
327 const bool theIsUpdateViewer )
329 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
330 aFaceBuilder.Build();
331 if( aFaceBuilder.IsDone() )
333 TopoDS_Face aFace = aFaceBuilder.Face();
334 setFace( aFace, theToDisplay, theIsUpdateViewer );
338 void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Face& theFace,
339 const bool theToDisplay,
340 const bool theIsUpdateViewer )
342 myTopoShape = theFace;
343 //myDisplayMode = GEOM_Actor::eShading;
346 void HYDROGUI_VTKPrsShape::setShape( const TopoDS_Shape& theShape,
347 const bool theToDisplay,
348 const bool theIsUpdateViewer )
350 myTopoShape = theShape;
351 //myDisplayMode = GEOM_Actor::eShading;