]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
TShell cannot be disconnected; use TCompound of shells/faces instead
authorisn <isn@opencascade.com>
Fri, 13 Nov 2015 08:48:13 +0000 (11:48 +0300)
committerisn <isn@opencascade.com>
Fri, 13 Nov 2015 09:17:14 +0000 (12:17 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx
src/HYDRO_tests/TestViewer.cxx
src/HYDRO_tests/TestViewer.h
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx

index 4af5467315e35e18a282f6a6025beadcdbbc1a74..969ce6d077423bc7f159fe8fedc31d29dfa19c82 100644 (file)
@@ -48,6 +48,8 @@
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <ShapeBuild_ReShape.hxx>
 #include <ShapeFix_Shape.hxx>
+#include <BRepCheck_Shell.hxx>
+#include <BRepCheck_ListOfStatus.hxx>
 
 
 #include <QFile>
@@ -65,16 +67,16 @@ IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
   Constructor
   @param theMap the land cover map to iterate through
 */
-HYDROData_LandCoverMap::Iterator::Iterator( const HYDROData_LandCoverMap& theMap )
+HYDROData_LandCoverMap::Explorer::Explorer( const HYDROData_LandCoverMap& theMap )
 {
   Init( theMap );
 }
 
-HYDROData_LandCoverMap::Iterator::Iterator( const Handle( HYDROData_LandCoverMap )& theMap )
+HYDROData_LandCoverMap::Explorer::Explorer( const Handle( HYDROData_LandCoverMap )& theMap )
 {
   if( theMap.IsNull() )
   {
-    myIterator = 0;
+    myExplorer = 0;
     myIndex = -1;
   }
   else
@@ -85,13 +87,16 @@ HYDROData_LandCoverMap::Iterator::Iterator( const Handle( HYDROData_LandCoverMap
   Initialize the iterator
   @param theMap the land cover map to iterate through
 */
-void HYDROData_LandCoverMap::Iterator::Init( const HYDROData_LandCoverMap& theMap )
+void HYDROData_LandCoverMap::Explorer::Init( const HYDROData_LandCoverMap& theMap )
 {
   TopoDS_Shape aShape = theMap.GetShape();
   if( aShape.IsNull() )
-    myIterator = 0;
+    myExplorer = 0;
   else
-    myIterator = new TopoDS_Iterator( aShape );
+  {
+    myExplorer = new TopExp_Explorer();
+    myExplorer->Init( aShape, TopAbs_FACE );
+  }
   
   theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
   if( myArray.IsNull() )
@@ -103,16 +108,16 @@ void HYDROData_LandCoverMap::Iterator::Init( const HYDROData_LandCoverMap& theMa
 /**
   Destructor
 */
-HYDROData_LandCoverMap::Iterator::~Iterator()
+HYDROData_LandCoverMap::Explorer::~Explorer()
 {
-  delete myIterator;
+  delete myExplorer;
 }
 
 /**
   Return the current 0-based index of the iterator
   @return the current index
 */
-int HYDROData_LandCoverMap::Iterator::Index() const
+int HYDROData_LandCoverMap::Explorer::Index() const
 {
   if( myArray.IsNull() )
     return -1;
@@ -124,19 +129,19 @@ int HYDROData_LandCoverMap::Iterator::Index() const
   Return if the iterator has more elements
   @return if the iterator has more elements
 */
-bool HYDROData_LandCoverMap::Iterator::More() const
+bool HYDROData_LandCoverMap::Explorer::More() const
 {
-  return !myArray.IsNull() && myIterator && myIterator->More();
+  return !myArray.IsNull() && myExplorer && myExplorer->More();
 }
 
 /**
   Move iterator to the next element
 */
-void HYDROData_LandCoverMap::Iterator::Next()
+void HYDROData_LandCoverMap::Explorer::Next()
 {
-  if( myIterator )
+  if( myExplorer )
   {
-    myIterator->Next();
+    myExplorer->Next();
     myIndex++;
   }
 }
@@ -145,10 +150,10 @@ void HYDROData_LandCoverMap::Iterator::Next()
   Get the current land cover (face)
   @return the land cover's face
 */
-TopoDS_Face HYDROData_LandCoverMap::Iterator::Face() const
+TopoDS_Face HYDROData_LandCoverMap::Explorer::Face() const
 {
-  if( myIterator )
-    return TopoDS::Face( myIterator->Value() );
+  if( myExplorer )
+    return TopoDS::Face( myExplorer->Current() );
   else
     return TopoDS_Face();
 }
@@ -157,7 +162,7 @@ TopoDS_Face HYDROData_LandCoverMap::Iterator::Face() const
   Get the current land cover's Strickler type 
   @return the land cover's Strickler type 
 */
-QString HYDROData_LandCoverMap::Iterator::StricklerType() const
+QString HYDROData_LandCoverMap::Explorer::StricklerType() const
 {
   if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
     return "";
@@ -169,7 +174,7 @@ QString HYDROData_LandCoverMap::Iterator::StricklerType() const
   Set the Strickler type for the current land cover
   @param theType the Strickler type
 */
-void HYDROData_LandCoverMap::Iterator::SetStricklerType( const QString& theType )
+void HYDROData_LandCoverMap::Explorer::SetStricklerType( const QString& theType )
 {
   if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
     return;
@@ -203,7 +208,7 @@ const ObjectKind HYDROData_LandCoverMap::GetKind() const
 
 int HYDROData_LandCoverMap::GetLCCount() const
 {
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   int i = 0;
   for( ; anIt.More(); anIt.Next() )
     i++;
@@ -212,7 +217,7 @@ int HYDROData_LandCoverMap::GetLCCount() const
 
 bool HYDROData_LandCoverMap::IsEmpty() const
 {
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   if ( !anIt.More() )
     return true;
   else
@@ -244,7 +249,7 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri
   aDBFImporter.DBF_GetAttributeList(FieldNameIndex, theAttrV ); 
 
   bool allOK = true;
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
   {
     int CurIndex = anIt.Index();
@@ -274,7 +279,7 @@ void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName,
     return;
   HYDROData_ShapeFile anExporter; 
   std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
   {
     QString CurST = anIt.StricklerType();
@@ -510,7 +515,7 @@ bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemov
       aFacesToRemove.Add( TopoDS::Face( aShape ), "" );
   }
 
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
     if( !aFacesToRemove.Contains( anIt.Face() ) )
       aNewFaces.Add( anIt.Face(), anIt.StricklerType() );
@@ -646,8 +651,18 @@ TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& the
   for( ; anExplorer.More(); anExplorer.Next(), n++ ) 
     anOneFace = TopoDS::Face( anExplorer.Current() );
 
-  if( n == 1 )
+  if (n == 1)
     aResult = anOneFace;
+  else if (aResult.ShapeType() == TopAbs_SHELL)
+  {
+    BRepCheck_Shell aBCS(TopoDS::Shell(aResult));
+    if (aBCS.Status().First() != BRepCheck_NoError)
+    {
+      ShapeFix_Shell aFixer;
+      aFixer.FixFaceOrientation(TopoDS::Shell(aResult), 1);
+      aResult = aFixer.Shape();
+    }
+  }
 
   return aResult;
 }
@@ -670,7 +685,7 @@ bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, c
   }
 
   int aNbChanges = 0;
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
     if( aFacesToChangeType.Contains( anIt.Face() ) )
     {
@@ -700,7 +715,7 @@ QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover )
 {
   QString aType = "";
 
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
     if( anIt.Face().IsEqual( theLandCover) )
     {
@@ -736,7 +751,7 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co
   HYDROData_MapOfFaceToStricklerType aNewFaces;
 
   // add faces to shapes list
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
     aShapesList.Append( anIt.Face() );
   aShapesList.Append( theNewShape );
@@ -841,12 +856,12 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
   TopoDS_Shape aResult;
   if( aListOfFaces.Extent() == 1 )
   {
-    TopoDS_Shell aShell;
+    /*TopoDS_Shell aShell;
     BRep_Builder aShellBuilder;
     aShellBuilder.MakeShell( aShell );
     aShell.Closed( Standard_False );
-    aShellBuilder.Add( aShell, aListOfFaces.First() );
-    aResult = aShell;
+    aShellBuilder.Add( aShell, aListOfFaces.First() );*/
+    aResult = aListOfFaces.First(); //aShell;
   }
   else if( aListOfFaces.Extent() > 1 )
     aResult = MergeFaces( aListOfFaces, false );
@@ -865,7 +880,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
 TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
 {
   //TODO: some more optimal algorithm
-  Iterator anIt( *this );
+  Explorer anIt( *this );
   for( ; anIt.More(); anIt.Next() )
     if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
     {
index a4c44ab683878facba88b6d74574a39c5d089b43..e4a54b875ec89501be4a72ee36caf22658d2a41d 100644 (file)
@@ -24,6 +24,7 @@
 #include <NCollection_IndexedDataMap.hxx>
 #include <QString>
 #include <TopoDS_Face.hxx>
+#include <TopExp_Explorer.hxx>
 
 typedef NCollection_IndexedDataMap<TopoDS_Face, QString> HYDROData_MapOfFaceToStricklerType;
 
@@ -50,12 +51,12 @@ protected:
   };
 
 public:
-  class Iterator
+  class Explorer
   {
   public:
-    Iterator( const HYDROData_LandCoverMap& );
-    HYDRODATA_EXPORT Iterator( const Handle( HYDROData_LandCoverMap )& );
-    HYDRODATA_EXPORT ~Iterator();
+    Explorer( const HYDROData_LandCoverMap& );
+    HYDRODATA_EXPORT Explorer( const Handle( HYDROData_LandCoverMap )& );
+    HYDRODATA_EXPORT ~Explorer();
 
     void Init( const HYDROData_LandCoverMap& );
     HYDRODATA_EXPORT bool More() const;
@@ -67,7 +68,7 @@ public:
     void SetStricklerType( const QString& );
 
   private:
-    TopoDS_Iterator* myIterator;
+    TopExp_Explorer* myExplorer;
     int              myIndex;
     Handle(TDataStd_ExtStringArray) myArray;
   };
@@ -138,7 +139,7 @@ public:
   DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );
 
 private:
-  friend class Iterator;
+  friend class Explorer;
   friend class test_HYDROData_LandCoverMap;
 };
 
index 629de51bf30d10a74d5862d00f1cf350bd0a7421..b6a4e737c336a6bff237188c8653a794f6831e70 100644 (file)
@@ -101,7 +101,7 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
   if ( !aLCM.IsNull() && !aLCM->IsEmpty())
   {
     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
-    HYDROData_LandCoverMap::Iterator It( aLCM );
+    HYDROData_LandCoverMap::Explorer It( aLCM );
     for( ; It.More(); It.Next() )
     {
       TopoDS_Face aFace = It.Face();
index 5e8a17f696910f1d83e181a2a12360e4faae775a..51c128188ebd474d5ec0a8a45787c6ef4d060510 100644 (file)
@@ -61,7 +61,7 @@ void HYDROGUI_LandCoverMapPrs::UpdateColors()
 {
   Set( myLCMap->GetShape() );
   SetMaterial( Graphic3d_NOM_PLASTIC );
-  HYDROData_LandCoverMap::Iterator anIt( myLCMap );
+  HYDROData_LandCoverMap::Explorer anIt( myLCMap );
   for( ; anIt.More(); anIt.Next() )
   {
     TopoDS_Face aFace = anIt.Face();
index fd031b6d4e69a84472e978e1bfa219dd391d6953..3fd331eb3acf1248a279171595fe1a8c6bd4aa2c 100644 (file)
@@ -42,6 +42,8 @@
 #include <QDir>
 #include <QPainter>
 #include <QHash>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
 
 #ifdef WIN32
   #pragma warning ( default: 4251 )
@@ -166,15 +168,15 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll,
   if( theShape.IsNull() )
     return;
 
-  int i = 0;
-  if( theShape.ShapeType()==TopAbs_SHELL )
+  if( theShape.ShapeType()==TopAbs_COMPOUND )
   {
-    TopoDS_Iterator anIt( theShape );
-    for( ; anIt.More(); anIt.Next(), i++ )
-      show( anIt.Value(), theMode, false, GetColor(i) );
+    TopExp_Explorer anExplorer( theShape, TopAbs_FACE );
+    for( ; anExplorer.More(); anExplorer.Next() ) 
+      ShowShape (anExplorer.Current(), theMode);
   }
   else
-    show( theShape, theMode, false, GetColor(0) );
+    ShowShape(theShape, theMode);
+
 
   if( isFitAll )
   {
@@ -183,6 +185,22 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll,
   }
 }
 
+void TestViewer::ShowShape(const TopoDS_Shape& theShape, int theMode)
+{
+  int i = 0;
+  if( theShape.ShapeType()==TopAbs_SHELL )
+  {
+    TopoDS_Iterator anIt( theShape );
+    for( ; anIt.More(); anIt.Next(), i++ )
+      show( anIt.Value(), theMode, false, GetColor(i) );
+  }
+  else if (theShape.ShapeType()==TopAbs_FACE ||
+           theShape.ShapeType()==TopAbs_WIRE ||
+           theShape.ShapeType()==TopAbs_EDGE ||
+           theShape.ShapeType()==TopAbs_VERTEX )
+    show( theShape, theMode, false, GetColor(0) );
+}
+
 bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double theTolerance )
 {
   if( theImage1.isNull() || theImage2.isNull() )
index c7be51fb9439f8fbf7d05c6342194005763bd1b6..8d07958e190879078762c4bd0acf0df470436dd1 100644 (file)
@@ -38,6 +38,7 @@ public:
                     int theMode, int theSelectionMode, bool isFitAll, const char* theKey );
   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor );
   static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey );
+  static void ShowShape(const TopoDS_Shape& theShape, int theMode);
   static bool AssertImages( QString& theMessage );
   static QColor GetColor(int i);
 
index 60b21ae904dc1e0b9449df83a50d0dabd325aac8..d4da4adba918cdfee33a94e49c709524dd6b132d 100644 (file)
@@ -64,7 +64,7 @@ void test_HYDROData_LandCoverMap::test_add_2_objects()
   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
   CPPUNIT_ASSERT_IMAGES
 
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
   anIt.Next();
@@ -99,7 +99,7 @@ void test_HYDROData_LandCoverMap::test_split()
   TestViewer::show( aWire, 0, true, Qt::blue );
   CPPUNIT_ASSERT_IMAGES
 
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
   anIt.Next();
@@ -134,7 +134,7 @@ void test_HYDROData_LandCoverMap::test_incomplete_split()
   TestViewer::show( aWire, 0, true, Qt::green );
   CPPUNIT_ASSERT_IMAGES
 
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
   anIt.Next();
@@ -448,7 +448,7 @@ void test_HYDROData_LandCoverMap::test_import_dbf()
   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
   QList<int> Inds = QList<int>() << 1 << 2 << 3;
   aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
  
   CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() );
   anIt.Next();