]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp
Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Measurement.cpp
index 7e497ada8245e6ee7a84fdafbf882baec20ae520..2bae620a3255f24e6a675621e3bb419e8426ebbb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2022  CEA/DEN, EDF R&D
+// Copyright (C) 2018-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -93,12 +93,15 @@ void FeaturesPlugin_Measurement::attributeChanged(const std::string& theID)
     std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
       attribute(RESULT_VALUES_ID()))->setSize(0);
   }
-  if (theID != RESULT_ID()) {
+  else if (theID != RESULT_ID() &&
+           theID != RESULT_VALUES_ID()) {
     std::string aKind = string(MEASURE_KIND())->value();
     if (aKind == MEASURE_LENGTH())
       computeLength();
     else if (aKind == MEASURE_DISTANCE())
       computeDistance();
+    else if (aKind == MEASURE_PROXIMITY())
+      computeProximity();
     else if (aKind == MEASURE_RADIUS())
       computeRadius();
     else if (aKind == MEASURE_ANGLE())
@@ -184,6 +187,41 @@ void FeaturesPlugin_Measurement::computeDistance()
   aValues->setValue(0, aDistance);
 }
 
+void FeaturesPlugin_Measurement::computeProximity()
+{
+  AttributeSelectionPtr aFirstFeature = selection(DISTANCE_FROM_OBJECT_ID());
+  GeomShapePtr aShape1;
+  if (aFirstFeature && aFirstFeature->isInitialized()) {
+    aShape1 = aFirstFeature->value();
+    if (!aShape1 && aFirstFeature->context())
+      aShape1 = aFirstFeature->context()->shape();
+  }
+
+  AttributeSelectionPtr aSecondFeature = selection(DISTANCE_TO_OBJECT_ID());
+  GeomShapePtr aShape2;
+  if (aSecondFeature && aSecondFeature->isInitialized()) {
+    aShape2 = aSecondFeature->value();
+    if (!aShape2 && aSecondFeature->context())
+      aShape2 = aSecondFeature->context()->shape();
+  }
+
+  if (!aShape1 || !aShape2) {
+    string(RESULT_ID())->setValue("");
+    return;
+  }
+
+  double aDistance = GeomAlgoAPI_ShapeTools::shapeProximity(aShape1, aShape2);
+
+  std::ostringstream anOutput;
+  anOutput << "Proximity = " << std::setprecision(10) << aDistance;
+  string(RESULT_ID())->setValue(anOutput.str());
+
+  AttributeDoubleArrayPtr aValues =
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+  aValues->setSize(1);
+  aValues->setValue(0, aDistance);
+}
+
 void FeaturesPlugin_Measurement::computeRadius()
 {
   AttributeSelectionPtr aSelectedFeature = selection(CIRCULAR_OBJECT_ID());