]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Bugs #113, 114: use polylines with several section and immersible zones made of such...
authormzn <mzn@opencascade.com>
Thu, 21 Nov 2013 15:48:23 +0000 (15:48 +0000)
committermzn <mzn@opencascade.com>
Thu, 21 Nov 2013 15:48:23 +0000 (15:48 +0000)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_ImmersibleZone.cxx
src/HYDROData/HYDROData_Polyline.cxx
src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx
src/HYDROGUI/HYDROGUI_ImmersibleZoneOp.cxx
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Shape.h

index 5259902971421651ee788c1b7b4e239a06091a21..4a75528ca44800db58791a6f757aa3f61d79b865 100644 (file)
@@ -16,6 +16,9 @@
 #include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_Sewing.hxx>
 #include <TopExp_Explorer.hxx>
+#include <TopExp.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 #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;
index f113ba31b684b1512de9bd3e4470ed08935b0f8d..05a468239cb007a32774d55c2f1cb83ba5eb5df1 100644 (file)
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Wire.hxx>
+#include <TopoDS_Compound.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <BRep_Builder.hxx>
 
 #include <QColor>
 #include <QStringList>
@@ -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
index 8e6b3d766f00ac112d036f6670709b591bf367bc..c88500016d63b6b7988316f23ba52ef6bbdd3042 100755 (executable)
@@ -23,6 +23,8 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 #include <QStringList>
 
@@ -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 );
 }
index f978dccdbd4fec410eec91998e7f43f9e6ae1d8b..6344eddd19da49c5dd25dd4c461ee7edf77fab56 100644 (file)
@@ -29,6 +29,7 @@
 #include <HYDROData_CalculationCase.h>
 
 #include <GeometryGUI.h>
+#include <GEOMBase.h>
 
 #include <SalomeApp_Study.h>
 
@@ -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 = 
index d9b072d483421f393add5bcd93ba418936ed2dd2..ecf6b2836e40ca5ef1e841bbde1ffe0f7c62fef8 100644 (file)
@@ -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()
index 1491564fe1004bf8c4d78b6bf53b5bc0a4fec4e2..534a57ce1135b1a831cefcebb6031ec62cf4d895 100644 (file)
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
 
+#include <TopExp_Explorer.hxx>
+
+#include <BRep_Builder.hxx>
+
 #include <Precision.hxx>
 
 #include <Prs3d_ShadingAspect.hxx>
@@ -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 )
index 84880112996aaa2e41e5b649475e8b043b53c953..31966461ae710c1d07aec6cb4955f9acffe6eb62 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Wire.hxx>
+#include <TopoDS_Compound.hxx>
 
 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 );