Some fixes for PropertyEnumeration:
+ when reading an enumeration ignore negative indexes and print a warning + raise an exception when trying to get the current value of an invalid enumeration
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Writer.h>
|
||||
@@ -356,6 +357,8 @@ bool PropertyEnumeration::isPartOf(const char *value) const
|
||||
|
||||
const char * PropertyEnumeration::getValueAsString(void) const
|
||||
{
|
||||
if (!_enum.isValid())
|
||||
throw Base::RuntimeError("Cannot get value from invalid enumeration");
|
||||
return _enum.getCStr();
|
||||
}
|
||||
|
||||
@@ -415,6 +418,11 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader)
|
||||
_enum.setEnums(values);
|
||||
}
|
||||
|
||||
if (val < 0) {
|
||||
Base::Console().Warning("Enumeration index %d is out of range, ignore it\n", val);
|
||||
val = getValue();
|
||||
}
|
||||
|
||||
setValue(val);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user