#include <Transfer_FinderProcess.hxx>
#include <TransferBRep.hxx>
#include <TransferBRep_ShapeMapper.hxx>
+#include <BRepTools.hxx>
+#include <ShapeAnalysis_Curve.hxx>
// Processing of non-manifold topology (ssv; 11.11.2010)
// ----------------------------------------------------------------------------
TopoDSToStep_MakeStepEdge::TopoDSToStep_MakeStepEdge
(const TopoDS_Edge& E,
- TopoDSToStep_Tool& T,
- const Handle(Transfer_FinderProcess)& FP)
+ TopoDSToStep_Tool& T,
+ const Handle(Transfer_FinderProcess)& FP)
{
done = Standard_False;
Init(E, T, FP);
// Purpose :
// ----------------------------------------------------------------------------
-void TopoDSToStep_MakeStepEdge::Init(const TopoDS_Edge& aEdge,
- TopoDSToStep_Tool& aTool,
- const Handle(Transfer_FinderProcess)& FP)
+void TopoDSToStep_MakeStepEdge::Init(const TopoDS_Edge& aEdge,
+ TopoDSToStep_Tool& aTool,
+ const Handle(Transfer_FinderProcess)& FP)
{
// ------------------------------------------------------------------
// The edge is given with its relative orientation (i.e. in the wire)
if (isNMMode) {
Handle(StepShape_EdgeCurve) anEC;
Handle(TransferBRep_ShapeMapper) aSTEPMapper = TransferBRep::ShapeMapper(FP, aEdge);
- if ( FP->FindTypedTransient(aSTEPMapper, STANDARD_TYPE(StepShape_EdgeCurve), anEC) ) {
+ if (FP->FindTypedTransient(aSTEPMapper, STANDARD_TYPE(StepShape_EdgeCurve), anEC)) {
// Non-manifold topology detected
myError = TopoDSToStep_EdgeDone;
myResult = anEC;
Standard_Integer i;
Standard_Real U, U1, U2;
gp_Pnt P;
-
+
Standard_Boolean isSeam = BRep_Tool::IsClosed(aEdge, aTool.CurrentFace());
-
+
//:i4 abv 02 Sep 98: ProSTEP TR8 Motor.rle f3 & f62: check that edge
// participates twice in the wires of the face before making it seam
// (else it can have two pcurves on the same surface being shared by
// two faces on that surface)
// This fix is necessary because sharing of surfaces is not preserved when
// writing faces to STEP (see TopoDSToSTEP_MakeStepFace)
- if ( isSeam ) {
+ if (isSeam) {
Standard_Integer count = 0;
- TopExp_Explorer exp ( aTool.CurrentFace(), TopAbs_EDGE );
- for ( ; exp.More(); exp.Next() )
- if ( aEdge.IsSame ( exp.Current() ) ) count++;
- if ( count < 2 ) isSeam = Standard_False;
+ TopExp_Explorer exp (aTool.CurrentFace(), TopAbs_EDGE);
+ for (; exp.More(); exp.Next())
+ if (aEdge.IsSame (exp.Current())) count++;
+ if (count < 2) isSeam = Standard_False;
}
BRepAdaptor_Curve CA = BRepAdaptor_Curve(aEdge);
BRepAdaptor_Surface SA = BRepAdaptor_Surface(aTool.CurrentFace());
if (aEdge.Orientation() == TopAbs_INTERNAL ||
- aEdge.Orientation() == TopAbs_EXTERNAL ) {
+ aEdge.Orientation() == TopAbs_EXTERNAL) {
Handle(TransferBRep_ShapeMapper) errShape =
new TransferBRep_ShapeMapper(aEdge);
FP->AddWarning(errShape, " Edge(internal/external) from Non Manifold Topology");
done = Standard_False;
return;
}
-
+
// Vertices
- Handle(StepShape_Vertex) V1,V2;
+ Handle(StepShape_Vertex) V1, V2;
Handle(StepShape_TopologicalRepresentationItem) Gpms2;
TopoDS_Vertex Vfirst, Vlast;
- TopExp::Vertices(aEdge,Vfirst, Vlast);
+ TopExp::Vertices(aEdge, Vfirst, Vlast);
TopoDSToStep_MakeStepVertex MkVertex;
-
- MkVertex.Init(Vfirst, aTool, FP);
+
+ MkVertex.Init(Vfirst, aTool, FP);
if (MkVertex.IsDone())
V1 = Handle(StepShape_Vertex)::DownCast(MkVertex.Value());
else {
done = Standard_False;
return;
}
-
+
MkVertex.Init(Vlast, aTool, FP);
if (MkVertex.IsDone())
V2 = Handle(StepShape_Vertex)::DownCast(MkVertex.Value());
done = Standard_False;
return;
}
-
+
// ---------------------------------------
// Translate 3D representation of the Edge
// ---------------------------------------
-
+
Handle(StepGeom_Curve) Gpms;
Handle(Geom_Curve) C = CA.Curve().Curve();
if (!C.IsNull()) {
C = Handle(Geom_Curve)::DownCast(C->Copy());
+
+ if (C->IsPeriodic())
+ {
+ Standard_Real dpar = CA.LastParameter() - CA.FirstParameter();
+
+ Standard_Real aTolV1 = BRep_Tool::Tolerance(Vfirst);
+ Standard_Real aTolV2 = BRep_Tool::Tolerance(Vlast);
+ gp_Pnt aP1 = BRep_Tool::Pnt(Vfirst);
+ gp_Pnt aP2 = BRep_Tool::Pnt(Vlast);
+ gp_Pnt pproj;
+ gp_Pnt aP11 = CA.Value(CA.FirstParameter());
+ gp_Pnt aP12 =CA.Value(CA.LastParameter());
+ ShapeAnalysis_Curve sac;
+ sac.Project (C, aP1, Tolerance(), pproj, U1, Standard_False);
+ sac.Project (C, aP2, Tolerance(), pproj, U2, Standard_False);
+ Standard_Real dU = U2 - U1;
+
+ if (dpar <= 0)
+ dpar += (ceil(fabs(dpar) / C->Period()) *C->Period());
+
+ if (dU <= 0)
+ dU += (ceil(fabs(dU) / C->Period()) *C->Period());
+ // if range obtained from projection of vertices is contradicted with range of the edge
+ //tnen vertices should be permuted
+
+ if ((dU > Precision::PConfusion() && dU <= 0.1 * C->Period() && dpar > 0.5 * C->Period()) ||
+ (dpar > Precision::PConfusion() && dpar <= 0.1 * C->Period() && dU > 0.5 * C->Period()))
+ {
+ Handle(StepShape_Vertex) aVtemp = V1;
+ V1 = V2; V2 = aVtemp;
+ }
+
+ gp_Pnt aPm = CA.Value((CA.FirstParameter() + CA.LastParameter()) *0.5);
+ Standard_Real aDist11 = aP11.Distance(aP12);
+ Standard_Real aDist1m = aP11.Distance(aPm);
+ Standard_Real aDist2m = aP12.Distance(aPm);
+ Standard_Real aDistMax = Max(Max(aDist1m, aDist2m), aDist11);
+ Standard_Boolean isSmallCurve = (aDistMax <= aTolV1 || aDistMax <= aTolV2);
+ //for small edge lying BSpline periodic curve segment of the BSpline periodic curve is used to avoid invalid computation of the edge range duriring reading
+ if (BRepTools::Compare(Vfirst, Vlast) && isSmallCurve && C->IsPeriodic() && dpar > Precision::PConfusion() && dpar <= 0.1 * C->Period())
+ {
+ if (C->IsKind(STANDARD_TYPE(Geom_BSplineCurve)))
+ {
+ Handle(Geom_BSplineCurve) aBspl1 = Handle(Geom_BSplineCurve)::DownCast(C->Copy());
+ aBspl1->Segment (CA.FirstParameter(), CA.LastParameter());
+ C = aBspl1;
+ }
+ }
+ }
gp_Trsf Tr1 = CA.Trsf();
C->Transform(Tr1);
GeomToStep_MakeCurve MkCurve(C);
Gpms = MkCurve.Value();
}
else {
-
+
// -------------------------
// a 3D Curve is constructed
// -------------------------
std::cout << "Warning: TopoDSToStep_MakeStepEdge: edge without 3d curve; creating..." << std::endl;
#endif
if ((SA.GetType() == GeomAbs_Plane) &&
- (CA.GetType() == GeomAbs_Line)) {
+ (CA.GetType() == GeomAbs_Line)) {
U1 = CA.FirstParameter();
U2 = CA.LastParameter();
- gp_Vec V = gp_Vec( CA.Value(U1), CA.Value(U2) );
- Handle(Geom_Line) L =
- new Geom_Line(CA.Value(U1), gp_Dir(V));
+ gp_Vec V = gp_Vec(CA.Value(U1), CA.Value(U2));
+ Handle(Geom_Line) L =
+ new Geom_Line(CA.Value(U1), gp_Dir(V));
GeomToStep_MakeLine MkLine(L);
Gpms = MkLine.Value();
}
else {
// To Be Optimized : create an approximated BSpline
// using GeomAPI_PointsToBSpline
- TColgp_Array1OfPnt Points(1,Nbpt);
- TColStd_Array1OfReal Knots(1,Nbpt);
- TColStd_Array1OfInteger Mult(1,Nbpt);
+ TColgp_Array1OfPnt Points(1, Nbpt);
+ TColStd_Array1OfReal Knots(1, Nbpt);
+ TColStd_Array1OfInteger Mult(1, Nbpt);
U1 = CA.FirstParameter();
U2 = CA.LastParameter();
- for ( i=1; i<=Nbpt; i++ ) {
- U = U1 + (i-1)*(U2 - U1)/(Nbpt - 1);
- P = CA.Value(U);
- Points.SetValue(i,P);
- Knots.SetValue(i,U);
- Mult.SetValue(i,1);
+ for (i=1; i<=Nbpt; i++) {
+ U = U1 + (i-1)*(U2 - U1)/(Nbpt - 1);
+ P = CA.Value(U);
+ Points.SetValue(i, P);
+ Knots.SetValue(i, U);
+ Mult.SetValue(i, 1);
}
//Points.SetValue(1, BRep_Tool::Pnt(Vfirst));
//Points.SetValue(Nbpt, BRep_Tool::Pnt(Vlast));
- Mult.SetValue(1,2);
- Mult.SetValue(Nbpt,2);
- Handle(Geom_Curve) Bs =
- new Geom_BSplineCurve(Points, Knots, Mult, 1);
+ Mult.SetValue(1, 2);
+ Mult.SetValue(Nbpt, 2);
+ Handle(Geom_Curve) Bs =
+ new Geom_BSplineCurve(Points, Knots, Mult, 1);
GeomToStep_MakeCurve MkCurve(Bs);
Gpms = MkCurve.Value();
}
}
-
+
// ---------------------------------------------------------
// Warning : if the edge is connected aGeom->Length = 2
// otherwise = 1 ;
//:abv 25.01.00 CAX-IF TRJ3
// if PcurveMode is 1 (default), make surface_curve instead of simple 3d curve
- if ( aTool.PCurveMode() != 0 ) {
-
+ if (aTool.PCurveMode() != 0) {
+
Handle(StepGeom_HArray1OfPcurveOrSurface) aGeom =
- new StepGeom_HArray1OfPcurveOrSurface(1,2);
+ new StepGeom_HArray1OfPcurveOrSurface(1, 2);
Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
-
+
if (!isSeam) {
Handle(StepGeom_SurfaceCurve) SurfaceCurve = new StepGeom_SurfaceCurve;
SurfaceCurve->Init(aName, Gpms, aGeom, StepGeom_pscrPcurveS1);
Gpms = SeamCurve;
}
}
-
+
// Edge curve
Handle(StepShape_EdgeCurve) Epms = new StepShape_EdgeCurve;
Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
Epms->Init(aName, V1, V2, Gpms, Standard_True);
-
+
aTool.Bind(aEdge, Epms);
myError = TopoDSToStep_EdgeDone;
myResult = Epms;
// Purpose :
// ----------------------------------------------------------------------------
-const Handle(StepShape_TopologicalRepresentationItem)& TopoDSToStep_MakeStepEdge::Value() const
+const Handle(StepShape_TopologicalRepresentationItem)& TopoDSToStep_MakeStepEdge::Value() const
{
StdFail_NotDone_Raise_if (!done, "TopoDSToStep_MakeStepEdge::Value() - no result");
return myResult;
// Purpose :
// ----------------------------------------------------------------------------
-TopoDSToStep_MakeEdgeError TopoDSToStep_MakeStepEdge::Error() const
+TopoDSToStep_MakeEdgeError TopoDSToStep_MakeStepEdge::Error() const
{
return myError;
}