Salome HOME
Issue #3140: Modify Iso-lines of a shape presentation
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
index 413f52c4ce616edd2c2e4cb49f84f0621dde2737..3d293492e517645cf583bdf62eb22a8c7fdea2d4 100644 (file)
@@ -785,6 +785,19 @@ void removeResults(const std::list<ResultPtr>& theResults)
   }
 }
 
+
+//**************************************************************
+void setDeflection(ResultPtr theResult, const double theDeflection)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
+  if (aDeflectionAttr.get() != NULL) {
+    aDeflectionAttr->setValue(theDeflection);
+  }
+}
+
 // used by GUI only
 // LCOV_EXCL_START
 double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult)
@@ -803,6 +816,22 @@ double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult)
   return aDeflection;
 }
 
+//******************************************************
+void setColor(ResultPtr theResult, const std::vector<int>& theColor)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+  if (aColorAttr.get() != NULL) {
+    if (!aColorAttr->size()) {
+      aColorAttr->setSize(3);
+    }
+    aColorAttr->setValue(0, theColor[0]);
+    aColorAttr->setValue(1, theColor[1]);
+    aColorAttr->setValue(2, theColor[2]);
+  }
+}
 
 void getColor(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int>& theColor)
 {
@@ -819,6 +848,49 @@ void getColor(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int
   }
 }
 
+//******************************************************
+void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int>& theNbLines)
+{
+  theNbLines.clear();
+  // get color from the attribute of the result
+  if (theResult.get() != NULL &&
+    theResult->data()->attribute(ModelAPI_Result::ISO_LINES_ID()).get() != NULL) {
+    AttributeIntArrayPtr aAttr = theResult->data()->intArray(ModelAPI_Result::ISO_LINES_ID());
+    if (aAttr.get() && aAttr->size()) {
+      theNbLines.push_back(aAttr->value(0));
+      theNbLines.push_back(aAttr->value(1));
+    }
+  }
+}
+
+//******************************************************
+void setIsoLines(ResultPtr theResult, const std::vector<int>& theIso)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeIntArrayPtr aAttr = theResult->data()->intArray(ModelAPI_Result::ISO_LINES_ID());
+  if (aAttr.get() != NULL) {
+    if (!aAttr->size()) {
+      aAttr->setSize(2);
+    }
+    aAttr->setValue(0, theIso[0]);
+    aAttr->setValue(1, theIso[1]);
+  }
+}
+
+//**************************************************************
+void setTransparency(ResultPtr theResult, double theTransparency)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
+  if (anAttribute.get() != NULL) {
+    anAttribute->setValue(theTransparency);
+  }
+}
+
 double getTransparency(const std::shared_ptr<ModelAPI_Result>& theResult)
 {
   double aTransparency = -1;
@@ -847,6 +919,16 @@ void copyVisualizationAttrs(
         aDestColor->setValue(a, aSourceColor->value(a));
     }
   }
+  // Iso-lines
+  AttributeIntArrayPtr aSource = theSource->data()->intArray(ModelAPI_Result::ISO_LINES_ID());
+  if (aSource.get() && aSource->isInitialized() && aSource->size()) {
+    AttributeIntArrayPtr aDest = theDest->data()->intArray(ModelAPI_Result::ISO_LINES_ID());
+    if (aDest.get()) {
+      aDest->setSize(aSource->size());
+      for(int a = 0; a < aSource->size(); a++)
+        aDest->setValue(a, aSource->value(a));
+    }
+  }
   // deflection
   AttributeDoublePtr aSourceDefl = theSource->data()->real(ModelAPI_Result::DEFLECTION_ID());
   if (aSourceDefl.get() && aSourceDefl->isInitialized()) {