PartDesign: Fixed issue #2302 with unit handling when using an expression for the fillet radius.

This commit is contained in:
Eivind Kvedalen 2015-10-25 21:48:39 +01:00 committed by wmayer
parent dff58e5df3
commit acd0f6a79e
2 changed files with 46 additions and 2 deletions

View File

@ -29,6 +29,8 @@
# include <TopoDS_Edge.hxx>
#endif
#include <Base/Console.h>
#include <Base/Reader.h>
#include <Mod/Part/App/TopoShape.h>
#include "FeatureFillet.h"
@ -39,11 +41,12 @@ using namespace PartDesign;
PROPERTY_SOURCE(PartDesign::Fillet, PartDesign::DressUp)
const App::PropertyFloatConstraint::Constraints floatRadius = {0.0,FLT_MAX,0.1};
const App::PropertyQuantityConstraint::Constraints floatRadius = {0.0,FLT_MAX,0.1};
Fillet::Fillet()
{
ADD_PROPERTY(Radius,(1.0));
Radius.setUnit(Base::Unit::Length);
Radius.setConstraints(&floatRadius);
}
@ -100,3 +103,39 @@ App::DocumentObjectExecReturn *Fillet::execute(void)
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
void Fillet::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");
}

View File

@ -25,6 +25,7 @@
#define PARTDESIGN_FEATUREFILLET_H
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include <App/PropertyLinks.h>
#include "FeatureDressUp.h"
@ -38,7 +39,7 @@ class PartDesignExport Fillet : public DressUp
public:
Fillet();
App::PropertyFloatConstraint Radius;
App::PropertyQuantityConstraint Radius;
/** @name methods override feature */
//@{
@ -50,6 +51,10 @@ public:
return "PartDesignGui::ViewProviderFillet";
}
//@}
protected:
void Restore(Base::XMLReader &reader);
};
} //namespace Part