Toponaming: add code to implement guessing missing references

This commit is contained in:
bgbsww
2024-08-03 13:21:01 -04:00
committed by Chris Hennes
parent 87cc683ccc
commit 80045d0e88
4 changed files with 34 additions and 2 deletions

View File

@@ -313,6 +313,9 @@ App::ElementNamePair Feature::getExportElementName(TopoShape shape,
auto names =
shape.decodeElementComboName(idxName, mapped.name, idxName.getType(), &postfix);
std::vector<int> ancestors;
// TODO: if names.empty() then the existing heuristic has failed to find anything
// and we're going to flag this element as missing. This is the place to add
// heuristics as we develop them.
for (auto& name : names) {
auto index = shape.getIndexedName(name);
if (!index) {
@@ -1697,6 +1700,16 @@ bool Feature::getCameraAlignmentDirection(Base::Vector3d& direction, const char*
return GeoFeature::getCameraAlignmentDirection(direction, subname);
}
void Feature::guessNewLink(std::string &replacementName, DocumentObject *base, const char *oldLink) {
for (auto &element : Part::Feature::getRelatedElements(base, oldLink)) {
replacementName.clear();
element.index.appendToStringBuffer(replacementName);
FC_WARN("Feature guess element reference " << oldLink << " -> " << replacementName);
return;
}
replacementName = oldLink;
}
// ---------------------------------------------------------
PROPERTY_SOURCE(Part::FilletBase, Part::Feature)

View File

@@ -153,7 +153,10 @@ public:
static bool isElementMappingDisabled(App::PropertyContainer *container);
bool getCameraAlignmentDirection(Base::Vector3d& direction, const char* subname) const override;
bool getCameraAlignmentDirection(Base::Vector3d &direction, const char *subname) const override;
static void guessNewLink(std::string &replacementName, DocumentObject *base, const char *oldLink);
#ifdef FC_USE_TNP_FIX
const std::vector<std::string>& searchElementCache(const std::string &element,

View File

@@ -461,6 +461,22 @@ TaskDlgDressUpParameters::TaskDlgDressUpParameters(ViewProviderDressUp *DressUpV
, parameter(nullptr)
{
assert(DressUpView);
auto pcDressUp = dynamic_cast<PartDesign::DressUp*>(DressUpView->getObject());
auto base = pcDressUp->Base.getValue();
std::vector<std::string> newSubList;
bool changed = false;
auto& shadowSubs = pcDressUp->Base.getShadowSubs();
for ( auto &shadowSub : shadowSubs ) {
auto displayName = shadowSub.oldName;
// If there is a missing tag on the shadow sub, take a guess at a new name.
if ( boost::starts_with(shadowSub.oldName,Data::MISSING_PREFIX)) {
Part::Feature::guessNewLink(displayName, base, shadowSub.newName.c_str());
newSubList.emplace_back(displayName);
changed = true;
}
}
if ( changed )
pcDressUp->Base.setValue(base, newSubList);
}
TaskDlgDressUpParameters::~TaskDlgDressUpParameters() = default;

View File

@@ -95,7 +95,7 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi
connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked,
this, &TaskFilletParameters::doubleClicked);
if (strings.size() == 0)
if (strings.empty())
setSelectionMode(refSel);
else
hideOnError();