//=======================================================================
// strongwire
//=======================================================================
-static Standard_Integer strongwire(Draw_Interpretor& theDI, Standard_Integer theArgC, const char** theArgV)
+static Standard_Integer strongwire(Draw_Interpretor&, Standard_Integer theArgC, const char** theArgV)
{
enum StrongWireMode {
StrongWireMode_FixTolerance = 1,
aFW->Load(aWire);
aFW->FixReorder();
- if (aFW->StatusReorder(ShapeExtend_FAIL1))
+ if (aFW->StatusReorder(ShapeExtend_FAIL1))
{
Message::SendFail() << "Error: Wire construction failed: several loops detected";
return 1;
}
- else if (aFW->StatusReorder(ShapeExtend_FAIL))
+ else if (aFW->StatusReorder(ShapeExtend_FAIL))
{
Message::SendFail() << "Wire construction failed";
return 1;
bool isClosed = false;
Handle(ShapeAnalysis_Wire) aSaw = aFW->Analyzer();
- if (aSaw->CheckGap3d(1)) // between last and first edges
+ if (aSaw->CheckGap3d(1)) // between last and first edges
{
Standard_Real aDist = aSaw->MinDistance3d();
if (aDist < aTolerance)
}
aFW->ClosedWireMode() = isClosed;
aFW->FixConnected(aTolerance);
- if (aMode == StrongWireMode_KeepCurveType)
- aFW->FixCurves();
if (aFW->StatusConnected(ShapeExtend_FAIL))
{
return 1;
}
- if (aFW->StatusConnected(ShapeExtend_DONE3))
+ if (aMode == StrongWireMode_KeepCurveType)
+ {
+ aFW->FixCurves();
+ if (aFW->StatusCurves(ShapeExtend_FAIL))
+ {
+ Message::SendFail() << "Wire construction failed: cannot rebuild curves through new points";
+ return 1;
+ }
+ }
+ else if (aFW->StatusConnected(ShapeExtend_DONE3))
{
if (aMode != StrongWireMode_Approximation)
- aFW->SetPrecision(aTolerance);
+ aFW->SetPrecision(aTolerance);
aFW->FixGapsByRangesMode() = Standard_True;
if (aFW->FixGaps3d())
{
Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
- for (Standard_Integer anIdx = 1; anIdx <= sbwd->NbEdges(); anIdx++)
+ for (Standard_Integer anIdx = 1; anIdx <= sbwd->NbEdges(); anIdx++)
{
TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(anIdx));
aFe->FixVertexTolerance(aEdge);
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <GeomConvert_CompCurveToBSplineCurve.hxx>
+#include <gp_Elips.hxx>
#include <gp_Pln.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <IntRes2d_SequenceOfIntersectionPoint.hxx>
myStatusReorder = emptyStatus;
myStatusSmall = emptyStatus;
myStatusConnected = emptyStatus;
+ myStatusCurves = emptyStatus;
myStatusEdgeCurves = emptyStatus;
myStatusDegenerated = emptyStatus;
myStatusSelfIntersection = emptyStatus;
//=======================================================================
Standard_Boolean ShapeFix_Wire::FixCurves()
{
- myStatusConnected = ShapeExtend::EncodeStatus(ShapeExtend_OK);
+ myStatusCurves = ShapeExtend::EncodeStatus(ShapeExtend_OK);
if (!IsLoaded()) return Standard_False;
- Standard_Integer stop = (myClosedMode ? 0 : 1);
- for (Standard_Integer anIdx = NbEdges(); anIdx > stop; anIdx--)
- {
+ for (Standard_Integer anIdx = NbEdges(); anIdx > 0; anIdx--) {
FixCurves(anIdx);
- myStatusConnected |= myLastFixStatus;
+ myStatusCurves |= myLastFixStatus;
}
- return StatusConnected(ShapeExtend_DONE);
+ return StatusCurves(ShapeExtend_DONE);
}
//=======================================================================
aCurve3d->D0(aCurBounds[0], aGeomEnds[0]);
aCurve3d->D0(aCurBounds[2], aGeomEnds[1]);
- // TODO: precise, if IsReversed flag should be considered here
Standard_Real aGap0 = Min(anEnds[0].Distance(aGeomEnds[0]), anEnds[0].Distance(aGeomEnds[1]));
Standard_Real aGap2 = Min(anEnds[2].Distance(aGeomEnds[0]), anEnds[2].Distance(aGeomEnds[1]));
- if (Max (aGap0, aGap2) < aPrec) // nothing to do
+ if (Max (aGap0, aGap2) < Precision::Confusion()) // nothing to do
return true;
- if (aCurve3d->IsKind(STANDARD_TYPE(Geom_Circle)))
- {
+ if (aCurve3d->IsKind(STANDARD_TYPE(Geom_Circle))) {
Standard_Real anOldR = Handle(Geom_Circle)::DownCast(aCurve3d)->Circ().Radius();
gp_Vec anArcNorm = gp_Vec(anEnds[2], anEnds[0]) / 2;
gp_Pnt aCenter(anEnds[0].XYZ() - anArcNorm.XYZ());
anSbwd->Set(aNewEdge, theIdx);
return true;
}
- else if (aCurve3d->IsKind(STANDARD_TYPE(Geom_Ellipse)))
- {
+ else if (aCurve3d->IsKind(STANDARD_TYPE(Geom_Ellipse))) {
+ /// aaajfa: BEGIN - to provide elliptic edge FORWARD orientation
+ gp_Pnt tmpPnt = anEnds[0];
+ anEnds[0] = anEnds[2];
+ anEnds[2] = tmpPnt;
+ /// aaajfa: END - to provide elliptic edge FORWARD orientation
+
Handle(Geom_Ellipse) anOld = Handle(Geom_Ellipse)::DownCast(aCurve3d);
Handle(Geom_Plane) aPln = new Geom_Plane(anEnds[0], gp_Vec(anEnds[2], anEnds[0]).Crossed(gp_Vec(anEnds[1], anEnds[0])));
GeomAPI_ProjectPointOnSurf aProjector(anOld->Elips().Location(), aPln);
gp_Pnt anOrigin = aProjector.NearestPoint();
aProjector.Init(anOld->Elips().Location().XYZ() + anOld->Elips().XAxis().Direction().XYZ(), aPln);
gp_Ax2 anAx(anOrigin, aPln->Axis().Direction(), aProjector.NearestPoint().XYZ() - anOrigin.XYZ());
-
+
// compute angle
Standard_Real aRec = DBL_MAX;
Standard_Real anAngle = 0.;
for (Standard_Integer anIdxI = -aSplNum; anIdxI < aSplNum; ++anIdxI)
{
Handle(Geom_Ellipse) anEll = new Geom_Ellipse(anAx, anOld->MajorRadius(), anOld->MinorRadius());
- anEll->Rotate(anAx.Axis(), aPrec*anIdxI / anEll->MajorRadius() / aSplNum);
+ Standard_Real anAnglei = aPrec*anIdxI / anEll->MajorRadius() / aSplNum;
+ anEll->Rotate(anAx.Axis(), anAnglei);
GeomAPI_ProjectPointOnCurve aProjector1(anEnds[0], anEll);
Standard_Real aDist = 0.;
for (Standard_Integer anIdxJ = 0; anIdxJ < 2; ++anIdxJ)
if (aDist < aRec)
{
aRec = aDist;
- anAngle = aPrec*anIdxI / anEll->MajorRadius() / aSplNum;
+ anAngle = anAnglei;
}
}
gp_Elips aTemp(anAx, anOld->MajorRadius(), anOld->MinorRadius());
gp_Vec aY = aTemp.YAxis().Direction();
gp_Pnt2d aP1((anEnds[0].XYZ() - anOrigin.XYZ()).Dot(aX.XYZ()), (anEnds[0].XYZ() - anOrigin.XYZ()).Dot(aY.XYZ()));
gp_Pnt2d aP2((anEnds[2].XYZ() - anOrigin.XYZ()).Dot(aX.XYZ()), (anEnds[2].XYZ() - anOrigin.XYZ()).Dot(aY.XYZ()));
-
+
// x = ky + p linear equation
// where (x, y) shift point,
// k, p constant coefficients
Standard_Real y2 = (-b + sqrt(b*b - 4 * a*c)) / 2 / a;
Standard_Real x1 = k*y1 + p;
Standard_Real x2 = k*y2 + p;
-
+
gp_Pnt anOri = anOld->Location();
if (x1*x1 + y1*y1 < x2*x2 + y2*y2)
anOri = anOri.XYZ() + aX.XYZ()*x1 + aY.XYZ()*y1;
else
anOri = anOri.XYZ() + aX.XYZ()*x2 + aY.XYZ()*y2;
aTemp.SetLocation(anOri);
-
+
GC_MakeArcOfEllipse anArc(aTemp, anEnds[2], anEnds[0], true);
TopoDS_Edge aNewEdge = BRepBuilderAPI_MakeEdge(anArc.Value()).Edge();
anSbwd->Set(aNewEdge, theIdx);
}
else if (aCurve3d->IsKind(STANDARD_TYPE(Geom_Line)))
{
- TopoDS_Edge aNewEdge = BRepBuilderAPI_MakeEdge(anEnds[2], anEnds[0]).Edge();
+ TopoDS_Edge aNewEdge = BRepBuilderAPI_MakeEdge(anEnds[0], anEnds[2]).Edge();
anSbwd->Set(aNewEdge, theIdx);
return true;
}
return true;
}
- // TODO: question: the below code works only for other curve types (not line/arc/circle/ellipse/bspline)
- // Is it really needed?
- myAnalyzer->CheckConnected(theIdx, aPrec);
- if (myAnalyzer->LastCheckStatus(ShapeExtend_FAIL))
- myLastFixStatus |= ShapeExtend::EncodeStatus(ShapeExtend_FAIL1);
-
return true;
}