Fem: add FemResult export to VTK files for visualization externally

This commit is contained in:
qingfengxia
2017-01-30 18:22:11 +01:00
committed by Bernd Hahnebach
parent bcea759287
commit 9ce1662ae1
5 changed files with 77 additions and 8 deletions

View File

@@ -281,16 +281,13 @@ private:
std::string EncodedName = std::string(fileName);
PyMem_Free(fileName);
if (!pcObj)
if (pcObj)
{
App::DocumentObjectPy* objpy= static_cast<App::DocumentObjectPy*>(pcObj);
App::DocumentObject* obj = objpy->getDocumentObjectPtr();
if (!obj)
if (PyObject_TypeCheck(pcObj, &(App::DocumentObjectPy::Type)))
{
App::Document* pcDoc = App::GetApplication().getActiveDocument();
obj = pcDoc->getActiveObject();
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(pcObj)->getDocumentObjectPtr();
FemVTKTools::writeResult(EncodedName.c_str(), obj);
}
FemVTKTools::readFluidicResult(EncodedName.c_str(), obj);
}
else
FemVTKTools::writeResult(EncodedName.c_str());

View File

@@ -114,6 +114,7 @@ SET(FemScripts_SRCS
convert2TetGen.py
importInpMesh.py
importZ88Mesh.py
FemResultVTK.py
Init.py
InitGui.py
FemAnalysis.py

View File

@@ -124,6 +124,9 @@ INSTALL(
_ViewProviderFemSolverZ88.py
_CommandSolverZ88.py
# result related import and export
FemResultVTK.py
DESTINATION
Mod/Fem
)

View File

@@ -0,0 +1,67 @@
# ***************************************************************************
# * (c) Qingfeng Xia 2017 *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# * Juergen Riegel 2002 *
# ***************************************************************************/
__title__ = "FreeCAD Result import and export VTK file library"
__author__ = "Qingfeng Xia"
__url__ = "http://www.freecadweb.org"
import os
from math import pow, sqrt
import numpy as np
import FreeCAD
if open.__module__ == '__builtin__':
pyopen = open # because we'll redefine open below
def insert(filename, docname):
"called when freecad wants to import a file"
try:
doc = FreeCAD.getDocument(docname)
except NameError:
doc = FreeCAD.newDocument(docname)
FreeCAD.ActiveDocument = doc
importFemResult(filename)
def open(filename):
"called when freecad opens a file"
docname = os.path.splitext(os.path.basename(filename))[0]
insert(filename, docname)
def importFemResult(filename):
FreeCAD.Console.PrintError("FemResult import is not implemented, actually not necessary\n")
def export(objectslist, filename):
"called when freecad exports a fem result object"
if len(objectslist) != 1:
FreeCAD.Console.PrintError("This exporter can only export one object at once\n")
return
obj = objectslist[0]
if not obj.isDerivedFrom("Fem::FemResultObject"):
FreeCAD.Console.PrintError("object selcted is not FemResultObject.\n")
return
import Fem
Fem.writeResult(filename, obj)

View File

@@ -30,9 +30,10 @@ import FreeCAD
FreeCAD.addExportType("TetGen file (*.poly)", "convert2TetGen")
FreeCAD.addImportType("FEM formats (*.unv *.med *.dat *.bdf)", "Fem")
if("BUILD_FEM_VTK" in FreeCAD.__cmake__):
FreeCAD.addImportType("FEM results (*.vtk *.vtp *.vts *.vtr *.vtu *.vti)", "Fem")
#FreeCAD.addImportType("FEM results (*.vtk *.vtp *.vts *.vtr *.vtu *.vti)", "FemResultVTK") # not implemented yet
FreeCAD.addImportType("FEM CFD Unstructure Mesh (*.vtk *.vtu)", "Fem")
FreeCAD.addExportType("FEM CFD Unstructure Mesh (*.vtk *.vtu)", "Fem")
FreeCAD.addExportType("FEM CFD Result in VTK format (*.vtk *.vtu)", "FemResultVTK")
FreeCAD.addExportType("FEM formats (*.unv *.med *.dat *.inp)", "Fem")
FreeCAD.addImportType("CalculiX result (*.frd)", "ccxFrdReader")