+ support loading projects with old pad features, fix critical bug where the unit gets replaced
This commit is contained in:
parent
22f3f85584
commit
e9b275c7e6
|
@ -57,34 +57,24 @@ TYPESYSTEM_SOURCE(App::PropertyQuantity, App::PropertyFloat);
|
|||
|
||||
Base::Quantity PropertyQuantity::getQuantityValue(void) const
|
||||
{
|
||||
return Quantity( _dValue,_Unit);
|
||||
}
|
||||
|
||||
void PropertyQuantity::setValue(const Base::Quantity &quant)
|
||||
{
|
||||
aboutToSetValue();
|
||||
_dValue = quant.getValue();
|
||||
_Unit = quant.getUnit();
|
||||
hasSetValue();
|
||||
return Quantity(_dValue,_Unit);
|
||||
}
|
||||
|
||||
const char* PropertyQuantity::getEditorName(void) const
|
||||
{
|
||||
|
||||
{
|
||||
return "Gui::PropertyEditor::PropertyUnitItem";
|
||||
|
||||
}
|
||||
|
||||
PyObject *PropertyQuantity::getPyObject(void)
|
||||
{
|
||||
return new QuantityPy (new Quantity( _dValue,_Unit));
|
||||
return new QuantityPy (new Quantity(_dValue,_Unit));
|
||||
}
|
||||
|
||||
void PropertyQuantity::setPyObject(PyObject *value)
|
||||
{
|
||||
Base::Quantity quant;
|
||||
Base::Quantity quant;
|
||||
|
||||
if (PyString_Check(value))
|
||||
if (PyString_Check(value))
|
||||
quant = Quantity::parse(QString::fromLatin1(PyString_AsString(value)));
|
||||
else if (PyFloat_Check(value))
|
||||
quant = Quantity(PyFloat_AsDouble(value),_Unit);
|
||||
|
@ -92,20 +82,21 @@ void PropertyQuantity::setPyObject(PyObject *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
|
||||
quant = *(pcObject->getQuantityPtr());
|
||||
}
|
||||
else
|
||||
throw Base::Exception("Wrong type!");
|
||||
|
||||
Unit unit = quant.getUnit();
|
||||
if(unit.isEmpty()){
|
||||
Unit unit = quant.getUnit();
|
||||
if (unit.isEmpty()){
|
||||
PropertyFloat::setValue(quant.getValue());
|
||||
return;
|
||||
}
|
||||
|
||||
if (unit != _Unit)
|
||||
throw Base::Exception("Not matching Unit!");
|
||||
return;
|
||||
}
|
||||
|
||||
PropertyFloat::setValue(quant.getValue());
|
||||
if (unit != _Unit)
|
||||
throw Base::Exception("Not matching Unit!");
|
||||
|
||||
PropertyFloat::setValue(quant.getValue());
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
|
|
|
@ -50,23 +50,23 @@ namespace App
|
|||
class AppExport PropertyQuantity : public PropertyFloat
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
|
||||
public:
|
||||
PropertyQuantity(void){}
|
||||
virtual ~PropertyQuantity(){}
|
||||
|
||||
void setValue(const Base::Quantity& quant);
|
||||
|
||||
Base::Quantity getQuantityValue(void) const;
|
||||
Base::Quantity getQuantityValue(void) const;
|
||||
|
||||
virtual const char* getEditorName(void) const;
|
||||
|
||||
virtual PyObject *getPyObject(void);
|
||||
virtual void setPyObject(PyObject *);
|
||||
|
||||
void setUnit(const Base::Unit &u){_Unit = u;}
|
||||
const Base::Unit &getUnit(void)const{return _Unit;}
|
||||
void setUnit(const Base::Unit &u) {_Unit = u;}
|
||||
const Base::Unit &getUnit(void) const {return _Unit;}
|
||||
|
||||
protected:
|
||||
Base::Unit _Unit;
|
||||
Base::Unit _Unit;
|
||||
};
|
||||
|
||||
/** Distance property
|
||||
|
|
|
@ -38,7 +38,7 @@ PROPERTY_SOURCE(Fem::FemResultObject, App::DocumentObject)
|
|||
FemResultObject::FemResultObject()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(DataType,(""), "General",Prop_None,"Type identifier of the result data");
|
||||
ADD_PROPERTY_TYPE(Unit,(Base::Quantity()), "General",Prop_None,"Unit of the data");
|
||||
ADD_PROPERTY_TYPE(Unit,(0), "General",Prop_None,"Unit of the data");
|
||||
ADD_PROPERTY_TYPE(ElementNumbers,(0), "Data",Prop_None,"Numbers of the result elements");
|
||||
ADD_PROPERTY_TYPE(Mesh,(0), "General",Prop_None,"Link to the corosbonding mesh");
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Placement.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Reader.h>
|
||||
#include <App/Document.h>
|
||||
|
||||
#include "FeaturePad.h"
|
||||
|
@ -75,6 +77,42 @@ short Pad::mustExecute() const
|
|||
return Additive::mustExecute();
|
||||
}
|
||||
|
||||
void Pad::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
reader.readElement("Properties");
|
||||
int Cnt = reader.getAttributeAsInteger("Count");
|
||||
|
||||
for (int i=0 ;i<Cnt ;i++) {
|
||||
reader.readElement("Property");
|
||||
const char* PropName = reader.getAttribute("name");
|
||||
const char* TypeName = reader.getAttribute("type");
|
||||
App::Property* prop = getPropertyByName(PropName);
|
||||
|
||||
try {
|
||||
if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) {
|
||||
prop->Restore(reader);
|
||||
}
|
||||
else if (prop && strcmp(TypeName,"App::PropertyLength") == 0 &&
|
||||
strcmp(prop->getTypeId().getName(), "App::PropertyQuantity") == 0) {
|
||||
App::PropertyLength p;
|
||||
p.Restore(reader);
|
||||
static_cast<App::PropertyQuantity*>(prop)->setValue(p.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());
|
||||
}
|
||||
reader.readEndElement("Property");
|
||||
}
|
||||
reader.readEndElement("Properties");
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *Pad::execute(void)
|
||||
{
|
||||
// Validate parameters
|
||||
|
|
|
@ -66,6 +66,10 @@ public:
|
|||
return "PartDesignGui::ViewProviderPad";
|
||||
}
|
||||
//@}
|
||||
|
||||
protected:
|
||||
void Restore(Base::XMLReader &reader);
|
||||
|
||||
private:
|
||||
static const char* TypeEnums[];
|
||||
//static const char* SideEnums[];
|
||||
|
|
Loading…
Reference in New Issue
Block a user