Salome HOME
Provide displaying of steps in data browser
[modules/shaper.git] / src / Model / Model_ResultField.cpp
index f10fe16af5149947712cb3342fee565672f09768..da8f1773a0e1c6cf5fcd4edccfd868f98daa2b0f 100644 (file)
@@ -5,10 +5,12 @@
 // Author:      Mikhail PONIKAROV
 
 #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 +21,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 +55,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 +80,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;
+}