diff --git a/src/Mod/Part/App/LineSegmentPyImp.cpp b/src/Mod/Part/App/LineSegmentPyImp.cpp index 975acb179..ecb7ecd36 100644 --- a/src/Mod/Part/App/LineSegmentPyImp.cpp +++ b/src/Mod/Part/App/LineSegmentPyImp.cpp @@ -115,6 +115,25 @@ int LineSegmentPy::PyInit(PyObject* args, PyObject* /*kwd*/) return 0; } + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!dd", &(LinePy::Type), &pLine, &first, &last)) { + // Copy line + LinePy* pcLine = static_cast(pLine); + // get Geom_Line of line segment + Handle_Geom_Line that_line = Handle_Geom_Line::DownCast + (pcLine->getGeomLinePtr()->handle()); + // get Geom_Line of line segment + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (this->getGeomLineSegmentPtr()->handle()); + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + + // Assign the lines + this_line->SetLin(that_line->Lin()); + this_curv->SetTrim(first, last); + return 0; + } + PyErr_Clear(); PyObject *pV1, *pV2; if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type), &pV1, @@ -159,6 +178,8 @@ int LineSegmentPy::PyInit(PyObject* args, PyObject* /*kwd*/) PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n" "-- empty parameter list\n" "-- LineSegment\n" + "-- LineSegment,double,double\n" + "-- Line,double,double\n" "-- Point, Point"); return -1; } diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index da1266c05..1d6f33b35 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -683,6 +683,9 @@ Py::Float TopoShapeEdgePy::getLength(void) const return Py::Float(GCPnts_AbscissaPoint::Length(adapt)); } +#include +#include + Py::Object TopoShapeEdgePy::getCurve() const { const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->getShape()); @@ -691,11 +694,41 @@ Py::Object TopoShapeEdgePy::getCurve() const { case GeomAbs_Line: { - GeomLine* line = new GeomLine(); - Handle_Geom_Line this_curv = Handle_Geom_Line::DownCast - (line->handle()); - this_curv->SetLin(adapt.Line()); - return Py::Object(new LinePy(line),true); + static bool LineOld = true; + static bool init = false; + if (!init) { + init = true; + Base::Reference hPartGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part"); + Base::Reference hGenPGrp = hPartGrp->GetGroup("General"); + LineOld = hGenPGrp->GetBool("LineOld", true); + } + + if (LineOld) { + GeomLineSegment* line = new GeomLineSegment(); + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (line->handle()); + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + this_line->SetLin(adapt.Line()); + this_curv->SetTrim(adapt.FirstParameter(), adapt.LastParameter()); + PyErr_SetString(PyExc_DeprecationWarning, + "For future usage 'Curve' will return 'Line' which is infinite " + "instead of the limited 'LineSegment'.\n" + "If you need a line segment then use this:\n" + "Part.LineSegment(edge.Curve,edge.FirstParameter,edge.LastParameter)" + "To suppress the warning set BaseApp/Preferences/Mod/Part/General/LineOld to false"); + PyErr_Print(); + + return Py::Object(new LineSegmentPy(line),true); // LinePyOld + } + else { + GeomLine* line = new GeomLine(); + Handle_Geom_Line this_curv = Handle_Geom_Line::DownCast + (line->handle()); + this_curv->SetLin(adapt.Line()); + return Py::Object(new LinePy(line),true); + } } case GeomAbs_Circle: {