Create Base property for SketchBased features and changed Pad to use it

This commit is contained in:
jrheinlaender
2013-04-02 20:51:31 +04:30
committed by Stefan Tröger
parent 0a893135c8
commit e9d8c03665
6 changed files with 100 additions and 23 deletions

View File

@@ -86,6 +86,22 @@ const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f)
return static_cast<const PartDesign::Feature*>(*it)->Shape.getShape();
}
App::DocumentObject* Body::getTipSolidFeature()
{
std::vector<App::DocumentObject*> features = Model.getValues();
if (features.empty()) return NULL;
std::vector<App::DocumentObject*>::const_iterator it = std::find(features.begin(), features.end(), Tip.getValue());
// Skip sketches
while (!(*it)->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
if (it == features.begin())
return NULL;
it--;
}
return *it;
}
const bool Body::hasFeature(const App::DocumentObject* f)
{
std::vector<App::DocumentObject*> features = Model.getValues();

View File

@@ -58,6 +58,14 @@ public:
/// Get the tip shape
const Part::TopoShape getTipShape();
/**
* Return Tip feature if it is a solid. Otherwise, go backwards in the Model and
* find the first feature that is a solid (i.e. Sketches are skipped)
* This is used by SketchBased features to determine the shape they should fuse with or cut out off
* NOTE: Currently only PartDesign features are accepted as TipSolidFeatures
*/
App::DocumentObject *getTipSolidFeature();
/// Return the shape of the feature preceding this feature
const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f);

View File

@@ -96,7 +96,20 @@ App::DocumentObjectExecReturn *Pad::execute(void)
return new App::DocumentObjectExecReturn(e.what());
}
TopoDS_Shape support;
try {
support = getSupportShape();
} catch (const Base::Exception&) {
// ignore, because support isn't mandatory
support = TopoDS_Shape();
}
/*
// Find Body feature which owns this Pad and get the shape of the feature preceding this one for fusing
// This method was rejected in favour of the Base property because it makes the feature atomic (independent of the
// Body object). See
// https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=19&t=3831
// https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=19&t=3855
PartDesign::Body* body = getBody();
if (body == NULL) {
return new App::DocumentObjectExecReturn(
@@ -113,6 +126,7 @@ App::DocumentObjectExecReturn *Pad::execute(void)
support = TopoDS_Shape();
else
support = prevShape._Shape;
*/
// get the Sketch plane
Base::Placement SketchPos = sketch->Placement.getValue();
@@ -184,13 +198,22 @@ App::DocumentObjectExecReturn *Pad::execute(void)
prism = refineShapeIfActive(prism);
this->AddShape.setValue(prism);
// if the sketch has a support fuse them to get one result object
if (!support.IsNull()) {
// if the Base property has a valid shape, fuse the prism into it
TopoDS_Shape base;
try {
base = getBaseShape();
base.Move(invObjLoc);
} catch (const Base::Exception&) {
// fall back to support (for legacy features)
base = support;
}
if (!base.IsNull()) {
// Let's call algorithm computing a fuse operation:
BRepAlgoAPI_Fuse mkFuse(support, prism);
BRepAlgoAPI_Fuse mkFuse(base, prism);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
return new App::DocumentObjectExecReturn("Pad: Fusion with support failed");
return new App::DocumentObjectExecReturn("Pad: Fusion with base feature failed");
TopoDS_Shape result = mkFuse.Shape();
// we have to get the solids (fuse sometimes creates compounds)
TopoDS_Shape solRes = this->getSolid(result);

View File

@@ -98,6 +98,7 @@ PROPERTY_SOURCE(PartDesign::SketchBased, PartDesign::Feature)
SketchBased::SketchBased()
{
ADD_PROPERTY(Base,(0));
ADD_PROPERTY_TYPE(Sketch,(0),"SketchBased", App::Prop_None, "Reference to sketch");
ADD_PROPERTY_TYPE(Midplane,(0),"SketchBased", App::Prop_None, "Extrude symmetric to sketch face");
ADD_PROPERTY_TYPE(Reversed, (0),"SketchBased", App::Prop_None, "Reverse extrusion direction");
@@ -231,6 +232,26 @@ const TopoDS_Shape& SketchBased::getSupportShape() const {
return result;
}
const TopoDS_Shape& SketchBased::getBaseShape() const {
App::DocumentObject* BaseLink = Base.getValue();
if (BaseLink == NULL) throw Base::Exception("Base property not set");
Part::Feature* BaseObject = NULL;
if (BaseLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
BaseObject = static_cast<Part::Feature*>(BaseLink);
if (BaseObject == NULL)
throw Base::Exception("No base feature linked");
const TopoDS_Shape& result = BaseObject->Shape.getValue();
if (result.IsNull())
throw Base::Exception("Base feature's shape is invalid");
TopExp_Explorer xp (result, TopAbs_SOLID);
if (!xp.More())
throw Base::Exception("Base feature's shape is not a solid");
return result;
}
int SketchBased::getSketchAxisCount(void) const
{
Part::Part2DObject *sketch = static_cast<Part::Part2DObject*>(Sketch.getValue());

View File

@@ -44,7 +44,10 @@ class PartDesignExport SketchBased : public PartDesign::Feature
public:
SketchBased();
/// Common properties for all sketch based features
// Common properties for all sketch based features
/// Base feature which this feature will be fused into or cut out of
App::PropertyLink Base;
/// Sketch used to create this feature
App::PropertyLink Sketch;
/// Reverse extrusion direction
App::PropertyBool Reversed;
@@ -72,6 +75,8 @@ public:
Part::Feature* getSupport() const;
/// Returns the sketch support shape (if any)
const TopoDS_Shape& getSupportShape() const;
/// Returns the base property's shape (if any)
const TopoDS_Shape& getBaseShape() const;
/// retrieves the number of axes in the linked sketch (defined as construction lines)
int getSketchAxisCount(void) const;