Measure: Fix crash when removing referenced element

Also improve error messages
Fixes #16183
This commit is contained in:
hlorus
2024-09-02 11:20:21 +02:00
committed by WandererFan
parent 6ef51daec1
commit b07b257542
9 changed files with 27 additions and 36 deletions

View File

@@ -95,12 +95,6 @@ void MeasureArea::parseSelection(const App::MeasureSelection& selection)
App::DocumentObjectExecReturn* MeasureArea::execute()
{
recalculateArea();
return DocumentObject::StdReturn;
}
void MeasureArea::recalculateArea()
{
const std::vector<App::DocumentObject*>& objects = Elements.getValues();
const std::vector<std::string>& subElements = Elements.getSubValues();
@@ -113,15 +107,17 @@ void MeasureArea::recalculateArea()
auto info = getMeasureInfo(subject);
if (!info || !info->valid) {
continue;
return new App::DocumentObjectExecReturn("Cannot calculate area");
}
auto areaInfo = std::dynamic_pointer_cast<Part::MeasureAreaInfo>(info);
result += areaInfo->area;
}
Area.setValue(result);
return DocumentObject::StdReturn;
}
void MeasureArea::onChanged(const App::Property* prop)
{
if (isRestoring() || isRemoving()) {
@@ -129,7 +125,8 @@ void MeasureArea::onChanged(const App::Property* prop)
}
if (prop == &Elements) {
recalculateArea();
auto ret = recompute();
delete ret;
}
MeasureBase::onChanged(prop);