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_Entity) aRefbject = anIter.Value();
196 if ( aRefbject.IsNull() )
199 QString aRefObjectName = aRefbject->GetName();
200 if ( aRefObjectName.isEmpty() )
203 anObjectsNames.append( aRefObjectName );
206 //setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
209 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
212 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
214 Handle(HYDROData_Profile) aProfile =
215 Handle(HYDROData_Profile)::DownCast( anObject );
217 TopoDS_Wire aProfileWire;
219 if ( aProfile->IsValid() ) {
220 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
222 if ( !aProfileShape.IsNull() &&
223 aProfileShape.ShapeType() == TopAbs_WIRE ) {
224 aProfileWire = TopoDS::Wire( aProfileShape );
228 setWire( aProfileWire, false, false );
230 QColor aWireColor = aProfile->GetBorderColor();
231 //setBorderColor( aWireColor, false, false );
233 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
234 anObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
235 anObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
237 Handle(HYDROData_Object) aGeomObject =
238 Handle(HYDROData_Object)::DownCast( anObject );
240 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
242 setShape( anObjShape, false, false );
244 QColor aFillingColor = aGeomObject->GetFillingColor();
245 QColor aBorderColor = aGeomObject->GetBorderColor();
247 //setFillingColor( aFillingColor, false, false );
248 //setBorderColor( aBorderColor, false, false );
250 else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
252 Handle(HYDROData_DummyObject3D) anObject3D =
253 Handle(HYDROData_DummyObject3D)::DownCast( anObject );
254 TopoDS_Shape aShape3D = anObject3D->GetShape();
256 setShape( aShape3D, false, false );
258 QColor aFillingColor = anObject3D->GetFillingColor();
259 QColor aBorderColor = anObject3D->GetBorderColor();
261 //setFillingColor( aFillingColor, false, false );
262 //setBorderColor( aBorderColor, false, false );
267 void HYDROGUI_VTKPrsShape::setWire( const TopoDS_Wire& theWire,
268 const bool theToDisplay,
269 const bool theIsUpdateViewer )
271 myTopoShape = theWire;
272 myDisplayMode = GEOM_Actor::eWireframe;
275 void HYDROGUI_VTKPrsShape::setFaces( const TopoDS_Compound& theWires,
276 const bool theToDisplay,
277 const bool theIsUpdateViewer )
279 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
280 TopoDS_Compound aCompound;
281 BRep_Builder aBuilder;
282 aBuilder.MakeCompound( aCompound );
284 for ( ; anExp.More(); anExp.Next() ) {
285 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
286 if ( aWire.IsNull() ) {
290 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
292 if( aMakeFace.IsDone() ) {
293 aBuilder.Add( aCompound, aMakeFace.Face() );
297 myTopoShape = aCompound;
298 //myDisplayMode = GEOM_Actor::eShading;
301 void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Wire& theWire,
302 const bool theToDisplay,
303 const bool theIsUpdateViewer )
305 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
306 aFaceBuilder.Build();
307 if( aFaceBuilder.IsDone() )
309 TopoDS_Face aFace = aFaceBuilder.Face();
310 setFace( aFace, theToDisplay, theIsUpdateViewer );
314 void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Face& theFace,
315 const bool theToDisplay,
316 const bool theIsUpdateViewer )
318 myTopoShape = theFace;
319 //myDisplayMode = GEOM_Actor::eShading;
322 void HYDROGUI_VTKPrsShape::setShape( const TopoDS_Shape& theShape,
323 const bool theToDisplay,
324 const bool theIsUpdateViewer )
326 myTopoShape = theShape;
327 //myDisplayMode = GEOM_Actor::eShading;