Skip to content

Commit

Permalink
FEM: mesh api, export of z88 mesh file with Fem API
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach committed Nov 6, 2018
1 parent ba11c3a commit 8988b89
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
36 changes: 35 additions & 1 deletion src/Mod/Fem/App/FemMesh.cpp
Expand Up @@ -42,6 +42,7 @@
#include <Base/FileInfo.h>
#include <Base/TimeInfo.h>
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <App/Application.h>

#include <Mod/Mesh/App/Core/MeshKernel.h>
Expand Down Expand Up @@ -1163,7 +1164,7 @@ void FemMesh::read(const char *FileName)
#if SMESH_VERSION_MAJOR < 7
else if (File.hasExtension("dat") ) {
// read brep-file
// vejmarie disable
// vejmarie disable
myMesh->DATToMesh(File.filePath().c_str());
}
#endif
Expand Down Expand Up @@ -1572,6 +1573,34 @@ void FemMesh::writeABAQUS(const std::string &Filename, int elemParam, bool group
}
}


void FemMesh::writeZ88(const std::string &FileName) const
{
Base::TimeInfo Start;
Base::Console().Log("Start: FemMesh::writeZ88() =================================\n");

/*
Python command to export FemMesh from StartWB FEM 3D example:
import feminout.importZ88Mesh
feminout.importZ88Mesh.write(App.ActiveDocument.Box_Mesh.FemMesh, '/tmp/mesh.z88')
*/

// create the Python commands
Base::FileInfo File(FileName);
Base::Console().Log("Export path: %s\n", File.filePath().c_str());
Base::Console().Log("Export mesh object: %s\n", "pendent");
std::string exportCommand = "feminout.importZ88Mesh.write(App.ActiveDocument.Box_Mesh.FemMesh, '" + File.filePath() + "')";

// the Python commands are passed to the interpreter
Base::Interpreter().runString("import feminout.importZ88Mesh");
Base::Interpreter().runString(exportCommand.c_str()); // std::string needs to be converted to const char* , newline \n in string gives error EOL ...

// this is zeiger nicht auf mesh object, sondern auf meshObject.FemMesh, daher brauche ich nur code fuer objnamen auf this ausfuehren ... , eben nicht, da zeiger auf FemMesh nicht mesh obj
//std::string objName = this->getName(); // this ist zeiger auf FemMesh
//std::string commandMeshInfo =
}


void FemMesh::write(const char *FileName) const
{
Base::FileInfo File(FileName);
Expand Down Expand Up @@ -1611,6 +1640,11 @@ void FemMesh::write(const char *FileName) const
FemVTKTools::writeVTKMesh(File.filePath().c_str(), this);
}
#endif
else if (File.hasExtension("z88") ) {
Base::Console().Log("FEM mesh object will be exported to z88 format.\n");
// write z88 file
writeZ88(File.filePath());
}
else{
throw Base::Exception("An unknown file extension was added!");
}
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Fem/App/FemMesh.h
Expand Up @@ -150,6 +150,7 @@ class AppFemExport FemMesh : public Data::ComplexGeoData
void read(const char *FileName);
void write(const char *FileName) const;
void writeABAQUS(const std::string &Filename, int elemParam, bool groupParam) const;
void writeZ88(const std::string &FileName) const;

private:
void copyMeshData(const FemMesh&);
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/Fem/Init.py
Expand Up @@ -30,8 +30,9 @@

FreeCAD.addExportType("FEM mesh TetGen (*.poly)", "feminout.convert2TetGen")

FreeCAD.addImportType("FEM mesh formats (*.unv *.med *.dat *.bdf)", "Fem")
FreeCAD.addExportType("FEM mesh formats (*.unv *.med *.stl *.dat *.inp *.vtk *.vtu)", "Fem")
# see FemMesh::read() and FemMesh::write() methods in src/Mod/Fem/App/FemMesh.cpp
FreeCAD.addImportType("FEM mesh formats (*.unv *.med *.dat *.bdf *.vtk *.vtu)", "Fem")
FreeCAD.addExportType("FEM mesh formats (*.unv *.med *.stl *.dat *.inp *.vtk *.vtu *.z88)", "Fem")

FreeCAD.addImportType("FEM mesh CalculiX/Abaqus (*.inp)", "feminout.importInpMesh")
FreeCAD.addImportType("FEM result CalculiX (*.frd)", "feminout.importCcxFrdResults")
Expand Down

0 comments on commit 8988b89

Please sign in to comment.