1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_ResultField.cpp
4 // Created: 08 Jul 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_ResultField.h>
8 #include <Model_Document.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_AttributeIntArray.h>
13 #include <ModelAPI_AttributeSelectionList.h>
15 #include <GeomAlgoAPI_CompoundBuilder.h>
17 #include <Config_PropManager.h>
19 Model_ResultField::Model_ResultField(std::shared_ptr<ModelAPI_Data> theOwnerData)
21 myOwnerData = theOwnerData;
24 Model_ResultField::~Model_ResultField()
26 while(mySteps.size() > 0) {
27 delete mySteps.back();
32 void Model_ResultField::colorConfigInfo(std::string& theSection, std::string& theName,
33 std::string& theDefault)
35 theSection = "Visualization";
36 theName = "result_field_color";
37 theDefault = DEFAULT_COLOR();
40 std::shared_ptr<GeomAPI_Shape> Model_ResultField::shape()
42 std::shared_ptr<GeomAPI_Shape> aResult;
44 AttributeSelectionListPtr aList = myOwnerData->selectionList("selected");
46 std::list<std::shared_ptr<GeomAPI_Shape> > aSubs;
47 if (aList->selectionType() == "part") { // all result bodies of the part
48 std::shared_ptr<Model_Document> aDoc =
49 std::dynamic_pointer_cast<Model_Document>(document());
52 FeaturePtr aThisFeature = document()->feature(
53 std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner()));
54 int aResults = document()->size(ModelAPI_ResultBody::group());
55 for(int a = 0; a < aResults; a++) {
56 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
57 document()->object(ModelAPI_ResultBody::group(), a));
60 // check that only results that were created before this field are used
61 FeaturePtr aResultFeature = document()->feature(aBody);
62 if (!aResultFeature.get())
64 if (aDoc->isLater(aResultFeature, aThisFeature))
66 GeomShapePtr aShape = aBody->shape();
67 if (!aShape.get() || aShape->isNull())
69 aSubs.push_back(aShape);
72 for(int a = aList->size() - 1; a >= 0; a--) {
73 std::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
74 if (aSelection && !aSelection->isNull()) {
75 aSubs.push_back(aSelection);
80 aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
88 void Model_ResultField::updateSteps()
90 // Update Array of steps
91 int aNbSteps = stepsSize();
92 if (mySteps.size() != aNbSteps) {
93 while(mySteps.size() > aNbSteps) {
94 delete mySteps.back();
97 while(mySteps.size() < aNbSteps) {
98 mySteps.push_back(new Model_ResultField::Model_FieldStep(this, mySteps.size()));
103 int Model_ResultField::stepsSize() const
106 AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
108 return aArray->size();
114 std::string Model_ResultField::textLine(int theLine) const
117 AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
119 if (theLine < aArray->size()) {
120 std::ostringstream aStream;
121 aStream << aArray->value(theLine);
122 return aStream.str();
130 ModelAPI_ResultField::ModelAPI_FieldStep* Model_ResultField::step(int theId) const
132 if (theId < mySteps.size()) {
133 return mySteps[theId];