Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / Model / Model_ResultField.cpp
index f10fe16af5149947712cb3342fee565672f09768..985b66f2fccf03f200335e8af2073ea8cf48559f 100644 (file)
@@ -1,14 +1,30 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        Model_ResultField.cpp
-// Created:     08 Jul 2014
-// Author:      Mikhail PONIKAROV
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include <Model_ResultField.h>
-#include <ModelAPI_AttributeSelectionList.h>
 #include <Model_Document.h>
+
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeSelectionList.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
@@ -19,6 +35,14 @@ Model_ResultField::Model_ResultField(std::shared_ptr<ModelAPI_Data> theOwnerData
   myOwnerData = theOwnerData;
 }
 
+Model_ResultField::~Model_ResultField()
+{
+  while(mySteps.size() > 0) {
+    delete mySteps.back();
+    mySteps.pop_back();
+  }
+}
+
 void Model_ResultField::colorConfigInfo(std::string& theSection, std::string& theName,
                                        std::string& theDefault)
 {
@@ -45,7 +69,7 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultField::shape()
         for(int a = 0; a < aResults; a++) {
           ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
             document()->object(ModelAPI_ResultBody::group(), a));
-          if (!aBody.get()) 
+          if (!aBody.get())
             continue;
           // check that only results that were created before this field are used
           FeaturePtr aResultFeature = document()->feature(aBody);
@@ -70,6 +94,57 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultField::shape()
         aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
       }
     }
+    updateSteps();
   }
   return aResult;
 }
+
+void Model_ResultField::updateSteps()
+{
+  // Update Array of steps
+  int aNbSteps = stepsSize();
+  if (mySteps.size() != aNbSteps) {
+    while(mySteps.size() > aNbSteps) {
+      delete mySteps.back();
+      mySteps.pop_back();
+    }
+    while(mySteps.size() < aNbSteps) {
+      mySteps.push_back(new Model_ResultField::Model_FieldStep(this, mySteps.size()));
+    }
+  }
+}
+
+int Model_ResultField::stepsSize() const
+{
+  if (myOwnerData) {
+    AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
+    if (aArray.get()) {
+      return aArray->size();
+    }
+  }
+  return 0;
+}
+
+std::string Model_ResultField::textLine(int theLine) const
+{
+  if (myOwnerData) {
+    AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
+    if (aArray.get()) {
+      if (theLine < aArray->size()) {
+        std::ostringstream aStream;
+        aStream << aArray->value(theLine);
+        return aStream.str();
+      }
+    }
+  }
+  return "";
+}
+
+
+ModelAPI_ResultField::ModelAPI_FieldStep* Model_ResultField::step(int theId) const
+{
+  if (theId < mySteps.size()) {
+    return mySteps[theId];
+  }
+  return NULL;
+}