Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / ModelAPI / ModelAPI_Result.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ModelAPI_Result.h"
22 #include <ModelAPI_Events.h>
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Attribute.h>
25 #include <ModelAPI_AttributeIntArray.h>
26 #include <ModelAPI_AttributeDouble.h>
27
28 #include <Events_Loop.h>
29
30 ModelAPI_Result::~ModelAPI_Result()
31 {
32 }
33
34 void ModelAPI_Result::initAttributes()
35 {
36   // append the color attribute. It is empty, the attribute will be filled by a request
37   DataPtr aData = data();
38   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
39   aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
40 }
41
42 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
43 {
44   if (myIsDisabled != theFlag) {
45     myIsDisabled = theFlag;
46     data()->setIsDeleted(theFlag); // store it in data model (to get back on undo/redo, etc)
47     // this must be before "updated" message send to have history updated for OB update
48     document()->updateHistory(groupName()); // to update the history cash data in the document
49     // generate related events
50     static Events_Loop* aLoop = Events_Loop::loop();
51     static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
52     if (myIsDisabled) { // disabled result looks like removed
53       aECreator->sendDeleted(document(), groupName());
54     } else { // un-disabled equals to created
55       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
56       aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature
57     }
58     static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
59     aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
60     return true;
61   }
62   return false;
63 }
64
65 bool ModelAPI_Result::isDisabled()
66 {
67   if (myIsDisabled != data()->isDeleted())
68     setDisabled(std::dynamic_pointer_cast<ModelAPI_Result>(
69       data()->owner()), data()->isDeleted()); // restore from the data model the correct value
70   return myIsDisabled;
71 }
72
73 bool ModelAPI_Result::isConcealed()
74 {
75   return myIsConcealed;
76 }
77
78 void ModelAPI_Result::setIsConcealed(const bool theValue)
79 {
80   if (myIsConcealed != theValue) {
81     myIsConcealed = theValue;
82     if (document().get()) { // can be on creation of result
83       document()->updateHistory(groupName()); // to update the history cash data in the document
84       if (myIsConcealed) {
85         ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
86         static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
87         ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kDispEvent);
88       } else {
89         static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
90         ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
91       }
92     }
93   }
94 }
95
96
97 std::shared_ptr<GeomAPI_Shape> ModelAPI_Result::shape()
98 {
99   return std::shared_ptr<GeomAPI_Shape>();
100 }
101
102 void ModelAPI_Result::attributeChanged(const std::string& theID)
103 {
104   static Events_Loop* aLoop = Events_Loop::loop();
105   static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
106   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
107   aECreator->sendUpdated(data()->attribute(theID)->owner(), EVENT_DISP);
108 }
109
110 void ModelAPI_Result::init()
111 {
112   myIsDisabled = true; // by default it is not initialized and false to be after created
113   myIsConcealed = false;
114 }