Salome HOME
Multiple fixes (issue #1757 , issue #1799 , issue #1842 , etc):
[modules/shaper.git] / src / ModelAPI / ModelAPI_Result.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Result.cpp
4 // Created:     07 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
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>
13
14 #include <Events_Loop.h>
15
16 ModelAPI_Result::~ModelAPI_Result()
17 {
18 }
19
20 void ModelAPI_Result::initAttributes()
21 {
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());
26 }
27
28 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
29 {
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
43     }
44     static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
45     aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
46     return true;
47   }
48   return false;
49 }
50
51 bool ModelAPI_Result::isDisabled()
52 {
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
56   return myIsDisabled;
57 }
58
59 bool ModelAPI_Result::isConcealed()
60 {
61   return myIsConcealed;
62 }
63
64 void ModelAPI_Result::setIsConcealed(const bool theValue)
65 {
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
70       if (myIsConcealed) {
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);
74       } else {
75         static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
76         ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
77       }
78     }
79   }
80 }
81
82
83 std::shared_ptr<GeomAPI_Shape> ModelAPI_Result::shape()
84 {
85   return std::shared_ptr<GeomAPI_Shape>();
86 }
87
88 void ModelAPI_Result::attributeChanged(const std::string& theID)
89 {
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);
94 }
95
96 void ModelAPI_Result::init()
97 {
98   myIsDisabled = true; // by default it is not initialized and false to be after created
99   myIsConcealed = false;
100 }