PartDesign: tidy up sketch support and base feature confusion
Not complete, transformPlacement and positionBySketch are pending...
This commit is contained in:
parent
b67c8bd34d
commit
03be8e1bba
|
@ -91,7 +91,7 @@ const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
|
|||
throw Base::Exception("getPointFromFace(): Not implemented yet for this case");
|
||||
}
|
||||
|
||||
const Part::Feature* Feature::getBaseObject() const {
|
||||
Part::Feature* Feature::getBaseObject() const {
|
||||
App::DocumentObject* BaseLink = BaseFeature.getValue();
|
||||
if (BaseLink == NULL) throw Base::Exception("Base property not set");
|
||||
Part::Feature* BaseObject = NULL;
|
||||
|
@ -136,14 +136,15 @@ bool Feature::isDatum(const App::DocumentObject* feature)
|
|||
|
||||
gp_Pln Feature::makePlnFromPlane(const App::DocumentObject* obj)
|
||||
{
|
||||
const App::Plane* plane = static_cast<const App::Plane*>(obj);
|
||||
const App::GeoFeature* plane = static_cast<const App::GeoFeature*>(obj);
|
||||
if (plane == NULL)
|
||||
throw Base::Exception("Feature: Null object");
|
||||
|
||||
Base::Vector3d pos = plane->Placement.getValue().getPosition();
|
||||
Base::Rotation rot = plane->Placement.getValue().getRotation();
|
||||
Base::Vector3d normal(0,0,1);
|
||||
rot.multVec(normal, normal);
|
||||
return gp_Pln(gp_Pnt(0,0,0), gp_Dir(normal.x,normal.y,normal.z));
|
||||
return gp_Pln(gp_Pnt(pos.x,pos.y,pos.z), gp_Dir(normal.x,normal.y,normal.z));
|
||||
}
|
||||
|
||||
TopoDS_Shape Feature::makeShapeFromPlane(const App::DocumentObject* obj)
|
||||
|
|
|
@ -56,14 +56,15 @@ public:
|
|||
/// Check whether the given feature is a datum feature
|
||||
static bool isDatum(const App::DocumentObject* feature);
|
||||
|
||||
protected:
|
||||
/// Returns the BaseFeature property's object (if any)
|
||||
const Part::Feature* getBaseObject() const;
|
||||
virtual Part::Feature* getBaseObject() const;
|
||||
/// Returns the BaseFeature property's shape (if any)
|
||||
const TopoDS_Shape& getBaseShape() const;
|
||||
virtual const TopoDS_Shape& getBaseShape() const;
|
||||
/// Returns the BaseFeature property's TopoShape (if any)
|
||||
const Part::TopoShape getBaseTopoShape() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Get a solid of the given shape. If no solid is found an exception is raised.
|
||||
*/
|
||||
|
|
|
@ -98,12 +98,7 @@ App::DocumentObjectExecReturn *Groove::execute(void)
|
|||
try {
|
||||
base = getBaseShape();
|
||||
} catch (const Base::Exception&) {
|
||||
try {
|
||||
// fall back to support (for legacy features)
|
||||
base = getSupportShape();
|
||||
} catch (const Base::Exception&) {
|
||||
return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the groove!");
|
||||
}
|
||||
return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the groove!");
|
||||
}
|
||||
|
||||
updateAxis();
|
||||
|
|
|
@ -107,13 +107,7 @@ App::DocumentObjectExecReturn *Pad::execute(void)
|
|||
try {
|
||||
base = getBaseShape();
|
||||
} catch (const Base::Exception&) {
|
||||
try {
|
||||
// fall back to support (for legacy features)
|
||||
base = getSupportShape();
|
||||
} catch (const Base::Exception&) {
|
||||
// ignore, because support isn't mandatory
|
||||
base = TopoDS_Shape();
|
||||
}
|
||||
base = TopoDS_Shape();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -104,12 +104,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
|
|||
try {
|
||||
base = getBaseShape();
|
||||
} catch (const Base::Exception&) {
|
||||
try {
|
||||
// fall back to support (for legacy features)
|
||||
base = getSupportShape();
|
||||
} catch (const Base::Exception&) {
|
||||
return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the pocket!");
|
||||
}
|
||||
return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the pocket!");
|
||||
}
|
||||
|
||||
// get the Sketch plane
|
||||
|
|
|
@ -99,12 +99,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
|
|||
base = getBaseShape();
|
||||
} catch (const Base::Exception&) {
|
||||
// fall back to support (for legacy features)
|
||||
try {
|
||||
base = getSupportShape();
|
||||
} catch (const Base::Exception&) {
|
||||
// ignore, because support isn't mandatory
|
||||
base = TopoDS_Shape();
|
||||
}
|
||||
base = TopoDS_Shape();
|
||||
}
|
||||
|
||||
// update Axis from ReferenceAxis
|
||||
|
|
|
@ -188,68 +188,41 @@ std::vector<TopoDS_Wire> SketchBased::getSketchWires() const {
|
|||
return result;
|
||||
}
|
||||
|
||||
// TODO: This code is taken from and duplicates code in Part2DObject::positionBySupport()
|
||||
// Note: We cannot return a reference, because it will become Null.
|
||||
// Not clear where, because we check for IsNull() here, but as soon as it is passed out of
|
||||
// this method, it becomes null!
|
||||
const TopoDS_Face SketchBased::getSupportFace() const {
|
||||
const App::PropertyLinkSub& Support = static_cast<Part::Part2DObject*>(Sketch.getValue())->Support;
|
||||
App::DocumentObject* ref = Support.getValue();
|
||||
const Part::Part2DObject* sketch = getVerifiedSketch();
|
||||
if (sketch->Support.getValue()) {
|
||||
const App::PropertyLinkSubList& Support = sketch->Support;
|
||||
App::DocumentObject* ref = Support.getValue();
|
||||
|
||||
if (ref->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
|
||||
TopoDS_Shape plane = Feature::makeShapeFromPlane(ref);
|
||||
return TopoDS::Face(plane);
|
||||
} else if (ref->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
|
||||
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(ref);
|
||||
return TopoDS::Face(plane->getShape());
|
||||
Part::Feature *part = static_cast<Part::Feature*>(ref);
|
||||
if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
const std::vector<std::string> &sub = Support.getSubValues();
|
||||
assert(sub.size()==1);
|
||||
// get the selected sub shape (a Face)
|
||||
const Part::TopoShape &shape = part->Shape.getShape();
|
||||
if (shape._Shape.IsNull())
|
||||
throw Base::Exception("Sketch support shape is empty!");
|
||||
|
||||
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());
|
||||
if (sh.IsNull())
|
||||
throw Base::Exception("Null shape in SketchBased::getSupportFace()!");
|
||||
|
||||
const TopoDS_Face face = TopoDS::Face(sh);
|
||||
if (face.IsNull())
|
||||
throw Base::Exception("Null face in SketchBased::getSupportFace()!");
|
||||
|
||||
BRepAdaptor_Surface adapt(face);
|
||||
if (adapt.GetType() != GeomAbs_Plane)
|
||||
throw Base::Exception("No planar face in SketchBased::getSupportFace()!");
|
||||
|
||||
return face;
|
||||
}
|
||||
}
|
||||
return TopoDS::Face(Feature::makeShapeFromPlane(sketch));
|
||||
|
||||
Part::Feature *part = static_cast<Part::Feature*>(Support.getValue());
|
||||
if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
throw Base::Exception("No support in sketch");
|
||||
|
||||
const std::vector<std::string> &sub = Support.getSubValues();
|
||||
assert(sub.size()==1);
|
||||
// get the selected sub shape (a Face)
|
||||
const Part::TopoShape &shape = part->Shape.getShape();
|
||||
if (shape._Shape.IsNull())
|
||||
throw Base::Exception("Sketch support shape is empty!");
|
||||
|
||||
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());
|
||||
if (sh.IsNull())
|
||||
throw Base::Exception("Null shape in SketchBased::getSupportFace()!");
|
||||
|
||||
const TopoDS_Face face = TopoDS::Face(sh);
|
||||
if (face.IsNull())
|
||||
throw Base::Exception("Null face in SketchBased::getSupportFace()!");
|
||||
|
||||
BRepAdaptor_Surface adapt(face);
|
||||
if (adapt.GetType() != GeomAbs_Plane)
|
||||
throw Base::Exception("No planar face in SketchBased::getSupportFace()!");
|
||||
|
||||
return face;
|
||||
}
|
||||
|
||||
const TopoDS_Shape& SketchBased::getSupportShape() const {
|
||||
if (!Sketch.getValue())
|
||||
throw Base::Exception("No Sketch!");
|
||||
|
||||
App::DocumentObject* SupportLink = static_cast<Part::Part2DObject*>(Sketch.getValue())->Support.getValue();
|
||||
Part::Feature* SupportObject = NULL;
|
||||
if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
SupportObject = static_cast<Part::Feature*>(SupportLink);
|
||||
|
||||
if (SupportObject == NULL)
|
||||
throw Base::Exception("No support in Sketch!");
|
||||
|
||||
const TopoDS_Shape& result = SupportObject->Shape.getValue();
|
||||
if (result.IsNull())
|
||||
throw Base::Exception("Support shape is invalid");
|
||||
TopExp_Explorer xp (result, TopAbs_SOLID);
|
||||
if (!xp.More())
|
||||
throw Base::Exception("Support shape is not a solid");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int SketchBased::getSketchAxisCount(void) const
|
||||
|
@ -260,6 +233,21 @@ int SketchBased::getSketchAxisCount(void) const
|
|||
return sketch->getAxisCount();
|
||||
}
|
||||
|
||||
Part::Feature *SketchBased::getBaseObject() const
|
||||
{
|
||||
try{
|
||||
return Feature::getBaseObject();
|
||||
} catch (Base::Exception) {
|
||||
Part::Part2DObject* sketch = getVerifiedSketch();
|
||||
App::DocumentObject* spt = sketch->Support.getValue();
|
||||
if(!spt)
|
||||
throw Base::Exception ("No base set, no sketch support either");
|
||||
if(!spt->isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
throw Base::Exception ("No base set, sketch support is not Part::Feature");
|
||||
return static_cast<Part::Feature*>(spt);
|
||||
}
|
||||
}
|
||||
|
||||
void SketchBased::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (prop == &Sketch) {
|
||||
|
@ -980,16 +968,6 @@ bool SketchBased::isParallelPlane(const TopoDS_Shape& s1, const TopoDS_Shape& s2
|
|||
return false;
|
||||
}
|
||||
|
||||
bool SketchBased::isSupportDatum() const
|
||||
{
|
||||
if (!Sketch.getValue())
|
||||
return 0;
|
||||
App::DocumentObject* SupportObject = static_cast<Part::Part2DObject*>(Sketch.getValue())->Support.getValue();
|
||||
if (SupportObject == NULL)
|
||||
throw Base::Exception("No support in Sketch!");
|
||||
|
||||
return isDatum(SupportObject);
|
||||
}
|
||||
|
||||
const double SketchBased::getReversedAngle(const Base::Vector3d &b, const Base::Vector3d &v)
|
||||
{
|
||||
|
|
|
@ -71,14 +71,12 @@ public:
|
|||
std::vector<TopoDS_Wire> getSketchWires() const;
|
||||
/// Returns the face of the sketch support (if any)
|
||||
const TopoDS_Face getSupportFace() const;
|
||||
/// Returns the sketch support shape (if any)
|
||||
const TopoDS_Shape& getSupportShape() const;
|
||||
/// Check whether the sketch support is a datum plane
|
||||
bool isSupportDatum() const;
|
||||
|
||||
/// retrieves the number of axes in the linked sketch (defined as construction lines)
|
||||
int getSketchAxisCount(void) const;
|
||||
|
||||
virtual Part::Feature* getBaseObject() const;
|
||||
|
||||
protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
TopoDS_Face validateFace(const TopoDS_Face&) const;
|
||||
|
|
|
@ -376,9 +376,7 @@ void TaskGrooveParameters::apply()
|
|||
App::DocumentObject* support = 0;
|
||||
if (groove->getTypeId().isDerivedFrom(PartDesign::Groove::getClassTypeId())) {
|
||||
sketch = static_cast<PartDesign::Groove*>(groove)->Sketch.getValue<Sketcher::SketchObject*>();
|
||||
if (sketch) {
|
||||
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
|
||||
}
|
||||
support = static_cast<PartDesign::Groove*>(groove)->getBaseObject();
|
||||
}
|
||||
|
||||
//Gui::Command::openCommand("Groove changed");
|
||||
|
|
|
@ -145,8 +145,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
|
|||
ui->lineFaceName->blockSignals(false);
|
||||
ui->changeMode->blockSignals(false);
|
||||
|
||||
// Activate the Reverse option only if the support is a datum plane
|
||||
ui->checkBoxReversed->setVisible(pcPocket->isSupportDatum());
|
||||
ui->checkBoxReversed->setVisible(true);
|
||||
|
||||
updateUI(index);
|
||||
|
||||
|
|
|
@ -372,10 +372,8 @@ void TaskRevolutionParameters::apply()
|
|||
App::DocumentObject* sketch = 0;
|
||||
App::DocumentObject* support = 0;
|
||||
if (revolve->getTypeId().isDerivedFrom(PartDesign::Revolution::getClassTypeId())) {
|
||||
sketch = static_cast<PartDesign::Revolution*>(revolve)->Sketch.getValue<Sketcher::SketchObject*>();
|
||||
if (sketch) {
|
||||
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
|
||||
}
|
||||
sketch = static_cast<PartDesign::Revolution*>(revolve)->Sketch.getValue();
|
||||
support = static_cast<PartDesign::Revolution*>(revolve)->getBaseObject();
|
||||
}
|
||||
|
||||
//Gui::Command::openCommand("Revolution changed");
|
||||
|
|
Loading…
Reference in New Issue
Block a user