1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_SplitToZonesTool.h"
21 #include "HYDROData_PolylineXY.h"
22 #include "HYDROData_ShapesGroup.h"
23 #include <HYDROData_Transform.h>
24 #include <BRepAlgoAPI_Cut.hxx>
25 #include <BRepAlgoAPI_Common.hxx>
26 #include <BRepBuilderAPI_MakeFace.hxx>
27 #include <BRep_Builder.hxx>
28 #include <TopExp_Explorer.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <BRepCheck_Analyzer.hxx>
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <BRepGProp.hxx>
40 #include <GProp_GProps.hxx>
41 #include <Geom_Plane.hxx>
42 #include <BRepBuilderAPI_FindPlane.hxx>
44 #include <BOPAlgo_BOP.hxx>
45 #include <BOPAlgo_Builder.hxx>
48 //#define DEB_SPLIT_TO_ZONES 1
49 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
50 #if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
51 #include <BRepTools.hxx>
52 static TCollection_AsciiString fileNameBefore("BeforeTranslation");
56 #include "HYDRO_trace.hxx"
58 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
64 if ( Shape.ShapeType() == TopAbs_FACE )
66 aResFace = TopoDS::Face( Shape );
68 else if ( Shape.ShapeType() == TopAbs_WIRE )
70 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( Shape ), Standard_True );
72 if( aMakeFace.IsDone() )
73 aResFace = aMakeFace.Face();
80 Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace)
83 BRepGProp::LinearProperties(theBndWire,G);
84 const gp_Pnt& aCPnt = G.CentreOfMass();
86 BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion());
88 aPln = fndPlane.Plane()->Pln();
90 aPln = gp_Pln(aCPnt, gp::OZ().Direction());
91 BRepBuilderAPI_MakeFace aMkFace(aPln, theBndWire);
92 if(aMkFace.IsDone()) {
93 outFace = aMkFace.Face();
94 if(!outFace.IsNull()) {
95 #ifdef DEB_SPLIT_TO_ZONES
96 // BRepTools::Write(limFace,"FL.brep");
101 return Standard_False;
103 //======================================================================================
105 void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter)
107 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
108 if(!theNameBefore.isNull() && !theNameBefore.isEmpty())
110 TCollection_AsciiString aName (theNameBefore.toStdString().data());
111 fileNameBefore = aName;
113 if(!theNameAfter.isNull() && !theNameAfter.isEmpty())
115 TCollection_AsciiString aName (theNameAfter.toStdString().data());
116 HYDROData_Transform::SetFileName (aName);
120 //======================================================================================
121 Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp,
122 HYDROData_Transform& theTool)
125 theTool.SetArgument(theComp);
127 const Standard_Boolean bToTransform = theTool.ToTransform();
128 theTool.SetToTransform(bToTransform);
130 Standard_Integer anErr = theTool.ErrorStatus();
134 //======================================================================================
135 HYDROData_SplitToZonesTool::SplitDataList
136 HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList,
137 const HYDROData_SequenceOfObjects& theGroupsList,
138 const Handle(HYDROData_PolylineXY)& thePolyline,
139 const HYDROData_SequenceOfObjects& InterPolys)
144 SplitDataList anOutputSplitDataList;
145 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> OutNE;
146 if(theObjectList.IsEmpty())
147 return anOutputSplitDataList;
149 // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape.
150 SplitDataList anInputSplitDataList;
151 #ifdef DEB_SPLIT_TO_ZONES
152 TCollection_AsciiString aNam("Faces_");
154 for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
156 Handle(HYDROData_Entity) anObj = theObjectList.Value( anIndex );
159 Handle(HYDROData_Object) aGeomObj = Handle(HYDROData_Object)::DownCast( anObj );
160 if( !aGeomObj.IsNull() ) {
161 aShape = aGeomObj->GetTopShape();
164 if ( aShape.IsNull() )
166 #ifdef DEB_SPLIT_TO_ZONES
167 TCollection_AsciiString aName = aNam + anIndex + "_a.brep";
168 BRepTools::Write(aShape, aName.ToCString());
170 if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
171 // Create split data for each face contained in the compound
172 TopExp_Explorer anExp( aShape, TopAbs_FACE );
173 for ( ; anExp.More(); anExp.Next() ) {
174 const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() );
175 if ( !aFace.IsNull() ) {
176 SplitData aSplitData( SplitData::Data_Zone, aFace, anObj->GetName() );
177 anInputSplitDataList.append( aSplitData );
181 SplitData aSplitData( SplitData::Data_Zone, aShape, anObj->GetName() );
182 anInputSplitDataList.append( aSplitData );
186 SplitDataList anInputGroupList;
187 for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ )
189 Handle(HYDROData_ShapesGroup) aGeomGroup =
190 Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
191 if( aGeomGroup.IsNull() )
194 TopTools_SequenceOfShape aGroupShapes;
195 aGeomGroup->GetShapes( aGroupShapes );
196 for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
197 const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i );
198 if ( aGroupShape.IsNull() )
201 if ( aGroupShape.ShapeType() == TopAbs_COMPOUND ) {
202 TopExp_Explorer anExp( aGroupShape, TopAbs_EDGE );
203 for ( ; anExp.More(); anExp.Next() ) {
204 const TopoDS_Edge& anEdge = TopoDS::Edge( anExp.Current() );
205 if ( !anEdge.IsNull() ) {
206 SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
207 anInputGroupList.append( aSplitData );
211 SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
212 anInputGroupList.append( aSplitData );
213 #ifdef DEB_SPLIT_TO_ZONES
214 QString aStr = aSplitData.ObjectNames.join(" ");
215 DEBTRACE("Group# = " <<anIndex <<" Nmb in grp = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size());
220 // If only one shape is given we don't split it
221 // algorithm just returns the unpacked input data
222 bool limplus1Object(false);
223 if(theObjectList.Size() == 1 )
225 if(thePolyline.IsNull())
227 //anOutputSplitDataList.append(anInputSplitDataList);
228 SplitData SD = anInputSplitDataList.at(0);
229 TopTools_ListOfShape newshs;
230 CutFaceByEdges(SD.Face(), newshs, InterPolys, &OutNE);
231 for (TopTools_ListIteratorOfListOfShape it(newshs); it.More(); it.Next())
234 NSD.Shape = it.Value();
235 anOutputSplitDataList.append(NSD);
238 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
239 for (;spit.More();spit.Next())
241 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
244 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
245 anOutputSplitDataList.append(SDI);
248 if(!theGroupsList.IsEmpty() )
249 anOutputSplitDataList.append(anInputGroupList);
250 return anOutputSplitDataList;
253 limplus1Object = true;// size =1 && hasLimits
255 HYDROData_DataMapOfShapeListOfString aDM3;
256 if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
257 QStringList aListOfNames;
258 for (int i=0;i < anInputGroupList.size() ;i++) {
259 const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
260 aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames);
264 // Step 1. Prepare Partition structures.
265 TopoDS_Shape aResult;
266 BOPCol_ListOfShape aLS;
267 QStringList aListOfNames;
268 TopoDS_Compound aCmp;
270 aBB.MakeCompound(aCmp);
271 for (int i=0;i < anInputSplitDataList.size() ;i++) {
272 const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
273 aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames);
276 #ifdef DEB_SPLIT_TO_ZONES
277 TCollection_AsciiString aName = aNam + i + "_b.brep";
278 BRepTools::Write(aSh, aName.ToCString());
281 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
282 TCollection_AsciiString aNameBefore = fileNameBefore + "_c.brep";
283 BRepTools::Write(aCmp, aNameBefore.ToCString());
286 HYDROData_DataMapOfShapeListOfShape aDM1;
287 if(anInputSplitDataList.size() > 1) {
288 HYDROData_Transform splitTool;
289 const Standard_Integer anErr = SplitFaces(aCmp, splitTool);
291 return anOutputSplitDataList;
292 aResult = splitTool.Shape();
293 if (aResult.IsNull())
294 return anOutputSplitDataList;
295 BRepCheck_Analyzer aCheck (aResult);
296 if(!aCheck.IsValid()) {
297 #ifdef DEB_SPLIT_TO_ZONES
298 DEBTRACE("result is not valid");
299 BRepTools::Write(aResult, "SplitFacesNV.brep");
301 return anOutputSplitDataList;
303 #ifdef DEB_SPLIT_TO_ZONES
304 BRepTools::Write(aResult, "SplitFacesV.brep");
307 // Step 3. Collect history
308 //HYDROData_DataMapOfShapeListOfShape aDM1;
309 BOPCol_ListIteratorOfListOfShape anIt(aLS);
310 #ifdef DEB_SPLIT_TO_ZONES
311 TCollection_AsciiString aNamM ("EdgM_");
312 TCollection_AsciiString aNamG ("EdgG_");
314 for (int i =1;anIt.More();anIt.Next(),i++) {
315 Standard_Boolean foundF(Standard_False);
316 const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
317 if(!aListOfNew.IsEmpty())
318 foundF = Standard_True;
320 TopTools_ListOfShape aList;
322 TopTools_ListIteratorOfListOfShape it(aListOfNew);
323 for(;it.More();it.Next())
324 aList.Append(it.Value());
325 /* *********************************************************************
326 // Bug in History: partition should give only modified entities! => temporary solution is used
327 //const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
328 //if(!aListOfGen.IsEmpty())
329 //foundF = Standard_True;
330 //it.Initialize(aListOfGen);
331 //for(;it.More();it.Next())
332 // aList.Append(it.Value());
333 ********************************************************************* */
334 if(!foundF) // face is not modified
335 aList.Append (anIt.Value());
336 aDM1.Add(anIt.Value(), aList);
337 #ifdef DEB_SPLIT_TO_ZONES
338 TCollection_AsciiString aName;
340 if(!anInputGroupList.isEmpty() ) { // 1
341 TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
342 for (int j =1;exp.More();exp.Next(),j++) {
344 Standard_Boolean foundE(Standard_False);
345 const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());
347 DEBTRACE("NB_EDGE_M = " << aListM.Extent());
349 if(aListM.Extent()) foundE = Standard_True;
350 it.Initialize(aListM);
351 for(int k=1;it.More();it.Next(),k++) {
352 aList.Append(it.Value());
353 #ifdef DEB_SPLIT_TO_ZONES
354 aName = aNamM + i + j +k +"_d.brep";
355 BRepTools::Write(it.Value(),aName.ToCString());
358 /* *********************************************************************
359 //const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
360 //if(aListG.Extent()) foundE = Standard_True;
361 //it.Initialize(aListG);
362 //for(int k=1;it.More();it.Next(),k++)
363 //aList.Append(it.Value());
364 //cout << "NB_EDGE = " << aList.Extent() <<endl;
365 ************************************************************************** */
367 aList.Append (exp.Current());
368 #ifdef DEB_SPLIT_TO_ZONES
369 aName = aNamG + i + j +"_e.brep";
370 BRepTools::Write(exp.Current(),aName.ToCString());
371 DEBTRACE(aName.ToCString()<< " = " << exp.Current().TShape());
374 aDM1.Add(exp.Current(), aList);
379 aResult = anInputSplitDataList.at(0).Shape; // get single input shape
382 // aDM2: NewShape ==> ListOfOldShapes
383 HYDROData_DataMapOfShapeListOfShape aDM2;
384 // make limiting face
385 HYDROData_DataMapOfShapeListOfShape aDM4;
386 Standard_Boolean hasLimits(Standard_False);
388 HYDROData_MapOfShape aBndView;
389 if (! thePolyline.IsNull()) {
390 Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape;
391 int nbWires = thePolyline->GetNbConnectedWires(aConnectedWires);
392 const TopoDS_Wire aBndWire = TopoDS::Wire(aConnectedWires->Value(1));
393 if(!aBndWire.IsNull()) {
395 if(buildLimFace(aBndWire, limFace)) {
396 TopoDS_Shape aComResult;
397 BRepAlgoAPI_Common mkCom(aResult, limFace);
399 aComResult = mkCom.Shape();
400 BRepCheck_Analyzer aCheck (aComResult);
401 if(aCheck.IsValid()) {
402 #ifdef DEB_SPLIT_TO_ZONES
403 BRepTools::Write(aComResult,"CommonV.brep");
404 BRepTools::Write(limFace,"limFace.brep");
406 aBndName = thePolyline->GetName();
407 hasLimits = Standard_True; // DM2 should be filled here
408 TopExp_Explorer exp (limFace, TopAbs_EDGE);
409 for (int i =1;exp.More();exp.Next(),i++) {
410 const TopoDS_Shape& anEdge = exp.Current();
411 if(anEdge.IsNull()) continue;
412 aBndView.Add(anEdge);
413 QStringList aListOfNames;
414 aListOfNames.append(aBndName);
415 aDM3.Add(anEdge, aListOfNames);
416 TopTools_ListOfShape aList;
417 aList.Append(anEdge);
418 aDM1.Add(anEdge,aList);
420 HYDROData_MapOfShape aView;
421 exp.Init (aResult, TopAbs_FACE);
422 for (int i =1;exp.More();exp.Next(),i++) {
423 const TopoDS_Shape& aFace = exp.Current();
424 if(!aFace.IsNull()) {
425 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
427 DEBTRACE("Modified: " << aListOfNew.Extent());
429 if(!aListOfNew.IsEmpty()) {
430 aDM4.Add(aFace, aListOfNew);
431 #ifdef DEB_SPLIT_TO_ZONES
432 TCollection_AsciiString aName = aNam + i + "_f.brep";
433 BRepTools::Write(aListOfNew.Last(), aName.ToCString());
437 if(!mkCom.IsDeleted(aFace)) {
438 const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);
439 if(!aListOfGen.IsEmpty()) {
440 /* aDM4.Bind(aFace, aListOfGen); ??? */
441 #ifdef DEB_SPLIT_TO_ZONES
442 TCollection_AsciiString aName = aNam + i + "_g.brep";
443 BRepTools::Write(aListOfGen.Last(), aName.ToCString());
447 TopTools_ListOfShape aList;
449 aDM4.Add(aFace, aList); //the same face - not modified
453 TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
454 for (int j =1;exp2.More();exp2.Next(),j++) {
455 const TopoDS_Shape& anEdge = exp2.Current();
456 if(!anEdge.IsNull()) {
457 if(aView.Contains(anEdge)) continue;
459 const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
460 if(!aListOfNewEd.IsEmpty())
461 aDM4.Add(anEdge, aListOfNewEd);
463 if(!mkCom.IsDeleted(anEdge)) {
464 const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
465 if(!aListOfGenEd.IsEmpty()) {
466 /* aDM4.Bind(anEdge, aListOfGenEd); ???*/
468 TopTools_ListOfShape aList;
469 aList.Append(anEdge);
470 aDM4.Add(anEdge, aList);//the same edge - not modified
477 } //end DM4 filling (phase 1)
478 //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
479 // phase 2 (from tool)
480 #ifdef DEB_SPLIT_TO_ZONES
481 TCollection_AsciiString aNam("BndEd_");
483 TopExp_Explorer expt (limFace, TopAbs_EDGE);
484 for(int i =1;expt.More();expt.Next(),i++) {
485 const TopoDS_Shape& anEdge = expt.Current();
486 if(!anEdge.IsNull()) {
487 const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
488 #ifdef DEB_SPLIT_TO_ZONES
489 TopTools_ListIteratorOfListOfShape itl(aListOfNewEd);
490 for(int j=1;itl.More();itl.Next(),j++) {
491 TCollection_AsciiString aName = aNam + i + "_" + j + "_j.brep";
492 BRepTools::Write(itl.Value(), aName.ToCString());
493 DEBTRACE(aName.ToCString()<<" = "<< itl.Value().TShape());
496 if(!aListOfNewEd.IsEmpty())
497 aDM4.Add(anEdge, aListOfNewEd);
499 if(!mkCom.IsDeleted(anEdge)) {
500 const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
501 if(!aListOfGenEd.IsEmpty()) {
502 /* aDM4.Bind(anEdge, aListOfGenEd); ??? */
504 TopTools_ListOfShape aList;
505 aList.Append(anEdge);
506 aDM4.Add(anEdge, aList);//the same edge - not modified
512 //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
514 // fill DM1 (old - new) and DM2 (new - old)
515 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
516 for(;mIt.More();mIt.Next()) {
517 const TopoDS_Shape& aKey = mIt.Key();//old
518 TopTools_ListOfShape aList;
520 const TopTools_ListOfShape& aListOfNew = mIt.Value();
521 aDM1.Add(aKey, aListOfNew);
522 TopTools_ListIteratorOfListOfShape it(aListOfNew);
523 for(;it.More();it.Next()) {
524 if(!aDM2.Contains(it.Value()))
525 aDM2.Add(it.Value(), aList);
527 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
533 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
534 //DM4 contains Old - New after common op. DM1: old - new after Split op.
535 for(;aMIt.More();aMIt.Next()) {
536 const TopoDS_Shape& aKey = aMIt.Key();
537 TopTools_ListOfShape aList;
539 const TopTools_ListOfShape& aListOfNew = aMIt.Value();
540 TopTools_ListIteratorOfListOfShape it(aListOfNew);
541 for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
542 if(!aDM4.Contains(it.Value())) // bi - is deleted
543 continue; // go to the next bi
545 const TopTools_ListOfShape& aListOfNew4 = aDM4.FindFromKey(it.Value());
546 TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
547 for(;it4.More();it4.Next()) {
548 if(!aDM2.Contains(it4.Value()))
549 aDM2.Add(it4.Value(), aList);
551 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it4.Value());
560 hasLimits = Standard_False;
561 #ifdef DEB_SPLIT_TO_ZONES
562 BRepTools::Write(aComResult,"CommonNV.brep");
568 }// end limits processing
570 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
571 for(;aMIt.More();aMIt.Next()) {
572 const TopoDS_Shape& aKey = aMIt.Key();
573 TopTools_ListOfShape aList;
575 const TopTools_ListOfShape& aListOfNew = aMIt.Value();
576 TopTools_ListIteratorOfListOfShape it(aListOfNew);
577 for(;it.More();it.Next()) {
578 if(!aDM2.Contains(it.Value()))
579 aDM2.Add(it.Value(), aList);
581 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
588 AddInternalEdges(aDM2, InterPolys, &OutNE);
589 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
590 for (;spit.More();spit.Next())
592 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
595 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
596 anOutputSplitDataList.append(SDI);
599 // Step 4. Fill output structure.
600 #ifdef DEB_SPLIT_TO_ZONES
601 TCollection_AsciiString aNam4 ("SC_");
603 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
604 for(int i =1;aMIt.More();aMIt.Next(),i++) {
605 SplitData aDestSplitData;
606 const TopoDS_Shape& aKey = aMIt.Key(); //new
607 aDestSplitData.Shape = aKey;
608 if(aKey.ShapeType() == TopAbs_FACE)
609 aDestSplitData.Type = SplitData::Data_Zone;
611 aDestSplitData.Type = SplitData::Data_Edge;
612 #ifdef DEB_SPLIT_TO_ZONES
613 TCollection_AsciiString aName = aNam4 + i + "_k.brep";
614 BRepTools::Write(aKey,aName.ToCString());
618 QStringList aListOfNames; // names processing
619 const TopTools_ListOfShape& aListOfOld = aMIt.Value();
620 TopTools_ListIteratorOfListOfShape it(aListOfOld);
621 for(int j =1;it.More();it.Next(),j++) {
622 const TopoDS_Shape& aSh = it.Value(); //old
623 if(aDM3.Contains(aSh)) {
624 const QStringList& ObjectNames = aDM3.FindFromKey(aSh);
625 aListOfNames.append(ObjectNames);
626 #ifdef DEB_SPLIT_TO_ZONES
627 TCollection_AsciiString aName = aNam4 + i +"_" + j + "_l.brep";
628 BRepTools::Write(aSh ,aName.ToCString());
631 #ifdef DEB_SPLIT_TO_ZONES
632 TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + "_m.brep";
633 BRepTools::Write(aSh ,aName.ToCString());
634 DEBTRACE(aName.ToCString()<<" = "<< aSh.TShape());
636 if(aBndView.Contains(aSh) && hasLimits) {
637 aListOfNames.append(aBndName);
638 #ifdef DEB_SPLIT_TO_ZONES
639 DEBTRACE(" BndName = "<<aBndName.toStdString());
645 aDestSplitData.ObjectNames = aListOfNames;
646 anOutputSplitDataList.append(aDestSplitData);
647 #ifdef DEB_SPLIT_TO_ZONES
648 QString aStr = aDestSplitData.ObjectNames.join(" ");
649 DEBTRACE("New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size());
653 return anOutputSplitDataList;
656 HYDROData_SplitToZonesTool::SplitDataList
657 HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList )
659 HYDROData_SequenceOfObjects aGeomGroups;
660 Handle(HYDROData_PolylineXY) aPolyline;
661 HYDROData_SequenceOfObjects InterPolys;
663 return Split( theObjectList, aGeomGroups, aPolyline, InterPolys );
666 void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
667 const HYDROData_SequenceOfObjects& thePolylines,
668 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
671 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
672 TopTools_ListOfShape Wires;
673 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
674 for (;it.More();it.Next())
676 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
677 const TopoDS_Shape& CW = P->GetShape();
682 HYDROData_DataMapOfShapeListOfShape newDM;
683 TopTools_IndexedDataMapOfShapeShape OutNE1;
684 for (int i = 1; i <= DM.Extent();i++)
686 const TopoDS_Shape& K = DM.FindKey(i);
687 const TopTools_ListOfShape& V = DM.FindFromIndex(i);
688 TopTools_ListOfShape out;
689 if (K.ShapeType() == TopAbs_FACE)
691 CutByEdges(K, Wires, out, &OutNE1);
692 TopTools_ListIteratorOfListOfShape it(out);
693 for (;it.More(); it.Next())
695 const TopoDS_Shape& NF = it.Value();
701 newDM.Add(K, V); // ignore edges, wires...
704 for (int i = 1; i <= OutNE1.Extent(); i++)
705 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
710 void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in,
711 TopTools_ListOfShape& out,
712 const HYDROData_SequenceOfObjects& thePolylines,
713 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
716 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
717 TopTools_ListOfShape Wires;
718 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
719 for (;it.More();it.Next())
721 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
722 const TopoDS_Shape& CW = P->GetShape();
727 TopTools_IndexedDataMapOfShapeShape OutNE1;
728 CutByEdges(in, Wires, out, &OutNE1);
730 for (int i = 1; i <= OutNE1.Extent(); i++)
731 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
735 int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW,
736 TopTools_ListOfShape& outShs, TopTools_IndexedDataMapOfShapeShape* OutNE)
747 TopTools_ListIteratorOfListOfShape anIt;
748 BOPAlgo_Builder anAlgo;
749 anAlgo.AddArgument(InSh);
751 anIt.Initialize( InW );
752 for( ; anIt.More(); anIt.Next() )
753 anAlgo.AddArgument( anIt.Value() );
756 anError = anAlgo.ErrorStatus();
760 outShs = anAlgo.Modified( InSh );
761 if (outShs.IsEmpty())
766 TopTools_IndexedDataMapOfShapeShape NonFOutNE;
767 anIt.Initialize( InW );
768 for( ; anIt.More(); anIt.Next() )
770 const TopoDS_Shape& OSH = anIt.Value();
771 TopExp_Explorer exp(OSH, TopAbs_EDGE);
772 for (;exp.More();exp.Next())
774 const TopoDS_Edge& OE = TopoDS::Edge(exp.Current());
775 const TopTools_ListOfShape& ls = anAlgo.Modified(OE);
776 TopTools_ListIteratorOfListOfShape itls(ls);
777 for (;itls.More();itls.Next())
778 NonFOutNE.Add(itls.Value(), OSH);
782 //filter edges; if face contain an edge => keep it
783 TopTools_IndexedMapOfShape AllEdges; //edges from output shape
784 for (anIt.Initialize(outShs); anIt.More();anIt.Next())
785 TopExp::MapShapes(anIt.Value(), TopAbs_EDGE, AllEdges);
787 for (int i = 1; i <= NonFOutNE.Extent(); i++)
789 const TopoDS_Shape& CE = NonFOutNE.FindKey(i);
790 const TopoDS_Shape& V = NonFOutNE.FindFromIndex(i);
791 if (AllEdges.Contains(CE))