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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include <Model_ResultCompSolid.h>
22 #include <Model_Document.h>
23 #include <Model_Objects.h>
24 #include <Model_BodyBuilder.h>
25 #include <Model_Document.h>
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_Events.h>
28 #include <Events_Loop.h>
30 #include <TopoDS_Shape.hxx>
31 #include <TopExp_Explorer.hxx>
34 Model_ResultCompSolid::Model_ResultCompSolid()
36 myBuilder = new Model_BodyBuilder(this);
37 myLastConcealed = false;
38 updateSubs(shape()); // in case of open, etc.
41 Model_ResultCompSolid::~Model_ResultCompSolid()
43 updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
46 void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
47 const bool theIsStoreSameShapes)
49 ModelAPI_ResultCompSolid::store(theShape, theIsStoreSameShapes);
53 void Model_ResultCompSolid::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
54 const std::shared_ptr<GeomAPI_Shape>& theToShape)
56 ModelAPI_ResultCompSolid::storeGenerated(theFromShape, theToShape);
57 updateSubs(theToShape);
60 void Model_ResultCompSolid::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
61 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
63 ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
64 updateSubs(theNewShape);
67 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
69 return int(mySubs.size());
72 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
75 return mySubs.at(theIndex);
78 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
80 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
81 for(; aSubIter != mySubs.cend(); aSubIter++)
82 if (*aSubIter == theObject)
87 void Model_ResultCompSolid::colorConfigInfo(std::string& theSection, std::string& theName,
88 std::string& theDefault)
90 theSection = "Visualization";
91 theName = "result_body_color";
92 theDefault = DEFAULT_COLOR();
95 bool Model_ResultCompSolid::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
98 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
99 if (aChanged) { // state is changed, so modifications are needed
100 myBuilder->evolutionToSelection(theFlag);
101 updateSubs(shape()); // to set disabled/enabled
106 bool Model_ResultCompSolid::isConcealed()
108 bool aResult = false;;
109 if (ModelAPI_ResultCompSolid::isConcealed()) {
112 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
113 for(; aSubIter != mySubs.cend(); aSubIter++) {
114 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed()) {
120 if (myLastConcealed != aResult) {
121 myLastConcealed = aResult;
122 //setIsConcealed(aResult); // set for all subs the same result
123 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
124 for(; aSubIter != mySubs.cend(); aSubIter++) { // update the visualization status of each sub
125 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != aResult) {
126 if (aResult) { // hidden unit must be redisplayed (hidden)
127 ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
128 // redisplay for the viewer (it must be disappeared also)
129 static Events_ID EVENT_DISP =
130 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
131 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
132 } else { // was not concealed become concealed => delete event
133 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
134 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
138 // update the display state of the subs: explicitly call Model_ResultBody::isConcealed
139 for(aSubIter = mySubs.cbegin(); aSubIter != mySubs.cend(); aSubIter++) {
140 (*aSubIter)->isConcealed();
146 void Model_ResultCompSolid::setIsConcealed(const bool theValue)
148 if (theValue != ModelAPI_ResultCompSolid::isConcealed()) {
149 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
150 for(; aSubIter != mySubs.cend(); aSubIter++) {
151 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != theValue) {
152 if (theValue) { // hidden unit must be redisplayed (hidden)
153 ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
154 // redisplay for the viewer (it must be disappeared also)
155 static Events_ID EVENT_DISP =
156 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
157 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
158 } else { // was not concealed become concealed => delete event
159 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
160 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
164 ModelAPI_ResultCompSolid::setIsConcealed(theValue);
165 // to set correct myLastConcealed
168 //myLastConcealed = theValue;
171 void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
173 static Events_Loop* aLoop = Events_Loop::loop();
174 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
175 static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
176 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
177 // iterate all sub-solids of compsolid to make sub-results synchronized with them
178 TopoDS_Shape aThisShape;
179 if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
180 if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
181 aThisShape.ShapeType() == TopAbs_COMPOUND)) {
182 bool aWasEmpty = mySubs.empty();
183 Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
184 unsigned int aSubIndex = 0;
185 TopoDS_Iterator aShapesIter(aThisShape);
186 for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) {
187 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
188 aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
190 if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
191 aSub = anObjects->createBody(this->data(), aSubIndex);
192 mySubs.push_back(aSub);
193 } else { // just update shape of this result
194 aSub = mySubs[aSubIndex];
196 if (!aShape->isEqual(aSub->shape())) {
197 aSub->store(aShape, false);
198 aECreator->sendUpdated(aSub, EVENT_DISP);
199 aECreator->sendUpdated(aSub, EVENT_UPD);
201 aSub->setDisabled(aSub, isDisabled());
202 aSub->setIsConcealed(myLastConcealed);
204 // erase left, unused results
205 while(mySubs.size() > aSubIndex) {
206 ResultBodyPtr anErased = *(mySubs.rbegin());
207 anErased->setDisabled(anErased, true);
210 if (aWasEmpty) { // erase all subs
211 // redisplay this because result with and without subs are displayed differently
212 aECreator->sendUpdated(data()->owner(), EVENT_DISP);
214 } else if (!mySubs.empty()) { // erase all subs
215 while(!mySubs.empty()) {
216 ResultBodyPtr anErased = *(mySubs.rbegin());
217 anErased->setDisabled(anErased, true);
220 // redisplay this because result with and without subs are displayed differently
221 aECreator->sendUpdated(data()->owner(), EVENT_DISP);
225 bool Model_ResultCompSolid::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
227 if (myBuilder->isLatestEqual(theShape))
229 // also check that it is asked for sub-elements
230 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
231 for(; aSubIter != mySubs.cend(); aSubIter++) {
232 if (aSubIter->get() && (*aSubIter)->isLatestEqual(theShape)) {