Skip to content

Commit

Permalink
reduce created models to improve loading performance
Browse files Browse the repository at this point in the history
- until now all were created recusively into all leaf states
  of all libraries even if those were never needed for the gui or the execution
  -> introduce NO_FULLY_RECURSIVE_LIBRARY_MODEL Flag in gui config
  -> generate only models that will be accessed
  -> use state copy initialized boolean to check if model exsist
- adapt state machine tree to limit depth of tree if new flag is True
- adapt meta data scaling function in respective module
  to coup with not fully recursive library models
- show content boolean in meta data is now minor to the
  visualized level limitation for show content set in gui config
  -> correct gaphas viewer observation and condition checks of show content
     accordingly
  • Loading branch information
Rbelder committed Sep 8, 2017
1 parent 3a98bf6 commit 238a995
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
12 changes: 9 additions & 3 deletions source/rafcon/gui/controllers/graphical_editor_gaphas.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,20 @@ def meta_changed_notify_after(self, state_machine_m, _, info):
if meta_signal_message.change == 'show_content':
library_state_m = model
library_state_v = view
if model.meta['gui']['show_content']:
if model.meta['gui']['show_content'] is not library_state_m.show_content():
logger.warning("Minor show content flag is not considered because of major show content depth "
"limitations for {0}, see GUI config MAX_VISIBLE_LIBRARY_HIERARCHY.".format(model))
if library_state_m.show_content():
if not library_state_m.state_copy_initialized:
logger.warning("Show library content without initialized state copy does not work {0}".format(model))
logger.debug("Show content of {}".format(library_state_m.state))
gui_helper_meta_data.scale_library_content(library_state_m)
self.add_state_view_for_model(library_state_m.state_copy, view, hierarchy_level=library_state_v.hierarchy_level + 1)
else:
logger.debug("Hide content of {}".format(library_state_m.state))
state_copy_v = self.canvas.get_view_for_model(library_state_m.state_copy)
state_copy_v.remove()
if state_copy_v:
state_copy_v.remove()
self.canvas.request_update(library_state_v)
self.canvas.perform_update()
else:
Expand Down Expand Up @@ -750,7 +756,7 @@ def add_state_view_for_model(self, state_m, parent_v=None, rel_pos=(0, 0), size=
# Keep state within parent
pass

if isinstance(state_m, LibraryStateModel) and state_m.show_content():
if isinstance(state_m, LibraryStateModel) and state_m.show_content() and state_m.state_copy_initialized:
gui_helper_meta_data.scale_library_content(state_m)
self.add_state_view_for_model(state_m.state_copy, state_v, hierarchy_level=hierarchy_level + 1)

Expand Down
7 changes: 4 additions & 3 deletions source/rafcon/gui/controllers/state_machine_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ def insert_and_update_recursively(self, parent_iter, state_model, with_expand=Fa
# 4.1 - in as library without show content -> nothing to do

# if state model is LibraryStateModel with enabled show content state_model becomes the library root state model
if isinstance(state_model, LibraryStateModel) and self.show_content(state_model):
if isinstance(state_model, LibraryStateModel) and self.show_content(state_model) and state_model.state_copy_initialized:
_state_model = state_model
state_model = state_model.state_copy
else:
_state_model = state_model

# TODO remove this workaround for removing LibraryStateModel or there root states by default
if isinstance(_state_model, LibraryStateModel):
if isinstance(_state_model, LibraryStateModel) and _state_model.state_copy_initialized:
state_row_iter = None
if _state_model.state.get_path() in self.state_row_iter_dict_by_state_path:
state_row_iter = self.state_row_iter_dict_by_state_path[_state_model.state.get_path()]
Expand Down Expand Up @@ -403,7 +403,8 @@ def insert_and_update_recursively(self, parent_iter, state_model, with_expand=Fa
child_id = self.tree_store.get_value(child_iter, self.ID_STORAGE_ID)

# check if there are left over rows of old states (switch from HS or CS to S and so on)
show_content_flag = isinstance(child_model, LibraryStateModel) and self.show_content(child_model)
show_content_flag = isinstance(child_model, LibraryStateModel) and self.show_content(child_model) and \
child_model.state_copy_initialized
child_is_lib_with_show_content = isinstance(child_model, LibraryStateModel) and show_content_flag
child_is_lib_without_show_content = isinstance(child_model, LibraryStateModel) and not show_content_flag
if not isinstance(state_model, ContainerStateModel) or child_model is None or \
Expand Down
1 change: 1 addition & 0 deletions source/rafcon/gui/gui_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SUBSTITUTE_STATE_KEEPS_STATE_NAME: True

MINIMUM_SIZE_FOR_CONTENT: 30
MAX_VISIBLE_LIBRARY_HIERARCHY: 2
NO_FULLY_RECURSIVE_LIBRARY_MODEL: True

USE_ICONS_AS_TAB_LABELS: True

Expand Down
6 changes: 4 additions & 2 deletions source/rafcon/gui/helpers/meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,14 @@ def resize_state_meta(state_m, factor, gaphas_editor):

if isinstance(state_m, LibraryStateModel):
# print "LIBRARY", state_m
if gaphas_editor:
if gaphas_editor and state_m.state_copy_initialized:
if state_m.meta_data_was_scaled:
resize_state_port_meta(state_m, factor, gaphas_editor)
else:
scale_library_ports_meta_data(state_m, gaphas_editor)
resize_state_meta(state_m.state_copy, factor, gaphas_editor)

if state_m.state_copy_initialized:
resize_state_meta(state_m.state_copy, factor, gaphas_editor)
# print "END LIBRARY RESIZE"
else:
# print "resize_state_meta -> resize_state_port_meta"
Expand Down
25 changes: 19 additions & 6 deletions source/rafcon/gui/models/library_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,38 @@ def __init__(self, state, parent=None, meta=None, load_meta_data=True):
self.state_copy_initialized = False
self.meta_data_was_scaled = False
super(LibraryStateModel, self).__init__(state, parent, meta)
model_class = get_state_model_class_for_state(state.state_copy)
if model_class is not None:
self.state_copy = model_class(state.state_copy, parent=self) # TODO think about load_meta_data=False)

# regulate depth of library model generation to reduce resource consumption
current_hierarchy_depth = self.state.library_hierarchy_depth
max_hierarchy_depth = global_gui_config.get_config_value("MAX_VISIBLE_LIBRARY_HIERARCHY", 2)
no_fully_rec_lib_model = global_gui_config.get_config_value("NO_FULLY_RECURSIVE_LIBRARY_MODEL", False)
recursive_model_generation = not (current_hierarchy_depth > max_hierarchy_depth) or not no_fully_rec_lib_model
if recursive_model_generation:
# logger.debug("initialize state copy {0}".format(self))
self.initiate_library_root_state_model()
else:
logger.error("Unknown state type '{type:s}'. Cannot create model.".format(type=type(state)))
self.state_copy_initialized = True
logger.debug("Do not initialize state copy {0}".format(self))

self._load_input_data_port_models()
self._load_output_data_port_models()
self._load_outcome_models()

if load_meta_data:

if not self.load_meta_data():
# TODO decide to scale here or still in the editor -> at the moment meta data is missing here
import rafcon.gui.helpers.meta_data as gui_helper_meta_data
# gui_helper_meta_data.scale_library_ports_meta_data(self)
else:
self.meta_data_was_scaled = True

def initiate_library_root_state_model(self):
model_class = get_state_model_class_for_state(self.state.state_copy)
if model_class is not None:
self.state_copy = model_class(self.state.state_copy, parent=self)
self.state_copy_initialized = True
else:
logger.error("Unknown state type '{type:s}'. Cannot create model.".format(type=type(self.state)))

def __eq__(self, other):
# logger.info("compare method")
if isinstance(other, LibraryStateModel):
Expand Down Expand Up @@ -136,5 +148,6 @@ def show_content(self):
return False if 'show_content' not in uppermost_lib_meta['gui'] else uppermost_lib_meta['gui']['show_content']

def copy_meta_data_from_state_m(self, source_state_m):
assert isinstance(source_state_m, LibraryStateModel)
super(LibraryStateModel, self).copy_meta_data_from_state_m(source_state_m)
self.meta_data_was_scaled = source_state_m.meta_data_was_scaled

0 comments on commit 238a995

Please sign in to comment.