1 // Copyright (C) 2014-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ModelAPI_Result.h"
21 #include <ModelAPI_Events.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Attribute.h>
24 #include <ModelAPI_AttributeIntArray.h>
25 #include <ModelAPI_AttributeDouble.h>
26 #include <ModelAPI_AttributeBoolean.h>
28 #include <Events_Loop.h>
30 ModelAPI_Result::~ModelAPI_Result()
34 void ModelAPI_Result::initAttributes()
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())->setIsArgument(false);
39 aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false);
40 aData->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false);
41 aData->addAttribute(ISO_LINES_ID(), ModelAPI_AttributeIntArray::typeId())->setIsArgument(false);
42 aData->addAttribute(SHOW_ISO_LINES_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
43 aData->addAttribute(SHOW_EDGES_DIRECTION_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
44 // Add the "Bring To Front" attribute to the Result base class, as we may support it in the future
45 // for all type of results. Actually, only ResultGroups are supported.
46 aData->addAttribute(BRING_TO_FRONT_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
49 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
51 if (myIsDisabled != theFlag) {
52 myIsDisabled = theFlag;
53 if (data()->isValid())
54 data()->setIsDeleted(theFlag); // store it in data model (to get back on undo/redo, etc)
55 // this must be before "updated" message send to have history updated for OB update
56 document()->updateHistory(groupName()); // to update the history cash data in the document
57 // generate related events
58 static Events_Loop* aLoop = Events_Loop::loop();
59 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
60 if (myIsDisabled) { // disabled result looks like removed
61 aECreator->sendDeleted(document(), groupName());
62 } else { // un-disabled equals to created
63 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
64 aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature
66 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
67 aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
73 bool ModelAPI_Result::isDisabled()
75 if (data()->isValid() && myIsDisabled != data()->isDeleted())
76 setDisabled(std::dynamic_pointer_cast<ModelAPI_Result>(
77 data()->owner()), data()->isDeleted()); // restore from the data model the correct value
81 bool ModelAPI_Result::isConcealed()
86 void ModelAPI_Result::setIsConcealed(const bool theValue, const bool /*theForced*/)
88 if (myIsConcealed != theValue) {
89 myIsConcealed = theValue;
90 if (document().get()) { // can be on creation of result
91 document()->updateHistory(groupName()); // to update the history cash data in the document
93 ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
94 static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
95 ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kDispEvent);
97 static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
98 ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
105 std::shared_ptr<GeomAPI_Shape> ModelAPI_Result::shape()
107 return std::shared_ptr<GeomAPI_Shape>();
110 void ModelAPI_Result::attributeChanged(const std::string& theID)
112 static Events_Loop* aLoop = Events_Loop::loop();
113 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
114 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
115 aECreator->sendUpdated(data()->attribute(theID)->owner(), EVENT_DISP);
118 void ModelAPI_Result::init()
120 myIsDisabled = true; // by default it is not initialized and false to be after created
121 myIsConcealed = false;