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_Document.h>
14 Model_ResultCompSolid::Model_ResultCompSolid()
18 Model_ResultCompSolid::~Model_ResultCompSolid()
22 void Model_ResultCompSolid::initAttributes()
24 data()->addAttribute(Model_ResultCompSolid::BODIES_ID(), ModelAPI_AttributeRefList::typeId());
27 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::addResult(const int theIndex)
29 std::shared_ptr<ModelAPI_ResultBody> aBody = document()->createBody(data(), theIndex);
31 data()->reflist(Model_ResultCompSolid::BODIES_ID())->append(aBody);
36 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
41 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
45 std::shared_ptr<ModelAPI_ResultBody> aBody;
49 ObjectPtr anObj = data()->reflist(Model_ResultCompSolid::BODIES_ID())->object(theIndex);
50 return std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
53 /*int Model_ResultCompSolid::subResultId(const int theIndex) const
55 return subResult(theIndex)->data()->featureId();
58 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
60 // check is this feature of result
61 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
63 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
65 aFeature = document()->feature(aRes);
68 return data()->reflist(Model_ResultCompSolid::BODIES_ID())->isInList(aResult);
73 void Model_ResultCompSolid::removeResult(std::shared_ptr<ModelAPI_ResultBody> theResult)
75 if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
78 std::list<ObjectPtr> aSubs = data()->reflist(Model_ResultCompSolid::BODIES_ID())->list();
80 std::list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
81 bool isRemoved = false;
82 bool aHasEmtpyResult = false;
83 for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
84 std::shared_ptr<ModelAPI_ResultBody> aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubIt);
85 if (aResult.get() != NULL && aResult == theResult) {
86 data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(aResult);
89 else if (aResult.get() == NULL)
90 aHasEmtpyResult = true;
92 // if the object is not found in the sketch sub-elements, that means that the object is removed already.
93 // Find the first empty element and remove it
94 if (!isRemoved && aHasEmtpyResult)
95 data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(ObjectPtr());