- ResultPtr anOwner = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
- std::shared_ptr<Model_ResultBody> aParent = std::dynamic_pointer_cast<Model_ResultBody>(
- ModelAPI_Tools::bodyOwner(anOwner));
-
- myLastConcealed = ModelAPI_ResultBody::isConcealed(); // set new value and check parent
- if (myLastConcealed) { // this becomes concealed, so, update all: parent and children
- if (aParent.get())
- aParent->updateConcealment();
- static Events_ID EVENT_DISP =
- Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
- ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
- std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
- for (; aSubIter != mySubs.cend(); aSubIter++) {
- std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
- }
- } else {
- // ask parent: if it is still concealed, nothing is changed
- if (aParent.get()) {
- aParent->updateConcealment();
- if (aParent->isConcealed()) {
- myLastConcealed = true;
- return;
- }
- }
- // iterate children: if they are concealed, nothing is changed
- bool aChildConcealed = false;
- std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
- for (; aSubIter != mySubs.cend(); aSubIter++) {
- std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
- if ((*aSubIter)->isConcealed()) {
- aChildConcealed = true;
- break;
- }
- }
- if (aChildConcealed) { // some child is concealed, so, update back
- myLastConcealed = true;
- if (aParent.get())
- aParent->updateConcealment();
- std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
- for (; aSubIter != mySubs.cend(); aSubIter++) {
- std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
+ // check the whole tree of results: if one is concealed, everybody are concealed
+ ResultBodyPtr anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(data()->owner());
+ if (!anOwner.get())
+ return; // "this" is invalid
+ ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(anOwner);
+ while(aParent.get()) {
+ anOwner = aParent;
+ aParent = ModelAPI_Tools::bodyOwner(anOwner);
+ }
+ // iterate all results and collect all results whose state may be updated
+ std::list<ResultBodyPtr> anUpdated;
+ bool aNewFlag = !myLastConcealed;
+ if (checkAllSubs(anOwner, aNewFlag, anUpdated)) { // state of everyone must be updated
+ std::list<ResultBodyPtr>::iterator aRes = anUpdated.begin();
+ for(; aRes != anUpdated.end(); aRes++) {
+ bool aLastConcealed = (*aRes)->isConcealed();
+ if (aNewFlag != aLastConcealed) {
+ std::dynamic_pointer_cast<Model_ResultBody>(*aRes)->myLastConcealed = aNewFlag;
+ if (aNewFlag) { // become concealed, behaves like removed
+ ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
+ } else { // become not-concealed, behaves like created
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(*aRes, anEvent);
+ }
+ static Events_ID EVENT_DISP = // must be redisplayed in any case
+ Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(*aRes, EVENT_DISP);