postprocess_gui.py

Go to the documentation of this file.
00001 import os,sys,string,math,shutil,glob,subprocess
00002 from time import sleep
00003 from os.path import join
00004 
00005 ##GUI related stuff
00006 from PyQt4 import QtCore, QtGui
00007 from postprocess import Ui_dialog
00008 ##------------------------------------------------
00009 
00010 
00011 from calculix_postprocess import calculix_postprocess
00012 from calculix_postprocess import get_sigini_values
00013 
00014 import FreeCAD,Fem,Part
00015 
00016 
00017 class MyForm(QtGui.QDialog,Ui_dialog):
00018     def __init__(self, parent=None):
00019         QtGui.QDialog.__init__(self, parent)
00020         self.setupUi(self)
00021         #Define some global variables
00022         self.dirname = QtCore.QString("")
00023         #Connect Signals and Slots
00024         QtCore.QObject.connect(self.button_select_results_folder, QtCore.SIGNAL("clicked()"), self.select_output)
00025         QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.onAbbrechen)
00026         QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.onAbbrechen)
00027         QtCore.QObject.connect(self.button_start_postprocessing, QtCore.SIGNAL("clicked()"), self.start_PostProcessing)    
00028         
00029 
00030     def select_output(self):
00031         self.dirname=QtGui.QFileDialog.getExistingDirectory(None, 'Open working directory', '', QtGui.QFileDialog.ShowDirsOnly)
00032         self.button_start_postprocessing.setEnabled(True)
00033 
00034     def onAbbrechen(self):
00035         self.close()
00036 
00037     def start_PostProcessing(self):
00038         outputfile = open(str(self.dirname + "/postprocessing_input.txt"),"wb")
00039         sort_tuple = (1,1.1,1.1,1.1,1.1,1.1,1.1,1.1,1.1,1.1,1.1,1.1)
00040         output_list = []
00041         lc_coeff = []
00042         ltc_coeff = []
00043         sigini = True
00044         for root, dirs, files in os.walk(str(self.dirname)):
00045            if 'final_fe_input.frd' in files:
00046                 bbox_orig,\
00047                 bbox_distorted,\
00048                 relationship,\
00049                 max_disp_x,\
00050                 min_disp_x,\
00051                 max_disp_y,\
00052                 min_disp_y,\
00053                 max_disp_z,\
00054                 min_disp_z = calculix_postprocess(os.path.join(root,'final_fe_input.frd'))
00055                 if sigini:
00056                     sigini = False
00057                     lc_coeff,ltc_coeff = get_sigini_values(os.path.join(root,'sigini_input.txt'))
00058                                 
00059                 #Get the current Offset-Level and rotation values from the folder-name
00060                 current_z_level = int(root[(root.rfind("_z_l")+4):])
00061                 x_rot = int(root[(root.rfind("x_rot")+5):(root.rfind("_y_rot"))])
00062                 y_rot = int(root[(root.rfind("y_rot")+5):(root.rfind("_z_rot"))])
00063                 z_rot = int(root[(root.rfind("z_rot")+5):(root.rfind("_z_l"))])
00064                 #Get also the coefficients
00065                 #now generate an output tuple and add it to the output-list
00066                 output_list.append((current_z_level,x_rot,y_rot,z_rot,relationship,max_disp_x,min_disp_x,max_disp_y,min_disp_y,max_disp_z,min_disp_z))
00067 
00068         sorted_list = sorted(output_list, key=lambda sort_tuple: sort_tuple[0])
00069         for item in sorted_list:
00070             if abs(item[5]) > abs(item[6]):
00071                 abs_disp_x = abs(item[5])
00072             else:
00073                 abs_disp_x = abs(item[6])
00074             if abs(item[7]) > abs(item[8]):
00075                 abs_disp_y = abs(item[7])
00076             else:
00077                 abs_disp_y = abs(item[8])
00078             if abs(item[9]) > abs(item[10]):
00079                 abs_disp_z = abs(item[9])
00080             else:
00081                 abs_disp_z = abs(item[10])
00082 
00083             outputfile.write(
00084                 str(item[0]) + " " +
00085                 str(item[1]) + " " +
00086                 str(item[2]) + " " +
00087                 str(item[3]) + " " +
00088                 str(item[4]) + " " +
00089                 str(item[5]) + " " +
00090                 str(item[6]) + " " +
00091                 str(item[7]) + " " +
00092                 str(item[8]) + " " +
00093                 str(item[9]) + " " +
00094                 str(item[10]) + " " +
00095                 str(abs_disp_x) + " " +
00096                 str(abs_disp_y) + " " +
00097                 str(abs_disp_z) + "\n")
00098                 
00099         outputfile.close()
00100         #Now create a batch file for GnuPlot and start the generation of the postprocess image generation
00101         self.start_gnu_plot(sorted_list,lc_coeff,ltc_coeff)
00102         
00103         
00104     def start_gnu_plot(self,list,lc_coeff,ltc_coeff):
00105         gnu_plot_input_file = open(str(self.dirname + "/gnu_plot_input.txt"),"wb")
00106         gnu_plot_input_file.write(
00107                                     "set term png\n" +
00108                                     "set output \"max_disp_z.png\"\n"+
00109                                     "set surface\n" +
00110                                     "set grid\n"+
00111                                     "set hidden3d\n"+
00112                                     "set dgrid3d " + str(len(list)-1) + "," + str(len(list)-1) + ",100\n" +
00113                                     "set view 80,05,1.3,1.0\n"+
00114                                     "set title \"Abs Displacement in Z vs. Z-Level Offset and Rotation around Z-Axis\" 0,-2\n"+
00115                                     "show title\n"+
00116                                     "set label \"L Coefficients used for the calculation:" + lc_coeff[0] + "," + lc_coeff[1] + "," + lc_coeff[2] + "," + lc_coeff[3] + "," + lc_coeff[4] + "," + lc_coeff[5][:-1] + "\" at screen 0.1, screen 0.95 left font \"Arial,8\"\n"+ 
00117                                     "set label \"LT Coefficients used for the calculation:" + ltc_coeff[0] + "," + ltc_coeff[1] + "," + ltc_coeff[2] + "," + ltc_coeff[3] + "," + ltc_coeff[4] + "," + ltc_coeff[5][:-1] + "\" at screen 0.1, screen 0.93 left font \"Arial,8\"\n"+
00118                                     "set label \"Z-Offset\\nin [mm]\" at screen 0.5, screen 0.1 center rotate by 0\n"+ 
00119                                     "set label \"Rotation around Z-Axis\\nin [" + str(chr(248)) +"]\" at screen 0.91, screen 0.2 center rotate by 50\n"+ 
00120                                     "set label \"Max Displacement Z direction\\nin [mm]\" at screen 0.03, screen 0.5 center rotate by 90\n"+ 
00121                                     "set xtics in nomirror offset character 0,-0.5\n"+
00122                                     "splot \"postprocessing_input.txt\" u 1:4:14 with pm3d title \"\"\n" + 
00123                                     "exit" )
00124                                     
00125 
00126                                     
00127         gnu_plot_input_file.close()
00128         os.chdir(str(self.dirname))
00129         fnull = open(os.devnull, 'w')
00130         commandline = FreeCAD.getHomePath() + "bin/gnuplot/gnuplot gnu_plot_input.txt"
00131         result = subprocess.call(commandline, shell = True, stdout = fnull, stderr = fnull)
00132         fnull.close()
00133 
00134 
00135 

Generated on Wed Nov 23 19:00:28 2011 for FreeCAD by  doxygen 1.6.1