Measure: Fix quickmeasure globalplacement.

This commit is contained in:
PaddleStroke
2024-09-17 09:44:58 +02:00
committed by Chris Hennes
parent 3a1a6d35ee
commit 0be29b11b7
2 changed files with 35 additions and 28 deletions

View File

@@ -42,6 +42,7 @@
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/TopoShape.h>
@@ -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<std::string> 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<App::GeoFeature*>(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");
}

View File

@@ -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<std::string> 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);
}
}
}