diff --git a/src/App/Application.cpp b/src/App/Application.cpp index f8c5f079ad..9b093ce973 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1004,11 +1004,14 @@ void Application::initTypes(void) App ::PropertyFloatList ::init(); App ::PropertyFloatConstraint ::init(); App ::PropertyQuantity ::init(); + App ::PropertyQuantityConstraint::init(); App ::PropertyAngle ::init(); App ::PropertyDistance ::init(); App ::PropertyLength ::init(); App ::PropertySpeed ::init(); App ::PropertyAcceleration ::init(); + App ::PropertyForce ::init(); + App ::PropertyPressure ::init(); App ::PropertyInteger ::init(); App ::PropertyIntegerConstraint ::init(); App ::PropertyPercent ::init(); diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index 8b294d39d3..ae9849baf0 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -50,7 +50,7 @@ using namespace std; //************************************************************************** //************************************************************************** -// PropertyFloatUnit +// PropertyQuantity //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TYPESYSTEM_SOURCE(App::PropertyQuantity, App::PropertyFloat); @@ -99,26 +99,98 @@ void PropertyQuantity::setPyObject(PyObject *value) PropertyFloat::setValue(quant.getValue()); } +//************************************************************************** +//************************************************************************** +// PropertyQuantityConstraint +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyQuantityConstraint, App::PropertyQuantity); + + + +void PropertyQuantityConstraint::setConstraints(const Constraints* sConstrain) +{ + _ConstStruct = sConstrain; +} + +const PropertyQuantityConstraint::Constraints* PropertyQuantityConstraint::getConstraints(void) const +{ + return _ConstStruct; +} + +void PropertyQuantityConstraint::setPyObject(PyObject *value) +{ + Base::Quantity quant; + + if (PyString_Check(value)) + quant = Quantity::parse(QString::fromLatin1(PyString_AsString(value))); + else if (PyFloat_Check(value)) + quant = Quantity(PyFloat_AsDouble(value),_Unit); + else if (PyInt_Check(value)) + quant = Quantity((double)PyInt_AsLong(value),_Unit); + else if (PyObject_TypeCheck(value, &(QuantityPy::Type))) { + Base::QuantityPy *pcObject = static_cast(value); + quant = *(pcObject->getQuantityPtr()); + } + else + throw Base::Exception("Wrong type!"); + + Unit unit = quant.getUnit(); + double temp = quant.getValue(); + if (_ConstStruct) { + if (temp > _ConstStruct->UpperBound) + temp = _ConstStruct->UpperBound; + else if (temp < _ConstStruct->LowerBound) + temp = _ConstStruct->LowerBound; + } + quant.setValue(temp); + + if (unit.isEmpty()){ + PropertyFloat::setValue(quant.getValue()); + return; + } + + if (unit != _Unit) + throw Base::Exception("Not matching Unit!"); + + PropertyFloat::setValue(quant.getValue()); +} + //************************************************************************** //************************************************************************** // PropertyDistance //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TYPESYSTEM_SOURCE(App::PropertyDistance, App::PropertyFloat); +TYPESYSTEM_SOURCE(App::PropertyDistance, App::PropertyQuantity); + +PropertyDistance::PropertyDistance() +{ + setUnit(Base::Unit::Length); +} //************************************************************************** //************************************************************************** // PropertySpeed //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TYPESYSTEM_SOURCE(App::PropertySpeed, App::PropertyFloat); +TYPESYSTEM_SOURCE(App::PropertySpeed, App::PropertyQuantity); + +PropertySpeed::PropertySpeed() +{ + setUnit(Base::Unit::Velocity); +} //************************************************************************** //************************************************************************** // PropertyAcceleration //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TYPESYSTEM_SOURCE(App::PropertyAcceleration, App::PropertyFloat); +TYPESYSTEM_SOURCE(App::PropertyAcceleration, App::PropertyQuantity); + +PropertyAcceleration::PropertyAcceleration() +{ + setUnit(Base::Unit::Acceleration); +} //************************************************************************** //************************************************************************** @@ -137,8 +209,34 @@ PropertyLength::PropertyLength() // PropertyAngle //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TYPESYSTEM_SOURCE(App::PropertyAngle, App::PropertyFloatConstraint); +TYPESYSTEM_SOURCE(App::PropertyAngle, App::PropertyQuantityConstraint); +PropertyAngle::PropertyAngle() +{ + setUnit(Base::Unit::Angle); +} +//************************************************************************** +//************************************************************************** +// PropertyPressure +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +TYPESYSTEM_SOURCE(App::PropertyPressure, App::PropertyQuantity); + +PropertyPressure::PropertyPressure() +{ + setUnit(Base::Unit::Pressure); +} + +//************************************************************************** +//************************************************************************** +// PropertyForce +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyForce, App::PropertyQuantity); + +PropertyForce::PropertyForce() +{ + setUnit(Base::Unit::Force); +} diff --git a/src/App/PropertyUnits.h b/src/App/PropertyUnits.h index 4cf8a5d1b8..f82f97f73a 100644 --- a/src/App/PropertyUnits.h +++ b/src/App/PropertyUnits.h @@ -69,18 +69,56 @@ protected: Base::Unit _Unit; }; +/** Float with Unit property + * This is a property for float with a predefined Unit associated . + */ +class AppExport PropertyQuantityConstraint : public PropertyQuantity +{ + TYPESYSTEM_HEADER(); + +public: + PropertyQuantityConstraint(void){} + virtual ~PropertyQuantityConstraint(){} + + /// Constraint methods + //@{ + /// the boundary struct + struct Constraints { + double LowerBound, UpperBound, StepSize; + }; + /** setting the boundaries + * This sets the constraint struct. It can be dynamically + * allocated or set as an static in the class the property + * blongs to: + * \code + * const Constraints percent = {0.0,100.0,1.0} + * \endcode + */ + void setConstraints(const Constraints* sConstrain); + /// get the constraint struct + const Constraints* getConstraints(void) const; + //@} + + virtual const char* getEditorName(void) const + { return "Gui::PropertyEditor::PropertyFloatConstraintItem"; } + + virtual void setPyObject(PyObject *); + + +protected: + const Constraints* _ConstStruct; +}; + /** Distance property * This is a property for representing distances. It is basically a float * property. On the Gui it has a quantity like m or mm. */ -class AppExport PropertyDistance: public App::PropertyFloat +class AppExport PropertyDistance: public PropertyQuantity { TYPESYSTEM_HEADER(); public: - PropertyDistance(void){} + PropertyDistance(void); virtual ~PropertyDistance(){} - virtual const char* getEditorName(void) const - { return "Gui::PropertyEditor::PropertyFloatItem"; } }; /** Length property @@ -99,11 +137,11 @@ public: * This is a property for representing angles. It basicly a float * property. On the Gui it has a quantity like RAD. */ -class AppExport PropertyAngle: public PropertyFloatConstraint -{ +class AppExport PropertyAngle: public PropertyQuantityConstraint +{ TYPESYSTEM_HEADER(); public: - PropertyAngle(void){} + PropertyAngle(void); virtual ~PropertyAngle(){} virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyAngleItem"; } }; @@ -112,11 +150,11 @@ public: * This is a property for representing speed. It is basically a float * property. On the Gui it has a quantity like m/s or km/h. */ -class AppExport PropertySpeed: public PropertyFloat +class AppExport PropertySpeed: public PropertyQuantity { TYPESYSTEM_HEADER(); public: - PropertySpeed(void){} + PropertySpeed(void); virtual ~PropertySpeed(){} virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; } }; @@ -125,15 +163,41 @@ public: * This is a property for representing acceleration. It is basically a float * property. On the Gui it has a quantity like m/s^2. */ -class AppExport PropertyAcceleration: public PropertyFloat +class AppExport PropertyAcceleration: public PropertyQuantity { TYPESYSTEM_HEADER(); public: - PropertyAcceleration(void){} + PropertyAcceleration(void); virtual ~PropertyAcceleration(){} virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; } }; +/** Pressure property + * This is a property for representing acceleration. It is basically a float + * property. On the Gui it has a quantity like m/s^2. + */ +class AppExport PropertyPressure: public PropertyQuantity +{ + TYPESYSTEM_HEADER(); +public: + PropertyPressure(void); + virtual ~PropertyPressure(){} + virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; } +}; + +/** Force property + * This is a property for representing acceleration. It is basically a float + * property. On the Gui it has a quantity like m/s^2. + */ +class AppExport PropertyForce: public PropertyQuantity +{ + TYPESYSTEM_HEADER(); +public: + PropertyForce(void); + virtual ~PropertyForce(){} + virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyFloatItem"; } +}; + } // namespace App diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index f8cefb6caf..f17660755a 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -779,7 +779,7 @@ PropertyAngleItem::PropertyAngleItem() void PropertyAngleItem::setEditorData(QWidget *editor, const QVariant& data) const { - const App::PropertyFloatConstraint::Constraints* c = 0; + const App::PropertyQuantityConstraint::Constraints* c = 0; const std::vector& items = getPropertyData(); if (!items.empty()) { App::PropertyAngle* prop = static_cast(items[0]); diff --git a/src/Mod/Part/App/FeaturePartCircle.cpp b/src/Mod/Part/App/FeaturePartCircle.cpp index dc793909db..6b522dd763 100644 --- a/src/Mod/Part/App/FeaturePartCircle.cpp +++ b/src/Mod/Part/App/FeaturePartCircle.cpp @@ -34,7 +34,7 @@ using namespace Part; -App::PropertyFloatConstraint::Constraints Circle::angleRange = {0.0,360.0,1.0}; +App::PropertyQuantityConstraint::Constraints Circle::angleRange = {0.0,360.0,1.0}; PROPERTY_SOURCE(Part::Circle, Part::Primitive) diff --git a/src/Mod/Part/App/FeaturePartCircle.h b/src/Mod/Part/App/FeaturePartCircle.h index 15dab6d75b..c8f5fe41a0 100644 --- a/src/Mod/Part/App/FeaturePartCircle.h +++ b/src/Mod/Part/App/FeaturePartCircle.h @@ -53,7 +53,7 @@ public: } private: - static App::PropertyFloatConstraint::Constraints angleRange; + static App::PropertyQuantityConstraint::Constraints angleRange; //@} }; diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 927a710309..d594b82df1 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -969,7 +969,7 @@ void Wedge::onChanged(const App::Property* prop) Part::Primitive::onChanged(prop); } -App::PropertyFloatConstraint::Constraints Ellipse::angleRange = {0.0,360.0,1.0}; +App::PropertyQuantityConstraint::Constraints Ellipse::angleRange = {0.0,360.0,1.0}; PROPERTY_SOURCE(Part::Ellipse, Part::Primitive) diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 7dd6a35964..baef52df58 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -411,7 +411,7 @@ public: //@} private: - static App::PropertyFloatConstraint::Constraints angleRange; + static App::PropertyQuantityConstraint::Constraints angleRange; }; } //namespace Part