Mesh: minor change to exporter based on suggestion
This commit is contained in:
@@ -50,9 +50,9 @@ using namespace Mesh;
|
||||
using namespace MeshCore;
|
||||
|
||||
static std::vector<std::string>
|
||||
expandSubObjects(const App::DocumentObject *obj,
|
||||
std::map<const App::DocumentObject*, std::vector<std::string> > &cache,
|
||||
int depth)
|
||||
expandSubObjectNames(const App::DocumentObject *obj,
|
||||
std::map<const App::DocumentObject*, std::vector<std::string> > &subObjectNameCache,
|
||||
int depth)
|
||||
{
|
||||
if (!App::GetApplication().checkLinkDepth(depth))
|
||||
return {};
|
||||
@@ -72,9 +72,10 @@ expandSubObjects(const App::DocumentObject *obj,
|
||||
if (!sobj || (vis < 0 && !sobj->Visibility.getValue()))
|
||||
continue;
|
||||
auto linked = sobj->getLinkedObject(true);
|
||||
auto it = cache.find(linked);
|
||||
if (it == cache.end())
|
||||
it = cache.emplace(linked, expandSubObjects(linked, cache, depth+1)).first;
|
||||
auto it = subObjectNameCache.find(linked);
|
||||
if (it == subObjectNameCache.end())
|
||||
it = subObjectNameCache.emplace(
|
||||
linked, expandSubObjectNames(linked, subObjectNameCache, depth+1)).first;
|
||||
for (auto & ssub : it->second)
|
||||
res.push_back(sub + ssub);
|
||||
}
|
||||
@@ -99,7 +100,7 @@ std::string Exporter::xmlEscape(const std::string &input)
|
||||
int Exporter::addObject(App::DocumentObject *obj, float tol)
|
||||
{
|
||||
int count = 0;
|
||||
for (std::string & sub : expandSubObjects(obj, cache, 0)) {
|
||||
for (std::string & sub : expandSubObjectNames(obj, subObjectNameCache, 0)) {
|
||||
Base::Matrix4D matrix;
|
||||
auto sobj = obj->getSubObject(sub.c_str(), nullptr, &matrix);
|
||||
auto linked = sobj->getLinkedObject(true, &matrix, false);
|
||||
|
||||
@@ -52,6 +52,14 @@ class Exporter
|
||||
Exporter();
|
||||
virtual ~Exporter() = default;
|
||||
|
||||
/// Add object and all subobjects and links etc. Returns the number of stuff added.
|
||||
/*!
|
||||
* @param obj The object to export. If this is a group like object, its
|
||||
* sub-objects will be added.
|
||||
* @param tol The tolerance/accuracy with which to generate the triangle mesh
|
||||
* @return The number of objects/subobjects that was exported from the document.
|
||||
See the parameter `accuracy` of ComplexGeoData::getFaces
|
||||
*/
|
||||
int addObject(App::DocumentObject *obj, float tol);
|
||||
|
||||
virtual bool addMesh(const char *name, const MeshObject & mesh) = 0;
|
||||
@@ -60,7 +68,7 @@ class Exporter
|
||||
/// Does some simple escaping of characters for XML-type exports
|
||||
static std::string xmlEscape(const std::string &input);
|
||||
|
||||
std::map<const App::DocumentObject *, std::vector<std::string> > cache;
|
||||
std::map<const App::DocumentObject *, std::vector<std::string> > subObjectNameCache;
|
||||
std::map<const App::DocumentObject *, MeshObject> meshCache;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user