X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_SplitToZonesTool.cxx;h=182c61781ffcc8601989763b74f99d91b5bedbcf;hb=58bb6b7459bebeeb089c9ed486c4683a8bae7288;hp=a4312ab4671110e8e16b579f9c26ffe467621b7f;hpb=b4100f7bda1606e214941fd08309898082ab73e9;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index a4312ab4..182c6178 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -1,3 +1,20 @@ +// 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" @@ -14,35 +31,30 @@ #include #include #include -#include #include -#include -#include -#include -#include -#include #include #include -#include +#include #include #include #include #include #include - -typedef NCollection_Map HYDROData_MapOfShape; -typedef HYDROData_MapOfShape::Iterator HYDROData_MapIteratorOfMapOfShape; -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 //#define DEB_SPLIT_TO_ZONES 1 -#ifdef DEB_SPLIT_TO_ZONES +//#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 + +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const { TopoDS_Face aResFace; @@ -78,58 +90,101 @@ Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFac aPln = gp_Pln(aCPnt, gp::OZ().Direction()); BRepBuilderAPI_MakeFace aMkFace(aPln, theBndWire); if(aMkFace.IsDone()) { - outFace = aMkFace.Face(); + outFace = aMkFace.Face(); if(!outFace.IsNull()) { #ifdef DEB_SPLIT_TO_ZONES -// BRepTools::Write(limFace,"FL.brep"); +// 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 ) + const Handle(HYDROData_PolylineXY)& thePolyline, + const HYDROData_SequenceOfObjects& InterPolys) { +#ifndef NDEBUG + DEBTRACE("Split"); +#endif 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; +#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; - //TCollection_AsciiString aName = aNam + anIndex + ".brep"; - //BRepTools::Write(aShape, aName.ToCString()); - +#ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aName = aNam + anIndex + "_a.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() ) { 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; anIndex <= theGroupsList.Length(); anIndex++ ) + for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ ) { Handle(HYDROData_ShapesGroup) aGeomGroup = Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) ); @@ -151,158 +206,209 @@ HYDROData_SplitToZonesTool::SplitDataList SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->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(" "); + DEBTRACE("Group# = " <SetArguments(aLS); - aPaveFiller->Perform(); - 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(aLS); - for (; anIt.More(); anIt.Next()) { - const TopoDS_Shape& aS = anIt.Value(); - aBuilder->AddArgument(aS); - } - aBuilder->PerformWithFiller(*aPaveFiller); - anErr = aBuilder->ErrorStatus(); - - //// - if(anErr) - return anOutputSplitDataList; - aResult = aBuilder->Shape(); - } */ - - if (aResult.IsNull()) - return anOutputSplitDataList; - BRepCheck_Analyzer aCheck (aResult); - if(!aCheck.IsValid()) { + aBB.Add(aCmp,aSh); #ifdef DEB_SPLIT_TO_ZONES - cout << "result is not valid" <*/sTool.Modified(anIt.Value()); - if(!aListOfNew.IsEmpty()) - foundF = Standard_True; - TopTools_ListOfShape aList; - TopTools_ListIteratorOfListOfShape it(aListOfNew); - for(;it.More();it.Next()) - aList.Append(it.Value()); - // Bug in History: partition should give only modified entities! => temporary solution is used - const TopTools_ListOfShape& aListOfGen = /*aBuilder->*/sTool.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.Bind(anIt.Value(), aList); - //TCollection_AsciiString aName; - if(!anInputGroupList.isEmpty() ) { // 1 - aList.Clear(); - TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE); - for (int j =1;exp.More();exp.Next(),j++) { - Standard_Boolean foundE(Standard_False); - const TopTools_ListOfShape& aListM = /*aBuilder->*/sTool.Modified(exp.Current()); - //cout << "NB_EDGE_M = " << aListM.Extent() <*/sTool.Generated(exp.Current()); - if(aListG.Extent()) foundE = Standard_True; - it.Initialize(aListG); - for(int k=1;it.More();it.Next(),k++) { - aList.Append(it.Value()); - //aName = aNamG + i + j +k +".brep"; - //BRepTools::Write(it.Value(),aName.ToCString()); - } - //cout << "NB_EDGE = " << aList.Extent() < 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 + DEBTRACE("result is not valid"); + BRepTools::Write(aResult, "SplitFacesNV.brep"); + #endif + return anOutputSplitDataList; + } + #ifdef DEB_SPLIT_TO_ZONES + BRepTools::Write(aResult, "SplitFacesV.brep"); + #endif + + // Step 3. Collect history + //HYDROData_DataMapOfShapeListOfShape aDM1; + BOPCol_ListIteratorOfListOfShape anIt(aLS); + #ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aNamM ("EdgM_"); + TCollection_AsciiString aNamG ("EdgG_"); + #endif + for (int i =1;anIt.More();anIt.Next(),i++) { + Standard_Boolean foundF(Standard_False); + const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value()); + if(!aListOfNew.IsEmpty()) + foundF = Standard_True; + + TopTools_ListOfShape aList; + + TopTools_ListIteratorOfListOfShape it(aListOfNew); + for(;it.More();it.Next()) + aList.Append(it.Value()); + /* ********************************************************************* + // Bug in History: partition should give only modified entities! => 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()); +#ifndef NDEBUG + DEBTRACE("NB_EDGE_M = " << aListM.Extent()); +#endif + if(aListM.Extent()) foundE = Standard_True; + it.Initialize(aListM); + for(int k=1;it.More();it.Next(),k++) { + aList.Append(it.Value()); + #ifdef DEB_SPLIT_TO_ZONES + aName = aNamM + i + j +k +"_d.brep"; + BRepTools::Write(it.Value(),aName.ToCString()); + #endif + } + /* ********************************************************************* + //const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current()); + //if(aListG.Extent()) foundE = Standard_True; + //it.Initialize(aListG); + //for(int k=1;it.More();it.Next(),k++) + //aList.Append(it.Value()); + //cout << "NB_EDGE = " << aList.Extent() <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() <::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. - //TCollection_AsciiString aNam4 ("SC_"); - +#ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aNam4 ("SC_"); +#endif HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2); for(int i =1;aMIt.More();aMIt.Next(),i++) { SplitData aDestSplitData; @@ -466,83 +639,207 @@ HYDROData_SplitToZonesTool::SplitDataList aDestSplitData.Shape = aKey; if(aKey.ShapeType() == TopAbs_FACE) aDestSplitData.Type = SplitData::Data_Zone; - else + else { aDestSplitData.Type = SplitData::Data_Edge; #ifdef DEB_SPLIT_TO_ZONES - //TCollection_AsciiString aName = aNam4 + i + ".brep"; - //BRepTools::Write(aKey,aName.ToCString()); -#endif - + TCollection_AsciiString aName = aNam4 + i + "_k.brep"; + BRepTools::Write(aKey,aName.ToCString()); +#endif + } QStringList aListOfNames; // names processing const TopTools_ListOfShape& aListOfOld = aMIt.Value(); 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.ObjectNames = aListOfNames; - anOutputSplitDataList.append(aDestSplitData); + for(int j =1;it.More();it.Next(),j++) { + const TopoDS_Shape& aSh = it.Value(); //old + if(aDM3.Contains(aSh)) { + const QStringList& ObjectNames = aDM3.FindFromKey(aSh); + aListOfNames.append(ObjectNames); +#ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aName = aNam4 + i +"_" + j + "_l.brep"; + BRepTools::Write(aSh ,aName.ToCString()); +#endif + } else { +#ifdef DEB_SPLIT_TO_ZONES + TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + "_m.brep"; + BRepTools::Write(aSh ,aName.ToCString()); + DEBTRACE(aName.ToCString()<<" = "<< aSh.TShape()); +#endif + if(aBndView.Contains(aSh) && hasLimits) { + aListOfNames.append(aBndName); +#ifdef DEB_SPLIT_TO_ZONES + DEBTRACE(" BndName = "<