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* BezierSurfacePy::setWeight(PyObject *args) { int uindex,vindex; double weight; if (!PyArg_ParseTuple(args, "iid",&uindex,&vindex,&weight)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); surf->SetWeight(uindex,vindex,weight); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineCurvePy::setWeight(PyObject * args) { int index; double weight; if (!PyArg_ParseTuple(args, "id", &index,&weight)) return 0; try { Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::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* 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* 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* BSplineSurfacePy::vIso(PyObject * args) { double v; if (!PyArg_ParseTuple(args, "d", &v)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); Handle_Geom_Curve c = surf->VIso(v); 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* 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* BezierSurfacePy::uIso(PyObject * args) { double u; if (!PyArg_ParseTuple(args, "d", &u)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); Handle_Geom_Curve c = surf->UIso(u); 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; } }
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::getResolution(PyObject *args) { double tol; if (!PyArg_ParseTuple(args, "d", &tol)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::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(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; }
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; }
OCCMesh *OCCFace::createMesh(double factor, double angle, bool qualityNormals = true) { OCCMesh *mesh = new OCCMesh(); try { Bnd_Box aBox; BRepBndLib::Add(this->getShape(), aBox); Standard_Real aXmin, aYmin, aZmin; Standard_Real aXmax, aYmax, aZmax; aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); Standard_Real maxd = fabs(aXmax - aXmin); maxd = std::max(maxd, fabs(aYmax - aYmin)); maxd = std::max(maxd, fabs(aZmax - aZmin)); BRepMesh_FastDiscret MSH(factor*maxd, angle, aBox, Standard_False, Standard_False, Standard_True, Standard_True); MSH.Perform(this->getShape()); BRepMesh_IncrementalMesh(this->getShape(),factor*maxd); if (this->getShape().ShapeType() != TopAbs_FACE) { TopExp_Explorer exFace; for (exFace.Init(this->getShape(), TopAbs_FACE); exFace.More(); exFace.Next()) { const TopoDS_Face& faceref = static_cast<const TopoDS_Face &>(exFace.Current()); mesh->extractFaceMesh(faceref, qualityNormals); } } else { mesh->extractFaceMesh(this->getFace(), qualityNormals); } } 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 mesh"); } return NULL; } return mesh; }
int OCCTools::readBREP(std::istream& str, TopoDS_Shape& shape) { try { // read brep-file BRep_Builder aBuilder; BRepTools::Read(shape, str, aBuilder); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); //printf("ERROR: %s\n", e->GetMessageString()); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to read BREP file"); } return 0; } return 1; }
PyObject* LinePy::setParameterRange(PyObject *args) { double first, last; if (!PyArg_ParseTuple(args, "dd", &first, &last)) return NULL; try { Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast (this->getGeomLineSegmentPtr()->handle()); this_curve->SetTrim(first, last); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return NULL; } Py_Return; }
App::DocumentObjectExecReturn* Sphere::execute(void) { // Build a sphere if (Radius.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Radius of sphere too small"); try { BRepPrimAPI_MakeSphere mkSphere(Radius.getValue(), Angle1.getValue()/180.0f*M_PI, Angle2.getValue()/180.0f*M_PI, Angle3.getValue()/180.0f*M_PI); return FeaturePrimitive::execute(mkSphere.Shape()); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } return App::DocumentObject::StdReturn; }
int OCCEdge::createArc3P(OCCVertex *start, OCCVertex *end, OCCStruct3d aPoint) { try { gp_Pnt aP1(start->X(), start->Y(), start->Z()); gp_Pnt aP2(aPoint.x, aPoint.y, aPoint.z); gp_Pnt aP3(end->X(), end->Y(), end->Z()); GC_MakeArcOfCircle arc(aP1, aP2, aP3); this->setShape(BRepBuilderAPI_MakeEdge(arc, 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 arc"); } return 0; } return 1; }
App::DocumentObjectExecReturn *Helix::execute(void) { try { Standard_Real myPitch = Pitch.getValue(); Standard_Real myHeight = Height.getValue(); Standard_Real myRadius = Radius.getValue(); Standard_Real myAngle = Angle.getValue(); Standard_Boolean myLocalCS = LocalCoord.getValue() ? Standard_True : Standard_False; Standard_Boolean myStyle = Style.getValue() ? Standard_True : Standard_False; TopoShape helix; this->Shape.setValue(helix.makeHelix(myPitch, myHeight, myRadius, myAngle, myLocalCS, myStyle)); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } return App::DocumentObject::StdReturn; }
PyObject* BezierCurve2dPy::getWeight(PyObject * args) { int index; if (!PyArg_ParseTuple(args, "i", &index)) return 0; try { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); Standard_OutOfRange_Raise_if (index < 1 || index > curve->NbPoles() , "Weight index out of range"); double weight = curve->Weight(index); return Py_BuildValue("d", weight); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineCurve2dPy::removeKnot(PyObject * args) { double tol; int Index,M; if (!PyArg_ParseTuple(args, "iid", &Index, &M, &tol)) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); Standard_Boolean ok = curve->RemoveKnot(Index,M,tol); return PyBool_FromLong(ok ? 1 : 0); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineSurfacePy::incrementVMultiplicity(PyObject *args) { int start, end, mult; if (!PyArg_ParseTuple(args, "iii", &start, &end, &mult)) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); surf->IncrementVMultiplicity(start, end, mult); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } Py_Return; }
PyObject* BSplineCurve2dPy::incrementMultiplicity(PyObject * args) { int start, end, mult; if (!PyArg_ParseTuple(args, "iii", &start, &end, &mult)) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); curve->IncrementMultiplicity(start, end, mult); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } Py_Return; }
PyObject* BSplineCurve2dPy::makeC1Continuous(PyObject *args) { double tol = Precision::Approximation(); if (!PyArg_ParseTuple(args, "|d", &tol)) return 0; try { Geom2dBSplineCurve* spline = this->getGeom2dBSplineCurvePtr(); spline->makeC1Continuous(tol); Py_Return; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); std::string err = e->GetMessageString(); if (err.empty()) err = e->DynamicType()->Name(); PyErr_SetString(PartExceptionOCCError, err.c_str()); return 0; } }
App::DocumentObjectExecReturn *Loft::execute(void) { if (Sections.getSize() == 0) return new App::DocumentObjectExecReturn("No sections linked."); try { TopTools_ListOfShape profiles; const std::vector<App::DocumentObject*>& shapes = Sections.getValues(); std::vector<App::DocumentObject*>::const_iterator it; for (it = shapes.begin(); it != shapes.end(); ++it) { if (!(*it)->isDerivedFrom(Part::Feature::getClassTypeId())) return new App::DocumentObjectExecReturn("Linked object is not a shape."); const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Linked shape is invalid."); if (shape.ShapeType() == TopAbs_WIRE) { profiles.Append(shape); } else if (shape.ShapeType() == TopAbs_EDGE) { BRepBuilderAPI_MakeWire mkWire(TopoDS::Edge(shape)); profiles.Append(mkWire.Wire()); } else if (shape.ShapeType() == TopAbs_VERTEX) { profiles.Append(shape); } else { return new App::DocumentObjectExecReturn("Linked shape is not a vertex, edge nor wire."); } } Standard_Boolean isSolid = Solid.getValue() ? Standard_True : Standard_False; Standard_Boolean isRuled = Ruled.getValue() ? Standard_True : Standard_False; TopoShape myShape; this->Shape.setValue(myShape.makeLoft(profiles, isSolid, isRuled)); return App::DocumentObject::StdReturn; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } }
PyObject* GeometryCurvePy::intersectCS(PyObject *args) { Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast(getGeometryPtr()->handle()); try { if (!curve.IsNull()) { PyObject *p; double prec = Precision::Confusion(); if (!PyArg_ParseTuple(args, "O!|d", &(Part::GeometrySurfacePy::Type), &p, &prec)) return 0; Handle_Geom_Surface surf = Handle_Geom_Surface::DownCast(static_cast<GeometryPy*>(p)->getGeometryPtr()->handle()); GeomAPI_IntCS intersector(curve, surf); if (!intersector.IsDone()) { PyErr_SetString(PyExc_Exception, "Intersection of curve and surface failed"); return 0; } Py::List points; for (int i = 1; i <= intersector.NbPoints(); i++) { gp_Pnt p = intersector.Point(i); points.append(Py::Object(new PointPy(new GeomPoint(Base::Vector3d(p.X(), p.Y(), p.Z()))))); } Py::List segments; for (int i = 1; i <= intersector.NbSegments(); i++) { Handle_Geom_Curve seg = intersector.Segment(i); segments.append(makeGeometryCurvePy(seg)); } Py::Tuple tuple(2); tuple.setItem(0, points); tuple.setItem(1, segments); return Py::new_reference_to(tuple); } } 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; }
PyObject* BezierSurfacePy::getWeight(PyObject *args) { int uindex,vindex; if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); Standard_OutOfRange_Raise_if (uindex < 1 || uindex > surf->NbUPoles() || vindex < 1 || vindex > surf->NbVPoles(), "Weight index out of range"); double w = surf->Weight(uindex,vindex); return Py_BuildValue("d", w); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BezierSurfacePy::getPole(PyObject *args) { int uindex,vindex; if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex)) return 0; try { Handle_Geom_BezierSurface surf = Handle_Geom_BezierSurface::DownCast (getGeometryPtr()->handle()); Standard_OutOfRange_Raise_if (uindex < 1 || uindex > surf->NbUPoles() || vindex < 1 || vindex > surf->NbVPoles(), "Pole index out of range"); gp_Pnt p = surf->Pole(uindex,vindex); return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z())); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineCurve2dPy::insertKnot(PyObject * args) { double U, tol = 0.0; int M=1; if (!PyArg_ParseTuple(args, "d|idO!", &U, &M, &tol)) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); curve->InsertKnot(U,M,tol); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } Py_Return; }
static HeeksObj* Fuse(HeeksObj* s1, HeeksObj* s2){ try { TopoDS_Shape sh1, sh2; TopoDS_Shape new_shape; if(wxGetApp().useOldFuse)new_shape = BRepAlgo_Fuse(((CShape*)s1)->Shape(), ((CShape*)s2)->Shape()); else new_shape = BRepAlgoAPI_Fuse(((CShape*)s1)->Shape(), ((CShape*)s2)->Shape()); HeeksObj* new_object = CShape::MakeObject(new_shape, _("Result of Fuse Operation"), SOLID_TYPE_UNKNOWN, ((CShape*)s1)->m_color, ((CShape*)s1)->GetOpacity()); wxGetApp().Add(new_object, NULL); wxGetApp().Remove(s1); wxGetApp().Remove(s2); return new_object; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); wxMessageBox(wxString(_("Error with fuse operation")) + _T(": ") + Ctt(e->GetMessageString())); return NULL; } }