From 1f6174e3f2511eefbf380416a58f2b88042606a2 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Fri, 2 Sep 2016 00:39:59 +0300 Subject: [PATCH] Part: Offset feature: split off into separate file withdrew code from PartFeatures.h/.cpp and created FeatureOffset.h/.cpp --- src/Mod/Part/App/AppPart.cpp | 1 + src/Mod/Part/App/CMakeLists.txt | 2 + src/Mod/Part/App/FeatureOffset.cpp | 95 +++++++++++++++++++++++++ src/Mod/Part/App/FeatureOffset.h | 65 +++++++++++++++++ src/Mod/Part/App/PartFeatures.cpp | 63 ---------------- src/Mod/Part/App/PartFeatures.h | 31 -------- src/Mod/Part/Gui/TaskOffset.cpp | 2 +- src/Mod/Part/Gui/ViewProviderMirror.cpp | 1 + 8 files changed, 165 insertions(+), 95 deletions(-) create mode 100644 src/Mod/Part/App/FeatureOffset.cpp create mode 100644 src/Mod/Part/App/FeatureOffset.h diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 3b63ea1d5..5b1efee33 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -49,6 +49,7 @@ #include "FeatureFillet.h" #include "FeatureMirroring.h" #include "FeatureRevolution.h" +#include "FeatureOffset.h" #include "PartFeatures.h" #include "BodyBase.h" #include "PrimitiveFeature.h" diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index a788d1484..4e101b76c 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -124,6 +124,8 @@ SET(Features_SRCS FeatureMirroring.h FeatureRevolution.cpp FeatureRevolution.h + FeatureOffset.cpp + FeatureOffset.h PartFeatures.cpp PartFeatures.h PartFeature.cpp diff --git a/src/Mod/Part/App/FeatureOffset.cpp b/src/Mod/Part/App/FeatureOffset.cpp new file mode 100644 index 000000000..7d3a736ec --- /dev/null +++ b/src/Mod/Part/App/FeatureOffset.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright (c) 2016 Victor Titov (DeepSOIC) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + + +#include "FeatureOffset.h" + + +using namespace Part; + +const char* Part::Offset::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL}; +const char* Part::Offset::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL}; + +PROPERTY_SOURCE(Part::Offset, Part::Feature) + +Offset::Offset() +{ + ADD_PROPERTY_TYPE(Source,(0),"Offset",App::Prop_None,"Source shape"); + ADD_PROPERTY_TYPE(Value,(1.0),"Offset",App::Prop_None,"Offset value"); + ADD_PROPERTY_TYPE(Mode,(long(0)),"Offset",App::Prop_None,"Mode"); + Mode.setEnums(ModeEnums); + ADD_PROPERTY_TYPE(Join,(long(0)),"Offset",App::Prop_None,"Join type"); + Join.setEnums(JoinEnums); + ADD_PROPERTY_TYPE(Intersection,(false),"Offset",App::Prop_None,"Intersection"); + ADD_PROPERTY_TYPE(SelfIntersection,(false),"Offset",App::Prop_None,"Self Intersection"); + ADD_PROPERTY_TYPE(Fill,(false),"Offset",App::Prop_None,"Fill offset"); +} + +Offset::~Offset() +{ + +} + +short Offset::mustExecute() const +{ + if (Source.isTouched()) + return 1; + if (Value.isTouched()) + return 1; + if (Mode.isTouched()) + return 1; + if (Join.isTouched()) + return 1; + if (Intersection.isTouched()) + return 1; + if (SelfIntersection.isTouched()) + return 1; + if (Fill.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *Offset::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(); + double tol = Precision::Confusion(); + bool inter = Intersection.getValue(); + bool self = SelfIntersection.getValue(); + short mode = (short)Mode.getValue(); + short join = (short)Join.getValue(); + bool fill = Fill.getValue(); + const TopoShape& shape = static_cast(source)->Shape.getShape(); + if (fabs(offset) > 2*tol) + this->Shape.setValue(shape.makeOffsetShape(offset, tol, inter, self, mode, join, fill)); + else + this->Shape.setValue(shape); + return App::DocumentObject::StdReturn; +} + + diff --git a/src/Mod/Part/App/FeatureOffset.h b/src/Mod/Part/App/FeatureOffset.h new file mode 100644 index 000000000..8a2daff49 --- /dev/null +++ b/src/Mod/Part/App/FeatureOffset.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2016 Victor Titov (DeepSOIC) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef PART_FEATUREOFFSET_H +#define PART_FEATUREOFFSET_H + +#include +#include +#include + +namespace Part +{ + +class PartExport Offset : public Part::Feature +{ + PROPERTY_HEADER(Part::Offset); + +public: + Offset(); + ~Offset(); + + App::PropertyLink Source; + App::PropertyFloat Value; + App::PropertyEnumeration Mode; + App::PropertyEnumeration Join; + App::PropertyBool Intersection; + App::PropertyBool SelfIntersection; + App::PropertyBool Fill; + + /** @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::ViewProviderOffset"; + } + //@} + +private: + static const char* ModeEnums[]; + static const char* JoinEnums[]; +}; + +} +#endif // PART_FEATUREOFFSET_H diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index d06122ac1..163febc0e 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -476,69 +476,6 @@ App::DocumentObjectExecReturn *Sweep::execute(void) // ---------------------------------------------------------------------------- -const char* Part::Offset::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL}; -const char* Part::Offset::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL}; - -PROPERTY_SOURCE(Part::Offset, Part::Feature) - -Offset::Offset() -{ - ADD_PROPERTY_TYPE(Source,(0),"Offset",App::Prop_None,"Source shape"); - ADD_PROPERTY_TYPE(Value,(1.0),"Offset",App::Prop_None,"Offset value"); - ADD_PROPERTY_TYPE(Mode,(long(0)),"Offset",App::Prop_None,"Mode"); - Mode.setEnums(ModeEnums); - ADD_PROPERTY_TYPE(Join,(long(0)),"Offset",App::Prop_None,"Join type"); - Join.setEnums(JoinEnums); - ADD_PROPERTY_TYPE(Intersection,(false),"Offset",App::Prop_None,"Intersection"); - ADD_PROPERTY_TYPE(SelfIntersection,(false),"Offset",App::Prop_None,"Self Intersection"); - ADD_PROPERTY_TYPE(Fill,(false),"Offset",App::Prop_None,"Fill offset"); -} - -Offset::~Offset() -{ -} - -short Offset::mustExecute() const -{ - if (Source.isTouched()) - return 1; - if (Value.isTouched()) - return 1; - if (Mode.isTouched()) - return 1; - if (Join.isTouched()) - return 1; - if (Intersection.isTouched()) - return 1; - if (SelfIntersection.isTouched()) - return 1; - if (Fill.isTouched()) - return 1; - return 0; -} - -App::DocumentObjectExecReturn *Offset::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(); - double tol = Precision::Confusion(); - bool inter = Intersection.getValue(); - bool self = SelfIntersection.getValue(); - short mode = (short)Mode.getValue(); - short join = (short)Join.getValue(); - bool fill = Fill.getValue(); - const TopoShape& shape = static_cast(source)->Shape.getShape(); - if (fabs(offset) > 2*tol) - this->Shape.setValue(shape.makeOffsetShape(offset, tol, inter, self, mode, join, fill)); - else - this->Shape.setValue(shape); - return App::DocumentObject::StdReturn; -} - -// ---------------------------------------------------------------------------- - const char* Part::Thickness::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL}; const char* Part::Thickness::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL}; diff --git a/src/Mod/Part/App/PartFeatures.h b/src/Mod/Part/App/PartFeatures.h index 60de836f6..41f951c57 100644 --- a/src/Mod/Part/App/PartFeatures.h +++ b/src/Mod/Part/App/PartFeatures.h @@ -115,37 +115,6 @@ private: static const char* TransitionEnums[]; }; -class Offset : public Part::Feature -{ - PROPERTY_HEADER(Part::Offset); - -public: - Offset(); - ~Offset(); - - App::PropertyLink Source; - App::PropertyFloat Value; - App::PropertyEnumeration Mode; - App::PropertyEnumeration Join; - App::PropertyBool Intersection; - App::PropertyBool SelfIntersection; - App::PropertyBool Fill; - - /** @name methods override feature */ - //@{ - /// recalculate the feature - App::DocumentObjectExecReturn *execute(void); - short mustExecute() const; - const char* getViewProviderName(void) const { - return "PartGui::ViewProviderOffset"; - } - //@} - -private: - static const char* ModeEnums[]; - static const char* JoinEnums[]; -}; - class Thickness : public Part::Feature { PROPERTY_HEADER(Part::Thickness); diff --git a/src/Mod/Part/Gui/TaskOffset.cpp b/src/Mod/Part/Gui/TaskOffset.cpp index 097273352..91cdc8b15 100644 --- a/src/Mod/Part/Gui/TaskOffset.cpp +++ b/src/Mod/Part/Gui/TaskOffset.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include using namespace PartGui; diff --git a/src/Mod/Part/Gui/ViewProviderMirror.cpp b/src/Mod/Part/Gui/ViewProviderMirror.cpp index 2307a12ae..60a6f422e 100644 --- a/src/Mod/Part/Gui/ViewProviderMirror.cpp +++ b/src/Mod/Part/Gui/ViewProviderMirror.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include