Salome HOME
Task 2.8. Measurement functions
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Measurement.cpp
index 466aa017808a766feac9dd5d95a8b2a4ff57602a..40029631414224f683574d5a3395a79f68c11d92 100644 (file)
@@ -115,3 +115,28 @@ std::list<double> measureAngle(const std::shared_ptr<ModelAPI_Document>& thePart
 
   return aValues;
 }
+
+double measureAngle(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const ModelHighAPI_Selection& thePoint1,
+                    const ModelHighAPI_Selection& thePoint2,
+                    const ModelHighAPI_Selection& thePoint3)
+{
+  FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
+  fillAttribute(FeaturesPlugin_Measurement::MEASURE_ANGLE_POINTS(),
+                aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
+  fillAttribute(thePoint1, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT1_ID()));
+  fillAttribute(thePoint2, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT2_ID()));
+  fillAttribute(thePoint3, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT3_ID()));
+  aMeasure->execute();
+
+  // obtain result
+  AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
+      aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
+  double aValue = aResult->size() ? aResult->value(0) : -1.0;
+
+  // perform removing macro feature Measurement
+  thePart->removeFeature(aMeasure);
+  apply();
+
+  return aValue;
+}