[PD] disallow invalid polar and linear pattern settings
as discussed in 423d41da19 we should disallow invalid property settings
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user