1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <Model_ResultCompSolid.h>
23 #include <Model_Document.h>
24 #include <Model_Objects.h>
25 #include <Model_BodyBuilder.h>
26 #include <Model_Document.h>
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Events.h>
29 #include <Events_Loop.h>
31 #include <TopoDS_Shape.hxx>
32 #include <TopExp_Explorer.hxx>
35 Model_ResultCompSolid::Model_ResultCompSolid()
37 myBuilder = new Model_BodyBuilder(this);
38 myLastConcealed = false;
39 updateSubs(shape()); // in case of open, etc.
42 Model_ResultCompSolid::~Model_ResultCompSolid()
44 updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
47 void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
48 const bool theIsStoreSameShapes)
50 ModelAPI_ResultCompSolid::store(theShape, theIsStoreSameShapes);
54 void Model_ResultCompSolid::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
55 const std::shared_ptr<GeomAPI_Shape>& theToShape)
57 ModelAPI_ResultCompSolid::storeGenerated(theFromShape, theToShape);
58 updateSubs(theToShape);
61 void Model_ResultCompSolid::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
62 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
64 ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
65 updateSubs(theNewShape);
68 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
70 return int(mySubs.size());
73 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
76 return mySubs.at(theIndex);
79 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
81 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
82 for(; aSubIter != mySubs.cend(); aSubIter++)
83 if (*aSubIter == theObject)
88 void Model_ResultCompSolid::colorConfigInfo(std::string& theSection, std::string& theName,
89 std::string& theDefault)
91 theSection = "Visualization";
92 theName = "result_body_color";
93 theDefault = DEFAULT_COLOR();
96 bool Model_ResultCompSolid::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
99 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
100 if (aChanged) { // state is changed, so modifications are needed
101 myBuilder->evolutionToSelection(theFlag);
102 updateSubs(shape()); // to set disabled/enabled
107 bool Model_ResultCompSolid::isConcealed()
109 bool aResult = false;;
110 if (ModelAPI_ResultCompSolid::isConcealed()) {
113 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
114 for(; aSubIter != mySubs.cend(); aSubIter++) {
115 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed()) {
121 if (myLastConcealed != aResult) {
122 myLastConcealed = aResult;
123 //setIsConcealed(aResult); // set for all subs the same result
124 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
125 for(; aSubIter != mySubs.cend(); aSubIter++) { // update the visualization status of each sub
126 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != aResult) {
127 if (aResult) { // hidden unit must be redisplayed (hidden)
128 ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
129 // redisplay for the viewer (it must be disappeared also)
130 static Events_ID EVENT_DISP =
131 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
132 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
133 } else { // was not concealed become concealed => delete event
134 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
135 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
139 // update the display state of the subs: explicitly call Model_ResultBody::isConcealed
140 for(aSubIter = mySubs.cbegin(); aSubIter != mySubs.cend(); aSubIter++) {
141 (*aSubIter)->isConcealed();
147 void Model_ResultCompSolid::setIsConcealed(const bool theValue)
149 if (theValue != ModelAPI_ResultCompSolid::isConcealed()) {
150 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
151 for(; aSubIter != mySubs.cend(); aSubIter++) {
152 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != theValue) {
153 if (theValue) { // hidden unit must be redisplayed (hidden)
154 ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
155 // redisplay for the viewer (it must be disappeared also)
156 static Events_ID EVENT_DISP =
157 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
158 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
159 } else { // was not concealed become concealed => delete event
160 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
161 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
165 ModelAPI_ResultCompSolid::setIsConcealed(theValue);
166 // to set correct myLastConcealed
169 //myLastConcealed = theValue;
172 void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
174 static Events_Loop* aLoop = Events_Loop::loop();
175 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
176 static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
177 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
178 // iterate all sub-solids of compsolid to make sub-results synchronized with them
179 TopoDS_Shape aThisShape;
180 if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
181 if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
182 aThisShape.ShapeType() == TopAbs_COMPOUND)) {
183 bool aWasEmpty = mySubs.empty();
184 Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
185 unsigned int aSubIndex = 0;
186 TopoDS_Iterator aShapesIter(aThisShape);
187 for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) {
188 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
189 aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
191 if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
192 aSub = anObjects->createBody(this->data(), aSubIndex);
193 mySubs.push_back(aSub);
194 } else { // just update shape of this result
195 aSub = mySubs[aSubIndex];
197 if (!aShape->isEqual(aSub->shape())) {
198 aSub->store(aShape, false);
199 aECreator->sendUpdated(aSub, EVENT_DISP);
200 aECreator->sendUpdated(aSub, EVENT_UPD);
202 aSub->setDisabled(aSub, isDisabled());
203 aSub->setIsConcealed(myLastConcealed);
205 // erase left, unused results
206 while(mySubs.size() > aSubIndex) {
207 ResultBodyPtr anErased = *(mySubs.rbegin());
208 anErased->setDisabled(anErased, true);
211 if (aWasEmpty) { // erase all subs
212 // redisplay this because result with and without subs are displayed differently
213 aECreator->sendUpdated(data()->owner(), EVENT_DISP);
215 } else if (!mySubs.empty()) { // erase all subs
216 while(!mySubs.empty()) {
217 ResultBodyPtr anErased = *(mySubs.rbegin());
218 anErased->setDisabled(anErased, true);
221 // redisplay this because result with and without subs are displayed differently
222 aECreator->sendUpdated(data()->owner(), EVENT_DISP);
226 bool Model_ResultCompSolid::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
228 if (myBuilder->isLatestEqual(theShape))
230 // also check that it is asked for sub-elements
231 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
232 for(; aSubIter != mySubs.cend(); aSubIter++) {
233 if (aSubIter->get() && (*aSubIter)->isLatestEqual(theShape)) {