1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Result.cpp
4 // Created: 07 Jul 2014
5 // Author: Mikhail PONIKAROV
7 #include "ModelAPI_Result.h"
8 #include <ModelAPI_Events.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Attribute.h>
11 #include <Events_Loop.h>
13 ModelAPI_Result::~ModelAPI_Result()
17 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
19 if (myIsDisabled != theFlag) {
20 myIsDisabled = theFlag;
21 data()->setIsDeleted(theFlag); // store it in data model (t oget back on undo/redo, etc)
22 // this must be before "updated" message send to have history updated for OB update
23 document()->updateHistory(groupName()); // to update the history cash data in the document
24 // generate related events
25 static Events_Loop* aLoop = Events_Loop::loop();
26 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
27 if (myIsDisabled) { // disabled result looks like removed
28 aECreator->sendDeleted(document(), groupName());
29 } else { // un-disabled equals to created
30 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
31 aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature
33 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
34 aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
40 bool ModelAPI_Result::isDisabled()
42 if (myIsDisabled != data()->isDeleted())
43 setDisabled(std::dynamic_pointer_cast<ModelAPI_Result>(
44 data()->owner()), data()->isDeleted()); // restore from the data model the correct value
48 bool ModelAPI_Result::isConcealed()
53 void ModelAPI_Result::setIsConcealed(const bool theValue)
55 if (myIsConcealed != theValue) {
56 myIsConcealed = theValue;
57 if (document().get()) { // can be on creation of result
58 document()->updateHistory(groupName()); // to update the history cash data in the document
60 ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
61 static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
62 ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kDispEvent);
64 static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
65 ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
72 std::shared_ptr<GeomAPI_Shape> ModelAPI_Result::shape()
74 return std::shared_ptr<GeomAPI_Shape>();
77 void ModelAPI_Result::attributeChanged(const std::string& theID)
79 static Events_Loop* aLoop = Events_Loop::loop();
80 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
81 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
82 aECreator->sendUpdated(data()->attribute(theID)->owner(), EVENT_DISP);
85 void ModelAPI_Result::init()
87 myIsDisabled = true; // by default it is not initialized and false to be after created
88 myIsConcealed = false;