From: isn Date: Fri, 13 Nov 2015 08:48:13 +0000 (+0300) Subject: TShell cannot be disconnected; use TCompound of shells/faces instead X-Git-Tag: v1.5~44^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=670039d7a5d25b1da51956b668f212756d31a86e;p=modules%2Fhydro.git TShell cannot be disconnected; use TCompound of shells/faces instead --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 4af54673..969ce6d0 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include @@ -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 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 ) { diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index a4c44ab6..e4a54b87 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -24,6 +24,7 @@ #include #include #include +#include typedef NCollection_IndexedDataMap 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; }; diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 629de51b..b6a4e737 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -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(); diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index 5e8a17f6..51c12818 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -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(); diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index fd031b6d..3fd331eb 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -42,6 +42,8 @@ #include #include #include +#include +#include #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() ) diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index c7be51fb..8d07958e 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -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); diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 60b21ae9..d4da4adb 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -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 Inds = QList() << 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();