Moved BaseFeature Property from SketchBased to PartDesign::Feature because all PartDesign features need it

This commit is contained in:
jrheinlaender 2013-04-08 20:25:59 +04:30 committed by Stefan Tröger
parent f7d9bf90c4
commit df7983fe10
4 changed files with 40 additions and 29 deletions

View File

@ -47,6 +47,15 @@ PROPERTY_SOURCE(PartDesign::Feature,Part::Feature)
Feature::Feature()
{
ADD_PROPERTY(BaseFeature,(0));
}
short Feature::mustExecute() const
{
if (BaseFeature.isTouched())
return 1;
return Part::Feature::mustExecute();
}
TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape)
@ -77,4 +86,24 @@ const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
throw Base::Exception("getPointFromFace(): Not implemented yet for this case");
}
const TopoDS_Shape& Feature::getBaseShape() const {
App::DocumentObject* BaseLink = BaseFeature.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;
}
}

View File

@ -45,9 +45,17 @@ class PartDesignExport Feature : public Part::Feature
PROPERTY_HEADER(PartDesign::Feature);
public:
Feature();
Feature();
/// Base feature which this feature will be fused into or cut out of
App::PropertyLink BaseFeature;
short mustExecute() const;
protected:
/// Returns the BaseFeature property's shape (if any)
const TopoDS_Shape& getBaseShape() const;
/**
* Get a solid of the given shape. If no solid is found an exception is raised.
*/

View File

@ -98,7 +98,6 @@ PROPERTY_SOURCE(PartDesign::SketchBased, PartDesign::Feature)
SketchBased::SketchBased()
{
ADD_PROPERTY(BaseFeature,(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");
@ -106,12 +105,11 @@ SketchBased::SketchBased()
short SketchBased::mustExecute() const
{
if (BaseFeature.isTouched() ||
Sketch.isTouched() ||
if (Sketch.isTouched() ||
Midplane.isTouched() ||
Reversed.isTouched())
return 1;
return 0; // PartDesign::Feature::mustExecute();
return PartDesign::Feature::mustExecute();
}
void SketchBased::positionBySketch(void)
@ -233,26 +231,6 @@ const TopoDS_Shape& SketchBased::getSupportShape() const {
return result;
}
const TopoDS_Shape& SketchBased::getBaseShape() const {
App::DocumentObject* BaseLink = BaseFeature.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

@ -45,8 +45,6 @@ public:
SketchBased();
// Common properties for all sketch based features
/// Base feature which this feature will be fused into or cut out of
App::PropertyLink BaseFeature;
/// Sketch used to create this feature
App::PropertyLink Sketch;
/// Reverse extrusion direction
@ -75,8 +73,6 @@ 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;