From 1913f6c582b989d5dab890d7362a01c0c726484e Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 25 Jan 2017 00:23:21 +0800 Subject: [PATCH] Path: added support to get Path.Area from Path::FeatureArea --- src/Mod/Path/App/Area.cpp | 21 ++++++ src/Mod/Path/App/Area.h | 1 + src/Mod/Path/App/CMakeLists.txt | 3 + src/Mod/Path/App/FeatureArea.cpp | 21 ++++-- src/Mod/Path/App/FeatureArea.h | 3 + src/Mod/Path/App/FeatureAreaPy.xml | 30 +++++++++ src/Mod/Path/App/FeatureAreaPyImp.cpp | 93 +++++++++++++++++++++++++++ 7 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 src/Mod/Path/App/FeatureAreaPy.xml create mode 100644 src/Mod/Path/App/FeatureAreaPyImp.cpp diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index d7343a44bac8..58516bab9865 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -110,6 +110,27 @@ Area::Area(const AreaParams *params) setParams(*params); } +Area::Area(const Area &other, bool deep_copy) +:Base::BaseClass(other) +,myShapes(other.myShapes) +,myTrsf(other.myTrsf) +,myParams(other.myParams) +,myWorkPlane(other.myWorkPlane) +,myHaveFace(other.myHaveFace) +,myHaveSolid(other.myHaveSolid) +,myShapeDone(false) +{ + if(!deep_copy) return; + if(other.myArea) + myArea.reset(new CArea(*other.myArea)); + myShapePlane = other.myShapePlane; + myShape = other.myShape; + myShapeDone = other.myShapeDone; + mySections.reserve(other.mySections.size()); + for(shared_ptr area:mySections) + mySections.push_back(make_shared(*area,true)); +} + Area::~Area() { clean(); } diff --git a/src/Mod/Path/App/Area.h b/src/Mod/Path/App/Area.h index b261ddb4711f..ca2866149db6 100644 --- a/src/Mod/Path/App/Area.h +++ b/src/Mod/Path/App/Area.h @@ -146,6 +146,7 @@ class PathExport Area: public Base::BaseClass { PARAM_ENUM_DECLARE(AREA_PARAMS_ALL) Area(const AreaParams *params = NULL); + Area(const Area &other, bool deep_copy=true); virtual ~Area(); /** Set a working plane diff --git a/src/Mod/Path/App/CMakeLists.txt b/src/Mod/Path/App/CMakeLists.txt index 14531ff4d80c..0816c7d07736 100644 --- a/src/Mod/Path/App/CMakeLists.txt +++ b/src/Mod/Path/App/CMakeLists.txt @@ -32,6 +32,7 @@ generate_from_xml(ToolPy) generate_from_xml(TooltablePy) generate_from_xml(FeaturePathCompoundPy) generate_from_xml(AreaPy) +generate_from_xml(FeatureAreaPy) SET(Python_SRCS CommandPy.xml @@ -45,6 +46,8 @@ SET(Python_SRCS FeaturePathCompoundPyImp.cpp AreaPy.xml AreaPyImp.cpp + FeatureAreaPy.xml + FeatureAreaPyImp.cpp ) SET(Mod_SRCS diff --git a/src/Mod/Path/App/FeatureArea.cpp b/src/Mod/Path/App/FeatureArea.cpp index b02d23441ec8..a8193f5ef456 100644 --- a/src/Mod/Path/App/FeatureArea.cpp +++ b/src/Mod/Path/App/FeatureArea.cpp @@ -29,6 +29,7 @@ #include #include "FeatureArea.h" +#include "FeatureAreaPy.h" #include #include #include @@ -81,18 +82,18 @@ App::DocumentObjectExecReturn *FeatureArea::execute(void) params.PARAM_FNAME(_param) = PARAM_FNAME(_param).getValue(); PARAM_FOREACH(AREA_PROP_GET,AREA_PARAMS_CONF) - Area area(¶ms); + myArea.clean(true); + myArea.setParams(params); TopoDS_Shape workPlane = WorkPlane.getShape().getShape(); - if(!workPlane.IsNull()) - area.setPlane(workPlane); + myArea.setPlane(workPlane); for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { - area.add(static_cast(*it)->Shape.getShape().getShape(), + myArea.add(static_cast(*it)->Shape.getShape().getShape(), PARAM_PROP_ARGS(AREA_PARAMS_OPCODE)); } - this->Shape.setValue(area.getShape(-1)); + this->Shape.setValue(myArea.getShape(-1)); return Part::Feature::execute(); } @@ -108,6 +109,16 @@ short FeatureArea::mustExecute(void) const return Part::Feature::mustExecute(); } +PyObject *FeatureArea::getPyObject() +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new FeatureAreaPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + + // Python Area feature --------------------------------------------------------- namespace App { diff --git a/src/Mod/Path/App/FeatureArea.h b/src/Mod/Path/App/FeatureArea.h index d5e10c2def5e..5a084f3b18df 100644 --- a/src/Mod/Path/App/FeatureArea.h +++ b/src/Mod/Path/App/FeatureArea.h @@ -40,6 +40,8 @@ class PathExport FeatureArea : public Part::Feature PROPERTY_HEADER(Path::FeatureArea); public: + Area myArea; + /// Constructor FeatureArea(void); virtual ~FeatureArea(); @@ -50,6 +52,7 @@ class PathExport FeatureArea : public Part::Feature } virtual App::DocumentObjectExecReturn *execute(void); virtual short mustExecute(void) const; + virtual PyObject *getPyObject(void); App::PropertyLinkList Sources; Part::PropertyPartShape WorkPlane; diff --git a/src/Mod/Path/App/FeatureAreaPy.xml b/src/Mod/Path/App/FeatureAreaPy.xml new file mode 100644 index 000000000000..e62d94ed16bd --- /dev/null +++ b/src/Mod/Path/App/FeatureAreaPy.xml @@ -0,0 +1,30 @@ + + + + + + This class handles Path Area features + + + + Return a copy of the encapsulated Python Area object. + + + + + setParams(key=value...): Convenient function to configure this feature.\n +Same usage as Path.Area.setParams(). This function stores the parameters in the properties. + + + + + + diff --git a/src/Mod/Path/App/FeatureAreaPyImp.cpp b/src/Mod/Path/App/FeatureAreaPyImp.cpp new file mode 100644 index 000000000000..1e76840e2bf1 --- /dev/null +++ b/src/Mod/Path/App/FeatureAreaPyImp.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** + * Copyright (c) 2017 Zheng, Lei (realthunder) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ****************************************************************************/ + +#include "PreCompiled.h" + +#include +#include "FeatureArea.h" + +// inclusion of the generated files (generated out of FeatureAreaPy.xml) +#include "FeatureAreaPy.h" +#include "FeatureAreaPy.cpp" + +#include "AreaPy.h" + +using namespace Path; + + +// returns a string which represent the object e.g. when printed in python +std::string FeatureAreaPy::representation(void) const +{ + return std::string(""); +} + + +PyObject* FeatureAreaPy::getArea(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + return new AreaPy(new Area(getFeatureAreaPtr()->myArea)); +} + +PyObject* FeatureAreaPy::setParams(PyObject *args, PyObject *keywds) +{ + static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_CONF),NULL}; + + //Declare variables defined in the NAME field of the CONF parameter list + PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_CONF); + + FeatureArea *feature = getFeatureAreaPtr(); + +#define AREA_SET(_param) \ + PARAM_FNAME(_param) = \ + PARAM_TYPED(PARAM_PY_CAST_,_param)(feature->PARAM_FNAME(_param).getValue()); + //populate the CONF variables with values in properties + PARAM_FOREACH(AREA_SET,AREA_PARAMS_CONF) + + //Parse arguments to overwrite CONF variables + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "|" PARAM_PY_KWDS(AREA_PARAMS_CONF), kwlist, + PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF))) + Py_Error(Base::BaseExceptionFreeCADError, + "Wrong parameters, call getParamsDesc() to get supported params"); + +#define AREA_GET(_param) \ + feature->PARAM_FNAME(_param).setValue(\ + PARAM_TYPED(PARAM_CAST_PY_,_param)(PARAM_FNAME(_param))); + //populate properties with the CONF variables + PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF) + + return Py_None; +} + +PyObject *FeatureAreaPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + + +int FeatureAreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} +