INT PAL 0052942: Error of geompy.MakeCurveParametric() is printed to a terminal instead of the Python Console

- Correct fix now
This commit is contained in:
vsr 2015-12-01 12:29:08 +03:00
parent 007a4cd246
commit 0138a9d57c
2 changed files with 100 additions and 102 deletions

View File

@ -78,46 +78,47 @@
* =========== PYTHON ============== * =========== PYTHON ==============
* ==================================*/ * ==================================*/
typedef struct { namespace
{
typedef struct {
PyObject_HEAD PyObject_HEAD
int softspace; int softspace;
std::string *out; std::string *out;
} PyStdOut; } PyStdOut;
static void static void
PyStdOut_dealloc(PyStdOut *self) PyStdOut_dealloc(PyStdOut *self)
{ {
PyObject_Del(self); PyObject_Del(self);
} }
static PyObject * static PyObject*
PyStdOut_write(PyStdOut *self, PyObject *args) PyStdOut_write(PyStdOut* self, PyObject* args)
{ {
char *c; char *c;
int l; int l;
if (!PyArg_ParseTuple(args, "t#:write",&c, &l)) if (!PyArg_ParseTuple(args, "t#:write", &c, &l))
return NULL; return NULL;
//std::cerr << c ; *(self->out) = *(self->out) + c;
*(self->out)=*(self->out)+c;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyMethodDef PyStdOut_methods[] = { static PyMethodDef PyStdOut_methods[] = {
{"write", (PyCFunction)PyStdOut_write, METH_VARARGS, {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
PyDoc_STR("write(string) -> None")}, PyDoc_STR("write(string) -> None")},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
static PyMemberDef PyStdOut_memberlist[] = { static PyMemberDef PyStdOut_memberlist[] = {
{(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0, {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
(char*)"flag indicating that a space needs to be printed; used by print"}, (char*)"flag indicating that a space needs to be printed; used by print"},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
static PyTypeObject PyStdOut_Type = { static PyTypeObject PyStdOut_Type = {
/* The ob_type field must be initialized in the module init function /* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */ * to be portable to Windows without using C++. */
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
@ -163,20 +164,19 @@ static PyTypeObject PyStdOut_Type = {
0, /*tp_new*/ 0, /*tp_new*/
0, /*tp_free*/ 0, /*tp_free*/
0, /*tp_is_gc*/ 0, /*tp_is_gc*/
}; };
PyObject * newPyStdOut( std::string& out ) PyObject* newPyStdOut( std::string& out )
{ {
PyStdOut *self; PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type);
self = PyObject_New(PyStdOut, &PyStdOut_Type); if (self) {
if (self == NULL)
return NULL;
self->softspace = 0; self->softspace = 0;
self->out=&out; self->out=&out;
}
return (PyObject*)self; return (PyObject*)self;
}
} }
////////////////////////END PYTHON/////////////////////////// ////////////////////////END PYTHON///////////////////////////
//============================================================================= //=============================================================================
/*! /*!
@ -996,7 +996,6 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
PyObject* main_dict = PyModule_GetDict(main_mod); PyObject* main_dict = PyModule_GetDict(main_mod);
PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL); PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
printf("%s\n", aPyScript.ToCString());
if (obj == NULL) { if (obj == NULL) {
SetErrorCode("Error during executing of python script !!!"); SetErrorCode("Error during executing of python script !!!");
@ -1022,15 +1021,14 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
else else
coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep ); coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
PyObject* new_stderr = NULL;
if (coords == NULL){ if (coords == NULL){
fflush(stderr); fflush(stderr);
std::string err_description=""; std::string err_description="";
new_stderr = newPyStdOut(err_description); PyObject* new_stderr = newPyStdOut(err_description);
PyObject* old_stderr = PySys_GetObject((char*)"stderr");
PySys_SetObject((char*)"stderr", new_stderr); PySys_SetObject((char*)"stderr", new_stderr);
PyErr_Print(); PyErr_Print();
PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__")); PySys_SetObject((char*)"stderr", old_stderr);
Py_DECREF(new_stderr); Py_DECREF(new_stderr);
MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description); MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
SetErrorCode("Can't evaluate the expressions, please check them !!!"); SetErrorCode("Can't evaluate the expressions, please check them !!!");

View File

@ -295,7 +295,7 @@ def ManageTransactions(theOpeName):
## Raise an Error, containing the Method_name, if Operation is Failed ## Raise an Error, containing the Method_name, if Operation is Failed
## @ingroup l1_geomBuilder_auxiliary ## @ingroup l1_geomBuilder_auxiliary
def RaiseIfFailed (Method_name, Operation): def RaiseIfFailed (Method_name, Operation):
if Operation.IsDone() == 0 and Operation.GetErrorCode() != "NOT_FOUND_ANY": if not Operation.IsDone() and Operation.GetErrorCode() != "NOT_FOUND_ANY":
raise RuntimeError, Method_name + " : " + Operation.GetErrorCode() raise RuntimeError, Method_name + " : " + Operation.GetErrorCode()
## Return list of variables value from salome notebook ## Return list of variables value from salome notebook
@ -2414,7 +2414,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
anObj = self.CurvesOp.MakeCurveParametricNew(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType) anObj = self.CurvesOp.MakeCurveParametricNew(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType)
else: else:
anObj = self.CurvesOp.MakeCurveParametric(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType) anObj = self.CurvesOp.MakeCurveParametric(thexExpr,theyExpr,thezExpr,theParamMin,theParamMax,theParamStep,theCurveType)
RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp) RaiseIfFailed("MakeCurveParametric", self.CurvesOp)
anObj.SetParameters(Parameters) anObj.SetParameters(Parameters)
self._autoPublish(anObj, theName, "curve") self._autoPublish(anObj, theName, "curve")
return anObj return anObj