PartDesign: Fixed similar issue compared to #2302 with unit handling when using an expression for the chamfer size.

This commit is contained in:
Eivind Kvedalen
2015-10-25 21:56:53 +01:00
committed by wmayer
parent 533514e8d3
commit e72dc31954
2 changed files with 46 additions and 2 deletions

View File

@@ -32,6 +32,8 @@
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#endif
#include <Base/Console.h>
#include <Base/Reader.h>
#include <Mod/Part/App/TopoShape.h>
#include "FeatureChamfer.h"
@@ -42,11 +44,12 @@ using namespace PartDesign;
PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp)
const App::PropertyFloatConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1};
const App::PropertyQuantityConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1};
Chamfer::Chamfer()
{
ADD_PROPERTY(Size,(1.0));
Size.setUnit(Base::Unit::Length);
Size.setConstraints(&floatSize);
}
@@ -109,3 +112,39 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
void Chamfer::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::PropertyFloatConstraint") == 0 &&
strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) {
App::PropertyFloatConstraint p;
p.Restore(reader);
static_cast<App::PropertyQuantityConstraint*>(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");
}