Toponaming: import code related to ElementMapVersion from LS3
*Imported original code
This commit is contained in:
committed by
Vincenzo Calligaro
parent
e5b1d05813
commit
89ec079fbf
@@ -48,6 +48,11 @@ PROPERTY_SOURCE(App::GeoFeature, App::DocumentObject)
|
||||
GeoFeature::GeoFeature()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Placement, (Base::Placement()), nullptr, Prop_NoRecompute, nullptr);
|
||||
ADD_PROPERTY_TYPE(_ElementMapVersion,
|
||||
(""),
|
||||
"Base",
|
||||
(App::PropertyType)(Prop_Output | Prop_Hidden | Prop_Transient),
|
||||
"");
|
||||
}
|
||||
|
||||
GeoFeature::~GeoFeature() = default;
|
||||
@@ -244,6 +249,16 @@ void GeoFeature::updateElementReference()
|
||||
return;
|
||||
}
|
||||
bool reset = false;
|
||||
|
||||
auto version = getElementMapVersion(prop);
|
||||
if (_ElementMapVersion.getStrValue().empty()) {
|
||||
_ElementMapVersion.setValue(version);
|
||||
}
|
||||
else if (_ElementMapVersion.getStrValue() != version) {
|
||||
reset = true;
|
||||
_ElementMapVersion.setValue(version);
|
||||
}
|
||||
|
||||
PropertyLinkBase::updateElementReferences(this, reset);
|
||||
}
|
||||
|
||||
@@ -258,6 +273,14 @@ void GeoFeature::onChanged(const Property* prop)
|
||||
DocumentObject::onChanged(prop);
|
||||
}
|
||||
|
||||
void GeoFeature::onDocumentRestored()
|
||||
{
|
||||
if (!getDocument()->testStatus(Document::Status::Importing)) {
|
||||
_ElementMapVersion.setValue(getElementMapVersion(getPropertyOfGeometry(), true));
|
||||
}
|
||||
DocumentObject::onDocumentRestored();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GeoFeature::searchElementCache(const std::string& element,
|
||||
Data::SearchOptions options,
|
||||
double tol,
|
||||
|
||||
@@ -42,6 +42,7 @@ class AppExport GeoFeature: public App::DocumentObject
|
||||
|
||||
public:
|
||||
PropertyPlacement Placement;
|
||||
PropertyString _ElementMapVersion;
|
||||
|
||||
/// Constructor
|
||||
GeoFeature();
|
||||
@@ -198,7 +199,7 @@ public:
|
||||
|
||||
protected:
|
||||
void onChanged(const Property* prop) override;
|
||||
// void onDocumentRestored() override;
|
||||
void onDocumentRestored() override;
|
||||
void updateElementReference();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1640,6 +1640,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)
|
||||
{
|
||||
|
||||
@@ -175,6 +175,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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -1502,6 +1502,8 @@ public:
|
||||
void mapSubElementsTo(std::vector<TopoShape>& shapes, const char* op = nullptr) const;
|
||||
bool hasPendingElementMap() const;
|
||||
|
||||
virtual std::string getElementMapVersion() const;
|
||||
|
||||
void flushElementMap() const override;
|
||||
|
||||
Data::ElementMapPtr resetElementMap(
|
||||
|
||||
@@ -2057,6 +2057,29 @@ 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;
|
||||
unsigned occ_ver;
|
||||
if ((OCC_VERSION_HEX & 0xFF0000) == 0x070000) {
|
||||
occ_ver = 0x070200;
|
||||
}
|
||||
else {
|
||||
occ_ver = OCC_VERSION_HEX;
|
||||
}
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user