Integrated PartDesign::Pad into Body feature workflow
This commit is contained in:
parent
6654b859eb
commit
5dbc66ae84
|
@ -31,6 +31,8 @@
|
|||
#include "Body.h"
|
||||
#include "BodyPy.h"
|
||||
|
||||
#include <Base/Console.h>
|
||||
|
||||
|
||||
using namespace PartDesign;
|
||||
|
||||
|
@ -51,18 +53,54 @@ short Body::mustExecute() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *Body::execute(void)
|
||||
const Part::TopoShape Body::getTipShape()
|
||||
{
|
||||
// TODO right selection for Body
|
||||
App::DocumentObject* link = Tip.getValue();
|
||||
if (!link)
|
||||
//return new App::DocumentObjectExecReturn("No object!");
|
||||
return App::DocumentObject::StdReturn;
|
||||
return Part::TopoShape();
|
||||
//Base::Console().Error("Body tip: %s\n", link->getNameInDocument());
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
return new App::DocumentObjectExecReturn("Linked object is not a PartDesign object");
|
||||
//return App::DocumentObject::StdReturn;
|
||||
//return new App::DocumentObjectExecReturn("Linked object is not a PartDesign object");
|
||||
return Part::TopoShape();
|
||||
// get the shape of the tip
|
||||
const Part::TopoShape& TipShape = static_cast<Part::Feature*>(link)->Shape.getShape();
|
||||
return static_cast<Part::Feature*>(link)->Shape.getShape();
|
||||
}
|
||||
|
||||
const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f)
|
||||
{
|
||||
std::vector<App::DocumentObject*> features = Model.getValues();
|
||||
std::vector<App::DocumentObject*>::const_iterator it = std::find(features.begin(), features.end(), f);
|
||||
if ((it == features.end()) || (it == features.begin()))
|
||||
// Wrong body or there is no previous feature
|
||||
return Part::TopoShape();
|
||||
// move to previous feature
|
||||
it--;
|
||||
// Skip sketches
|
||||
while (!(*it)->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
|
||||
if (it == features.begin())
|
||||
return Part::TopoShape();
|
||||
it--;
|
||||
}
|
||||
|
||||
return static_cast<const PartDesign::Feature*>(*it)->Shape.getShape();
|
||||
}
|
||||
|
||||
const bool Body::hasFeature(const PartDesign::Feature* f)
|
||||
{
|
||||
std::vector<App::DocumentObject*> features = Model.getValues();
|
||||
return std::find(features.begin(), features.end(), f) != features.end();
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *Body::execute(void)
|
||||
{
|
||||
std::vector<App::DocumentObject*> children = Model.getValues();
|
||||
//Base::Console().Error("Body exec children:\n");
|
||||
//for (std::vector<App::DocumentObject*>::const_iterator o = children.begin(); o != children.end(); o++)
|
||||
// Base::Console().Error("%s\n", (*o)->getNameInDocument());
|
||||
|
||||
const Part::TopoShape& TipShape = getTipShape();
|
||||
|
||||
if (TipShape._Shape.IsNull())
|
||||
//return new App::DocumentObjectExecReturn("empty shape");
|
||||
return App::DocumentObject::StdReturn;
|
||||
|
@ -82,4 +120,4 @@ PyObject *Body::getPyObject(void)
|
|||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
namespace PartDesign
|
||||
{
|
||||
|
||||
class Feature;
|
||||
|
||||
class Body : public Part::BodyBase
|
||||
{
|
||||
PROPERTY_HEADER(PartDesign::Body);
|
||||
|
@ -49,6 +51,15 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
/// Get the tip shape
|
||||
const Part::TopoShape getTipShape();
|
||||
|
||||
/// Return the shape of the feature preceding this feature
|
||||
const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f);
|
||||
|
||||
/// Return true if the feature belongs to this body
|
||||
const bool hasFeature(const PartDesign::Feature* f);
|
||||
|
||||
PyObject *getPyObject(void);
|
||||
|
||||
};
|
||||
|
|
|
@ -28,11 +28,13 @@
|
|||
# include <TopExp_Explorer.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <gp_Pnt.hxx>
|
||||
# include <gp_Pnt.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include "App/Document.h"
|
||||
#include "Body.h"
|
||||
#include "Feature.h"
|
||||
|
||||
|
||||
|
@ -59,6 +61,17 @@ TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape)
|
|||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
PartDesign::Body* Feature::getBody()
|
||||
{
|
||||
std::vector<App::DocumentObject*> bodies = this->getDocument()->getObjectsOfType(PartDesign::Body::getClassTypeId());
|
||||
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++) {
|
||||
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);
|
||||
if (body->hasFeature(this))
|
||||
return body;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
|
||||
{
|
||||
if (!f.Infinite()) {
|
||||
|
@ -73,5 +86,5 @@ const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
|
|||
// Or get a "corner" point if the face is limited?
|
||||
throw Base::Exception("getPointFromFace(): Not implemented yet for this case");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ class gp_Pnt;
|
|||
namespace PartDesign
|
||||
{
|
||||
|
||||
class Body;
|
||||
|
||||
/** PartDesign feature
|
||||
* Base class of all PartDesign features.
|
||||
* This kind of features only produce solids or fail.
|
||||
|
@ -46,11 +48,14 @@ public:
|
|||
Feature();
|
||||
|
||||
protected:
|
||||
/// Get the body feature which this feature belongs to
|
||||
Body* getBody();
|
||||
|
||||
/**
|
||||
* Get a solid of the given shape. If no solid is found an exception is raised.
|
||||
*/
|
||||
static TopoDS_Shape getSolid(const TopoDS_Shape&);
|
||||
|
||||
static TopoDS_Shape getSolid(const TopoDS_Shape&);
|
||||
|
||||
/// Grab any point from the given face
|
||||
static const gp_Pnt getPointFromFace(const TopoDS_Face& f);
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include <Base/Reader.h>
|
||||
#include <App/Document.h>
|
||||
|
||||
#include "Body.h"
|
||||
#include "FeaturePad.h"
|
||||
|
||||
|
||||
|
@ -95,13 +96,23 @@ App::DocumentObjectExecReturn *Pad::execute(void)
|
|||
return new App::DocumentObjectExecReturn(e.what());
|
||||
}
|
||||
|
||||
// Find active Body feature and get the shape of the feature preceding this one for fusing
|
||||
PartDesign::Body* body = getBody();
|
||||
if (body == NULL) {
|
||||
return new App::DocumentObjectExecReturn(
|
||||
"In order to use PartDesign you need an active Body object in the document. "
|
||||
"Please make one active or create one. If you have a legacy document "
|
||||
"with PartDesign objects without Body, use the transfer function in "
|
||||
"PartDesign to put them into a Body."
|
||||
);
|
||||
}
|
||||
const Part::TopoShape& prevShape = body->getPreviousSolid(this);
|
||||
TopoDS_Shape support;
|
||||
try {
|
||||
support = getSupportShape();
|
||||
} catch (const Base::Exception&) {
|
||||
if (prevShape.isNull())
|
||||
// ignore, because support isn't mandatory
|
||||
support = TopoDS_Shape();
|
||||
}
|
||||
else
|
||||
support = prevShape._Shape;
|
||||
|
||||
// get the Sketch plane
|
||||
Base::Placement SketchPos = sketch->Placement.getValue();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -33,6 +33,8 @@
|
|||
#include <Mod/PartDesign/App/FeatureSketchBased.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Base/Console.h"
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderBody,PartGui::ViewProviderPart)
|
||||
|
@ -109,7 +111,9 @@ std::vector<App::DocumentObject*> ViewProviderBody::claimChildren(void)const
|
|||
for(std::vector<App::DocumentObject*>::const_iterator it = Model.begin();it!=Model.end();++it){
|
||||
// sketches of SketchBased features get claimed under the feature so has to be removed from the Body
|
||||
if ((*it)->isDerivedFrom(PartDesign::SketchBased::getClassTypeId())){
|
||||
OutSet.insert(static_cast<PartDesign::SketchBased*>(*it)->Sketch.getValue());
|
||||
App::DocumentObject* sketch = static_cast<PartDesign::SketchBased*>(*it)->Sketch.getValue();
|
||||
if (sketch != NULL)
|
||||
OutSet.insert(sketch);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +122,9 @@ std::vector<App::DocumentObject*> ViewProviderBody::claimChildren(void)const
|
|||
sort (Model.begin(), Model.end());
|
||||
std::vector<App::DocumentObject*>::iterator it = set_difference (Model.begin(), Model.end(), OutSet.begin(),OutSet.end(), Result.begin());
|
||||
|
||||
//Base::Console().Error("Body claimed children:\n");
|
||||
//for (std::vector<App::DocumentObject*>::const_iterator o = Result.begin(); o != it; o++)
|
||||
// Base::Console().Error("%s\n", (*o)->getNameInDocument());
|
||||
// return the rest as claim set of the Body
|
||||
return std::vector<App::DocumentObject*>(Result.begin(),it);
|
||||
}
|
||||
|
@ -125,7 +132,10 @@ std::vector<App::DocumentObject*> ViewProviderBody::claimChildren(void)const
|
|||
|
||||
std::vector<App::DocumentObject*> ViewProviderBody::claimChildren3D(void)const
|
||||
{
|
||||
|
||||
std::vector<App::DocumentObject*> children = static_cast<PartDesign::Body*>(getObject())->Model.getValues();
|
||||
//Base::Console().Error("Body 3D claimed children:\n");
|
||||
//for (std::vector<App::DocumentObject*>::const_iterator o = children.begin(); o != children.end(); o++)
|
||||
// Base::Console().Error("%s\n", (*o)->getNameInDocument());
|
||||
return static_cast<PartDesign::Body*>(getObject())->Model.getValues();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user