Skip to content

Commit

Permalink
switch the physical Properties to Quantity and add Pressure and Force
Browse files Browse the repository at this point in the history
  • Loading branch information
jriegel committed Feb 16, 2014
1 parent 587f6b2 commit 0fbe570
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/App/Application.cpp
Expand Up @@ -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();
Expand Down
108 changes: 103 additions & 5 deletions src/App/PropertyUnits.cpp
Expand Up @@ -50,7 +50,7 @@ using namespace std;

//**************************************************************************
//**************************************************************************
// PropertyFloatUnit
// PropertyQuantity
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

TYPESYSTEM_SOURCE(App::PropertyQuantity, App::PropertyFloat);
Expand Down Expand Up @@ -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);
}

//**************************************************************************
//**************************************************************************
Expand All @@ -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);
}

86 changes: 75 additions & 11 deletions src/App/PropertyUnits.h
Expand Up @@ -69,18 +69,56 @@ class AppExport PropertyQuantity : public PropertyFloat
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
Expand All @@ -99,11 +137,11 @@ class AppExport PropertyLength : public PropertyQuantity
* 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"; }
};
Expand All @@ -112,11 +150,11 @@ class AppExport PropertyAngle: public PropertyFloatConstraint
* 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"; }
};
Expand All @@ -125,15 +163,41 @@ class AppExport PropertySpeed: public PropertyFloat
* 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

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Part/App/FeaturePartCircle.cpp
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Part/App/FeaturePartCircle.h
Expand Up @@ -53,7 +53,7 @@ class Circle : public Part::Primitive
}

private:
static App::PropertyFloatConstraint::Constraints angleRange;
static App::PropertyQuantityConstraint::Constraints angleRange;
//@}
};

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Part/App/PrimitiveFeature.cpp
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Part/App/PrimitiveFeature.h
Expand Up @@ -411,7 +411,7 @@ class Ellipse : public Part::Primitive
//@}

private:
static App::PropertyFloatConstraint::Constraints angleRange;
static App::PropertyQuantityConstraint::Constraints angleRange;
};

} //namespace Part
Expand Down

0 comments on commit 0fbe570

Please sign in to comment.