1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Compare commits

...

1 Commits

Author SHA1 Message Date
dpasukhi
2674598ff1 0033353: Data Exchange, Step Import - Healing corrupted file with missed vertex edges
Added detection vertex from STEP edge neighbors or own curve
(Commit just to test)
2023-04-03 02:25:10 +01:00
2 changed files with 231 additions and 58 deletions

View File

@@ -155,8 +155,16 @@ static TopoDS_Edge MakeEdge
TopoDS_Edge E;
B.MakeEdge (E,C3D,Precision::Confusion());
B.Add (E,V1); B.Add (E,V2);
B.UpdateVertex(V1, U1, E, 0.);
B.UpdateVertex(V2, U2, E, 0.);
if (!Precision::IsPositiveInfinite(U1) &&
!Precision::IsNegativeInfinite(U1))
{
B.UpdateVertex(V1, U1, E, 0.);
}
if (!Precision::IsPositiveInfinite(U2) &&
!Precision::IsNegativeInfinite(U2))
{
B.UpdateVertex(V2, U2, E, 0.);
}
return E;
}
@@ -302,11 +310,17 @@ void StepToTopoDS_TranslateEdge::Init(const Handle(StepShape_Edge)& aEdge,
// --- * a 3D Curve
// ----------------------------------------------------------
if ( C->IsKind(STANDARD_TYPE(StepGeom_Pcurve))) {
if (C->IsKind(STANDARD_TYPE(StepGeom_Pcurve)))
{
B.MakeEdge(E);
//:S4136 B.UpdateEdge (E,preci);
B.Add(E, V1);
B.Add(E, V2);
if (!V1.IsNull())
{
B.Add(E, V1);
}
if (!V2.IsNull())
{
B.Add(E, V2);
}
}
else if (C->IsKind(STANDARD_TYPE(StepGeom_SurfaceCurve)) ) {
// For SeamCurve and IntersectionCurve types
@@ -380,6 +394,21 @@ void StepToTopoDS_TranslateEdge::MakeFromCurve3D
done = Standard_False;
return;
}
//BRep_Builder aBuilder;
//if (V1.IsNull())
//{
// TopoDS_Vertex aTmpVert;
// const Standard_Real aFirst = C1->FirstParameter();
// aBuilder.MakeVertex(aTmpVert, C1->Value(aFirst), preci);
// V1 = aTmpVert;
//}
//if (V2.IsNull())
//{
// TopoDS_Vertex aTmpVert;
// const Standard_Real aFirst = C1->LastParameter();
// aBuilder.MakeVertex(aTmpVert, C1->Value(aFirst), preci);
// V2 = aTmpVert;
//}
// -- Statistics -- -> No Warning message
aTool.AddContinuity (C1);
BRep_Builder B;

View File

@@ -22,21 +22,27 @@
// rln 02.06.99 removing #include <StepToTopoDS_DegeneratedTool.hxx>
// smh 31.01.01 BUC60810 : IsNull protection
#include <StepToTopoDS_TranslateEdgeLoop.hxx>
#include <BRep_Builder.hxx>
#include <BRep_TEdge.hxx>
#include <BRep_Tool.hxx>
#include <ElCLib.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_Curve.hxx>
#include <gp_Dir.hxx>
#include <Geom_Plane.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_Surface.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom2d_Curve.hxx>
#include <GeomToStep_MakeCartesianPoint.hxx>
#include <gp_Pnt.hxx>
#include <Interface_Static.hxx>
#include <Precision.hxx>
#include <ShapeAlgo.hxx>
#include <ShapeAlgo_AlgoContainer.hxx>
#include <ShapeAlgo_ToolContainer.hxx>
#include <Geom_Line.hxx>
#include <ShapeAnalysis_Curve.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <ShapeBuild_Edge.hxx>
@@ -52,13 +58,13 @@
#include <StepShape_FaceBound.hxx>
#include <StepShape_OrientedEdge.hxx>
#include <StepShape_Vertex.hxx>
#include <StepShape_VertexPoint.hxx>
#include <StepToGeom.hxx>
#include <StepToTopoDS.hxx>
#include <StepToTopoDS_GeometricTool.hxx>
#include <StepToTopoDS_NMTool.hxx>
#include <StepToTopoDS_Tool.hxx>
#include <StepToTopoDS_TranslateEdge.hxx>
#include <StepToTopoDS_TranslateEdgeLoop.hxx>
#include <StepToTopoDS_TranslateVertex.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
@@ -74,6 +80,26 @@
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
// ============================================================================
// Method : MakeCurveFromStep
// Purpose :
// ============================================================================
static Handle(Geom_Curve) MakeCurveFromStep (const Handle(StepGeom_Curve)& theStepCurve,
const Handle(Transfer_TransientProcess) theTP)
{
Handle(Geom_Curve) aResCurve = Handle(Geom_Curve)::DownCast(theTP->FindTransient(theStepCurve));
if (!aResCurve.IsNull())
{
return aResCurve;
}
aResCurve = StepToGeom::MakeCurve(theStepCurve);
if (!aResCurve.IsNull())
{
theTP->BindTransient(theStepCurve, aResCurve);
}
return aResCurve;
}
// ============================================================================
// Method : RemoveSinglePCurve
// Purpose :
@@ -220,21 +246,13 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
BRep_Builder B;
Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
Standard_Real preci = Precision();
const Standard_Real preci = Precision();
TopoDS_Wire W;
TopoDS_Edge E;
TopoDS_Vertex V;
Standard_Boolean isSeam, isLikeSeam;
Handle(Geom2d_Curve) C2d, C2d1, C2d2;
Handle(StepShape_OrientedEdge) OrEdge1, OrEdge2;
Handle(StepGeom_Curve) StepCurve, StepCurve1, StepCurve2;
Handle(StepRepr_DefinitionalRepresentation) DRI, Dri1, Dri2;
Handle(Geom2d_Curve) C2d, C2d1, C2d2, WhichC2d1, WhichC2d2;
TopoDS_Edge suspectE; //:f1, degEdge;
Standard_Integer j, NbEdge = EL->NbEdgeList();
const Standard_Integer NbEdge = EL->NbEdgeList();
if (NbEdge == 0) {
TP->AddWarning(EL, "Wire not done. EdgeLoop does not contain edges.");
done = Standard_False;
@@ -269,9 +287,9 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
// This case may not be processed, PCurves has to be recomputed from scratch
// -----------------------------------------------
// Standard_Integer theSame = 1; //gka 15.12.98
for (j=1; j<=NbEdge; j++) {
OrEdge1 = EL->EdgeListValue(j);
NCollection_Map<Handle(StepShape_OrientedEdge)> aIncorrectEdges;
for (Standard_Integer j=1; j<=NbEdge; j++) {
Handle(StepShape_OrientedEdge) OrEdge1 = EL->EdgeListValue(j);
if (OrEdge1.IsNull() || OrEdge1->EdgeElement().IsNull())
{
@@ -337,21 +355,38 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
StepToTopoDS_TranslateVertex myTranVertex1(Vstart, aTool, NMTool);
StepToTopoDS_TranslateVertex myTranVertex2(Vend, aTool, NMTool);
if (myTranVertex1.IsDone()) {
if (myTranVertex1.IsDone())
{
V1 = TopoDS::Vertex(myTranVertex1.Value());
}
if (myTranVertex2.IsDone()) {
if (myTranVertex2.IsDone())
{
V2 = TopoDS::Vertex(myTranVertex2.Value());
gp_Pnt p1 = BRep_Tool::Pnt(V1);
gp_Pnt p2 = BRep_Tool::Pnt(V2);
if (p1.Distance(p2) <= Precision::Confusion()) { //:S4136: preci) {
Standard_Boolean Fixed = Standard_True;
if (!iseV) aTool.Bind(Vend, V1); //gka 21.08.1998 bug PRO7656
else if (!istV) aTool.Bind (Vstart, V2);
else aTool.Bind (Vend, V1);
if (!C1.IsNull() && !C1->IsClosed() && Fixed)
}
if (!V1.IsNull() && !V2.IsNull())
{
gp_Pnt aPnt1 = BRep_Tool::Pnt(V1);
gp_Pnt aPnt2 = BRep_Tool::Pnt(V2);
if (aPnt1.Distance(aPnt2) <= Precision::Confusion())
{
Standard_Boolean aIsFixed = Standard_True;
if (!iseV)
{
aTool.Bind(Vend, V1);
}
else if (!istV)
{
aTool.Bind(Vstart, V2);
}
else
{
aTool.Bind(Vend, V1);
}
if (!C1.IsNull() && !C1->IsClosed() && aIsFixed)
{
TP->AddWarning(EL->EdgeListValue(j),
"Vertex of same coordinates, set confused");
"Vertex of same coordinates, set confused");
}
}
}
}
@@ -361,32 +396,141 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
// and make it be one vertex
// NOTE: this is done only for the case if at least one of edges
// was not yet translated; else nothing will help
for (j=1; j<=NbEdge; j++) {
OrEdge1 = EL->EdgeListValue (j);
OrEdge2 = EL->EdgeListValue (j < NbEdge ? j + 1 : 1);
if (OrEdge1.IsNull() || OrEdge2.IsNull())
for (Standard_Integer anEdgeInd = 1; anEdgeInd <= NbEdge; anEdgeInd++)
{
Handle(StepShape_OrientedEdge) anOrEdge1 =
EL->EdgeListValue(anEdgeInd);
Handle(StepShape_OrientedEdge) anOrEdge2 =
EL->EdgeListValue(anEdgeInd < NbEdge ? anEdgeInd + 1 : 1);
if (anOrEdge1.IsNull() || anOrEdge2.IsNull())
continue;
Handle(StepShape_EdgeCurve) EC1 =
Handle(StepShape_EdgeCurve)::DownCast (OrEdge1->EdgeElement());
Handle(StepShape_EdgeCurve) EC2 =
Handle(StepShape_EdgeCurve)::DownCast (OrEdge2->EdgeElement());
if (EC1.IsNull() || EC2.IsNull()) // see #29979
if (!anOrEdge1->EdgeElement().IsNull() &&
anOrEdge1->EdgeElement()->IsKind(STANDARD_TYPE(StepShape_OrientedEdge)))
{
anOrEdge1 = Handle(StepShape_OrientedEdge)::DownCast(anOrEdge1->EdgeElement());
}
if (!anOrEdge2->EdgeElement().IsNull() &&
anOrEdge2->EdgeElement()->IsKind(STANDARD_TYPE(StepShape_OrientedEdge)))
{
anOrEdge2 = Handle(StepShape_OrientedEdge)::DownCast(anOrEdge2->EdgeElement());
}
Handle(StepShape_EdgeCurve) aEC1 =
Handle(StepShape_EdgeCurve)::DownCast(anOrEdge1->EdgeElement());
const Handle(StepShape_EdgeCurve) aEC2 =
Handle(StepShape_EdgeCurve)::DownCast(anOrEdge2->EdgeElement());
if (aEC1.IsNull() || aEC2.IsNull()) // see #29979
{
continue;
}
Handle(StepShape_Vertex) Vs1, Vs2, Vs11, Vs22;
Vs1 = (OrEdge1->Orientation() ? EC1->EdgeEnd() : EC1->EdgeStart());
Vs2 = (OrEdge2->Orientation() ? EC2->EdgeStart() : EC2->EdgeEnd());
Handle(StepShape_Vertex) aVs1 = anOrEdge1->Orientation() ? aEC1->EdgeEnd() : aEC1->EdgeStart();
Handle(StepShape_Vertex) aVs2 = anOrEdge2->Orientation() ? aEC2->EdgeStart() : aEC2->EdgeEnd();
Vs11 = (OrEdge1->Orientation() ? EC1->EdgeStart() : EC1->EdgeEnd());
Vs22 = (OrEdge2->Orientation() ? EC2->EdgeEnd() : EC2->EdgeStart());
Handle(StepShape_Vertex) aVs11 = anOrEdge1->Orientation() ? aEC1->EdgeStart() : aEC1->EdgeEnd();
const Handle(StepShape_Vertex) aVs22 = anOrEdge2->Orientation() ? aEC2->EdgeEnd() : aEC2->EdgeStart();
if ((Vs1 == Vs2) || (Vs1 == Vs22) || (Vs2 == Vs11) || (Vs22 == Vs11)) continue;
StepToTopoDS_TranslateVertex myTranVertex1 (Vs1, aTool, NMTool);
StepToTopoDS_TranslateVertex myTranVertex2 (Vs2, aTool, NMTool);
if (!aVs1.IsNull() && !aVs11.IsNull() &&
((aVs1 == aVs2) || (aVs1 == aVs22) || (aVs2 == aVs11) || (aVs22 == aVs11)))
{
//continue;
}
if (aVs1.IsNull())
{
aIncorrectEdges.Add(anOrEdge1);
if (aVs2.IsNull())
{
Handle(Geom_Curve) aCurve;
const Handle(Geom_Curve) aCurveFirst = MakeCurveFromStep(aEC1->EdgeGeometry(), TP);
const Handle(Geom_Curve) aCurveSecond = MakeCurveFromStep(aEC2->EdgeGeometry(), TP);
Standard_Real aLast = Precision::Infinite();
aCurve = aCurveFirst;
aLast = anOrEdge1->Orientation() ? aCurve->LastParameter() : aCurve->FirstParameter();
if (Precision::IsPositiveInfinite(aLast) ||
Precision::IsNegativeInfinite(aLast))
{
aCurve = aCurveSecond;
aLast = anOrEdge2->Orientation() ? aCurve->FirstParameter() : aCurve->LastParameter();
}
gp_Pnt aStartP;
Standard_Boolean aIsFinded = Standard_False;
if (Precision::IsPositiveInfinite(aLast) ||
Precision::IsNegativeInfinite(aLast))
{
//if (anOrEdge2->Orientation())
//{
// aLast = 0.0;
//}
//else
//{
aCurve = aCurveFirst;
Handle(StepShape_VertexPoint) VP = Handle(StepShape_VertexPoint)::DownCast(aVs22);
Handle(StepGeom_Point) P = VP->VertexGeometry();
Handle(StepGeom_CartesianPoint) P1 = Handle(StepGeom_CartesianPoint)::DownCast(P);
Handle(Geom_CartesianPoint) P2 = StepToGeom::MakeCartesianPoint(P1);
gp_Pnt aLastPnt = P2->Pnt();
VP = Handle(StepShape_VertexPoint)::DownCast(aVs11);
P = VP->VertexGeometry();
P1 = Handle(StepGeom_CartesianPoint)::DownCast(P);
P2 = StepToGeom::MakeCartesianPoint(P1);
gp_Pnt aFirstPnt = P2->Pnt();
aLast = anOrEdge1->Orientation() ? aLastPnt.Distance(aFirstPnt) : 0.0;
if (aCurveFirst->IsKind(STANDARD_TYPE(Geom_Line)))
{
Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurveFirst);
aStartP = aFirstPnt.XYZ() + ((aLine->Position().Direction().XYZ() * aLastPnt.Distance(aFirstPnt)) * (anOrEdge1->Orientation() ? 1 : -1));
aIsFinded = Standard_True;
}
//}
}
if (!aIsFinded)
{
aStartP = aCurve->Value(aLast);
}
GeomToStep_MakeCartesianPoint aMkPoint(aStartP);
const Handle(StepGeom_CartesianPoint) aGpms = aMkPoint.Value();
const Handle(StepShape_VertexPoint) aVSP0 =
new StepShape_VertexPoint();
const Handle(TCollection_HAsciiString) aName =
new TCollection_HAsciiString("");
aVSP0->Init(aName, aGpms);
aVs2 = aVSP0;
}
if (!aVs2.IsNull())
{
aVs1 = aVs2;
if (anOrEdge1->Orientation())
{
aEC1->SetEdgeEnd(aVs1);
}
else
{
aEC1->SetEdgeStart(aVs1);
}
if (anOrEdge2->Orientation())
{
aEC2->SetEdgeStart(aVs1);
}
else
{
aEC2->SetEdgeEnd(aVs1);
}
}
}
else if (aVs2.IsNull())
{
aVs2 = aVs1;
if (anOrEdge2->Orientation())
{
aEC2->SetEdgeStart(aVs1);
}
else
{
aEC2->SetEdgeEnd(aVs1);
}
}
StepToTopoDS_TranslateVertex myTranVertex1 (aVs1, aTool, NMTool);
StepToTopoDS_TranslateVertex myTranVertex2 (aVs2, aTool, NMTool);
TopoDS_Vertex V1, V2;
if (myTranVertex1.IsDone())
@@ -400,8 +544,8 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
gp_Pnt p2 = BRep_Tool::Pnt(V2);
Standard_Boolean locFixed = Standard_True;
if (p1.Distance(p2) <= preci) {
if (! aTool.IsBound (EC1)) aTool.Bind (Vs1, V2);
else if (! aTool.IsBound (EC2)) aTool.Bind (Vs2, V1);
if (! aTool.IsBound (aEC1)) aTool.Bind (aVs1, V2);
else if (! aTool.IsBound (aEC2)) aTool.Bind (aVs2, V1);
else locFixed = Standard_False;
}
else locFixed = Standard_False;
@@ -413,7 +557,7 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
// Iteration on each Oriented Edge of the EdgeLoop
// -----------------------------------------------
for (j=1; j<=NbEdge; j++) {
for (Standard_Integer j=1; j<=NbEdge; j++) {
Standard_Boolean ThereIsLikeSeam = Standard_False;
@@ -421,7 +565,7 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
std::cout << " Processing Edge :" << j << std::endl;
#endif
OrEdge1 = EL->EdgeListValue(j);
Handle(StepShape_OrientedEdge) OrEdge1 = EL->EdgeListValue(j);
if (OrEdge1.IsNull() || OrEdge1->EdgeElement().IsNull())
continue;
@@ -430,7 +574,7 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
OrEdge1 = Handle(StepShape_OrientedEdge)::DownCast (OrEdge1->EdgeElement());
Handle(StepShape_EdgeCurve) EC = Handle(StepShape_EdgeCurve)::DownCast(OrEdge1->EdgeElement());
if (EC.IsNull())
if (EC.IsNull()/* || aIncorrectEdges.Contains(OrEdge1)*/)
{
continue;
}
@@ -458,7 +602,8 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
E.Orientation(TopAbs_FORWARD);
else E.Orientation(TopAbs_REVERSED);
isSeam = isLikeSeam = Standard_False;
Standard_Boolean isSeam = Standard_False;
Standard_Boolean isLikeSeam = Standard_False;
// ------------------------------------------
// Map the StepEdge parametric representation
@@ -526,7 +671,6 @@ void StepToTopoDS_TranslateEdgeLoop::Init(const Handle(StepShape_FaceBound)& Fac
}
if (isLikeSeam) {
suspectE = E;
ThereIsLikeSeam = Standard_True;
hasPcurve = Standard_True;
}