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>
49 //#define DEB_SPLIT_TO_ZONES 1
50 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
51 #if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
52 #include <BRepTools.hxx>
53 static TCollection_AsciiString fileNameBefore("BeforeTranslation");
57 #include "HYDRO_trace.hxx"
59 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
65 if ( Shape.ShapeType() == TopAbs_FACE )
67 aResFace = TopoDS::Face( Shape );
69 else if ( Shape.ShapeType() == TopAbs_WIRE )
71 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( Shape ), Standard_True );
73 if( aMakeFace.IsDone() )
74 aResFace = aMakeFace.Face();
81 Standard_Boolean HYDROData_SplitToZonesTool::buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace)
84 BRepGProp::LinearProperties(theBndWire,G);
85 const gp_Pnt& aCPnt = G.CentreOfMass();
87 BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion());
89 aPln = fndPlane.Plane()->Pln();
91 aPln = gp_Pln(aCPnt, gp::OZ().Direction());
92 BRepBuilderAPI_MakeFace aMkFace(aPln, theBndWire);
93 if(aMkFace.IsDone()) {
94 outFace = aMkFace.Face();
95 if(!outFace.IsNull()) {
96 #ifdef DEB_SPLIT_TO_ZONES
97 // BRepTools::Write(limFace,"FL.brep");
102 return Standard_False;
104 //======================================================================================
106 void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter)
108 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
109 if(!theNameBefore.isNull() && !theNameBefore.isEmpty())
111 TCollection_AsciiString aName (theNameBefore.toStdString().data());
112 fileNameBefore = aName;
114 if(!theNameAfter.isNull() && !theNameAfter.isEmpty())
116 TCollection_AsciiString aName (theNameAfter.toStdString().data());
117 HYDROData_Transform::SetFileName (aName);
121 //======================================================================================
122 bool HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp,
123 HYDROData_Transform& theTool)
126 theTool.SetArgument(theComp);
128 const Standard_Boolean bToTransform = theTool.ToTransform();
129 theTool.SetToTransform(bToTransform);
131 return theTool.HasErrors();
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 TopTools_IndexedDataMapOfShapeListOfShape OutOrSh2M;
231 CutFaceByEdges(SD.Face(), newshs, InterPolys, &OutNE, &OutOrSh2M);
232 for (TopTools_ListIteratorOfListOfShape it(newshs); it.More(); it.Next())
235 NSD.Shape = it.Value();
236 anOutputSplitDataList.append(NSD);
239 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
240 for (;spit.More();spit.Next())
242 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
245 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
246 anOutputSplitDataList.append(SDI);
250 //check CutFaceByEdges method: ensure that SD.Face() edges fully covered by
251 //history map (OutOrSh2M)
252 if (!OutOrSh2M.IsEmpty())
254 TopTools_IndexedMapOfShape EE;
255 TopExp::MapShapes(SD.Face(), TopAbs_EDGE, EE);
257 for (int i = 1; i <= EE.Extent(); i++)
259 const TopoDS_Shape& E = EE(i);
260 noncontNb += !OutOrSh2M.Contains(E);
262 //noncontNb > 0 => some problem with edge history
263 assert(noncontNb == 0);
267 if(!theGroupsList.IsEmpty() )
269 SplitDataList ModifInpGroupList;
270 SplitDataListIterator it(anInputGroupList);
271 while( it.hasNext() )
273 const SplitData& SData = it.next();
274 if (SData.Type != SplitData::Data_Edge)
275 ModifInpGroupList.append(SData); //add as is
276 const TopoDS_Shape& SData_sh = SData.Shape;
277 TopTools_ListOfShape modif_ls;
278 if (!InterPolys.IsEmpty())
279 if (OutOrSh2M.Contains(SData_sh))
280 modif_ls = OutOrSh2M.FindFromKey(SData_sh);
281 //else TODO - show message that one of the object should be updated
284 if (!InterPolys.IsEmpty() && OutOrSh2M.IsEmpty())
287 if (modif_ls.IsEmpty())
288 ModifInpGroupList.append(SData); //non modified
291 TopTools_ListIteratorOfListOfShape itl_modif(modif_ls);
292 for (;itl_modif.More();itl_modif.Next())
294 const TopoDS_Shape& CSH = itl_modif.Value();
295 if (CSH.ShapeType() == TopAbs_EDGE)
298 NewSData.ObjectNames = SData.ObjectNames;
299 NewSData.Type = SData.Type;
300 NewSData.Shape = CSH;
301 ModifInpGroupList.append(NewSData);
307 anOutputSplitDataList.append(ModifInpGroupList);
309 return anOutputSplitDataList;
312 limplus1Object = true;// size =1 && hasLimits
314 HYDROData_DataMapOfShapeListOfString aDM3;
315 if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
316 QStringList aListOfNames;
317 for (int i=0;i < anInputGroupList.size() ;i++) {
318 const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
319 aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames);
323 // Step 1. Prepare Partition structures.
324 TopoDS_Shape aResult;
325 TopTools_ListOfShape aLS;
326 QStringList aListOfNames;
327 TopoDS_Compound aCmp;
329 aBB.MakeCompound(aCmp);
330 for (int i=0;i < anInputSplitDataList.size() ;i++) {
331 const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
332 aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames);
335 #ifdef DEB_SPLIT_TO_ZONES
336 TCollection_AsciiString aName = aNam + i + "_b.brep";
337 BRepTools::Write(aSh, aName.ToCString());
340 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
341 TCollection_AsciiString aNameBefore = fileNameBefore + "_c.brep";
342 BRepTools::Write(aCmp, aNameBefore.ToCString());
345 HYDROData_DataMapOfShapeListOfShape aDM1;
346 if(anInputSplitDataList.size() > 1) {
347 HYDROData_Transform splitTool;
348 bool anErr = SplitFaces(aCmp, splitTool);
350 return anOutputSplitDataList;
351 aResult = splitTool.Shape();
352 if (aResult.IsNull())
353 return anOutputSplitDataList;
354 BRepCheck_Analyzer aCheck (aResult);
355 if(!aCheck.IsValid()) {
356 #ifdef DEB_SPLIT_TO_ZONES
357 DEBTRACE("result is not valid");
358 BRepTools::Write(aResult, "SplitFacesNV.brep");
360 return anOutputSplitDataList;
362 #ifdef DEB_SPLIT_TO_ZONES
363 BRepTools::Write(aResult, "SplitFacesV.brep");
366 // Step 3. Collect history
367 //HYDROData_DataMapOfShapeListOfShape aDM1;
368 TopTools_ListIteratorOfListOfShape anIt(aLS);
369 #ifdef DEB_SPLIT_TO_ZONES
370 TCollection_AsciiString aNamM ("EdgM_");
371 TCollection_AsciiString aNamG ("EdgG_");
373 for (int i =1;anIt.More();anIt.Next(),i++) {
374 Standard_Boolean foundF(Standard_False);
375 const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
376 if(!aListOfNew.IsEmpty())
377 foundF = Standard_True;
379 TopTools_ListOfShape aList;
381 TopTools_ListIteratorOfListOfShape it(aListOfNew);
382 for(;it.More();it.Next())
383 aList.Append(it.Value());
384 /* *********************************************************************
385 // Bug in History: partition should give only modified entities! => temporary solution is used
386 //const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
387 //if(!aListOfGen.IsEmpty())
388 //foundF = Standard_True;
389 //it.Initialize(aListOfGen);
390 //for(;it.More();it.Next())
391 // aList.Append(it.Value());
392 ********************************************************************* */
393 if(!foundF) // face is not modified
394 aList.Append (anIt.Value());
395 aDM1.Add(anIt.Value(), aList);
396 #ifdef DEB_SPLIT_TO_ZONES
397 TCollection_AsciiString aName;
399 if(!anInputGroupList.isEmpty() ) { // 1
400 TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
401 for (int j =1;exp.More();exp.Next(),j++) {
403 Standard_Boolean foundE(Standard_False);
404 const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());
406 DEBTRACE("NB_EDGE_M = " << aListM.Extent());
408 if(aListM.Extent()) foundE = Standard_True;
409 it.Initialize(aListM);
410 for(int k=1;it.More();it.Next(),k++) {
411 aList.Append(it.Value());
412 #ifdef DEB_SPLIT_TO_ZONES
413 aName = aNamM + i + j +k +"_d.brep";
414 BRepTools::Write(it.Value(),aName.ToCString());
417 /* *********************************************************************
418 //const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
419 //if(aListG.Extent()) foundE = Standard_True;
420 //it.Initialize(aListG);
421 //for(int k=1;it.More();it.Next(),k++)
422 //aList.Append(it.Value());
423 //cout << "NB_EDGE = " << aList.Extent() <<endl;
424 ************************************************************************** */
426 aList.Append (exp.Current());
427 #ifdef DEB_SPLIT_TO_ZONES
428 aName = aNamG + i + j +"_e.brep";
429 BRepTools::Write(exp.Current(),aName.ToCString());
430 DEBTRACE(aName.ToCString()<< " = " << exp.Current().TShape());
433 aDM1.Add(exp.Current(), aList);
438 aResult = anInputSplitDataList.at(0).Shape; // get single input shape
441 // aDM2: NewShape ==> ListOfOldShapes
442 HYDROData_DataMapOfShapeListOfShape aDM2;
443 // make limiting face
444 HYDROData_DataMapOfShapeListOfShape aDM4;
445 Standard_Boolean hasLimits(Standard_False);
447 HYDROData_MapOfShape aBndView;
448 if (! thePolyline.IsNull()) {
449 Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape;
450 int nbWires = thePolyline->GetNbConnectedWires(aConnectedWires);
451 const TopoDS_Wire aBndWire = TopoDS::Wire(aConnectedWires->Value(1));
452 if(!aBndWire.IsNull()) {
454 if(buildLimFace(aBndWire, limFace)) {
455 TopoDS_Shape aComResult;
456 BRepAlgoAPI_Common mkCom(aResult, limFace);
458 aComResult = mkCom.Shape();
459 BRepCheck_Analyzer aCheck (aComResult);
460 if(aCheck.IsValid()) {
461 #ifdef DEB_SPLIT_TO_ZONES
462 BRepTools::Write(aComResult,"CommonV.brep");
463 BRepTools::Write(limFace,"limFace.brep");
465 aBndName = thePolyline->GetName();
466 hasLimits = Standard_True; // DM2 should be filled here
467 TopExp_Explorer exp (limFace, TopAbs_EDGE);
468 for (int i =1;exp.More();exp.Next(),i++) {
469 const TopoDS_Shape& anEdge = exp.Current();
470 if(anEdge.IsNull()) continue;
471 aBndView.Add(anEdge);
472 QStringList aListOfNames;
473 aListOfNames.append(aBndName);
474 aDM3.Add(anEdge, aListOfNames);
475 TopTools_ListOfShape aList;
476 aList.Append(anEdge);
477 aDM1.Add(anEdge,aList);
479 HYDROData_MapOfShape aView;
480 exp.Init (aResult, TopAbs_FACE);
481 for (int i =1;exp.More();exp.Next(),i++) {
482 const TopoDS_Shape& aFace = exp.Current();
483 if(!aFace.IsNull()) {
484 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
486 DEBTRACE("Modified: " << aListOfNew.Extent());
488 if(!aListOfNew.IsEmpty()) {
489 aDM4.Add(aFace, aListOfNew);
490 #ifdef DEB_SPLIT_TO_ZONES
491 TCollection_AsciiString aName = aNam + i + "_f.brep";
492 BRepTools::Write(aListOfNew.Last(), aName.ToCString());
496 if(!mkCom.IsDeleted(aFace)) {
497 const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);
498 if(!aListOfGen.IsEmpty()) {
499 /* aDM4.Bind(aFace, aListOfGen); ??? */
500 #ifdef DEB_SPLIT_TO_ZONES
501 TCollection_AsciiString aName = aNam + i + "_g.brep";
502 BRepTools::Write(aListOfGen.Last(), aName.ToCString());
506 TopTools_ListOfShape aList;
508 aDM4.Add(aFace, aList); //the same face - not modified
512 TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
513 for (int j =1;exp2.More();exp2.Next(),j++) {
514 const TopoDS_Shape& anEdge = exp2.Current();
515 if(!anEdge.IsNull()) {
516 if(aView.Contains(anEdge)) continue;
518 const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
519 if(!aListOfNewEd.IsEmpty())
520 aDM4.Add(anEdge, aListOfNewEd);
522 if(!mkCom.IsDeleted(anEdge)) {
523 const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
524 if(!aListOfGenEd.IsEmpty()) {
525 /* aDM4.Bind(anEdge, aListOfGenEd); ???*/
527 TopTools_ListOfShape aList;
528 aList.Append(anEdge);
529 aDM4.Add(anEdge, aList);//the same edge - not modified
536 } //end DM4 filling (phase 1)
537 //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
538 // phase 2 (from tool)
539 #ifdef DEB_SPLIT_TO_ZONES
540 TCollection_AsciiString aNam("BndEd_");
542 TopExp_Explorer expt (limFace, TopAbs_EDGE);
543 for(int i =1;expt.More();expt.Next(),i++) {
544 const TopoDS_Shape& anEdge = expt.Current();
545 if(!anEdge.IsNull()) {
546 const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
547 #ifdef DEB_SPLIT_TO_ZONES
548 TopTools_ListIteratorOfListOfShape itl(aListOfNewEd);
549 for(int j=1;itl.More();itl.Next(),j++) {
550 TCollection_AsciiString aName = aNam + i + "_" + j + "_j.brep";
551 BRepTools::Write(itl.Value(), aName.ToCString());
552 DEBTRACE(aName.ToCString()<<" = "<< itl.Value().TShape());
555 if(!aListOfNewEd.IsEmpty())
556 aDM4.Add(anEdge, aListOfNewEd);
558 if(!mkCom.IsDeleted(anEdge)) {
559 const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
560 if(!aListOfGenEd.IsEmpty()) {
561 /* aDM4.Bind(anEdge, aListOfGenEd); ??? */
563 TopTools_ListOfShape aList;
564 aList.Append(anEdge);
565 aDM4.Add(anEdge, aList);//the same edge - not modified
571 //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
573 // fill DM1 (old - new) and DM2 (new - old)
574 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
575 for(;mIt.More();mIt.Next()) {
576 const TopoDS_Shape& aKey = mIt.Key();//old
577 TopTools_ListOfShape aList;
579 const TopTools_ListOfShape& aListOfNew = mIt.Value();
580 aDM1.Add(aKey, aListOfNew);
581 TopTools_ListIteratorOfListOfShape it(aListOfNew);
582 for(;it.More();it.Next()) {
583 if(!aDM2.Contains(it.Value()))
584 aDM2.Add(it.Value(), aList);
586 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
592 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
593 //DM4 contains Old - New after common op. DM1: old - new after Split op.
594 for(;aMIt.More();aMIt.Next()) {
595 const TopoDS_Shape& aKey = aMIt.Key();
596 TopTools_ListOfShape aList;
598 const TopTools_ListOfShape& aListOfNew = aMIt.Value();
599 TopTools_ListIteratorOfListOfShape it(aListOfNew);
600 for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
601 if(!aDM4.Contains(it.Value())) // bi - is deleted
602 continue; // go to the next bi
604 const TopTools_ListOfShape& aListOfNew4 = aDM4.FindFromKey(it.Value());
605 TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
606 for(;it4.More();it4.Next()) {
607 if(!aDM2.Contains(it4.Value()))
608 aDM2.Add(it4.Value(), aList);
610 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it4.Value());
619 hasLimits = Standard_False;
620 #ifdef DEB_SPLIT_TO_ZONES
621 BRepTools::Write(aComResult,"CommonNV.brep");
627 }// end limits processing
629 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
630 for(;aMIt.More();aMIt.Next()) {
631 const TopoDS_Shape& aKey = aMIt.Key();
632 TopTools_ListOfShape aList;
634 const TopTools_ListOfShape& aListOfNew = aMIt.Value();
635 TopTools_ListIteratorOfListOfShape it(aListOfNew);
636 for(;it.More();it.Next()) {
637 if(!aDM2.Contains(it.Value()))
638 aDM2.Add(it.Value(), aList);
640 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
648 #ifdef DEB_SPLIT_TO_ZONES
650 TopoDS_Compound cmp2;
651 B.MakeCompound(cmp2);
652 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape dIt(aDM2);
653 for(int i =1;dIt.More();dIt.Next(),i++)
655 const TopoDS_Shape& aKey = dIt.Key();
660 AddInternalEdges(aDM2, InterPolys, &OutNE);
661 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
662 for (;spit.More();spit.Next())
664 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
667 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
668 anOutputSplitDataList.append(SDI);
671 // Step 4. Fill output structure.
672 #ifdef DEB_SPLIT_TO_ZONES
673 TCollection_AsciiString aNam4 ("SC_");
675 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
676 for(int i =1;aMIt.More();aMIt.Next(),i++) {
677 SplitData aDestSplitData;
678 const TopoDS_Shape& aKey = aMIt.Key(); //new
679 aDestSplitData.Shape = aKey;
680 if(aKey.ShapeType() == TopAbs_FACE)
681 aDestSplitData.Type = SplitData::Data_Zone;
683 aDestSplitData.Type = SplitData::Data_Edge;
684 #ifdef DEB_SPLIT_TO_ZONES
685 TCollection_AsciiString aName = aNam4 + i + "_k.brep";
686 BRepTools::Write(aKey,aName.ToCString());
690 QStringList aListOfNames; // names processing
691 const TopTools_ListOfShape& aListOfOld = aMIt.Value();
692 TopTools_ListIteratorOfListOfShape it(aListOfOld);
693 for(int j =1;it.More();it.Next(),j++) {
694 const TopoDS_Shape& aSh = it.Value(); //old
695 if(aDM3.Contains(aSh)) {
696 const QStringList& ObjectNames = aDM3.FindFromKey(aSh);
697 aListOfNames.append(ObjectNames);
698 #ifdef DEB_SPLIT_TO_ZONES
699 TCollection_AsciiString aName = aNam4 + i +"_" + j + "_l.brep";
700 BRepTools::Write(aSh ,aName.ToCString());
703 #ifdef DEB_SPLIT_TO_ZONES
704 TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + "_m.brep";
705 BRepTools::Write(aSh ,aName.ToCString());
706 DEBTRACE(aName.ToCString()<<" = "<< aSh.TShape());
708 if(aBndView.Contains(aSh) && hasLimits) {
709 aListOfNames.append(aBndName);
710 #ifdef DEB_SPLIT_TO_ZONES
711 DEBTRACE(" BndName = "<<aBndName.toStdString());
717 aDestSplitData.ObjectNames = aListOfNames;
718 anOutputSplitDataList.append(aDestSplitData);
719 #ifdef DEB_SPLIT_TO_ZONES
720 QString aStr = aDestSplitData.ObjectNames.join(" ");
721 DEBTRACE("New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size());
725 return anOutputSplitDataList;
728 HYDROData_SplitToZonesTool::SplitDataList
729 HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList )
731 HYDROData_SequenceOfObjects aGeomGroups;
732 Handle(HYDROData_PolylineXY) aPolyline;
733 HYDROData_SequenceOfObjects InterPolys;
735 return Split( theObjectList, aGeomGroups, aPolyline, InterPolys );
738 void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
739 const HYDROData_SequenceOfObjects& thePolylines,
740 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
743 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
744 TopTools_ListOfShape Wires;
745 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
746 for (;it.More();it.Next())
748 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
749 const TopoDS_Shape& CW = P->GetShape();
754 HYDROData_DataMapOfShapeListOfShape newDM;
755 TopTools_IndexedDataMapOfShapeShape OutNE1;
758 TopoDS_Compound cmpDM;
759 BB.MakeCompound(cmpDM);
760 TopTools_ListOfShape out;
762 for (int i = 1; i <= DM.Extent();i++)
764 const TopoDS_Shape& K = DM.FindKey(i);
768 TopTools_IndexedDataMapOfShapeListOfShape OInSH2MSH;
769 CutByEdges(cmpDM, Wires, out, true, &OutNE1, &OInSH2MSH);
771 for (int i = 1; i <= DM.Extent();i++)
773 const TopoDS_Shape& K = DM.FindKey(i);
774 const TopTools_ListOfShape& V = DM.FindFromIndex(i);
775 const TopTools_ListOfShape* modifSh = OInSH2MSH.Seek(K);
776 if (modifSh && !modifSh->IsEmpty())
778 TopTools_ListIteratorOfListOfShape it(*modifSh);
779 for (;it.More(); it.Next())
781 const TopoDS_Shape& NF = it.Value();
787 newDM.Add(K, V); //was not modified by bop (CutByEdges)
792 for (int i = 1; i <= OutNE1.Extent(); i++)
793 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
798 void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in,
799 TopTools_ListOfShape& out,
800 const HYDROData_SequenceOfObjects& thePolylines,
801 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE,
802 TopTools_IndexedDataMapOfShapeListOfShape* OutOrSh2M)
805 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
806 TopTools_ListOfShape Wires;
807 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
808 for (;it.More();it.Next())
810 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
811 const TopoDS_Shape& CW = P->GetShape();
816 TopTools_IndexedDataMapOfShapeShape OutNE1;
817 CutByEdges(in, Wires, out, false, &OutNE1, OutOrSh2M);
819 for (int i = 1; i <= OutNE1.Extent(); i++)
820 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
824 int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW,
825 TopTools_ListOfShape& outShs,
827 TopTools_IndexedDataMapOfShapeShape* OutNE,
828 TopTools_IndexedDataMapOfShapeListOfShape* OInSH2MSH)
839 TopTools_ListIteratorOfListOfShape anIt;
840 BOPAlgo_Builder anAlgo;
841 anAlgo.AddArgument(InSh);
843 anIt.Initialize( InW );
844 for( ; anIt.More(); anIt.Next() )
845 anAlgo.AddArgument( anIt.Value() );
848 if (anAlgo.HasErrors())
853 outShs = anAlgo.Modified( InSh );
854 if (outShs.IsEmpty())
859 TopoDS_Shape Res = anAlgo.Shape();
865 TopTools_IndexedDataMapOfShapeShape NonFOutNE;
866 anIt.Initialize( InW );
867 for( ; anIt.More(); anIt.Next() )
869 const TopoDS_Shape& OSH = anIt.Value();
870 TopExp_Explorer exp(OSH, TopAbs_EDGE);
871 for (;exp.More();exp.Next())
873 const TopoDS_Edge& OE = TopoDS::Edge(exp.Current());
874 const TopTools_ListOfShape& ls = anAlgo.Modified(OE);
875 TopTools_ListIteratorOfListOfShape itls(ls);
876 for (;itls.More();itls.Next())
877 NonFOutNE.Add(itls.Value(), OSH);
881 //filter edges; if face contain an edge => keep it
882 TopTools_IndexedMapOfShape AllEdges; //edges from output shape
883 for (anIt.Initialize(outShs); anIt.More();anIt.Next())
884 TopExp::MapShapes(anIt.Value(), TopAbs_EDGE, AllEdges);
886 for (int i = 1; i <= NonFOutNE.Extent(); i++)
888 const TopoDS_Shape& CE = NonFOutNE.FindKey(i);
889 const TopoDS_Shape& V = NonFOutNE.FindFromIndex(i);
890 if (AllEdges.Contains(CE))
895 //map all sub-shapes from the original InSh to modified shapes
898 TopTools_IndexedMapOfShape allSh;
899 TopExp::MapShapes(InSh, allSh);
900 for(int i = 1; i <= allSh.Extent(); i++ )
902 const TopoDS_Shape& or_sh = allSh(i);
903 const TopTools_ListOfShape& ls = anAlgo.Modified(or_sh);
904 OInSH2MSH->Add(or_sh, ls);