From 03be8e1bba5367eb18e12a31f96095a95451e7a1 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Mon, 29 Jun 2015 22:50:31 +0300 Subject: [PATCH] PartDesign: tidy up sketch support and base feature confusion Not complete, transformPlacement and positionBySketch are pending... --- src/Mod/PartDesign/App/Feature.cpp | 7 +- src/Mod/PartDesign/App/Feature.h | 7 +- src/Mod/PartDesign/App/FeatureGroove.cpp | 7 +- src/Mod/PartDesign/App/FeaturePad.cpp | 8 +- src/Mod/PartDesign/App/FeaturePocket.cpp | 7 +- src/Mod/PartDesign/App/FeatureRevolution.cpp | 7 +- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 108 +++++++----------- src/Mod/PartDesign/App/FeatureSketchBased.h | 6 +- .../PartDesign/Gui/TaskGrooveParameters.cpp | 4 +- .../PartDesign/Gui/TaskPocketParameters.cpp | 3 +- .../Gui/TaskRevolutionParameters.cpp | 6 +- 11 files changed, 61 insertions(+), 109 deletions(-) diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 2b77148fa8..fe589b6a41 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -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(obj); + const App::GeoFeature* plane = static_cast(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) diff --git a/src/Mod/PartDesign/App/Feature.h b/src/Mod/PartDesign/App/Feature.h index c9f0d170eb..c9723389b4 100644 --- a/src/Mod/PartDesign/App/Feature.h +++ b/src/Mod/PartDesign/App/Feature.h @@ -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. */ diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index f9eb3cf77e..b363a056bc 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -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(); diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index 30b6788112..3c360b5f5d 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -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(); } /* diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index ef06f4265b..ad2ce488ef 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -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 diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index 8c2f648ba9..8ff5d93646 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -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 diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 5256fa2788..dc11f13a34 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -188,68 +188,41 @@ std::vector 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(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(ref); - return TopoDS::Face(plane->getShape()); + Part::Feature *part = static_cast(ref); + if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + const std::vector &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(Support.getValue()); - if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - throw Base::Exception("No support in sketch"); - - const std::vector &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(Sketch.getValue())->Support.getValue(); - Part::Feature* SupportObject = NULL; - if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - SupportObject = static_cast(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(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(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) { diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.h b/src/Mod/PartDesign/App/FeatureSketchBased.h index bb2f38784b..f3c9780091 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.h +++ b/src/Mod/PartDesign/App/FeatureSketchBased.h @@ -71,14 +71,12 @@ public: std::vector 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; diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp index 927d9b0231..13c3c76671 100644 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp @@ -376,9 +376,7 @@ void TaskGrooveParameters::apply() App::DocumentObject* support = 0; if (groove->getTypeId().isDerivedFrom(PartDesign::Groove::getClassTypeId())) { sketch = static_cast(groove)->Sketch.getValue(); - if (sketch) { - support = static_cast(sketch)->Support.getValue(); - } + support = static_cast(groove)->getBaseObject(); } //Gui::Command::openCommand("Groove changed"); diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp index 023735e2b1..357f43491b 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp @@ -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); diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 9d7e7b8f25..d206110af4 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -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(revolve)->Sketch.getValue(); - if (sketch) { - support = static_cast(sketch)->Support.getValue(); - } + sketch = static_cast(revolve)->Sketch.getValue(); + support = static_cast(revolve)->getBaseObject(); } //Gui::Command::openCommand("Revolution changed");