Py: fix memory leaks by incorrect use of PyList_Append
This commit is contained in:
@@ -793,21 +793,20 @@ private:
|
||||
Py::Object getFacets(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *shape;
|
||||
PyObject *list = PyList_New(0);
|
||||
Py::List list;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "O", &shape))
|
||||
throw Py::Exception();
|
||||
auto theShape = static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
|
||||
for(TopExp_Explorer ex(theShape, TopAbs_FACE); ex.More(); ex.Next())
|
||||
{
|
||||
for (TopExp_Explorer ex(theShape, TopAbs_FACE); ex.More(); ex.Next()) {
|
||||
TopoDS_Face currentFace = TopoDS::Face(ex.Current());
|
||||
TopLoc_Location loc;
|
||||
Handle(Poly_Triangulation) facets = BRep_Tool::Triangulation(currentFace, loc);
|
||||
const TopAbs_Orientation anOrientation = currentFace.Orientation();
|
||||
bool flip = (anOrientation == TopAbs_REVERSED);
|
||||
if(!facets.IsNull()){
|
||||
if (!facets.IsNull()) {
|
||||
const TColgp_Array1OfPnt& nodes = facets->Nodes();
|
||||
const Poly_Array1OfTriangle& triangles = facets->Triangles();
|
||||
for(int i = 1; i <= triangles.Length(); i++){
|
||||
for (int i = 1; i <= triangles.Length(); i++) {
|
||||
Standard_Integer n1,n2,n3;
|
||||
triangles(i).Get(n1, n2, n3);
|
||||
gp_Pnt p1 = nodes(n1);
|
||||
@@ -821,19 +820,17 @@ private:
|
||||
PyObject *t1 = PyTuple_Pack(3, PyFloat_FromDouble(p1.X()), PyFloat_FromDouble(p1.Y()), PyFloat_FromDouble(p1.Z()));
|
||||
PyObject *t2 = PyTuple_Pack(3, PyFloat_FromDouble(p2.X()), PyFloat_FromDouble(p2.Y()), PyFloat_FromDouble(p2.Z()));
|
||||
PyObject *t3 = PyTuple_Pack(3, PyFloat_FromDouble(p3.X()), PyFloat_FromDouble(p3.Y()), PyFloat_FromDouble(p3.Z()));
|
||||
PyObject *points;
|
||||
if(flip)
|
||||
{
|
||||
points = PyTuple_Pack(3, t2, t1, t3);
|
||||
} else {
|
||||
points = PyTuple_Pack(3, t1, t2, t3);
|
||||
if (flip) {
|
||||
list.append(Py::asObject(PyTuple_Pack(3, t2, t1, t3)));
|
||||
}
|
||||
else {
|
||||
list.append(Py::asObject(PyTuple_Pack(3, t1, t2, t3)));
|
||||
}
|
||||
PyList_Append(list, points);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Py::asObject(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
Py::Object makeCompound(const Py::Tuple& args)
|
||||
{
|
||||
|
||||
@@ -105,30 +105,31 @@ PyObject* FT2FC(const Py_UNICODE *PyUString,
|
||||
const size_t length,
|
||||
const char *FontSpec,
|
||||
const double stringheight, // fc coords
|
||||
const double tracking) { // fc coords
|
||||
FT_Library FTLib;
|
||||
FT_Face FTFont;
|
||||
FT_Error error;
|
||||
FT_Long FaceIndex = 0; // some fonts have multiple faces
|
||||
FT_Vector kern;
|
||||
FT_UInt FTLoadFlags = FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP;
|
||||
const double tracking) // fc coords
|
||||
{
|
||||
FT_Library FTLib;
|
||||
FT_Face FTFont;
|
||||
FT_Error error;
|
||||
FT_Long FaceIndex = 0; // some fonts have multiple faces
|
||||
FT_Vector kern;
|
||||
FT_UInt FTLoadFlags = FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP;
|
||||
|
||||
std::stringstream ErrorMsg;
|
||||
double PenPos = 0, scalefactor;
|
||||
UNICHAR prevchar = 0, currchar = 0;
|
||||
int cadv;
|
||||
size_t i;
|
||||
PyObject *WireList, *CharList;
|
||||
std::stringstream ErrorMsg;
|
||||
double PenPos = 0, scalefactor;
|
||||
UNICHAR prevchar = 0, currchar = 0;
|
||||
int cadv;
|
||||
size_t i;
|
||||
Py::List CharList;
|
||||
|
||||
error = FT_Init_FreeType(&FTLib);
|
||||
if(error) {
|
||||
ErrorMsg << "FT_Init_FreeType failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
error = FT_Init_FreeType(&FTLib);
|
||||
if (error) {
|
||||
ErrorMsg << "FT_Init_FreeType failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
|
||||
#ifdef FC_OS_WIN32
|
||||
Base::FileInfo fi(FontSpec);
|
||||
if (!fi.isReadable()) {
|
||||
if (!fi.isReadable()) {
|
||||
ErrorMsg << "Font file not found (Win): " << FontSpec;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
@@ -143,58 +144,61 @@ PyObject* FT2FC(const Py_UNICODE *PyUString,
|
||||
#endif
|
||||
|
||||
|
||||
error = FT_New_Face(FTLib,FontSpec,FaceIndex, &FTFont);
|
||||
if(error) {
|
||||
ErrorMsg << "FT_New_Face failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
error = FT_New_Face(FTLib,FontSpec,FaceIndex, &FTFont);
|
||||
if (error) {
|
||||
ErrorMsg << "FT_New_Face failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
|
||||
//TODO: check that FTFont is scalable? only relevant for hinting etc?
|
||||
|
||||
// FT2 blows up if char size is not set to some non-zero value.
|
||||
// This sets size to 48 point. Magic.
|
||||
error = FT_Set_Char_Size(FTFont,
|
||||
0, /* char_width in 1/64th of points */
|
||||
48*64, /* char_height in 1/64th of points */
|
||||
0, /* horizontal device resolution */
|
||||
0 ); /* vertical device resolution */
|
||||
if(error) {
|
||||
ErrorMsg << "FT_Set_Char_Size failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
error = FT_Set_Char_Size(FTFont,
|
||||
0, /* char_width in 1/64th of points */
|
||||
48*64, /* char_height in 1/64th of points */
|
||||
0, /* horizontal device resolution */
|
||||
0 ); /* vertical device resolution */
|
||||
if (error) {
|
||||
ErrorMsg << "FT_Set_Char_Size failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
|
||||
CharList = PyList_New(0);
|
||||
scalefactor = stringheight/float(FTFont->height);
|
||||
for (i=0; i<length; i++) {
|
||||
currchar = PyUString[i];
|
||||
error = FT_Load_Char(FTFont,
|
||||
currchar,
|
||||
FTLoadFlags);
|
||||
if(error) {
|
||||
ErrorMsg << "FT_Load_Char failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
scalefactor = stringheight/float(FTFont->height);
|
||||
for (i=0; i<length; i++) {
|
||||
currchar = PyUString[i];
|
||||
error = FT_Load_Char(FTFont,
|
||||
currchar,
|
||||
FTLoadFlags);
|
||||
if (error) {
|
||||
ErrorMsg << "FT_Load_Char failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
|
||||
cadv = FTFont->glyph->advance.x;
|
||||
kern = getKerning(FTFont,prevchar,currchar);
|
||||
PenPos += kern.x;
|
||||
WireList = getGlyphContours(FTFont,currchar,PenPos, scalefactor,i,tracking);
|
||||
if (!PyList_Size(WireList)) // empty ==> whitespace
|
||||
Base::Console().Log("FT2FC char '0x%04x'/'%d' has no Wires!\n", currchar, currchar);
|
||||
else
|
||||
PyList_Append(CharList, WireList);
|
||||
PenPos += cadv;
|
||||
prevchar = currchar;
|
||||
}
|
||||
cadv = FTFont->glyph->advance.x;
|
||||
kern = getKerning(FTFont,prevchar,currchar);
|
||||
PenPos += kern.x;
|
||||
try {
|
||||
Py::List WireList(getGlyphContours(FTFont, currchar, PenPos, scalefactor, i, tracking), true);
|
||||
CharList.append(WireList);
|
||||
}
|
||||
catch (Py::Exception& e) {
|
||||
e.clear();
|
||||
Base::Console().Log("FT2FC char '0x%04x'/'%d' has no Wires!\n", currchar, currchar);
|
||||
}
|
||||
|
||||
error = FT_Done_FreeType(FTLib);
|
||||
if(error) {
|
||||
ErrorMsg << "FT_Done_FreeType failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
PenPos += cadv;
|
||||
prevchar = currchar;
|
||||
}
|
||||
|
||||
return(CharList);
|
||||
}
|
||||
error = FT_Done_FreeType(FTLib);
|
||||
if (error) {
|
||||
ErrorMsg << "FT_Done_FreeType failed: " << error;
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
|
||||
return Py::new_reference_to(CharList);
|
||||
}
|
||||
|
||||
//********** FT Decompose callbacks and data defns
|
||||
// FT Decomp Context for 1 char
|
||||
@@ -342,7 +346,7 @@ PyObject* getGlyphContours(FT_Face FTFont, UNICHAR currchar, double PenPos, doub
|
||||
isTTF = true;
|
||||
}
|
||||
|
||||
PyObject* ret = PyList_New(0);
|
||||
Py::List list;
|
||||
|
||||
gp_Vec pointer = gp_Vec(PenPos * Scale + charNum*tracking,0.0,0.0);
|
||||
gp_Trsf xForm;
|
||||
@@ -372,9 +376,11 @@ PyObject* getGlyphContours(FT_Face FTFont, UNICHAR currchar, double PenPos, doub
|
||||
ErrorMsg << "FT2FC OCC BRepScale failed \n";
|
||||
throw std::runtime_error(ErrorMsg.str());
|
||||
}
|
||||
PyList_Append(ret,new TopoShapeWirePy(new TopoShape(TopoDS::Wire(BRepScale.Shape()))));
|
||||
|
||||
PyObject* wire = new TopoShapeWirePy(new TopoShape(TopoDS::Wire(BRepScale.Shape())));
|
||||
list.append(Py::asObject(wire));
|
||||
}
|
||||
return(ret);
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
|
||||
// get kerning values for this char pair
|
||||
|
||||
@@ -2524,16 +2524,16 @@ PyObject* TopoShapePy::proximity(PyObject *args)
|
||||
PyObject* ps2;
|
||||
Standard_Real tol = Precision::Confusion();
|
||||
if (!PyArg_ParseTuple(args, "O!|d",&(TopoShapePy::Type), &ps2, &tol))
|
||||
return 0;
|
||||
return nullptr;
|
||||
const TopoDS_Shape& s1 = getTopoShapePtr()->getShape();
|
||||
const TopoDS_Shape& s2 = static_cast<Part::TopoShapePy*>(ps2)->getTopoShapePtr()->getShape();
|
||||
if (s1.IsNull()) {
|
||||
PyErr_SetString(PyExc_ValueError, "proximity: Shape object is invalid");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
if (s2.IsNull()) {
|
||||
PyErr_SetString(PyExc_ValueError, "proximity: Shape parameter is invalid");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BRepExtrema_ShapeProximity proximity;
|
||||
@@ -2551,7 +2551,7 @@ PyObject* TopoShapePy::proximity(PyObject *args)
|
||||
BRep_Tool::Triangulation(TopoDS::Face(xp.Current()), aLoc);
|
||||
if (aTriangulation.IsNull()) {
|
||||
PyErr_SetString(PartExceptionOCCError, "BRepExtrema_ShapeProximity not done, call 'tessellate' beforehand");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2561,7 +2561,7 @@ PyObject* TopoShapePy::proximity(PyObject *args)
|
||||
BRep_Tool::Triangulation(TopoDS::Face(xp.Current()), aLoc);
|
||||
if (aTriangulation.IsNull()) {
|
||||
PyErr_SetString(PartExceptionOCCError, "BRepExtrema_ShapeProximity not done, call 'tessellate' beforehand");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2572,7 +2572,7 @@ PyObject* TopoShapePy::proximity(PyObject *args)
|
||||
BRep_Tool::Polygon3D(TopoDS::Edge(xp.Current()), aLoc);
|
||||
if (aPoly3D.IsNull()) {
|
||||
PyErr_SetString(PartExceptionOCCError, "BRepExtrema_ShapeProximity not done, call 'tessellate' beforehand");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2582,37 +2582,29 @@ PyObject* TopoShapePy::proximity(PyObject *args)
|
||||
BRep_Tool::Polygon3D(TopoDS::Edge(xp.Current()), aLoc);
|
||||
if (aPoly3D.IsNull()) {
|
||||
PyErr_SetString(PartExceptionOCCError, "BRepExtrema_ShapeProximity not done, call 'tessellate' beforehand");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// another problem must have occurred
|
||||
PyErr_SetString(PartExceptionOCCError, "BRepExtrema_ShapeProximity not done");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
//PyObject* overlappss1 = PyList_New(0);
|
||||
//PyObject* overlappss2 = PyList_New(0);
|
||||
PyObject* overlappssindex1 = PyList_New(0);
|
||||
PyObject* overlappssindex2 = PyList_New(0);
|
||||
|
||||
Py::List overlappssindex1;
|
||||
Py::List overlappssindex2;
|
||||
|
||||
for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (proximity.OverlapSubShapes1()); anIt1.More(); anIt1.Next()) {
|
||||
//PyList_Append(overlappss1, new TopoShapeFacePy(new TopoShape(proximity.GetSubShape1 (anIt1.Key()))));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyList_Append(overlappssindex1,PyLong_FromLong(anIt1.Key()+1));
|
||||
#else
|
||||
PyList_Append(overlappssindex1,PyInt_FromLong(anIt1.Key()+1));
|
||||
#endif
|
||||
overlappssindex1.append(Py::Long(anIt1.Key() + 1));
|
||||
}
|
||||
for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (proximity.OverlapSubShapes2()); anIt2.More(); anIt2.Next()) {
|
||||
//PyList_Append(overlappss2, new TopoShapeFacePy(new TopoShape(proximity.GetSubShape2 (anIt2.Key()))));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyList_Append(overlappssindex2,PyLong_FromLong(anIt2.Key()+1));
|
||||
#else
|
||||
PyList_Append(overlappssindex2,PyInt_FromLong(anIt2.Key()+1));
|
||||
#endif
|
||||
overlappssindex2.append(Py::Long(anIt2.Key() + 1));
|
||||
}
|
||||
//return Py_BuildValue("OO", overlappss1, overlappss2); //subshapes
|
||||
return Py_BuildValue("OO", overlappssindex1, overlappssindex2); //face indexes
|
||||
|
||||
Py::Tuple tuple(2);
|
||||
tuple.setItem(0, overlappssindex1);
|
||||
tuple.setItem(1, overlappssindex2);
|
||||
return Py::new_reference_to(tuple); //face indexes
|
||||
#else
|
||||
(void)args;
|
||||
PyErr_SetString(PyExc_NotImplementedError, "proximity requires OCCT >= 6.8.1");
|
||||
|
||||
@@ -389,8 +389,9 @@ private:
|
||||
throw Py::Exception();
|
||||
|
||||
std::list<TopoDS_Shape> shapes;
|
||||
if (PyObject_TypeCheck(pShapes, &(Part::TopoShapePy::Type)))
|
||||
if (PyObject_TypeCheck(pShapes, &(Part::TopoShapePy::Type))) {
|
||||
shapes.push_back(static_cast<Part::TopoShapePy*>(pShapes)->getTopoShapePtr()->getShape());
|
||||
}
|
||||
else if (PyObject_TypeCheck(pShapes, &(PyList_Type)) ||
|
||||
PyObject_TypeCheck(pShapes, &(PyTuple_Type))) {
|
||||
Py::Sequence shapeSeq(pShapes);
|
||||
@@ -414,21 +415,18 @@ private:
|
||||
bool need_arc_plane = arc_plane==Area::ArcPlaneAuto;
|
||||
std::list<TopoDS_Shape> wires = Area::sortWires(shapes,start!=0,&pstart,
|
||||
&pend, 0, &arc_plane, PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SORT));
|
||||
PyObject *list = PyList_New(0);
|
||||
for(auto &wire : wires)
|
||||
PyList_Append(list,Py::new_reference_to(
|
||||
Part::shape2pyshape(TopoDS::Wire(wire))));
|
||||
PyObject *ret = PyTuple_New(need_arc_plane?3:2);
|
||||
PyTuple_SetItem(ret,0,list);
|
||||
PyTuple_SetItem(ret,1,new Base::VectorPy(
|
||||
Base::Vector3d(pend.X(),pend.Y(),pend.Z())));
|
||||
if(need_arc_plane)
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyTuple_SetItem(ret,2,PyInt_FromLong(arc_plane));
|
||||
#else
|
||||
PyTuple_SetItem(ret,2,PyLong_FromLong(arc_plane));
|
||||
#endif
|
||||
return Py::asObject(ret);
|
||||
Py::List list;
|
||||
for(auto &wire : wires) {
|
||||
list.append(Part::shape2pyshape(TopoDS::Wire(wire)));
|
||||
}
|
||||
|
||||
Py::Tuple ret(need_arc_plane ? 3 : 2);
|
||||
ret.setItem(0, list);
|
||||
ret.setItem(1, Py::asObject(new Base::VectorPy(Base::Vector3d(pend.X(),pend.Y(),pend.Z()))));
|
||||
if (need_arc_plane)
|
||||
ret.setItem(2, Py::Long(arc_plane));
|
||||
|
||||
return ret;
|
||||
} PATH_CATCH
|
||||
}
|
||||
};
|
||||
|
||||
@@ -277,12 +277,12 @@ PyObject* ToolPy::getToolTypes(PyObject * args)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
std::vector<std::string> toolTypes = Tool::ToolTypes();
|
||||
PyObject *list = PyList_New(0);
|
||||
Py::List list;
|
||||
for(unsigned i = 0; i != toolTypes.size(); i++) {
|
||||
|
||||
PyList_Append(list, PYSTRING_FROMSTRING(toolTypes[i].c_str()));
|
||||
list.append(Py::asObject(PYSTRING_FROMSTRING(toolTypes[i].c_str())));
|
||||
}
|
||||
return list;
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
throw Py::TypeError("This method accepts no argument");
|
||||
}
|
||||
@@ -291,12 +291,12 @@ PyObject* ToolPy::getToolMaterials(PyObject * args)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
std::vector<std::string> toolMaterials = Tool::ToolMaterials();
|
||||
PyObject *list = PyList_New(0);
|
||||
Py::List list;;
|
||||
for(unsigned i = 0; i != toolMaterials.size(); i++) {
|
||||
|
||||
PyList_Append(list, PYSTRING_FROMSTRING(toolMaterials[i].c_str()));
|
||||
list.append(Py::asObject(PYSTRING_FROMSTRING(toolMaterials[i].c_str())));
|
||||
}
|
||||
return list;
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
throw Py::TypeError("This method accepts no argument");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,8 @@ private:
|
||||
} else {
|
||||
biggie = false;
|
||||
}
|
||||
PyObject* result = PyList_New(0);
|
||||
|
||||
Py::List result;
|
||||
|
||||
try {
|
||||
EdgeWalker ew;
|
||||
@@ -207,16 +208,18 @@ private:
|
||||
std::vector<TopoDS_Wire> rw = ew.getResultNoDups();
|
||||
std::vector<TopoDS_Wire> sortedWires = ew.sortStrip(rw,biggie); //false==>do not include biggest wires
|
||||
for (auto& w:sortedWires) {
|
||||
PyList_Append(result,new TopoShapeWirePy(new TopoShape(w)));
|
||||
PyObject* wire = new TopoShapeWirePy(new TopoShape(w));
|
||||
result.append(Py::asObject(wire));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Base::Console().Warning("edgeWalker: input is not planar graph. Wire detection not done\n");
|
||||
}
|
||||
}
|
||||
catch (Base::Exception &e) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError, e.what());
|
||||
}
|
||||
return Py::asObject(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Py::Object findOuterWire(const Py::Tuple& args)
|
||||
|
||||
@@ -300,13 +300,13 @@ Py::Object CenterLinePy::getEdges(void) const
|
||||
std::vector<std::string> edges = cl->m_edges;
|
||||
int size = edges.size();
|
||||
|
||||
PyObject* result = PyList_New(size);
|
||||
Py::List result(size);
|
||||
|
||||
for (auto& e: edges) {
|
||||
PyList_Append(result, PyUnicode_FromString(e.c_str()));
|
||||
result.append(Py::asObject(PyUnicode_FromString(e.c_str())));
|
||||
}
|
||||
|
||||
return Py::asObject(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CenterLinePy::setEdges(Py::Object arg)
|
||||
@@ -346,13 +346,13 @@ Py::Object CenterLinePy::getFaces(void) const
|
||||
std::vector<std::string> faces = cl->m_faces;
|
||||
int size = faces.size();
|
||||
|
||||
PyObject* result = PyList_New(size);
|
||||
Py::List result(size);
|
||||
|
||||
for (auto& f: faces) {
|
||||
PyList_Append(result, PyUnicode_FromString(f.c_str()));
|
||||
result.append(Py::asObject(PyUnicode_FromString(f.c_str())));
|
||||
}
|
||||
|
||||
return Py::asObject(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CenterLinePy::setFaces(Py::Object arg)
|
||||
@@ -393,13 +393,13 @@ Py::Object CenterLinePy::getPoints(void) const
|
||||
std::vector<std::string> points = cl->m_verts;
|
||||
int size = points.size();
|
||||
|
||||
PyObject* result = PyList_New(size);
|
||||
Py::List result(size);
|
||||
|
||||
for (auto& p: points) {
|
||||
PyList_Append(result, PyUnicode_FromString(p.c_str()));
|
||||
result.append(Py::asObject(PyUnicode_FromString(p.c_str())));
|
||||
}
|
||||
|
||||
return Py::asObject(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CenterLinePy::setPoints(Py::Object arg)
|
||||
|
||||
@@ -82,23 +82,23 @@ PyObject* DrawPagePy::getAllViews(PyObject* args)
|
||||
DrawPage* page = getDrawPagePtr();
|
||||
std::vector<App::DocumentObject*> allViews = page->getAllViews();
|
||||
|
||||
PyObject* ret = PyList_New(0);
|
||||
Py::List ret;
|
||||
for (auto&v: allViews) {
|
||||
if (v->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
|
||||
TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(v);
|
||||
PyList_Append(ret,new TechDraw::DrawProjGroupItemPy(dpgi)); //is this legit? or need to make new copy of dv?
|
||||
ret.append(Py::asObject(new TechDraw::DrawProjGroupItemPy(dpgi))); //is this legit? or need to make new copy of dv?
|
||||
} else if (v->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
|
||||
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(v);
|
||||
PyList_Append(ret,new TechDraw::DrawViewPartPy(dvp));
|
||||
ret.append(Py::asObject(new TechDraw::DrawViewPartPy(dvp)));
|
||||
} else if (v->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) {
|
||||
TechDraw::DrawViewAnnotation* dva = static_cast<TechDraw::DrawViewAnnotation*>(v);
|
||||
PyList_Append(ret,new TechDraw::DrawViewAnnotationPy(dva));
|
||||
ret.append(Py::asObject(new TechDraw::DrawViewAnnotationPy(dva)));
|
||||
} else {
|
||||
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
|
||||
PyList_Append(ret,new TechDraw::DrawViewPy(dv));
|
||||
ret.append(Py::asObject(new TechDraw::DrawViewPy(dv)));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
|
||||
// double getPageWidth() const;
|
||||
|
||||
@@ -93,27 +93,20 @@ PyObject* DrawViewClipPy::removeView(PyObject* args)
|
||||
PyObject* DrawViewClipPy::getChildViewNames(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
DrawViewClip* clip = getDrawViewClipPtr();
|
||||
std::vector<std::string> strings = clip->getChildViewNames();
|
||||
int stringSize = strings.size();
|
||||
|
||||
PyObject* result = PyList_New(stringSize);
|
||||
Py::List result(stringSize);
|
||||
|
||||
std::vector<std::string>::iterator it = strings.begin();
|
||||
for( ; it != strings.end(); it++) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject* pString = PyString_FromString(it->c_str()); //TODO: unicode & py3
|
||||
#else
|
||||
PyObject* pString = PyUnicode_FromString(it->c_str());
|
||||
#endif
|
||||
//int rc =
|
||||
static_cast<void> (PyList_Append(result, pString));
|
||||
result.append(Py::String(*it));
|
||||
}
|
||||
|
||||
// PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
|
||||
return result;
|
||||
return Py::new_reference_to(result);
|
||||
}
|
||||
|
||||
PyObject *DrawViewClipPy::getCustomAttributes(const char* ) const
|
||||
|
||||
@@ -76,10 +76,10 @@ PyObject* DrawViewDimensionPy::getLinearPoints(PyObject* args)
|
||||
(void) args;
|
||||
DrawViewDimension* dvd = getDrawViewDimensionPtr();
|
||||
pointPair pts = dvd->getLinearPoints();
|
||||
PyObject* ret = PyList_New(0);
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.first)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.second)));
|
||||
return ret;
|
||||
Py::List ret;
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.first))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.second))));
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
|
||||
PyObject* DrawViewDimensionPy::getArcPoints(PyObject* args)
|
||||
@@ -87,14 +87,14 @@ PyObject* DrawViewDimensionPy::getArcPoints(PyObject* args)
|
||||
(void) args;
|
||||
DrawViewDimension* dvd = getDrawViewDimensionPtr();
|
||||
arcPoints pts = dvd->getArcPoints();
|
||||
PyObject* ret = PyList_New(0);
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.center)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.onCurve.first)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.onCurve.second)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.arcEnds.first)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.arcEnds.second)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.midArc)));
|
||||
return ret;
|
||||
Py::List ret;
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.center))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.onCurve.first))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.onCurve.second))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.arcEnds.first))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.arcEnds.second))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.midArc))));
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
|
||||
PyObject* DrawViewDimensionPy::getAnglePoints(PyObject* args)
|
||||
@@ -102,11 +102,11 @@ PyObject* DrawViewDimensionPy::getAnglePoints(PyObject* args)
|
||||
(void) args;
|
||||
DrawViewDimension* dvd = getDrawViewDimensionPtr();
|
||||
anglePoints pts = dvd->getAnglePoints();
|
||||
PyObject* ret = PyList_New(0);
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.ends.first)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.ends.second)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.vertex)));
|
||||
return ret;
|
||||
Py::List ret;
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.ends.first))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.ends.second))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.vertex))));
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
|
||||
PyObject* DrawViewDimensionPy::getArrowPositions(PyObject* args)
|
||||
@@ -114,10 +114,10 @@ PyObject* DrawViewDimensionPy::getArrowPositions(PyObject* args)
|
||||
(void) args;
|
||||
DrawViewDimension* dvd = getDrawViewDimensionPtr();
|
||||
pointPair pts = dvd->getArrowPositions();
|
||||
PyObject* ret = PyList_New(0);
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.first)));
|
||||
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.second)));
|
||||
return ret;
|
||||
Py::List ret;
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.first))));
|
||||
ret.append(Py::asObject(new Base::VectorPy(new Base::Vector3d(pts.second))));
|
||||
return Py::new_reference_to(ret);
|
||||
}
|
||||
PyObject *DrawViewDimensionPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
|
||||
@@ -77,32 +77,32 @@ PyObject* DrawViewPartPy::getVisibleEdges(PyObject *args)
|
||||
{
|
||||
(void) args;
|
||||
DrawViewPart* dvp = getDrawViewPartPtr();
|
||||
PyObject* pEdgeList = PyList_New(0);
|
||||
Py::List pEdgeList;
|
||||
std::vector<TechDraw::BaseGeom*> geoms = dvp->getEdgeGeometry();
|
||||
for (auto& g: geoms) {
|
||||
if (g->hlrVisible) {
|
||||
PyObject* pEdge = new Part::TopoShapeEdgePy(new Part::TopoShape(g->occEdge));
|
||||
PyList_Append(pEdgeList, pEdge);
|
||||
pEdgeList.append(Py::asObject(pEdge));
|
||||
}
|
||||
}
|
||||
|
||||
return pEdgeList;
|
||||
return Py::new_reference_to(pEdgeList);
|
||||
}
|
||||
|
||||
PyObject* DrawViewPartPy::getHiddenEdges(PyObject *args)
|
||||
{
|
||||
(void) args;
|
||||
DrawViewPart* dvp = getDrawViewPartPtr();
|
||||
PyObject* pEdgeList = PyList_New(0);
|
||||
Py::List pEdgeList;
|
||||
std::vector<TechDraw::BaseGeom*> geoms = dvp->getEdgeGeometry();
|
||||
for (auto& g: geoms) {
|
||||
if (!g->hlrVisible) {
|
||||
PyObject* pEdge = new Part::TopoShapeEdgePy(new Part::TopoShape(g->occEdge));
|
||||
PyList_Append(pEdgeList, pEdge);
|
||||
pEdgeList.append(Py::asObject(pEdge));
|
||||
}
|
||||
}
|
||||
|
||||
return pEdgeList;
|
||||
return Py::new_reference_to(pEdgeList);
|
||||
}
|
||||
|
||||
PyObject* DrawViewPartPy::requestPaint(PyObject *args)
|
||||
|
||||
Reference in New Issue
Block a user