Salome HOME
Creation of producedByFeature initial implementation neede for the issue #1306
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_ResultBody.cpp
4 // Created:     08 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_ResultBody.h>
8 #include <Model_BodyBuilder.h>
9 #include <ModelAPI_AttributeIntArray.h>
10 #include <ModelAPI_Tools.h>
11 #include <Config_PropManager.h>
12 #include <ModelAPI_Events.h>
13 // DEB
14 //#include <TCollection_AsciiString.hxx>
15 //#include <TDF_Tool.hxx>
16 //#define DEB_IMPORT 1
17
18 Model_ResultBody::Model_ResultBody()
19 {
20   myBuilder = new Model_BodyBuilder(this);
21   myWasConcealed = false;
22 }
23
24 void Model_ResultBody::initAttributes()
25 {
26   // append the color attribute. It is empty, the attribute will be filled by a request
27   DataPtr aData = data();
28   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
29 }
30
31 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
32   std::string& theDefault)
33 {
34   theSection = "Visualization";
35   theName = "result_body_color";
36   theDefault = DEFAULT_COLOR();
37 }
38
39 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
40 {
41   bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
42   if (aChanged) { // state is changed, so modifications are needed
43     myBuilder->evolutionToSelection(theFlag);
44   }
45   return aChanged;
46 }
47
48 bool Model_ResultBody::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
49 {
50   return myBuilder->isLatestEqual(theShape);
51 }
52
53 bool Model_ResultBody::isConcealed()
54 {
55   bool aResult = false;
56   if (ModelAPI_ResultBody::isConcealed()) {
57     aResult = true;
58   } else {
59     ResultPtr aThis = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
60     if (aThis.get()) {
61       ResultCompSolidPtr aParent = ModelAPI_Tools::compSolidOwner(aThis);
62       if (aParent.get()) {
63         if (aParent->isConcealed())
64           aResult = true;
65       }
66     }
67   }
68   if (myWasConcealed != aResult) {
69     myWasConcealed = aResult;
70     if (aResult) { // hidden unit must be redisplayed (hidden)
71       ModelAPI_EventCreator::get()->sendDeleted(document(), this->groupName());
72       // redisplay for the viewer (it must be disappeared also)
73       static Events_ID EVENT_DISP = 
74         Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
75       ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
76     } else { // was not concealed become concealed => delete event
77       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
78       ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
79     }
80   }
81
82   return aResult;
83 }