1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_ResultCompSolid.cpp
4 // Created: 20 Jul 2015
5 // Author: Natalia ERMOLAEVA
7 #include <Model_ResultCompSolid.h>
9 #include <Model_Document.h>
10 #include <Model_Objects.h>
11 #include <Model_BodyBuilder.h>
12 #include <Model_Document.h>
13 #include <ModelAPI_Object.h>
14 #include <ModelAPI_Events.h>
15 #include <Events_Loop.h>
17 #include <TopoDS_Shape.hxx>
18 #include <TopExp_Explorer.hxx>
21 Model_ResultCompSolid::Model_ResultCompSolid()
23 myBuilder = new Model_BodyBuilder(this);
24 myLastConcealed = false;
25 updateSubs(shape()); // in case of open, etc.
28 Model_ResultCompSolid::~Model_ResultCompSolid()
30 updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
33 void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
35 ModelAPI_ResultCompSolid::store(theShape);
39 void Model_ResultCompSolid::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
40 const std::shared_ptr<GeomAPI_Shape>& theToShape)
42 ModelAPI_ResultCompSolid::storeGenerated(theFromShape, theToShape);
43 updateSubs(theToShape);
46 void Model_ResultCompSolid::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
47 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
49 ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
50 updateSubs(theNewShape);
53 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
55 return int(mySubs.size());
58 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
61 return mySubs.at(theIndex);
64 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
66 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
67 for(; aSubIter != mySubs.cend(); aSubIter++)
68 if (*aSubIter == theObject)
73 void Model_ResultCompSolid::colorConfigInfo(std::string& theSection, std::string& theName,
74 std::string& theDefault)
76 theSection = "Visualization";
77 theName = "result_body_color";
78 theDefault = DEFAULT_COLOR();
81 bool Model_ResultCompSolid::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
83 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
84 if (aChanged) { // state is changed, so modifications are needed
85 myBuilder->evolutionToSelection(theFlag);
86 updateSubs(shape()); // to set disabled/enabled
91 bool Model_ResultCompSolid::isConcealed()
93 bool aResult = false;;
94 if (ModelAPI_ResultCompSolid::isConcealed()) {
97 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
98 for(; aSubIter != mySubs.cend(); aSubIter++) {
99 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed()) {
105 if (myLastConcealed != aResult) {
106 myLastConcealed = aResult;
107 //setIsConcealed(aResult); // set for all subs the same result
108 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
109 for(; aSubIter != mySubs.cend(); aSubIter++) { // update the visualization status of each sub
110 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != aResult) {
111 if (aResult) { // hidden unit must be redisplayed (hidden)
112 ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
113 // redisplay for the viewer (it must be disappeared also)
114 static Events_ID EVENT_DISP =
115 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
116 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
117 } else { // was not concealed become concealed => delete event
118 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
119 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
127 void Model_ResultCompSolid::setIsConcealed(const bool theValue)
129 if (theValue != ModelAPI_ResultCompSolid::isConcealed()) {
130 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
131 for(; aSubIter != mySubs.cend(); aSubIter++) {
132 if ((*aSubIter)->ModelAPI_ResultBody::isConcealed() != theValue) {
133 if (theValue) { // hidden unit must be redisplayed (hidden)
134 ModelAPI_EventCreator::get()->sendDeleted(document(), (*aSubIter)->groupName());
135 // redisplay for the viewer (it must be disappeared also)
136 static Events_ID EVENT_DISP =
137 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
138 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, EVENT_DISP);
139 } else { // was not concealed become concealed => delete event
140 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
141 ModelAPI_EventCreator::get()->sendUpdated(*aSubIter, anEvent);
145 ModelAPI_ResultCompSolid::setIsConcealed(theValue);
146 // to set correct myLastConcealed
149 //myLastConcealed = theValue;
152 void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
154 static Events_Loop* aLoop = Events_Loop::loop();
155 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
156 static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
157 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
158 // iterate all sub-solids of compsolid to make sub-results synchronized with them
159 TopoDS_Shape aThisShape;
160 if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
161 if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
162 aThisShape.ShapeType() == TopAbs_COMPOUND)) {
163 bool aWasEmpty = mySubs.empty();
164 Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
165 unsigned int aSubIndex = 0;
166 TopoDS_Iterator aShapesIter(aThisShape);
167 for(; aShapesIter.More(); aShapesIter.Next(), aSubIndex++) {
168 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
169 aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
171 if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
172 aSub = anObjects->createBody(this->data(), aSubIndex);
173 mySubs.push_back(aSub);
174 } else { // just update shape of this result
175 aSub = mySubs[aSubIndex];
177 if (!aShape->isEqual(aSub->shape())) {
178 aSub->store(aShape, false);
179 aECreator->sendUpdated(aSub, EVENT_DISP);
180 aECreator->sendUpdated(aSub, EVENT_UPD);
182 aSub->setDisabled(aSub, isDisabled());
183 aSub->setIsConcealed(myLastConcealed);
185 // erase left, unused results
186 while(mySubs.size() > aSubIndex) {
187 ResultBodyPtr anErased = *(mySubs.rbegin());
188 anErased->setDisabled(anErased, true);
191 if (aWasEmpty) { // erase all subs
192 // redisplay this because result with and without subs are displayed differently
193 aECreator->sendUpdated(data()->owner(), EVENT_DISP);
195 } else if (!mySubs.empty()) { // erase all subs
196 while(!mySubs.empty()) {
197 ResultBodyPtr anErased = *(mySubs.rbegin());
198 anErased->setDisabled(anErased, true);
201 // redisplay this because result with and without subs are displayed differently
202 aECreator->sendUpdated(data()->owner(), EVENT_DISP);
206 bool Model_ResultCompSolid::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
208 if (myBuilder->isLatestEqual(theShape))
210 // also check that it is asked for sub-elements
211 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
212 for(; aSubIter != mySubs.cend(); aSubIter++) {
213 if (aSubIter->get() && (*aSubIter)->isLatestEqual(theShape)) {