Mesh: minor change to exporter based on suggestion

This commit is contained in:
Zheng, Lei
2021-01-07 11:57:22 +08:00
committed by wwmayer
parent ea61253c67
commit db9525e7d7
2 changed files with 17 additions and 8 deletions

View File

@@ -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);

View File

@@ -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;
};