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