Merge pull request #15501 from bgbsww/bgbsww-toponamingSaveRestore4
Toponaming: Transfer in getLinksTo
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <Base/Writer.h>
|
||||
|
||||
#include "PropertyGeometryList.h"
|
||||
#include "GeometryMigrationExtension.h"
|
||||
#include "GeometryPy.h"
|
||||
#include "Part2DObject.h"
|
||||
|
||||
@@ -84,26 +85,43 @@ void PropertyGeometryList::setValue(const Geometry* lValue)
|
||||
void PropertyGeometryList::setValues(const std::vector<Geometry*>& lValue)
|
||||
{
|
||||
auto copy = lValue;
|
||||
for(auto &geo : copy) // copy of the individual geometry pointers
|
||||
geo = geo->clone();
|
||||
|
||||
setValues(std::move(copy));
|
||||
aboutToSetValue();
|
||||
std::sort(_lValueList.begin(), _lValueList.end());
|
||||
for (auto & geo : copy) {
|
||||
auto range = std::equal_range(_lValueList.begin(), _lValueList.end(), geo);
|
||||
// clone if the new entry does not exist in the original value list, or
|
||||
// else, simply reuse it (i.e. erase it so that it won't get deleted below).
|
||||
if (range.first == range.second)
|
||||
geo = geo->clone();
|
||||
else
|
||||
_lValueList.erase(range.first, range.second);
|
||||
}
|
||||
for (auto v : _lValueList)
|
||||
delete v;
|
||||
_lValueList = std::move(copy);
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyGeometryList::setValues(std::vector<Geometry*> &&lValue)
|
||||
{
|
||||
// Unlike above, the moved version of setValues() indicates the caller want
|
||||
// us to manager the memory of the passed in values. So no need clone.
|
||||
aboutToSetValue();
|
||||
std::set<Geometry*> valueSet(_lValueList.begin(),_lValueList.end());
|
||||
for(auto v : lValue)
|
||||
valueSet.erase(v);
|
||||
std::sort(_lValueList.begin(), _lValueList.end());
|
||||
for (auto geo : lValue) {
|
||||
auto range = std::equal_range(_lValueList.begin(), _lValueList.end(), geo);
|
||||
_lValueList.erase(range.first, range.second);
|
||||
}
|
||||
for (auto geo : _lValueList)
|
||||
delete geo;
|
||||
_lValueList = std::move(lValue);
|
||||
for(auto v : valueSet)
|
||||
delete v;
|
||||
hasSetValue();
|
||||
}
|
||||
|
||||
void PropertyGeometryList::set1Value(int idx, std::unique_ptr<Geometry> &&lValue)
|
||||
{
|
||||
if (!lValue)
|
||||
return;
|
||||
if(idx>=(int)_lValueList.size())
|
||||
throw Base::IndexError("Index out of bound");
|
||||
aboutToSetValue();
|
||||
@@ -171,6 +189,12 @@ void PropertyGeometryList::trySaveGeometry(Geometry * geom, Base::Writer &writer
|
||||
// Not all geometry classes implement Save() and throw an exception instead
|
||||
try {
|
||||
geom->Save(writer);
|
||||
for( auto & ext : geom->getExtensions() ) {
|
||||
auto extension = ext.lock();
|
||||
auto gpe = freecad_dynamic_cast<GeometryMigrationPersistenceExtension>(extension.get());
|
||||
if (gpe)
|
||||
gpe->postSave(writer);
|
||||
}
|
||||
}
|
||||
catch (const Base::NotImplementedError& e) {
|
||||
Base::Console().Warning(std::string("PropertyGeometryList"), "Not yet implemented: %s\n", e.what());
|
||||
@@ -181,6 +205,17 @@ void PropertyGeometryList::tryRestoreGeometry(Geometry * geom, Base::XMLReader &
|
||||
{
|
||||
// Not all geometry classes implement Restore() and throw an exception instead
|
||||
try {
|
||||
if (!reader.getAttributeAsInteger("migrated", "0") && reader.hasAttribute("id")) {
|
||||
auto ext = std::make_unique<GeometryMigrationExtension>();
|
||||
ext->setId(reader.getAttributeAsInteger("id"));
|
||||
if(reader.hasAttribute("ref")) {
|
||||
const char *ref = reader.getAttribute("ref");
|
||||
int index = reader.getAttributeAsInteger("refIndex", "1");
|
||||
unsigned long flags = (unsigned long)reader.getAttributeAsUnsigned("flags");
|
||||
ext->setReference(ref, index, flags);
|
||||
}
|
||||
geom->setExtension(std::move(ext));
|
||||
}
|
||||
geom->Restore(reader);
|
||||
}
|
||||
catch (const Base::NotImplementedError& e) {
|
||||
@@ -193,8 +228,16 @@ void PropertyGeometryList::Save(Writer &writer) const
|
||||
writer.Stream() << writer.ind() << "<GeometryList count=\"" << getSize() <<"\">" << endl;
|
||||
writer.incInd();
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
writer.Stream() << writer.ind() << "<Geometry type=\""
|
||||
<< _lValueList[i]->getTypeId().getName() << "\">" << endl;;
|
||||
writer.Stream() << writer.ind() << "<Geometry type=\""
|
||||
<< _lValueList[i]->getTypeId().getName() << "\"" << endl;
|
||||
for( auto &e : _lValueList[i]->getExtensions() ) {
|
||||
auto ext = e.lock();
|
||||
auto gpe = freecad_dynamic_cast<GeometryMigrationPersistenceExtension>(ext.get());
|
||||
if (gpe)
|
||||
gpe->preSave(writer);
|
||||
}
|
||||
writer.Stream() << " migrated=\"1\">\n";
|
||||
|
||||
writer.incInd();
|
||||
trySaveGeometry(_lValueList[i], writer);
|
||||
writer.decInd();
|
||||
@@ -263,3 +306,10 @@ unsigned int PropertyGeometryList::getMemSize() const
|
||||
size += _lValueList[i]->getMemSize();
|
||||
return size;
|
||||
}
|
||||
|
||||
void PropertyGeometryList::moveValues(PropertyGeometryList &&other)
|
||||
{
|
||||
setValues(std::move(other._lValueList));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -64,8 +64,10 @@ public:
|
||||
void setValues(const std::vector<Geometry*>&);
|
||||
void setValues(std::vector<Geometry*>&&);
|
||||
|
||||
void moveValues(PropertyGeometryList &&other);
|
||||
|
||||
/// index operator
|
||||
const Geometry *operator[] (const int idx) const {
|
||||
Geometry *operator[] (const int idx) const {
|
||||
return _lValueList[idx];
|
||||
}
|
||||
|
||||
|
||||
@@ -303,8 +303,14 @@ void PropertyPartShape::Save (Base::Writer &writer) const
|
||||
writer.Stream() << " file=\""
|
||||
<< writer.addFile(getFileName(binary?".bin":".brp").c_str(), this)
|
||||
<< "\"/>\n";
|
||||
} else if(binary) {
|
||||
writer.Stream() << " binary=\"1\">\n";
|
||||
_Shape.exportBinary(writer.beginCharStream(Base::CharStreamFormat::Base64Encoded));
|
||||
writer.endCharStream() << writer.ind() << "</Part>\n";
|
||||
} else {
|
||||
writer.Stream() << "/>\n";
|
||||
writer.Stream() << " brep=\"1\">\n";
|
||||
_Shape.exportBrep(writer.beginCharStream(Base::CharStreamFormat::Raw)<<'\n');
|
||||
writer.endCharStream() << '\n' << writer.ind() << "</Part>\n";
|
||||
}
|
||||
|
||||
if(_SaveHasher) {
|
||||
|
||||
@@ -423,7 +423,7 @@ App::DocumentObject *Feature::getSubObject(const char *subname,
|
||||
if (dot) {
|
||||
auto body = PartDesign::Body::findBodyOf(this);
|
||||
if (body) {
|
||||
auto feat = body->Group.find(std::string(subname, dot));
|
||||
auto feat = body->Group.findUsingMap(std::string(subname, dot));
|
||||
if (feat) {
|
||||
Base::Matrix4D _mat;
|
||||
if (!transform) {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObserver.h>
|
||||
#include <App/Expression.h>
|
||||
#include <App/ExpressionParser.h>
|
||||
#include <App/ExpressionVisitors.h>
|
||||
@@ -2267,3 +2268,52 @@ bool PropertySheet::hasSpan() const
|
||||
{
|
||||
return !mergedCells.empty();
|
||||
}
|
||||
|
||||
void PropertySheet::getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
|
||||
App::DocumentObject* obj,
|
||||
const char* subname,
|
||||
bool all) const
|
||||
{
|
||||
Expression::DepOption option =
|
||||
all ? Expression::DepOption::DepAll : Expression::DepOption::DepNormal;
|
||||
|
||||
App::SubObjectT objT(obj, subname);
|
||||
auto subObject = objT.getSubObject();
|
||||
auto subElement = objT.getOldElementName();
|
||||
|
||||
auto owner = Base::freecad_dynamic_cast<App::DocumentObject>(getContainer());
|
||||
for (const auto& [cellName, cellExpression] : data) {
|
||||
if (auto expr = cellExpression->getExpression()) {
|
||||
const auto& deps = expr->getDeps(option);
|
||||
auto it = deps.find(obj);
|
||||
if (it == deps.end()) {
|
||||
continue;
|
||||
}
|
||||
const auto [docObj, depsList] = *it;
|
||||
for (auto& [depName, paths] : depsList) {
|
||||
if (!subname) {
|
||||
identifiers.emplace_back(owner, cellName.toString().c_str());
|
||||
break;
|
||||
}
|
||||
bool found = false;
|
||||
for (const auto& path : paths) {
|
||||
if (path.getSubObjectName() == subname) {
|
||||
identifiers.emplace_back(owner, cellName.toString().c_str());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
App::SubObjectT sobjT(obj, path.getSubObjectName().c_str());
|
||||
if (sobjT.getSubObject() == subObject
|
||||
&& sobjT.getOldElementName() == subElement) {
|
||||
identifiers.emplace_back(owner, cellName.toString().c_str());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,11 @@ public:
|
||||
|
||||
void Restore(Base::XMLReader& reader) override;
|
||||
|
||||
void getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
|
||||
App::DocumentObject* obj,
|
||||
const char* subname = nullptr,
|
||||
bool all = false) const override;
|
||||
|
||||
void copyCells(Base::Writer& writer, const std::vector<App::Range>& ranges) const;
|
||||
|
||||
void pasteCells(Base::XMLReader& reader, App::Range dstRange);
|
||||
|
||||
Reference in New Issue
Block a user