Hi everyone,
When using mitk::EnumerationProperty I noticed some behaviour that I did not
expect.
I was using mitk::EnumerationProperty to assign dynamic enumeration properties
to specific nodes in my application like this:
auto prop = qilin::EnumerationProperty::New();
prop ->AddEnum("Apple", 0);
prop ->AddEnum("Pear", 1);
prop ->AddEnum("Orange", 2);
node->SetProperty("Fruit", prop);
I figured this was alright since in the documentation of
mitk::EnumerationProperty it reads:
* To use the class enumeration property you have 2 choices:
*
* 1. Directly use the class and add your possible enumeration values via
* AddEnum(name, id). NOte that the ids do not have to be in any order,
they
* just have to be unique. The current value is set via SetValue(...) and
* retrieved via GetValueAsId() or GetValueAsString().
However, this only works as long as a single instance of
mitk::EnumerationProperty exists.
If multiple custom enumeration properties do exist, the instances affect each
other by changing the enumeration values.
I looked up the implementation of mitk::EnumerationProperty and found the cause
there:
The maps for the enumeration Ids and Strings are associated to the class name
(GetNameOfClass) of the instance and stored in a static map member.
This way, all instances of mitk::EnumerationProperty share the same maps for
ids and strings and changing one instance will affect all the others.
I feel like this is inconsistent with the documentation.
Also I'm not sure of how to work around this issue since the GetMemberEnumIds
and GetMemberEnumStrings methods are not declared virtual. Deriving from
mitk::EnumerationProperty for each enumeration type won't work either since I
do work with dynamic enumeration types (they depend on imported data). I can
think of a workaround that overloads GetNameOfClass and returns some UUID, but
that does not seem like a proper solution either (also the data would never get
deleted from the static member map). I could implement my own
EnumerationProperty, but this way the Property Editor won't be able to show the
dropdown for the enumeration (still, it's the best solution I can think of so
far).
Maybe I missed something, but in my opinion the design of
mitk::EnumerationProperty is misleading and should be changed.
Kind regards
Bertram
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
mitk-users mailing list
mitk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mitk-users