Esempio n. 1
0
def insert_self_transition_meta_data(state_m,
                                     t_id,
                                     origin='graphical_editor',
                                     combined_action=False):

    try:
        state_meta = state_m.get_meta_data_editor()

        if 'rel_pos' not in state_meta or 'size' not in state_meta:
            return

        transition_m = state_m.parent.get_transition_m(t_id)
        margin = min(state_meta['size']) / 10.

        origin_port_m = state_m.get_outcome_m(
            transition_m.transition.from_outcome)
        origin_port_x, origin_port_y = origin_port_m.get_meta_data_editor(
        )['rel_pos']
        target_port_x, target_port_y = state_m.income.get_meta_data_editor(
        )['rel_pos']
        x_osign = 1 if origin_port_x / state_meta['size'][0] > 0.5 else -1
        x_tsign = -1 if target_port_x / state_meta['size'][0] < 0.5 else 1
        y_osign = 1 if origin_port_y / state_meta['size'][1] > 0.5 else -1
        y_tsign = -1 if target_port_y / state_meta['size'][1] < 0.5 else 1
        first_point_x = state_meta['rel_pos'][0] + x_osign * margin + (
            state_meta['size'][0] if x_osign == 1 else 0.)
        first_point_y = state_meta['rel_pos'][1] + y_osign * margin + (
            state_meta['size'][1] if y_osign == 1 else 0.)
        second_point_x = state_meta['rel_pos'][0] + x_tsign * margin + (
            state_meta['size'][0] if x_tsign == 1 else 0.)
        second_point_y = state_meta['rel_pos'][1] + y_tsign * margin + (
            state_meta['size'][1] if y_tsign == 1 else 0.)

        if (first_point_x, first_point_y) == (second_point_x, second_point_y):
            waypoints = [(first_point_x, first_point_y)]
        else:
            waypoints = [(first_point_x, first_point_y),
                         (second_point_x, second_point_y)]
        transition_m.set_meta_data_editor(
            'waypoints',
            waypoints,
        )

        if combined_action:
            transition_m.meta_signal.emit(
                MetaSignalMsg(origin=origin, change='append_to_last_change'))
        else:
            transition_m.meta_signal.emit(
                MetaSignalMsg(origin=origin, change='viapoint_position'))
    except TypeError:
        # meta data generation currently only supported for OpenGL editor
        pass
Esempio n. 2
0
    def load_meta_data(self, path=None, recursively=True):
        """Load meta data of state machine model from the file system

        The meta data of the state machine model is loaded from the file system and stored in the meta property of the
        model. Existing meta data is removed. Also the meta data of root state and children is loaded.

        :param str path: Optional path to the meta data file. If not given, the path will be derived from the state
            machine's path on the filesystem
        """
        meta_data_path = path if path is not None else self.state_machine.file_system_path

        if meta_data_path:
            path_meta_data = os.path.join(meta_data_path,
                                          storage.FILE_NAME_META_DATA)

            try:
                tmp_meta = storage.load_data_file(path_meta_data)
            except ValueError:
                tmp_meta = {}
        else:
            tmp_meta = {}

        # JSON returns a dict, which must be converted to a Vividict
        tmp_meta = Vividict(tmp_meta)

        if recursively:
            root_state_path = None if not path else os.path.join(
                path, self.root_state.state.state_id)
            self.root_state.load_meta_data(root_state_path)

        if tmp_meta:
            # assign the meta data to the state
            self.meta = tmp_meta
            self.meta_signal.emit(MetaSignalMsg("load_meta_data", "all", True))
Esempio n. 3
0
    def copy_meta_data_from_state_m(self, source_state_m):
        """Dismiss current meta data and copy meta data from given state model

        The meta data of the given state model is used as meta data for this state. Also the meta data of all state
        elements (data ports, outcomes, etc.) is overwritten with the meta data of the elements of the given state.

        :param source_state_m: State model to load the meta data from
        """

        self.meta = deepcopy(source_state_m.meta)

        for input_data_port_m in self.input_data_ports:
            source_data_port_m = source_state_m.get_input_data_port_m(
                input_data_port_m.data_port.data_port_id)
            input_data_port_m.meta = deepcopy(source_data_port_m.meta)
        for output_data_port_m in self.output_data_ports:
            source_data_port_m = source_state_m.get_output_data_port_m(
                output_data_port_m.data_port.data_port_id)
            output_data_port_m.meta = deepcopy(source_data_port_m.meta)
        for outcome_m in self.outcomes:
            source_outcome_m = source_state_m.get_outcome_m(
                outcome_m.outcome.outcome_id)
            outcome_m.meta = deepcopy(source_outcome_m.meta)

        self.meta_signal.emit(MetaSignalMsg("copy_state_m", "all", True))
Esempio n. 4
0
 def on_toggle_show_content(self, checkbox):
     if self._external_update:
         return
     self.model.meta['gui']['show_content'] = checkbox.get_active()
     msg = MetaSignalMsg(origin='state_overview',
                         change='show_content',
                         affects_children=False)
     self.model.meta_signal.emit(msg)
Esempio n. 5
0
    def load_meta_data(self, path=None):
        """Load meta data of state model from the file system

        The meta data of the state model is loaded from the file system and stored in the meta property of the model.
        Existing meta data is removed. Also the meta data of all state elements (data ports, outcomes,
        etc) are loaded, as those stored in the same file as the meta data of the state.

        This is either called on the __init__ of a new state model or if a state model for a container state is created,
        which then calls load_meta_data for all its children.

        :param str path: Optional file system path to the meta data file. If not given, the path will be derived from
            the state's path on the filesystem
        :return: if meta data file was loaded True otherwise False
        :rtype: bool
        """
        # TODO: for an Execution state this method is called for each hierarchy level again and again, still?? check it!
        # print("1AbstractState_load_meta_data: ", path, not path)
        if not path:
            path = self.state.file_system_path
        # print("2AbstractState_load_meta_data: ", path)
        if path is None:
            self.meta = Vividict({})
            return False
        path_meta_data = os.path.join(path, storage.FILE_NAME_META_DATA)

        # TODO: Should be removed with next minor release
        if not os.path.exists(path_meta_data):
            logger.debug("Because meta data was not found in {0} use backup option {1}"
                         "".format(path_meta_data, os.path.join(path, storage.FILE_NAME_META_DATA_OLD)))
            path_meta_data = os.path.join(path, storage.FILE_NAME_META_DATA_OLD)
            # TODO use the following logger message to debug meta data load process and to avoid maybe repetitive loads
            # if not os.path.exists(path_meta_data):
            #     logger.info("path not found {0}".format(path_meta_data))

        try:
            # print("try to load meta data from {0} for state {1}".format(path_meta_data, self.state))
            tmp_meta = storage.load_data_file(path_meta_data)
        except ValueError as e:
            # if no element which is newly generated log a warning
            # if os.path.exists(os.path.dirname(path)):
            #     logger.debug("Because '{1}' meta data of {0} was not loaded properly.".format(self, e))
            if not path.startswith(constants.RAFCON_TEMP_PATH_STORAGE) and not os.path.exists(os.path.dirname(path)):
                logger.debug("Because '{1}' meta data of {0} was not loaded properly.".format(self, e))
            tmp_meta = {}

        # JSON returns a dict, which must be converted to a Vividict
        tmp_meta = Vividict(tmp_meta)

        if tmp_meta:
            self._parse_for_element_meta_data(tmp_meta)
            # assign the meta data to the state
            self.meta = tmp_meta
            self.meta_signal.emit(MetaSignalMsg("load_meta_data", "all", True))
            return True
        else:
            # print("nothing to parse", tmp_meta)
            return False
Esempio n. 6
0
def insert_self_transition_meta_data(state_m, t_id, origin='graphical_editor', combined_action=False):

    try:
        gaphas_editor = global_gui_config.get_config_value('GAPHAS_EDITOR', True)
        y_axis_mirror = 1 if gaphas_editor else -1
        state_meta = state_m.get_meta_data_editor(for_gaphas=gaphas_editor)

        if 'rel_pos' not in state_meta or 'size' not in state_meta:
            return

        transition_m = state_m.parent.get_transition_m(t_id)
        margin = min(state_meta['size']) / 10.
        if gaphas_editor:
            origin_port_m = state_m.get_outcome_m(transition_m.transition.from_outcome)
            origin_port_x, origin_port_y = origin_port_m.get_meta_data_editor(for_gaphas=gaphas_editor)['rel_pos']
            target_port_x, target_port_y = state_m.get_meta_data_editor(for_gaphas=gaphas_editor)['income']['rel_pos']
            x_osign = 1 if origin_port_x/state_meta['size'][0] > 0.5 else -1
            x_tsign = -1 if target_port_x/state_meta['size'][0] < 0.5 else 1
            y_osign = 1 if origin_port_y/state_meta['size'][1] > 0.5 else -1
            y_tsign = -1 if target_port_y/state_meta['size'][1] < 0.5 else 1
            first_point_x = state_meta['rel_pos'][0] + x_osign*margin + (state_meta['size'][0] if x_osign == 1 else 0.)
            first_point_y = state_meta['rel_pos'][1] + y_osign*margin + (state_meta['size'][1] if y_osign == 1 else 0.)
            second_point_x = state_meta['rel_pos'][0] + x_tsign*margin + (state_meta['size'][0] if x_tsign == 1 else 0.)
            second_point_y = state_meta['rel_pos'][1] + y_tsign*margin + (state_meta['size'][1] if y_tsign == 1 else 0.)
        else:
            first_point_x = state_meta['rel_pos'][0] + state_meta['size'][0] + margin
            first_point_y = state_meta['rel_pos'][1] - y_axis_mirror * margin
            second_point_x = state_meta['rel_pos'][0] - margin
            second_point_y = state_meta['rel_pos'][1] - y_axis_mirror * margin

        if gaphas_editor and (first_point_x, first_point_y) == (second_point_x, second_point_y):
            waypoints = [(first_point_x, first_point_y)]
        else:
            waypoints = [(first_point_x, first_point_y), (second_point_x, second_point_y)]
        transition_m.set_meta_data_editor('waypoints', waypoints, from_gaphas=gaphas_editor)

        if combined_action:
            transition_m.meta_signal.emit(MetaSignalMsg(origin=origin, change='append_to_last_change'))
        else:
            transition_m.meta_signal.emit(MetaSignalMsg(origin=origin, change='viapoint_position'))
    except TypeError:
        # meta data generation currently only supported for OpenGL editor
        pass
Esempio n. 7
0
def toggle_show_content_flag_of_library_state_model(state_m):
    if not isinstance(state_m, LibraryStateModel):
        logger.warning("The show content is only available for LibraryStateModel instances and can not be toggled for"
                       "{0}".format(state_m))
        return

    if state_m.state.get_next_upper_library_root_state() is not None:
        logger.warning("Can not change show content of library state that is not uppermost library state.")
        return

    state_m.meta['gui']['show_content'] = False if state_m.meta['gui']['show_content'] else True
    msg = MetaSignalMsg(origin='state_overview', change='show_content', affects_children=False)
    state_m.meta_signal.emit(msg)
Esempio n. 8
0
    def load_meta_data(self, path=None):
        """Load meta data of state model from the file system

        The meta data of the state model is loaded from the file system and stored in the meta property of the model.
        Existing meta data is removed. Also the meta data of all state elements (data ports, outcomes,
        etc) are loaded, as those stored in the same file as the meta data of the state.

        This is either called on the __init__ of a new state model or if a state model for a container state is created,
        which then calls load_meta_data for all its children.

        :param str path: Optional file system path to the meta data file. If not given, the path will be derived from
            the state's path on the filesystem
        :return: if meta data file was loaded True otherwise False
        :rtype: bool
        """
        if not path:
            path = self.state.file_system_path
        if path is None:
            self.meta = Vividict({})
            return False
        path_meta_data = os.path.join(path, storage.FILE_NAME_META_DATA)
        try:
            tmp_meta = storage.load_data_file(path_meta_data)
        except ValueError as e:
            if not path.startswith(
                    constants.RAFCON_TEMP_PATH_STORAGE) and not os.path.exists(
                        os.path.dirname(path)):
                logger.debug(
                    "Because '{1}' meta data of {0} was not loaded properly.".
                    format(self, e))
            tmp_meta = {}

        # JSON returns a dict, which must be converted to a Vividict
        tmp_meta = Vividict(tmp_meta)

        if tmp_meta:
            self._parse_for_element_meta_data(tmp_meta)
            # assign the meta data to the state
            self.meta = tmp_meta
            self.meta_signal.emit(MetaSignalMsg("load_meta_data", "all", True))
            return True
        else:
            return False