switch the physical Properties to Quantity and add Pressure and Force

This commit is contained in:
jriegel 2014-02-16 17:59:29 +01:00
parent 587f6b220b
commit 0fbe570f9e
8 changed files with 186 additions and 21 deletions

View File

@ -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();

View File

@ -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<Base::QuantityPy*>(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);
}

View File

@ -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

View File

@ -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<App::Property*>& items = getPropertyData();
if (!items.empty()) {
App::PropertyAngle* prop = static_cast<App::PropertyAngle*>(items[0]);

View File

@ -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)

View File

@ -53,7 +53,7 @@ public:
}
private:
static App::PropertyFloatConstraint::Constraints angleRange;
static App::PropertyQuantityConstraint::Constraints angleRange;
//@}
};

View File

@ -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)

View File

@ -411,7 +411,7 @@ public:
//@}
private:
static App::PropertyFloatConstraint::Constraints angleRange;
static App::PropertyQuantityConstraint::Constraints angleRange;
};
} //namespace Part