+ Support to write out mesh name
This commit is contained in:
parent
970f9c193d
commit
58b1a0947f
|
@ -1467,6 +1467,7 @@ bool MeshOutput::SaveAny(const char* FileName, MeshIO::Format format) const
|
|||
}
|
||||
else if (fileformat == MeshIO::ASTL) {
|
||||
MeshOutput aWriter(_rclMesh);
|
||||
aWriter.SetObjectName(objectName);
|
||||
aWriter.Transform(this->_transform);
|
||||
|
||||
// write file
|
||||
|
@ -1557,7 +1558,10 @@ bool MeshOutput::SaveAsciiSTL (std::ostream &rstrOut) const
|
|||
rstrOut.setf(std::ios::fixed | std::ios::showpoint);
|
||||
Base::SequencerLauncher seq("saving...", _rclMesh.CountFacets() + 1);
|
||||
|
||||
rstrOut << "solid Mesh" << std::endl;
|
||||
if (this->objectName.empty())
|
||||
rstrOut << "solid Mesh" << std::endl;
|
||||
else
|
||||
rstrOut << "solid " << this->objectName << std::endl;
|
||||
|
||||
clIter.Begin();
|
||||
clEnd.End();
|
||||
|
|
|
@ -126,9 +126,11 @@ public:
|
|||
MeshOutput (const MeshKernel &rclM, const Material* m)
|
||||
: _rclMesh(rclM), _material(m), apply_transform(false){}
|
||||
virtual ~MeshOutput (void) { }
|
||||
void SetObjectName(const std::string& n)
|
||||
{ objectName = n; }
|
||||
void Transform(const Base::Matrix4D&);
|
||||
/** Set custom data to the header of a binary STL.
|
||||
* If the data exceeds 80 characters the the characters too much
|
||||
* If the data exceeds 80 characters then the characters too much
|
||||
* are ignored. If the data has less than 80 characters they are
|
||||
* automatically filled up with spaces.
|
||||
*/
|
||||
|
@ -170,6 +172,7 @@ protected:
|
|||
const Material* _material;
|
||||
Base::Matrix4D _transform;
|
||||
bool apply_transform;
|
||||
std::string objectName;
|
||||
static std::string stl_header;
|
||||
};
|
||||
|
||||
|
|
|
@ -303,9 +303,12 @@ void MeshObject::RestoreDocFile(Base::Reader &reader)
|
|||
}
|
||||
|
||||
void MeshObject::save(const char* file, MeshCore::MeshIO::Format f,
|
||||
const MeshCore::Material* mat) const
|
||||
const MeshCore::Material* mat,
|
||||
const char* objectname) const
|
||||
{
|
||||
MeshCore::MeshOutput aWriter(this->_kernel, mat);
|
||||
if (objectname)
|
||||
aWriter.SetObjectName(objectname);
|
||||
aWriter.Transform(this->_Mtrx);
|
||||
aWriter.SaveAny(file, f);
|
||||
}
|
||||
|
|
|
@ -149,7 +149,8 @@ public:
|
|||
void Restore(Base::XMLReader &reader);
|
||||
void RestoreDocFile(Base::Reader &reader);
|
||||
void save(const char* file,MeshCore::MeshIO::Format f=MeshCore::MeshIO::Undefined,
|
||||
const MeshCore::Material* mat = 0) const;
|
||||
const MeshCore::Material* mat = 0,
|
||||
const char* objectname = 0) const;
|
||||
void save(std::ostream&) const;
|
||||
bool load(const char* file, MeshCore::Material* mat = 0);
|
||||
void load(std::istream&);
|
||||
|
|
|
@ -149,7 +149,8 @@ PyObject* MeshPy::write(PyObject *args)
|
|||
{
|
||||
const char* Name;
|
||||
char* Ext=0;
|
||||
if (!PyArg_ParseTuple(args, "s|s",&Name,&Ext))
|
||||
char* ObjName;
|
||||
if (!PyArg_ParseTuple(args, "s|ss",&Name,&Ext,&ObjName))
|
||||
return NULL;
|
||||
|
||||
MeshCore::MeshIO::Format format = MeshCore::MeshIO::Undefined;
|
||||
|
@ -175,7 +176,7 @@ PyObject* MeshPy::write(PyObject *args)
|
|||
};
|
||||
|
||||
PY_TRY {
|
||||
getMeshObjectPtr()->save(Name, format);
|
||||
getMeshObjectPtr()->save(Name, format, 0, ObjName);
|
||||
} PY_CATCH;
|
||||
|
||||
Py_Return;
|
||||
|
|
|
@ -381,10 +381,11 @@ void CmdMeshExport::activated(int iMsg)
|
|||
}
|
||||
|
||||
//openCommand("Export Mesh");
|
||||
doCommand(Doc,"FreeCAD.ActiveDocument.getObject(\"%s\").Mesh.write(\"%s\",\"%s\")",
|
||||
doCommand(Doc,"FreeCAD.ActiveDocument.getObject(\"%s\").Mesh.write(\"%s\",\"%s\",\"%s\")",
|
||||
docObj->getNameInDocument(),
|
||||
(const char*)fn.toUtf8(),
|
||||
(const char*)extension);
|
||||
(const char*)extension,
|
||||
docObj->Label.getValue());
|
||||
//commitCommand();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user