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_Obstacle.h>
28 #include <HYDROData_PolylineXY.h>
29 #include <HYDROData_Polyline3D.h>
30 #include <HYDROData_Profile.h>
31 #include <HYDROData_Region.h>
32 #include <HYDROData_Stream.h>
33 #include <HYDROData_Zone.h>
35 #include <BRepBuilderAPI_MakeEdge.hxx>
36 #include <BRepBuilderAPI_MakeWire.hxx>
37 #include <BRepBuilderAPI_MakeFace.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <Graphic3d_MaterialAspect.hxx>
45 #include <TopoDS_Wire.hxx>
46 #include <TopoDS_Face.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <BRep_Builder.hxx>
52 #include <Precision.hxx>
54 #include <HYDROGUI_Actor.h>
55 #include <vtkScalarBarActor.h>
59 // Hard-coded value of shape deflection coefficient for VTK viewer
60 const double VTK_MIN_DEFLECTION = 0.001;
63 //=======================================================================
64 // name : HYDROGUI_VTKPrsShape
65 // Purpose : Constructor
66 //=======================================================================
67 HYDROGUI_VTKPrsShape::HYDROGUI_VTKPrsShape( const Handle(HYDROData_Entity)& theObject )
68 : HYDROGUI_VTKPrs( theObject ),
69 myDisplayMode( GEOM_Actor::eWireframe )
73 //=======================================================================
74 // name : HYDROGUI_VTKPrsShape
75 // Purpose : Destructor
76 //=======================================================================
77 HYDROGUI_VTKPrsShape::~HYDROGUI_VTKPrsShape()
81 //================================================================
84 //================================================================
85 void HYDROGUI_VTKPrsShape::compute()
87 HYDROGUI_VTKPrs::compute();
89 if ( !getObject().IsNull() )
93 if ( !myTopoShape.IsNull() )
95 HYDROGUI_Actor* anActor = getActor<HYDROGUI_Actor>(this);
96 anActor->SetShape( myTopoShape, VTK_MIN_DEFLECTION );
97 anActor->setDisplayMode( myDisplayMode );
98 anActor->setIO( getIO() );
104 void HYDROGUI_VTKPrsShape::buildShape()
106 Handle(HYDROData_Entity) anObject = getObject();
107 // Try to retrieve information from object
108 if ( !anObject.IsNull() )
110 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( anObject->Label() );
112 if ( anObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
114 Handle(HYDROData_ImmersibleZone) aZoneObj =
115 Handle(HYDROData_ImmersibleZone)::DownCast( anObject );
117 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
118 if ( !aZoneShape.IsNull() ) {
119 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
120 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
121 setFace( aZoneFace, false, false );
123 myTopoShape = aZoneShape;
127 QColor aFillingColor = aZoneObj->GetFillingColor();
128 QColor aBorderColor = aZoneObj->GetBorderColor();
130 //setFillingColor( aFillingColor, false, false );
131 //setBorderColor( aBorderColor, false, false );
133 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
135 Handle(HYDROData_PolylineXY) aPolyline =
136 Handle(HYDROData_PolylineXY)::DownCast( anObject );
138 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
140 if ( !aPolylineShape.IsNull() ) {
141 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
142 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
143 setWire( aPolylineWire, false, false );
145 myTopoShape = aPolylineShape;
146 myDisplayMode = GEOM_Actor::eWireframe;
150 QColor aWireColor = aPolyline->GetWireColor();
151 //setBorderColor( aWireColor, false, false );
153 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
155 Handle(HYDROData_Polyline3D) aPolyline =
156 Handle(HYDROData_Polyline3D)::DownCast( anObject );
158 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
160 if ( !aPolylineShape.IsNull() ) {
161 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
162 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
163 setWire( aPolylineWire, false, false );
165 myTopoShape = aPolylineShape;
166 myDisplayMode = GEOM_Actor::eWireframe;
170 QColor aWireColor = aPolyline->GetBorderColor();
171 //setBorderColor( aWireColor, false, false );
173 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
175 Handle(HYDROData_Zone) aZone =
176 Handle(HYDROData_Zone)::DownCast( anObject );
178 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
180 setFace( aZoneFace, false, false );
181 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
183 // Red color for a zone with bathymetry conflict
184 //setFillingColor( Qt::red );
188 // Generate the filling color for zone
189 QStringList anObjectsNames;
191 HYDROData_SequenceOfObjects aRefObjects = aZone->GetObjects();
192 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
193 for ( ; anIter.More(); anIter.Next() )
195 Handle(HYDROData_Object) aRefbject =
196 Handle(HYDROData_Object)::DownCast( 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 );
268 void HYDROGUI_VTKPrsShape::setWire( const TopoDS_Wire& theWire,
269 const bool theToDisplay,
270 const bool theIsUpdateViewer )
272 myTopoShape = theWire;
273 myDisplayMode = GEOM_Actor::eWireframe;
276 void HYDROGUI_VTKPrsShape::setFaces( const TopoDS_Compound& theWires,
277 const bool theToDisplay,
278 const bool theIsUpdateViewer )
280 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
281 TopoDS_Compound aCompound;
282 BRep_Builder aBuilder;
283 aBuilder.MakeCompound( aCompound );
285 for ( ; anExp.More(); anExp.Next() ) {
286 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
287 if ( aWire.IsNull() ) {
291 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
293 if( aMakeFace.IsDone() ) {
294 aBuilder.Add( aCompound, aMakeFace.Face() );
298 myTopoShape = aCompound;
299 //myDisplayMode = GEOM_Actor::eShading;
302 void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Wire& theWire,
303 const bool theToDisplay,
304 const bool theIsUpdateViewer )
306 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
307 aFaceBuilder.Build();
308 if( aFaceBuilder.IsDone() )
310 TopoDS_Face aFace = aFaceBuilder.Face();
311 setFace( aFace, theToDisplay, theIsUpdateViewer );
315 void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Face& theFace,
316 const bool theToDisplay,
317 const bool theIsUpdateViewer )
319 myTopoShape = theFace;
320 //myDisplayMode = GEOM_Actor::eShading;
323 void HYDROGUI_VTKPrsShape::setShape( const TopoDS_Shape& theShape,
324 const bool theToDisplay,
325 const bool theIsUpdateViewer )
327 myTopoShape = theShape;
328 //myDisplayMode = GEOM_Actor::eShading;