Salome HOME
Update of the ExportToGEOM test
[modules/shaper.git] / src / Model / Model_ResultBody.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 <Model_ResultBody.h>
22 #include <Model_BodyBuilder.h>
23 #include <ModelAPI_ResultCompSolid.h>
24 #include <ModelAPI_Tools.h>
25 #include <Config_PropManager.h>
26 #include <ModelAPI_Events.h>
27 // DEB
28 //#include <TCollection_AsciiString.hxx>
29 //#include <TDF_Tool.hxx>
30 //#define DEB_IMPORT 1
31
32 Model_ResultBody::Model_ResultBody()
33 {
34   myBuilder = new Model_BodyBuilder(this);
35   myWasConcealed = false;
36   myConnect = ConnectionNotComputed;
37 }
38
39 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
40   std::string& theDefault)
41 {
42   theSection = "Visualization";
43   theName = "result_body_color";
44   theDefault = DEFAULT_COLOR();
45 }
46
47 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
48 {
49   bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
50   if (aChanged && data()->isValid()) { // state is changed, so modifications are needed
51     myBuilder->evolutionToSelection(theFlag);
52   }
53   return aChanged;
54 }
55
56 bool Model_ResultBody::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
57 {
58   return myBuilder->isLatestEqual(theShape);
59 }
60
61 bool Model_ResultBody::isConcealed()
62 {
63   bool aResult = false;
64   if (ModelAPI_ResultBody::isConcealed()) {
65     aResult = true;
66   } else {
67     ResultPtr aThis = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
68     if (aThis.get()) {
69       ResultCompSolidPtr aParent = ModelAPI_Tools::compSolidOwner(aThis);
70       if (aParent.get()) {
71         if (aParent->isConcealed())
72           aResult = true;
73       }
74     }
75   }
76   if (myWasConcealed != aResult) {
77     myWasConcealed = aResult;
78     if (aResult) { // hidden unit must be redisplayed (hidden)
79       ModelAPI_EventCreator::get()->sendDeleted(document(), this->groupName());
80       // redisplay for the viewer (it must be disappeared also)
81       static Events_ID EVENT_DISP =
82         Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
83       ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
84     } else { // was not concealed become concealed => delete event
85       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
86       ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
87     }
88   }
89
90   return aResult;
91 }