Sketcher: Changed return type of Constraint::getPresentationValue() to Quantity, to be able to include unit.

This commit is contained in:
Eivind Kvedalen 2016-06-14 01:13:33 +02:00 committed by wmayer
parent 171fce7b19
commit 7afcb4beda
4 changed files with 12 additions and 19 deletions

View File

@ -133,20 +133,20 @@ double Constraint::getValue() const
return Value;
}
double Constraint::getPresentationValue() const
Quantity Constraint::getPresentationValue() const
{
switch (Type) {
case Distance:
case Radius:
return Value;
return Quantity(Value, Unit::Length);
case DistanceX:
case DistanceY:
if (FirstPos == Sketcher::none || Second != Sketcher::Constraint::GeoUndef)
return Value;
return Quantity(Value, Unit::Length);
else
return Value;
return Quantity(Value, Unit::Length);
case Angle:
return Base::toDegrees<double>(Value);
return Quantity(toDegrees<double>(Value), Unit::Angle);
case SnellsLaw:
return Value;
default:

View File

@ -26,6 +26,7 @@
#include <Base/Persistence.h>
#include <Base/Quantity.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
@ -89,7 +90,7 @@ public:
virtual PyObject *getPyObject(void);
void setValue(double newValue);
double getPresentationValue() const;
Base::Quantity getPresentationValue() const;
double getValue() const;
friend class Sketch;

View File

@ -123,22 +123,14 @@ public:
case Sketcher::Symmetric:
break;
case Sketcher::Distance:
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity(constraint->getPresentationValue(),Base::Unit::Length).getUserString());
break;
case Sketcher::DistanceX:
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity(constraint->getPresentationValue(),Base::Unit::Length).getUserString());
break;
case Sketcher::DistanceY:
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity(constraint->getPresentationValue(),Base::Unit::Length).getUserString());
break;
case Sketcher::Radius:
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity(constraint->getPresentationValue(),Base::Unit::Length).getUserString());
break;
case Sketcher::Angle:
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity(constraint->getPresentationValue(),Base::Unit::Angle).getUserString());
name = QString::fromLatin1("%1 (%2)").arg(name).arg(constraint->getPresentationValue().getUserString());
break;
case Sketcher::SnellsLaw: {
double v = constraint->getPresentationValue();
double v = constraint->getPresentationValue().getValue();
double n1 = 1.0;
double n2 = 1.0;
if (fabs(v) >= 1) {

View File

@ -3526,7 +3526,7 @@ Restart:
break;
SoDatumLabel *asciiText = dynamic_cast<SoDatumLabel *>(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL));
asciiText->string = SbString(Base::Quantity(Constr->getPresentationValue(),Base::Unit::Length).getUserString().toUtf8().constData());
asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData());
if (Constr->Type == Distance)
asciiText->datumtype = SoDatumLabel::DISTANCE;
@ -3825,7 +3825,7 @@ Restart:
break;
SoDatumLabel *asciiText = dynamic_cast<SoDatumLabel *>(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL));
asciiText->string = SbString(Base::Quantity(Constr->getPresentationValue(),Base::Unit::Angle).getUserString().toUtf8().constData());
asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData());
asciiText->datumtype = SoDatumLabel::ANGLE;
asciiText->param1 = Constr->LabelDistance;
asciiText->param2 = startangle;
@ -3879,7 +3879,7 @@ Restart:
SbVec3f p2(pnt2.x,pnt2.y,zConstr);
SoDatumLabel *asciiText = dynamic_cast<SoDatumLabel *>(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL));
asciiText->string = SbString(Base::Quantity(Constr->getPresentationValue(),Base::Unit::Length).getUserString().toUtf8().constData());
asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData());
asciiText->datumtype = SoDatumLabel::RADIUS;
asciiText->param1 = Constr->LabelDistance;