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_AttributeRefList.h>
14 #include <ModelAPI_AttributeIntArray.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Events.h>
17 #include <Events_Loop.h>
19 #include <TopoDS_Shape.hxx>
20 #include <TopExp_Explorer.hxx>
23 Model_ResultCompSolid::Model_ResultCompSolid()
25 myBuilder = new Model_BodyBuilder(this);
26 updateSubs(shape()); // in case of open, etc.
29 Model_ResultCompSolid::~Model_ResultCompSolid()
31 updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
34 void Model_ResultCompSolid::initAttributes()
36 DataPtr aData = data();
37 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
40 void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
42 ModelAPI_ResultCompSolid::store(theShape);
46 void Model_ResultCompSolid::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
47 const std::shared_ptr<GeomAPI_Shape>& theToShape)
49 ModelAPI_ResultCompSolid::storeGenerated(theFromShape, theToShape);
50 updateSubs(theToShape);
53 void Model_ResultCompSolid::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
54 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
56 ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
57 updateSubs(theNewShape);
60 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
65 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
68 return mySubs.at(theIndex);
71 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
73 std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
74 for(; aSubIter != mySubs.cend(); aSubIter++)
75 if (*aSubIter == theObject)
80 void Model_ResultCompSolid::colorConfigInfo(std::string& theSection, std::string& theName,
81 std::string& theDefault)
83 theSection = "Visualization";
84 theName = "result_body_color";
85 theDefault = DEFAULT_COLOR();
88 bool Model_ResultCompSolid::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
90 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
91 if (aChanged) { // state is changed, so modifications are needed
92 myBuilder->evolutionToSelection(theFlag);
97 void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape)
99 // iterate all sub-solids of compsolid to make sub-results synchronized with them
100 TopoDS_Shape aThisShape;
101 if (theThisShape.get()) aThisShape = theThisShape->impl<TopoDS_Shape>();
102 if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_COMPSOLID ||
103 aThisShape.ShapeType() == TopAbs_COMPOUND)) {
104 Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
105 unsigned int aSubIndex = 0;
106 TopExp_Explorer aSolids(aThisShape, TopAbs_SOLID);
107 for(; aSolids.More(); aSolids.Next(), aSubIndex++) {
108 std::shared_ptr<GeomAPI_Shape> aSolidShape(new GeomAPI_Shape);
109 aSolidShape->setImpl(new TopoDS_Shape(aSolids.Current()));
111 if (mySubs.size() >= aSubIndex) { // it is needed to create a new sub-result
112 aSub = anObjects->createBody(this->data(), aSubIndex);
113 mySubs.push_back(aSub);
114 } else { // just update shape of this result
115 aSub = mySubs[aSubIndex];
117 if (!aSolidShape->isEqual(aSub->shape())) {
118 aSub->store(aSolidShape);
119 static Events_Loop* aLoop = Events_Loop::loop();
120 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
121 static Events_ID EVENT_UPD = aLoop->eventByName(EVENT_OBJECT_UPDATED);
122 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
123 aECreator->sendUpdated(aSub, EVENT_DISP);
124 aECreator->sendUpdated(aSub, EVENT_UPD);
126 aSub->setDisabled(aSub, false);
128 // erase left, unused results
129 while(mySubs.size() > aSubIndex) {
130 ResultBodyPtr anErased = *(mySubs.rbegin());
131 anErased->setDisabled(anErased, true);
134 } else { // erase all subs
135 while(!mySubs.empty()) {
136 ResultBodyPtr anErased = *(mySubs.rbegin());
137 anErased->setDisabled(anErased, true);