From eb87a20f8ba0fe97fb551332894465f47da3ccda Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 18 Sep 2017 12:06:24 +0200 Subject: [PATCH] use constraint to limit minimum and maximum degree --- src/Mod/Part/App/PartFeatures.cpp | 4 ++++ src/Mod/Part/App/PartFeatures.h | 5 ++++- src/Mod/Part/App/TopoShape.cpp | 22 ++++++++++++---------- src/Mod/Part/App/TopoShape.h | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index ba06aedf11..b3ca6c658f 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -29,6 +29,7 @@ # include # include # include +# include # include # include # include @@ -256,6 +257,8 @@ App::DocumentObjectExecReturn *RuledSurface::execute(void) // ---------------------------------------------------------------------------- +App::PropertyIntegerConstraint::Constraints Loft::Degrees = {2,Geom_BSplineSurface::MaxDegree(),1}; + PROPERTY_SOURCE(Part::Loft, Part::Feature) Loft::Loft() @@ -266,6 +269,7 @@ Loft::Loft() ADD_PROPERTY_TYPE(Ruled,(false),"Loft",App::Prop_None,"Ruled surface"); ADD_PROPERTY_TYPE(Closed,(false),"Loft",App::Prop_None,"Close Last to First Profile"); ADD_PROPERTY_TYPE(MaxDegree,(5),"Loft",App::Prop_None,"Maximum Degree"); + MaxDegree.setConstraints(&Degrees); } short Loft::mustExecute() const diff --git a/src/Mod/Part/App/PartFeatures.h b/src/Mod/Part/App/PartFeatures.h index d93b591ef1..0852a88c3d 100644 --- a/src/Mod/Part/App/PartFeatures.h +++ b/src/Mod/Part/App/PartFeatures.h @@ -73,7 +73,7 @@ public: App::PropertyBool Solid; App::PropertyBool Ruled; App::PropertyBool Closed; - App::PropertyInteger MaxDegree; + App::PropertyIntegerConstraint MaxDegree; /** @name methods override feature */ //@{ @@ -87,6 +87,9 @@ public: protected: void onChanged (const App::Property* prop); + +private: + static App::PropertyIntegerConstraint::Constraints Degrees; }; class Sweep : public Part::Feature diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 22df23a20e..c377ac0e0c 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -2090,11 +2090,11 @@ TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, Standard_Boolean isRuled, Standard_Boolean isClosed, - Standard_Integer MaxDegree) const + Standard_Integer maxDegree) const { // http://opencascade.blogspot.com/2010/01/surface-modeling-part5.html BRepOffsetAPI_ThruSections aGenerator (isSolid,isRuled); - aGenerator.SetMaxDegree(MaxDegree); + aGenerator.SetMaxDegree(maxDegree); TopTools_ListIteratorOfListOfShape it; int countShapes = 0; @@ -2116,7 +2116,8 @@ TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, } if (countShapes < 2) { - Standard_Failure::Raise("Need at least two vertices, edges or wires to create loft face"); } + Standard_Failure::Raise("Need at least two vertices, edges or wires to create loft face"); + } else { // close loft by duplicating initial profile as last profile. not perfect. if (isClosed) { @@ -2125,8 +2126,9 @@ TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, - V1-W1-W2-W3 ==> V1-W1-W2-W3-V1 valid closed - W1-W2-W3-V1 ==> W1-W2-W3-V1-W1 invalid closed - W1-W2-W3 ==> W1-W2-W3-W1 valid closed*/ - if (profiles.Last().ShapeType() == TopAbs_VERTEX) { - Base::Console().Message("TopoShape::makeLoft: can't close Loft with Vertex as last profile. 'Closed' ignored.\n"); } + if (profiles.Last().ShapeType() == TopAbs_VERTEX) { + Base::Console().Message("TopoShape::makeLoft: can't close Loft with Vertex as last profile. 'Closed' ignored.\n"); + } else { // repeat Add logic above for first profile const TopoDS_Shape& firstProfile = profiles.First(); @@ -2135,12 +2137,12 @@ TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, countShapes++; } else if (firstProfile.ShapeType() == TopAbs_EDGE) { - aGenerator.AddWire(TopoDS::Wire (firstProfile)); - countShapes++; + aGenerator.AddWire(TopoDS::Wire (firstProfile)); + countShapes++; } else if (firstProfile.ShapeType() == TopAbs_WIRE) { - aGenerator.AddWire(TopoDS::Wire (firstProfile)); - countShapes++; + aGenerator.AddWire(TopoDS::Wire (firstProfile)); + countShapes++; } } } @@ -2151,7 +2153,7 @@ TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, aGenerator.Build(); if (!aGenerator.IsDone()) Standard_Failure::Raise("Failed to create loft face"); - + //Base::Console().Message("DEBUG: TopoShape::makeLoft returns.\n"); return aGenerator.Shape(); } diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index b657ec8715..8f97f4dd9d 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -208,7 +208,7 @@ public: TopoDS_Shape makeThread(Standard_Real pitch, Standard_Real depth, Standard_Real height, Standard_Real radius) const; TopoDS_Shape makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, - Standard_Boolean isRuled, Standard_Boolean isClosed = Standard_False, Standard_Integer MaxDegree = 5) const; + Standard_Boolean isRuled, Standard_Boolean isClosed = Standard_False, Standard_Integer maxDegree = 5) const; TopoDS_Shape makeOffsetShape(double offset, double tol, bool intersection = false, bool selfInter = false, short offsetMode = 0, short join = 0, bool fill = false) const;