@@ -103,6 +103,11 @@ def __init__(self, solver_object):
103
103
QtCore .SIGNAL ("clicked()" ),
104
104
self .runCalculix
105
105
)
106
+ QtCore .QObject .connect (
107
+ self .form .pb_run_ccx ,
108
+ QtCore .SIGNAL ("clicked()" ),
109
+ self .stopCalculix
110
+ )
106
111
QtCore .QObject .connect (
107
112
self .form .rb_static_analysis ,
108
113
QtCore .SIGNAL ("clicked()" ),
@@ -145,7 +150,7 @@ def __init__(self, solver_object):
145
150
)
146
151
QtCore .QObject .connect (
147
152
self .Calculix ,
148
- QtCore .SIGNAL ("finished(int)" ),
153
+ QtCore .SIGNAL ("finished(int, QProcess::ExitStatus )" ),
149
154
self .calculixFinished
150
155
)
151
156
QtCore .QObject .connect (
@@ -245,7 +250,7 @@ def calculixStateChanged(self, newState):
245
250
else :
246
251
self .femConsoleMessage ("Problems." )
247
252
248
- def calculixFinished (self , exitCode ):
253
+ def calculixFinished (self , exitCode , exitStatus ):
249
254
# print("calculixFinished(), exit code: {}".format(exitCode))
250
255
FreeCAD .Console .PrintLog ("calculix state: {}\n " .format (self .Calculix .state ()))
251
256
@@ -254,12 +259,16 @@ def calculixFinished(self, exitCode):
254
259
255
260
self .Timer .stop ()
256
261
262
+ self .form .pb_run_ccx .setText ("Re-run CalculiX" )
263
+
264
+ if exitStatus != QtCore .QProcess .ExitStatus .NormalExit :
265
+ return
266
+
257
267
if self .printCalculiXstdout ():
258
268
self .calculixNoError ()
259
269
else :
260
270
self .calculixError ()
261
271
262
- self .form .pb_run_ccx .setText ("Re-run CalculiX" )
263
272
self .femConsoleMessage ("Loading result sets..." )
264
273
self .form .l_time .setText ("Time: {0:4.1f}: " .format (time .time () - self .Start ))
265
274
self .fea .reset_mesh_purge_results_checked ()
@@ -354,45 +363,50 @@ def editCalculixInputFile(self):
354
363
FemGui .open (self .fea .inp_file_name )
355
364
356
365
def runCalculix (self ):
357
- if self .fea .ccx_binary_present is False :
358
- self .femConsoleMessage (
359
- "CalculiX can not be started. Missing or incorrect CalculiX binary: {}"
360
- .format (self .fea .ccx_binary )
366
+ if self .Calculix .state () == QtCore .QProcess .ProcessState .NotRunning :
367
+ if self .fea .ccx_binary_present is False :
368
+ self .femConsoleMessage (
369
+ "CalculiX can not be started. Missing or incorrect CalculiX binary: {}"
370
+ .format (self .fea .ccx_binary )
371
+ )
372
+ # TODO deactivate the run button
373
+ return
374
+ # print("runCalculix")
375
+ self .Start = time .time ()
376
+
377
+ self .femConsoleMessage ("CalculiX binary: {}" .format (self .fea .ccx_binary ))
378
+ self .femConsoleMessage ("CalculiX input file: {}" .format (self .fea .inp_file_name ))
379
+ self .femConsoleMessage ("Run CalculiX..." )
380
+
381
+ FreeCAD .Console .PrintMessage (
382
+ "run CalculiX at: {} with: {}\n "
383
+ .format (self .fea .ccx_binary , self .fea .inp_file_name )
361
384
)
362
- # TODO deactivate the run button
363
- return
364
- # print("runCalculix")
365
- self .Start = time .time ()
366
-
367
- self .femConsoleMessage ("CalculiX binary: {}" .format (self .fea .ccx_binary ))
368
- self .femConsoleMessage ("CalculiX input file: {}" .format (self .fea .inp_file_name ))
369
- self .femConsoleMessage ("Run CalculiX..." )
370
-
371
- FreeCAD .Console .PrintMessage (
372
- "run CalculiX at: {} with: {}\n "
373
- .format (self .fea .ccx_binary , self .fea .inp_file_name )
374
- )
375
- # change cwd because ccx may crash if directory has no write permission
376
- # there is also a limit of the length of file names so jump to the document directory
385
+ # change cwd because ccx may crash if directory has no write permission
386
+ # there is also a limit of the length of file names so jump to the document directory
387
+
388
+ # Set up for multi-threading. Note: same functionality as ccx_tools.py/start_ccx()
389
+ ccx_prefs = FreeCAD .ParamGet (self .PREFS_PATH )
390
+ env = QtCore .QProcessEnvironment .systemEnvironment ()
391
+ num_cpu_pref = ccx_prefs .GetInt ("AnalysisNumCPUs" , 1 )
392
+ if num_cpu_pref > 1 :
393
+ env .insert ("OMP_NUM_THREADS" , str (num_cpu_pref ))
394
+ else :
395
+ cpu_count = os .cpu_count ()
396
+ if cpu_count is not None and cpu_count > 1 :
397
+ env .insert ("OMP_NUM_THREADS" , str (cpu_count ))
398
+ self .Calculix .setProcessEnvironment (env )
377
399
378
- # Set up for multi-threading. Note: same functionality as ccx_tools.py/start_ccx()
379
- ccx_prefs = FreeCAD .ParamGet (self .PREFS_PATH )
380
- env = QtCore .QProcessEnvironment .systemEnvironment ()
381
- num_cpu_pref = ccx_prefs .GetInt ("AnalysisNumCPUs" , 1 )
382
- if num_cpu_pref > 1 :
383
- env .insert ("OMP_NUM_THREADS" , str (num_cpu_pref ))
384
- else :
385
- cpu_count = os .cpu_count ()
386
- if cpu_count is not None and cpu_count > 1 :
387
- env .insert ("OMP_NUM_THREADS" , str (cpu_count ))
388
- self .Calculix .setProcessEnvironment (env )
400
+ self .cwd = QtCore .QDir .currentPath ()
401
+ fi = QtCore .QFileInfo (self .fea .inp_file_name )
402
+ QtCore .QDir .setCurrent (fi .path ())
403
+ self .Calculix .start (self .fea .ccx_binary , ["-i" , fi .baseName ()])
389
404
390
- self .cwd = QtCore .QDir .currentPath ()
391
- fi = QtCore .QFileInfo (self .fea .inp_file_name )
392
- QtCore .QDir .setCurrent (fi .path ())
393
- self .Calculix .start (self .fea .ccx_binary , ["-i" , fi .baseName ()])
405
+ QApplication .restoreOverrideCursor ()
394
406
395
- QApplication .restoreOverrideCursor ()
407
+ def stopCalculix (self ):
408
+ if self .Calculix .state () == QtCore .QProcess .ProcessState .Running :
409
+ self .Calculix .kill ()
396
410
397
411
def select_analysis_type (self , analysis_type ):
398
412
if self .fea .solver .AnalysisType != analysis_type :
0 commit comments