X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_SplitToZonesTool.cxx;h=3df841ed040d9a09a29f351170c004f87d8f46ea;hb=191c33b8fd827caa9af8886728e9df22ae55451e;hp=6f20f0d69115ead1f755c2160938c7cb4ea11642;hpb=ae522e78e8c55629201efc69831cc49c6fe83a61;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index 6f20f0d6..3df841ed 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -3,35 +3,33 @@ #include "HYDROData_PolylineXY.h" #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 #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 - -#define DEB_SPLIT_TO_ZONES 1 -#ifdef DEB_SPLIT_TO_ZONES +#include +#include +#include +#include +#include + +//#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; @@ -54,16 +52,74 @@ 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; - + 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 = @@ -74,7 +130,10 @@ HYDROData_SplitToZonesTool::SplitDataList TopoDS_Shape aShape = aGeomObj->GetTopShape(); if ( aShape.IsNull() ) 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 ); @@ -92,7 +151,7 @@ HYDROData_SplitToZonesTool::SplitDataList } // 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 ) ); @@ -114,302 +173,409 @@ 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(" "); + cout << "Group# = " <Modified(anIt.Value()); - 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->Generated(anIt.Value()); - it.Initialize(aListOfGen); - for(;it.More();it.Next()) - aList.Append(it.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++) { - const TopTools_ListOfShape& aListM = aBuilder->Modified(exp.Current()); - //cout << "NB_EDGE_M = " << aListM.Extent() <Generated(exp.Current()); - 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()); + 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() <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() < " << ObjectNames.size() <<" " << aStr.toStdString()<