The macro generates a setter that sets a data member to the required value and sends out a ModifiedEvent.
The problem with this is that there is no way to block sending out the event. Imagine that you want to re-initialise an object, but there are observers listening to its 'Modified' events already. Let's suppose that re-initialising the object involves setting several of its members. Since you cannot block the modified events, there will be one event sent out after each call of a setter, which results that the observers will be notified after each step of the initialisation.
This is seriously wrong for several reasons.
First, the observers will do an update two many times. This can make the application significantly slower if e.g. the cascade of events ends in updating all the render windows (mitk::RenderingManager::GetInstance()->RequestUpdateAll() ).
Second, the observers are notified when the initialisation of the object has not finished, and it is inconsistent or invalid state. The observers react to this state, and all sorts of nasty things can happen. I am just debugging a crash that is caused by this. The image navigator is listening to the modification of the steppers. It receives a signal when some property of the stepper has been set but the renderer did not get its geometry yet. I have seen many other crashes like this.
Currently, the only way to resolve the crash is to put a nullptr check in the image navigator code to check if the renderer has a valid geometry. However, this makes the code of the image navigator more complicated, although the actual problem is not there. The modified event should not have been sent out until the initialisation has finished, and after the initialisation, it should have been sent out only one time.
A basic solution would be to replace the itkSetMacro-s by regular setters that only do an equality check but do not send out signals. You could call Modified() when you finish modifying an object. However, this does not handle the case when Modified() is called somewhere down the call stack.
The proper solution would be to introduce a function to block / unblock events, a bit similarly as Qt does with signals. Then, there would be a new macro, mitkSetMacro, that would be like itkSetMacro but it would send out the modified event only if the events are not blocked. If the events are blocked, it would just put it in a queue, and the event would be sent out when the events are unblocked. (One event per type.)
Usage would look like this:
mitk::Stepper* stepper = ... bool wereBlocked = stepper->BlockEvents(true); set all the things you want... stepper->BlockEvents(wereBlocked);
Optionally, BlockEvents could have an argument, what kind of events you want to block or unblock, that could default to itk::AnyEvent().