From 4af9b740c7c9dcb353e1f2508a90fb070753de5e Mon Sep 17 00:00:00 2001 From: isn Date: Fri, 21 Oct 2016 18:27:57 +0300 Subject: [PATCH] export of calc case -- groups def. --- src/HYDROData/HYDROData_CalculationCase.cxx | 66 ++++--- src/HYDROData/HYDROData_Entity.cxx | 19 ++ src/HYDROData/HYDROData_Entity.h | 4 + src/HYDROData/HYDROData_GeomTool.cxx | 10 +- src/HYDROData/HYDROData_Region.cxx | 177 ++++++++++++------- src/HYDROData/HYDROData_Region.h | 3 +- src/HYDROData/HYDROData_ShapesGroup.cxx | 39 ++++ src/HYDROData/HYDROData_ShapesGroup.h | 5 + src/HYDROData/HYDROData_SplitShapesGroup.cxx | 9 + src/HYDROData/HYDROData_SplitShapesGroup.h | 6 +- src/HYDROData/HYDROData_SplitToZonesTool.cxx | 135 ++++++++++++-- src/HYDROData/HYDROData_SplitToZonesTool.h | 19 +- src/HYDRO_tests/test_HYDROData_CalcCase.cxx | 10 +- 13 files changed, 390 insertions(+), 112 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 9323fe6c..610e96a1 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -303,7 +303,8 @@ void HYDROData_CalculationCase::Update() const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next(); if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone ) aZonesList.append( aSplitData ); - else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ) + else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge || + aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge) anEdgesList.append( aSplitData ); } } @@ -460,6 +461,12 @@ void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Docu continue; aSplitGroup->AddShape( aSplitData.Shape ); + + TopTools_SequenceOfShape theShapes; + aSplitGroup->GetShapes(theShapes); + + if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge) + aSplitGroup->SetInternal(true); } } @@ -1055,6 +1062,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine, // Get groups definitions HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups(); + TopTools_SequenceOfShape IntSh; //internal edges HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups ); for ( ; anIter.More(); anIter.Next() ) { @@ -1070,6 +1078,16 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine, aGroup->GetShapes( aGroupDef.Shapes ); aSeqOfGroupsDefs.Append( aGroupDef ); + + Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() ); + TopTools_SequenceOfShape dummy; + if (!aSSGroup.IsNull()) + if (aSSGroup->GetInternal()) + { + aSSGroup->GetShapes(dummy); + IntSh.Append(dummy); + } + } // Get faces @@ -1087,7 +1105,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine, if ( isAllNotSubmersible ) isAllNotSubmersible = false; - TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs ); + TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh ); aShToNames.Add( aRegionShape, aRegion->GetName() ); } @@ -1122,33 +1140,32 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var TCollection_AsciiString aNam("Sh_"); int i=1; #endif + TopTools_DataMapOfShapeListOfShape SH2M; for ( int i = 1; i <= aShToName.Extent(); i++ ) { const TopoDS_Shape& aShape = aShToName.FindKey(i); if ( aShape.IsNull() ) continue; - - if ( aShape.ShapeType() == TopAbs_FACE ) + + SH2M.Bind(aShape, TopTools_ListOfShape()); + TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape); + if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL ) { aSewing.Add( aShape ); -#ifdef DEB_CALCULATION - TCollection_AsciiString aName = aNam + ++i + ".brep"; - BRepTools::Write(aShape ,aName.ToCString()); -#endif + LM.Append(aShape); } - else + else if (aShape.ShapeType() == TopAbs_COMPOUND) { -#ifdef DEB_CALCULATION - int j = 1; -#endif - TopExp_Explorer anExp( aShape, TopAbs_FACE ); - for (; anExp.More(); anExp.Next() ) { + TopExp_Explorer anExp( aShape, TopAbs_SHELL ); + for (; anExp.More(); anExp.Next() ) + { aSewing.Add( anExp.Current() ); -#ifdef DEB_CALCULATION - - TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep"; - BRepTools::Write(anExp.Current() ,aName.ToCString()); -#endif + LM.Append(anExp.Current()); + } + anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL ); + { + aSewing.Add( anExp.Current() ); + LM.Append(anExp.Current()); } } } // faces iterator @@ -1162,13 +1179,14 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var { const TopoDS_Shape& CurShape = aShToName.FindKey(i); const QString& Qstr = aShToName.FindFromIndex(i); - for (TopExp_Explorer Exp(CurShape, TopAbs_FACE); Exp.More(); Exp.Next()) + const TopTools_ListOfShape& LM = SH2M(CurShape); + for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next()) { - const TopoDS_Face& cf = TopoDS::Face(Exp.Current()); - if (aSewing.IsModified(cf)) - aFacesToNameModif.Add(aSewing.Modified(cf), Qstr); + const TopoDS_Shape& csh = it.Value(); + if (aSewing.IsModified(csh)) + aFacesToNameModif.Add(aSewing.Modified(csh), Qstr); else - aFacesToNameModif.Add(cf, Qstr); + aFacesToNameModif.Add(csh, Qstr); } } diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index 8d4c2afb..5a055f78 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -822,3 +822,22 @@ double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const return anAttr->Get(); } + +void HYDROData_Entity::SetInteger( int theTag, int theValue ) +{ + Handle(TDataStd_Integer) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) ) + aLabel.AddAttribute( anAttr = new TDataStd_Integer() ); + anAttr->Set( theValue ); +} + +int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const +{ + Handle(TDataStd_Integer) anAttr; + TDF_Label aLabel = myLab.FindChild( theTag ); + if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) ) + return 0; + + return anAttr->Get(); +} diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index a38e771d..37bdcc66 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -453,6 +453,10 @@ protected: void SetDouble( int theTag, double theValue ); double GetDouble( int theTag, double theDefValue = 0.0 ) const; + void SetInteger( int theTag, int theValue ); + int GetInteger( int theTag, int theDefValue = 0 ) const; + + int GetGeomChangeFlag() const; protected: diff --git a/src/HYDROData/HYDROData_GeomTool.cxx b/src/HYDROData/HYDROData_GeomTool.cxx index 45add501..3d54e13f 100644 --- a/src/HYDROData/HYDROData_GeomTool.cxx +++ b/src/HYDROData/HYDROData_GeomTool.cxx @@ -175,6 +175,14 @@ GEOM::GEOM_Object_ptr HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( GEOM::GE TopTools_MapOfShape mapShape; + NCollection_IndexedDataMap aFF2N; + for (int i = 1; i <= aFacesToNameModif.Extent(); i++) + { + TopExp_Explorer exp (aFacesToNameModif.FindKey(i), TopAbs_FACE); + for (;exp.More(); exp.Next()) + aFF2N.Add(exp.Current(), aFacesToNameModif.FindFromIndex(i)); + } + TopExp_Explorer exp (theShape, TopAbs_FACE); QVector Names; for (; exp.More(); exp.Next()) @@ -183,7 +191,7 @@ GEOM::GEOM_Object_ptr HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( GEOM::GE if (mapShape.Add(csh)) { //listShape.Append(csh); - QString Qstr = aFacesToNameModif.FindFromKey(csh); + QString Qstr = aFF2N.FindFromKey(csh); Names.push_back(Qstr); } } diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 698cfc94..226e0e46 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -38,6 +38,7 @@ #include #include + #include #include @@ -46,6 +47,11 @@ #include #include +#include "Handle_Geom_Plane.hxx" +#include "Geom_Plane.hxx" +#include "gp_Pln.hxx" +#include "BRepTools_ReShape.hxx" + //#define DEB_GET_REGION_SHAPE IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity) @@ -239,7 +245,9 @@ void getUsedGroups( const TopoDS_Shape& theShape, } } -TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* theSeqOfGroups ) const + + +TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* theSeqOfGroups, const TopTools_SequenceOfShape* IntSh ) const { HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroups; HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfUsedGroups; @@ -260,6 +268,9 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* HYDROData_SequenceOfObjects aZones = GetZones(); HYDROData_SequenceOfObjects::Iterator aZoneIter( aZones ); + TopTools_IndexedMapOfShape AllE; + TopTools_IndexedMapOfShape IE; //int edges + for ( ; aZoneIter.More(); aZoneIter.Next() ) { Handle(HYDROData_Zone) aZone = @@ -273,19 +284,25 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape ); aRegionFacesList.Append( aZoneFace ); - + TopExp::MapShapes(aZoneFace, TopAbs_EDGE, AllE); // collect all edges getUsedGroups( aZoneFace, aSeqOfGroups, aSeqOfUsedGroups ); } // zones iterator + + for (int i = 1; i <= IntSh->Length(); i++) + { + const TopoDS_Shape& CS = (*IntSh)(i); + if (AllE.Contains(CS)) + IE.Add(CS); + } if ( aRegionFacesList.IsEmpty() ) return aResShape; - // The unite region face TopoDS_Face aRegionFace; if ( aRegionFacesList.Extent() == 1 ) { - aRegionFace = TopoDS::Face( aRegionFacesList.First() ); + aResShape = TopoDS::Face( aRegionFacesList.First() ); } else { @@ -312,6 +329,35 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* } aFuseShape = aFuse.Shape(); + + //update history of internal edges + TopTools_IndexedMapOfShape DIE; + TopTools_ListOfShape newSh1, newSh2; + for (int i = 1; i <= IE.Extent(); i++) + { + const TopoDS_Shape& CSH = IE(i); + newSh1.Clear(); + newSh2.Clear(); + newSh1 = aFuse.Modified(CSH); + if (newSh1.IsEmpty()) + { + newSh2 = aFuse.Generated(CSH); + if (newSh2.IsEmpty()) + DIE.Add(CSH); + else + for (TopTools_ListIteratorOfListOfShape lt(newSh2); lt.More(); lt.Next()) + if (!lt.Value().IsNull()) + DIE.Add(lt.Value()); + } + else + { + for (TopTools_ListIteratorOfListOfShape lt(newSh1); lt.More(); lt.Next()) + if (!lt.Value().IsNull()) + DIE.Add(lt.Value()); + } + } + IE = DIE; + //update groups HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &aFuse ); } // faces iterator @@ -319,73 +365,86 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Fused face edges:", aFuseShape, TopAbs_EDGE ); #endif - // Check the result of fuse operation - if ( !aFuseShape.IsNull() ) + BRep_Builder BB; + TopoDS_Face DF; + if (!IE.IsEmpty()) { - ShapeUpgrade_UnifySameDomain anUnifier( aFuseShape ); - anUnifier.Build(); + //add dummy face to existing shell + //this face contains all internal edges + //USD algo will skip such edges and will not perform unifying through them + //(more than 2 faces are connected to one edge + non same domain surfaces) + TopoDS_Wire DW; + Handle_Geom_Plane DPl = new Geom_Plane(gp_Pln (gp_Pnt(0,0,0), gp_Dir(0,1,0))); //non same domain with the main surf + BB.MakeFace(DF, DPl, Precision::Confusion()); + BB.MakeWire(DW); + for (int i = 1; i <= IE.Extent(); i++) + BB.Add(DW, IE(i)); + BB.Add(DF, DW); + BB.Add(aFuseShape, DF); + } - const TopoDS_Shape& anUnitedShape = anUnifier.Shape(); + ShapeUpgrade_UnifySameDomain unif( aFuseShape ); + unif.Build(); + TopoDS_Shape anUnitedShape; + const TopoDS_Shape& out = unif.Shape(); - TopTools_SequenceOfShape aShapeFaces; - HYDROData_ShapesTool::ExploreShapeToShapes( anUnitedShape, TopAbs_FACE, aShapeFaces ); - if ( aShapeFaces.Length() == 1 ) - { - aRegionFace = TopoDS::Face( aShapeFaces.Value( 1 ) ); + HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &unif ); -#ifdef DEB_GET_REGION_SHAPE - HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Result face edges:", aRegionFace, TopAbs_EDGE ); -#endif + if (!IE.IsEmpty()) + { + //remove dummy face from shell; shell becomes valid + const TopoDS_Shape& NDF = unif.Generated(DF); + BRepTools_ReShape ReShaper; + ReShaper.Remove(NDF); + anUnitedShape = ReShaper.Apply(out); + HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &ReShaper ); + } + else + anUnitedShape = out; - HYDROData_ShapesGroup::GroupDefinition::Update( &aSeqOfUsedGroups, &anUnifier ); + TopTools_SequenceOfShape aShapeFaces; + HYDROData_ShapesTool::ExploreShapeToShapes( anUnitedShape, TopAbs_FACE, aShapeFaces ); + if ( aShapeFaces.Length() == 1 ) //it should be either face or compound of faces (?) + { + const TopoDS_Face& CF = TopoDS::Face( aShapeFaces.Value( 1 )); + aResShape = CF; + } + else + { + TopTools_SequenceOfShape aShapeShells; + HYDROData_ShapesTool::ExploreShapeToShapes( anUnitedShape, TopAbs_SHELL, aShapeShells ); + if (aShapeShells.Length() == 1) + aResShape = TopoDS::Shell(aShapeShells(1)); + else + aResShape = anUnitedShape; + } - // Update the sequence of groups - if ( theSeqOfGroups ) + // Update the sequence of groups + if ( theSeqOfGroups ) + { + HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator aUsedIter( aSeqOfUsedGroups ); + for ( ; aUsedIter.More(); aUsedIter.Next() ) + { + const HYDROData_ShapesGroup::GroupDefinition& aUsedGroupDef = aUsedIter.Value(); + if ( aUsedGroupDef.Shapes.IsEmpty() ) + continue; + + HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator anOriIter( aSeqOfGroups ); + for ( ; anOriIter.More(); anOriIter.Next() ) { - HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator aUsedIter( aSeqOfUsedGroups ); - for ( ; aUsedIter.More(); aUsedIter.Next() ) - { - const HYDROData_ShapesGroup::GroupDefinition& aUsedGroupDef = aUsedIter.Value(); - if ( aUsedGroupDef.Shapes.IsEmpty() ) - continue; - - HYDROData_ShapesGroup::SeqOfGroupsDefs::Iterator anOriIter( aSeqOfGroups ); - for ( ; anOriIter.More(); anOriIter.Next() ) - { - HYDROData_ShapesGroup::GroupDefinition& anOriGroupDef = anOriIter.ChangeValue(); - if ( anOriGroupDef.Name != aUsedGroupDef.Name ) - continue; - - HYDROData_ShapesTool::AddShapes( anOriGroupDef.Shapes, aUsedGroupDef.Shapes ); - break; - } - } - - *theSeqOfGroups = aSeqOfGroups; + HYDROData_ShapesGroup::GroupDefinition& anOriGroupDef = anOriIter.ChangeValue(); + if ( anOriGroupDef.Name != aUsedGroupDef.Name ) + continue; + + HYDROData_ShapesTool::AddShapes( anOriGroupDef.Shapes, aUsedGroupDef.Shapes ); + break; } } - } - } - if ( !aRegionFace.IsNull() ) - { - // result shape is a face - aResShape = aRegionFace; + *theSeqOfGroups = aSeqOfGroups; + } } - else - { - // result shape is a shell - TopoDS_Shell aShell; - BRep_Builder aBuilder; - aBuilder.MakeShell( aShell ); - TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList ); - for ( ; aFaceIter.More(); aFaceIter.Next() ) - aBuilder.Add( aShell, aFaceIter.Value() ); - - aResShape = aShell; - } - return aResShape; } diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index 08af0ab6..bc9a7c6a 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -114,7 +114,8 @@ public: * - a shell if the zones faces can't be united into one face * \return shape as TopoDS_Shape */ - HYDRODATA_EXPORT virtual TopoDS_Shape GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* theSeqOfGroups = 0 ) const; + HYDRODATA_EXPORT virtual TopoDS_Shape GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* theSeqOfGroups = 0, + const TopTools_SequenceOfShape* IntSh = NULL ) const; HYDRODATA_EXPORT bool IsSubmersible() const; diff --git a/src/HYDROData/HYDROData_ShapesGroup.cxx b/src/HYDROData/HYDROData_ShapesGroup.cxx index 6c0d5ae0..92fd7e17 100644 --- a/src/HYDROData/HYDROData_ShapesGroup.cxx +++ b/src/HYDROData/HYDROData_ShapesGroup.cxx @@ -30,6 +30,7 @@ #include #include #include +#include IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity) @@ -113,6 +114,44 @@ void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* } } +void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs, + BRepTools_ReShape* theAlgo ) +{ + if ( !theGroupsDefs || !theAlgo ) + return; + + SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs ); + for ( ; anIter.More(); anIter.Next() ) + { + GroupDefinition& aGroupDef = anIter.ChangeValue(); + if ( aGroupDef.Shapes.IsEmpty() ) + continue; + + TopTools_ListOfShape aShapesToAdd; + for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i ) + { + TopoDS_Shape aShape = aGroupDef.Shapes.Value( i ); + + TopoDS_Shape aGeneratedByAlgo = theAlgo->Value( aShape ); + if ( aGeneratedByAlgo.IsNull() ) + { + // Edge has been removed + aGroupDef.Shapes.Remove( i ); + --i; + } + else if ( !aShape.IsEqual( aGeneratedByAlgo ) ) + { + // Edge has been modified + aShapesToAdd.Append( aGeneratedByAlgo ); + aGroupDef.Shapes.Remove( i ); + --i; + } + } + + HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd ); + } +} + void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const { theStream << "Name: " << Name.ToCString() << "\n"; diff --git a/src/HYDROData/HYDROData_ShapesGroup.h b/src/HYDROData/HYDROData_ShapesGroup.h index db2a29ea..394bf16e 100644 --- a/src/HYDROData/HYDROData_ShapesGroup.h +++ b/src/HYDROData/HYDROData_ShapesGroup.h @@ -29,6 +29,7 @@ class TopoDS_Shape; class TopTools_ListOfShape; class BRepBuilderAPI_MakeShape; class ShapeUpgrade_UnifySameDomain; +class BRepTools_ReShape; DEFINE_STANDARD_HANDLE(HYDROData_ShapesGroup, HYDROData_Entity) @@ -49,6 +50,10 @@ public: static void Update( NCollection_Sequence* theGroupsDefs, ShapeUpgrade_UnifySameDomain* theAlgo ); + static void Update( NCollection_Sequence* theGroupsDefs, + BRepTools_ReShape* theAlgo ); + + void Dump( std::ostream& theStream ) const; static void Dump( std::ostream& theStream, diff --git a/src/HYDROData/HYDROData_SplitShapesGroup.cxx b/src/HYDROData/HYDROData_SplitShapesGroup.cxx index dd50bc4e..a73b11cb 100644 --- a/src/HYDROData/HYDROData_SplitShapesGroup.cxx +++ b/src/HYDROData/HYDROData_SplitShapesGroup.cxx @@ -30,4 +30,13 @@ HYDROData_SplitShapesGroup::~HYDROData_SplitShapesGroup() { } +void HYDROData_SplitShapesGroup::SetInternal(bool flag) +{ + SetInteger(DataTag_InternalEdge, (int)flag); +} + +bool HYDROData_SplitShapesGroup::GetInternal() const +{ + return (bool)GetInteger(DataTag_InternalEdge); +} diff --git a/src/HYDROData/HYDROData_SplitShapesGroup.h b/src/HYDROData/HYDROData_SplitShapesGroup.h index 81e04ded..b6812301 100644 --- a/src/HYDROData/HYDROData_SplitShapesGroup.h +++ b/src/HYDROData/HYDROData_SplitShapesGroup.h @@ -35,7 +35,8 @@ protected: */ enum DataTag { - DataTag_First = HYDROData_ShapesGroup::DataTag_First + 100 ///< first tag, to reserve + DataTag_First = HYDROData_ShapesGroup::DataTag_First + 100, ///< first tag, to reserve + DataTag_InternalEdge }; public: @@ -46,6 +47,9 @@ public: */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_SPLIT_GROUP; } + void SetInternal(bool flag); + bool GetInternal() const; + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index e5a1d842..ddcc4070 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #include #include +#include //#define DEB_SPLIT_TO_ZONES 1 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1 @@ -138,7 +140,9 @@ HYDROData_SplitToZonesTool::SplitDataList { DEBTRACE("Split"); SplitDataList anOutputSplitDataList; - if(theObjectList.IsEmpty()) return anOutputSplitDataList; + NCollection_DataMap OutNE; + if(theObjectList.IsEmpty()) + return anOutputSplitDataList; // Preparation. // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape. SplitDataList anInputSplitDataList; @@ -214,14 +218,37 @@ HYDROData_SplitToZonesTool::SplitDataList // If only one shape is given we don't split it // algorithm just returns the unpacked input data bool limplus1Object(false); - if(theObjectList.Size() == 1 ) { - if(thePolyline.IsNull()) { - anOutputSplitDataList.append(anInputSplitDataList); + if(theObjectList.Size() == 1 ) + { + if(thePolyline.IsNull()) + { + //anOutputSplitDataList.append(anInputSplitDataList); + SplitData SD = anInputSplitDataList.at(0); + TopTools_ListOfShape newshs; + CutFaceByEdges(SD.Face(), newshs, InterPolys, &OutNE); + for (TopTools_ListIteratorOfListOfShape it(newshs); it.More(); it.Next()) + { + SplitData NSD = SD; + NSD.Shape = it.Value(); + anOutputSplitDataList.append(NSD); + } + + NCollection_DataMap::Iterator spit(OutNE); + for (;spit.More();spit.Next()) + { + const TopoDS_Edge& E = TopoDS::Edge(spit.Key()); + if (E.IsNull()) + continue; + SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName()); + anOutputSplitDataList.append(SDI); + } + if(!theGroupsList.IsEmpty() ) anOutputSplitDataList.append(anInputGroupList); return anOutputSplitDataList; - } else - limplus1Object = true;// size =1 && hasLimits + } + else + limplus1Object = true;// size =1 && hasLimits } HYDROData_DataMapOfShapeListOfString aDM3; if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names @@ -552,7 +579,16 @@ HYDROData_SplitToZonesTool::SplitDataList } } - AddInternalEdges(aDM2, InterPolys); + AddInternalEdges(aDM2, InterPolys, &OutNE); + NCollection_DataMap::Iterator spit(OutNE); + for (;spit.More();spit.Next()) + { + const TopoDS_Edge& E = TopoDS::Edge(spit.Key()); + if (E.IsNull()) + continue; + SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName()); + anOutputSplitDataList.append(SDI); + } // Step 4. Fill output structure. #ifdef DEB_SPLIT_TO_ZONES @@ -622,22 +658,23 @@ HYDROData_SplitToZonesTool::SplitDataList } void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM, - const HYDROData_SequenceOfObjects& thePolylines) + const HYDROData_SequenceOfObjects& thePolylines, + NCollection_DataMap* OutNE) { HYDROData_SequenceOfObjects::Iterator it(thePolylines); TopTools_ListOfShape Wires; + NCollection_DataMap W2P; for (;it.More();it.Next()) { Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value()); - Wires.Append(P->GetShape()); - //Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape; - //if (P->GetNbConnectedWires(aConnectedWires) > 0) - // Wires.Append(aConnectedWires->Value(1)); + const TopoDS_Shape& CW = P->GetShape(); + Wires.Append(CW); + W2P.Bind(CW, P); } HYDROData_DataMapOfShapeListOfShape newDM; - + TopTools_IndexedDataMapOfShapeShape OutNE1; for (int i = 1; i <= DM.Extent();i++) { const TopoDS_Shape& K = DM.FindKey(i); @@ -645,7 +682,7 @@ void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOf TopTools_ListOfShape out; if (K.ShapeType() == TopAbs_FACE) { - CutByEdges(K, Wires, out); + CutByEdges(K, Wires, out, &OutNE1); TopTools_ListIteratorOfListOfShape it(out); for (;it.More(); it.Next()) { @@ -658,17 +695,44 @@ void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOf newDM.Add(K, V); // ignore edges, wires... } + for (int i = 1; i <= OutNE1.Extent(); i++) + OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i))); + DM = newDM; } +void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in, + TopTools_ListOfShape& out, + const HYDROData_SequenceOfObjects& thePolylines, + NCollection_DataMap* OutNE) +{ -int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InEdges, - TopTools_ListOfShape& outShs) + HYDROData_SequenceOfObjects::Iterator it(thePolylines); + TopTools_ListOfShape Wires; + NCollection_DataMap W2P; + for (;it.More();it.Next()) + { + Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value()); + const TopoDS_Shape& CW = P->GetShape(); + Wires.Append(CW); + W2P.Bind(CW, P); + } + + TopTools_IndexedDataMapOfShapeShape OutNE1; + CutByEdges(in, Wires, out, &OutNE1); + + for (int i = 1; i <= OutNE1.Extent(); i++) + OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i))); + +} + +int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW, + TopTools_ListOfShape& outShs, TopTools_IndexedDataMapOfShapeShape* OutNE) { int anError; if (InSh.IsNull()) return -1; - if (InEdges.IsEmpty()) + if (InW.IsEmpty()) { outShs.Clear(); outShs.Append(InSh); @@ -677,7 +741,8 @@ int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTo TopTools_ListIteratorOfListOfShape anIt; BOPAlgo_Builder anAlgo; anAlgo.AddArgument(InSh); - anIt.Initialize( InEdges ); + + anIt.Initialize( InW ); for( ; anIt.More(); anIt.Next() ) anAlgo.AddArgument( anIt.Value() ); @@ -689,5 +754,39 @@ int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTo outShs = anAlgo.Modified( InSh ); if (outShs.IsEmpty()) outShs.Append(InSh); + + if (OutNE) + { + TopTools_IndexedDataMapOfShapeShape NonFOutNE; + anIt.Initialize( InW ); + for( ; anIt.More(); anIt.Next() ) + { + const TopoDS_Shape& OSH = anIt.Value(); + TopExp_Explorer exp(OSH, TopAbs_EDGE); + for (;exp.More();exp.Next()) + { + const TopoDS_Edge& OE = TopoDS::Edge(exp.Current()); + const TopTools_ListOfShape& ls = anAlgo.Modified(OE); + TopTools_ListIteratorOfListOfShape itls(ls); + for (;itls.More();itls.Next()) + NonFOutNE.Add(itls.Value(), OSH); + } + } + + //filter edges; if face contain an edge => keep it + TopTools_IndexedMapOfShape AllEdges; //edges from output shape + for (anIt.Initialize(outShs); anIt.More();anIt.Next()) + TopExp::MapShapes(anIt.Value(), TopAbs_EDGE, AllEdges); + + for (int i = 1; i <= NonFOutNE.Extent(); i++) + { + const TopoDS_Shape& CE = NonFOutNE.FindKey(i); + const TopoDS_Shape& V = NonFOutNE.FindFromIndex(i); + if (AllEdges.Contains(CE)) + OutNE->Add(CE, V); + } + + } + return 0; } diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.h b/src/HYDROData/HYDROData_SplitToZonesTool.h index 530e7f2a..63a3065e 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.h +++ b/src/HYDROData/HYDROData_SplitToZonesTool.h @@ -30,9 +30,10 @@ #include #include #include -#include +#include #include #include +#include class Handle(HYDROData_PolylineXY); @@ -50,7 +51,8 @@ public: { Data_None, Data_Zone, - Data_Edge + Data_Edge, + Data_IntEdge }; TopoDS_Shape Shape; @@ -93,10 +95,17 @@ public: static SplitDataList Split( const HYDROData_SequenceOfObjects& theObjectList ); static void AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM, - const HYDROData_SequenceOfObjects& thePolylines); + const HYDROData_SequenceOfObjects& thePolylines, + NCollection_DataMap* OutNE); - static int CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InEdges, - TopTools_ListOfShape& outShs); + static void CutFaceByEdges(const TopoDS_Face& in, + TopTools_ListOfShape& out, + const HYDROData_SequenceOfObjects& thePolylines, + NCollection_DataMap* OutNE); + + static int CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW, + TopTools_ListOfShape& outShs, + TopTools_IndexedDataMapOfShapeShape* OutNE2OE); static void SetFileNames(const QString& theNameBefore, const QString& theNameAfter); diff --git a/src/HYDRO_tests/test_HYDROData_CalcCase.cxx b/src/HYDRO_tests/test_HYDROData_CalcCase.cxx index fdec7023..f1cf71b8 100644 --- a/src/HYDRO_tests/test_HYDROData_CalcCase.cxx +++ b/src/HYDRO_tests/test_HYDROData_CalcCase.cxx @@ -52,7 +52,9 @@ void test_HYDROData_CalcCase::test_add_int_wires() Wires.Append(InP); TopTools_ListOfShape OutSh; - HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh); + TopTools_IndexedDataMapOfShapeShape ls; + HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh, &ls); + CPPUNIT_ASSERT_EQUAL(2, OutSh.Extent()); TopoDS_Compound cmp; B.MakeCompound(cmp); @@ -74,7 +76,8 @@ void test_HYDROData_CalcCase::test_add_int_wires() Wires.Append(InP); TopTools_ListOfShape OutSh; - HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh); + TopTools_IndexedDataMapOfShapeShape ls; + HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh, &ls); CPPUNIT_ASSERT_EQUAL(1, OutSh.Extent()); TestViewer::show( OutSh.First(), AIS_WireFrame, true, "cc_int_w_2" ); //CPPUNIT_ASSERT_IMAGES @@ -92,7 +95,8 @@ void test_HYDROData_CalcCase::test_add_int_wires() Wires.Append(InP); TopTools_ListOfShape OutSh; - HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh); + TopTools_IndexedDataMapOfShapeShape ls; + HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh, &ls); CPPUNIT_ASSERT_EQUAL(1, OutSh.Extent()); TestViewer::show( OutSh.First(), AIS_WireFrame, true, "cc_int_w_3" ); CPPUNIT_ASSERT_IMAGES -- 2.39.2