--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_VTKPrsShape.h"
+
+#include <HYDROData_Entity.h>
+#include <HYDROData_Channel.h>
+#include <HYDROData_Document.h>
+#include <HYDROData_DummyObject3D.h>
+#include <HYDROData_Image.h>
+#include <HYDROData_ImmersibleZone.h>
+#include <HYDROData_Obstacle.h>
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_Polyline3D.h>
+#include <HYDROData_Profile.h>
+#include <HYDROData_Region.h>
+#include <HYDROData_Stream.h>
+#include <HYDROData_Zone.h>
+
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+
+#include <gp_Pnt.hxx>
+
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_MaterialAspect.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
+
+#include <TopExp_Explorer.hxx>
+
+#include <BRep_Builder.hxx>
+
+#include <Precision.hxx>
+
+#include <GEOM_Actor.h>
+#include <vtkScalarBarActor.h>
+
+#include <QString>
+
+// Hard-coded value of shape deflection coefficient for VTK viewer
+const double VTK_MIN_DEFLECTION = 0.001;
+
+
+//=======================================================================
+// name : HYDROGUI_VTKPrsShape
+// Purpose : Constructor
+//=======================================================================
+HYDROGUI_VTKPrsShape::HYDROGUI_VTKPrsShape( const Handle(HYDROData_Entity)& theObject )
+: HYDROGUI_VTKPrs( theObject )
+{
+}
+
+//=======================================================================
+// name : HYDROGUI_VTKPrsShape
+// Purpose : Destructor
+//=======================================================================
+HYDROGUI_VTKPrsShape::~HYDROGUI_VTKPrsShape()
+{
+}
+
+//================================================================
+// Function : compute
+// Purpose :
+//================================================================
+void HYDROGUI_VTKPrsShape::compute()
+{
+ if ( !getObject().IsNull() )
+ {
+ buildShape();
+
+ if ( !myTopoShape.IsNull() )
+ {
+ GEOM_Actor* anActor = GEOM_Actor::New();
+ anActor->SetShape( myTopoShape, VTK_MIN_DEFLECTION );
+ anActor->setIO( getIO() );
+ AddObject( anActor );
+
+ anActor->Delete();
+ }
+ }
+}
+
+
+void HYDROGUI_VTKPrsShape::buildShape()
+{
+ Handle(HYDROData_Entity) anObject = getObject();
+ // Try to retrieve information from object
+ if ( !anObject.IsNull() )
+ {
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( anObject->Label() );
+
+ if ( anObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
+ {
+ Handle(HYDROData_ImmersibleZone) aZoneObj =
+ Handle(HYDROData_ImmersibleZone)::DownCast( anObject );
+
+ TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
+ if ( !aZoneShape.IsNull() ) {
+ if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
+ TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
+ setFace( aZoneFace, false, false );
+ } else {
+ myTopoShape = aZoneShape;
+ }
+ }
+
+ QColor aFillingColor = aZoneObj->GetFillingColor();
+ QColor aBorderColor = aZoneObj->GetBorderColor();
+
+ //setFillingColor( aFillingColor, false, false );
+ //setBorderColor( aBorderColor, false, false );
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
+ {
+ Handle(HYDROData_PolylineXY) aPolyline =
+ Handle(HYDROData_PolylineXY)::DownCast( anObject );
+
+ TopoDS_Shape aPolylineShape = aPolyline->GetShape();
+
+ if ( !aPolylineShape.IsNull() ) {
+ if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
+ TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
+ setWire( aPolylineWire, false, false );
+ } else {
+ myTopoShape = aPolylineShape;
+ }
+ }
+
+ QColor aWireColor = aPolyline->GetWireColor();
+ //setBorderColor( aWireColor, false, false );
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
+ {
+ Handle(HYDROData_Polyline3D) aPolyline =
+ Handle(HYDROData_Polyline3D)::DownCast( anObject );
+
+ TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
+
+ if ( !aPolylineShape.IsNull() ) {
+ if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
+ TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
+ setWire( aPolylineWire, false, false );
+ } else {
+ myTopoShape = aPolylineShape;
+ }
+ }
+
+ QColor aWireColor = aPolyline->GetBorderColor();
+ //setBorderColor( aWireColor, false, false );
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
+ {
+ Handle(HYDROData_Zone) aZone =
+ Handle(HYDROData_Zone)::DownCast( anObject );
+
+ TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
+
+ setFace( aZoneFace, false, false );
+ if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
+ {
+ // Red color for a zone with bathymetry conflict
+ //setFillingColor( Qt::red );
+ }
+ else
+ {
+ // Generate the filling color for zone
+ QStringList aGeomObjectsNames;
+
+ HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
+ HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Object) aRefbject =
+ Handle(HYDROData_Object)::DownCast( anIter.Value() );
+ if ( aRefbject.IsNull() )
+ continue;
+
+ QString aRefObjectName = aRefbject->GetName();
+ if ( aRefObjectName.isEmpty() )
+ continue;
+
+ aGeomObjectsNames.append( aRefObjectName );
+ }
+
+ //setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
+ }
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
+ {
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
+ {
+ Handle(HYDROData_Profile) aProfile =
+ Handle(HYDROData_Profile)::DownCast( anObject );
+
+ TopoDS_Wire aProfileWire;
+
+ if ( aProfile->IsValid() ) {
+ TopoDS_Shape aProfileShape = aProfile->GetShape3D();
+
+ if ( !aProfileShape.IsNull() &&
+ aProfileShape.ShapeType() == TopAbs_WIRE ) {
+ aProfileWire = TopoDS::Wire( aProfileShape );
+ }
+ }
+
+ setWire( aProfileWire, false, false );
+
+ QColor aWireColor = aProfile->GetBorderColor();
+ //setBorderColor( aWireColor, false, false );
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
+ anObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
+ anObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
+ {
+ Handle(HYDROData_Object) aGeomObject =
+ Handle(HYDROData_Object)::DownCast( anObject );
+
+ TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
+
+ setShape( anObjShape, false, false );
+
+ QColor aFillingColor = aGeomObject->GetFillingColor();
+ QColor aBorderColor = aGeomObject->GetBorderColor();
+
+ //setFillingColor( aFillingColor, false, false );
+ //setBorderColor( aBorderColor, false, false );
+ }
+ else if ( anObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
+ {
+ Handle(HYDROData_DummyObject3D) anObject3D =
+ Handle(HYDROData_DummyObject3D)::DownCast( anObject );
+ TopoDS_Shape aShape3D = anObject3D->GetShape();
+
+ setShape( aShape3D, false, false );
+
+ QColor aFillingColor = anObject3D->GetFillingColor();
+ QColor aBorderColor = anObject3D->GetBorderColor();
+
+ //setFillingColor( aFillingColor, false, false );
+ //setBorderColor( aBorderColor, false, false );
+ }
+ }
+}
+
+void HYDROGUI_VTKPrsShape::setWire( const TopoDS_Wire& theWire,
+ const bool theToDisplay,
+ const bool theIsUpdateViewer )
+{
+ myTopoShape = theWire;
+}
+
+void HYDROGUI_VTKPrsShape::setFaces( const TopoDS_Compound& theWires,
+ const bool theToDisplay,
+ const bool theIsUpdateViewer )
+{
+ TopExp_Explorer anExp( theWires, TopAbs_WIRE );
+ TopoDS_Compound aCompound;
+ BRep_Builder aBuilder;
+ aBuilder.MakeCompound( aCompound );
+
+ for ( ; anExp.More(); anExp.Next() ) {
+ TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
+ if ( aWire.IsNull() ) {
+ continue;
+ }
+
+ BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
+ aMakeFace.Build();
+ if( aMakeFace.IsDone() ) {
+ aBuilder.Add( aCompound, aMakeFace.Face() );
+ }
+ }
+
+ myTopoShape = aCompound;
+}
+
+void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Wire& theWire,
+ const bool theToDisplay,
+ const bool theIsUpdateViewer )
+{
+ BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
+ aFaceBuilder.Build();
+ if( aFaceBuilder.IsDone() )
+ {
+ TopoDS_Face aFace = aFaceBuilder.Face();
+ setFace( aFace, theToDisplay, theIsUpdateViewer );
+ }
+}
+
+void HYDROGUI_VTKPrsShape::setFace( const TopoDS_Face& theFace,
+ const bool theToDisplay,
+ const bool theIsUpdateViewer )
+{
+ myTopoShape = theFace;
+}
+
+void HYDROGUI_VTKPrsShape::setShape( const TopoDS_Shape& theShape,
+ const bool theToDisplay,
+ const bool theIsUpdateViewer )
+{
+ myTopoShape = theShape;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_VTK_PRS_SHAPE_H
+#define HYDROGUI_VTK_PRS_SHAPE_H
+
+#include "HYDROGUI_VTKPrs.h"
+
+#include <HYDROData_Entity.h>
+
+#include <vtkScalarsToColors.h>
+#include <vtkWeakPointer.h>
+#include <vtkNew.h>
+#include <vtkPolyDataMapper.h>
+
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Compound.hxx>
+
+#include <QColor>
+#include <QString>
+
+class TopoDS_Shape;
+
+/*
+ Class : HYDROGUI_VTKPrsShape
+ Description : Presentation for HYDRO object on the base of OCC shape
+*/
+class HYDROGUI_VTKPrsShape : public HYDROGUI_VTKPrs
+{
+public:
+ HYDROGUI_VTKPrsShape( const Handle(HYDROData_Entity)& theObject );
+ virtual ~HYDROGUI_VTKPrsShape();
+
+ virtual void compute();
+
+ //! Get the range of colored
+ void setLookupTable( vtkScalarsToColors* theTable ) { myLookupTable = theTable; }
+
+protected:
+ virtual vtkMapper* mapper() { return myMapper.GetPointer(); }
+
+ void buildShape();
+
+ virtual void setWire( const TopoDS_Wire& theWire,
+ const bool theToDisplay = true,
+ const bool theIsUpdateViewer = true );
+
+ virtual void setFaces( const TopoDS_Compound& theWires,
+ const bool theToDisplay = true,
+ const bool theIsUpdateViewer = true );
+
+ virtual void setFace( const TopoDS_Wire& theWire,
+ const bool theToDisplay = true,
+ const bool theIsUpdateViewer = true );
+
+ virtual void setFace( const TopoDS_Face& theFace,
+ const bool theToDisplay = true,
+ const bool theIsUpdateViewer = true );
+
+ virtual void setShape( const TopoDS_Shape& theShape,
+ const bool theToDisplay = true,
+ const bool theIsUpdateViewer = true );
+private:
+ vtkWeakPointer< vtkScalarsToColors > myLookupTable;
+ vtkNew< vtkPolyDataMapper > myMapper;
+ TopoDS_Shape myTopoShape;
+};
+
+#endif