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 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());
647 AddInternalEdges(aDM2, InterPolys, &OutNE);
648 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>::Iterator spit(OutNE);
649 for (;spit.More();spit.Next())
651 const TopoDS_Edge& E = TopoDS::Edge(spit.Key());
654 SplitData SDI(SplitData::Data_IntEdge, E, spit.Value()->GetName());
655 anOutputSplitDataList.append(SDI);
658 // Step 4. Fill output structure.
659 #ifdef DEB_SPLIT_TO_ZONES
660 TCollection_AsciiString aNam4 ("SC_");
662 HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
663 for(int i =1;aMIt.More();aMIt.Next(),i++) {
664 SplitData aDestSplitData;
665 const TopoDS_Shape& aKey = aMIt.Key(); //new
666 aDestSplitData.Shape = aKey;
667 if(aKey.ShapeType() == TopAbs_FACE)
668 aDestSplitData.Type = SplitData::Data_Zone;
670 aDestSplitData.Type = SplitData::Data_Edge;
671 #ifdef DEB_SPLIT_TO_ZONES
672 TCollection_AsciiString aName = aNam4 + i + "_k.brep";
673 BRepTools::Write(aKey,aName.ToCString());
677 QStringList aListOfNames; // names processing
678 const TopTools_ListOfShape& aListOfOld = aMIt.Value();
679 TopTools_ListIteratorOfListOfShape it(aListOfOld);
680 for(int j =1;it.More();it.Next(),j++) {
681 const TopoDS_Shape& aSh = it.Value(); //old
682 if(aDM3.Contains(aSh)) {
683 const QStringList& ObjectNames = aDM3.FindFromKey(aSh);
684 aListOfNames.append(ObjectNames);
685 #ifdef DEB_SPLIT_TO_ZONES
686 TCollection_AsciiString aName = aNam4 + i +"_" + j + "_l.brep";
687 BRepTools::Write(aSh ,aName.ToCString());
690 #ifdef DEB_SPLIT_TO_ZONES
691 TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + "_m.brep";
692 BRepTools::Write(aSh ,aName.ToCString());
693 DEBTRACE(aName.ToCString()<<" = "<< aSh.TShape());
695 if(aBndView.Contains(aSh) && hasLimits) {
696 aListOfNames.append(aBndName);
697 #ifdef DEB_SPLIT_TO_ZONES
698 DEBTRACE(" BndName = "<<aBndName.toStdString());
704 aDestSplitData.ObjectNames = aListOfNames;
705 anOutputSplitDataList.append(aDestSplitData);
706 #ifdef DEB_SPLIT_TO_ZONES
707 QString aStr = aDestSplitData.ObjectNames.join(" ");
708 DEBTRACE("New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size());
712 return anOutputSplitDataList;
715 HYDROData_SplitToZonesTool::SplitDataList
716 HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList )
718 HYDROData_SequenceOfObjects aGeomGroups;
719 Handle(HYDROData_PolylineXY) aPolyline;
720 HYDROData_SequenceOfObjects InterPolys;
722 return Split( theObjectList, aGeomGroups, aPolyline, InterPolys );
725 void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOfShape& DM,
726 const HYDROData_SequenceOfObjects& thePolylines,
727 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
730 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
731 TopTools_ListOfShape Wires;
732 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
733 for (;it.More();it.Next())
735 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
736 const TopoDS_Shape& CW = P->GetShape();
741 HYDROData_DataMapOfShapeListOfShape newDM;
742 TopTools_IndexedDataMapOfShapeShape OutNE1;
743 for (int i = 1; i <= DM.Extent();i++)
745 const TopoDS_Shape& K = DM.FindKey(i);
746 const TopTools_ListOfShape& V = DM.FindFromIndex(i);
747 TopTools_ListOfShape out;
748 if (K.ShapeType() == TopAbs_FACE)
750 CutByEdges(K, Wires, out, &OutNE1, NULL);
751 TopTools_ListIteratorOfListOfShape it(out);
752 for (;it.More(); it.Next())
754 const TopoDS_Shape& NF = it.Value();
760 newDM.Add(K, V); // ignore edges, wires...
763 for (int i = 1; i <= OutNE1.Extent(); i++)
764 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
769 void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in,
770 TopTools_ListOfShape& out,
771 const HYDROData_SequenceOfObjects& thePolylines,
772 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE,
773 TopTools_IndexedDataMapOfShapeListOfShape* OutOrSh2M)
776 HYDROData_SequenceOfObjects::Iterator it(thePolylines);
777 TopTools_ListOfShape Wires;
778 NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> W2P;
779 for (;it.More();it.Next())
781 Handle(HYDROData_PolylineXY) P = Handle(HYDROData_PolylineXY)::DownCast(it.Value());
782 const TopoDS_Shape& CW = P->GetShape();
787 TopTools_IndexedDataMapOfShapeShape OutNE1;
788 CutByEdges(in, Wires, out, &OutNE1, OutOrSh2M);
790 for (int i = 1; i <= OutNE1.Extent(); i++)
791 OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
795 int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW,
796 TopTools_ListOfShape& outShs,
797 TopTools_IndexedDataMapOfShapeShape* OutNE,
798 TopTools_IndexedDataMapOfShapeListOfShape* OInSH2MSH)
809 TopTools_ListIteratorOfListOfShape anIt;
810 BOPAlgo_Builder anAlgo;
811 anAlgo.AddArgument(InSh);
813 anIt.Initialize( InW );
814 for( ; anIt.More(); anIt.Next() )
815 anAlgo.AddArgument( anIt.Value() );
818 if (anAlgo.HasErrors())
821 outShs = anAlgo.Modified( InSh );
822 if (outShs.IsEmpty())
827 TopTools_IndexedDataMapOfShapeShape NonFOutNE;
828 anIt.Initialize( InW );
829 for( ; anIt.More(); anIt.Next() )
831 const TopoDS_Shape& OSH = anIt.Value();
832 TopExp_Explorer exp(OSH, TopAbs_EDGE);
833 for (;exp.More();exp.Next())
835 const TopoDS_Edge& OE = TopoDS::Edge(exp.Current());
836 const TopTools_ListOfShape& ls = anAlgo.Modified(OE);
837 TopTools_ListIteratorOfListOfShape itls(ls);
838 for (;itls.More();itls.Next())
839 NonFOutNE.Add(itls.Value(), OSH);
843 //filter edges; if face contain an edge => keep it
844 TopTools_IndexedMapOfShape AllEdges; //edges from output shape
845 for (anIt.Initialize(outShs); anIt.More();anIt.Next())
846 TopExp::MapShapes(anIt.Value(), TopAbs_EDGE, AllEdges);
848 for (int i = 1; i <= NonFOutNE.Extent(); i++)
850 const TopoDS_Shape& CE = NonFOutNE.FindKey(i);
851 const TopoDS_Shape& V = NonFOutNE.FindFromIndex(i);
852 if (AllEdges.Contains(CE))
857 //map all sub-shapes from the original InSh to modified shapes
860 TopTools_IndexedMapOfShape allSh;
861 TopExp::MapShapes(InSh, allSh);
862 for(int i = 1; i <= allSh.Extent(); i++ )
864 const TopoDS_Shape& or_sh = allSh(i);
865 const TopTools_ListOfShape& ls = anAlgo.Modified(or_sh);
866 OInSH2MSH->Add(or_sh, ls);