+ for importBrep() and exportBrep() allow file names or file objects

This commit is contained in:
wmayer 2016-06-11 12:38:58 +02:00
parent 432dcb5833
commit 9c7bc073e4

View File

@ -338,8 +338,7 @@ PyObject* TopoShapePy::exportStep(PyObject *args)
PyObject* TopoShapePy::exportBrep(PyObject *args) PyObject* TopoShapePy::exportBrep(PyObject *args)
{ {
char* Name; char* Name;
if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) if (PyArg_ParseTuple(args, "et","utf-8",&Name)) {
return NULL;
std::string EncodedName = std::string(Name); std::string EncodedName = std::string(Name);
PyMem_Free(Name); PyMem_Free(Name);
@ -355,6 +354,29 @@ PyObject* TopoShapePy::exportBrep(PyObject *args)
Py_Return; Py_Return;
} }
PyErr_Clear();
PyObject* input;
if (PyArg_ParseTuple(args, "O", &input)) {
try {
// read brep
Base::PyStreambuf buf(input);
std::ostream str(0);
str.rdbuf(&buf);
getTopoShapePtr()->exportBrep(str);
}
catch (const Base::Exception& e) {
PyErr_SetString(PartExceptionOCCError,e.what());
return NULL;
}
Py_Return;
}
PyErr_SetString(PyExc_TypeError, "expect string or file object");
return NULL;
}
PyObject* TopoShapePy::exportBinary(PyObject *args) PyObject* TopoShapePy::exportBinary(PyObject *args)
{ {
char* input; char* input;
@ -428,18 +450,31 @@ PyObject* TopoShapePy::exportBrepToString(PyObject *args)
PyObject* TopoShapePy::importBrep(PyObject *args) PyObject* TopoShapePy::importBrep(PyObject *args)
{ {
PyObject* input; char* Name;
if (!PyArg_ParseTuple(args, "O", &input)) if (PyArg_ParseTuple(args, "et","utf-8",&Name)) {
//char* input; std::string EncodedName = std::string(Name);
//if (!PyArg_ParseTuple(args, "s", &input)) PyMem_Free(Name);
return NULL;
try {
// write brep file
getTopoShapePtr()->importBrep(EncodedName.c_str());
}
catch (const Base::Exception& e) {
PyErr_SetString(PartExceptionOCCError,e.what());
return NULL;
}
Py_Return;
}
PyErr_Clear();
PyObject* input;
if (PyArg_ParseTuple(args, "O", &input)) {
try { try {
// read brep // read brep
Base::PyStreambuf buf(input); Base::PyStreambuf buf(input);
std::istream str(0); std::istream str(0);
str.rdbuf(&buf); str.rdbuf(&buf);
//std::stringstream str(input);
getTopoShapePtr()->importBrep(str); getTopoShapePtr()->importBrep(str);
} }
catch (const Base::Exception& e) { catch (const Base::Exception& e) {
@ -450,6 +485,10 @@ PyObject* TopoShapePy::importBrep(PyObject *args)
Py_Return; Py_Return;
} }
PyErr_SetString(PyExc_TypeError, "expect string or file object");
return NULL;
}
PyObject* TopoShapePy::importBinary(PyObject *args) PyObject* TopoShapePy::importBinary(PyObject *args)
{ {
char* input; char* input;