Path: added support to get Path.Area from Path::FeatureArea

This commit is contained in:
Zheng, Lei
2017-01-25 00:23:21 +08:00
parent 16cec19733
commit 01f68f88e1
7 changed files with 167 additions and 5 deletions

View File

@@ -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> area:mySections)
mySections.push_back(make_shared<Area>(*area,true));
}
Area::~Area() {
clean();
}

View File

@@ -146,6 +146,7 @@ public:
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

View File

@@ -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

View File

@@ -29,6 +29,7 @@
#include <TopoDS_Compound.hxx>
#include "FeatureArea.h"
#include "FeatureAreaPy.h"
#include <App/DocumentObjectPy.h>
#include <Base/Placement.h>
#include <Mod/Part/App/PartFeature.h>
@@ -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(&params);
myArea.clean(true);
myArea.setParams(params);
TopoDS_Shape workPlane = WorkPlane.getShape().getShape();
if(!workPlane.IsNull())
area.setPlane(workPlane);
myArea.setPlane(workPlane);
for (std::vector<App::DocumentObject*>::iterator it = links.begin(); it != links.end(); ++it) {
area.add(static_cast<Part::Feature*>(*it)->Shape.getShape().getShape(),
myArea.add(static_cast<Part::Feature*>(*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 {

View File

@@ -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 @@ public:
}
virtual App::DocumentObjectExecReturn *execute(void);
virtual short mustExecute(void) const;
virtual PyObject *getPyObject(void);
App::PropertyLinkList Sources;
Part::PropertyPartShape WorkPlane;

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DocumentObjectPy"
Name="FeatureAreaPy"
Twin="FeatureArea"
TwinPointer="FeatureArea"
Include="Mod/Path/App/FeatureArea.h"
Namespace="Path"
FatherInclude="App/DocumentObjectPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Zheng, Lei" EMail="realthunder.dev@gmail.com" />
<UserDocu>This class handles Path Area features</UserDocu>
</Documentation>
<Methode Name="getArea">
<Documentation>
<UserDocu>Return a copy of the encapsulated Python Area object.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setParams" Keyword="true">
<Documentation>
<UserDocu>setParams(key=value...): Convenient function to configure this feature.\n
Same usage as Path.Area.setParams(). This function stores the parameters in the properties.</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,93 @@
/****************************************************************************
* Copyright (c) 2017 Zheng, Lei (realthunder) <realthunder.dev@gmail.com>*
* *
* 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 <CXX/Objects.hxx>
#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("<Path::FeatureArea>");
}
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;
}