1 // Created on: 1994-06-07
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <BRepFill_Pipe.ixx>
24 #include <Standard_ErrorHandler.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRep_Builder.hxx>
28 #include <BRepClass3d_SolidClassifier.hxx>
29 #include <BRepLib_MakeVertex.hxx>
30 #include <BRepTools_Substitution.hxx>
32 #include <GeomFill_CorrectedFrenet.hxx>
33 #include <GeomFill_CurveAndTrihedron.hxx>
35 #include <BRepFill_SectionPlacement.hxx>
36 #include <BRepFill_ShapeLaw.hxx>
37 #include <BRepFill_Edge3DLaw.hxx>
38 #include <BRepFill_Sweep.hxx>
40 #include <GeomAbs_Shape.hxx>
42 #include <TopAbs_ShapeEnum.hxx>
44 #include <TopoDS_Shell.hxx>
45 #include <TopoDS_Solid.hxx>
46 #include <TopoDS_Compound.hxx>
47 #include <TopoDS_Iterator.hxx>
48 #include <TopTools_DataMapOfShapeInteger.hxx>
49 #include <TColStd_DataMapOfIntegerInteger.hxx>
50 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
52 #include <Precision.hxx>
53 #include <Standard_NotImplemented.hxx>
55 #include <Geom_TrimmedCurve.hxx>
56 #include <Geom_OffsetCurve.hxx>
57 #include <Geom_BSplineCurve.hxx>
61 static Standard_Boolean Affich = 0;
64 //=======================================================================
65 //function : BRepFill_Pipe
67 //=======================================================================
69 BRepFill_Pipe::BRepFill_Pipe()
76 //=======================================================================
77 //function : BRepFill_Pipe
79 //=======================================================================
81 BRepFill_Pipe::BRepFill_Pipe(const TopoDS_Wire& Spine,
82 const TopoDS_Shape& Profile,
83 const Standard_Boolean KPart)
87 Perform(Spine, Profile, KPart);
92 //=======================================================================
95 //=======================================================================
97 void BRepFill_Pipe::Perform(const TopoDS_Wire& Spine,
98 const TopoDS_Shape& Profile,
99 const Standard_Boolean KPart)
102 mySections.Nullify();
111 BRepTools_WireExplorer wexp;
112 TopoDS_Shape TheProf;
115 Handle(GeomFill_CorrectedFrenet) TLaw =
116 new (GeomFill_CorrectedFrenet) ();
117 Handle(GeomFill_CurveAndTrihedron) Loc =
118 new (GeomFill_CurveAndTrihedron) (TLaw);
119 myLoc = new (BRepFill_Edge3DLaw) (mySpine, Loc);
120 if (myLoc->NbLaw() == 0) {
121 return; // Degenerated case
123 myLoc->TransformInG0Law(); // Set into continuity
125 BRepFill_SectionPlacement Place(myLoc, Profile);
126 myTrsf = Place.Transformation();
128 TopLoc_Location Loc2(myTrsf), Loc1;
129 Loc1 = Profile.Location();
132 TheProf.Location(Loc2.Multiplied(Loc1));
134 // Construct First && Last Shape
135 Handle(GeomFill_LocationLaw) law;
140 Standard_Real first, last;
141 myLoc->Law(1)->GetDomain(first, last);
142 myLoc->Law(1)->D0(first, M, V);
143 fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
144 M(2,1), M(2,2), M(2,3), V.Y(),
145 M(3,1), M(3,2), M(3,3), V.Z(),
148 fila.Multiply(myTrsf);
149 TopLoc_Location LocFirst(fila);
151 if ( ! LocFirst.IsIdentity()) {
152 myFirst.Location( LocFirst.Multiplied(myProfile.Location()) );
155 myLoc->Law(myLoc->NbLaw())->GetDomain(first, last);
156 myLoc->Law(myLoc->NbLaw())->D0(last,M, V);
157 // try { // Not good, but there are no other means to test SetValues
158 fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
159 M(2,1), M(2,2), M(2,3), V.Y(),
160 M(3,1), M(3,2), M(3,3), V.Z(),
162 fila.Multiply(myTrsf);
163 TopLoc_Location LocLast(fila);
164 if (! myLoc->IsClosed() || LocFirst != LocLast) {
166 if ( ! LocLast.IsIdentity()) {
167 myLast.Location(LocLast.Multiplied(myProfile.Location()) );
175 DBRep::Set("theprof", TheProf);
176 DBRep::Set("thefirst", myFirst);
177 DBRep::Set("thelast" , myLast);
181 myShape = MakeShape(TheProf, myFirst, myLast);
185 //=======================================================================
188 //=======================================================================
190 const TopoDS_Shape& BRepFill_Pipe::Spine() const
195 //=======================================================================
198 //=======================================================================
200 const TopoDS_Shape& BRepFill_Pipe::Profile() const
205 //=======================================================================
208 //=======================================================================
210 const TopoDS_Shape& BRepFill_Pipe::Shape() const
216 //=======================================================================
217 //function : FirstShape
219 //=======================================================================
221 const TopoDS_Shape& BRepFill_Pipe::FirstShape() const
227 //=======================================================================
228 //function : LastShape
230 //=======================================================================
232 const TopoDS_Shape& BRepFill_Pipe::LastShape() const
238 //=======================================================================
241 //=======================================================================
243 TopoDS_Face BRepFill_Pipe::Face(const TopoDS_Edge& ESpine,
244 const TopoDS_Edge& EProfile)
248 if ( BRep_Tool::Degenerated(EProfile))
251 Standard_Integer ii, ispin = 0, iprof = 0, count = 0;
253 // *************************************************
254 // Search if EProfile is an edge of myProfile
255 // *************************************************
256 iprof = FindEdge(myProfile, EProfile, count);
258 if (!iprof) Standard_DomainError::Raise(
259 "BRepFill_Pipe::Face : Edge not in the Profile");
262 // *************************************************
263 // Search if ESpine is an edge of mySpine and find
264 // the index of the corresponding Filler
265 // *************************************************
266 for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++)
267 if (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii;
269 if (!ispin) Standard_DomainError::Raise(
270 "BRepFill_Pipe::Edge : Edge not in the Spine");
272 theFace = TopoDS::Face(myFaces->Value(iprof, ispin));
277 //=======================================================================
280 //=======================================================================
281 TopoDS_Edge BRepFill_Pipe::Edge(const TopoDS_Edge& ESpine,
282 const TopoDS_Vertex& VProfile)
284 Standard_Integer ii, ispin = 0, iprof = 0, count = 0;;
286 // *************************************************
287 // Search if VProfile is a Vertex of myProfile
288 // *************************************************
289 iprof = FindVertex(myProfile, VProfile, count);
290 if (!iprof) Standard_DomainError::Raise(
291 "BRepFill_Pipe::Edge : Vertex not in the Profile");
294 // *************************************************
295 // Search if ESpine is an edge of mySpine and find
296 // the index of the corresponding Filler
297 // *************************************************
299 for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++)
300 if (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii;
302 if (!ispin) Standard_DomainError::Raise(
303 "BRepFill_Pipe::Edge : Edge not in the Spine");
306 // *************************************************
307 // Generate the corresponding Shape
308 // *************************************************
310 theEdge = TopoDS::Edge(myEdges->Value(iprof, ispin));
317 //=======================================================================
320 //=======================================================================
322 TopoDS_Shape BRepFill_Pipe::Section(const TopoDS_Vertex& VSpine) const
324 TopoDS_Iterator it, itv;
326 Standard_Integer ii, ispin = 0;
328 TopoDS_Shape curSect = myProfile;
330 // *************************************************
331 // Search if ESpine is an edge of mySpine and find
332 // the index of the corresponding Filler
333 // *************************************************
335 // iterate on all the edges of mySpine
336 for (ii=1; ii<=myLoc->NbLaw()+1 && (!ispin); ii++)
337 if (VSpine.IsSame(myLoc->Vertex(ii))) ispin = ii;
339 if (!ispin) Standard_DomainError::Raise(
340 "BRepFill_Pipe::Section : Vertex not in the Spine");
343 TopoDS_Compound Comp;
344 B.MakeCompound(Comp);
345 for (ii=1; ii<=mySections->ColLength(); ii++)
346 B.Add(Comp, mySections->Value(ii, ispin));
351 //=======================================================================
352 //function : PipeLine
353 //purpose : Construct a wire by sweeping of a point
354 //=======================================================================
356 TopoDS_Wire BRepFill_Pipe::PipeLine(const gp_Pnt& Point) const
363 BRepLib_MakeVertex MkV(P);
364 Handle(BRepFill_ShapeLaw) Section =
365 new (BRepFill_ShapeLaw) (MkV.Vertex());
368 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
369 MkSw.Build( BRepFill_Modified, GeomFill_Location, GeomAbs_C2, myDegmax, mySegmax );
370 TopoDS_Shape aLocalShape = MkSw.Shape();
371 return TopoDS::Wire(aLocalShape);
372 // return TopoDS::Wire(MkSw.Shape());
375 //=======================================================================
376 //function : MakeShape
378 //=======================================================================
380 TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
381 const TopoDS_Shape& FirstShape,
382 const TopoDS_Shape& LastShape)
386 Standard_Boolean explode = Standard_False;
387 TopoDS_Shape TheS, TheFirst, TheLast;
388 Standard_Integer InitialLength = 0;
390 TheFirst = FirstShape;
392 if (! myFaces.IsNull()) InitialLength = myFaces->ColLength();
394 // there are two kinds of generation
395 // 1. generate with S from each Filler (Vertex, Edge)
396 // 2. call MakeShape recursively on the subshapes of S
398 // explode is True in the second case
400 // create the result empty
402 switch (S.ShapeType()) {
406 B.MakeWire(TopoDS::Wire(result));
413 B.MakeShell(TopoDS::Shell(result));
416 W.Closed(S.Closed());
418 if (!FirstShape.IsNull()) {
420 B.Add(W, FirstShape);
421 W.Closed(FirstShape.Closed());
424 if (!LastShape.IsNull()) {
427 W.Closed(LastShape.Closed());
434 B.MakeShell(TopoDS::Shell(result));
439 B.MakeShell(TopoDS::Shell(result));
440 explode = Standard_True;
441 if ( !mySpine.Closed() && !TheFirst.IsNull()) {
442 B.Add(result, TheFirst.Reversed());
449 B.MakeCompSolid(TopoDS::CompSolid(result));
450 explode = Standard_True;
455 case TopAbs_COMPSOLID :
456 Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
459 case TopAbs_COMPOUND :
461 B.MakeCompound(TopoDS::Compound(result));
462 explode = Standard_True;
471 TopoDS_Iterator itFirst, itLast;
472 TopoDS_Shape first, last;
473 if (!TheFirst.IsNull()) itFirst.Initialize(TheFirst);
474 if (!TheLast.IsNull()) itLast.Initialize(TheLast);
476 for (TopoDS_Iterator it(S); it.More(); it.Next()) {
477 if (!TheFirst.IsNull()) first = itFirst.Value();
478 if (!TheLast.IsNull()) last = itLast.Value();
479 if (TheS.ShapeType() == TopAbs_FACE )
480 MakeShape(it.Value(), first, last);
482 B.Add(result,MakeShape(it.Value(), first, last));
484 if (!TheFirst.IsNull()) itFirst.Next();
485 if (!TheLast.IsNull()) itLast.Next();
490 if (TheS.ShapeType() == TopAbs_VERTEX ) {
491 Handle(BRepFill_ShapeLaw) Section =
492 new (BRepFill_ShapeLaw) (TopoDS::Vertex(TheS));
493 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
494 MkSw.Build( BRepFill_Modified, GeomFill_Location, GeomAbs_C2, myDegmax, mySegmax );
495 result = MkSw.Shape();
498 if (TheS.ShapeType() == TopAbs_WIRE ) {
499 Handle(BRepFill_ShapeLaw) Section =
500 new (BRepFill_ShapeLaw) (TopoDS::Wire(TheS));
501 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
502 MkSw.SetBounds(TopoDS::Wire(TheFirst),
503 TopoDS::Wire(TheLast));
504 MkSw.Build( BRepFill_Modified, GeomFill_Location, GeomAbs_C2, myDegmax, mySegmax );
505 result = MkSw.Shape();
507 // Labeling of elements
508 if (mySections.IsNull()) {
509 myFaces = MkSw.SubShape();
510 mySections = MkSw.Sections();
511 myEdges = MkSw.InterFaces();
514 Handle(TopTools_HArray2OfShape) Aux, Somme;
515 Standard_Integer length;
516 Standard_Integer ii, jj, kk;
517 const Standard_Integer aNbFaces = myFaces->ColLength();
518 const Standard_Integer aNbEdges = myEdges->ColLength();
519 const Standard_Integer aNbSections = mySections->ColLength();
521 Aux = MkSw.SubShape();
522 length = Aux->ColLength() + myFaces->ColLength();
523 Somme = new (TopTools_HArray2OfShape) (1, length, 1,
525 for (jj=1; jj<=myFaces->RowLength(); jj++) {
526 for (ii=1; ii<=myFaces->ColLength(); ii++)
527 Somme->SetValue(ii, jj, myFaces->Value(ii, jj));
529 for (kk=1, ii=myFaces->ColLength()+1;
530 kk <=Aux->ColLength(); kk++, ii++)
531 Somme->SetValue(ii, jj, Aux->Value(kk, jj));
535 Aux = MkSw.Sections();
536 length = Aux->ColLength() + mySections->ColLength();
537 Somme = new (TopTools_HArray2OfShape) (1, length, 1,
539 for (jj=1; jj<=mySections->RowLength(); jj++) {
540 for (ii=1; ii<=mySections->ColLength(); ii++)
541 Somme->SetValue(ii, jj, mySections->Value(ii, jj));
543 for (kk=1, ii=mySections->ColLength()+1;
544 kk <=Aux->ColLength(); kk++, ii++)
545 Somme->SetValue(ii, jj, Aux->Value(kk, jj));
549 Aux = MkSw.InterFaces();
550 length = Aux->ColLength() + myEdges->ColLength();
551 Somme = new (TopTools_HArray2OfShape) (1, length, 1,
553 for (jj=1; jj<=myEdges->RowLength(); jj++) {
554 for (ii=1; ii<=myEdges->ColLength(); ii++)
555 Somme->SetValue(ii, jj, myEdges->Value(ii, jj));
557 for (kk=1, ii=myEdges->ColLength()+1;
558 kk <=Aux->ColLength(); kk++, ii++)
559 Somme->SetValue(ii, jj, Aux->Value(kk, jj));
564 // Perform sharing faces
565 result = ShareFaces(result, aNbFaces, aNbEdges, aNbSections);
570 if ( TheS.ShapeType() == TopAbs_FACE ) {
571 Standard_Integer ii, jj;
573 for (ii=InitialLength+1; ii<=myFaces->ColLength(); ii++) {
574 for (jj=1; jj<=myFaces->RowLength(); jj++) {
575 F = TopoDS::Face(myFaces->Value(ii, jj));
576 if (!F.IsNull()) B.Add(result, F);
580 if ( !mySpine.Closed()) {
581 // if Spine is not closed
582 // add the last face of the solid
583 B.Add(result, TopoDS::Face(TheLast));
590 result.Closed(Standard_True);
591 BS.Add(solid,TopoDS::Shell(result));
593 BRepClass3d_SolidClassifier SC(solid);
594 SC.PerformInfinitePoint(Precision::Confusion());
595 if ( SC.State() == TopAbs_IN) {
597 TopoDS_Shape aLocalShape = result.Reversed();
598 BS.Add(solid,TopoDS::Shell(aLocalShape));
599 // BS.Add(solid,TopoDS::Shell(result.Reversed()));
609 //============================================================================
610 //function : FindEdge
611 //purpose : Find the number of edge corresponding to the edge of the profile.
612 //============================================================================
614 Standard_Integer BRepFill_Pipe::FindEdge(const TopoDS_Shape& S,
615 const TopoDS_Edge& E,
616 Standard_Integer& InitialLength) const
618 Standard_Integer result = 0;
620 switch (S.ShapeType()) {
625 if (S.IsSame(E)) result = InitialLength;
631 Standard_Integer ii = InitialLength+1;
632 Handle(BRepFill_ShapeLaw) Section =
633 new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
634 InitialLength += Section->NbLaw();
636 for (; (ii<=InitialLength) && (!result); ii++) {
637 if (E.IsSame(Section->Edge(ii)) ) result = ii;
644 case TopAbs_COMPOUND :
646 for (TopoDS_Iterator it(S); it.More() && (!result); it.Next())
647 result = FindEdge(it.Value(), E, InitialLength );
652 case TopAbs_COMPSOLID :
653 Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
662 //=======================================================================
663 //function : FindVertex
664 //purpose : Find the number of edge corresponding to an edge of the profile.
665 //=======================================================================
667 Standard_Integer BRepFill_Pipe::FindVertex(const TopoDS_Shape& S,
668 const TopoDS_Vertex& V,
669 Standard_Integer& InitialLength) const
671 Standard_Integer result = 0;
673 switch (S.ShapeType()) {
677 if (S.IsSame(V)) result = InitialLength;
683 TopoDS_Vertex VF, VL;
684 TopExp::Vertices(TopoDS::Edge(S), VF, VL);
685 if (S.Orientation() == TopAbs_REVERSED) {
687 aux = VF; VF = VL; VL = aux;
689 if (VF.IsSame(V)) result = InitialLength+1;
690 else if (VL.IsSame(V)) result = InitialLength+2;
697 Standard_Integer ii = InitialLength+1;
698 Handle(BRepFill_ShapeLaw) Section =
699 new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
700 InitialLength += Section->NbLaw()+1;
702 for (; (ii<=InitialLength) && (!result); ii++) {
703 if (V.IsSame(Section->Vertex(ii, 0.)) ) result = ii;
710 case TopAbs_COMPOUND :
712 for (TopoDS_Iterator it(S); it.More() && (!result); it.Next())
713 result = FindVertex(it.Value(), V, InitialLength);
718 case TopAbs_COMPSOLID :
719 Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
728 //=======================================================================
729 //function : DefineRealSegmax
730 //purpose : Defines the real number of segments
731 // required in the case of bspline spine
732 //=======================================================================
734 void BRepFill_Pipe::DefineRealSegmax()
736 Standard_Integer RealSegmax = 0;
738 TopoDS_Iterator iter(mySpine);
739 for (; iter.More(); iter.Next())
741 TopoDS_Edge E = TopoDS::Edge(iter.Value());
742 Standard_Real first, last;
743 Handle(Geom_Curve) C = BRep_Tool::Curve( E, first, last );
746 while (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve) ||
747 C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
749 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
750 C = (*((Handle(Geom_TrimmedCurve)*)&C))->BasisCurve();
751 if (C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
752 C = (*((Handle(Geom_OffsetCurve)*)&C))->BasisCurve();
754 if (C->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve))
756 const Handle(Geom_BSplineCurve)& BC = *((Handle(Geom_BSplineCurve)*)&C);
757 Standard_Integer NbKnots = BC->NbKnots();
758 Standard_Integer RealNbKnots = NbKnots;
759 if (first > BC->FirstParameter())
761 Standard_Integer I1, I2;
762 BC->LocateU( first, Precision::PConfusion(), I1, I2 );
765 if (last < BC->LastParameter())
767 Standard_Integer I1, I2;
768 BC->LocateU( last, Precision::PConfusion(), I1, I2 );
769 RealNbKnots -= NbKnots-I2;
771 RealSegmax += RealNbKnots-1;
775 if (mySegmax < RealSegmax)
776 mySegmax = RealSegmax;
779 //=======================================================================
780 //function : ShareFaces
782 //=======================================================================
784 TopoDS_Shape BRepFill_Pipe::ShareFaces
785 (const TopoDS_Shape &theShape,
786 const Standard_Integer theInitialFacesLen,
787 const Standard_Integer theInitialEdgesLen,
788 const Standard_Integer theInitialSectionsLen)
790 TopoDS_Shape aResult = theShape;
791 // Check if there are shapes to be shared.
792 TopTools_DataMapOfShapeInteger aMapBndEdgeIndex;
793 TColStd_DataMapOfIntegerInteger aMapNewOldFIndex;
794 TColStd_DataMapOfIntegerInteger aMapNewOldEIndex;
795 TopTools_MapOfShape aMapUsedVtx;
796 TopExp_Explorer anExp;
800 BRep_Builder aBuilder;
802 // Check the first and last J index of myFaces.
803 for (i = 1; i <= 2; i++) {
804 // Compute jj index of faces.
808 jj == myFaces->RowLength();
815 // Fill the map of boundary edges on initial faces.
816 for (ii = 1; ii <= theInitialFacesLen; ii++) {
817 anExp.Init(myFaces->Value(ii, jj), TopAbs_EDGE);
819 for (; anExp.More(); anExp.Next()) {
820 if (aMapBndEdgeIndex.IsBound(anExp.Current())) {
821 // This is not boundary edge. Remove it.
822 aMapBndEdgeIndex.UnBind(anExp.Current());
824 // Add boundary edge.
825 aMapBndEdgeIndex.Bind(anExp.Current(), ii);
830 // Check if edges of newly created faces are shared with old ones.
831 for (ii = theInitialFacesLen + 1; ii <= myFaces->ColLength(); ii++) {
832 anExp.Init(myFaces->Value(ii, jj), TopAbs_EDGE);
834 for (; anExp.More(); anExp.Next()) {
835 if (aMapBndEdgeIndex.IsBound(anExp.Current())) {
836 // This row should be replaced.
837 Standard_Integer anOldIndex = aMapBndEdgeIndex.Find(anExp.Current());
839 aMapNewOldFIndex.Bind(ii, anOldIndex);
841 // Find corresponding new and old edges indices.
843 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV[0], aV[1]);
846 Standard_Integer indV;
848 // Compute jj index of edges.
852 je == myEdges->RowLength();
857 for (j = 0; j < 2; j++) {
858 if (aMapUsedVtx.Contains(aV[j])) {
859 // This vertex is treated.
864 Standard_Integer iEOld = -1;
865 TopoDS_Vertex aVE[2];
867 for (ie = 1; ie <= theInitialEdgesLen; ie++) {
868 const TopoDS_Shape &anEdge = myEdges->Value(ie, je);
870 TopExp::Vertices(TopoDS::Edge(anEdge), aVE[0], aVE[1]);
872 if (aV[j].IsSame(aVE[0]) || aV[j].IsSame(aVE[1])) {
880 for (ie = theInitialEdgesLen+1; ie <= myEdges->ColLength(); ie++) {
881 const TopoDS_Shape &anEdge = myEdges->Value(ie, je);
883 TopExp::Vertices(TopoDS::Edge(anEdge), aVE[0], aVE[1]);
885 if (aV[j].IsSame(aVE[0]) || aV[j].IsSame(aVE[1])) {
886 // This row should be replaced.
887 aMapNewOldEIndex.Bind(ie, iEOld);
888 aMapUsedVtx.Add(aV[j]);
901 if (!aMapNewOldFIndex.IsEmpty()) {
902 TColStd_DataMapIteratorOfDataMapOfIntegerInteger anIter(aMapNewOldFIndex);
903 TopTools_ListOfShape aListShape;
904 BRepTools_Substitution aSubstitute;
906 for (; anIter.More(); anIter.Next()) {
907 const Standard_Integer aNewIndex = anIter.Key();
908 const Standard_Integer anOldIndex = anIter.Value();
910 // Change new faces by old ones.
911 for (jj = 1; jj <= myFaces->RowLength(); jj++) {
912 const TopoDS_Shape &aNewFace = myFaces->Value(aNewIndex, jj);
913 const TopoDS_Shape &anOldFace = myFaces->Value(anOldIndex, jj);
915 if (!aSubstitute.IsCopied(aNewFace)) {
916 aListShape.Append(anOldFace.Oriented(TopAbs_REVERSED));
917 aSubstitute.Substitute(aNewFace, aListShape);
923 // Change new edges by old ones.
924 for (anIter.Initialize(aMapNewOldEIndex); anIter.More(); anIter.Next()) {
925 const Standard_Integer aNewIndex = anIter.Key();
926 const Standard_Integer anOldIndex = anIter.Value();
928 for (jj = 1; jj <= myEdges->RowLength(); jj++) {
929 const TopoDS_Shape &aNewEdge = myEdges->Value(aNewIndex, jj);
930 const TopoDS_Shape &anOldEdge = myEdges->Value(anOldIndex, jj);
932 if (!aSubstitute.IsCopied(aNewEdge)) {
933 aListShape.Append(anOldEdge.Oriented(TopAbs_FORWARD));
934 aSubstitute.Substitute(aNewEdge, aListShape);
937 // Change new vertices by old ones.
938 TopoDS_Iterator aNewIt(aNewEdge);
939 TopoDS_Iterator anOldIt(anOldEdge);
941 for (; aNewIt.More() && anOldIt.More();
942 aNewIt.Next(), anOldIt.Next()) {
943 if (!aNewIt.Value().IsSame(anOldIt.Value())) {
944 if (!aSubstitute.IsCopied(aNewIt.Value())) {
945 aListShape.Append(anOldIt.Value().Oriented(TopAbs_FORWARD));
946 aSubstitute.Substitute(aNewIt.Value(), aListShape);
955 // Perform substitution.
956 aSubstitute.Build(aResult);
958 if (aSubstitute.IsCopied(aResult)) {
960 const TopTools_ListOfShape& listSh = aSubstitute.Copy(aResult);
962 aResult = listSh.First();
964 // Update original faces with copied ones.
965 for (ii = theInitialFacesLen + 1; ii <= myFaces->ColLength(); ii++) {
966 for (jj = 1; jj <= myFaces->RowLength(); jj++) {
967 TopoDS_Shape anOldFace = myFaces->Value(ii, jj); // Copy
969 if (aSubstitute.IsCopied(anOldFace)) {
970 const TopTools_ListOfShape& aList = aSubstitute.Copy(anOldFace);
972 if(!aList.IsEmpty()) {
973 // Store copied face.
974 const TopoDS_Shape &aCopyFace = aList.First();
975 TopAbs_Orientation anOri = anOldFace.Orientation();
976 const Standard_Boolean isShared = aMapNewOldFIndex.IsBound(ii);
979 // Reverse the orientation for shared face.
980 anOri = TopAbs::Reverse(anOri);
983 myFaces->SetValue(ii, jj, aCopyFace.Oriented(anOri));
985 // Check if it is necessary to update PCurves on this face.
987 TopoDS_Face anOldF = TopoDS::Face(anOldFace);
988 TopoDS_Face aCopyF = TopoDS::Face(aCopyFace);
990 anOldF.Orientation(TopAbs_FORWARD);
991 anExp.Init(anOldF, TopAbs_EDGE);
993 for (; anExp.More(); anExp.Next()) {
994 const TopoDS_Shape &anOldEdge = anExp.Current();
996 if (aSubstitute.IsCopied(anOldEdge)) {
997 const TopTools_ListOfShape& aListE =
998 aSubstitute.Copy(anOldEdge);
1000 if(!aListE.IsEmpty()) {
1001 // This edge is copied. Check if there is a PCurve
1003 TopoDS_Edge aCopyE = TopoDS::Edge(aListE.First());
1004 Standard_Real aFirst;
1005 Standard_Real aLast;
1006 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface
1007 (aCopyE, aCopyF, aFirst, aLast);
1009 if (aPCurve.IsNull()) {
1010 // There is no pcurve copy it from the old edge.
1011 TopoDS_Edge anOldE = TopoDS::Edge(anOldEdge);
1013 aPCurve = BRep_Tool::CurveOnSurface
1014 (anOldE, anOldF, aFirst, aLast);
1016 if (aPCurve.IsNull() == Standard_False) {
1017 // Update the shared edge with PCurve from new Face.
1018 Standard_Real aTol = Max(BRep_Tool::Tolerance(anOldE),
1019 BRep_Tool::Tolerance(aCopyE));
1021 aBuilder.UpdateEdge(aCopyE, aPCurve, aCopyF, aTol);
1033 // Update new edges with shared ones.
1034 for (ii = theInitialEdgesLen + 1; ii <= myEdges->ColLength(); ii++) {
1035 for (jj = 1; jj <= myEdges->RowLength(); jj++) {
1036 const TopoDS_Shape &aLocalShape = myEdges->Value(ii, jj);
1038 if (aSubstitute.IsCopied(aLocalShape)) {
1039 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
1041 if(!aList.IsEmpty()) {
1042 const TopAbs_Orientation anOri = TopAbs_FORWARD;
1044 myEdges->SetValue(ii, jj, aList.First().Oriented(anOri));
1050 // Update new sections with shared ones.
1051 for (ii = theInitialSectionsLen+1; ii <= mySections->ColLength(); ii++) {
1052 for (jj = 1; jj <= mySections->RowLength(); jj++) {
1053 const TopoDS_Shape &aLocalShape = mySections->Value(ii, jj);
1055 if (aSubstitute.IsCopied(aLocalShape)) {
1056 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
1058 if(!aList.IsEmpty()) {
1059 const TopAbs_Orientation anOri = TopAbs_FORWARD;
1061 mySections->SetValue(ii, jj, aList.First().Oriented(anOri));