Merge pull request #18791 from CalligaroV/toponaming-ElementMapVersion-code-from-LS3

[Toponaming] Import code releted to _ElementMapVersion from LS3
This commit is contained in:
Chris Hennes
2025-02-14 10:54:38 -06:00
committed by GitHub
10 changed files with 216 additions and 3 deletions

View File

@@ -1581,6 +1581,12 @@ Feature* Feature::create(const TopoShape& shape, const char* name, App::Document
return res;
}
void Feature::onDocumentRestored()
{
// expandShapeContents();
App::GeoFeature::onDocumentRestored();
}
ShapeHistory Feature::buildHistory(BRepBuilderAPI_MakeShape& mkShape, TopAbs_ShapeEnum type,
const TopoDS_Shape& newS, const TopoDS_Shape& oldS)
{

View File

@@ -168,6 +168,7 @@ protected:
App::DocumentObjectExecReturn *execute() override;
void onBeforeChange(const App::Property* prop) override;
void onChanged(const App::Property* prop) override;
void onDocumentRestored() override;
void copyMaterial(Feature* feature);
void copyMaterial(App::DocumentObject* link);

View File

@@ -587,11 +587,25 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
void PropertyPartShape::RestoreDocFile(Base::Reader &reader)
{
// save the element map
auto elementMap = _Shape.resetElementMap();
auto hasher = _Shape.Hasher;
Base::FileInfo brep(reader.getFileName());
TopoShape shape;
// In LS3 the following statement is executed right before shape.Hasher = hasher;
// https://github.com/realthunder/FreeCAD/blob/a9810d509a6f112b5ac03d4d4831b67e6bffd5b7/src/Mod/Part/App/PropertyTopoShape.cpp#L639
// Now it's not possible anymore because both PropertyPartShape::loadFromFile() and
// PropertyPartShape::loadFromStream() calls PropertyPartShape::setValue() which clears the
// value of _Ver.
// Therefor we're storing the value of _Ver here so that we don't lose it.
std::string ver = _Ver;
if (brep.hasExtension("bin")) {
TopoShape shape;
shape.importBinary(reader);
setValue(shape);
}
else {
bool direct = App::GetApplication().GetParameterGroupByPath
@@ -604,7 +618,14 @@ void PropertyPartShape::RestoreDocFile(Base::Reader &reader)
loadFromStream(reader);
reader.exceptions(iostate);
}
shape = getValue();
}
// restore the element map
shape.Hasher = hasher;
shape.resetElementMap(elementMap);
setValue(shape);
_Ver = ver;
}
// -------------------------------------------------------------------------

View File

@@ -1502,6 +1502,8 @@ public:
void mapSubElementsTo(std::vector<TopoShape>& shapes, const char* op = nullptr) const;
bool hasPendingElementMap() const;
std::string getElementMapVersion() const override;
void flushElementMap() const override;
Data::ElementMapPtr resetElementMap(

View File

@@ -2057,6 +2057,27 @@ TopoShape TopoShape::getSubTopoShape(TopAbs_ShapeEnum type, int idx, bool silent
return shapeMap.getTopoShape(*this, idx);
}
static const std::string& _getElementMapVersion()
{
static std::string _ver;
if (_ver.empty()) {
std::ostringstream ss;
// Stabilize the reported OCCT version: report 7.2.0 as the version so that we aren't
// constantly inadvertently reporting differing versions. This is retained for
// cross-compatibility with LinkStage3 (which retains supporting code for OCCT 6.x,
// removed here).
unsigned occ_ver {0x070200};
ss << OpCodes::Version << '.' << std::hex << occ_ver << '.';
_ver = ss.str();
}
return _ver;
}
std::string TopoShape::getElementMapVersion() const
{
return _getElementMapVersion() + Data::ComplexGeoData::getElementMapVersion();
}
TopoShape& TopoShape::makeElementEvolve(const TopoShape& spine,
const TopoShape& profile,
JoinType join,