]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_ResultCompSolid.cpp
Salome HOME
Result CompSolid should inherits ResultBody. All model realization concerned Naming...
[modules/shaper.git] / src / Model / Model_ResultCompSolid.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_ResultCompSolid.cpp
4 // Created:     20 Jul 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <Model_ResultCompSolid.h>
8
9 #include <ModelAPI_AttributeRefList.h>
10 #include <ModelAPI_Object.h>
11
12 #include <Model_BodyBuilder.h>
13
14 #include <Model_Document.h>
15
16 Model_ResultCompSolid::Model_ResultCompSolid()
17 {
18   myBuilder = new Model_BodyBuilder(this);
19 }
20
21 Model_ResultCompSolid::~Model_ResultCompSolid()
22 {
23 }
24
25 void Model_ResultCompSolid::initAttributes()
26 {
27   data()->addAttribute(Model_ResultCompSolid::BODIES_ID(), ModelAPI_AttributeRefList::typeId());
28 }
29
30 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::addResult(const int theIndex)
31 {
32   std::shared_ptr<ModelAPI_ResultBody> aBody = document()->createBody(data(), theIndex);
33   if (aBody.get()) {
34     data()->reflist(Model_ResultCompSolid::BODIES_ID())->append(aBody);
35   }
36   return aBody;
37 }
38
39 int Model_ResultCompSolid::numberOfSubs(bool forTree) const
40 {
41   return 0;
42 }
43
44 std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
45                                                                       bool forTree) const
46 {
47   if (forTree) {
48     std::shared_ptr<ModelAPI_ResultBody> aBody;
49     return aBody;
50   }
51
52   ObjectPtr anObj = data()->reflist(Model_ResultCompSolid::BODIES_ID())->object(theIndex);
53   return std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
54 }
55
56 /*int Model_ResultCompSolid::subResultId(const int theIndex) const
57 {
58   return subResult(theIndex)->data()->featureId();
59 }*/
60
61 bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
62 {
63   // check is this feature of result
64   ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
65   /*if (!aFeature) {
66     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
67     if (aRes)
68       aFeature = document()->feature(aRes);
69   }*/
70   if (aResult) {
71     return data()->reflist(Model_ResultCompSolid::BODIES_ID())->isInList(aResult);
72   }
73   return false;
74 }
75
76 void Model_ResultCompSolid::removeResult(std::shared_ptr<ModelAPI_ResultBody> theResult)
77 {
78   if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
79     return;
80
81   std::list<ObjectPtr> aSubs = data()->reflist(Model_ResultCompSolid::BODIES_ID())->list();
82
83   std::list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
84   bool isRemoved = false;
85   bool aHasEmtpyResult = false;
86   for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
87     std::shared_ptr<ModelAPI_ResultBody> aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubIt);
88     if (aResult.get() != NULL && aResult == theResult) {
89       data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(aResult);
90       isRemoved = true;
91     }
92     else if (aResult.get() == NULL)
93       aHasEmtpyResult = true;
94   }
95   // if the object is not found in the sketch sub-elements, that means that the object is removed already.
96   // Find the first empty element and remove it
97   if (!isRemoved && aHasEmtpyResult)
98     data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(ObjectPtr());
99 }