From 6ba81a695f5e233b1da71e5242b1f32bf1debae0 Mon Sep 17 00:00:00 2001 From: ssafarov Date: Mon, 15 Nov 2021 18:15:33 +0300 Subject: [PATCH] 0026174: Data Exchange, IGES - Loss of color after the second write of file A copy of myface is made, where further on the copy the geometry changes. We connect the face, wire, edge of the original shape with the one whose geometry was changed. This is done in order to get the original shape in the TransferWire() and TransferEdge() methods. --- src/BRepToIGES/BRepToIGES_BREntity.cxx | 3 +- src/BRepToIGES/BRepToIGES_BRShell.cxx | 99 +++++++++++--------- src/BRepToIGES/BRepToIGES_BRSolid.cxx | 3 +- src/BRepToIGES/BRepToIGES_BRWire.cxx | 91 ++++++++++-------- src/BRepToIGES/BRepToIGES_BRWire.hxx | 46 ++++----- src/BRepToIGESBRep/BRepToIGESBRep_Entity.cxx | 12 ++- tests/bugs/iges/bug26174 | 45 +++++++++ tests/bugs/xde/bug26174 | 53 ----------- 8 files changed, 187 insertions(+), 165 deletions(-) create mode 100644 tests/bugs/iges/bug26174 delete mode 100644 tests/bugs/xde/bug26174 diff --git a/src/BRepToIGES/BRepToIGES_BREntity.cxx b/src/BRepToIGES/BRepToIGES_BREntity.cxx index 50963f80e7..37d1cba74c 100644 --- a/src/BRepToIGES/BRepToIGES_BREntity.cxx +++ b/src/BRepToIGES/BRepToIGES_BREntity.cxx @@ -146,7 +146,8 @@ Handle(IGESData_IGESEntity) BRepToIGES_BREntity::TransferShape TopoDS_Edge E = TopoDS::Edge(start); BRepToIGES_BRWire BW(*this); BW.SetModel(GetModel()); - res = BW.TransferEdge(E, Standard_False); + TopTools_DataMapOfShapeShape anEmptyMap; + res = BW.TransferEdge(E, anEmptyMap, Standard_False); } else if (start.ShapeType() == TopAbs_WIRE) { TopoDS_Wire W = TopoDS::Wire(start); diff --git a/src/BRepToIGES/BRepToIGES_BRShell.cxx b/src/BRepToIGES/BRepToIGES_BRShell.cxx index 30955574e1..34e5f6dce5 100644 --- a/src/BRepToIGES/BRepToIGES_BRShell.cxx +++ b/src/BRepToIGES/BRepToIGES_BRShell.cxx @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -123,8 +124,14 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& } // pour explorer la face , il faut la mettre fORWARD. - TopoDS_Face myface; + TopoDS_Face aFace = start; + // Associates the input face (start) and its sub-shapes with the reversed variant, + // if the input face has a Reversed orientation + TopTools_DataMapOfShapeShape aShapeShapeMap; if (start.Orientation() == TopAbs_REVERSED) { + BRepBuilderAPI_Copy aCopy; + aCopy.Perform(aFace); + //create face with redirected surface BRep_Builder B; TopLoc_Location aLoc; @@ -133,29 +140,35 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& { // take basis surface, because pcurves will be transformed, so trim will be shifted, // accorded to new face bounds - Handle(Geom_RectangularTrimmedSurface) aTrimmedSurf = + Handle(Geom_RectangularTrimmedSurface) aTrimmedSurf = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf); aSurf = aTrimmedSurf->BasisSurface(); } aSurf = aSurf->UReversed(); Standard_Real aTol = BRep_Tool::Tolerance(start); - B.MakeFace(myface, aSurf, aLoc ,aTol); + B.MakeFace(aFace, aSurf, aLoc, aTol); // set specifics flags of a Face - B.NaturalRestriction(myface, BRep_Tool::NaturalRestriction(start)); + B.NaturalRestriction(aFace, BRep_Tool::NaturalRestriction(start)); //add wires TopoDS_Wire anOuter = TopoDS::Wire(ShapeAlgo::AlgoContainer()->OuterWire(start)); TopExp_Explorer ex; - for (ex.Init(start,TopAbs_WIRE); ex.More(); ex.Next()) { + for (ex.Init(start, TopAbs_WIRE); ex.More(); ex.Next()) { TopoDS_Wire W = TopoDS::Wire(ex.Current()); + TopoDS_Wire aCopyWire = TopoDS::Wire(aCopy.ModifiedShape(W)); + aCopyWire = TopoDS::Wire(aCopyWire.Oriented(W.Orientation())); if (!W.IsNull() && W.IsSame(anOuter)) { - B.Add(myface, W); + B.Add(aFace, aCopyWire); + aShapeShapeMap.Bind(aCopyWire, W); // Bind the reversed copy of Wire to the original break; } - } - for (ex.Init(start,TopAbs_WIRE); ex.More(); ex.Next()) { + } + for (ex.Init(start, TopAbs_WIRE); ex.More(); ex.Next()) { TopoDS_Wire W = TopoDS::Wire(ex.Current()); + TopoDS_Wire aCopyWire = TopoDS::Wire(aCopy.ModifiedShape(W)); + aCopyWire = TopoDS::Wire(aCopyWire.Oriented(W.Orientation())); if (!W.IsNull() && !W.IsSame(anOuter)) { - B.Add(myface, W); + B.Add(aFace, aCopyWire); + aShapeShapeMap.Bind(aCopyWire, W); // Bind the reversed copy of Wire to the original } } @@ -167,43 +180,48 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& gp_Ax2d axis(gp_Pnt2d(aCenter, V1), gp_Dir2d(0.,1.)); T.SetMirror(axis); NCollection_Map aMap (101, new NCollection_IncAllocator); - for (ex.Init(myface,TopAbs_EDGE);ex.More(); ex.Next()) { - TopoDS_Edge anEdge = TopoDS::Edge(ex.Current()); - if (!aMap.Add(anEdge)) + for (ex.Init(start, TopAbs_EDGE); ex.More(); ex.Next()) { + TopoDS_Edge anOrigEdge = TopoDS::Edge(ex.Current()); + TopoDS_Edge aCopyEdge = TopoDS::Edge(aCopy.ModifiedShape(anOrigEdge)); + aCopyEdge = TopoDS::Edge(aCopyEdge.Oriented(anOrigEdge.Orientation())); + if (!aMap.Add(aCopyEdge)) // seam edge has been already updated continue; Standard_Real f, l; Handle(Geom2d_Curve) aCurve1, aCurve2; - aCurve1 = BRep_Tool::CurveOnSurface(anEdge, start, f, l); - aTol = BRep_Tool::Tolerance(anEdge); + aCurve1 = BRep_Tool::CurveOnSurface(aCopyEdge, TopoDS::Face(aCopy.ModifiedShape(start)), f, l); + aTol = BRep_Tool::Tolerance(aCopyEdge); if (!aCurve1.IsNull()) { aCurve1 = Handle(Geom2d_Curve)::DownCast(aCurve1->Transformed(T)); - if (BRepTools::IsReallyClosed(anEdge, start)) { - TopoDS_Edge revEdge = TopoDS::Edge(anEdge.Reversed()); - aCurve2 = BRep_Tool::CurveOnSurface(revEdge, start, f, l); + if (BRepTools::IsReallyClosed(aCopyEdge, TopoDS::Face(aCopy.ModifiedShape(start)))) { + TopoDS_Edge revEdge = TopoDS::Edge(aCopyEdge.Reversed()); + aCurve2 = BRep_Tool::CurveOnSurface(revEdge, TopoDS::Face(aCopy.ModifiedShape(start)), f, l); if (!aCurve2.IsNull()) { aCurve2 = Handle(Geom2d_Curve)::DownCast(aCurve2->Transformed(T)); - if (anEdge.Orientation() == TopAbs_FORWARD) - B.UpdateEdge(anEdge, aCurve1, aCurve2, myface, aTol); + if (aCopyEdge.Orientation() == TopAbs_FORWARD) + { + B.UpdateEdge(aCopyEdge, aCurve1, aCurve2, aFace, aTol); + } else - B.UpdateEdge(anEdge, aCurve2, aCurve1, myface, aTol); + { + B.UpdateEdge(aCopyEdge, aCurve2, aCurve1, aFace, aTol); + } } else { - B.UpdateEdge(anEdge, aCurve1, myface, aTol); + B.UpdateEdge(aCopyEdge, aCurve1, aFace, aTol); } } else { - B.UpdateEdge(anEdge, aCurve1, myface, aTol); + B.UpdateEdge(aCopyEdge, aCurve1, aFace, aTol); } // set range for degenerated edges - if (BRep_Tool::Degenerated(anEdge)) { - B.Range(anEdge, myface, f, l); + if (BRep_Tool::Degenerated(aCopyEdge)) { + B.Range(aCopyEdge, aFace, f, l); } } + aShapeShapeMap.Bind(aCopyEdge, anOrigEdge); // Bind the reversed copy of Edge to the original } - } - else { - myface = start; + aShapeShapeMap.Bind(start, aFace); // Bind the original face to the reversed copy } //Standard_Integer Nb = 0; //szv#4:S4163:12Mar99 unused @@ -213,13 +231,12 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& // returns the face surface // ------------------------ - Handle(Geom_Surface) Surf = BRep_Tool::Surface(myface); - Handle(Geom_Surface) Surf1; + Handle(Geom_Surface) Surf = BRep_Tool::Surface(aFace); if (!Surf.IsNull()) { Standard_Real U1, U2, V1, V2; // pour limiter les surfaces de base - BRepTools::UVBounds(myface, U1, U2, V1, V2); + BRepTools::UVBounds(aFace, U1, U2, V1, V2); GeomToIGES_GeomSurface GS; GS.SetModel(GetModel()); ISurf = GS.TransferSurface(Surf, U1, U2, V1, V2); @@ -228,14 +245,6 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& return res; } Length = GS.Length(); - - // modif mjm du 17/07/97 - if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { - DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf); - Surf1 = rectang->BasisSurface(); - } - else - Surf1 = Surf; } @@ -249,11 +258,11 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& // outer wire //:n3 TopoDS_Wire Outer = BRepTools::OuterWire(myface); - TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(myface); //:n3 + TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(aFace); //:n3 Handle(IGESGeom_CurveOnSurface) IOuter = new IGESGeom_CurveOnSurface; if (!Outer.IsNull()) { Handle(IGESData_IGESEntity) ICurve3d = - BW.TransferWire(Outer, myface, ICurve2d, Length); + BW.TransferWire(Outer, aFace, aShapeShapeMap, ICurve2d, Length); if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3; if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2; if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1; @@ -264,7 +273,7 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& TopExp_Explorer Ex; Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); - for (Ex.Init(myface,TopAbs_WIRE); Ex.More(); Ex.Next()) { + for (Ex.Init(aFace, TopAbs_WIRE); Ex.More(); Ex.Next()) { TopoDS_Wire W = TopoDS::Wire(Ex.Current()); Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface; if (W.IsNull()) { @@ -272,7 +281,7 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& } else if (!W.IsSame(Outer)) { Handle(IGESData_IGESEntity) ICurve3d = - BW.TransferWire(W, myface, ICurve2d, Length); + BW.TransferWire(W, aFace, aShapeShapeMap, ICurve2d, Length); if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3; if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2; if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1; @@ -282,15 +291,15 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& } // all inners edges not in a wire - for (Ex.Init(myface,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) { + for (Ex.Init(aFace,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) { TopoDS_Edge E = TopoDS::Edge(Ex.Current()); Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface; if (E.IsNull()) { AddWarning(start," an Edge is a null entity"); } else { - Handle(IGESData_IGESEntity) ICurve3d = BW.TransferEdge(E, Standard_False); - Handle(IGESData_IGESEntity) newICurve2d = BW.TransferEdge(E, myface, Length, Standard_False); + Handle(IGESData_IGESEntity) ICurve3d = BW.TransferEdge(E, aShapeShapeMap, Standard_False); + Handle(IGESData_IGESEntity) newICurve2d = BW.TransferEdge(E, aFace, aShapeShapeMap, Length, Standard_False); if ((!ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 3; if ((!ICurve3d.IsNull()) && (newICurve2d.IsNull())) Iprefer = 2; if ((ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 1; diff --git a/src/BRepToIGES/BRepToIGES_BRSolid.cxx b/src/BRepToIGES/BRepToIGES_BRSolid.cxx index 6d6e3c1f09..21ababf37b 100644 --- a/src/BRepToIGES/BRepToIGES_BRSolid.cxx +++ b/src/BRepToIGES/BRepToIGES_BRSolid.cxx @@ -306,7 +306,8 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferCompound(const TopoDS_C AddWarning(start," an Edge is a null entity"); } else { - IShape = BW.TransferEdge(S, Standard_False); + TopTools_DataMapOfShapeShape anEmptyMap; + IShape = BW.TransferEdge(S, anEmptyMap, Standard_False); if (!IShape.IsNull()) Seq->Append(IShape); } } diff --git a/src/BRepToIGES/BRepToIGES_BRWire.cxx b/src/BRepToIGES/BRepToIGES_BRWire.cxx index 595a3619d7..6db3258f44 100644 --- a/src/BRepToIGES/BRepToIGES_BRWire.cxx +++ b/src/BRepToIGES/BRepToIGES_BRWire.cxx @@ -111,7 +111,8 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire } else if (start.ShapeType() == TopAbs_EDGE) { TopoDS_Edge E = TopoDS::Edge(start); - res = TransferEdge(E, Standard_False); + TopTools_DataMapOfShapeShape anEmptyMap; + res = TransferEdge(E, anEmptyMap, Standard_False); } else if (start.ShapeType() == TopAbs_WIRE) { TopoDS_Wire W = TopoDS::Wire(start); @@ -249,17 +250,18 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferVertex //============================================================================= Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge -(const TopoDS_Edge& myedge, - const Standard_Boolean isBRepMode) +(const TopoDS_Edge& theEdge, + const TopTools_DataMapOfShapeShape& theOriginMap, + const Standard_Boolean theIsBRepMode) { Handle(IGESData_IGESEntity) res; - if ( myedge.IsNull()) return res; + if (theEdge.IsNull()) return res; // returns the 3d curve of the edge and the parameter range TopLoc_Location L; Standard_Real First, Last, U1, U2; Handle(IGESData_IGESEntity) ICurve; - Handle(Geom_Curve) Curve3d = BRep_Tool::Curve(myedge, L, First, Last); + Handle(Geom_Curve) Curve3d = BRep_Tool::Curve(theEdge, L, First, Last); //#28 rln 19.10.98 UKI60155, etc. //Only Bezier will be converted into B-Spline, not Conic. This conertation @@ -275,7 +277,7 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge else Curve3d = Handle(Geom_Curve)::DownCast(Curve3d->Copy()); - if (myedge.Orientation() == TopAbs_REVERSED && !isBRepMode) { + if (theEdge.Orientation() == TopAbs_REVERSED && !theIsBRepMode) { U1 = Curve3d->ReversedParameter(Last); U2 = Curve3d->ReversedParameter(First); Curve3d->Reverse(); @@ -296,7 +298,9 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge if (!ICurve.IsNull()) res = ICurve; - SetShapeResult ( myedge, res ); + // In the reverted face's case find an origin by the reverted + TopoDS_Edge anEdge = !theOriginMap.IsEmpty() ? TopoDS::Edge(theOriginMap.Find(theEdge)) : theEdge; + SetShapeResult ( anEdge, res ); return res; } @@ -306,22 +310,23 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge // TransferEdge //============================================================================= -Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge (const TopoDS_Edge& myedge, - const TopoDS_Face& myface, - const Standard_Real length, - const Standard_Boolean isBRepMode) +Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge (const TopoDS_Edge& theEdge, + const TopoDS_Face& theFace, + const TopTools_DataMapOfShapeShape& theOriginMap, + const Standard_Real theLength, + const Standard_Boolean theIsBRepMode) { Handle(IGESData_IGESEntity) res; - if ( myedge.IsNull() || GetPCurveMode() ==0 || - ( ! isBRepMode && BRep_Tool::Degenerated ( myedge ) ) ) return res; + if (theEdge.IsNull() || GetPCurveMode() ==0 || + ( ! theIsBRepMode && BRep_Tool::Degenerated (theEdge) ) ) return res; //S4181 pdn 23.04.99 adjusting length factor according to analytic mode. - Standard_Real myLen = length; - Standard_Boolean analyticMode = ( GetConvertSurfaceMode() ==0 && isBRepMode ); + Standard_Real myLen = theLength; + Standard_Boolean analyticMode = ( GetConvertSurfaceMode() ==0 && theIsBRepMode ); - // returns the 2d curve associated to myedge in the parametric space of myface + // returns the 2d curve associated to theEdge in the parametric space of theFace Standard_Real First, Last; - Handle(Geom2d_Curve) Curve2d = BRep_Tool::CurveOnSurface(myedge, myface, First, Last); + Handle(Geom2d_Curve) Curve2d = BRep_Tool::CurveOnSurface(theEdge, theFace, First, Last); Handle(IGESData_IGESEntity) ICurve2d; //#29 rln 19.10.98 @@ -333,12 +338,12 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge (const TopoDS_Edge& // It is necessary to invert (u,v) surfaces of revolution. TopLoc_Location L; - Handle(Geom_Surface) st = BRep_Tool::Surface(myface, L); + Handle(Geom_Surface) st = BRep_Tool::Surface(theFace, L); if (st->IsKind(STANDARD_TYPE(Geom_Plane))){ return res; } Standard_Real Ufirst, Ulast, Vfirst, Vlast; - BRepTools::UVBounds(myface, Ufirst, Ulast, Vfirst, Vlast); + BRepTools::UVBounds(theFace, Ufirst, Ulast, Vfirst, Vlast); Handle(Geom_Surface) Surf; if (st->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { @@ -439,7 +444,7 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge (const TopoDS_Edge& //S4181 transfer functionality gp_Trsf2d trans; Standard_Real uFact = 1.; - if(isBRepMode && Surf->IsKind(STANDARD_TYPE(Geom_Plane))) { + if(theIsBRepMode && Surf->IsKind(STANDARD_TYPE(Geom_Plane))) { trans.SetScale(gp_Pnt2d(0,0),1./GetUnit()); } if(Surf->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) { @@ -485,7 +490,7 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge (const TopoDS_Edge& Curve2d = sbe.TransformPCurve(Curve2d,trans1,1.,First,Last); } - if (myedge.Orientation() == TopAbs_REVERSED) { + if (theEdge.Orientation() == TopAbs_REVERSED) { Standard_Real tmpFirst = Curve2d->ReversedParameter(Last), tmpLast = Curve2d->ReversedParameter(First); Curve2d->Reverse(); @@ -503,7 +508,9 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferEdge (const TopoDS_Edge& if (!ICurve2d.IsNull()) res = ICurve2d; - SetShapeResult ( myedge, res ); + // In the reverted face's case find an origin by the reverted + TopoDS_Edge anEdge = !theOriginMap.IsEmpty() ? TopoDS::Edge(theOriginMap.Find(theEdge)) : theEdge; + SetShapeResult ( anEdge, res ); return res; } @@ -535,7 +542,8 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire AddWarning(mywire, "an Edge is a null entity"); } else { - ent = TransferEdge(E, Standard_False); + TopTools_DataMapOfShapeShape anEmptyMap; + ent = TransferEdge(E, anEmptyMap, Standard_False); if (!ent.IsNull()) Seq->Append(ent); } } @@ -571,13 +579,14 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire //============================================================================= Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire -(const TopoDS_Wire & mywire, - const TopoDS_Face & myface, - Handle(IGESData_IGESEntity)& mycurve2d, - const Standard_Real length) +(const TopoDS_Wire & theWire, + const TopoDS_Face& theFace, + const TopTools_DataMapOfShapeShape& theOriginMap, + Handle(IGESData_IGESEntity)& theCurve2d, + const Standard_Real theLength) { Handle(IGESData_IGESEntity) res; - if ( mywire.IsNull()) return res; + if (theWire.IsNull()) return res; Handle(IGESData_IGESEntity) ent3d ; Handle(IGESData_IGESEntity) ent2d ; @@ -586,45 +595,45 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire // create a 3d CompositeCurve and a 2d CompositeCurve - TopExp_Explorer TE(mywire, TopAbs_VERTEX); + TopExp_Explorer TE(theWire, TopAbs_VERTEX); if ( TE.More()) { // PTV OCC908 workaround for KAS:dev version /* BRepTools_WireExplorer WE; - for ( WE.Init(mywire,myface); WE.More(); WE.Next()) { + for ( WE.Init(theWire,theFace); WE.More(); WE.Next()) { TopoDS_Edge E = WE.Current(); if (E.IsNull()) { - AddWarning(mywire, "an Edge is a null entity"); + AddWarning(theWire, "an Edge is a null entity"); } else { ent3d = TransferEdge(E, Standard_False); if (!ent3d.IsNull()) Seq3d->Append(ent3d); - ent2d = TransferEdge(E, myface, length, Standard_False); + ent2d = TransferEdge(E, theFace, theLength, Standard_False); if (!ent2d.IsNull()) Seq2d->Append(ent2d); } } */ Handle(ShapeFix_Wire) aSFW = - new ShapeFix_Wire( mywire, myface, Precision::Confusion() ); + new ShapeFix_Wire( theWire, theFace, Precision::Confusion() ); aSFW->FixReorder(); Handle(ShapeExtend_WireData) aSEWD = aSFW->WireData(); Standard_Integer nbE = aSEWD->NbEdges(); for (Standard_Integer windex = 1; windex <= nbE; windex++) { TopoDS_Edge E = aSEWD->Edge( windex ); if (E.IsNull()) { - AddWarning(mywire, "an Edge is a null entity"); + AddWarning(theWire, "an Edge is a null entity"); } else { - ent3d = TransferEdge(E, Standard_False); + ent3d = TransferEdge(E, theOriginMap, Standard_False); if (!ent3d.IsNull()) Seq3d->Append(ent3d); - ent2d = TransferEdge(E, myface, length, Standard_False); + ent2d = TransferEdge(E, theFace, theOriginMap, theLength, Standard_False); if (!ent2d.IsNull()) Seq2d->Append(ent2d); } } // OCC908 end of workaround } else - AddWarning(mywire, " no Vertex associated to the Wire"); + AddWarning(theWire, " no Vertex associated to the Wire"); // Composite Curve 3D Standard_Integer nb3d = Seq3d->Length(); @@ -649,7 +658,7 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire Standard_Integer nb2d = Seq2d->Length(); Handle(IGESData_HArray1OfIGESEntity) Tab2d; if ( nb2d == 1 ) { - mycurve2d = ent2d; + theCurve2d = ent2d; } else if (nb2d >= 2) { Tab2d = new IGESData_HArray1OfIGESEntity(1,nb2d); @@ -661,10 +670,12 @@ Handle(IGESData_IGESEntity) BRepToIGES_BRWire ::TransferWire } Handle(IGESGeom_CompositeCurve) Comp = new IGESGeom_CompositeCurve; Comp->Init(Tab2d); - mycurve2d = Comp; + theCurve2d = Comp; } - SetShapeResult ( mywire, res ); + // In the reverted face's case find an origin by the reverted + TopoDS_Wire aWire = !theOriginMap.IsEmpty() ? TopoDS::Wire(theOriginMap.Find(theWire)) : theWire; + SetShapeResult ( aWire, res ); return res; } diff --git a/src/BRepToIGES/BRepToIGES_BRWire.hxx b/src/BRepToIGES/BRepToIGES_BRWire.hxx index 265aa826db..600ec0369f 100644 --- a/src/BRepToIGES/BRepToIGES_BRWire.hxx +++ b/src/BRepToIGES/BRepToIGES_BRWire.hxx @@ -24,6 +24,8 @@ #include #include #include +#include + class IGESData_IGESEntity; class TopoDS_Shape; class TopoDS_Vertex; @@ -90,22 +92,22 @@ public: //! this member returns a NullEntity. Standard_EXPORT Handle(IGESData_IGESEntity) TransferVertex (const TopoDS_Vertex& myvertex, const TopoDS_Face& myface, gp_Pnt2d& mypoint); - //! Transfert an Edge entity from TopoDS to IGES - //! If this Entity could not be converted, - //! this member returns a NullEntity. - //! isBRepMode indicates if write mode is BRep - //! (True when called from BRepToIGESBRep and False when from BRepToIGES) - //! If edge is REVERSED and isBRepMode is False 3D edge curve is reversed, - //! otherwise, not. - Standard_EXPORT Handle(IGESData_IGESEntity) TransferEdge (const TopoDS_Edge& myedge, const Standard_Boolean isBRepMode); + //! Transfert an Edge 3d entity from TopoDS to IGES + //! If edge is REVERSED and isBRepMode is False 3D edge curve is reversed + //! @param[in] theEdge input edge to transfer + //! @param[in] theOriginMap shapemap contains the original shapes. Should be empty if face is not reversed + //! @param[in] theIsBRepMode indicates if write mode is BRep + //! @return Iges entity or null if could not be converted + Standard_EXPORT Handle(IGESData_IGESEntity) TransferEdge (const TopoDS_Edge& theEdge, const TopTools_DataMapOfShapeShape& theOriginMap, const Standard_Boolean theIsBRepMode); - //! Transfert an Edge entity on a Face from TopoDS to IGES - //! If this Entity could not be converted, - //! this member returns a NullEntity. - //! isBRepMode indicates if write mode is BRep - //! (True when called from BRepToIGESBRep and False when from BRepToIGES) - //! passing into Transform2dCurve() - Standard_EXPORT Handle(IGESData_IGESEntity) TransferEdge (const TopoDS_Edge& myedge, const TopoDS_Face& myface, const Standard_Real length, const Standard_Boolean isBRepMode); + //! Transfert an Edge 2d entity on a Face from TopoDS to IGES + //! @param[in] theEdge input edge to transfer + //! @param[in] theFace input face to get the surface and UV coordinates from it + //! @param[in] theOriginMap shapemap contains the original shapes. Should be empty if face is not reversed + //! @param[in] theLength input surface length + //! @param[in] theIsBRepMode indicates if write mode is BRep + //! @return Iges entity or null if could not be converted + Standard_EXPORT Handle(IGESData_IGESEntity) TransferEdge (const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, const TopTools_DataMapOfShapeShape& theOriginMap, const Standard_Real theLength, const Standard_Boolean theIsBRepMode); //! Transfert a Wire entity from TopoDS to IGES //! If this Entity could not be converted, @@ -113,12 +115,14 @@ public: Standard_EXPORT Handle(IGESData_IGESEntity) TransferWire (const TopoDS_Wire& mywire); //! Transfert a Wire entity from TopoDS to IGES. - //! Returns the curve associated to mywire in - //! the parametric space of myface. - //! If this Entity could not be converted, - //! this member returns a NullEntity. - //! Parameter IsRevol is not used anymore - Standard_EXPORT Handle(IGESData_IGESEntity) TransferWire (const TopoDS_Wire& mywire, const TopoDS_Face& myface, Handle(IGESData_IGESEntity)& mycurve2d, const Standard_Real length); + //! @param[in] theWire input wire + //! @param[in] theFace input face + //! @param[in] theOriginMap shapemap contains the original shapes. Should be empty if face is not reversed + //! @param[in] theCurve2d input curve 2d + //! @param[in] theLength input surface length + //! @return Iges entity (the curve associated to mywire in the parametric space of myface) + //! or null if could not be converted + Standard_EXPORT Handle(IGESData_IGESEntity) TransferWire (const TopoDS_Wire& theWire, const TopoDS_Face& theFace, const TopTools_DataMapOfShapeShape& theOriginMap, Handle(IGESData_IGESEntity)& theCurve2d, const Standard_Real theLength); diff --git a/src/BRepToIGESBRep/BRepToIGESBRep_Entity.cxx b/src/BRepToIGESBRep/BRepToIGESBRep_Entity.cxx index f0c2054187..d1e166b633 100644 --- a/src/BRepToIGESBRep/BRepToIGESBRep_Entity.cxx +++ b/src/BRepToIGESBRep/BRepToIGESBRep_Entity.cxx @@ -303,7 +303,8 @@ Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferShape TopoDS_Edge E = TopoDS::Edge(start); BRepToIGES_BRWire BW(*this); BW.SetModel(GetModel()); - res = BW.TransferEdge(E, Standard_False); + TopTools_DataMapOfShapeShape anEmptyMap; + res = BW.TransferEdge(E, anEmptyMap, Standard_False); return res; } else if (start.ShapeType() == TopAbs_WIRE) { @@ -357,7 +358,8 @@ Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferEdge (const TopoDS_E { BRepToIGES_BRWire BR(*this); BR.SetModel(GetModel()); - return BR.TransferEdge (myedge, Standard_True); + TopTools_DataMapOfShapeShape anEmptyMap; + return BR.TransferEdge (myedge, anEmptyMap, Standard_True); } @@ -375,7 +377,8 @@ Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferEdge (const TopoDS_Ed BRepToIGES_BRWire BR(*this); BR.SetModel(GetModel()); - ICurve2d = BR.TransferEdge (myedge, myface, Length, Standard_True); + TopTools_DataMapOfShapeShape anEmptyMap; + ICurve2d = BR.TransferEdge (myedge, myface, anEmptyMap, Length, Standard_True); // curve 3d is obligatory. If it does not exist it is created and stored in "myCurves". // If the edge is degenerated, there is no associated 3d. So "edge-tuple" @@ -897,7 +900,8 @@ Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferCompound (const TopoD BRepToIGES_BRWire BW(*this); BW.SetModel(GetModel()); - IShape = BW.TransferEdge(S, Standard_False); + TopTools_DataMapOfShapeShape anEmptyMap; + IShape = BW.TransferEdge(S, anEmptyMap, Standard_False); if (!IShape.IsNull()) Seq->Append(IShape); } diff --git a/tests/bugs/iges/bug26174 b/tests/bugs/iges/bug26174 new file mode 100644 index 0000000000..ae57337c76 --- /dev/null +++ b/tests/bugs/iges/bug26174 @@ -0,0 +1,45 @@ +puts "============" +puts "0026174: Data Exchange, IGES - Loss of color after the second write of file" +puts "============" + +pload XDE +catch { Close D } +catch { Close D1 } + +box b 0 0 0 10 10 10 +compound b c +XNewDoc D +XAddShape D c 1 +XSetColor D 0:1:1:1:1 1 0 0 + +WriteIges D $imagedir/${casename}_orig.igs +XGetOneShape res D +set dump [dump res] +if { [regexp "Dump of 24 Curve2ds" $dump] != 1 } { + puts "Error: incorrect Curve transfer" +} +WriteIges D $imagedir/${casename}_comp.igs +ReadIges D1 $imagedir/${casename}_comp.igs +XGetOneShape res1 D1 + +vinit view1 +vclear +XDisplay D1 0:1:1:1 +vfit +set ColorD1 [string trim [vreadpixel 204 204 name]] +if {$ColorD1 != "RED 1"} { + puts "Error: expected color of shape from Document1 is RED." +} + +catch {[file delete $imagedir/${casename}_orig.igs]} +catch {[file delete $imagedir/${casename}_comp.igs]} + +checkprops res -equal res1 +set color_orig [XGetAllColors D] +set color_comp [XGetAllColors D1] +if { $color_orig != $color_comp } { + puts "Error: incorrect color transfer" +} + +checknbshapes res -vertex 8 -edge 12 -wire 6 -face 6 +checkview -screenshot -3d -path $imagedir/${test_image}.png diff --git a/tests/bugs/xde/bug26174 b/tests/bugs/xde/bug26174 deleted file mode 100644 index 8575727753..0000000000 --- a/tests/bugs/xde/bug26174 +++ /dev/null @@ -1,53 +0,0 @@ -puts "TODO OCC26174 ALL: ERROR: OCC26174 is reproduced." - -puts "========" -puts "OCC26174" -puts "========" -puts "" -####################################################### -# Loss of color after the second write of file (iges) -####################################################### - -pload DCAF - -set aFileD1 ${imagedir}/${casename}_D1.igs -set aFileD2 ${imagedir}/${casename}_D2.igs - -set anImageD $imagedir/${casename}_D.png -set anImageD1 $imagedir/${casename}_D1.png -set anImageD2 $imagedir/${casename}_D2.png - -box b 0 0 0 10 10 10 -compound b c -NewDocument D -XAddShape D c 1 -XSetColor D 0:1:1:1 1 0 0 - -XShow D -vfit -set ColorD [string trim [vreadpixel 204 204 name]] -vdump $anImageD - -WriteIges D ${aFileD1} -WriteIges D ${aFileD2} - -ReadIges D1 ${aFileD1} -ReadIges D2 ${aFileD2} -file delete -force ${aFileD1} -file delete -force ${aFileD2} - -XShow D1 -vfit -set ColorD1 [string trim [vreadpixel 204 204 name]] -vdump $anImageD1 -if {$ColorD != $ColorD1} { - puts "ERROR: OCC26174 is reproduced. Expected color of shape from Document1 is ${ColorD}, not ${ColorD1}." -} - -XShow D2 -vfit -set ColorD2 [string trim [vreadpixel 204 204 name]] -vdump $anImageD2 -if {$ColorD != $ColorD2} { - puts "ERROR: OCC26174 is reproduced. Expected color of shape from Document2 is ${ColorD}, not ${ColorD2}." -}