From e3ca28baa824917a1e110f3354da7fc27533434d Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Fri, 2 Sep 2016 00:50:48 +0300 Subject: [PATCH] Part: add Offset2D feature derived from Part::Offset, to re-use task dialog easily --- src/Mod/Part/App/AppPart.cpp | 1 + src/Mod/Part/App/FeatureOffset.cpp | 49 +++++++++++++++++++++++++ src/Mod/Part/App/FeatureOffset.h | 18 +++++++++ src/Mod/Part/Gui/AppPartGui.cpp | 1 + src/Mod/Part/Gui/ViewProviderMirror.cpp | 5 +++ src/Mod/Part/Gui/ViewProviderMirror.h | 10 +++++ 6 files changed, 84 insertions(+) diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 5b1efee33..326abb887 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -301,6 +301,7 @@ PyMODINIT_FUNC initPart() Part::Loft ::init(); Part::Sweep ::init(); Part::Offset ::init(); + Part::Offset2D ::init(); Part::Thickness ::init(); // Geometry types diff --git a/src/Mod/Part/App/FeatureOffset.cpp b/src/Mod/Part/App/FeatureOffset.cpp index 7d3a736ec..a341d2fd5 100644 --- a/src/Mod/Part/App/FeatureOffset.cpp +++ b/src/Mod/Part/App/FeatureOffset.cpp @@ -93,3 +93,52 @@ App::DocumentObjectExecReturn *Offset::execute(void) } +//------------------------------------------------------------------------------------------------------- + + +PROPERTY_SOURCE(Part::Offset2D, Part::Offset) + +Offset2D::Offset2D() +{ + this->SelfIntersection.setStatus(App::Property::Status::Hidden, true); + this->Mode.setValue(1); //switch to Pipe mode by default, because skin mode does not function properly on closed profiles. +} + +Offset2D::~Offset2D() +{ + +} + +short Offset2D::mustExecute() const +{ + if (Source.isTouched()) + return 1; + if (Value.isTouched()) + return 1; + if (Mode.isTouched()) + return 1; + if (Join.isTouched()) + return 1; + if (Fill.isTouched()) + return 1; + if (Intersection.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *Offset2D::execute(void) +{ + App::DocumentObject* source = Source.getValue(); + if (!(source && source->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))) + return new App::DocumentObjectExecReturn("No source shape linked."); + double offset = Value.getValue(); + short mode = (short)Mode.getValue(); + short join = (short)Join.getValue(); + bool fill = Fill.getValue(); + bool inter = Intersection.getValue(); + if (mode == 2) + return new App::DocumentObjectExecReturn("Mode 'Recto-Verso' is not supported for 2D offset."); + const TopoShape& shape = static_cast(source)->Shape.getShape(); + this->Shape.setValue(shape.makeOffset2D(offset, join, fill, mode == 0, inter)); + return App::DocumentObject::StdReturn; +} diff --git a/src/Mod/Part/App/FeatureOffset.h b/src/Mod/Part/App/FeatureOffset.h index 8a2daff49..b00fcdd31 100644 --- a/src/Mod/Part/App/FeatureOffset.h +++ b/src/Mod/Part/App/FeatureOffset.h @@ -61,5 +61,23 @@ private: static const char* JoinEnums[]; }; +class PartExport Offset2D : public Offset +{ + PROPERTY_HEADER(Part::Offset2D); +public: + Offset2D(); + ~Offset2D(); + + /** @name methods override feature */ + //@{ + /// recalculate the feature + virtual App::DocumentObjectExecReturn *execute(void) override; + virtual short mustExecute() const override; + virtual const char* getViewProviderName(void) const override { + return "PartGui::ViewProviderOffset2D"; + } + //@} +}; + } #endif // PART_FEATUREOFFSET_H diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index bae44f7ae..450c52b54 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -150,6 +150,7 @@ PyMODINIT_FUNC initPartGui() PartGui::ViewProviderLoft ::init(); PartGui::ViewProviderSweep ::init(); PartGui::ViewProviderOffset ::init(); + PartGui::ViewProviderOffset2D ::init(); PartGui::ViewProviderThickness ::init(); PartGui::ViewProviderCustom ::init(); PartGui::ViewProviderCustomPython ::init(); diff --git a/src/Mod/Part/Gui/ViewProviderMirror.cpp b/src/Mod/Part/Gui/ViewProviderMirror.cpp index 60a6f422e..26ff1e6d0 100644 --- a/src/Mod/Part/Gui/ViewProviderMirror.cpp +++ b/src/Mod/Part/Gui/ViewProviderMirror.cpp @@ -581,6 +581,11 @@ bool ViewProviderOffset::onDelete(const std::vector &) return true; } +// --------------------------------------- + +PROPERTY_SOURCE(PartGui::ViewProviderOffset2D, PartGui::ViewProviderOffset) + + // --------------------------------------- PROPERTY_SOURCE(PartGui::ViewProviderThickness, PartGui::ViewProviderPart) diff --git a/src/Mod/Part/Gui/ViewProviderMirror.h b/src/Mod/Part/Gui/ViewProviderMirror.h index 802ffcc94..793210439 100644 --- a/src/Mod/Part/Gui/ViewProviderMirror.h +++ b/src/Mod/Part/Gui/ViewProviderMirror.h @@ -163,6 +163,16 @@ protected: virtual void unsetEdit(int ModNum); }; +class ViewProviderOffset2D : public ViewProviderOffset +{ + PROPERTY_HEADER(PartGui::ViewProviderOffset2D); + +public: + ViewProviderOffset2D(){ + sPixmap = "Part_Offset2D"; + } +}; + class ViewProviderThickness : public ViewProviderPart { PROPERTY_HEADER(PartGui::ViewProviderThickness);