Skip to content

Commit

Permalink
Some fixes for PropertyEnumeration:
Browse files Browse the repository at this point in the history
+ 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
  • Loading branch information
wwmayer committed Jun 9, 2018
1 parent 5ea2114 commit 8f19b46
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/App/PropertyStandard.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 8f19b46

Please sign in to comment.