// constructor method int Line2dSegmentPy::PyInit(PyObject* args, PyObject* /*kwd*/) { #if 1 return 0; #else if (PyArg_ParseTuple(args, "")) { // default line Infinite=false; return 0; } PyErr_Clear(); PyObject *pLine; if (PyArg_ParseTuple(args, "O!", &(Line2dSegmentPy::Type), &pLine)) { // Copy line Line2dSegmentPy* pcLine = static_cast<Line2dSegmentPy*>(pLine); // get Geom_Line of line segment Handle_Geom_TrimmedCurve that_curv = Handle_Geom_TrimmedCurve::DownCast (pcLine->getGeom2dLineSegmentPtr()->handle()); Handle_Geom_Line that_line = Handle_Geom_Line::DownCast (that_curv->BasisCurve()); // get Geom_Line of line segment Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle_Geom_Line this_line = Handle_Geom_Line::DownCast (this_curv->BasisCurve()); Infinite = pcLine->Infinite; // Assign the lines this_line->SetLin(that_line->Lin()); this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); return 0; } PyErr_Clear(); double first, last; if (PyArg_ParseTuple(args, "O!dd", &(Line2dSegmentPy::Type), &pLine, &first, &last)) { // Copy line Line2dSegmentPy* pcLine = static_cast<Line2dSegmentPy*>(pLine); // get Geom_Line of line segment Handle_Geom_TrimmedCurve that_curv = Handle_Geom_TrimmedCurve::DownCast (pcLine->getGeom2dLineSegmentPtr()->handle()); Handle_Geom_Line that_line = Handle_Geom_Line::DownCast (that_curv->BasisCurve()); // get Geom_Line of line segment Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle_Geom_Line this_line = Handle_Geom_Line::DownCast (this_curv->BasisCurve()); Infinite = pcLine->Infinite; // 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, &(Base::VectorPy::Type), &pV2)) { Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value(); Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value(); try { // Create line out of two points double distance = Base::Distance(v1, v2); if (distance < gp::Resolution()) Standard_Failure::Raise("Both points are equal"); GC_MakeSegment ms(gp_Pnt(v1.x,v1.y,v1.z), gp_Pnt(v2.x,v2.y,v2.z)); if (!ms.IsDone()) { PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(ms.Status())); return -1; } // get Geom_Line of line segment Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle_Geom_Line this_line = Handle_Geom_Line::DownCast (this_curv->BasisCurve()); Handle_Geom_TrimmedCurve that_curv = ms.Value(); Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve()); this_line->SetLin(that_line->Lin()); this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); Infinite = false; return 0; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return -1; } catch (...) { PyErr_SetString(PartExceptionOCCError, "creation of line failed"); return -1; } } PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n" "-- empty parameter list\n" "-- Line\n" "-- Point, Point"); return -1; #endif }
// constructor method int Line2dSegmentPy::PyInit(PyObject* args, PyObject* /*kwd*/) { if (PyArg_ParseTuple(args, "")) { // default line return 0; } PyErr_Clear(); PyObject *pLine; if (PyArg_ParseTuple(args, "O!", &(Line2dSegmentPy::Type), &pLine)) { // Copy line Line2dSegmentPy* pcLine = static_cast<Line2dSegmentPy*>(pLine); // get Geom_Line of line segment Handle(Geom2d_TrimmedCurve) that_curv = Handle(Geom2d_TrimmedCurve)::DownCast (pcLine->getGeom2dLineSegmentPtr()->handle()); Handle(Geom2d_Line) that_line = Handle(Geom2d_Line)::DownCast (that_curv->BasisCurve()); // get Geom_Line of line segment Handle(Geom2d_TrimmedCurve) this_curv = Handle(Geom2d_TrimmedCurve)::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle(Geom2d_Line) this_line = Handle(Geom2d_Line)::DownCast (this_curv->BasisCurve()); // Assign the lines this_line->SetLin2d(that_line->Lin2d()); this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); return 0; } PyErr_Clear(); double first, last; if (PyArg_ParseTuple(args, "O!dd", &(Line2dSegmentPy::Type), &pLine, &first, &last)) { // Copy line Line2dSegmentPy* pcLine = static_cast<Line2dSegmentPy*>(pLine); // get Geom_Line of line segment Handle(Geom2d_TrimmedCurve) that_curv = Handle(Geom2d_TrimmedCurve)::DownCast (pcLine->getGeom2dLineSegmentPtr()->handle()); Handle(Geom2d_Line) that_line = Handle(Geom2d_Line)::DownCast (that_curv->BasisCurve()); // get Geom_Line of line segment Handle(Geom2d_TrimmedCurve) this_curv = Handle(Geom2d_TrimmedCurve)::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle(Geom2d_Line) this_line = Handle(Geom2d_Line)::DownCast (this_curv->BasisCurve()); // Assign the lines this_line->SetLin2d(that_line->Lin2d()); this_curv->SetTrim(first, last); return 0; } PyErr_Clear(); if (PyArg_ParseTuple(args, "O!dd", &(Line2dPy::Type), &pLine, &first, &last)) { // Copy line Line2dPy* pcLine = static_cast<Line2dPy*>(pLine); // get Geom_Line of line Handle(Geom2d_Line) that_line = Handle(Geom2d_Line)::DownCast (pcLine->getGeom2dLinePtr()->handle()); // get Geom_Line of line segment Handle(Geom2d_TrimmedCurve) this_curv = Handle(Geom2d_TrimmedCurve)::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle(Geom2d_Line) this_line = Handle(Geom2d_Line)::DownCast (this_curv->BasisCurve()); // Assign the lines this_line->SetLin2d(that_line->Lin2d()); this_curv->SetTrim(first, last); return 0; } PyErr_Clear(); PyObject *pV1, *pV2; if (PyArg_ParseTuple(args, "O!O!", Base::Vector2dPy::type_object(), &pV1, Base::Vector2dPy::type_object(), &pV2)) { Base::Vector2d v1 = Py::toVector2d(pV1); Base::Vector2d v2 = Py::toVector2d(pV2); try { // Create line out of two points double distance = (v1-v2).Length(); if (distance < gp::Resolution()) Standard_Failure::Raise("Both points are equal"); GCE2d_MakeSegment ms(gp_Pnt2d(v1.x,v1.y), gp_Pnt2d(v2.x,v2.y)); if (!ms.IsDone()) { PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(ms.Status())); return -1; } // get Geom_Line of line segment Handle(Geom2d_TrimmedCurve) this_curv = Handle(Geom2d_TrimmedCurve)::DownCast (this->getGeom2dLineSegmentPtr()->handle()); Handle(Geom2d_Line) this_line = Handle(Geom2d_Line)::DownCast (this_curv->BasisCurve()); Handle(Geom2d_TrimmedCurve) that_curv = ms.Value(); Handle(Geom2d_Line) that_line = Handle(Geom2d_Line)::DownCast(that_curv->BasisCurve()); this_line->SetLin2d(that_line->Lin2d()); this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); return 0; } catch (Standard_Failure& e) { PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); return -1; } catch (...) { PyErr_SetString(PartExceptionOCCError, "creation of line failed"); return -1; } } PyErr_SetString(PyExc_TypeError, "Line2dSegment constructor accepts:\n" "-- empty parameter list\n" "-- Line2dSegment\n" "-- Line2dSegment, float, float\n" "-- Line2d, float, float\n" "-- Point, Point"); return -1; }