TechDraw: Improve and clean up code in some Python classes
This commit is contained in:
@@ -43,49 +43,31 @@ std::string DrawViewClipPy::representation() const
|
||||
|
||||
PyObject* DrawViewClipPy::addView(PyObject* args)
|
||||
{
|
||||
//this implements iRC = pyClip.addView(pyView) -or-
|
||||
//doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
|
||||
PyObject *pcDocObj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &pcDocObj)) {
|
||||
Base::Console().Error("Error: DrawViewClipPy::addView - Bad Arg - not DocumentObject\n");
|
||||
if (!PyArg_ParseTuple(args, "O!", &(TechDraw::DrawViewPy::Type), &pcDocObj)) {
|
||||
return nullptr;
|
||||
//TODO: sb PyErr??
|
||||
//PyErr_SetString(PyExc_TypeError, "addView expects a DrawView");
|
||||
//return -1;
|
||||
}
|
||||
|
||||
DrawViewClip* clip = getDrawViewClipPtr(); //get DrawViewClip for pyClip
|
||||
//TODO: argument 1 arrives as "DocumentObjectPy", not "DrawViewPy"
|
||||
//how to validate that obj is DrawView before use??
|
||||
DrawViewPy* pyView = static_cast<TechDraw::DrawViewPy*>(pcDocObj);
|
||||
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
|
||||
|
||||
clip->addView(view);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DrawViewClipPy::removeView(PyObject* args)
|
||||
{
|
||||
//this implements iRC = pyClip.removeView(pyView) -or-
|
||||
//doCommand(Doc, "App.activeDocument().%s.removeView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
|
||||
PyObject *pcDocObj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &pcDocObj)) {
|
||||
Base::Console().Error("Error: DrawViewClipPy::removeView - Bad Arg - not DocumentObject\n");
|
||||
if (!PyArg_ParseTuple(args, "O!", &(TechDraw::DrawViewPy::Type), &pcDocObj)) {
|
||||
return nullptr;
|
||||
//TODO: sb PyErr??
|
||||
//PyErr_SetString(PyExc_TypeError, "removeView expects a DrawView");
|
||||
//return -1;
|
||||
}
|
||||
|
||||
DrawViewClip* clip = getDrawViewClipPtr(); //get DrawViewClip for pyClip
|
||||
//TODO: argument 1 arrives as "DocumentObjectPy", not "DrawViewPy"
|
||||
//how to validate that obj is DrawView before use??
|
||||
DrawViewPy* pyView = static_cast<TechDraw::DrawViewPy*>(pcDocObj);
|
||||
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
|
||||
|
||||
clip->removeView(view);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@@ -97,13 +79,10 @@ PyObject* DrawViewClipPy::getChildViewNames(PyObject* args)
|
||||
|
||||
DrawViewClip* clip = getDrawViewClipPtr();
|
||||
std::vector<std::string> strings = clip->getChildViewNames();
|
||||
int stringSize = strings.size();
|
||||
Py::List result;
|
||||
|
||||
Py::List result(stringSize);
|
||||
|
||||
std::vector<std::string>::iterator it = strings.begin();
|
||||
for( ; it != strings.end(); it++) {
|
||||
result.append(Py::String(*it));
|
||||
for (const auto& str: strings) {
|
||||
result.append(Py::String(str));
|
||||
}
|
||||
|
||||
return Py::new_reference_to(result);
|
||||
|
||||
Reference in New Issue
Block a user