Tidy up.
This commit is contained in:
parent
944aa01e6b
commit
095bb48c22
|
@ -30,7 +30,6 @@
|
||||||
#include <CXX/Extensions.hxx>
|
#include <CXX/Extensions.hxx>
|
||||||
#include <CXX/Objects.hxx>
|
#include <CXX/Objects.hxx>
|
||||||
|
|
||||||
#include <Base/Console.h>
|
|
||||||
#include <Base/Interpreter.h>
|
#include <Base/Interpreter.h>
|
||||||
#include <Base/FileInfo.h>
|
#include <Base/FileInfo.h>
|
||||||
#include <Base/Tools.h>
|
#include <Base/Tools.h>
|
||||||
|
@ -302,10 +301,13 @@ private:
|
||||||
static char *kwList[] = {"objectList", "filename", "tolerance",
|
static char *kwList[] = {"objectList", "filename", "tolerance",
|
||||||
"exportAmfCompressed", NULL};
|
"exportAmfCompressed", NULL};
|
||||||
|
|
||||||
// NOTE FOR PYTHON 3: Should switch exportAmfCompressed from using integer 'i' to bool 'p'
|
if (!PyArg_ParseTupleAndKeywords( args.ptr(), keywds.ptr(),
|
||||||
// TODO Deal with above nicely, and double check that the docstring is correct with regards to tol's default
|
#if PY_MAJOR_VERSION >= 3
|
||||||
if (!PyArg_ParseTupleAndKeywords( args.ptr(), keywds.ptr(), "Oet|fi", kwList, &objects,
|
"Oet|fp",
|
||||||
"utf-8", &fileNamePy,
|
#else
|
||||||
|
"Oet|fi",
|
||||||
|
#endif // Python version switch
|
||||||
|
kwList, &objects, "utf-8", &fileNamePy,
|
||||||
&fTolerance, &exportAmfCompressed )) {
|
&fTolerance, &exportAmfCompressed )) {
|
||||||
throw Py::Exception();
|
throw Py::Exception();
|
||||||
}
|
}
|
||||||
|
@ -331,29 +333,13 @@ private:
|
||||||
exporter.reset( new MergeExporter(outputFileName, exportFormat) );
|
exporter.reset( new MergeExporter(outputFileName, exportFormat) );
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto meshFeatId( Base::Type::fromName("Mesh::Feature") );
|
|
||||||
const auto partFeatId( Base::Type::fromName("Part::Feature") );
|
|
||||||
const auto appPartId( Base::Type::fromName("App::Part") );
|
|
||||||
const auto appDOGId( Base::Type::fromName("App::DocumentObjectGroup") );
|
|
||||||
|
|
||||||
Py::Sequence list(objects);
|
Py::Sequence list(objects);
|
||||||
for (auto it : list) {
|
for (auto it : list) {
|
||||||
PyObject *item = it.ptr();
|
PyObject *item = it.ptr();
|
||||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||||
auto obj( static_cast<App::DocumentObjectPy *>(item)->getDocumentObjectPtr() );
|
auto obj( static_cast<App::DocumentObjectPy *>(item)->getDocumentObjectPtr() );
|
||||||
|
|
||||||
if (obj->getTypeId().isDerivedFrom(meshFeatId)) {
|
exporter->addObject(obj, fTolerance);
|
||||||
exporter->addMeshFeat( obj );
|
|
||||||
} else if (obj->getTypeId().isDerivedFrom(partFeatId)) {
|
|
||||||
exporter->addPartFeat( obj, fTolerance );
|
|
||||||
} else if ( obj->getTypeId().isDerivedFrom(appPartId) ||
|
|
||||||
obj->getTypeId().isDerivedFrom(appDOGId) ) {
|
|
||||||
exporter->addAppGroup( obj, fTolerance );
|
|
||||||
} else {
|
|
||||||
Base::Console().Message(
|
|
||||||
"'%s' is of type %s, and can not be exported as a mesh.\n",
|
|
||||||
obj->Label.getValue(), obj->getTypeId().getName() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exporter.reset(); // deletes Exporter, mesh file is written by destructor
|
exporter.reset(); // deletes Exporter, mesh file is written by destructor
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) Ian Rees <ian.rees@gmail.com> *
|
* Copyright (c) 2017 Ian Rees <ian.rees@gmail.com> *
|
||||||
* *
|
* *
|
||||||
* This file is part of the FreeCAD CAx development system. *
|
* This file is part of the FreeCAD CAx development system. *
|
||||||
* *
|
* *
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include "Core/Iterator.h"
|
#include "Core/Iterator.h"
|
||||||
|
|
||||||
|
#include "Base/Console.h"
|
||||||
#include "Base/Exception.h"
|
#include "Base/Exception.h"
|
||||||
#include "Base/FileInfo.h"
|
#include "Base/FileInfo.h"
|
||||||
#include "Base/Sequencer.h"
|
#include "Base/Sequencer.h"
|
||||||
|
@ -44,6 +45,13 @@
|
||||||
using namespace Mesh;
|
using namespace Mesh;
|
||||||
using namespace MeshCore;
|
using namespace MeshCore;
|
||||||
|
|
||||||
|
Exporter::Exporter() :
|
||||||
|
meshFeatId( Base::Type::fromName("Mesh::Feature") ),
|
||||||
|
partFeatId( Base::Type::fromName("Part::Feature") ),
|
||||||
|
appPartId( Base::Type::fromName("App::Part") ),
|
||||||
|
appDOGId( Base::Type::fromName("App::DocumentObjectGroup") )
|
||||||
|
{ }
|
||||||
|
|
||||||
//static
|
//static
|
||||||
std::string Exporter::xmlEscape(const std::string &input)
|
std::string Exporter::xmlEscape(const std::string &input)
|
||||||
{
|
{
|
||||||
|
@ -58,11 +66,6 @@ std::string Exporter::xmlEscape(const std::string &input)
|
||||||
|
|
||||||
bool Exporter::addAppGroup(App::DocumentObject *obj, float tol)
|
bool Exporter::addAppGroup(App::DocumentObject *obj, float tol)
|
||||||
{
|
{
|
||||||
const auto meshFeatId( Base::Type::fromName("Mesh::Feature") );
|
|
||||||
const auto partFeatId( Base::Type::fromName("Part::Feature") );
|
|
||||||
const auto appPartId( Base::Type::fromName("App::Part") );
|
|
||||||
const auto appDOGId( Base::Type::fromName("App::DocumentObjectGroup") );
|
|
||||||
|
|
||||||
auto ret(true);
|
auto ret(true);
|
||||||
|
|
||||||
for (auto it : static_cast<App::Part *>(obj)->getOutList()) {
|
for (auto it : static_cast<App::Part *>(obj)->getOutList()) {
|
||||||
|
@ -80,6 +83,22 @@ bool Exporter::addAppGroup(App::DocumentObject *obj, float tol)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Exporter::addObject(App::DocumentObject *obj, float tol)
|
||||||
|
{
|
||||||
|
if (obj->getTypeId().isDerivedFrom(meshFeatId)) {
|
||||||
|
return addMeshFeat( obj );
|
||||||
|
} else if (obj->getTypeId().isDerivedFrom(partFeatId)) {
|
||||||
|
return addPartFeat( obj, tol );
|
||||||
|
} else if ( obj->getTypeId().isDerivedFrom(appPartId) ||
|
||||||
|
obj->getTypeId().isDerivedFrom(appDOGId) ) {
|
||||||
|
return addAppGroup( obj, tol );
|
||||||
|
} else {
|
||||||
|
Base::Console().Message(
|
||||||
|
"'%s' is of type %s, and can not be exported as a mesh.\n",
|
||||||
|
obj->Label.getValue(), obj->getTypeId().getName() );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MergeExporter::MergeExporter(std::string fileName, MeshIO::Format)
|
MergeExporter::MergeExporter(std::string fileName, MeshIO::Format)
|
||||||
:fName(fileName)
|
:fName(fileName)
|
||||||
|
@ -241,7 +260,7 @@ AmfExporter::~AmfExporter()
|
||||||
bool AmfExporter::addPartFeat(App::DocumentObject *obj, float tol)
|
bool AmfExporter::addPartFeat(App::DocumentObject *obj, float tol)
|
||||||
{
|
{
|
||||||
auto *shape(obj->getPropertyByName("Shape"));
|
auto *shape(obj->getPropertyByName("Shape"));
|
||||||
// TODO: Look into a different way to extract mesh with vertex normals
|
|
||||||
if (shape && shape->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) {
|
if (shape && shape->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) {
|
||||||
Base::Reference<MeshObject> mesh(new MeshObject());
|
Base::Reference<MeshObject> mesh(new MeshObject());
|
||||||
|
|
||||||
|
@ -269,7 +288,6 @@ bool AmfExporter::addPartFeat(App::DocumentObject *obj, float tol)
|
||||||
|
|
||||||
bool AmfExporter::addMeshFeat(App::DocumentObject *obj)
|
bool AmfExporter::addMeshFeat(App::DocumentObject *obj)
|
||||||
{
|
{
|
||||||
// TODO: Add name, colour, etc. from the mesh feature
|
|
||||||
const MeshObject &mesh( static_cast<Mesh::Feature *>(obj)->Mesh.getValue() );
|
const MeshObject &mesh( static_cast<Mesh::Feature *>(obj)->Mesh.getValue() );
|
||||||
MeshCore::MeshKernel kernel( mesh.getKernel() );
|
MeshCore::MeshKernel kernel( mesh.getKernel() );
|
||||||
kernel.Transform(mesh.getTransform());
|
kernel.Transform(mesh.getTransform());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) Ian Rees <ian.rees@gmail.com> *
|
* Copyright (c) 2017 Ian Rees <ian.rees@gmail.com> *
|
||||||
* *
|
* *
|
||||||
* This file is part of the FreeCAD CAx development system. *
|
* This file is part of the FreeCAD CAx development system. *
|
||||||
* *
|
* *
|
||||||
|
@ -26,7 +26,9 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include <App/Property.h>
|
#include "Base/Type.h"
|
||||||
|
|
||||||
|
#include "App/Property.h"
|
||||||
|
|
||||||
#include "MeshFeature.h"
|
#include "MeshFeature.h"
|
||||||
#include "Core/MeshIO.h"
|
#include "Core/MeshIO.h"
|
||||||
|
@ -48,6 +50,8 @@ namespace Mesh
|
||||||
class Exporter
|
class Exporter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Exporter();
|
||||||
|
|
||||||
virtual bool addMeshFeat(App::DocumentObject *obj) = 0;
|
virtual bool addMeshFeat(App::DocumentObject *obj) = 0;
|
||||||
virtual bool addPartFeat(App::DocumentObject *obj, float tol) = 0;
|
virtual bool addPartFeat(App::DocumentObject *obj, float tol) = 0;
|
||||||
|
|
||||||
|
@ -57,12 +61,19 @@ class Exporter
|
||||||
* added successfully.
|
* added successfully.
|
||||||
*/
|
*/
|
||||||
bool addAppGroup(App::DocumentObject *obj, float tol);
|
bool addAppGroup(App::DocumentObject *obj, float tol);
|
||||||
|
|
||||||
|
bool addObject(App::DocumentObject *obj, float tol);
|
||||||
|
|
||||||
virtual ~Exporter() = default;
|
virtual ~Exporter() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Does some simple escaping of characters for XML-type exports
|
/// Does some simple escaping of characters for XML-type exports
|
||||||
//TODO: Use xerces or something instead?
|
|
||||||
static std::string xmlEscape(const std::string &input);
|
static std::string xmlEscape(const std::string &input);
|
||||||
|
|
||||||
|
const Base::Type meshFeatId;
|
||||||
|
const Base::Type partFeatId;
|
||||||
|
const Base::Type appPartId;
|
||||||
|
const Base::Type appDOGId;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a single mesh, in a file, from one or more objects
|
/// Creates a single mesh, in a file, from one or more objects
|
||||||
|
|
Loading…
Reference in New Issue
Block a user