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 <ModelAPI_AttributeRefList.h>
10 #include <ModelAPI_Object.h>
12 #include <Model_BodyBuilder.h>
14 #include <Model_Document.h>
16 Model_ResultCompSolid::Model_ResultCompSolid()
18 myBuilder = new Model_BodyBuilder(this);
21 Model_ResultCompSolid::~Model_ResultCompSolid()
25 void Model_ResultCompSolid::initAttributes()
27 data()->addAttribute(Model_ResultCompSolid::BODIES_ID(), ModelAPI_AttributeRefList::typeId());
30 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::addResult(const int theIndex)
32 std::shared_ptr<ModelAPI_ResultBody> aBody = document()->createBody(data(), theIndex);
34 data()->reflist(Model_ResultCompSolid::BODIES_ID())->append(aBody);
39 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
43 return data()->reflist(Model_ResultCompSolid::BODIES_ID())->size();
46 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
50 std::shared_ptr<ModelAPI_ResultBody> aBody;
54 ObjectPtr anObj = data()->reflist(Model_ResultCompSolid::BODIES_ID())->object(theIndex);
55 return std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
58 /*int Model_ResultCompSolid::subResultId(const int theIndex) const
60 return subResult(theIndex)->data()->featureId();
63 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
65 // check is this feature of result
66 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
68 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
70 aFeature = document()->feature(aRes);
73 return data()->reflist(Model_ResultCompSolid::BODIES_ID())->isInList(aResult);
78 void Model_ResultCompSolid::removeResult(std::shared_ptr<ModelAPI_ResultBody> theResult)
80 if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
83 std::list<ObjectPtr> aSubs = data()->reflist(Model_ResultCompSolid::BODIES_ID())->list();
85 std::list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
86 bool isRemoved = false;
87 bool aHasEmtpyResult = false;
88 for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
89 std::shared_ptr<ModelAPI_ResultBody> aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubIt);
90 if (aResult.get() != NULL && aResult == theResult) {
91 data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(aResult);
94 else if (aResult.get() == NULL)
95 aHasEmtpyResult = true;
97 // if the object is not found in the sketch sub-elements, that means that the object is removed already.
98 // Find the first empty element and remove it
99 if (!isRemoved && aHasEmtpyResult)
100 data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(ObjectPtr());