X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_SplitToZonesTool.cxx;h=f91732cd2fcdba0a6ae49707008b8b684b76dee3;hb=545854182f0363f61284d5abe34c3627d4f3b088;hp=4960a9b741be3c17643236d8222c0b7d75ba00f7;hpb=4c1ccf71f6e25cd39583d61dd7bea9b1db3eaa7f;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index 4960a9b7..f91732cd 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -1,35 +1,52 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "HYDROData_SplitToZonesTool.h" #include "HYDROData_PolylineXY.h" - -#include +#include "HYDROData_ShapesGroup.h" +#include #include +#include #include - +#include #include #include -#include +#include +#include #include -#include +#include #include -#include -#include -#include -#include #include -#include -#include -typedef NCollection_DataMap HYDROData_DataMapOfShapeListOfShape; -typedef HYDROData_DataMapOfShapeListOfShape::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape; -typedef NCollection_DataMap HYDROData_DataMapOfShapeListOfString; -typedef HYDROData_DataMapOfShapeListOfString::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfString; -#undef _NCollection_MapHasher +#include +#include +#include +#include +#include +#include -#define DEB_SPLIT_TO_ZONES 1 -#ifdef DEB_SPLIT_TO_ZONES +//#define DEB_SPLIT_TO_ZONES 1 +//#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1 +#if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION)) #include +static TCollection_AsciiString fileNameBefore("BeforeTranslation"); #endif + TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const { TopoDS_Face aResFace; @@ -52,269 +69,540 @@ TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const return aResFace; } +Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace) +{ + GProp_GProps G; + BRepGProp::LinearProperties(theBndWire,G); + const gp_Pnt& aCPnt = G.CentreOfMass(); + gp_Pln aPln; + BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion()); + if(fndPlane.Found()) + aPln = fndPlane.Plane()->Pln(); + else + aPln = gp_Pln(aCPnt, gp::OZ().Direction()); + BRepBuilderAPI_MakeFace aMkFace(aPln, theBndWire); + if(aMkFace.IsDone()) { + outFace = aMkFace.Face(); + if(!outFace.IsNull()) { +#ifdef DEB_SPLIT_TO_ZONES +// BRepTools::Write(limFace,"FL.brep"); +#endif + return Standard_True; + } + } + return Standard_False; +} +//====================================================================================== + +void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter) +{ +#ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION + if(!theNameBefore.isNull() && !theNameBefore.isEmpty()) + { + TCollection_AsciiString aName (theNameBefore.toStdString().data()); + fileNameBefore = aName; + } + if(!theNameAfter.isNull() && !theNameAfter.isEmpty()) + { + TCollection_AsciiString aName (theNameAfter.toStdString().data()); + HYDROData_Transform::SetFileName (aName); + } +#endif +} +//====================================================================================== +Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, + HYDROData_Transform& theTool) +{ + theTool.Clear(); + theTool.SetArgument(theComp); + theTool.Detect(); + const Standard_Boolean bToTransform = theTool.ToTransform(); + theTool.SetToTransform(bToTransform); + theTool.Perform(); + Standard_Integer anErr = theTool.ErrorStatus(); + return anErr; +} + +//====================================================================================== HYDROData_SplitToZonesTool::SplitDataList HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList, const HYDROData_SequenceOfObjects& theGroupsList, const Handle(HYDROData_PolylineXY)& thePolyline ) { SplitDataList anOutputSplitDataList; - - // Preparation. Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape. + 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; +#ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aNam("Faces_"); +#endif for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Object) aGeomObj = - Handle(HYDROData_Object)::DownCast( theObjectList.Value( anIndex ) ); - if( aGeomObj.IsNull() ) - continue; + Handle(HYDROData_Entity) anObj = theObjectList.Value( anIndex ); + TopoDS_Shape aShape; + + Handle(HYDROData_Object) aGeomObj = Handle(HYDROData_Object)::DownCast( anObj ); + if( !aGeomObj.IsNull() ) { + aShape = aGeomObj->GetTopShape(); + } - TopoDS_Shape aShape = aGeomObj->GetTopShape(); if ( aShape.IsNull() ) - continue; - + continue; +#ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aName = aNam + anIndex + ".brep"; + BRepTools::Write(aShape, aName.ToCString()); +#endif if ( aShape.ShapeType() == TopAbs_COMPOUND ) { // Create split data for each face contained in the compound TopExp_Explorer anExp( aShape, TopAbs_FACE ); for ( ; anExp.More(); anExp.Next() ) { - TopoDS_Face aFace = TopoDS::Face( anExp.Current() ); + const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() ); if ( !aFace.IsNull() ) { - SplitData aSplitData( SplitData::Data_Zone, aFace, aGeomObj->GetName() ); + SplitData aSplitData( SplitData::Data_Zone, aFace, anObj->GetName() ); anInputSplitDataList.append( aSplitData ); } } } else { - SplitData aSplitData( SplitData::Data_Zone, aShape, aGeomObj->GetName() ); + SplitData aSplitData( SplitData::Data_Zone, aShape, anObj->GetName() ); anInputSplitDataList.append( aSplitData ); } } + // + SplitDataList anInputGroupList; + for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ ) + { + Handle(HYDROData_ShapesGroup) aGeomGroup = + Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) ); + if( aGeomGroup.IsNull() ) + continue; + + TopTools_SequenceOfShape aGroupShapes; + aGeomGroup->GetShapes( aGroupShapes ); + for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) { + const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i ); + if ( aGroupShape.IsNull() ) + continue; - // Step 1. Prepare Partition structures. - Handle(NCollection_BaseAllocator) pA1 = new NCollection_IncAllocator, pA2 = new NCollection_IncAllocator; - BOPAlgo_PaveFiller* aPaveFiller = new BOPAlgo_PaveFiller(pA1); - BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder(pA2); - BOPCol_ListOfShape aLS; - HYDROData_DataMapOfShapeListOfString aDM3; - QStringList aListOfNames; - for (int i=0;i < anInputSplitDataList.size() ;i++) { - const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape; - aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames); - aLS.Append(aSh); - } - aPaveFiller->SetArguments(aLS); - aPaveFiller->Perform(); - Standard_Integer anErr = aPaveFiller->ErrorStatus(); - if(anErr) - return anOutputSplitDataList; - BOPDS_PDS pDS = aPaveFiller->PDS(); - if (!pDS) - return anOutputSplitDataList; - aBuilder->Clear(); - - // Step 2. Split faces - BOPCol_ListIteratorOfListOfShape anIt(aPaveFiller->Arguments()); - for (; anIt.More(); anIt.Next()) { - const TopoDS_Shape& aS = anIt.Value(); - aBuilder->AddArgument(aS); - } - aBuilder->PerformWithFiller(*aPaveFiller); - anErr = aBuilder->ErrorStatus(); - if(anErr) - return anOutputSplitDataList; - const TopoDS_Shape& aResult = aBuilder->Shape(); - if (aResult.IsNull()) - return anOutputSplitDataList; - BRepCheck_Analyzer aCheck (aResult); - if(!aCheck.IsValid()) { -#ifdef DEB_SPLIT_TO_ZONES - cout << "result is not valid" <GetName() ); + anInputGroupList.append( aSplitData ); + } + } + } else { + SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() ); + anInputGroupList.append( aSplitData ); +#ifdef DEB_SPLIT_TO_ZONES + QString aStr = aSplitData.ObjectNames.join(" "); + cout << "Group# = " <Modified(anIt.Value()); - aDM1.Bind(anIt.Value(), aListOfNew); - //cout << "NB_Face = " << aList.Extent() <Modified(exp.Current()); - // cout << "NB_EDGE = " << aList2.Extent() < ListOfOldShapes - HYDROData_DataMapOfShapeListOfShape aDM2; - HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1); - for(;aMIt.More();aMIt.Next()) { - const TopoDS_Shape& aKey = aMIt.Key(); - TopTools_ListOfShape aList; - aList.Append(aKey); - const TopTools_ListOfShape& aListOfNew = aMIt.Value(); - TopTools_ListIteratorOfListOfShape it(aListOfNew); - for(;it.More();it.Next()) { - if(!aDM2.IsBound(it.Value())) - aDM2.Bind(it.Value(), aList); - else { - TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value()); - aList.Prepend(aKey); - } - } + HYDROData_DataMapOfShapeListOfString aDM3; + if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names + QStringList aListOfNames; + for (int i=0;i < anInputGroupList.size() ;i++) { + const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape; + aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames); + } } - // Step 4. Fill output structure. - aMIt.Initialize(aDM2); - for(;aMIt.More();aMIt.Next()) { - const TopoDS_Shape& aKey = aMIt.Key(); //new - const TopTools_ListOfShape& aListOfOld = aMIt.Value(); - SplitData aDestSplitData; - QStringList aListOfNames; - TopTools_ListIteratorOfListOfShape it(aListOfOld); - for(;it.More();it.Next()) { - const TopoDS_Shape& aSh = it.Value(); //old - if(aDM3.IsBound(aSh)) { - const QStringList& ObjectNames = aDM3.Find(aSh); - aListOfNames.append(ObjectNames); - } - } - aDestSplitData.Shape = aKey; - aDestSplitData.ObjectNames = aListOfNames; - anOutputSplitDataList.append(aDestSplitData); + // Step 1. Prepare Partition structures. + TopoDS_Shape aResult; + BOPCol_ListOfShape aLS; + QStringList aListOfNames; + TopoDS_Compound aCmp; + BRep_Builder aBB; + aBB.MakeCompound(aCmp); + for (int i=0;i < anInputSplitDataList.size() ;i++) { + const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape; + aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames); + aLS.Append(aSh); + aBB.Add(aCmp,aSh); +#ifdef DEB_SPLIT_TO_ZONES + //TCollection_AsciiString aName = aNam + i + ".brep"; + //BRepTools::Write(aSh, aName.ToCString()); +#endif } - return anOutputSplitDataList; - /* - SplitDataListIterator anInputIter( anInputSplitDataList ); - while( anInputIter.hasNext() ) - { - const SplitData& anInputSplitData = anInputIter.next(); - if( anOutputSplitDataList.isEmpty() ) - anOutputSplitDataList.append( anInputSplitData ); - else - { - SplitDataList aSplitDataList; - - SplitDataList aSrcSplitDataList; - aSrcSplitDataList.append( anInputSplitData ); - - SplitDataList aDestSplitDataList = anOutputSplitDataList; - anOutputSplitDataList.clear(); +#ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION + TCollection_AsciiString aNameBefore = fileNameBefore + ".brep"; + BRepTools::Write(aCmp, aNameBefore.ToCString()); +#endif - while( !aDestSplitDataList.isEmpty() ) - { - SplitData aSrcSplitData = aSrcSplitDataList.last(); + HYDROData_DataMapOfShapeListOfShape aDM1; + if(anInputSplitDataList.size() > 1) { + HYDROData_Transform splitTool; + const Standard_Integer anErr = SplitFaces(aCmp, splitTool); + if(anErr) + return anOutputSplitDataList; + aResult = splitTool.Shape(); + if (aResult.IsNull()) + return anOutputSplitDataList; + BRepCheck_Analyzer aCheck (aResult); + if(!aCheck.IsValid()) { + #ifdef DEB_SPLIT_TO_ZONES + cout << "result is not valid" < temporary solution is used + //const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value()); + //if(!aListOfGen.IsEmpty()) + //foundF = Standard_True; + //it.Initialize(aListOfGen); + //for(;it.More();it.Next()) + // aList.Append(it.Value()); + ********************************************************************* */ + if(!foundF) // face is not modified + aList.Append (anIt.Value()); + aDM1.Add(anIt.Value(), aList); + #ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aName; + #endif + if(!anInputGroupList.isEmpty() ) { // 1 + TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE); + for (int j =1;exp.More();exp.Next(),j++) { + aList.Clear(); + Standard_Boolean foundE(Standard_False); + const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current()); + //cout << "NB_EDGE_M = " << aListM.Extent() < ListOfOldShapes + HYDROData_DataMapOfShapeListOfShape aDM2; + // make limiting face + HYDROData_DataMapOfShapeListOfShape aDM4; + Standard_Boolean hasLimits(Standard_False); + QString aBndName; + HYDROData_MapOfShape aBndView; + if (! thePolyline.IsNull()) { + const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape()); + if(!aBndWire.IsNull()) { + TopoDS_Face limFace; + if(buildLimFace(aBndWire, limFace)) { + TopoDS_Shape aComResult; + BRepAlgoAPI_Common mkCom(aResult, limFace); + if(mkCom.IsDone()) { + aComResult = mkCom.Shape(); + BRepCheck_Analyzer aCheck (aComResult); + if(aCheck.IsValid()) { +#ifdef DEB_SPLIT_TO_ZONES + BRepTools::Write(aComResult,"CommonV.brep"); + BRepTools::Write(limFace,"limFace.brep"); +#endif + aBndName = thePolyline->GetName(); + hasLimits = Standard_True; // DM2 should be filled here + TopExp_Explorer exp (limFace, TopAbs_EDGE); + for (int i =1;exp.More();exp.Next(),i++) { + const TopoDS_Shape& anEdge = exp.Current(); + if(anEdge.IsNull()) continue; + aBndView.Add(anEdge); + QStringList aListOfNames; + aListOfNames.append(aBndName); + aDM3.Add(anEdge, aListOfNames); + TopTools_ListOfShape aList; + aList.Append(anEdge); + aDM1.Add(anEdge,aList); + } + HYDROData_MapOfShape aView; + exp.Init (aResult, TopAbs_FACE); + for (int i =1;exp.More();exp.Next(),i++) { + const TopoDS_Shape& aFace = exp.Current(); + if(!aFace.IsNull()) { + const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace); + //cout << "Modified: " << aListOfNew.Extent() <