diff --git a/src/Mod/Part/App/FeaturePartCircle.h b/src/Mod/Part/App/FeaturePartCircle.h index c8f5fe41a02a..dc9400204a7d 100644 --- a/src/Mod/Part/App/FeaturePartCircle.h +++ b/src/Mod/Part/App/FeaturePartCircle.h @@ -37,7 +37,7 @@ class Circle : public Part::Primitive Circle(); virtual ~Circle(); - App::PropertyFloat Radius; + App::PropertyLength Radius; App::PropertyAngle Angle0; App::PropertyAngle Angle1; diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 5e357fe72484..676e68cafac2 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -63,6 +63,9 @@ #include "PrimitiveFeature.h" +#include +#include +#include #include #ifndef M_PI @@ -71,11 +74,11 @@ namespace Part { - const App::PropertyFloatConstraint::Constraints floatRange = {0.0,FLT_MAX,0.1}; - const App::PropertyFloatConstraint::Constraints apexRange = {0.0,90.0,0.1}; - const App::PropertyFloatConstraint::Constraints angleRangeU = {0.0,360.0,1.0}; - const App::PropertyFloatConstraint::Constraints angleRangeV = {-90.0,90.0,1.0}; - const App::PropertyFloatConstraint::Constraints torusRangeV = {-180.0,180.0,1.0}; + const App::PropertyQuantityConstraint::Constraints apexRange = {0.0,90.0,0.1}; + const App::PropertyQuantityConstraint::Constraints torusRangeV = {-180.0,180.0,1.0}; + const App::PropertyQuantityConstraint::Constraints angleRangeU = {0.0,360.0,1.0}; + const App::PropertyQuantityConstraint::Constraints angleRangeV = {-90.0,90.0,1.0}; + const App::PropertyQuantityConstraint::Constraints quantityRange = {0.0,FLT_MAX,0.1}; } using namespace Part; @@ -97,6 +100,60 @@ short Primitive::mustExecute(void) const return Feature::mustExecute(); } +void Primitive::Restore(Base::XMLReader &reader) +{ + reader.readElement("Properties"); + int Cnt = reader.getAttributeAsInteger("Count"); + + for (int i=0 ;igetTypeId().getName(), TypeName) == 0) { + prop->Restore(reader); + } + else if (prop) { + Base::Type inputType = Base::Type::fromName(TypeName); + if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) && + inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) { + // Do not directly call the property's Restore method in case the implmentation + // has changed. So, create a temporary PropertyFloat object and assign the value. + App::PropertyFloat floatProp; + floatProp.Restore(reader); + static_cast(prop)->setValue(floatProp.getValue()); + } + } + } + catch (const Base::XMLParseException&) { + throw; // re-throw + } + catch (const Base::Exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const std::exception &e) { + Base::Console().Error("%s\n", e.what()); + } + catch (const char* e) { + Base::Console().Error("%s\n", e); + } +#ifndef FC_DEBUG + catch (...) { + Base::Console().Error("Primitive::Restore: Unknown C++ exception thrown"); + } +#endif + + reader.readEndElement("Property"); + } + reader.readEndElement("Properties"); +} + void Primitive::onChanged(const App::Property* prop) { if (!isRestoring()) { @@ -307,7 +364,7 @@ PROPERTY_SOURCE(Part::Sphere, Part::Primitive) Sphere::Sphere(void) { ADD_PROPERTY_TYPE(Radius,(5.0),"Sphere",App::Prop_None,"The radius of the sphere"); - Radius.setConstraints(&floatRange); + Radius.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Angle1,(-90.0f),"Sphere",App::Prop_None,"The angle of the sphere"); Angle1.setConstraints(&angleRangeV); ADD_PROPERTY_TYPE(Angle2,(90.0f),"Sphere",App::Prop_None,"The angle of the sphere"); @@ -355,11 +412,11 @@ PROPERTY_SOURCE(Part::Ellipsoid, Part::Primitive) Ellipsoid::Ellipsoid(void) { ADD_PROPERTY_TYPE(Radius1,(2.0),"Ellipsoid",App::Prop_None,"The radius of the ellipsoid"); - Radius1.setConstraints(&floatRange); + Radius1.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Radius2,(4.0),"Ellipsoid",App::Prop_None,"The radius of the ellipsoid"); - Radius2.setConstraints(&floatRange); + Radius2.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Radius3,(0.0),"Ellipsoid",App::Prop_None,"The radius of the ellipsoid"); - Radius3.setConstraints(&floatRange); + Radius3.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Angle1,(-90.0f),"Ellipsoid",App::Prop_None,"The angle of the ellipsoid"); Angle1.setConstraints(&angleRangeV); ADD_PROPERTY_TYPE(Angle2,(90.0f),"Ellipsoid",App::Prop_None,"The angle of the ellipsoid"); @@ -640,9 +697,9 @@ PROPERTY_SOURCE(Part::Torus, Part::Primitive) Torus::Torus(void) { ADD_PROPERTY_TYPE(Radius1,(10.0),"Torus",App::Prop_None,"The radius of the torus"); - Radius1.setConstraints(&floatRange); + Radius1.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Radius2,(2.0),"Torus",App::Prop_None,"The radius of the torus"); - Radius2.setConstraints(&floatRange); + Radius2.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Angle1,(-180.0),"Torus",App::Prop_None,"The angle of the torus"); Angle1.setConstraints(&torusRangeV); ADD_PROPERTY_TYPE(Angle2,(180.0),"Torus",App::Prop_None,"The angle of the torus"); @@ -715,11 +772,11 @@ const char* Part::Helix::StyleEnums []= {"Old style","New style",NULL}; Helix::Helix(void) { ADD_PROPERTY_TYPE(Pitch, (1.0),"Helix",App::Prop_None,"The pitch of the helix"); - Pitch.setConstraints(&floatRange); + Pitch.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Height,(2.0),"Helix",App::Prop_None,"The height of the helix"); - Height.setConstraints(&floatRange); + Height.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Radius,(1.0),"Helix",App::Prop_None,"The radius of the helix"); - Radius.setConstraints(&floatRange); + Radius.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Angle,(0.0),"Helix",App::Prop_None,"If angle is > 0 a conical otherwise a cylindircal surface is used"); Angle.setConstraints(&apexRange); ADD_PROPERTY_TYPE(LocalCoord,(long(0)),"Coordinate System",App::Prop_None,"Orientation of the local coordinate system of the helix"); @@ -793,11 +850,11 @@ PROPERTY_SOURCE(Part::Spiral, Part::Primitive) Spiral::Spiral(void) { ADD_PROPERTY_TYPE(Growth, (1.0),"Spiral",App::Prop_None,"The growth of the spiral per rotation"); - Growth.setConstraints(&floatRange); + Growth.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Radius,(1.0),"Spiral",App::Prop_None,"The radius of the spiral"); - Radius.setConstraints(&floatRange); + Radius.setConstraints(&quantityRange); ADD_PROPERTY_TYPE(Rotations,(2.0),"Spiral",App::Prop_None,"The number of rotations"); - Rotations.setConstraints(&floatRange); + Rotations.setConstraints(&quantityRange); } void Spiral::onChanged(const App::Property* prop) diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 3440579c5fad..f548146f6db4 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -46,6 +46,7 @@ class PartExport Primitive : public Part::Feature //@} protected: + void Restore(Base::XMLReader &reader); void onChanged (const App::Property* prop); }; @@ -57,9 +58,9 @@ class PartExport Vertex : public Part::Primitive Vertex(); virtual ~Vertex(); - App::PropertyFloat X; - App::PropertyFloat Y; - App::PropertyFloat Z; + App::PropertyDistance X; + App::PropertyDistance Y; + App::PropertyDistance Z; /** @name methods override feature */ //@{ @@ -82,12 +83,12 @@ class PartExport Line : public Part::Primitive Line(); virtual ~Line(); - App::PropertyFloat X1; - App::PropertyFloat Y1; - App::PropertyFloat Z1; - App::PropertyFloat X2; - App::PropertyFloat Y2; - App::PropertyFloat Z2; + App::PropertyDistance X1; + App::PropertyDistance Y1; + App::PropertyDistance Z1; + App::PropertyDistance X2; + App::PropertyDistance Y2; + App::PropertyDistance Z2; /** @name methods override feature */ //@{ @@ -131,10 +132,10 @@ class PartExport Sphere : public Primitive public: Sphere(); - App::PropertyFloatConstraint Radius; - App::PropertyFloatConstraint Angle1; - App::PropertyFloatConstraint Angle2; - App::PropertyFloatConstraint Angle3; + App::PropertyLength Radius; + App::PropertyAngle Angle1; + App::PropertyAngle Angle2; + App::PropertyAngle Angle3; /** @name methods override feature */ //@{ @@ -155,12 +156,12 @@ class PartExport Ellipsoid : public Primitive public: Ellipsoid(); - App::PropertyFloatConstraint Radius1; - App::PropertyFloatConstraint Radius2; - App::PropertyFloatConstraint Radius3; - App::PropertyFloatConstraint Angle1; - App::PropertyFloatConstraint Angle2; - App::PropertyFloatConstraint Angle3; + App::PropertyLength Radius1; + App::PropertyLength Radius2; + App::PropertyLength Radius3; + App::PropertyAngle Angle1; + App::PropertyAngle Angle2; + App::PropertyAngle Angle3; /** @name methods override feature */ //@{ @@ -182,7 +183,7 @@ class PartExport Cylinder : public Primitive App::PropertyLength Radius; App::PropertyLength Height; - App::PropertyFloatConstraint Angle; + App::PropertyAngle Angle; /** @name methods override feature */ //@{ @@ -255,7 +256,7 @@ class PartExport Cone : public Primitive App::PropertyLength Radius1; App::PropertyLength Radius2; App::PropertyLength Height; - App::PropertyFloatConstraint Angle; + App::PropertyAngle Angle; /** @name methods override feature */ //@{ @@ -276,11 +277,11 @@ class PartExport Torus : public Primitive public: Torus(); - App::PropertyFloatConstraint Radius1; - App::PropertyFloatConstraint Radius2; - App::PropertyFloatConstraint Angle1; - App::PropertyFloatConstraint Angle2; - App::PropertyFloatConstraint Angle3; + App::PropertyLength Radius1; + App::PropertyLength Radius2; + App::PropertyAngle Angle1; + App::PropertyAngle Angle2; + App::PropertyAngle Angle3; /** @name methods override feature */ //@{ @@ -301,10 +302,10 @@ class PartExport Helix : public Primitive public: Helix(); - App::PropertyFloatConstraint Pitch; - App::PropertyFloatConstraint Height; - App::PropertyFloatConstraint Radius; - App::PropertyFloatConstraint Angle; + App::PropertyLength Pitch; + App::PropertyLength Height; + App::PropertyLength Radius; + App::PropertyAngle Angle; App::PropertyEnumeration LocalCoord; App::PropertyEnumeration Style; @@ -334,9 +335,9 @@ class PartExport Spiral : public Primitive public: Spiral(); - App::PropertyFloatConstraint Growth; - App::PropertyFloatConstraint Rotations; - App::PropertyFloatConstraint Radius; + App::PropertyLength Growth; + App::PropertyLength Rotations; + App::PropertyLength Radius; /** @name methods override feature */ //@{ @@ -360,16 +361,16 @@ class PartExport Wedge : public Primitive public: Wedge(); - App::PropertyFloat Xmin; - App::PropertyFloat Ymin; - App::PropertyFloat Zmin; - App::PropertyFloat Z2min; - App::PropertyFloat X2min; - App::PropertyFloat Xmax; - App::PropertyFloat Ymax; - App::PropertyFloat Zmax; - App::PropertyFloat Z2max; - App::PropertyFloat X2max; + App::PropertyDistance Xmin; + App::PropertyDistance Ymin; + App::PropertyDistance Zmin; + App::PropertyDistance Z2min; + App::PropertyDistance X2min; + App::PropertyDistance Xmax; + App::PropertyDistance Ymax; + App::PropertyDistance Zmax; + App::PropertyDistance Z2max; + App::PropertyDistance X2max; /** @name methods override feature */ //@{ @@ -394,8 +395,8 @@ class Ellipse : public Part::Primitive Ellipse(); virtual ~Ellipse(); - App::PropertyFloat MajorRadius; - App::PropertyFloat MinorRadius; + App::PropertyLength MajorRadius; + App::PropertyLength MinorRadius; App::PropertyAngle Angle0; App::PropertyAngle Angle1; diff --git a/src/Mod/Part/Gui/DlgExtrusion.cpp b/src/Mod/Part/Gui/DlgExtrusion.cpp index cdc168652c3a..8e1c34df0277 100644 --- a/src/Mod/Part/Gui/DlgExtrusion.cpp +++ b/src/Mod/Part/Gui/DlgExtrusion.cpp @@ -62,7 +62,7 @@ DlgExtrusion::DlgExtrusion(QWidget* parent, Qt::WFlags fl) ui->dirY->setDecimals(Base::UnitsApi::getDecimals()); ui->dirZ->setDecimals(Base::UnitsApi::getDecimals()); ui->dirLen->setDecimals(Base::UnitsApi::getDecimals()); - ui->taperAngle->setDecimals(Base::UnitsApi::getDecimals()); + ui->taperAngle->setUnit(Base::Unit::Angle); ui->dirLen->setMinimumWidth(55); // needed to show all digits findShapes(); @@ -182,7 +182,7 @@ void DlgExtrusion::apply() double dirX = ui->dirX->value(); double dirY = ui->dirY->value(); double dirZ = ui->dirZ->value(); - double angle = ui->taperAngle->value(); + double angle = ui->taperAngle->value().getValue(); bool makeSolid = ui->makeSolid->isChecked(); // inspect geometry diff --git a/src/Mod/Part/Gui/DlgExtrusion.ui b/src/Mod/Part/Gui/DlgExtrusion.ui index b3485461c204..a3d6cd30077e 100644 --- a/src/Mod/Part/Gui/DlgExtrusion.ui +++ b/src/Mod/Part/Gui/DlgExtrusion.ui @@ -197,7 +197,7 @@ - + -180.000000000000000 @@ -244,6 +244,13 @@ + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
treeWidget dirX