[PD] disallow invalid polar and linear pattern settings

as discussed in 423d41da19 we should disallow invalid property settings
This commit is contained in:
donovaly
2021-03-02 03:24:15 +01:00
committed by wmayer
parent 6d02284b81
commit 20024707a9
4 changed files with 44 additions and 6 deletions

View File

@@ -49,12 +49,15 @@ namespace PartDesign {
PROPERTY_SOURCE(PartDesign::LinearPattern, PartDesign::Transformed)
const App::PropertyIntegerConstraint::Constraints intOccurrences = { 1, INT_MAX, 1 };
LinearPattern::LinearPattern()
{
ADD_PROPERTY_TYPE(Direction,(0),"LinearPattern",(App::PropertyType)(App::Prop_None),"Direction");
ADD_PROPERTY(Reversed,(0));
ADD_PROPERTY(Length,(100.0));
ADD_PROPERTY(Occurrences,(3));
Occurrences.setConstraints(&intOccurrences);
}
short LinearPattern::mustExecute() const
@@ -187,4 +190,16 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
return transformations;
}
void LinearPattern::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop)
// transforms properties that had been changed
{
// property Occurrences had the App::PropertyInteger and was changed to App::PropertyIntegerConstraint
if (prop == &Occurrences && strcmp(TypeName, "App::PropertyInteger") == 0) {
App::PropertyInteger OccurrencesProperty;
// restore the PropertyInteger to be able to set its value
OccurrencesProperty.Restore(reader);
Occurrences.setValue(OccurrencesProperty.getValue());
}
}
}

View File

@@ -41,7 +41,7 @@ public:
App::PropertyLinkSub Direction;
App::PropertyBool Reversed;
App::PropertyLength Length;
App::PropertyInteger Occurrences;
App::PropertyIntegerConstraint Occurrences;
/** @name methods override feature */
//@{
@@ -63,6 +63,9 @@ public:
* If Reversed is true, the direction of transformation will be opposite
*/
const std::list<gp_Trsf> getTransformations(const std::vector<App::DocumentObject*> );
protected:
virtual void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop);
};
} //namespace PartDesign

View File

@@ -48,12 +48,17 @@ namespace PartDesign {
PROPERTY_SOURCE(PartDesign::PolarPattern, PartDesign::Transformed)
const App::PropertyIntegerConstraint::Constraints intOccurrences = { 1, INT_MAX, 1 };
const App::PropertyAngle::Constraints floatAngle = { Base::toDegrees<double>(Precision::Angular()), 360.0, 1.0 };
PolarPattern::PolarPattern()
{
ADD_PROPERTY_TYPE(Axis,(0),"PolarPattern",(App::PropertyType)(App::Prop_None),"Direction");
ADD_PROPERTY(Reversed,(0));
ADD_PROPERTY(Angle,(360.0));
ADD_PROPERTY(Occurrences,(3));
ADD_PROPERTY_TYPE(Axis, (0), "PolarPattern", (App::PropertyType)(App::Prop_None), "Direction");
ADD_PROPERTY(Reversed, (0));
ADD_PROPERTY(Angle, (360.0));
Angle.setConstraints(&floatAngle);
ADD_PROPERTY(Occurrences, (3));
Occurrences.setConstraints(&intOccurrences);
}
short PolarPattern::mustExecute() const
@@ -173,4 +178,16 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
return transformations;
}
void PolarPattern::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop)
// transforms properties that had been changed
{
// property Occurrences had the App::PropertyInteger and was changed to App::PropertyIntegerConstraint
if (prop == &Occurrences && strcmp(TypeName, "App::PropertyInteger") == 0) {
App::PropertyInteger OccurrencesProperty;
// restore the PropertyInteger to be able to set its value
OccurrencesProperty.Restore(reader);
Occurrences.setValue(OccurrencesProperty.getValue());
}
}
}

View File

@@ -42,7 +42,7 @@ public:
App::PropertyLinkSub Axis;
App::PropertyBool Reversed;
App::PropertyAngle Angle;
App::PropertyInteger Occurrences;
App::PropertyIntegerConstraint Occurrences;
/** @name methods override feature */
//@{
@@ -65,6 +65,9 @@ public:
* If Reversed is true, the direction of rotation will be opposite.
*/
const std::list<gp_Trsf> getTransformations(const std::vector<App::DocumentObject*>);
protected:
virtual void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop);
};
} //namespace PartDesign