Skip to content

Commit

Permalink
Toponaming: Refactor out duplicated code using elementMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
bgbsww authored and chennes committed Aug 10, 2024
1 parent aab0b31 commit 99b753b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 63 deletions.
9 changes: 9 additions & 0 deletions src/App/ComplexGeoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ ElementMapPtr ComplexGeoData::elementMap(bool flush) const
return _elementMap;
}

ElementMapPtr ComplexGeoData::ensureElementMap(bool flush)
{
if (!_elementMap) {
resetElementMap(std::make_shared<Data::ElementMap>());
}
return elementMap(flush);

}

void ComplexGeoData::flushElementMap() const
{}

Expand Down
1 change: 1 addition & 0 deletions src/App/ComplexGeoData.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ class AppExport ComplexGeoData: public Base::Persistence, public Base::Handled

protected:
ElementMapPtr elementMap(bool flush=true) const;
ElementMapPtr ensureElementMap(bool flush=true);

private:
ElementMapPtr _elementMap;
Expand Down
70 changes: 7 additions & 63 deletions src/Mod/Part/App/TopoShapeExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,16 +878,8 @@ void TopoShape::mapSubElementTypeForShape(const TopoShape& other,
}
char elementType {shapeName(type)[0]};

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

std::ostringstream ss;
elementMap()->encodeElementName(elementType, name, ss, &sids, Tag, op, other.Tag);
ensureElementMap()->encodeElementName(elementType, name, ss, &sids, Tag, op, other.Tag);
elementMap()->setElementName(element, name, Tag, &sids);
}
}
Expand Down Expand Up @@ -1033,15 +1025,7 @@ void TopoShape::mapSubElement(const TopoShape& other, const char* op, bool force
}
ss.str("");

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

elementMap()->encodeElementName(shapetype[0], name, ss, &sids, Tag, op, other.Tag);
ensureElementMap()->encodeElementName(shapetype[0], name, ss, &sids, Tag, op, other.Tag);
elementMap()->setElementName(element, name, Tag, &sids);
}
}
Expand Down Expand Up @@ -1784,15 +1768,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape,
}
Data::MappedName other_name = other_key.name;

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

elementMap()->encodeElementName(*other_info.shapetype,
ensureElementMap()->encodeElementName(*other_info.shapetype,
other_name,
ss2,
&sids,
Expand Down Expand Up @@ -1845,15 +1821,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape,
}
ss << postfix;

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

elementMap()
ensureElementMap()
->encodeElementName(element[0], first_name, ss, &sids, Tag, op, first_key.tag);
elementMap()->setElementName(element, first_name, Tag, &sids);
if (!delayed && first_key.shapetype < 3) {
Expand Down Expand Up @@ -1943,15 +1911,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape,
ss << nameInfo.index;
}

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

elementMap()->encodeElementName(indexedName[0], newName, ss, &sids, Tag, op);
ensureElementMap()->encodeElementName(indexedName[0], newName, ss, &sids, Tag, op);
elementMap()->setElementName(indexedName, newName, Tag, &sids);
}
}
Expand Down Expand Up @@ -2049,15 +2009,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape,
}
}

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

elementMap()->encodeElementName(element[0], newName, ss, &sids, Tag, op);
ensureElementMap()->encodeElementName(element[0], newName, ss, &sids, Tag, op);
elementMap()->setElementName(element, newName, Tag, &sids);
}
}
Expand Down Expand Up @@ -5092,15 +5044,7 @@ Data::MappedName TopoShape::setElementComboName(const Data::IndexedName& element
}
}

// Originally in ComplexGeoData::setElementName
// LinkStable/src/App/ComplexGeoData.cpp#L1631
// No longer possible after map separated in ElementMap.cpp

if (!elementMap()) {
resetElementMap(std::make_shared<Data::ElementMap>());
}

elementMap()->encodeElementName(element[0], newName, ss, &sids, Tag, op);
ensureElementMap()->encodeElementName(element[0], newName, ss, &sids, Tag, op);
return elementMap()->setElementName(element, newName, Tag, &sids);
}

Expand Down

0 comments on commit 99b753b

Please sign in to comment.