1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-08 18:40:55 +03:00

0032817: Data Exchange - Step export - writing untrimmed Curve

Incorrect curve handling.
If curve doesn't have trims and vertexes, we handle it such as trimmed curve, but it should be a simple curve.
Curves with only one vertex and one trim should handle by another way, such as a curve that has trims but doesn't have vertexes.
So I added conditions which handles these cases
This commit is contained in:
atychini 2022-02-07 15:57:38 +03:00 committed by smoskvin
parent 9140163ba8
commit 452ba192d5
4 changed files with 173 additions and 108 deletions

@ -151,166 +151,192 @@ static Handle(StepGeom_TrimmedCurve) MakeTrimmedCurve (const Handle(StepGeom_Cur
} }
Standard_Boolean TopoDSToStep_WireframeBuilder:: Standard_Boolean TopoDSToStep_WireframeBuilder::
GetTrimmedCurveFromEdge(const TopoDS_Edge& theEdge, GetTrimmedCurveFromEdge(const TopoDS_Edge& theEdge,
const TopoDS_Face& aFace, const TopoDS_Face& theFace,
MoniTool_DataMapOfShapeTransient& aMap, MoniTool_DataMapOfShapeTransient& theMap,
Handle(TColStd_HSequenceOfTransient)& curveList) const Handle(TColStd_HSequenceOfTransient)& theCurveList) const
{ {
if (theEdge.Orientation() == TopAbs_INTERNAL || if (theEdge.Orientation() == TopAbs_INTERNAL ||
theEdge.Orientation() == TopAbs_EXTERNAL ) { theEdge.Orientation() == TopAbs_EXTERNAL )
{
#ifdef OCCT_DEBUG #ifdef OCCT_DEBUG
std::cout <<"Warning: TopoDSToStep_WireframeBuilder::GetTrimmedCurveFromEdge: Edge is internal or external; dropped" << std::endl; std::cout <<"Warning: TopoDSToStep_WireframeBuilder::GetTrimmedCurveFromEdge: Edge is internal or external; dropped" << std::endl;
#endif #endif
return Standard_False; return Standard_False;
} }
//szv#4:S4163:12Mar99 SGI warns //szv#4:S4163:12Mar99 SGI warns
TopoDS_Shape sh = theEdge.Oriented(TopAbs_FORWARD); TopoDS_Shape aSh = theEdge.Oriented(TopAbs_FORWARD);
TopoDS_Edge anEdge = TopoDS::Edge ( sh ); TopoDS_Edge anEdge = TopoDS::Edge ( aSh );
// resulting curve // resulting curve
Handle(StepGeom_Curve) Gpms; Handle(StepGeom_Curve) aSGC;
if (const Handle(Standard_Transient)* aTransient = theMap.Seek(anEdge))
if ( aMap.IsBound(anEdge)) { {
Gpms = Handle(StepGeom_Curve)::DownCast ( aMap.Find(anEdge) ); aSGC = Handle(StepGeom_Curve)::DownCast(*aTransient);
if ( Gpms.IsNull() ) return Standard_False;
//?? curveList->Append(Gpms);
return Standard_True;
} }
BRepAdaptor_Curve CA; BRepAdaptor_Curve aCA;
try { try
{
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
CA.Initialize (anEdge); aCA.Initialize (anEdge);
} }
catch (Standard_NullObject const&) { catch (Standard_NullObject const&)
{
return Standard_False; return Standard_False;
} }
// Vertices TopoDS_Vertex aVFirst, aVLast;
TopoDS_Vertex Vfirst, Vlast; Handle(StepGeom_CartesianPoint) aSGCP1, aSGCP2;
Handle(StepGeom_CartesianPoint) pmsP1, pmsP2; for (TopExp_Explorer anExp(anEdge, TopAbs_VERTEX); anExp.More(); anExp.Next())
for (TopoDS_Iterator It(anEdge);It.More();It.Next()) { {
// Translates the Edge Vertices TopoDS_Vertex aVertex = TopoDS::Vertex(anExp.Value());
TopoDS_Vertex V = TopoDS::Vertex(It.Value()); gp_Pnt aGpP = BRep_Tool::Pnt(aVertex);
gp_Pnt gpP = BRep_Tool::Pnt(V); if (aVertex.Orientation() == TopAbs_FORWARD)
if ( V.Orientation() == TopAbs_FORWARD ) { {
Vfirst = V; aVFirst = aVertex;
// 1.point for trimming // 1.point for trimming
GeomToStep_MakeCartesianPoint gtpP(gpP); GeomToStep_MakeCartesianPoint aGTSMCP(aGpP);
pmsP1 = gtpP.Value(); aSGCP1 = aGTSMCP.Value();
} }
if ( V.Orientation() == TopAbs_REVERSED ) { if (aVertex.Orientation() == TopAbs_REVERSED)
Vlast = V; {
aVLast = aVertex;
// 2.point for trimming // 2.point for trimming
GeomToStep_MakeCartesianPoint gtpP(gpP); GeomToStep_MakeCartesianPoint aGTSMCP(aGpP);
pmsP2 = gtpP.Value(); aSGCP2 = aGTSMCP.Value();
} }
} }
// ---------------------------------------
// Translate 3D representation of the Edge
// ---------------------------------------
// Handle(Geom_Curve) C = CA.Curve().Curve();
// UPDATE FMA 26-02-96 Standard_Real aFirst, aLast;
// General remark : this full code should be deaply reworked Handle(Geom_Curve) aC = BRep_Tool::Curve(anEdge, aFirst, aLast);
// Too many objects are not used !
Standard_Real First, Last; if (!aC.IsNull())
Handle(Geom_Curve) C = BRep_Tool::Curve(anEdge, First, Last); {
if ( ! C.IsNull() ) { if (aC->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)))
if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve(); aC = Handle(Geom_TrimmedCurve)::DownCast(aC)->BasisCurve();
GeomToStep_MakeCurve gtpC(C); }
GeomToStep_MakeCurve aGTSMC(aC);
if(!gtpC.IsDone()) if (!aGTSMC.IsDone())
{
return Standard_False; return Standard_False;
}
Handle(StepGeom_Curve) pmsC = gtpC.Value(); Handle(StepGeom_Curve) aPMSC = aGTSMC.Value();
// trim the curve // trim the curve
Standard_Real trim1 = CA.FirstParameter(); Standard_Real aTrim1 = aCA.FirstParameter();
Standard_Real trim2 = CA.LastParameter(); Standard_Real aTrim2 = aCA.LastParameter();
/* //:j1 abv 22 Oct 98: radians are used in the produced STEP file (at least by default)
if(C->IsKind(STANDARD_TYPE(Geom_Circle)) || if (aVFirst.IsNull() && aVLast.IsNull() && Precision::IsInfinite(aFirst) && Precision::IsInfinite(aLast))
C->IsKind(STANDARD_TYPE(Geom_Ellipse))) { {
Standard_Real fact = 180. / M_PI; GeomToStep_MakeCurve aCurveMaker(aC);
trim1 = trim1 * fact; if (aCurveMaker.IsDone())
trim2 = trim2 * fact; {
aSGC = aCurveMaker.Value();
theCurveList->Append(aSGC);
return Standard_True;
}
return Standard_False;
} }
*/ if (aVFirst.IsNull())
Gpms = MakeTrimmedCurve (pmsC, pmsP1, pmsP2, trim1, trim2, Standard_True ); {
// (anEdge.Orientation() == TopAbs_FORWARD)); GeomToStep_MakeCartesianPoint aGTSMCP(aCA.Value(aFirst));
aSGCP1 = aGTSMCP.Value();
}
if (aVLast.IsNull())
{
GeomToStep_MakeCartesianPoint aGTSMCP(aCA.Value(aLast));
aSGCP2 = aGTSMCP.Value();
}
/* //:j1 abv 22 Oct 98: radians are used in the produced STEP file (at least by default)
if(C->IsKind(STANDARD_TYPE(Geom_Circle)) ||
C->IsKind(STANDARD_TYPE(Geom_Ellipse))) {
Standard_Real fact = 180. / M_PI;
trim1 = trim1 * fact;
trim2 = trim2 * fact;
}
*/
aSGC = MakeTrimmedCurve(aPMSC, aSGCP1, aSGCP2, aTrim1, aTrim2, Standard_True);
} }
else { else
{
// ------------------------- // -------------------------
// a 3D Curve is constructed // a 3D Curve is constructed
// ------------------------- // -------------------------
Standard_Boolean iaplan = Standard_False; Standard_Boolean aIPlan = Standard_False;
if ( ! aFace.IsNull() ) { if (!theFace.IsNull())
Standard_Real cf, cl; {
Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(anEdge, aFace, cf, cl); Standard_Real aCF, aCL;
Handle(Geom_Surface) S = BRep_Tool::Surface(aFace); Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, theFace, aCF, aCL);
if (S->IsKind(STANDARD_TYPE(Geom_Plane)) && Handle(Geom_Surface) aS = BRep_Tool::Surface(theFace);
C2d->IsKind(STANDARD_TYPE(Geom2d_Line))) iaplan = Standard_True; if (aS->IsKind(STANDARD_TYPE(Geom_Plane)) && aC2d->IsKind(STANDARD_TYPE(Geom2d_Line)))
{
aIPlan = Standard_True;
}
} }
// to be modified : cf and cl are the topological trimming parameter // to be modified : cf and cl are the topological trimming parameter
// these are computed after ! (U1 and U2) -> cf and cl instead // these are computed after ! (U1 and U2) -> cf and cl instead
if (iaplan) { if (aIPlan)
gp_Pnt Pnt1 = CA.Value(CA.FirstParameter()), Pnt2 = CA.Value(CA.LastParameter()); {
gp_Vec V ( Pnt1, Pnt2 ); gp_Pnt aPnt1 = aCA.Value(aCA.FirstParameter()), aPnt2 = aCA.Value(aCA.LastParameter());
Standard_Real length = V.Magnitude(); gp_Vec aV(aPnt1, aPnt2);
if ( length >= Precision::Confusion() ) { Standard_Real aLength = aV.Magnitude();
Handle(Geom_Line) L = new Geom_Line(Pnt1, gp_Dir(V)); if (aLength >= Precision::Confusion())
GeomToStep_MakeLine gtpL(L); {
Gpms = gtpL.Value(); Handle(Geom_Line) aL = new Geom_Line(aPnt1, gp_Dir(aV));
Gpms = MakeTrimmedCurve (gtpL.Value(), pmsP1, pmsP2, 0, length, Standard_True ); GeomToStep_MakeLine aGTSML(aL);
// (anEdge.Orientation() == TopAbs_FORWARD)); aSGC = aGTSML.Value();
aSGC = MakeTrimmedCurve(aGTSML.Value(), aSGCP1, aSGCP2, 0, aLength, Standard_True);
} }
#ifdef OCCT_DEBUG #ifdef OCCT_DEBUG
else std::cout << "Warning: TopoDSToStep_WireframeBuilder::GetTrimmedCurveFromEdge: Null-length curve not mapped" << std::endl; else std::cout << "Warning: TopoDSToStep_WireframeBuilder::GetTrimmedCurveFromEdge: Null-length curve not mapped" << std::endl;
#endif #endif
} }
else { else
TColgp_Array1OfPnt Points(1,Nbpt); {
TColStd_Array1OfReal Knots(1,Nbpt); TColgp_Array1OfPnt aPoints(1, Nbpt);
TColStd_Array1OfInteger Mult(1,Nbpt); TColStd_Array1OfReal aKnots(1, Nbpt);
Standard_Real U1 = CA.FirstParameter(); TColStd_Array1OfInteger aMult(1, Nbpt);
Standard_Real U2 = CA.LastParameter(); Standard_Real aU1 = aCA.FirstParameter();
for ( Standard_Integer i=1; i<=Nbpt; i++ ) { Standard_Real aU2 = aCA.LastParameter();
Standard_Real U = U1 + (i-1)*(U2 - U1)/(Nbpt - 1); for (Standard_Integer i = 1; i <= Nbpt; i++)
gp_Pnt P = CA.Value(U); {
Points.SetValue(i,P); Standard_Real aU = aU1 + (i - 1) * (aU2 - aU1) / (Nbpt - 1);
Knots.SetValue(i,U); gp_Pnt aP = aCA.Value(aU);
Mult.SetValue(i,1); aPoints.SetValue(i, aP);
aKnots.SetValue(i, aU);
aMult.SetValue(i, 1);
} }
Points.SetValue(1, BRep_Tool::Pnt(Vfirst)); aPoints.SetValue(1, BRep_Tool::Pnt(aVFirst));
Points.SetValue(Nbpt, BRep_Tool::Pnt(Vlast)); aPoints.SetValue(Nbpt, BRep_Tool::Pnt(aVLast));
Mult.SetValue(1,2); aMult.SetValue(1, 2);
Mult.SetValue(Nbpt,2); aMult.SetValue(Nbpt, 2);
Handle(Geom_Curve) Bs = Handle(Geom_Curve) aBSCurve = new Geom_BSplineCurve(aPoints, aKnots, aMult, 1);
new Geom_BSplineCurve(Points, Knots, Mult, 1); GeomToStep_MakeCurve aGTSMC(aBSCurve);
GeomToStep_MakeCurve gtpC(Bs); aSGC = aGTSMC.Value();
Gpms = gtpC.Value();
} }
} }
if( Gpms.IsNull() ) return Standard_False;
aMap.Bind(anEdge, Gpms); if (aSGC.IsNull())
curveList->Append(Gpms); {
return Standard_False;
}
theMap.Bind(anEdge, aSGC);
theCurveList->Append(aSGC);
return Standard_True; return Standard_True;
} }
Standard_Boolean TopoDSToStep_WireframeBuilder:: Standard_Boolean TopoDSToStep_WireframeBuilder::
GetTrimmedCurveFromFace(const TopoDS_Face& aFace, GetTrimmedCurveFromFace(const TopoDS_Face& aFace,
MoniTool_DataMapOfShapeTransient& aMap, MoniTool_DataMapOfShapeTransient& aMap,
Handle(TColStd_HSequenceOfTransient)& aCurveList) const Handle(TColStd_HSequenceOfTransient)& aCurveList) const
{ {
TopoDS_Shape curShape; TopoDS_Shape curShape;
TopoDS_Edge curEdge; TopoDS_Edge curEdge;

@ -0,0 +1,13 @@
puts "================"
puts "0032817: Data Exchange - Step export - writing untrimmed Curve"
puts "================"
pload XDE
catch {Close D}
XNewDoc D
line l1 0 0 0 0 1 0
mkedge e1 l1
XAddShape D e1
WriteStep D $imagedir/${casename}.stp
file delete $imagedir/${casename}.stp

@ -0,0 +1,13 @@
puts "================"
puts "0032817: Data Exchange - Step export - writing untrimmed Curve"
puts "================"
pload XDE
catch {Close D}
XNewDoc D
line l1 0 0 0 0 1 0
mkedge e1 l1 10 2e+100
XAddShape D e1
WriteStep D $imagedir/${casename}.stp
file delete $imagedir/${casename}.stp

@ -0,0 +1,13 @@
puts "================"
puts "0032817: Data Exchange - Step export - writing untrimmed Curve"
puts "================"
pload XDE
catch {Close D}
XNewDoc D
line l1 0 0 0 1 1 0
mkedge e1 l1 -2e+100 10
XAddShape D e1
WriteStep D $imagedir/${casename}.stp
file delete $imagedir/${casename}.stp