diff --git a/src/Mod/Measure/App/Measurement.cpp b/src/Mod/Measure/App/Measurement.cpp
index 7068f3801b..2b195f77a4 100644
--- a/src/Mod/Measure/App/Measurement.cpp
+++ b/src/Mod/Measure/App/Measurement.cpp
@@ -42,6 +42,7 @@
#include
#include
+#include
#include
#include
@@ -281,27 +282,22 @@ MeasureType Measurement::getType()
return measureType;
}
-TopoDS_Shape Measurement::getShape(App::DocumentObject* obj, const char* subName) const
+TopoDS_Shape Measurement::getShape(App::DocumentObject* rootObj, const char* subName) const
{
- // temporary fix to get "Vertex7" from "Body003.Pocket020.Vertex7"
- // when selected, Body features are provided as featureName and subNameAndIndex
- // other sources provide the full extended name with index
- if (strcmp(subName, "") == 0) {
- return Part::Feature::getShape(obj);
- }
- std::string workingSubName(subName);
- size_t lastDot = workingSubName.rfind('.');
- if (lastDot != std::string::npos) {
- workingSubName = workingSubName.substr(lastDot + 1);
+ std::vector names = Base::Tools::splitSubName(subName);
+
+ if (names.empty() || names.back() == "") {
+ return Part::Feature::getShape(rootObj);
}
try {
+ App::DocumentObject* obj = rootObj->getSubObject(subName);
+
Part::TopoShape partShape = Part::Feature::getTopoShape(obj);
- App::GeoFeature* geoFeat = dynamic_cast(obj);
- if (geoFeat) {
- partShape.setPlacement(geoFeat->globalPlacement());
- }
- TopoDS_Shape shape = partShape.getSubShape(workingSubName.c_str());
+
+ partShape.setPlacement(App::GeoFeature::getGlobalPlacement(obj, rootObj, subName));
+
+ TopoDS_Shape shape = partShape.getSubShape(names.back().c_str());
if (shape.IsNull()) {
throw Part::NullShapeException("null shape in measurement");
}
diff --git a/src/Mod/Measure/Gui/QuickMeasure.cpp b/src/Mod/Measure/Gui/QuickMeasure.cpp
index af142c7c31..7d513505d5 100644
--- a/src/Mod/Measure/Gui/QuickMeasure.cpp
+++ b/src/Mod/Measure/Gui/QuickMeasure.cpp
@@ -117,19 +117,23 @@ void QuickMeasure::addSelectionToMeasurement()
int count = 0;
int limit = 100;
- for (auto& selObj : Gui::Selection().getSelectionEx()) {
- App::DocumentObject* obj = selObj.getObject();
-
+ // Lambda function to check whether to continue
+ auto shouldSkip = [](App::DocumentObject* obj) {
std::string vpType = obj->getViewProviderName();
auto* vp = Gui::Application::Instance->getViewProvider(obj);
- if ((vpType == "SketcherGui::ViewProviderSketch" && vp->isEditing())
+ return (vpType == "SketcherGui::ViewProviderSketch" && vp->isEditing())
|| vpType.find("Gui::ViewProviderOrigin") != std::string::npos
|| vpType.find("Gui::ViewProviderPart") != std::string::npos
|| vpType.find("SpreadsheetGui") != std::string::npos
- || vpType.find("TechDrawGui") != std::string::npos) {
- continue;
- }
+ || vpType.find("TechDrawGui") != std::string::npos;
+ };
+ auto selObjs = Gui::Selection().getSelectionEx(nullptr,
+ App::DocumentObject::getClassTypeId(),
+ Gui::ResolveMode::NoResolve);
+
+ for (auto& selObj : selObjs) {
+ App::DocumentObject* rootObj = selObj.getObject();
const std::vector subNames = selObj.getSubNames();
// Check that there's not too many selection
@@ -140,12 +144,19 @@ void QuickMeasure::addSelectionToMeasurement()
}
if (subNames.empty()) {
- measurement->addReference3D(obj, "");
- }
- else {
- for (auto& subName : subNames) {
- measurement->addReference3D(obj, subName);
+ if (!shouldSkip(rootObj)) {
+ measurement->addReference3D(rootObj, "");
}
+ continue;
+ }
+
+ for (auto& subName : subNames) {
+ App::DocumentObject* obj = rootObj->getSubObject(subName.c_str());
+
+ if (shouldSkip(obj)) {
+ continue;
+ }
+ measurement->addReference3D(rootObj, subName);
}
}
}