3434
3535# create server object and the state, control variables
3636SERVER = get_server ()
37- STATE , CTRL = SERVER .state , SERVER .controller
38- # STATE contains all the state variables, CTRL contains all the control functions / elements, UI
37+ STATE , CTRL , CTXT = SERVER .state , SERVER .controller , SERVER . context
38+ # STATE contains all the state variables to be shared between server and client , CTRL contains all the control functions / elements, CTXT is a server-only state object which can be utilized to collect global server variables
3939
4040
4141def run_webviewer (dat_file = None ):
@@ -84,11 +84,18 @@ def run_webviewer(dat_file=None):
8484 vtu_threshold_condition_points = vtu .create_vtu_threshold_points (reader , STATE )
8585 vtu_sphere = vtu .create_vtu_sphere (reader )
8686
87+ # create global coordinate system
88+ vtu_global_cos = vtu .create_vtu_global_cos (reader )
89+
8790 STATE .TEMP_DIR = temp_dir
88- STATE .READER = reader
89- STATE .VTU_THRESHOLD_MAT = vtu_threshold_mat
90- STATE .VTU_THRESHOLD_CONDITION_POINTS = vtu_threshold_condition_points
91- STATE .VTU_SPHERE = vtu_sphere
91+
92+ # we put the non-serializable objects into CTXT instead of STATE
93+ # -> no errors anymore, and functionality is preserved, because these variables are only required on the server side
94+ CTXT .READER = reader
95+ CTXT .VTU_THRESHOLD_MAT = vtu_threshold_mat
96+ CTXT .VTU_THRESHOLD_CONDITION_POINTS = vtu_threshold_condition_points
97+ CTXT .VTU_SPHERE = vtu_sphere
98+ CTXT .VTU_GLOBAL_COS = vtu_global_cos
9299
93100 # append functions to CTRL
94101 CTRL .CLICK_INFO_BUTTON = click_info_button
@@ -98,7 +105,7 @@ def run_webviewer(dat_file=None):
98105
99106 # create vtu render window
100107 render_window = vtu .create_vtu_render_window (
101- reader , vtu_threshold_condition_points , vtu_threshold_mat , vtu_sphere
108+ reader , vtu_threshold_condition_points , vtu_threshold_mat , vtu_sphere , vtu_global_cos
102109 )
103110
104111 gui .create_gui (SERVER , render_window )
@@ -371,22 +378,9 @@ def STATE_initialization(temp_dir, dat_file_name, dat_file_lines, dat_file_size,
371378 STATE .COND_TYPE_LIST = dat_file_content ["cond_type_list" ]
372379
373380 # GET THE RESULT DESCRIPTION
374- # STATE.RESULT_DESCRIPTION = STATE.CATEGORY_ITEMS[
375- # STATE.CATEGORIES.index("RESULT DESCRIPTION")
376- # ]
377- STATE .RESULT_DESCRIPTION = [
378- [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ],
379- [
380- "STRUCTURE DIS structure NODE 4 QUANTITY dispy VALUE -1.31962249833408790e-01 TOLERANCE 9.1e-10" ,
381- "STRUCTURE DIS structure NODE 5 QUANTITY dispx VALUE -1.31962249833408513e-01 TOLERANCE 9.1e-10" ,
382- "STRUCTURE DIS structure NODE 8 QUANTITY dispx VALUE -9.06271329067036280e-02 TOLERANCE 9.1e-10" ,
383- "STRUCTURE DIS structure NODE 8 QUANTITY dispy VALUE -9.06271329067068060e-02 TOLERANCE 9.1e-10" ,
384- "STRUCTURE DIS structure NODE 8 QUANTITY dispz VALUE 2.84025416687741394e-01 TOLERANCE 2.8e-09" ,
385- "STRUCTURE DIS structure NODE 6 QUANTITY dispx VALUE -9.06271329067021153e-02 TOLERANCE 9.1e-10" ,
386- "STRUCTURE DIS structure NODE 4 QUANTITY stress_zz VALUE 1.83879098311578976e-01 TOLERANCE 1.8e-07" ,
387- "STRUCTURE DIS structure NODE 8 QUANTITY stress_zz VALUE 1.83879098311589884e-01 TOLERANCE 1.8e-07" ,
388- ],
389- ]
381+ STATE .RESULT_DESCRIPTION = STATE .CATEGORY_ITEMS [
382+ STATE .CATEGORIES .index ("RESULT DESCRIPTION" )
383+ ]
390384
391385 # GET THE GEOMETRY LINES
392386 STATE .GEOMETRY_LINES = dat_file_content ["geometry_lines" ]
@@ -570,8 +564,8 @@ def change_selected_cmm_line(SELECTED_CMM_LINE, **kwargs):
570564 )
571565
572566 # set threshold of the material of the vtk local view
573- STATE .VTU_THRESHOLD_MAT .SetLowerThreshold (STATE .SELECTED_CMM_LINE_INDEX + 1 )
574- STATE .VTU_THRESHOLD_MAT .SetUpperThreshold (STATE .SELECTED_CMM_LINE_INDEX + 1 )
567+ CTXT .VTU_THRESHOLD_MAT .SetLowerThreshold (STATE .SELECTED_CMM_LINE_INDEX + 1 )
568+ CTXT .VTU_THRESHOLD_MAT .SetUpperThreshold (STATE .SELECTED_CMM_LINE_INDEX + 1 )
575569 # update the vtk local view
576570 CTRL .VIEW_UPDATE ()
577571
@@ -611,7 +605,7 @@ def change_selected_cond_general_type(SELECTED_COND_GENERAL_TYPE, **kwargs):
611605 STATE .SELECTED_COND_GENERAL_TYPE_INDEX
612606 ][0 ]
613607 # set thresholdPoints of the condition of the vtk figure
614- STATE .VTU_THRESHOLD_CONDITION_POINTS .SetInputArrayToProcess (
608+ CTXT .VTU_THRESHOLD_CONDITION_POINTS .SetInputArrayToProcess (
615609 0 ,
616610 0 ,
617611 0 ,
@@ -633,7 +627,7 @@ def change_selected_cond_entity(SELECTED_COND_ENTITY, **kwargs):
633627 ].index (SELECTED_COND_ENTITY )
634628
635629 # set thresholdPoints of the condition of the vtk figure
636- STATE .VTU_THRESHOLD_CONDITION_POINTS .SetInputArrayToProcess (
630+ CTXT .VTU_THRESHOLD_CONDITION_POINTS .SetInputArrayToProcess (
637631 0 ,
638632 0 ,
639633 0 ,
@@ -656,19 +650,7 @@ def change_selected_result_descr_index(SELECTED_RESULT_DESCR_INDEX, **kwargs):
656650# after selecting a result description from the list: item change
657651@STATE .change ("SELECTED_RESULT_DESCR" )
658652def change_selected_result_descr (SELECTED_RESULT_DESCR , ** kwargs ):
659- # check if the line contains the marker "NODE"
660- if len (re .findall ("NODE" , STATE .SELECTED_RESULT_DESCR )) > 0 :
661- # get the specified node
662- result_descr_components = STATE .SELECTED_RESULT_DESCR .split (" " )
663- node_index = (
664- int (result_descr_components [result_descr_components .index ("NODE" ) + 1 ]) - 1
665- )
666-
667- # update graphic representation
668- node_coords = STATE .READER .GetOutput ().GetPoints ().GetPoint (node_index )
669- STATE .VTU_SPHERE .SetCenter (node_coords [0 ], node_coords [1 ], node_coords [2 ])
670- # update the vtk figure
671- CTRL .VIEW_UPDATE ()
653+ vtu .update_vtu_render_window (CTXT .READER , CTXT .VTU_SPHERE , CTXT .VTU_GLOBAL_COS , SERVER )
672654
673655
674656# changing the values for t_max, x, y or z for the function plots
@@ -738,7 +720,7 @@ def click_convert_button():
738720 vtu_path = convert_to_vtu (temp_dat_file , STATE .TEMP_DIR )
739721
740722 # update reader to read the current vtu file
741- vtu .update_vtu_reader (STATE .READER , vtu_path )
723+ vtu .update_vtu_reader (CTXT .READER , vtu_path )
742724
743725 # read dat file content
744726 dat_file_content = read_dat_file (STATE .DAT_NAME , STATE .DAT_LINES )
@@ -754,10 +736,9 @@ def click_convert_button():
754736 # flush state: force push server changes
755737 STATE .flush ()
756738
757- # it is not required to update the actor_cond point size
758- STATE .VTU_SPHERE .SetRadius (
759- vtu .get_length_scale_rendered_object (STATE .READER ) / 50.0
760- )
739+
740+ # update render window (manual scaling of various elements)
741+ vtu .update_vtu_render_window (CTXT .READER , CTXT .VTU_SPHERE , CTXT .VTU_GLOBAL_COS , SERVER )
761742
762743 CTRL .VIEW_RESET_CAMERA ()
763744 CTRL .VIEW_UPDATE ()
0 commit comments