1st cut PyClip functionality

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

View File

@@ -32,6 +32,7 @@ generate_from_xml(DrawTemplatePy)
generate_from_xml(DrawParametricTemplatePy)
generate_from_xml(DrawSVGTemplatePy)
generate_from_xml(DrawViewSymbolPy)
generate_from_xml(DrawViewClipPy)
SET(Draw_SRCS
DrawPage.cpp
@@ -95,6 +96,8 @@ SET(Python_SRCS
DrawParametricTemplatePyImp.cpp
DrawSVGTemplatePy.xml
DrawSVGTemplatePyImp.cpp
DrawViewClipPy.xml
DrawViewClipPyImp.cpp
)
SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS})

View File

@@ -50,7 +50,7 @@ using namespace std;
PROPERTY_SOURCE(TechDraw::DrawViewClip, TechDraw::DrawView)
DrawViewClip::DrawViewClip(void)
DrawViewClip::DrawViewClip(void)
{
static const char *group = "Clip Group";
//App::PropertyType hidden = (App::PropertyType)(App::Prop_Hidden);
@@ -72,11 +72,11 @@ DrawViewClip::DrawViewClip(void)
//ScaleType.StatusBits.set(bitReadOnly, true);
//ScaleType.StatusBits.set(bitHidden, true);
//Scale.StatusBits.set(bitReadOnly, true);
//Scale.StatusBits.set(bitHidden,true);
//Scale.StatusBits.set(bitHidden,true);
ScaleType.setStatus(App::Property::ReadOnly,true);
ScaleType.setStatus(App::Property::Hidden,true);
Scale.setStatus(App::Property::ReadOnly,true);
Scale.setStatus(App::Property::Hidden,true);
Scale.setStatus(App::Property::Hidden,true);
}
DrawViewClip::~DrawViewClip()
@@ -164,7 +164,7 @@ namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewClipPython, TechDraw::DrawViewClip)
template<> const char* TechDraw::DrawViewClipPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderDrawClip";
return "TechDrawGui::ViewProviderViewClip";
}
/// @endcond

View File

@@ -64,7 +64,7 @@ public:
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderDrawClip";
return "TechDrawGui::ViewProviderViewClip";
}
std::vector<std::string> getChildViewNames();

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DrawViewPy"
Name="DrawViewClipPy"
Twin="DrawViewClip"
TwinPointer="DrawViewClip"
Include="Mod/TechDraw/App/DrawViewClip.h"
Namespace="TechDraw"
FatherInclude="Mod/TechDraw/App/DrawViewPy.h"
FatherNamespace="TechDraw">
<Documentation>
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating Technical Drawing Clip Views</UserDocu>
</Documentation>
<Methode Name="addView">
<Documentation>
<UserDocu>addView(DrawView) - Add a View to this ClipView</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeView">
<Documentation>
<UserDocu>removeView(DrawView) - Remove specified View to this ClipView</UserDocu>
</Documentation>
</Methode>
<Methode Name="getChildViewNames">
<Documentation>
<UserDocu>getChildViewNames() - get a list of the DrawViews in this ClipView</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

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;
}

View File

@@ -58,6 +58,8 @@ public:
App::PropertyBool CentreLines;
App::PropertyString FormatSpec;
//TODO: do we need a property for the actual dimension value? how else to access from Py?
short mustExecute() const;
bool hasReferences(void) const;

View File

@@ -64,6 +64,8 @@ public:
//int removeHatch(App::DocumentObject *docObj);
std::vector<TechDraw::DrawHatch*> getHatches(void) const;
//TODO: are there use-cases for Python access to TechDrawGeometry???
const std::vector<TechDrawGeometry::Vertex *> & getVertexGeometry() const;
const std::vector<TechDrawGeometry::BaseGeom *> & getEdgeGeometry() const;
const std::vector<TechDrawGeometry::Face *> & getFaceGeometry() const;

View File

@@ -11,7 +11,7 @@
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating Drawing Views</UserDocu>
<UserDocu>Feature for creating and manipulating Technical Drawing Views</UserDocu>
</Documentation>
<CustomAttributes />
</PythonExport>

View File

@@ -88,7 +88,7 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute(void)
{
std::string svg = Symbol.getValue();
const std::vector<std::string>& editText = EditableTexts.getValues();
if (!editText.empty()) {
boost::regex e1 ("<text.*?freecad:editable=\"(.*?)\".*?<tspan.*?>(.*?)</tspan>");
string::const_iterator begin, end;
@@ -115,7 +115,8 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute(void)
newsvg.insert(newsvg.end(), begin, end);
svg = newsvg;
}
//TODO: shouldn't there be a Symbol.setValue(svg) here??? -wf
#if 0
std::stringstream result;
result << "<g transform=\"translate(" << X.getValue() << "," << Y.getValue() << ")"
<< " rotate(" << Rotation.getValue() << ")"
@@ -126,6 +127,7 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute(void)
// Apply the resulting fragment
// no more ViewResult! Need to xlate SVG to Geometry object???
//ViewResult.setValue(result.str().c_str());
#endif
//return App::DocumentObject::StdReturn;
return DrawView::execute();