+ // aDM2: NewShape ==> ListOfOldShapes
+ HYDROData_DataMapOfShapeListOfShape aDM2;
+ // 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.Add(anEdge, aListOfNames);
+ TopTools_ListOfShape aList;
+ aList.Append(anEdge);
+ aDM1.Add(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.Add(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.Add(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.Add(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.Add(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.Add(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.Add(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.Add(aKey, aListOfNew);
+ TopTools_ListIteratorOfListOfShape it(aListOfNew);
+ for(;it.More();it.Next()) {
+ if(!aDM2.Contains(it.Value()))
+ aDM2.Add(it.Value(), aList);
+ else {
+ TopTools_ListOfShape& aList = aDM2.ChangeFromKey(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.Contains(it.Value())) // bi - is deleted
+ continue; // go to the next bi
+ else {
+ const TopTools_ListOfShape& aListOfNew4 = aDM4.FindFromKey(it.Value());
+ TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
+ for(;it4.More();it4.Next()) {
+ if(!aDM2.Contains(it4.Value()))
+ aDM2.Add(it4.Value(), aList);
+ else {
+ TopTools_ListOfShape& aList = aDM2.ChangeFromKey(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.Contains(it.Value()))
+ aDM2.Add(it.Value(), aList);
+ else {
+ TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
+ aList.Prepend(aKey);