[PD] set constraints for helix properties

at the moment it is possible by a click to set e.g. -1 turn which would cause an error
This commit is contained in:
donovaly
2021-03-03 01:44:06 +01:00
committed by wwmayer
parent ed01a60cf0
commit fc36ab6c64
2 changed files with 36 additions and 22 deletions

View File

@@ -71,24 +71,29 @@ const char* Helix::ModeEnums[] = {"pitch-height", "pitch-turns", "height-turns",
PROPERTY_SOURCE(PartDesign::Helix, PartDesign::ProfileBased)
// we purposely use not FLT_MAX because this would not be computable
const App::PropertyFloatConstraint::Constraints floatTurns = { Precision::Confusion(), INT_MAX, 1.0 };
const App::PropertyAngle::Constraints floatAngle = { -89.0, 89.0, 1.0 };
Helix::Helix()
{
addSubType = FeatureAddSub::Additive;
ADD_PROPERTY_TYPE(Base,(Base::Vector3d(0.0,0.0,0.0)),"Helix", App::Prop_ReadOnly, "Base");
ADD_PROPERTY_TYPE(Axis,(Base::Vector3d(0.0,1.0,0.0)),"Helix", App::Prop_ReadOnly, "Axis");
ADD_PROPERTY_TYPE(Pitch,(10.),"Helix", App::Prop_None, "Pitch");
ADD_PROPERTY_TYPE(Height,(30.0),"Helix", App::Prop_None, "Height");
ADD_PROPERTY_TYPE(Turns,(3.0),"Helix", App::Prop_None, "Turns");
ADD_PROPERTY_TYPE(LeftHanded,(long(0)),"Helix", App::Prop_None, "LeftHanded");
ADD_PROPERTY_TYPE(Reversed,(long(0)),"Helix", App::Prop_None, "Reversed");
ADD_PROPERTY_TYPE(Angle,(0.0),"Helix", App::Prop_None, "Angle");
ADD_PROPERTY_TYPE(ReferenceAxis,(0),"Helix", App::Prop_None, "Reference axis of revolution");
ADD_PROPERTY_TYPE(Base, (Base::Vector3d(0.0, 0.0, 0.0)), "Helix", App::Prop_ReadOnly, "Base");
ADD_PROPERTY_TYPE(Axis, (Base::Vector3d(0.0, 1.0, 0.0)), "Helix", App::Prop_ReadOnly, "Axis");
ADD_PROPERTY_TYPE(Pitch, (10.), "Helix", App::Prop_None, "Pitch");
ADD_PROPERTY_TYPE(Height, (30.0), "Helix", App::Prop_None, "Height");
ADD_PROPERTY_TYPE(Turns, (3.0), "Helix", App::Prop_None, "Turns");
Turns.setConstraints(&floatTurns);
ADD_PROPERTY_TYPE(LeftHanded, (long(0)), "Helix", App::Prop_None, "LeftHanded");
ADD_PROPERTY_TYPE(Reversed, (long(0)), "Helix", App::Prop_None, "Reversed");
ADD_PROPERTY_TYPE(Angle, (0.0), "Helix", App::Prop_None, "Angle");
Angle.setConstraints(&floatAngle);
ADD_PROPERTY_TYPE(ReferenceAxis, (0), "Helix", App::Prop_None, "Reference axis of revolution");
ADD_PROPERTY_TYPE(Mode, (long(0)), "Helix", App::Prop_None, "Helix input mode");
ADD_PROPERTY_TYPE(Outside,(long(0)),"Helix", App::Prop_None, "Outside");
ADD_PROPERTY_TYPE(HasBeenEdited,(long(0)),"Helix", App::Prop_None, "HasBeenEdited");
ADD_PROPERTY_TYPE(Outside, (long(0)), "Helix", App::Prop_None, "Outside");
ADD_PROPERTY_TYPE(HasBeenEdited, (long(0)), "Helix", App::Prop_None, "HasBeenEdited");
Mode.setEnums(ModeEnums);
}
short Helix::mustExecute() const
@@ -146,7 +151,7 @@ App::DocumentObjectExecReturn *Helix::execute(void)
//We would need a method to translate the front shape to match the shell starting position somehow...
TopoDS_Face face = TopoDS::Face(sketchshape);
BRepAdaptor_Surface adapt(face);
if(adapt.GetType() != GeomAbs_Plane)
if (adapt.GetType() != GeomAbs_Plane)
return new App::DocumentObjectExecReturn("Error: Face must be planar");
}
@@ -159,7 +164,6 @@ App::DocumentObjectExecReturn *Helix::execute(void)
base = TopoDS_Shape();
}
// update Axis from ReferenceAxis
try {
updateAxis();
@@ -248,7 +252,7 @@ App::DocumentObjectExecReturn *Helix::execute(void)
}
}
if(!mkSolid.IsDone())
if (!mkSolid.IsDone())
return new App::DocumentObjectExecReturn("Error: Result is not a solid");
TopoDS_Shape result = mkSolid.Shape();
@@ -260,7 +264,7 @@ App::DocumentObjectExecReturn *Helix::execute(void)
AddSubShape.setValue(result);
if(base.IsNull()) {
if (base.IsNull()) {
if (getAddSubType() == FeatureAddSub::Subtractive)
return new App::DocumentObjectExecReturn("Error: There is nothing to subtract\n");
@@ -273,7 +277,7 @@ App::DocumentObjectExecReturn *Helix::execute(void)
return App::DocumentObject::StdReturn;
}
if(getAddSubType() == FeatureAddSub::Additive) {
if (getAddSubType() == FeatureAddSub::Additive) {
BRepAlgoAPI_Fuse mkFuse(base, result);
if (!mkFuse.IsDone())
@@ -293,7 +297,7 @@ App::DocumentObjectExecReturn *Helix::execute(void)
boolOp = refineShapeIfActive(boolOp);
Shape.setValue(getSolid(boolOp));
}
else if(getAddSubType() == FeatureAddSub::Subtractive) {
else if (getAddSubType() == FeatureAddSub::Subtractive) {
TopoDS_Shape boolOp;
@@ -337,8 +341,6 @@ App::DocumentObjectExecReturn *Helix::execute(void)
}
}
void Helix::updateAxis(void)
{
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
@@ -351,7 +353,6 @@ void Helix::updateAxis(void)
Axis.setValue(dir.x,dir.y,dir.z);
}
TopoDS_Shape Helix::generateHelixPath(void)
{
double pitch = Pitch.getValue();
@@ -496,6 +497,16 @@ Base::Vector3d Helix::getProfileCenterPoint()
return Base::Vector3d(0.5*(xmin+xmax), 0.5*(ymin+ymax), 0.5*(zmin+zmax));
}
void Helix::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop)
{
// property Turns had the App::PropertyFloat and was changed to App::PropertyFloatConstraint
if (prop == &Turns && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat TurnsProperty;
// restore the PropertyFloat to be able to set its value
TurnsProperty.Restore(reader);
Turns.setValue(TurnsProperty.getValue());
}
}
PROPERTY_SOURCE(PartDesign::AdditiveHelix, PartDesign::Helix)
AdditiveHelix::AdditiveHelix() {

View File

@@ -42,7 +42,7 @@ public:
App::PropertyVector Axis;
App::PropertyLength Pitch;
App::PropertyLength Height;
App::PropertyFloat Turns;
App::PropertyFloatConstraint Turns;
App::PropertyBool LeftHanded;
App::PropertyAngle Angle;
App::PropertyEnumeration Mode;
@@ -80,6 +80,9 @@ protected:
// center of profile bounding box
Base::Vector3d getProfileCenterPoint();
// handle changed property
virtual void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop);
private:
static const char* ModeEnums[];
};