Salome HOME
Update line endings according to coding rules
[modules/shaper.git] / src / Model / Model_ResultField.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_ResultField.cpp
4 // Created:     08 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_ResultField.h>
8 #include <ModelAPI_AttributeSelectionList.h>
9 #include <Model_Document.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <ModelAPI_Feature.h>
12
13 #include <GeomAlgoAPI_CompoundBuilder.h>
14
15 #include <Config_PropManager.h>
16
17 Model_ResultField::Model_ResultField(std::shared_ptr<ModelAPI_Data> theOwnerData)
18 {
19   myOwnerData = theOwnerData;
20 }
21
22 void Model_ResultField::colorConfigInfo(std::string& theSection, std::string& theName,
23                                        std::string& theDefault)
24 {
25   theSection = "Visualization";
26   theName = "result_field_color";
27   theDefault = DEFAULT_COLOR();
28 }
29
30 std::shared_ptr<GeomAPI_Shape> Model_ResultField::shape()
31 {
32   std::shared_ptr<GeomAPI_Shape> aResult;
33   if (myOwnerData) {
34     AttributeSelectionListPtr aList = myOwnerData->selectionList("selected");
35     if (aList) {
36       std::list<std::shared_ptr<GeomAPI_Shape> > aSubs;
37       if (aList->selectionType() == "part") { // all result bodies of the part
38         std::shared_ptr<Model_Document> aDoc =
39           std::dynamic_pointer_cast<Model_Document>(document());
40         if (!aDoc.get())
41           return aResult;
42         FeaturePtr aThisFeature = document()->feature(
43           std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner()));
44         int aResults = document()->size(ModelAPI_ResultBody::group());
45         for(int a = 0; a < aResults; a++) {
46           ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
47             document()->object(ModelAPI_ResultBody::group(), a));
48           if (!aBody.get())
49             continue;
50           // check that only results that were created before this field are used
51           FeaturePtr aResultFeature = document()->feature(aBody);
52           if (!aResultFeature.get())
53             continue;
54           if (aDoc->isLater(aResultFeature, aThisFeature))
55             continue;
56           GeomShapePtr aShape = aBody->shape();
57           if (!aShape.get() || aShape->isNull())
58             continue;
59           aSubs.push_back(aShape);
60         }
61       } else {
62         for(int a = aList->size() - 1; a >= 0; a--) {
63           std::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
64           if (aSelection && !aSelection->isNull()) {
65             aSubs.push_back(aSelection);
66           }
67         }
68       }
69       if (!aSubs.empty()) {
70         aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
71       }
72     }
73   }
74   return aResult;
75 }