Skip to content

Commit

Permalink
Path: added support to get Path.Area from Path::FeatureArea
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder committed Jan 24, 2017
1 parent 9afefdc commit 1913f6c
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/Mod/Path/App/Area.cpp
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Path/App/Area.h
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Path/App/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -45,6 +46,8 @@ SET(Python_SRCS
FeaturePathCompoundPyImp.cpp
AreaPy.xml
AreaPyImp.cpp
FeatureAreaPy.xml
FeatureAreaPyImp.cpp
)

SET(Mod_SRCS
Expand Down
21 changes: 16 additions & 5 deletions src/Mod/Path/App/FeatureArea.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
}

Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Path/App/FeatureArea.h
Expand Up @@ -40,6 +40,8 @@ class PathExport FeatureArea : public Part::Feature
PROPERTY_HEADER(Path::FeatureArea);

public:
Area myArea;

/// Constructor
FeatureArea(void);
virtual ~FeatureArea();
Expand All @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/Mod/Path/App/FeatureAreaPy.xml
@@ -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>

93 changes: 93 additions & 0 deletions src/Mod/Path/App/FeatureAreaPyImp.cpp
@@ -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;
}

0 comments on commit 1913f6c

Please sign in to comment.