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)
142 SplitDataList anOutputSplitDataList;
143 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> OutNE;
144 if(theObjectList.IsEmpty())
145 return anOutputSplitDataList;
147 // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape.
148 SplitDataList anInputSplitDataList;
149 #ifdef DEB_SPLIT_TO_ZONES
150 TCollection_AsciiString aNam("Faces_");
152 for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
154 Handle(HYDROData_Entity) anObj = theObjectList.Value( anIndex );
157 Handle(HYDROData_Object) aGeomObj = Handle(HYDROData_Object)::DownCast( anObj );
158 if( !aGeomObj.IsNull() ) {
159 aShape = aGeomObj->GetTopShape();
162 if ( aShape.IsNull() )
164 #ifdef DEB_SPLIT_TO_ZONES
165 TCollection_AsciiString aName = aNam + anIndex + "_a.brep";
166 BRepTools::Write(aShape, aName.ToCString());
168 if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
169 // Create split data for each face contained in the compound
170 TopExp_Explorer anExp( aShape, TopAbs_FACE );
171 for ( ; anExp.More(); anExp.Next() ) {
172 const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() );
173 if ( !aFace.IsNull() ) {
174 SplitData aSplitData( SplitData::Data_Zone, aFace, anObj->GetName() );
175 anInputSplitDataList.append( aSplitData );
179 SplitData aSplitData( SplitData::Data_Zone, aShape, anObj->GetName() );
180 anInputSplitDataList.append( aSplitData );
184 SplitDataList anInputGroupList;
185 for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ )
187 Handle(HYDROData_ShapesGroup) aGeomGroup =
188 Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
189 if( aGeomGroup.IsNull() )
192 TopTools_SequenceOfShape aGroupShapes;
193 aGeomGroup->GetShapes( aGroupShapes );
194 for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
195 const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i );
196 if ( aGroupShape.IsNull() )
199 if ( aGroupShape.ShapeType() == TopAbs_COMPOUND ) {
200 TopExp_Explorer anExp( aGroupShape, TopAbs_EDGE );
201 for ( ; anExp.More(); anExp.Next() ) {
202 const TopoDS_Edge& anEdge = TopoDS::Edge( anExp.Current() );
203 if ( !anEdge.IsNull() ) {
204 SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
205 anInputGroupList.append( aSplitData );
209 SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
210 anInputGroupList.append( aSplitData );
211 #ifdef DEB_SPLIT_TO_ZONES
212 QString aStr = aSplitData.ObjectNames.join(" ");
213 DEBTRACE("Group# = " <<anIndex <<" Nmb in grp = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size());
218 // If only one shape is given we don't split it
219 // algorithm just returns the unpacked input data
220 bool limplus1Object(false);
221 if(theObjectList.Size() == 1 )
223 if(thePolyline.IsNull())
225 //anOutputSplitDataList.append(anInputSplitDataList);
226 SplitData SD = anInputSplitDataList.at(0);
227 TopTools_ListOfShape newshs;
228 CutFaceByEdges(SD.Face(), newshs, InterPolys, &OutNE);
229 for (TopTools_ListIteratorOfListOfShape it(newshs); it.More(); it.Next())
232 NSD.Shape = it.Value();
233 anOutputSplitDataList.append(NSD);
236 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
237 for (;spit.More();spit.Next())
239 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
242 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
243 anOutputSplitDataList.append(SDI);
246 if(!theGroupsList.IsEmpty() )
247 anOutputSplitDataList.append(anInputGroupList);
248 return anOutputSplitDataList;
251 limplus1Object = true;// size =1 && hasLimits
253 HYDROData_DataMapOfShapeListOfString aDM3;
254 if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
255 QStringList aListOfNames;
256 for (int i=0;i < anInputGroupList.size() ;i++) {
257 const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
258 aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames);
262 // Step 1. Prepare Partition structures.
263 TopoDS_Shape aResult;
264 BOPCol_ListOfShape aLS;
265 QStringList aListOfNames;
266 TopoDS_Compound aCmp;
268 aBB.MakeCompound(aCmp);
269 for (int i=0;i < anInputSplitDataList.size() ;i++) {
270 const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
271 aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames);
274 #ifdef DEB_SPLIT_TO_ZONES
275 TCollection_AsciiString aName = aNam + i + "_b.brep";
276 BRepTools::Write(aSh, aName.ToCString());
279 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
280 TCollection_AsciiString aNameBefore = fileNameBefore + "_c.brep";
281 BRepTools::Write(aCmp, aNameBefore.ToCString());
284 HYDROData_DataMapOfShapeListOfShape aDM1;
285 if(anInputSplitDataList.size() > 1) {
286 HYDROData_Transform splitTool;
287 const Standard_Integer anErr = SplitFaces(aCmp, splitTool);
289 return anOutputSplitDataList;
290 aResult = splitTool.Shape();
291 if (aResult.IsNull())
292 return anOutputSplitDataList;
293 BRepCheck_Analyzer aCheck (aResult);
294 if(!aCheck.IsValid()) {
295 #ifdef DEB_SPLIT_TO_ZONES
296 DEBTRACE("result is not valid");
297 BRepTools::Write(aResult, "SplitFacesNV.brep");
299 return anOutputSplitDataList;
301 #ifdef DEB_SPLIT_TO_ZONES
302 BRepTools::Write(aResult, "SplitFacesV.brep");
305 // Step 3. Collect history
306 //HYDROData_DataMapOfShapeListOfShape aDM1;
307 BOPCol_ListIteratorOfListOfShape anIt(aLS);
308 #ifdef DEB_SPLIT_TO_ZONES
309 TCollection_AsciiString aNamM ("EdgM_");
310 TCollection_AsciiString aNamG ("EdgG_");
312 for (int i =1;anIt.More();anIt.Next(),i++) {
313 Standard_Boolean foundF(Standard_False);
314 const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
315 if(!aListOfNew.IsEmpty())
316 foundF = Standard_True;
318 TopTools_ListOfShape aList;
320 TopTools_ListIteratorOfListOfShape it(aListOfNew);
321 for(;it.More();it.Next())
322 aList.Append(it.Value());
323 /* *********************************************************************
324 // Bug in History: partition should give only modified entities! => temporary solution is used
325 //const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
326 //if(!aListOfGen.IsEmpty())
327 //foundF = Standard_True;
328 //it.Initialize(aListOfGen);
329 //for(;it.More();it.Next())
330 // aList.Append(it.Value());
331 ********************************************************************* */
332 if(!foundF) // face is not modified
333 aList.Append (anIt.Value());
334 aDM1.Add(anIt.Value(), aList);
335 #ifdef DEB_SPLIT_TO_ZONES
336 TCollection_AsciiString aName;
338 if(!anInputGroupList.isEmpty() ) { // 1
339 TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
340 for (int j =1;exp.More();exp.Next(),j++) {
342 Standard_Boolean foundE(Standard_False);
343 const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());
344 DEBTRACE("NB_EDGE_M = " << aListM.Extent());
345 if(aListM.Extent()) foundE = Standard_True;
346 it.Initialize(aListM);
347 for(int k=1;it.More();it.Next(),k++) {
348 aList.Append(it.Value());
349 #ifdef DEB_SPLIT_TO_ZONES
350 aName = aNamM + i + j +k +"_d.brep";
351 BRepTools::Write(it.Value(),aName.ToCString());
354 /* *********************************************************************
355 //const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
356 //if(aListG.Extent()) foundE = Standard_True;
357 //it.Initialize(aListG);
358 //for(int k=1;it.More();it.Next(),k++)
359 //aList.Append(it.Value());
360 //cout << "NB_EDGE = " << aList.Extent() <<endl;
361 ************************************************************************** */
363 aList.Append (exp.Current());
364 #ifdef DEB_SPLIT_TO_ZONES
365 aName = aNamG + i + j +"_e.brep";
366 BRepTools::Write(exp.Current(),aName.ToCString());
367 DEBTRACE(aName.ToCString()<< " = " << exp.Current().TShape());
370 aDM1.Add(exp.Current(), aList);
375 aResult = anInputSplitDataList.at(0).Shape; // get single input shape
378 // aDM2: NewShape ==> ListOfOldShapes
379 HYDROData_DataMapOfShapeListOfShape aDM2;
380 // make limiting face
381 HYDROData_DataMapOfShapeListOfShape aDM4;
382 Standard_Boolean hasLimits(Standard_False);
384 HYDROData_MapOfShape aBndView;
385 if (! thePolyline.IsNull()) {
386 Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape;
387 int nbWires = thePolyline->GetNbConnectedWires(aConnectedWires);
388 const TopoDS_Wire aBndWire = TopoDS::Wire(aConnectedWires->Value(1));
389 if(!aBndWire.IsNull()) {
391 if(buildLimFace(aBndWire, limFace)) {
392 TopoDS_Shape aComResult;
393 BRepAlgoAPI_Common mkCom(aResult, limFace);
395 aComResult = mkCom.Shape();
396 BRepCheck_Analyzer aCheck (aComResult);
397 if(aCheck.IsValid()) {
398 #ifdef DEB_SPLIT_TO_ZONES
399 BRepTools::Write(aComResult,"CommonV.brep");
400 BRepTools::Write(limFace,"limFace.brep");
402 aBndName = thePolyline->GetName();
403 hasLimits = Standard_True; // DM2 should be filled here
404 TopExp_Explorer exp (limFace, TopAbs_EDGE);
405 for (int i =1;exp.More();exp.Next(),i++) {
406 const TopoDS_Shape& anEdge = exp.Current();
407 if(anEdge.IsNull()) continue;
408 aBndView.Add(anEdge);
409 QStringList aListOfNames;
410 aListOfNames.append(aBndName);
411 aDM3.Add(anEdge, aListOfNames);
412 TopTools_ListOfShape aList;
413 aList.Append(anEdge);
414 aDM1.Add(anEdge,aList);
416 HYDROData_MapOfShape aView;
417 exp.Init (aResult, TopAbs_FACE);
418 for (int i =1;exp.More();exp.Next(),i++) {
419 const TopoDS_Shape& aFace = exp.Current();
420 if(!aFace.IsNull()) {
421 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
422 DEBTRACE("Modified: " << aListOfNew.Extent());
423 if(!aListOfNew.IsEmpty()) {
424 aDM4.Add(aFace, aListOfNew);
425 #ifdef DEB_SPLIT_TO_ZONES
426 TCollection_AsciiString aName = aNam + i + "_f.brep";
427 BRepTools::Write(aListOfNew.Last(), aName.ToCString());
431 if(!mkCom.IsDeleted(aFace)) {
432 const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);
433 if(!aListOfGen.IsEmpty()) {
434 /* aDM4.Bind(aFace, aListOfGen); ??? */
435 #ifdef DEB_SPLIT_TO_ZONES
436 TCollection_AsciiString aName = aNam + i + "_g.brep";
437 BRepTools::Write(aListOfGen.Last(), aName.ToCString());
441 TopTools_ListOfShape aList;
443 aDM4.Add(aFace, aList); //the same face - not modified
447 TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
448 for (int j =1;exp2.More();exp2.Next(),j++) {
449 const TopoDS_Shape& anEdge = exp2.Current();
450 if(!anEdge.IsNull()) {
451 if(aView.Contains(anEdge)) continue;
453 const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
454 if(!aListOfNewEd.IsEmpty())
455 aDM4.Add(anEdge, aListOfNewEd);
457 if(!mkCom.IsDeleted(anEdge)) {
458 const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
459 if(!aListOfGenEd.IsEmpty()) {
460 /* aDM4.Bind(anEdge, aListOfGenEd); ???*/
462 TopTools_ListOfShape aList;
463 aList.Append(anEdge);
464 aDM4.Add(anEdge, aList);//the same edge - not modified
471 } //end DM4 filling (phase 1)
472 //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
473 // phase 2 (from tool)
474 #ifdef DEB_SPLIT_TO_ZONES
475 TCollection_AsciiString aNam("BndEd_");
477 TopExp_Explorer expt (limFace, TopAbs_EDGE);
478 for(int i =1;expt.More();expt.Next(),i++) {
479 const TopoDS_Shape& anEdge = expt.Current();
480 if(!anEdge.IsNull()) {
481 const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
482 #ifdef DEB_SPLIT_TO_ZONES
483 TopTools_ListIteratorOfListOfShape itl(aListOfNewEd);
484 for(int j=1;itl.More();itl.Next(),j++) {
485 TCollection_AsciiString aName = aNam + i + "_" + j + "_j.brep";
486 BRepTools::Write(itl.Value(), aName.ToCString());
487 DEBTRACE(aName.ToCString()<<" = "<< itl.Value().TShape());
490 if(!aListOfNewEd.IsEmpty())
491 aDM4.Add(anEdge, aListOfNewEd);
493 if(!mkCom.IsDeleted(anEdge)) {
494 const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
495 if(!aListOfGenEd.IsEmpty()) {
496 /* aDM4.Bind(anEdge, aListOfGenEd); ??? */
498 TopTools_ListOfShape aList;
499 aList.Append(anEdge);
500 aDM4.Add(anEdge, aList);//the same edge - not modified
506 //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
508 // fill DM1 (old - new) and DM2 (new - old)
509 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
510 for(;mIt.More();mIt.Next()) {
511 const TopoDS_Shape& aKey = mIt.Key();//old
512 TopTools_ListOfShape aList;
514 const TopTools_ListOfShape& aListOfNew = mIt.Value();
515 aDM1.Add(aKey, aListOfNew);
516 TopTools_ListIteratorOfListOfShape it(aListOfNew);
517 for(;it.More();it.Next()) {
518 if(!aDM2.Contains(it.Value()))
519 aDM2.Add(it.Value(), aList);
521 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
527 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
528 //DM4 contains Old - New after common op. DM1: old - new after Split op.
529 for(;aMIt.More();aMIt.Next()) {
530 const TopoDS_Shape& aKey = aMIt.Key();
531 TopTools_ListOfShape aList;
533 const TopTools_ListOfShape& aListOfNew = aMIt.Value();
534 TopTools_ListIteratorOfListOfShape it(aListOfNew);
535 for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
536 if(!aDM4.Contains(it.Value())) // bi - is deleted
537 continue; // go to the next bi
539 const TopTools_ListOfShape& aListOfNew4 = aDM4.FindFromKey(it.Value());
540 TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
541 for(;it4.More();it4.Next()) {
542 if(!aDM2.Contains(it4.Value()))
543 aDM2.Add(it4.Value(), aList);
545 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it4.Value());
554 hasLimits = Standard_False;
555 #ifdef DEB_SPLIT_TO_ZONES
556 BRepTools::Write(aComResult,"CommonNV.brep");
562 }// end limits processing
564 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
565 for(;aMIt.More();aMIt.Next()) {
566 const TopoDS_Shape& aKey = aMIt.Key();
567 TopTools_ListOfShape aList;
569 const TopTools_ListOfShape& aListOfNew = aMIt.Value();
570 TopTools_ListIteratorOfListOfShape it(aListOfNew);
571 for(;it.More();it.Next()) {
572 if(!aDM2.Contains(it.Value()))
573 aDM2.Add(it.Value(), aList);
575 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
582 AddInternalEdges(aDM2, InterPolys, &OutNE);
583 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
584 for (;spit.More();spit.Next())
586 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
589 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
590 anOutputSplitDataList.append(SDI);
593 // Step 4. Fill output structure.
594 #ifdef DEB_SPLIT_TO_ZONES
595 TCollection_AsciiString aNam4 ("SC_");
597 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
598 for(int i =1;aMIt.More();aMIt.Next(),i++) {
599 SplitData aDestSplitData;
600 const TopoDS_Shape& aKey = aMIt.Key(); //new
601 aDestSplitData.Shape = aKey;
602 if(aKey.ShapeType() == TopAbs_FACE)
603 aDestSplitData.Type = SplitData::Data_Zone;
605 aDestSplitData.Type = SplitData::Data_Edge;
606 #ifdef DEB_SPLIT_TO_ZONES
607 TCollection_AsciiString aName = aNam4 + i + "_k.brep";
608 BRepTools::Write(aKey,aName.ToCString());
612 QStringList aListOfNames; // names processing
613 const TopTools_ListOfShape& aListOfOld = aMIt.Value();
614 TopTools_ListIteratorOfListOfShape it(aListOfOld);
615 for(int j =1;it.More();it.Next(),j++) {
616 const TopoDS_Shape& aSh = it.Value(); //old
617 if(aDM3.Contains(aSh)) {
618 const QStringList& ObjectNames = aDM3.FindFromKey(aSh);
619 aListOfNames.append(ObjectNames);
620 #ifdef DEB_SPLIT_TO_ZONES
621 TCollection_AsciiString aName = aNam4 + i +"_" + j + "_l.brep";
622 BRepTools::Write(aSh ,aName.ToCString());
625 #ifdef DEB_SPLIT_TO_ZONES
626 TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + "_m.brep";
627 BRepTools::Write(aSh ,aName.ToCString());
628 DEBTRACE(aName.ToCString()<<" = "<< aSh.TShape());
630 if(aBndView.Contains(aSh) && hasLimits) {
631 aListOfNames.append(aBndName);
632 #ifdef DEB_SPLIT_TO_ZONES
633 DEBTRACE(" BndName = "<<aBndName.toStdString());
639 aDestSplitData.ObjectNames = aListOfNames;
640 anOutputSplitDataList.append(aDestSplitData);
641 #ifdef DEB_SPLIT_TO_ZONES
642 QString aStr = aDestSplitData.ObjectNames.join(" ");
643 DEBTRACE("New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size());
647 return anOutputSplitDataList;
650 HYDROData_SplitToZonesTool::SplitDataList
651 HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList )
653 HYDROData_SequenceOfObjects aGeomGroups;
654 Handle(HYDROData_PolylineXY) aPolyline;
655 HYDROData_SequenceOfObjects InterPolys;
657 return Split( theObjectList, aGeomGroups, aPolyline, InterPolys );
660 void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
661 const HYDROData_SequenceOfObjects& thePolylines,
662 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
665 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
666 TopTools_ListOfShape Wires;
667 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
668 for (;it.More();it.Next())
670 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
671 const TopoDS_Shape& CW = P->GetShape();
676 HYDROData_DataMapOfShapeListOfShape newDM;
677 TopTools_IndexedDataMapOfShapeShape OutNE1;
678 for (int i = 1; i <= DM.Extent();i++)
680 const TopoDS_Shape& K = DM.FindKey(i);
681 const TopTools_ListOfShape& V = DM.FindFromIndex(i);
682 TopTools_ListOfShape out;
683 if (K.ShapeType() == TopAbs_FACE)
685 CutByEdges(K, Wires, out, &OutNE1);
686 TopTools_ListIteratorOfListOfShape it(out);
687 for (;it.More(); it.Next())
689 const TopoDS_Shape& NF = it.Value();
695 newDM.Add(K, V); // ignore edges, wires...
698 for (int i = 1; i <= OutNE1.Extent(); i++)
699 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
704 void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in,
705 TopTools_ListOfShape& out,
706 const HYDROData_SequenceOfObjects& thePolylines,
707 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
710 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
711 TopTools_ListOfShape Wires;
712 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
713 for (;it.More();it.Next())
715 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
716 const TopoDS_Shape& CW = P->GetShape();
721 TopTools_IndexedDataMapOfShapeShape OutNE1;
722 CutByEdges(in, Wires, out, &OutNE1);
724 for (int i = 1; i <= OutNE1.Extent(); i++)
725 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
729 int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW,
730 TopTools_ListOfShape& outShs, TopTools_IndexedDataMapOfShapeShape* OutNE)
741 TopTools_ListIteratorOfListOfShape anIt;
742 BOPAlgo_Builder anAlgo;
743 anAlgo.AddArgument(InSh);
745 anIt.Initialize( InW );
746 for( ; anIt.More(); anIt.Next() )
747 anAlgo.AddArgument( anIt.Value() );
750 anError = anAlgo.ErrorStatus();
754 outShs = anAlgo.Modified( InSh );
755 if (outShs.IsEmpty())
760 TopTools_IndexedDataMapOfShapeShape NonFOutNE;
761 anIt.Initialize( InW );
762 for( ; anIt.More(); anIt.Next() )
764 const TopoDS_Shape& OSH = anIt.Value();
765 TopExp_Explorer exp(OSH, TopAbs_EDGE);
766 for (;exp.More();exp.Next())
768 const TopoDS_Edge& OE = TopoDS::Edge(exp.Current());
769 const TopTools_ListOfShape& ls = anAlgo.Modified(OE);
770 TopTools_ListIteratorOfListOfShape itls(ls);
771 for (;itls.More();itls.Next())
772 NonFOutNE.Add(itls.Value(), OSH);
776 //filter edges; if face contain an edge => keep it
777 TopTools_IndexedMapOfShape AllEdges; //edges from output shape
778 for (anIt.Initialize(outShs); anIt.More();anIt.Next())
779 TopExp::MapShapes(anIt.Value(), TopAbs_EDGE, AllEdges);
781 for (int i = 1; i <= NonFOutNE.Extent(); i++)
783 const TopoDS_Shape& CE = NonFOutNE.FindKey(i);
784 const TopoDS_Shape& V = NonFOutNE.FindFromIndex(i);
785 if (AllEdges.Contains(CE))