+ // make limiting face
+ HYDROData_DataMapOfShapeListOfShape aDM4;
+ Standard_Boolean hasLimits(Standard_False);
+ QString aBndName;
+ HYDROData_MapOfShape aBndView;
+ if (! thePolyline.IsNull()) {
+ const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape());
+ if(!aBndWire.IsNull()) {
+ TopoDS_Face limFace;
+ if(buildLimFace(aBndWire, limFace)) {
+ TopoDS_Shape aComResult;
+ BRepAlgoAPI_Common mkCom(aResult, limFace);
+ if(mkCom.IsDone()) {
+ aComResult = mkCom.Shape();
+ BRepCheck_Analyzer aCheck (aComResult);
+ if(aCheck.IsValid()) {
+#ifdef DEB_SPLIT_TO_ZONES
+ BRepTools::Write(aComResult,"CommonV.brep");
+ BRepTools::Write(limFace,"limFace.brep");
+#endif
+ aBndName = thePolyline->GetName();
+ hasLimits = Standard_True; // DM2 should be filled here
+ TopExp_Explorer exp (limFace, TopAbs_EDGE);
+ for (int i =1;exp.More();exp.Next(),i++) {
+ const TopoDS_Shape& anEdge = exp.Current();
+ if(anEdge.IsNull()) continue;
+ aBndView.Add(anEdge);
+ QStringList aListOfNames;
+ aListOfNames.append(aBndName);
+ aDM3.Bind(anEdge, aListOfNames);
+ TopTools_ListOfShape aList;
+ aList.Append(anEdge);
+ aDM1.Bind(anEdge,aList);
+ }
+ HYDROData_MapOfShape aView;
+ exp.Init (aResult, TopAbs_FACE);
+ for (int i =1;exp.More();exp.Next(),i++) {
+ const TopoDS_Shape& aFace = exp.Current();
+ if(!aFace.IsNull()) {
+ const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
+ //cout << "Modified: " << aListOfNew.Extent() <<endl;
+ if(!aListOfNew.IsEmpty()) {
+ aDM4.Bind(aFace, aListOfNew);
+#ifdef DEB_SPLIT_TO_ZONES
+ //TCollection_AsciiString aName = aNam + i + ".brep";
+ //BRepTools::Write(aListOfNew.Last(), aName.ToCString());
+#endif
+ }
+ else {
+ if(!mkCom.IsDeleted(aFace)) {
+ const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);
+ if(!aListOfGen.IsEmpty()) {
+ aDM4.Bind(aFace, aListOfGen);
+#ifdef DEB_SPLIT_TO_ZONES
+ //TCollection_AsciiString aName = aNam + i + "g.brep";
+ //BRepTools::Write(aListOfGen.Last(), aName.ToCString());
+#endif
+ }
+ else {
+ TopTools_ListOfShape aList;
+ aList.Append(aFace);
+ aDM4.Bind(aFace, aList); //the same face - not modified
+ }
+ }
+ }
+ TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
+ for (int j =1;exp2.More();exp2.Next(),j++) {
+ const TopoDS_Shape& anEdge = exp2.Current();
+ if(!anEdge.IsNull()) {
+ if(aView.Contains(anEdge)) continue;
+ aView.Add(anEdge);
+ const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
+ if(!aListOfNewEd.IsEmpty())
+ aDM4.Bind(anEdge, aListOfNewEd);
+ else {
+ if(!mkCom.IsDeleted(anEdge)) {
+ const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
+ if(!aListOfGenEd.IsEmpty()) {
+ aDM4.Bind(anEdge, aListOfGenEd);
+ } else {
+ TopTools_ListOfShape aList;
+ aList.Append(anEdge);
+ aDM4.Bind(anEdge, aList);//the same edge - not modified
+ }
+ }
+ }
+ }
+ }
+ }
+ } //end DM4 filling (phase 1)
+ //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
+ // phase 2 (from tool)
+#ifdef DEB_SPLIT_TO_ZONES
+ TCollection_AsciiString aNam("BndEd_");
+#endif
+ TopExp_Explorer expt (limFace, TopAbs_EDGE);
+ for(int i =1;expt.More();expt.Next(),i++) {
+ const TopoDS_Shape& anEdge = expt.Current();
+ if(!anEdge.IsNull()) {
+ const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
+#ifdef DEB_SPLIT_TO_ZONES
+ TopTools_ListIteratorOfListOfShape itl(aListOfNewEd);
+ for(int j=1;itl.More();itl.Next(),j++) {
+ TCollection_AsciiString aName = aNam + i + "_" + j + ".brep";
+ BRepTools::Write(itl.Value(), aName.ToCString());
+ cout <<aName.ToCString()<<" = "<< itl.Value().TShape() <<endl;
+ }
+#endif
+ if(!aListOfNewEd.IsEmpty())
+ aDM4.Bind(anEdge, aListOfNewEd);
+ else {
+ if(!mkCom.IsDeleted(anEdge)) {
+ const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
+ if(!aListOfGenEd.IsEmpty()) {
+ aDM4.Bind(anEdge, aListOfGenEd);
+ } else {
+ TopTools_ListOfShape aList;
+ aList.Append(anEdge);
+ aDM4.Bind(anEdge, aList);//the same edge - not modified
+ }
+ }
+ }
+ }
+ }
+ //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
+ if(limplus1Object) {
+ // fill DM1 (old - new) and DM2 (new - old)
+ HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
+ for(;mIt.More();mIt.Next()) {
+ const TopoDS_Shape& aKey = mIt.Key();//old
+ TopTools_ListOfShape aList;
+ aList.Append(aKey);
+ const TopTools_ListOfShape& aListOfNew = mIt.Value();
+ aDM1.Bind(aKey, aListOfNew);
+ TopTools_ListIteratorOfListOfShape it(aListOfNew);
+ for(;it.More();it.Next()) {
+ if(!aDM2.IsBound(it.Value()))
+ aDM2.Bind(it.Value(), aList);
+ else {
+ TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
+ aList.Prepend(aKey);
+ }
+ }
+ }
+ } else {
+ HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
+ //DM4 contains Old - New after common op. DM1: old - new after Split op.
+ for(;aMIt.More();aMIt.Next()) {
+ const TopoDS_Shape& aKey = aMIt.Key();
+ TopTools_ListOfShape aList;
+ aList.Append(aKey);
+ const TopTools_ListOfShape& aListOfNew = aMIt.Value();
+ TopTools_ListIteratorOfListOfShape it(aListOfNew);
+ for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
+ if(!aDM4.IsBound(it.Value())) // bi - is deleted
+ continue; // go to the next bi
+ else {
+ const TopTools_ListOfShape& aListOfNew4 = aDM4.Find(it.Value());
+ TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
+ for(;it4.More();it4.Next()) {
+ if(!aDM2.IsBound(it4.Value()))
+ aDM2.Bind(it4.Value(), aList);
+ else {
+ TopTools_ListOfShape& aList = aDM2.ChangeFind(it4.Value());
+ aList.Prepend(aKey);
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ hasLimits = Standard_False;
+#ifdef DEB_SPLIT_TO_ZONES
+ BRepTools::Write(aComResult,"CommonNV.brep");
+#endif
+ }
+ }
+ }
+ }
+ }// end limits processing
+ if(!hasLimits) {
+ HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
+ for(;aMIt.More();aMIt.Next()) {
+ const TopoDS_Shape& aKey = aMIt.Key();
+ TopTools_ListOfShape aList;
+ aList.Append(aKey);
+ const TopTools_ListOfShape& aListOfNew = aMIt.Value();
+ TopTools_ListIteratorOfListOfShape it(aListOfNew);
+ for(;it.More();it.Next()) {
+ if(!aDM2.IsBound(it.Value()))
+ aDM2.Bind(it.Value(), aList);
+ else {
+ TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
+ aList.Prepend(aKey);
+ }
+ }
+ }