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 <ModelAPI_AttributeIntArray.h>
12 #include <ModelAPI_AttributeDouble.h>
14 #include <Events_Loop.h>
16 ModelAPI_Result::~ModelAPI_Result()
20 void ModelAPI_Result::initAttributes()
22 // append the color attribute. It is empty, the attribute will be filled by a request
23 DataPtr aData = data();
24 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
25 aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
28 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
30 if (myIsDisabled != theFlag) {
31 myIsDisabled = theFlag;
32 data()->setIsDeleted(theFlag); // store it in data model (to get back on undo/redo, etc)
33 // this must be before "updated" message send to have history updated for OB update
34 document()->updateHistory(groupName()); // to update the history cash data in the document
35 // generate related events
36 static Events_Loop* aLoop = Events_Loop::loop();
37 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
38 if (myIsDisabled) { // disabled result looks like removed
39 aECreator->sendDeleted(document(), groupName());
40 } else { // un-disabled equals to created
41 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
42 aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature
44 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
45 aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
51 bool ModelAPI_Result::isDisabled()
53 if (myIsDisabled != data()->isDeleted())
54 setDisabled(std::dynamic_pointer_cast<ModelAPI_Result>(
55 data()->owner()), data()->isDeleted()); // restore from the data model the correct value
59 bool ModelAPI_Result::isConcealed()
64 void ModelAPI_Result::setIsConcealed(const bool theValue)
66 if (myIsConcealed != theValue) {
67 myIsConcealed = theValue;
68 if (document().get()) { // can be on creation of result
69 document()->updateHistory(groupName()); // to update the history cash data in the document
71 ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
72 static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
73 ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kDispEvent);
75 static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
76 ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
83 std::shared_ptr<GeomAPI_Shape> ModelAPI_Result::shape()
85 return std::shared_ptr<GeomAPI_Shape>();
88 void ModelAPI_Result::attributeChanged(const std::string& theID)
90 static Events_Loop* aLoop = Events_Loop::loop();
91 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
92 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
93 aECreator->sendUpdated(data()->attribute(theID)->owner(), EVENT_DISP);
96 void ModelAPI_Result::init()
98 myIsDisabled = true; // by default it is not initialized and false to be after created
99 myIsConcealed = false;