1st cut PyClip functionality

This commit is contained in:
WandererFan
2016-01-22 14:01:05 -05:00
committed by wmayer
parent ccdb56c06e
commit 5bf42856fd
12 changed files with 169 additions and 28 deletions

View File

@@ -0,0 +1,100 @@
#include "PreCompiled.h"
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include "Mod/TechDraw/App/DrawViewClip.h"
#include "Mod/TechDraw/App/DrawView.h"
#include "DrawViewPy.h"
// inclusion of the generated files (generated out of DrawViewClipPy.xml)
#include "DrawViewClipPy.h"
#include "DrawViewClipPy.cpp"
using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
std::string DrawViewClipPy::representation(void) const
{
return std::string("<DrawViewClip object>");
}
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");
return NULL;
//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");
return NULL;
//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;
}
// std::vector<std::string> getChildViewNames();
PyObject* DrawViewClipPy::getChildViewNames(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
DrawViewClip* clip = getDrawViewClipPtr();
std::vector<std::string> strings = clip->getChildViewNames();
int stringSize = strings.size();
PyObject* result = PyList_New(stringSize);
std::vector<std::string>::iterator it = strings.begin();
for( ; it != strings.end(); it++) {
PyObject* pString = PyString_FromString(it->c_str()); //TODO: unicode & py3
int rc = PyList_Append(result, pString);
}
// PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
return result;
}
PyObject *DrawViewClipPy::getCustomAttributes(const char* attr) const
{
return 0;
}
int DrawViewClipPy::setCustomAttributes(const char* attr, PyObject *obj)
{
return 0;
}