-// 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
#include <PrsDim_AngleDimension.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
+#include <Basics_OCCTVersion.hxx>
+
#include <iomanip>
#include <sstream>
+#include <array>
FeaturesPlugin_Measurement::FeaturesPlugin_Measurement() : mySceenScale(1)
{
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())
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());
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);