Skip to content

Commit

Permalink
Path.Area: Changed FeatureArea WorkPlane behavior
Browse files Browse the repository at this point in the history
FeatureArea will return the user defined workplane if there is one, or
else it returns auto selected plane by its internal Area object
  • Loading branch information
realthunder authored and wwmayer committed Mar 23, 2017
1 parent b8843ec commit c1ab980
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Path/App/Area.cpp
Expand Up @@ -146,6 +146,7 @@ Area::~Area() {
}

void Area::setPlane(const TopoDS_Shape &shape) {
clean();
if(shape.IsNull()) {
myWorkPlane.Nullify();
return;
Expand All @@ -156,7 +157,6 @@ void Area::setPlane(const TopoDS_Shape &shape) {
throw Base::ValueError("shape is not planar");
myWorkPlane = plane;
myTrsf = trsf;
clean();
}

bool Area::isCoplanar(const TopoDS_Shape &s1, const TopoDS_Shape &s2) {
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Path/App/Area.h
Expand Up @@ -242,8 +242,6 @@ class PathExport Area: public Base::BaseClass {

void explode(const TopoDS_Shape &shape);

bool isBuilt() const;

TopoDS_Shape findPlane(const TopoDS_Shape &shape, gp_Trsf &trsf);

public:
Expand All @@ -254,6 +252,8 @@ class PathExport Area: public Base::BaseClass {
Area(const Area &other, bool deep_copy=true);
virtual ~Area();

bool isBuilt() const;

/** Set a working plane
*
* \arg \c shape: a shape defining a working plane.
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/App/AreaPy.xml
Expand Up @@ -98,7 +98,7 @@ same algorithm</UserDocu>
</Documentation>
<Parameter Name="Sections" Type="List"/>
</Attribute>
<Attribute Name="Workplane" ReadOnly="true">
<Attribute Name="Workplane" ReadOnly="false">
<Documentation>
<UserDocu>The current workplane. If no plane is set, it is derived from the added shapes.</UserDocu>
</Documentation>
Expand Down
13 changes: 9 additions & 4 deletions src/Mod/Path/App/AreaPyImp.cpp
Expand Up @@ -178,10 +178,6 @@ struct AreaPyModifier {

static AreaPyModifier mod;

namespace Part {
extern PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape);
}

using namespace Path;

// returns a string which represents the object e.g. when printed in python
Expand Down Expand Up @@ -481,6 +477,15 @@ Py::Object AreaPy::getWorkplane(void) const {
return Part::shape2pyshape(getAreaPtr()->getPlane());
}

void AreaPy::setWorkplane(Py::Object obj) {
PyObject* p = obj.ptr();
if (!PyObject_TypeCheck(p, &(Part::TopoShapePy::Type))) {
std::string error = std::string("type must be 'TopoShape', not ");
error += p->ob_type->tp_name;
throw Py::TypeError(error);
}
getAreaPtr()->setPlane(GET_TOPOSHAPE(p));
}

// custom attributes get/set

Expand Down
9 changes: 1 addition & 8 deletions src/Mod/Path/App/FeatureArea.cpp
Expand Up @@ -136,14 +136,7 @@ const std::vector<TopoDS_Shape> &FeatureArea::getShapes() {

short FeatureArea::mustExecute(void) const
{
if (Sources.isTouched())
return 1;
if (WorkPlane.isTouched())
return 1;

PARAM_PROP_TOUCHED(AREA_PARAMS_ALL)

return Part::Feature::mustExecute();
return !myArea.isBuilt() || Part::Feature::mustExecute();
}

PyObject *FeatureArea::getPyObject()
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Path/App/FeatureArea.h
Expand Up @@ -60,6 +60,11 @@ class PathExport FeatureArea : public Part::Feature

PARAM_PROP_DECLARE(AREA_PARAMS_ALL)

void setWorkPlane(const TopoDS_Shape &shape) {
WorkPlane.setValue(shape);
myArea.setPlane(shape);
}

private:
bool myBuild;
Area myArea;
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Path/App/FeatureAreaPy.xml
Expand Up @@ -24,6 +24,12 @@
Same usage as Path.Area.setParams(). This function stores the parameters in the properties.</UserDocu>
</Documentation>
</Methode>
<Attribute Name="WorkPlane" ReadOnly="false">
<Documentation>
<UserDocu>The current workplane. If no plane is set, it is derived from the added shapes.</UserDocu>
</Documentation>
<Parameter Name="WorkPlane" Type="Object"/>
</Attribute>
<CustomAttributes />
</PythonExport>
</GenerateModel>
Expand Down
16 changes: 16 additions & 0 deletions src/Mod/Path/App/FeatureAreaPyImp.cpp
Expand Up @@ -23,6 +23,7 @@
#include "PreCompiled.h"

#include <CXX/Objects.hxx>
#include <Mod/Part/App/TopoShapePy.h>
#include "FeatureArea.h"

// inclusion of the generated files (generated out of FeatureAreaPy.xml)
Expand Down Expand Up @@ -80,6 +81,21 @@ PyObject* FeatureAreaPy::setParams(PyObject *args, PyObject *keywds)
return Py_None;
}

Py::Object FeatureAreaPy::getWorkPlane(void) const {
return Part::shape2pyshape(getFeatureAreaPtr()->getArea().getPlane());
}

void FeatureAreaPy::setWorkPlane(Py::Object obj) {
PyObject* p = obj.ptr();
if (!PyObject_TypeCheck(p, &(Part::TopoShapePy::Type))) {
std::string error = std::string("type must be 'TopoShape', not ");
error += p->ob_type->tp_name;
throw Py::TypeError(error);
}
getFeatureAreaPtr()->setWorkPlane(
static_cast<Part::TopoShapePy*>(p)->getTopoShapePtr()->getShape());
}

PyObject *FeatureAreaPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
Expand Down

0 comments on commit c1ab980

Please sign in to comment.