Py::List PropertyContainerPy::getPropertiesList(void) const { Py::List ret; std::map<std::string,Property*> Map; getPropertyContainerPtr()->getPropertyMap(Map); for (std::map<std::string,Property*>::const_iterator It=Map.begin();It!=Map.end();++It) ret.append(Py::String(It->first)); return ret; }
PyObject* DocumentPy::supportedTypes(PyObject *args) { if (!PyArg_ParseTuple(args, "")) // convert args: Python->C return NULL; // NULL triggers exception std::vector<Base::Type> ary; Base::Type::getAllDerivedFrom(App::DocumentObject::getClassTypeId(), ary); Py::List res; for (std::vector<Base::Type>::iterator it = ary.begin(); it != ary.end(); ++it) res.append(Py::String(it->getName())); return Py::new_reference_to(res); }
void MatrixPy::setA(Py::List arg) { double mat[16]; this->getMatrixPtr()->getMatrix(mat); int index=0; for (Py::List::iterator it = arg.begin(); it != arg.end() && index < 16; ++it) { mat[index++] = (double)Py::Float(*it); } this->getMatrixPtr()->setMatrix(mat); }
void PathPy::setCommands(Py::List list) { getToolpathPtr()->clear(); for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { Path::Command &cmd = *static_cast<Path::CommandPy*>((*it).ptr())->getCommandPtr(); getToolpathPtr()->addCommand(cmd); } else { throw Py::Exception("The list can only contain Path Commands"); } } }
Py::List AttachEnginePy::getImplementedModes(void) const { try { Py::List ret; AttachEngine &attacher = *(this->getAttachEnginePtr()); for(int imode = 0 ; imode < mmDummy_NumberOfModes ; imode++){ if(attacher.modeRefTypes[imode].size() > 0){ ret.append(Py::String(attacher.getModeName(eMapMode(imode)))); } } return ret; } ATTACHERPY_STDCATCH_ATTR; }
PyObject* MeshPy::getPointSelection(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; Py::List ary; std::vector<unsigned long> points; getMeshObjectPtr()->getPointsFromSelection(points); for (std::vector<unsigned long>::const_iterator it = points.begin(); it != points.end(); ++it) { ary.append(Py::Int((int)*it)); } return Py::new_reference_to(ary); }
PyObject* Application::sGetVersion(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { if (!PyArg_ParseTuple(args, "")) // convert args: Python->C return NULL; // NULL triggers exception Py::List list; const std::map<std::string, std::string>& cfg = Application::Config(); std::map<std::string, std::string>::const_iterator it; it = cfg.find("BuildVersionMajor"); list.append(Py::String(it != cfg.end() ? it->second : "")); it = cfg.find("BuildVersionMinor"); list.append(Py::String(it != cfg.end() ? it->second : "")); it = cfg.find("BuildRevision"); list.append(Py::String(it != cfg.end() ? it->second : "")); it = cfg.find("BuildRepositoryURL"); list.append(Py::String(it != cfg.end() ? it->second : "")); it = cfg.find("BuildRevisionDate"); list.append(Py::String(it != cfg.end() ? it->second : "")); it = cfg.find("BuildRevisionBranch"); if (it != cfg.end()) list.append(Py::String(it->second)); it = cfg.find("BuildRevisionHash"); if (it != cfg.end()) list.append(Py::String(it->second)); return Py::new_reference_to(list); }
PyObject* MeshPy::getSeparateComponents(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; Py::List meshesList; std::vector<std::vector<unsigned long> > segs; segs = getMeshObjectPtr()->getComponents(); for (unsigned int i=0; i<segs.size(); i++) { MeshObject* mesh = getMeshObjectPtr()->meshFromSegment(segs[i]); meshesList.append(Py::Object(new MeshPy(mesh),true)); } return Py::new_reference_to(meshesList); }
Py::List DocumentObjectPy::getInListRecursive(void) const { Py::List ret; try { std::vector<DocumentObject*> list = getDocumentObjectPtr()->getInListRecursive(); for (std::vector<DocumentObject*>::iterator It = list.begin(); It != list.end(); ++It) ret.append(Py::Object((*It)->getPyObject(), true)); } catch (const Base::Exception& e) { throw Py::IndexError(e.what()); } return ret; }
Py::List BSplineSurfacePy::getVKnotSequence(void) const { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); Standard_Integer m = 0; for (int i=1; i<= surf->NbVKnots(); i++) m += surf->VMultiplicity(i); TColStd_Array1OfReal k(1,m); surf->VKnotSequence(k); Py::List list; for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) { list.append(Py::Float(k(i))); } return list; }
PyObject* BRepOffsetAPI_MakePipeShellPy::generated(PyObject *args) { PyObject *shape; if (!PyArg_ParseTuple(args, "O!",&Part::TopoShapePy::Type,&shape)) return 0; const TopoDS_Shape& s = static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->_Shape; const TopTools_ListOfShape& list = this->getBRepOffsetAPI_MakePipeShellPtr()->Generated(s); Py::List shapes; TopTools_ListIteratorOfListOfShape it; for (it.Initialize(list); it.More(); it.Next()) { const TopoDS_Shape& s = it.Value(); shapes.append(Py::asObject(new TopoShapePy(new TopoShape(s)))); } return Py::new_reference_to(shapes); }
Py::List toListOfStrings( Py::Object obj ) { Py::List list; if( obj.isList() ) list = obj; else list.append( obj ); // check all members of the list are strings for( Py::List::size_type i=0; i<list.length(); i++ ) { Py::String path_str( list[i] ); } return list; }
/*! * @brief Format a WSGI application response as an HTTP response. * @param status HTTP status line (without the HTTP version) * @param headers a list of pairs of strings with HTTP headers * @param body the response body */ void operator() ( const py::Bytes& status, const py::List& headers, const py::Bytes& body ) { // Send status line. myStream << "HTTP/1.1 " << status << "\r\n"; bool contentlength = false; // Send headers. for ( py::ssize_t i = 0; (i < headers.size()); ++i ) { const py::Tuple header(headers[i]); const py::Bytes field(header[0]); const py::Bytes value(header[1]); if ( field == "Content-Length" ) { contentlength = true; } myStream << field << ": " << value << "\r\n"; } // More headers (if desired). if ( !contentlength ) { myStream << "Content-Length" << ": " << body.size() << "\r\n"; } // Send body. myStream << "\r\n" << body; }
PyObject* DocumentPy::getObjectsByLabel(PyObject *args) { char *sName; if (!PyArg_ParseTuple(args, "s",&sName)) // convert args: Python->C return NULL; // NULL triggers exception Py::List list; std::string name = sName; std::vector<DocumentObject*> objs = getDocumentPtr()->getObjects(); for (std::vector<DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) { if (name == (*it)->Label.getValue()) list.append(Py::asObject((*it)->getPyObject())); } return Py::new_reference_to(list); }
PyObject* PropertyContainerPy::getEditorMode(PyObject *args) { char* name; if (!PyArg_ParseTuple(args, "s", &name)) // convert args: Python->C return NULL; // NULL triggers exception App::Property* prop = getPropertyContainerPtr()->getPropertyByName(name); Py::List ret; if (prop) { short Type = prop->getType(); if ((prop->testStatus(Property::ReadOnly)) || (Type & Prop_ReadOnly)) ret.append(Py::String("ReadOnly")); if ((prop->testStatus(Property::Hidden)) || (Type & Prop_Hidden)) ret.append(Py::String("Hidden")); } return Py::new_reference_to(ret); }
PyObject* FeaturePythonPy::supportedProperties(PyObject *args) { if (!PyArg_ParseTuple(args, "")) // convert args: Python->C return NULL; // NULL triggers exception std::vector<Base::Type> ary; Base::Type::getAllDerivedFrom(App::Property::getClassTypeId(), ary); Py::List res; for (std::vector<Base::Type>::iterator it = ary.begin(); it != ary.end(); ++it) { Base::BaseClass *data = static_cast<Base::BaseClass*>(it->createInstance()); if (data) { delete data; res.append(Py::String(it->getName())); } } return Py::new_reference_to(res); }
Py::List DocumentObjectPy::getState(void) const { DocumentObject* object = this->getDocumentObjectPtr(); Py::List list; bool uptodate = true; if (object->isTouched()) { uptodate = false; list.append(Py::String("Touched")); } if (object->isError()) { uptodate = false; list.append(Py::String("Invalid")); } if (object->isRecomputing()) { uptodate = false; list.append(Py::String("Recompute")); } if (object->isRestoring()) { uptodate = false; list.append(Py::String("Restore")); } if (object->testStatus(App::Expand)){ list.append(Py::String("Expanded")); } if (uptodate) { list.append(Py::String("Up-to-date")); } return list; }
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; }
PyObject* BSplineCurve2dPy::toBezier(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; Handle_Geom2d_BSplineCurve spline = Handle_Geom2d_BSplineCurve::DownCast (this->getGeom2dBSplineCurvePtr()->handle()); Geom2dConvert_BSplineCurveToBezierCurve crt(spline); Py::List list; Standard_Integer arcs = crt.NbArcs(); for (Standard_Integer i=1; i<=arcs; i++) { Handle_Geom2d_BezierCurve bezier = crt.Arc(i); list.append(Py::asObject(new BezierCurve2dPy(new Geom2dBezierCurve(bezier)))); } return Py::new_reference_to(list); }
PyObject *SelectionSingleton::sGetCompleteSelection(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/) { if (!PyArg_ParseTuple(args, "")) return NULL; std::vector<SelectionSingleton::SelObj> sel; sel = Selection().getCompleteSelection(); try { Py::List list; for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) { list.append(Py::asObject(it->pObject->getPyObject())); } return Py::new_reference_to(list); } catch (Py::Exception&) { return 0; } }
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* MeshPy::getSegment(PyObject *args) { unsigned long index; if (!PyArg_ParseTuple(args, "k", &index)) return 0; unsigned long count = getMeshObjectPtr()->countSegments(); if (index >= count) { PyErr_SetString(PyExc_IndexError, "index out of range"); return 0; } Py::List ary; const std::vector<unsigned long>& segm = getMeshObjectPtr()->getSegment(index).getIndices(); for (std::vector<unsigned long>::const_iterator it = segm.begin(); it != segm.end(); ++it) { ary.append(Py::Int((int)*it)); } return Py::new_reference_to(ary); }
PyObject* DocumentPy::mdiViewsOfType(PyObject *args) { char* sType; if (!PyArg_ParseTuple(args, "s", &sType)) // convert args: Python->C return NULL; // NULL triggers exception Base::Type type = Base::Type::fromName(sType); if (type == Base::Type::badType()) { PyErr_Format(Base::BaseExceptionFreeCADError, "'%s' is not a valid type", sType); return NULL; } PY_TRY { std::list<Gui::MDIView*> views = getDocumentPtr()->getMDIViewsOfType(type); Py::List list; for (std::list<Gui::MDIView*>::iterator it = views.begin(); it != views.end(); ++it) list.append(Py::asObject((*it)->getPyObject())); return Py::new_reference_to(list); } PY_CATCH; }
PyObject *SelectionSingleton::sGetSelectionEx(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/) { char *documentName=0; if (!PyArg_ParseTuple(args, "|s", &documentName)) // convert args: Python->C return NULL; // NULL triggers exception std::vector<SelectionObject> sel; sel = Selection().getSelectionEx(documentName); try { Py::List list; for (std::vector<SelectionObject>::iterator it = sel.begin(); it != sel.end(); ++it) { list.append(Py::asObject(it->getPyObject())); } return Py::new_reference_to(list); } catch (Py::Exception&) { return 0; } }
static PyObject * wireFromSegment(PyObject *self, PyObject *args) { PyObject *o, *m; if (!PyArg_ParseTuple(args, "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o)) return 0; Py::List list(o); Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr(); std::vector<unsigned long> segm; segm.reserve(list.size()); for (unsigned int i=0; i<list.size(); i++) { segm.push_back((int)Py::Int(list[i])); } std::list<std::vector<Base::Vector3f> > bounds; MeshCore::MeshAlgorithm algo(mesh->getKernel()); algo.GetFacetBorders(segm, bounds); Py::List wires; std::list<std::vector<Base::Vector3f> >::iterator bt; try { for (bt = bounds.begin(); bt != bounds.end(); ++bt) { BRepBuilderAPI_MakePolygon mkPoly; for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) { mkPoly.Add(gp_Pnt(it->x,it->y,it->z)); } if (mkPoly.IsDone()) { PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire())); wires.append(Py::Object(wire, true)); } } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString()); return 0; } return Py::new_reference_to(wires); }
PyObject* BezierCurve2dPy::getWeights(PyObject * args) { if (!PyArg_ParseTuple(args, "")) return 0; try { Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast (getGeometryPtr()->handle()); TColStd_Array1OfReal w(1,curve->NbPoles()); curve->Weights(w); Py::List weights; for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) { weights.append(Py::Float(w(i))); } return Py::new_reference_to(weights); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
PyObject* BSplineSurfacePy::getVKnots(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); TColStd_Array1OfReal w(1,surf->NbVKnots()); surf->VKnots(w); Py::List knots; for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) { knots.append(Py::Float(w(i))); } return Py::new_reference_to(knots); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* BSplineSurfacePy::getUMultiplicities(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; try { Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast (getGeometryPtr()->handle()); TColStd_Array1OfInteger m(1,surf->NbUKnots()); surf->UMultiplicities(m); Py::List mults; for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { mults.append(Py::Int(m(i))); } return Py::new_reference_to(mults); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } }
PyObject* BSplineCurve2dPy::getMultiplicities(PyObject * args) { if (!PyArg_ParseTuple(args, "")) return 0; try { Handle_Geom2d_BSplineCurve curve = Handle_Geom2d_BSplineCurve::DownCast (getGeometry2dPtr()->handle()); TColStd_Array1OfInteger m(1,curve->NbKnots()); curve->Multiplicities(m); Py::List mults; for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { mults.append(Py::Int(m(i))); } return Py::new_reference_to(mults); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } }
Py::Object projectEx(const Py::Tuple& args) { PyObject *pcObjShape; PyObject *pcObjDir=0; if (!PyArg_ParseTuple(args.ptr(), "O!|O!", &(TopoShapePy::Type), &pcObjShape, &(Base::VectorPy::Type), &pcObjDir)) throw Py::Exception(); TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape); Base::Vector3d Vector(0,0,1); if (pcObjDir) Vector = *static_cast<Base::VectorPy*>(pcObjDir)->getVectorPtr(); ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector); Py::List list; list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)) , true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V1)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VN)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VO)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VI)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)) , true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H1)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HN)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HO)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HI)), true)); return list; }