Mesh: Apply clang-format

This commit is contained in:
wmayer
2023-09-22 19:59:39 +02:00
committed by wwmayer
parent 70ba930230
commit 23db389a76
116 changed files with 15683 additions and 12447 deletions

View File

@@ -22,12 +22,14 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <vector>
# include <boost/algorithm/string/replace.hpp>
# include <boost/core/ignore_unused.hpp>
#include <algorithm>
#include <boost/algorithm/string/replace.hpp>
#include <boost/core/ignore_unused.hpp>
#include <vector>
#endif
#include "Core/IO/Writer3MF.h"
#include "Core/Iterator.h"
#include <App/Application.h>
#include <App/ComplexGeoData.h>
#include <App/ComplexGeoDataPy.h>
@@ -38,8 +40,6 @@
#include <Base/Sequencer.h>
#include <Base/Stream.h>
#include <Base/Tools.h>
#include "Core/Iterator.h"
#include "Core/IO/Writer3MF.h"
#include <zipios++/zipoutputstream.h>
#include "Exporter.h"
@@ -48,13 +48,14 @@
using namespace Mesh;
using namespace MeshCore;
static std::vector<std::string>
expandSubObjectNames(const App::DocumentObject *obj,
std::map<const App::DocumentObject*, std::vector<std::string> > &subObjectNameCache,
int depth)
static std::vector<std::string> expandSubObjectNames(
const App::DocumentObject* obj,
std::map<const App::DocumentObject*, std::vector<std::string>>& subObjectNameCache,
int depth)
{
if (!App::GetApplication().checkLinkDepth(depth))
if (!App::GetApplication().checkLinkDepth(depth)) {
return {};
}
auto subs = obj->getSubObjects();
if (subs.empty()) {
@@ -63,28 +64,33 @@ expandSubObjectNames(const App::DocumentObject *obj,
}
std::vector<std::string> res;
for (auto & sub : subs) {
for (auto& sub : subs) {
int vis = sub.empty() ? 1 : obj->isElementVisible(sub.c_str());
if (vis == 0)
if (vis == 0) {
continue;
}
auto sobj = obj->getSubObject(sub.c_str());
if (!sobj || (vis < 0 && !sobj->Visibility.getValue()))
if (!sobj || (vis < 0 && !sobj->Visibility.getValue())) {
continue;
}
auto linked = sobj->getLinkedObject(true);
auto it = subObjectNameCache.find(linked);
if (it == subObjectNameCache.end())
it = subObjectNameCache.emplace(
linked, expandSubObjectNames(linked, subObjectNameCache, depth+1)).first;
for (auto & ssub : it->second)
if (it == subObjectNameCache.end()) {
it = subObjectNameCache
.emplace(linked, expandSubObjectNames(linked, subObjectNameCache, depth + 1))
.first;
}
for (auto& ssub : it->second) {
res.push_back(sub + ssub);
}
}
return res;
}
Exporter::Exporter() = default;
//static
std::string Exporter::xmlEscape(const std::string &input)
// static
std::string Exporter::xmlEscape(const std::string& input)
{
std::string out(input);
boost::replace_all(out, "&", "&amp;");
@@ -95,30 +101,32 @@ std::string Exporter::xmlEscape(const std::string &input)
return out;
}
int Exporter::addObject(App::DocumentObject *obj, float tol)
int Exporter::addObject(App::DocumentObject* obj, float tol)
{
int count = 0;
for (std::string & sub : expandSubObjectNames(obj, subObjectNameCache, 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);
auto it = meshCache.find(linked);
if (it == meshCache.end()) {
if (linked->isDerivedFrom(Mesh::Feature::getClassTypeId())) {
it = meshCache.emplace(linked,
static_cast<Mesh::Feature*>(linked)->Mesh.getValue()).first;
it = meshCache.emplace(linked, static_cast<Mesh::Feature*>(linked)->Mesh.getValue())
.first;
it->second.setTransform(matrix);
}
else {
Base::PyGILStateLocker lock;
PyObject *pyobj = nullptr;
PyObject* pyobj = nullptr;
linked->getSubObject("", &pyobj, nullptr, false);
if (!pyobj)
if (!pyobj) {
continue;
}
if (PyObject_TypeCheck(pyobj, &Data::ComplexGeoDataPy::Type)) {
std::vector<Base::Vector3d> aPoints;
std::vector<Data::ComplexGeoData::Facet> aTopo;
auto geoData = static_cast<Data::ComplexGeoDataPy*>(pyobj)->getComplexGeoDataPtr();
auto geoData =
static_cast<Data::ComplexGeoDataPy*>(pyobj)->getComplexGeoDataPtr();
geoData->getFaces(aPoints, aTopo, tol);
it = meshCache.emplace(linked, MeshObject()).first;
it->second.setFacets(aTopo, aPoints);
@@ -130,8 +138,9 @@ int Exporter::addObject(App::DocumentObject *obj, float tol)
// Add a new mesh
if (it != meshCache.end()) {
if (addMesh(sobj->Label.getValue(), it->second))
if (addMesh(sobj->Label.getValue(), it->second)) {
++count;
}
}
}
return count;
@@ -150,9 +159,8 @@ void Exporter::throwIfNoPermission(const std::string& filename)
// ----------------------------------------------------------------------------
MergeExporter::MergeExporter(std::string fileName, MeshIO::Format)
:fName(fileName)
{
}
: fName(fileName)
{}
MergeExporter::~MergeExporter()
{
@@ -176,40 +184,42 @@ void MergeExporter::write()
}
}
bool MergeExporter::addMesh(const char *name, const MeshObject & mesh)
bool MergeExporter::addMesh(const char* name, const MeshObject& mesh)
{
auto kernel = mesh.getKernel();
kernel.Transform(mesh.getTransform());
auto countFacets( mergingMesh.countFacets() );
auto countFacets(mergingMesh.countFacets());
if (countFacets == 0) {
mergingMesh.setKernel(kernel);
} else {
}
else {
mergingMesh.addMesh(kernel);
}
// if the mesh already has persistent segments then use them instead
unsigned long numSegm = mesh.countSegments();
unsigned long canSave = 0;
for (unsigned long i=0; i<numSegm; i++) {
if (mesh.getSegment(i).isSaved())
for (unsigned long i = 0; i < numSegm; i++) {
if (mesh.getSegment(i).isSaved()) {
canSave++;
}
}
if (canSave > 0) {
for (unsigned long i=0; i<numSegm; i++) {
for (unsigned long i = 0; i < numSegm; i++) {
const Segment& segm = mesh.getSegment(i);
if (segm.isSaved()) {
std::vector<FacetIndex> indices = segm.getIndices();
std::for_each( indices.begin(), indices.end(),
[countFacets] (FacetIndex &v) {
v += countFacets;
} );
std::for_each(indices.begin(), indices.end(), [countFacets](FacetIndex& v) {
v += countFacets;
});
Segment new_segm(&mergingMesh, indices, true);
new_segm.setName(segm.getName());
mergingMesh.addSegment(new_segm);
}
}
} else {
}
else {
// now create a segment for the added mesh
std::vector<FacetIndex> indices;
indices.resize(mergingMesh.countFacets() - countFacets);
@@ -233,10 +243,12 @@ void GuiExtension3MFProducer::initialize()
{
Base::PyGILStateLocker lock;
PyObject* module = PyImport_ImportModule("MeshGui");
if (module)
if (module) {
Py_DECREF(module);
else
}
else {
PyErr_Clear();
}
}
void Extension3MFFactory::addProducer(Extension3MFProducer* ext)
@@ -257,21 +269,22 @@ std::vector<Extension3MFPtr> Extension3MFFactory::createExtensions()
std::vector<Extension3MFPtr> ext;
for (const auto& it : producer) {
Extension3MFPtr ptr = std::dynamic_pointer_cast<Extension3MF>(it->create());
if (ptr)
if (ptr) {
ext.push_back(ptr);
}
}
return ext;
}
std::vector<Extension3MFProducerPtr> Extension3MFFactory::producer;
class Exporter3MF::Private {
class Exporter3MF::Private
{
public:
explicit Private(const std::string& filename,
const std::vector<Extension3MFPtr>& ext)
: writer3mf(filename)
, ext(ext) {
}
explicit Private(const std::string& filename, const std::vector<Extension3MFPtr>& ext)
: writer3mf(filename)
, ext(ext)
{}
MeshCore::Writer3MF writer3mf;
std::vector<Extension3MFPtr> ext;
};
@@ -287,7 +300,7 @@ Exporter3MF::~Exporter3MF()
write();
}
bool Exporter3MF::addMesh(const char *name, const MeshObject & mesh)
bool Exporter3MF::addMesh(const char* name, const MeshObject& mesh)
{
boost::ignore_unused(name);
bool ok = d->writer3mf.AddMesh(mesh.getKernel(), mesh.getTransform());
@@ -312,35 +325,35 @@ void Exporter3MF::write()
// ----------------------------------------------------------------------------
ExporterAMF::ExporterAMF( std::string fileName,
const std::map<std::string, std::string> &meta,
bool compress )
ExporterAMF::ExporterAMF(std::string fileName,
const std::map<std::string, std::string>& meta,
bool compress)
{
// ask for write permission
throwIfNoPermission(fileName);
Base::FileInfo fi(fileName);
if (compress) {
auto *zipStreamPtr( new zipios::ZipOutputStream(fi.filePath()) );
auto* zipStreamPtr(new zipios::ZipOutputStream(fi.filePath()));
// ISO 52915 specifies that compressed AMF files are zip-compressed and
// must contain the AMF XML in an entry with the same name as the
// compressed file. It's OK to have other files in the zip too.
zipStreamPtr->putNextEntry( zipios::ZipCDirEntry(fi.fileName()) );
zipStreamPtr->putNextEntry(zipios::ZipCDirEntry(fi.fileName()));
// Default compression seems to work fine.
outputStreamPtr = zipStreamPtr;
} else {
}
else {
outputStreamPtr = new Base::ofstream(fi, std::ios::out | std::ios::binary);
}
if (outputStreamPtr) {
*outputStreamPtr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
<< "<amf unit=\"millimeter\">\n";
for (auto const &metaEntry : meta) {
*outputStreamPtr << "\t<metadata type=\"" << metaEntry.first
<< "\">" << metaEntry.second << "</metadata>\n";
for (auto const& metaEntry : meta) {
*outputStreamPtr << "\t<metadata type=\"" << metaEntry.first << "\">"
<< metaEntry.second << "</metadata>\n";
}
}
}
@@ -370,25 +383,28 @@ void ExporterAMF::write()
class ExporterAMF::VertLess
{
public:
bool operator()(const Base::Vector3f &a, const Base::Vector3f &b) const
bool operator()(const Base::Vector3f& a, const Base::Vector3f& b) const
{
if (a.x == b.x) {
if (a.y == b.y) {
if (a.z == b.z) {
return false;
} else {
}
else {
return a.z < b.z;
}
} else {
}
else {
return a.y < b.y;
}
} else {
}
else {
return a.x < b.x;
}
}
};
bool ExporterAMF::addMesh(const char *name, const MeshObject & mesh)
bool ExporterAMF::addMesh(const char* name, const MeshObject& mesh)
{
auto kernel = mesh.getKernel();
kernel.Transform(mesh.getTransform());
@@ -397,7 +413,7 @@ bool ExporterAMF::addMesh(const char *name, const MeshObject & mesh)
return false;
}
auto numFacets( kernel.CountFacets() );
auto numFacets(kernel.CountFacets());
if (numFacets == 0) {
return false;
@@ -408,12 +424,11 @@ bool ExporterAMF::addMesh(const char *name, const MeshObject & mesh)
Base::SequencerLauncher seq("Saving...", 2 * numFacets + 1);
*outputStreamPtr << "\t<object id=\"" << nextObjectIndex << "\">\n";
*outputStreamPtr << "\t\t<metadata type=\"name\">"
<< xmlEscape(name) << "</metadata>\n";
*outputStreamPtr << "\t\t<metadata type=\"name\">" << xmlEscape(name) << "</metadata>\n";
*outputStreamPtr << "\t\t<mesh>\n"
<< "\t\t\t<vertices>\n";
const MeshCore::MeshGeomFacet *facet;
const MeshCore::MeshGeomFacet* facet;
// Iterate through all facets of the mesh, and construct a:
// * Cache (map) of used vertices, outputting each new unique vertex to
@@ -427,14 +442,14 @@ bool ExporterAMF::addMesh(const char *name, const MeshObject & mesh)
std::vector<unsigned long> facets;
// For each facet in mesh
for(clIter.Begin(), clEnd.End(); clIter < clEnd; ++clIter) {
for (clIter.Begin(), clEnd.End(); clIter < clEnd; ++clIter) {
facet = &(*clIter);
// For each vertex in facet
for (auto pnt : facet->_aclPoints) {
vertItr = vertices.find(pnt);
if ( vertItr == vertices.end() ) {
if (vertItr == vertices.end()) {
facets.push_back(vertexCount);
vertices[pnt] = vertexCount++;
@@ -442,20 +457,20 @@ bool ExporterAMF::addMesh(const char *name, const MeshObject & mesh)
// Output facet
*outputStreamPtr << "\t\t\t\t<vertex>\n"
<< "\t\t\t\t\t<coordinates>\n";
for ( auto j(0); j < 3; ++j) {
for (auto j(0); j < 3; ++j) {
char axis('x' + j);
*outputStreamPtr << "\t\t\t\t\t\t<" << axis << '>'
<< pnt[j]
<< "</" << axis << ">\n";
*outputStreamPtr << "\t\t\t\t\t\t<" << axis << '>' << pnt[j] << "</" << axis
<< ">\n";
}
*outputStreamPtr << "\t\t\t\t\t</coordinates>\n"
<< "\t\t\t\t</vertex>\n";
} else {
}
else {
facets.push_back(vertItr->second);
}
}
seq.next(true); // allow to cancel
seq.next(true); // allow to cancel
}
*outputStreamPtr << "\t\t\t</vertices>\n"
@@ -463,14 +478,13 @@ bool ExporterAMF::addMesh(const char *name, const MeshObject & mesh)
// Now that we've output all the vertices, we can
// output the facets that refer to them!
for (auto triItr(facets.begin()); triItr != facets.end(); ) {
for (auto triItr(facets.begin()); triItr != facets.end();) {
*outputStreamPtr << "\t\t\t\t<triangle>\n";
for (auto i(1); i < 4; ++i) {
*outputStreamPtr << "\t\t\t\t\t<v" << i << '>'
<< *(triItr++) << "</v" << i << ">\n";
*outputStreamPtr << "\t\t\t\t\t<v" << i << '>' << *(triItr++) << "</v" << i << ">\n";
}
*outputStreamPtr << "\t\t\t\t</triangle>\n";
seq.next(true); // allow to cancel
seq.next(true); // allow to cancel
}
*outputStreamPtr << "\t\t\t</volume>\n"