]> 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 e8cb398bbaef07d497911473ee0dee53fcf3eb18..2bae620a3255f24e6a675621e3bb419e8426ebbb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2021  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
 #include <PrsDim_AngleDimension.hxx>
 #include <BRepExtrema_DistShapeShape.hxx>
 
+#include <Basics_OCCTVersion.hxx>
+
 #include <iomanip>
 #include <sstream>
+#include <array>
 
 FeaturesPlugin_Measurement::FeaturesPlugin_Measurement() : mySceenScale(1)
 {
@@ -90,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())
@@ -181,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());
@@ -616,6 +657,12 @@ void FeaturesPlugin_Measurement::setupDimension(AISObjectPtr theDim)
     std::string aFont = Config_PropManager::string("Visualization", "dimension_font");
 
     Handle(Prs3d_DimensionAspect) anAspect = aDim->DimensionAspect();
+#if OCC_VERSION_LARGE >= 0x07070000
+    if (anAspect.IsNull()) {
+      aDim->Attributes()->SetupOwnDefaults();
+      anAspect = aDim->DimensionAspect();
+    }
+#endif
     anAspect->MakeArrows3d(false);
     anAspect->MakeText3d(false);
     anAspect->MakeTextShaded(false);