From 90d1e986c0e567fe8892f11e0532ec6cf40a5b8b Mon Sep 17 00:00:00 2001 From: mzn Date: Thu, 21 Nov 2013 15:48:23 +0000 Subject: [PATCH] Bugs #113, 114: use polylines with several section and immersible zones made of such polylines. --- src/HYDROData/HYDROData_CalculationCase.cxx | 37 ++++++++- src/HYDROData/HYDROData_ImmersibleZone.cxx | 52 +++++++++++-- src/HYDROData/HYDROData_Polyline.cxx | 21 +++++- src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx | 3 +- src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx | 15 +++- src/HYDROGUI/HYDROGUI_Shape.cxx | 75 ++++++++++++++++++- src/HYDROGUI/HYDROGUI_Shape.h | 9 +++ 7 files changed, 196 insertions(+), 16 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 52599029..4a75528c 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #define CALCULATION_REGIONS_PREF GetName() + "_Reg" #define CALCULATION_ZONES_PREF GetName() + "_Zone" @@ -375,6 +378,8 @@ TopoDS_Shell HYDROData_CalculationCase::GetShell() { TopoDS_Shell aShell; + TopTools_ListOfShape aFacesList; + // Make shell containing all region shapes BRepBuilderAPI_Sewing aSewing( Precision::Confusion()*10.0 ); @@ -389,7 +394,21 @@ TopoDS_Shell HYDROData_CalculationCase::GetShell() TopoDS_Shape aRegionShape = aRegion->GetShape(); if( !aRegionShape.IsNull() ) { - aSewing.Add( aRegionShape ); + TopExp_Explorer anExp( aRegionShape, TopAbs_FACE ); + if ( anExp.More() ) { + for ( ; anExp.More(); anExp.Next() ) { + TopoDS_Face aFace = TopoDS::Face( anExp.Current() ); + if ( !aFace.IsNull() ) { + aFacesList.Append( aFace ); + aSewing.Add( aFace ); + } + } + } else { + if ( aRegionShape.ShapeType() == TopAbs_FACE ) { + aFacesList.Append( aRegionShape ); + } + aSewing.Add( aRegionShape ); + } } } // regions iterator @@ -424,6 +443,22 @@ TopoDS_Shell HYDROData_CalculationCase::GetShell() } } + if ( !aShell.IsNull() ) { + TopTools_IndexedMapOfShape aMapOfFaces; + TopExp::MapShapes( aShell, TopAbs_FACE, aMapOfFaces ); + if ( aMapOfFaces.Extent() != aFacesList.Extent() ) { + aShell.Nullify(); + BRep_Builder aBuilder; + aBuilder.MakeShell( aShell ); + + TopTools_ListIteratorOfListOfShape anIter( aFacesList ); + for ( ; anIter.More(); anIter.Next() ) { + TopoDS_Face aFace = TopoDS::Face( anIter.Value() ); + aBuilder.Add( aShell, aFace ); + } + } + } + /* TODO: old version // Make shell BRep_Builder aBuilder; diff --git a/src/HYDROData/HYDROData_ImmersibleZone.cxx b/src/HYDROData/HYDROData_ImmersibleZone.cxx index f113ba31..05a46823 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.cxx +++ b/src/HYDROData/HYDROData_ImmersibleZone.cxx @@ -10,6 +10,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -71,19 +75,53 @@ QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTrea TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const { + TopoDS_Shape aResShape = TopoDS_Face(); + Handle(HYDROData_Polyline) aPolyline = GetPolyline(); if( !aPolyline.IsNull() ) { - TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() ); - if( !aPolylineWire.IsNull() ) - { - BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True ); + TopoDS_Shape aPolylineShape = aPolyline->GetTopShape(); + TopTools_ListOfShape aWiresList; + + TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE ); + if ( !anExp.More() ) { + TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape ); + if ( !aPolylineWire.IsNull() ) { + BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) { + return aMakeFace.Face(); + } + } + } else { + for ( ; anExp.More(); anExp.Next() ) { + TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() ); + aWiresList.Append( aWire ); + } + } + + TopoDS_Compound aCompound; + BRep_Builder aBuilder; + aBuilder.MakeCompound( aCompound ); + + TopTools_ListIteratorOfListOfShape anIter( aWiresList ); + for ( ; anIter.More(); anIter.Next() ) { + TopoDS_Wire aWire = TopoDS::Wire( anIter.Value() ); + if ( aWire.IsNull() ) { + continue; + } + + BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True ); aMakeFace.Build(); - if( aMakeFace.IsDone() ) - return aMakeFace.Face(); + if( aMakeFace.IsDone() ) { + aBuilder.Add( aCompound, aMakeFace.Face() ); + } } + + aResShape = aCompound; } - return TopoDS_Face(); + + return aResShape; } TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const diff --git a/src/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx index 8e6b3d76..c8850001 100755 --- a/src/HYDROData/HYDROData_Polyline.cxx +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -397,6 +399,8 @@ void HYDROData_Polyline::UpdateWire( const PolylineData& theSections ) double aZValue = ZValue(); + TopTools_ListOfShape aSectionWiresList; + int aSectionCount = theSections.size(); for( int aSectionId = 0; aSectionId < aSectionCount; aSectionId++ ) { @@ -444,10 +448,25 @@ void HYDROData_Polyline::UpdateWire( const PolylineData& theSections ) aMakeSectionWire.Add( anEdge ); } TopoDS_Wire aSectionWire = aMakeSectionWire.Wire(); + aSectionWiresList.Append( aSectionWire ); aMakeWire.Add( aSectionWire ); } } - TopoDS_Shape aShape = aMakeWire.Shape(); + TopoDS_Shape aShape; + if ( aMakeWire.IsDone() ) { + aShape = aMakeWire.Shape(); + } else { + // build compound + TopoDS_Compound aCompound; + BRep_Builder aBuilder; + aBuilder.MakeCompound( aCompound ); + TopTools_ListIteratorOfListOfShape anIter( aSectionWiresList ); + for ( ; anIter.More(); anIter.Next() ) { + aBuilder.Add( aCompound, anIter.Value() ); + } + aShape = aCompound; + } + SetTopShape( aShape ); } diff --git a/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx b/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx index f978dccd..6344eddd 100644 --- a/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx @@ -29,6 +29,7 @@ #include #include +#include #include @@ -113,7 +114,7 @@ bool HYDROGUI_ExportCalculationOp::processApply( int& theUpdateFlags, // Puplish the GEOM object if ( !aGeomObj->_is_nil() ) { - QString aName = tr( "OBJ_PREFIX" ) + aCalculation->GetName(); + QString aName = GEOMBase::GetDefaultName( tr( "OBJ_PREFIX" ) + aCalculation->GetName() ); SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() ); SALOMEDS::SObject_var aResultSO = diff --git a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx index d9b072d4..ecf6b283 100644 --- a/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx @@ -239,12 +239,16 @@ void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName return; TopoDS_Wire aWire; + TopoDS_Shape aShape; Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINE ) ); if ( !aPolyline.IsNull() ) { - aWire = TopoDS::Wire( aPolyline->GetTopShape() ); + aShape = aPolyline->GetTopShape(); + if ( aShape.ShapeType() == TopAbs_WIRE ) { + aWire = TopoDS::Wire( aShape ); + } } LightApp_Application* anApp = module()->getApp(); @@ -274,7 +278,14 @@ void HYDROGUI_ImmersibleZoneOp::onCreatePreview( const QString& thePolylineName myPreviewPrs->setFillingColor( aFillingColor, false, false ); myPreviewPrs->setBorderColor( aBorderColor, false, false ); - myPreviewPrs->setFace( aWire ); + if ( !aWire.IsNull() ) { + myPreviewPrs->setFace( aWire ); + } else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND ) { + TopoDS_Compound aCompound = TopoDS::Compound( aShape ); + if ( !aCompound.IsNull() ) { + myPreviewPrs->setFaces( aCompound ); + } + } } void HYDROGUI_ImmersibleZoneOp::closePreview() diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 1491564f..534a57ce 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -49,6 +49,10 @@ #include #include +#include + +#include + #include #include @@ -115,22 +119,45 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) Handle(HYDROData_ImmersibleZone) aZoneObj = Handle(HYDROData_ImmersibleZone)::DownCast( myObject ); + 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; + myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2; + + buildShape(); + updateShape( false, false ); + } + } + QColor aFillingColor = aZoneObj->GetFillingColor(); QColor aBorderColor = aZoneObj->GetBorderColor(); - TopoDS_Face aZoneFace = TopoDS::Face( aZoneObj->GetTopShape() ); setFillingColor( aFillingColor, false, false ); setBorderColor( aBorderColor, false, false ); - setFace( aZoneFace, false, false ); } else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline) ) ) { Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( myObject ); - TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() ); + TopoDS_Shape aPolylineShape = aPolyline->GetTopShape(); + + if ( !aPolylineShape.IsNull() ) { + if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) { + TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape ); + setWire( aPolylineWire, false, false ); + } else { + myTopoShape = aPolylineShape; + myDisplayMode = AIS_WireFrame; - setWire( aPolylineWire, false, false ); + buildShape(); + updateShape( false, false ); + } + } } else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) ) { @@ -295,6 +322,35 @@ void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire, updateShape( theToDisplay, theIsUpdateViewer ); } +void HYDROGUI_Shape::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; + myDisplayMode = AIS_Shaded; + + buildShape(); + updateShape( theToDisplay, theIsUpdateViewer ); +} + void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire, const bool theToDisplay, const bool theIsUpdateViewer ) @@ -321,6 +377,17 @@ void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace, updateShape( theToDisplay, theIsUpdateViewer ); } +void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape, + const bool theToDisplay, + const bool theIsUpdateViewer ) +{ + myTopoShape = theShape; + myDisplayMode = AIS_Shaded; + + buildShape(); + updateShape( theToDisplay, theIsUpdateViewer ); +} + void HYDROGUI_Shape::setFillingColor( const QColor& theColor, const bool theToDisplay, const bool theIsUpdateViewer ) diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 84880112..31966461 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -33,6 +33,7 @@ #include #include +#include class HYDROGUI_Shape { @@ -63,6 +64,10 @@ public: 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 ); @@ -71,6 +76,10 @@ public: const bool theToDisplay = true, const bool theIsUpdateViewer = true ); + virtual void setShape( const TopoDS_Shape& theShape, + const bool theToDisplay = true, + const bool theIsUpdateViewer = true ); + virtual void setFillingColor( const QColor& theColor, const bool theToDisplay = true, const bool theIsUpdateViewer = true ); -- 2.39.2