1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Model_ResultField.h>
21 #include <Model_Document.h>
23 #include <ModelAPI_ResultBody.h>
24 #include <ModelAPI_Feature.h>
25 #include <ModelAPI_AttributeIntArray.h>
26 #include <ModelAPI_AttributeSelectionList.h>
27 #include <ModelAPI_Tools.h>
29 #include <GeomAlgoAPI_CompoundBuilder.h>
31 #include <Locale_Convert.h>
33 #include <Config_PropManager.h>
35 Model_ResultField::Model_ResultField(std::shared_ptr<ModelAPI_Data> theOwnerData)
37 myOwnerData = theOwnerData;
40 Model_ResultField::~Model_ResultField()
42 while(mySteps.size() > 0) {
43 //delete mySteps.back();
49 void Model_ResultField::colorConfigInfo(std::string& theSection, std::string& theName,
50 std::string& theDefault)
52 theSection = "Visualization";
53 theName = "result_field_color";
54 theDefault = DEFAULT_COLOR();
58 std::shared_ptr<GeomAPI_Shape> Model_ResultField::shape()
60 std::shared_ptr<GeomAPI_Shape> aResult;
62 AttributeSelectionListPtr aList = myOwnerData->selectionList("selected");
64 std::list<std::shared_ptr<GeomAPI_Shape> > aSubs;
65 if (aList->selectionType() == "part") { // all result bodies of the part
66 std::shared_ptr<Model_Document> aDoc =
67 std::dynamic_pointer_cast<Model_Document>(document());
70 FeaturePtr aThisFeature = document()->feature(
71 std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner()));
72 int aResults = document()->size(ModelAPI_ResultBody::group());
73 for(int a = 0; a < aResults; a++) {
74 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
75 document()->object(ModelAPI_ResultBody::group(), a));
78 // check that only results that were created before this field are used
79 FeaturePtr aResultFeature = document()->feature(aBody);
80 if (!aResultFeature.get())
82 if (aDoc->isLater(aResultFeature, aThisFeature))
84 GeomShapePtr aShape = aBody->shape();
85 if (!aShape.get() || aShape->isNull())
87 aSubs.push_back(aShape);
90 for(int a = aList->size() - 1; a >= 0; a--) {
91 std::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
92 if (aSelection && !aSelection->isNull()) {
93 aSubs.push_back(aSelection);
98 aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
106 void Model_ResultField::updateSteps()
108 // Update Array of steps
109 int aNbSteps = stepsSize();
110 if ((int)mySteps.size() != aNbSteps) {
111 while((int)mySteps.size() > aNbSteps) {
112 //delete mySteps.back();
115 while((int)mySteps.size() < aNbSteps) {
116 mySteps.push_back(FieldStepPtr(new Model_ResultField::Model_FieldStep(this,
117 (int)mySteps.size())));
122 int Model_ResultField::stepsSize() const
125 AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
127 return aArray->size();
133 std::string Model_ResultField::textLine(int theLine) const
136 AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
138 if (theLine < aArray->size()) {
139 std::ostringstream aStream;
140 aStream << aArray->value(theLine);
141 return aStream.str();
150 std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> Model_ResultField::step(int theId) const
152 if (theId < (int)mySteps.size()) {
153 return mySteps[theId];
158 std::wstring Model_ResultField::Model_FieldStep::name() {
159 std::wostringstream aStream;
160 aStream<<myParent->data()->name()<<std::endl;
161 aStream<<"Step "<<(myId + 1)<<" "<< Locale::Convert::toWString(myParent->textLine(myId));
162 return aStream.str();