PyObject* BezierSurfacePy::removePoleRow(PyObject *args) { int uindex; if (!PyArg_ParseTuple(args, "i",&uindex)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); surf->RemovePoleRow(uindex); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
App::DocumentObjectExecReturn *Ellipsoid::execute(void) { // Build a sphere if (Radius1.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Radius of ellipsoid too small"); if (Radius2.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Radius of ellipsoid too small"); try { gp_Pnt pnt(0.0,0.0,0.0); gp_Dir dir(0.0,0.0,1.0); gp_Ax2 ax2(pnt,dir); BRepPrimAPI_MakeSphere mkSphere(ax2, Radius2.getValue(), Angle1.getValue()/180.0f*M_PI, Angle2.getValue()/180.0f*M_PI, Angle3.getValue()/180.0f*M_PI); Standard_Real scaleX = 1.0; Standard_Real scaleZ = Radius1.getValue()/Radius2.getValue(); // issue #1798: A third radius has been introduced. To be backward // compatible if Radius3 is 0.0 (default) it's handled to be the same // as Radius2 Standard_Real scaleY = 1.0; if (Radius3.getValue() >= Precision::Confusion()) scaleY = Radius3.getValue()/Radius2.getValue(); gp_GTrsf mat; mat.SetValue(1,1,scaleX); mat.SetValue(2,1,0.0); mat.SetValue(3,1,0.0); mat.SetValue(1,2,0.0); mat.SetValue(2,2,scaleY); mat.SetValue(3,2,0.0); mat.SetValue(1,3,0.0); mat.SetValue(2,3,0.0); mat.SetValue(3,3,scaleZ); BRepBuilderAPI_GTransform mkTrsf(mkSphere.Shape(), mat); TopoDS_Shape ResultShape = mkTrsf.Shape(); this->Shape.setValue(ResultShape); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } return Primitive::execute(); }
App::DocumentObjectExecReturn *Fillet::execute(void) { App::DocumentObject* link = Base.getValue(); if (!link) return new App::DocumentObjectExecReturn("No object linked"); if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) return new App::DocumentObjectExecReturn("Linked object is not a Part object"); Part::Feature *base = static_cast<Part::Feature*>(Base.getValue()); const Part::TopoShape& TopShape = base->Shape.getShape(); if (TopShape._Shape.IsNull()) return new App::DocumentObjectExecReturn("Cannot fillet invalid shape"); const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Edge"); if (SubVals.size() == 0) return new App::DocumentObjectExecReturn("No edges specified"); double radius = Radius.getValue(); this->positionByBase(); // create an untransformed copy of the base shape Part::TopoShape baseShape(TopShape); baseShape.setTransform(Base::Matrix4D()); try { BRepFilletAPI_MakeFillet mkFillet(baseShape._Shape); for (std::vector<std::string>::const_iterator it=SubVals.begin(); it != SubVals.end(); ++it) { TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str())); mkFillet.Add(radius, edge); } mkFillet.Build(); if (!mkFillet.IsDone()) return new App::DocumentObjectExecReturn("Failed to create fillet"); TopoDS_Shape shape = mkFillet.Shape(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is null"); this->Shape.setValue(shape); return App::DocumentObject::StdReturn; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } }
PyObject* BSplineSurfacePy::setVOrigin(PyObject *args) { int index; if (!PyArg_ParseTuple(args, "i", &index)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); surf->SetVOrigin(index); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* BSplineCurve2dPy::segment(PyObject * args) { double u1,u2; if (!PyArg_ParseTuple(args, "dd", &u1,&u2)) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); curve->Segment(u1,u2); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineCurve2dPy::getMultiplicity(PyObject * args) { int index; if (!PyArg_ParseTuple(args, "i", &index)) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); int mult = curve->Multiplicity(index); return Py_BuildValue("i", mult); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineSurfacePy::segment(PyObject *args) { double u1,u2,v1,v2; if (!PyArg_ParseTuple(args, "dddd", &u1,&u2,&v1,&v2)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); surf->Segment(u1,u2,v1,v2); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* BSplineCurve2dPy::setOrigin(PyObject * args) { int index; if (!PyArg_ParseTuple(args, "i", &index)) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); curve->SetOrigin(index); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BezierSurfacePy::increase(PyObject *args) { int udegree,vdegree; if (!PyArg_ParseTuple(args, "ii", &udegree, &vdegree)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); surf->Increase(udegree, vdegree); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* AttachableObjectPy::positionBySupport(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; bool bAttached = false; try{ bAttached = this->getAttachableObjectPtr()->positionBySupport(); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return NULL; } catch (Base::Exception &e) { PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); return NULL; } return Py::new_reference_to(Py::Boolean(bAttached)); }
PyObject* BSplineSurfacePy::getVMultiplicity(PyObject *args) { int index; if (!PyArg_ParseTuple(args, "i", &index)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); int mult = surf->VMultiplicity(index); return Py_BuildValue("i", mult); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* TopoShapeFacePy::makeHalfSpace(PyObject *args) { PyObject* pPnt; if (!PyArg_ParseTuple(args, "O!",&(Base::VectorPy::Type),&pPnt)) return 0; try { Base::Vector3d pt = Py::Vector(pPnt,false).toVector(); BRepPrimAPI_MakeHalfSpace mkHS(TopoDS::Face(this->getTopoShapePtr()->_Shape), gp_Pnt(pt.x,pt.y,pt.z)); return new TopoShapeSolidPy(new TopoShape(mkHS.Solid())); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* GeometrySurfacePy::VPeriod(PyObject * args) { if (!PyArg_ParseTuple(args, "")) return 0; try { Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast (getGeometryPtr()->handle()); Standard_Real val = surf->VPeriod(); return PyFloat_FromDouble(val); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* TopoShapeEdgePy::discretize(PyObject *args) { PyObject* defl_or_num; if (!PyArg_ParseTuple(args, "O", &defl_or_num)) return 0; try { BRepAdaptor_Curve adapt(TopoDS::Edge(getTopoShapePtr()->_Shape)); GCPnts_UniformAbscissa discretizer; if (PyInt_Check(defl_or_num)) { int num = PyInt_AsLong(defl_or_num); discretizer.Initialize (adapt, num); } else if (PyFloat_Check(defl_or_num)) { double defl = PyFloat_AsDouble(defl_or_num); discretizer.Initialize (adapt, defl); } else { PyErr_SetString(PyExc_TypeError, "Either int or float expected"); return 0; } if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = adapt.Value (discretizer.Parameter (i)); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PyExc_Exception, "Descretization of curve failed"); return 0; } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } PyErr_SetString(PyExc_Exception, "Geometry is not a curve"); return 0; }
// constructor method int TopoShapeShellPy::PyInit(PyObject* args, PyObject* /*kwd*/) { PyObject *obj; if (!PyArg_ParseTuple(args, "O", &obj)) return -1; BRep_Builder builder; TopoDS_Shape shape; TopoDS_Shell shell; //BRepOffsetAPI_Sewing mkShell; builder.MakeShell(shell); try { Py::Sequence list(obj); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapeFacePy::Type))) { const TopoDS_Shape& sh = static_cast<TopoShapeFacePy*>((*it).ptr())-> getTopoShapePtr()->_Shape; if (!sh.IsNull()) builder.Add(shell, sh); } } shape = shell; BRepCheck_Analyzer check(shell); if (!check.IsValid()) { ShapeUpgrade_ShellSewing sewShell; shape = sewShell.ApplySewing(shell); } if (shape.IsNull()) Standard_Failure::Raise("Shape is null"); if (shape.ShapeType() != TopAbs_SHELL) Standard_Failure::Raise("Shape is not a shell"); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return -1; } getTopoShapePtr()->_Shape = shape; return 0; }
int OCCWire::offset(double distance, int joinType = 0) { Handle(TopTools_HSequenceOfShape) wires = new TopTools_HSequenceOfShape; Handle(TopTools_HSequenceOfShape) edges = new TopTools_HSequenceOfShape; TopExp_Explorer ex; try { GeomAbs_JoinType join = GeomAbs_Arc; switch (joinType) { case 1: join = GeomAbs_Tangent; break; case 2: join = GeomAbs_Intersection; break; } BRepOffsetAPI_MakeOffset MO(this->getWire(), join); MO.Perform(distance); for (ex.Init(MO.Shape(), TopAbs_EDGE); ex.More(); ex.Next()) { if (!ex.Current().IsNull()) { edges->Append(TopoDS::Edge(ex.Current())); } } ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edges,Precision::Confusion(),Standard_True,wires); if (wires->Length() != 1) StdFail_NotDone::Raise("offset operation created empty result"); this->setShape(wires->Value(1)); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to offset wire"); } return 0; } return 1; }
PyObject* AttachableObjectPy::changeAttacherType(PyObject *args) { const char* typeName; if (!PyArg_ParseTuple(args, "s", &typeName)) return 0; bool ret; try{ ret = this->getAttachableObjectPtr()->changeAttacherType(typeName); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return NULL; } catch (Base::Exception &e) { PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); return NULL; } return Py::new_reference_to(Py::Boolean(ret)); }
PyObject* ConePy::vIso(PyObject * args) { double v; if (!PyArg_ParseTuple(args, "d", &v)) return 0; try { Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast (getGeomConePtr()->handle()); Handle_Geom_Curve c = cone->VIso(v); return new CirclePy(new GeomCircle(Handle_Geom_Circle::DownCast(c))); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineSurfacePy::getResolution(PyObject *args) { double tol; if (!PyArg_ParseTuple(args, "d", &tol)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); double utol, vtol; surf->Resolution(tol,utol,vtol); return Py_BuildValue("(dd)",utol,vtol); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* TopoShapeWirePy::makePipe(PyObject *args) { PyObject *pShape; if (PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pShape)) { try { TopoDS_Shape profile = static_cast<TopoShapePy*>(pShape)->getTopoShapePtr()->_Shape; TopoDS_Shape shape = this->getTopoShapePtr()->makePipe(profile); return new TopoShapePy(new TopoShape(shape)); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } } return 0; }
PyObject* BSplineSurfacePy::uIso(PyObject * args) { double u; if (!PyArg_ParseTuple(args, "d", &u)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); Handle_Geom_Curve c = surf->UIso(u); return new BSplineCurvePy(new GeomBSplineCurve(Handle_Geom_BSplineCurve::DownCast(c))); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
Py::Object AttachableObjectPy::getAttacher(void) const { try { this->getAttachableObjectPtr()->attacher(); //throws if attacher is not set } catch (Base::Exception) { return Py::None(); } try { return Py::Object( new Attacher::AttachEnginePy(this->getAttachableObjectPtr()->attacher().copy()), true); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); throw Py::Exception(Part::PartExceptionOCCError, e->GetMessageString()); } catch (Base::Exception &e) { throw Py::Exception(Base::BaseExceptionFreeCADError, e.what()); } }
PyObject* BSplineSurfacePy::setWeight(PyObject *args) { int uindex,vindex; double weight; if (!PyArg_ParseTuple(args, "iid",&uindex,&vindex,&weight)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); surf->SetWeight(uindex,vindex,weight); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* ToroidPy::vIso(PyObject * args) { double v; if (!PyArg_ParseTuple(args, "d", &v)) return 0; try { Handle_Geom_ToroidalSurface torus = Handle_Geom_ToroidalSurface::DownCast (getGeomToroidPtr()->handle()); Handle_Geom_Circle c = Handle_Geom_Circle::DownCast(torus->VIso(v)); return new CirclePy(new GeomCircle(c)); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* BezierCurve2dPy::getResolution(PyObject* args) { double tol; if (!PyArg_ParseTuple(args, "d", &tol)) return 0; try { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); double utol; curve->Resolution(tol,utol); return Py_BuildValue("d",utol); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
int OCCEdge::createLine(OCCVertex *start, OCCVertex *end) { try { gp_Pnt aP1(start->X(), start->Y(), start->Z()); gp_Pnt aP2(end->X(), end->Y(), end->Z()); GC_MakeLine line(aP1, aP2); this->setShape(BRepBuilderAPI_MakeEdge(line, start->vertex, end->vertex)); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to create line"); } return 0; } return 1; }
PyObject* BezierCurve2dPy::setWeight(PyObject * args) { int index; double weight; if (!PyArg_ParseTuple(args, "id", &index,&weight)) return 0; try { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); curve->SetWeight(index,weight); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BezierSurfacePy::exchangeUV(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); //FIXME: Crashes surf->ExchangeUV(); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BezierSurfacePy::vIso(PyObject * args) { double v; if (!PyArg_ParseTuple(args, "d", &v)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); Handle_Geom_Curve c = surf->VIso(v); return new BezierCurvePy(new GeomBezierCurve(Handle_Geom_BezierCurve::DownCast(c))); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
int OCCEdge::createHelix(double pitch, double height, double radius, double angle, bool leftHanded) { try { gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); if (radius <= Precision::Confusion()) { StdFail_NotDone::Raise("radius to small"); } Handle_Geom_Surface surf; if (angle <= 0.0) { surf = new Geom_CylindricalSurface(cylAx2, radius); } else { surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius); } gp_Pnt2d aPnt(0, 0); gp_Dir2d aDir(2. * M_PI, pitch); if (leftHanded) { aPnt.SetCoord(2. * M_PI, 0.0); aDir.SetCoord(-2. * M_PI, pitch); } gp_Ax2d aAx2d(aPnt, aDir); Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d); gp_Pnt2d pnt_beg = line->Value(0); gp_Pnt2d pnt_end = line->Value(sqrt(4.0*M_PI*M_PI+pitch*pitch)*(height/pitch)); const Handle(Geom2d_TrimmedCurve)& segm = GCE2d_MakeSegment(pnt_beg , pnt_end); this->setShape(BRepBuilderAPI_MakeEdge(segm , surf)); BRepLib::BuildCurves3d(edge); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to create helix"); } return 0; } return 1; }