repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
DLR-RM/RAFCON
source/rafcon/core/execution/execution_engine.py
ExecutionEngine.run_to_states
def run_to_states(self): """Property for the _run_to_states field """ self.execution_engine_lock.acquire() return_value = self._run_to_states self.execution_engine_lock.release() return return_value
python
def run_to_states(self): """Property for the _run_to_states field """ self.execution_engine_lock.acquire() return_value = self._run_to_states self.execution_engine_lock.release() return return_value
[ "def", "run_to_states", "(", "self", ")", ":", "self", ".", "execution_engine_lock", ".", "acquire", "(", ")", "return_value", "=", "self", ".", "_run_to_states", "self", ".", "execution_engine_lock", ".", "release", "(", ")", "return", "return_value" ]
Property for the _run_to_states field
[ "Property", "for", "the", "_run_to_states", "field" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L527-L534
train
40,600
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.recursively_preempt_states
def recursively_preempt_states(self): """ Preempt the state and all of it child states. """ super(ContainerState, self).recursively_preempt_states() # notify the transition condition variable to let the state instantaneously stop self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() for state in self.states.values(): state.recursively_preempt_states()
python
def recursively_preempt_states(self): """ Preempt the state and all of it child states. """ super(ContainerState, self).recursively_preempt_states() # notify the transition condition variable to let the state instantaneously stop self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() for state in self.states.values(): state.recursively_preempt_states()
[ "def", "recursively_preempt_states", "(", "self", ")", ":", "super", "(", "ContainerState", ",", "self", ")", ".", "recursively_preempt_states", "(", ")", "# notify the transition condition variable to let the state instantaneously stop", "self", ".", "_transitions_cv", ".", ...
Preempt the state and all of it child states.
[ "Preempt", "the", "state", "and", "all", "of", "it", "child", "states", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L222-L231
train
40,601
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.recursively_pause_states
def recursively_pause_states(self): """ Pause the state and all of it child states. """ super(ContainerState, self).recursively_pause_states() for state in self.states.values(): state.recursively_pause_states()
python
def recursively_pause_states(self): """ Pause the state and all of it child states. """ super(ContainerState, self).recursively_pause_states() for state in self.states.values(): state.recursively_pause_states()
[ "def", "recursively_pause_states", "(", "self", ")", ":", "super", "(", "ContainerState", ",", "self", ")", ".", "recursively_pause_states", "(", ")", "for", "state", "in", "self", ".", "states", ".", "values", "(", ")", ":", "state", ".", "recursively_pause...
Pause the state and all of it child states.
[ "Pause", "the", "state", "and", "all", "of", "it", "child", "states", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L233-L238
train
40,602
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.recursively_resume_states
def recursively_resume_states(self): """ Resume the state and all of it child states. """ super(ContainerState, self).recursively_resume_states() for state in self.states.values(): state.recursively_resume_states()
python
def recursively_resume_states(self): """ Resume the state and all of it child states. """ super(ContainerState, self).recursively_resume_states() for state in self.states.values(): state.recursively_resume_states()
[ "def", "recursively_resume_states", "(", "self", ")", ":", "super", "(", "ContainerState", ",", "self", ")", ".", "recursively_resume_states", "(", ")", "for", "state", "in", "self", ".", "states", ".", "values", "(", ")", ":", "state", ".", "recursively_res...
Resume the state and all of it child states.
[ "Resume", "the", "state", "and", "all", "of", "it", "child", "states", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L240-L245
train
40,603
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.handle_no_transition
def handle_no_transition(self, state): """ This function handles the case that there is no transition for a specific outcome of a sub-state. The method waits on a condition variable to a new transition that will be connected by the programmer or GUI-user. :param state: The sub-state to find a transition for :return: The transition for the target state. :raises exceptions.RuntimeError: if the execution engine is stopped (this will be caught at the end of the run method) """ transition = None while not transition: # (child) state preempted or aborted if self.preempted or state.final_outcome.outcome_id in [-2, -1]: if self.concurrency_queue: self.concurrency_queue.put(self.state_id) self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE if state.final_outcome.outcome_id == -1: self.final_outcome = Outcome(-1, "aborted") else: self.final_outcome = Outcome(-2, "preempted") logger.debug("{0} of {1} not connected, using default transition to parental {2}".format( state.final_outcome, state, self.final_outcome)) return None # depending on the execution mode pause execution execution_signal = state_machine_execution_engine.handle_execution_mode(self) if execution_signal is StateMachineExecutionStatus.STOPPED: # this will be caught at the end of the run method self.last_child.state_execution_status = StateExecutionStatus.INACTIVE logger.warning("State machine was stopped, while state {} waited for the next transition.".format( state.name )) return None # wait until the user connects the outcome of the state with a transition logger.warning("Waiting for new transition at {1} of {0} ".format(state, state.final_outcome)) self._transitions_cv.acquire() self._transitions_cv.wait(3.0) self._transitions_cv.release() transition = self.get_transition_for_outcome(state, state.final_outcome) return transition
python
def handle_no_transition(self, state): """ This function handles the case that there is no transition for a specific outcome of a sub-state. The method waits on a condition variable to a new transition that will be connected by the programmer or GUI-user. :param state: The sub-state to find a transition for :return: The transition for the target state. :raises exceptions.RuntimeError: if the execution engine is stopped (this will be caught at the end of the run method) """ transition = None while not transition: # (child) state preempted or aborted if self.preempted or state.final_outcome.outcome_id in [-2, -1]: if self.concurrency_queue: self.concurrency_queue.put(self.state_id) self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE if state.final_outcome.outcome_id == -1: self.final_outcome = Outcome(-1, "aborted") else: self.final_outcome = Outcome(-2, "preempted") logger.debug("{0} of {1} not connected, using default transition to parental {2}".format( state.final_outcome, state, self.final_outcome)) return None # depending on the execution mode pause execution execution_signal = state_machine_execution_engine.handle_execution_mode(self) if execution_signal is StateMachineExecutionStatus.STOPPED: # this will be caught at the end of the run method self.last_child.state_execution_status = StateExecutionStatus.INACTIVE logger.warning("State machine was stopped, while state {} waited for the next transition.".format( state.name )) return None # wait until the user connects the outcome of the state with a transition logger.warning("Waiting for new transition at {1} of {0} ".format(state, state.final_outcome)) self._transitions_cv.acquire() self._transitions_cv.wait(3.0) self._transitions_cv.release() transition = self.get_transition_for_outcome(state, state.final_outcome) return transition
[ "def", "handle_no_transition", "(", "self", ",", "state", ")", ":", "transition", "=", "None", "while", "not", "transition", ":", "# (child) state preempted or aborted", "if", "self", ".", "preempted", "or", "state", ".", "final_outcome", ".", "outcome_id", "in", ...
This function handles the case that there is no transition for a specific outcome of a sub-state. The method waits on a condition variable to a new transition that will be connected by the programmer or GUI-user. :param state: The sub-state to find a transition for :return: The transition for the target state. :raises exceptions.RuntimeError: if the execution engine is stopped (this will be caught at the end of the run method)
[ "This", "function", "handles", "the", "case", "that", "there", "is", "no", "transition", "for", "a", "specific", "outcome", "of", "a", "sub", "-", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L259-L306
train
40,604
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.handle_no_start_state
def handle_no_start_state(self): """Handles the situation, when no start state exists during execution The method waits, until a transition is created. It then checks again for an existing start state and waits again, if this is not the case. It returns the None state if the the state machine was stopped. """ start_state = self.get_start_state(set_final_outcome=True) while not start_state: # depending on the execution mode pause execution execution_signal = state_machine_execution_engine.handle_execution_mode(self) if execution_signal is StateMachineExecutionStatus.STOPPED: # this will be caught at the end of the run method return None self._transitions_cv.acquire() self._transitions_cv.wait(3.0) self._transitions_cv.release() start_state = self.get_start_state(set_final_outcome=True) return start_state
python
def handle_no_start_state(self): """Handles the situation, when no start state exists during execution The method waits, until a transition is created. It then checks again for an existing start state and waits again, if this is not the case. It returns the None state if the the state machine was stopped. """ start_state = self.get_start_state(set_final_outcome=True) while not start_state: # depending on the execution mode pause execution execution_signal = state_machine_execution_engine.handle_execution_mode(self) if execution_signal is StateMachineExecutionStatus.STOPPED: # this will be caught at the end of the run method return None self._transitions_cv.acquire() self._transitions_cv.wait(3.0) self._transitions_cv.release() start_state = self.get_start_state(set_final_outcome=True) return start_state
[ "def", "handle_no_start_state", "(", "self", ")", ":", "start_state", "=", "self", ".", "get_start_state", "(", "set_final_outcome", "=", "True", ")", "while", "not", "start_state", ":", "# depending on the execution mode pause execution", "execution_signal", "=", "stat...
Handles the situation, when no start state exists during execution The method waits, until a transition is created. It then checks again for an existing start state and waits again, if this is not the case. It returns the None state if the the state machine was stopped.
[ "Handles", "the", "situation", "when", "no", "start", "state", "exists", "during", "execution" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L308-L326
train
40,605
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_state
def add_state(self, state, storage_load=False): """Adds a state to the container state. :param state: the state that is going to be added :param storage_load: True if the state was directly loaded from filesystem :return: the state_id of the new state :raises exceptions.AttributeError: if state.state_id already exist """ assert isinstance(state, State) # logger.info("add state {}".format(state)) # handle the case that the child state id is the same as the container state id or future sibling state id while state.state_id == self.state_id or state.state_id in self.states: state.change_state_id() # TODO: add validity checks for states and then remove this check => to discuss if state.state_id in self._states.keys(): raise AttributeError("State id %s already exists in the container state", state.state_id) else: state.parent = self self._states[state.state_id] = state return state.state_id
python
def add_state(self, state, storage_load=False): """Adds a state to the container state. :param state: the state that is going to be added :param storage_load: True if the state was directly loaded from filesystem :return: the state_id of the new state :raises exceptions.AttributeError: if state.state_id already exist """ assert isinstance(state, State) # logger.info("add state {}".format(state)) # handle the case that the child state id is the same as the container state id or future sibling state id while state.state_id == self.state_id or state.state_id in self.states: state.change_state_id() # TODO: add validity checks for states and then remove this check => to discuss if state.state_id in self._states.keys(): raise AttributeError("State id %s already exists in the container state", state.state_id) else: state.parent = self self._states[state.state_id] = state return state.state_id
[ "def", "add_state", "(", "self", ",", "state", ",", "storage_load", "=", "False", ")", ":", "assert", "isinstance", "(", "state", ",", "State", ")", "# logger.info(\"add state {}\".format(state))", "# handle the case that the child state id is the same as the container state ...
Adds a state to the container state. :param state: the state that is going to be added :param storage_load: True if the state was directly loaded from filesystem :return: the state_id of the new state :raises exceptions.AttributeError: if state.state_id already exist
[ "Adds", "a", "state", "to", "the", "container", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L765-L787
train
40,606
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.remove_state
def remove_state(self, state_id, recursive=True, force=False, destroy=True): """Remove a state from the container state. :param state_id: the id of the state to remove :param recursive: a flag to indicate a recursive disassembling of all substates :param force: a flag to indicate forcefully deletion of all states (important for the decider state in the barrier concurrency state) :param destroy: a flag which indicates if the state should not only be disconnected from the state but also destroyed, including all its state elements :raises exceptions.AttributeError: if state.state_id does not """ if state_id not in self.states: raise AttributeError("State_id %s does not exist" % state_id) if state_id == self.start_state_id: self.set_start_state(None) # first delete all transitions and data_flows, which are connected to the state to be deleted keys_to_delete = [] for key, transition in self.transitions.items(): if transition.from_state == state_id or transition.to_state == state_id: keys_to_delete.append(key) for key in keys_to_delete: self.remove_transition(key, True) keys_to_delete = [] for key, data_flow in self.data_flows.items(): if data_flow.from_state == state_id or data_flow.to_state == state_id: keys_to_delete.append(key) for key in keys_to_delete: self.remove_data_flow(key) if recursive and not destroy: raise AttributeError("The recursive flag requires the destroy flag to be set, too.") if destroy: # Recursively delete all transitions, data flows and states within the state to be deleted self.states[state_id].destroy(recursive) # final delete the state it self self.states[state_id].parent = None return self.states.pop(state_id)
python
def remove_state(self, state_id, recursive=True, force=False, destroy=True): """Remove a state from the container state. :param state_id: the id of the state to remove :param recursive: a flag to indicate a recursive disassembling of all substates :param force: a flag to indicate forcefully deletion of all states (important for the decider state in the barrier concurrency state) :param destroy: a flag which indicates if the state should not only be disconnected from the state but also destroyed, including all its state elements :raises exceptions.AttributeError: if state.state_id does not """ if state_id not in self.states: raise AttributeError("State_id %s does not exist" % state_id) if state_id == self.start_state_id: self.set_start_state(None) # first delete all transitions and data_flows, which are connected to the state to be deleted keys_to_delete = [] for key, transition in self.transitions.items(): if transition.from_state == state_id or transition.to_state == state_id: keys_to_delete.append(key) for key in keys_to_delete: self.remove_transition(key, True) keys_to_delete = [] for key, data_flow in self.data_flows.items(): if data_flow.from_state == state_id or data_flow.to_state == state_id: keys_to_delete.append(key) for key in keys_to_delete: self.remove_data_flow(key) if recursive and not destroy: raise AttributeError("The recursive flag requires the destroy flag to be set, too.") if destroy: # Recursively delete all transitions, data flows and states within the state to be deleted self.states[state_id].destroy(recursive) # final delete the state it self self.states[state_id].parent = None return self.states.pop(state_id)
[ "def", "remove_state", "(", "self", ",", "state_id", ",", "recursive", "=", "True", ",", "force", "=", "False", ",", "destroy", "=", "True", ")", ":", "if", "state_id", "not", "in", "self", ".", "states", ":", "raise", "AttributeError", "(", "\"State_id ...
Remove a state from the container state. :param state_id: the id of the state to remove :param recursive: a flag to indicate a recursive disassembling of all substates :param force: a flag to indicate forcefully deletion of all states (important for the decider state in the barrier concurrency state) :param destroy: a flag which indicates if the state should not only be disconnected from the state but also destroyed, including all its state elements :raises exceptions.AttributeError: if state.state_id does not
[ "Remove", "a", "state", "from", "the", "container", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L791-L832
train
40,607
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.change_state_type
def change_state_type(self, state, new_state_class): """ Changes the type of the state to another type :param state: the state to be changed :param new_state_class: the new type of the state :return: the new state having the new state type :rtype: :py:class:`rafcon.core.states.state.State` :raises exceptions.ValueError: if the state does not exist in the container state """ from rafcon.gui.helpers.state import create_new_state_from_state_with_type state_id = state.state_id if state_id not in self.states: raise ValueError("State '{0}' with id '{1}' does not exist".format(state.name, state_id)) new_state = create_new_state_from_state_with_type(state, new_state_class) new_state.parent = self assert new_state.state_id == state_id self.states[state_id] = new_state return new_state
python
def change_state_type(self, state, new_state_class): """ Changes the type of the state to another type :param state: the state to be changed :param new_state_class: the new type of the state :return: the new state having the new state type :rtype: :py:class:`rafcon.core.states.state.State` :raises exceptions.ValueError: if the state does not exist in the container state """ from rafcon.gui.helpers.state import create_new_state_from_state_with_type state_id = state.state_id if state_id not in self.states: raise ValueError("State '{0}' with id '{1}' does not exist".format(state.name, state_id)) new_state = create_new_state_from_state_with_type(state, new_state_class) new_state.parent = self assert new_state.state_id == state_id self.states[state_id] = new_state return new_state
[ "def", "change_state_type", "(", "self", ",", "state", ",", "new_state_class", ")", ":", "from", "rafcon", ".", "gui", ".", "helpers", ".", "state", "import", "create_new_state_from_state_with_type", "state_id", "=", "state", ".", "state_id", "if", "state_id", "...
Changes the type of the state to another type :param state: the state to be changed :param new_state_class: the new type of the state :return: the new state having the new state type :rtype: :py:class:`rafcon.core.states.state.State` :raises exceptions.ValueError: if the state does not exist in the container state
[ "Changes", "the", "type", "of", "the", "state", "to", "another", "type" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1047-L1070
train
40,608
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.set_start_state
def set_start_state(self, state): """Sets the start state of a container state :param state: The state_id of a state or a direct reference ot he state (that was already added to the container) that will be the start state of this container state. """ if state is None: self.start_state_id = None elif isinstance(state, State): self.start_state_id = state.state_id else: self.start_state_id = state
python
def set_start_state(self, state): """Sets the start state of a container state :param state: The state_id of a state or a direct reference ot he state (that was already added to the container) that will be the start state of this container state. """ if state is None: self.start_state_id = None elif isinstance(state, State): self.start_state_id = state.state_id else: self.start_state_id = state
[ "def", "set_start_state", "(", "self", ",", "state", ")", ":", "if", "state", "is", "None", ":", "self", ".", "start_state_id", "=", "None", "elif", "isinstance", "(", "state", ",", "State", ")", ":", "self", ".", "start_state_id", "=", "state", ".", "...
Sets the start state of a container state :param state: The state_id of a state or a direct reference ot he state (that was already added to the container) that will be the start state of this container state.
[ "Sets", "the", "start", "state", "of", "a", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1074-L1086
train
40,609
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.get_start_state
def get_start_state(self, set_final_outcome=False): """Get the start state of the container state :param set_final_outcome: if the final_outcome of the state should be set if the income directly connects to an outcome :return: the start state """ # overwrite the start state in the case that a specific start state is specific e.g. by start_from_state if self.get_path() in state_machine_execution_engine.start_state_paths: for state_id, state in self.states.items(): if state.get_path() in state_machine_execution_engine.start_state_paths: state_machine_execution_engine.start_state_paths.remove(self.get_path()) self._start_state_modified = True return state if self.start_state_id is None: return None # It is possible to connect the income directly with an outcome if self.start_state_id == self.state_id: if set_final_outcome: for transition_id in self.transitions: # the transition of which the from state is None is the transition that directly connects the income if self.transitions[transition_id].from_state is None: to_outcome_id = self.transitions[transition_id].to_outcome self.final_outcome = self.outcomes[to_outcome_id] break return self return self.states[self.start_state_id]
python
def get_start_state(self, set_final_outcome=False): """Get the start state of the container state :param set_final_outcome: if the final_outcome of the state should be set if the income directly connects to an outcome :return: the start state """ # overwrite the start state in the case that a specific start state is specific e.g. by start_from_state if self.get_path() in state_machine_execution_engine.start_state_paths: for state_id, state in self.states.items(): if state.get_path() in state_machine_execution_engine.start_state_paths: state_machine_execution_engine.start_state_paths.remove(self.get_path()) self._start_state_modified = True return state if self.start_state_id is None: return None # It is possible to connect the income directly with an outcome if self.start_state_id == self.state_id: if set_final_outcome: for transition_id in self.transitions: # the transition of which the from state is None is the transition that directly connects the income if self.transitions[transition_id].from_state is None: to_outcome_id = self.transitions[transition_id].to_outcome self.final_outcome = self.outcomes[to_outcome_id] break return self return self.states[self.start_state_id]
[ "def", "get_start_state", "(", "self", ",", "set_final_outcome", "=", "False", ")", ":", "# overwrite the start state in the case that a specific start state is specific e.g. by start_from_state", "if", "self", ".", "get_path", "(", ")", "in", "state_machine_execution_engine", ...
Get the start state of the container state :param set_final_outcome: if the final_outcome of the state should be set if the income directly connects to an outcome :return: the start state
[ "Get", "the", "start", "state", "of", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1088-L1118
train
40,610
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.check_transition_id
def check_transition_id(self, transition_id): """ Check the transition id and calculate a new one if its None :param transition_id: The transition-id to check :return: The new transition id :raises exceptions.AttributeError: if transition.transition_id already exists """ if transition_id is not None: if transition_id in self._transitions.keys(): raise AttributeError("The transition id %s already exists. Cannot add transition!", transition_id) else: transition_id = generate_transition_id() while transition_id in self._transitions.keys(): transition_id = generate_transition_id() return transition_id
python
def check_transition_id(self, transition_id): """ Check the transition id and calculate a new one if its None :param transition_id: The transition-id to check :return: The new transition id :raises exceptions.AttributeError: if transition.transition_id already exists """ if transition_id is not None: if transition_id in self._transitions.keys(): raise AttributeError("The transition id %s already exists. Cannot add transition!", transition_id) else: transition_id = generate_transition_id() while transition_id in self._transitions.keys(): transition_id = generate_transition_id() return transition_id
[ "def", "check_transition_id", "(", "self", ",", "transition_id", ")", ":", "if", "transition_id", "is", "not", "None", ":", "if", "transition_id", "in", "self", ".", "_transitions", ".", "keys", "(", ")", ":", "raise", "AttributeError", "(", "\"The transition ...
Check the transition id and calculate a new one if its None :param transition_id: The transition-id to check :return: The new transition id :raises exceptions.AttributeError: if transition.transition_id already exists
[ "Check", "the", "transition", "id", "and", "calculate", "a", "new", "one", "if", "its", "None" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1145-L1159
train
40,611
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.check_if_outcome_already_connected
def check_if_outcome_already_connected(self, from_state_id, from_outcome): """ check if outcome of from state is not already connected :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :raises exceptions.AttributeError: if the outcome of the state with the state_id==from_state_id is already connected """ for trans_key, transition in self.transitions.items(): if transition.from_state == from_state_id: if transition.from_outcome == from_outcome: raise AttributeError("Outcome %s of state %s is already connected" % (str(from_outcome), str(from_state_id)))
python
def check_if_outcome_already_connected(self, from_state_id, from_outcome): """ check if outcome of from state is not already connected :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :raises exceptions.AttributeError: if the outcome of the state with the state_id==from_state_id is already connected """ for trans_key, transition in self.transitions.items(): if transition.from_state == from_state_id: if transition.from_outcome == from_outcome: raise AttributeError("Outcome %s of state %s is already connected" % (str(from_outcome), str(from_state_id)))
[ "def", "check_if_outcome_already_connected", "(", "self", ",", "from_state_id", ",", "from_outcome", ")", ":", "for", "trans_key", ",", "transition", "in", "self", ".", "transitions", ".", "items", "(", ")", ":", "if", "transition", ".", "from_state", "==", "f...
check if outcome of from state is not already connected :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :raises exceptions.AttributeError: if the outcome of the state with the state_id==from_state_id is already connected
[ "check", "if", "outcome", "of", "from", "state", "is", "not", "already", "connected" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1164-L1176
train
40,612
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.create_transition
def create_transition(self, from_state_id, from_outcome, to_state_id, to_outcome, transition_id): """ Creates a new transition. Lookout: Check the parameters first before creating a new transition :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :param to_state_id: The target state of the transition :param to_outcome: The target outcome of a container state :param transition_id: An optional transition id for the new transition :raises exceptions.AttributeError: if the from or to state is incorrect :return: the id of the new transition """ # get correct states if from_state_id is not None: if from_state_id == self.state_id: from_state = self else: from_state = self.states[from_state_id] # finally add transition if from_outcome is not None: if from_outcome in from_state.outcomes: if to_outcome is not None: if to_outcome in self.outcomes: # if to_state is None then the to_outcome must be an outcome of self self.transitions[transition_id] = \ Transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id, self) else: raise AttributeError("to_state does not have outcome %s", to_outcome) else: # to outcome is None but to_state is not None, so the transition is valid self.transitions[transition_id] = \ Transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id, self) else: raise AttributeError("from_state does not have outcome %s", from_state) else: self.transitions[transition_id] = \ Transition(None, None, to_state_id, to_outcome, transition_id, self) # notify all states waiting for transition to be connected self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() return transition_id
python
def create_transition(self, from_state_id, from_outcome, to_state_id, to_outcome, transition_id): """ Creates a new transition. Lookout: Check the parameters first before creating a new transition :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :param to_state_id: The target state of the transition :param to_outcome: The target outcome of a container state :param transition_id: An optional transition id for the new transition :raises exceptions.AttributeError: if the from or to state is incorrect :return: the id of the new transition """ # get correct states if from_state_id is not None: if from_state_id == self.state_id: from_state = self else: from_state = self.states[from_state_id] # finally add transition if from_outcome is not None: if from_outcome in from_state.outcomes: if to_outcome is not None: if to_outcome in self.outcomes: # if to_state is None then the to_outcome must be an outcome of self self.transitions[transition_id] = \ Transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id, self) else: raise AttributeError("to_state does not have outcome %s", to_outcome) else: # to outcome is None but to_state is not None, so the transition is valid self.transitions[transition_id] = \ Transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id, self) else: raise AttributeError("from_state does not have outcome %s", from_state) else: self.transitions[transition_id] = \ Transition(None, None, to_state_id, to_outcome, transition_id, self) # notify all states waiting for transition to be connected self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() return transition_id
[ "def", "create_transition", "(", "self", ",", "from_state_id", ",", "from_outcome", ",", "to_state_id", ",", "to_outcome", ",", "transition_id", ")", ":", "# get correct states", "if", "from_state_id", "is", "not", "None", ":", "if", "from_state_id", "==", "self",...
Creates a new transition. Lookout: Check the parameters first before creating a new transition :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :param to_state_id: The target state of the transition :param to_outcome: The target outcome of a container state :param transition_id: An optional transition id for the new transition :raises exceptions.AttributeError: if the from or to state is incorrect :return: the id of the new transition
[ "Creates", "a", "new", "transition", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1179-L1223
train
40,613
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_transition
def add_transition(self, from_state_id, from_outcome, to_state_id, to_outcome, transition_id=None): """Adds a transition to the container state Note: Either the toState or the toOutcome needs to be "None" :param from_state_id: The source state of the transition :param from_outcome: The outcome id of the source state to connect the transition to :param to_state_id: The target state of the transition :param to_outcome: The target outcome id of a container state :param transition_id: An optional transition id for the new transition """ transition_id = self.check_transition_id(transition_id) # Set from_state_id to None for start transitions, as from_state_id and from_outcome should both be None for # these transitions if from_state_id == self.state_id and from_outcome is None: from_state_id = None new_transition = Transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id, self) self.transitions[transition_id] = new_transition # notify all states waiting for transition to be connected self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() # self.create_transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id) return transition_id
python
def add_transition(self, from_state_id, from_outcome, to_state_id, to_outcome, transition_id=None): """Adds a transition to the container state Note: Either the toState or the toOutcome needs to be "None" :param from_state_id: The source state of the transition :param from_outcome: The outcome id of the source state to connect the transition to :param to_state_id: The target state of the transition :param to_outcome: The target outcome id of a container state :param transition_id: An optional transition id for the new transition """ transition_id = self.check_transition_id(transition_id) # Set from_state_id to None for start transitions, as from_state_id and from_outcome should both be None for # these transitions if from_state_id == self.state_id and from_outcome is None: from_state_id = None new_transition = Transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id, self) self.transitions[transition_id] = new_transition # notify all states waiting for transition to be connected self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() # self.create_transition(from_state_id, from_outcome, to_state_id, to_outcome, transition_id) return transition_id
[ "def", "add_transition", "(", "self", ",", "from_state_id", ",", "from_outcome", ",", "to_state_id", ",", "to_outcome", ",", "transition_id", "=", "None", ")", ":", "transition_id", "=", "self", ".", "check_transition_id", "(", "transition_id", ")", "# Set from_st...
Adds a transition to the container state Note: Either the toState or the toOutcome needs to be "None" :param from_state_id: The source state of the transition :param from_outcome: The outcome id of the source state to connect the transition to :param to_state_id: The target state of the transition :param to_outcome: The target outcome id of a container state :param transition_id: An optional transition id for the new transition
[ "Adds", "a", "transition", "to", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1227-L1254
train
40,614
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.get_transition_for_outcome
def get_transition_for_outcome(self, state, outcome): """Determines the next transition of a state. :param state: The state for which the transition is determined :param outcome: The outcome of the state, that is given in the first parameter :return: the transition specified by the the state and the outcome :raises exceptions.TypeError: if the types of the passed parameters are incorrect """ if not isinstance(state, State): raise TypeError("state must be of type State") if not isinstance(outcome, Outcome): raise TypeError("outcome must be of type Outcome") result_transition = None for key, transition in self.transitions.items(): if transition.from_state == state.state_id and transition.from_outcome == outcome.outcome_id: result_transition = transition return result_transition
python
def get_transition_for_outcome(self, state, outcome): """Determines the next transition of a state. :param state: The state for which the transition is determined :param outcome: The outcome of the state, that is given in the first parameter :return: the transition specified by the the state and the outcome :raises exceptions.TypeError: if the types of the passed parameters are incorrect """ if not isinstance(state, State): raise TypeError("state must be of type State") if not isinstance(outcome, Outcome): raise TypeError("outcome must be of type Outcome") result_transition = None for key, transition in self.transitions.items(): if transition.from_state == state.state_id and transition.from_outcome == outcome.outcome_id: result_transition = transition return result_transition
[ "def", "get_transition_for_outcome", "(", "self", ",", "state", ",", "outcome", ")", ":", "if", "not", "isinstance", "(", "state", ",", "State", ")", ":", "raise", "TypeError", "(", "\"state must be of type State\"", ")", "if", "not", "isinstance", "(", "outco...
Determines the next transition of a state. :param state: The state for which the transition is determined :param outcome: The outcome of the state, that is given in the first parameter :return: the transition specified by the the state and the outcome :raises exceptions.TypeError: if the types of the passed parameters are incorrect
[ "Determines", "the", "next", "transition", "of", "a", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1256-L1272
train
40,615
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.remove_transition
def remove_transition(self, transition_id, destroy=True): """Removes a transition from the container state :param transition_id: the id of the transition to remove :raises exceptions.AttributeError: if the transition_id is already used """ if transition_id == -1 or transition_id == -2: raise AttributeError("The transition_id must not be -1 (Aborted) or -2 (Preempted)") if transition_id not in self._transitions: raise AttributeError("The transition_id %s does not exist" % str(transition_id)) self.transitions[transition_id].parent = None return self.transitions.pop(transition_id)
python
def remove_transition(self, transition_id, destroy=True): """Removes a transition from the container state :param transition_id: the id of the transition to remove :raises exceptions.AttributeError: if the transition_id is already used """ if transition_id == -1 or transition_id == -2: raise AttributeError("The transition_id must not be -1 (Aborted) or -2 (Preempted)") if transition_id not in self._transitions: raise AttributeError("The transition_id %s does not exist" % str(transition_id)) self.transitions[transition_id].parent = None return self.transitions.pop(transition_id)
[ "def", "remove_transition", "(", "self", ",", "transition_id", ",", "destroy", "=", "True", ")", ":", "if", "transition_id", "==", "-", "1", "or", "transition_id", "==", "-", "2", ":", "raise", "AttributeError", "(", "\"The transition_id must not be -1 (Aborted) o...
Removes a transition from the container state :param transition_id: the id of the transition to remove :raises exceptions.AttributeError: if the transition_id is already used
[ "Removes", "a", "transition", "from", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1276-L1288
train
40,616
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.remove_outcome_hook
def remove_outcome_hook(self, outcome_id): """Removes internal transition going to the outcome """ for transition_id in list(self.transitions.keys()): transition = self.transitions[transition_id] if transition.to_outcome == outcome_id and transition.to_state == self.state_id: self.remove_transition(transition_id)
python
def remove_outcome_hook(self, outcome_id): """Removes internal transition going to the outcome """ for transition_id in list(self.transitions.keys()): transition = self.transitions[transition_id] if transition.to_outcome == outcome_id and transition.to_state == self.state_id: self.remove_transition(transition_id)
[ "def", "remove_outcome_hook", "(", "self", ",", "outcome_id", ")", ":", "for", "transition_id", "in", "list", "(", "self", ".", "transitions", ".", "keys", "(", ")", ")", ":", "transition", "=", "self", ".", "transitions", "[", "transition_id", "]", "if", ...
Removes internal transition going to the outcome
[ "Removes", "internal", "transition", "going", "to", "the", "outcome" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1291-L1297
train
40,617
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.check_data_flow_id
def check_data_flow_id(self, data_flow_id): """ Check the data flow id and calculate a new one if its None :param data_flow_id: The data flow id to check :return: The new data flow id :raises exceptions.AttributeError: if data_flow.data_flow_id already exists """ if data_flow_id is not None: if data_flow_id in self._data_flows.keys(): raise AttributeError("The data_flow id %s already exists. Cannot add data_flow!", data_flow_id) else: data_flow_id = generate_data_flow_id() while data_flow_id in self._data_flows.keys(): data_flow_id = generate_data_flow_id() return data_flow_id
python
def check_data_flow_id(self, data_flow_id): """ Check the data flow id and calculate a new one if its None :param data_flow_id: The data flow id to check :return: The new data flow id :raises exceptions.AttributeError: if data_flow.data_flow_id already exists """ if data_flow_id is not None: if data_flow_id in self._data_flows.keys(): raise AttributeError("The data_flow id %s already exists. Cannot add data_flow!", data_flow_id) else: data_flow_id = generate_data_flow_id() while data_flow_id in self._data_flows.keys(): data_flow_id = generate_data_flow_id() return data_flow_id
[ "def", "check_data_flow_id", "(", "self", ",", "data_flow_id", ")", ":", "if", "data_flow_id", "is", "not", "None", ":", "if", "data_flow_id", "in", "self", ".", "_data_flows", ".", "keys", "(", ")", ":", "raise", "AttributeError", "(", "\"The data_flow id %s ...
Check the data flow id and calculate a new one if its None :param data_flow_id: The data flow id to check :return: The new data flow id :raises exceptions.AttributeError: if data_flow.data_flow_id already exists
[ "Check", "the", "data", "flow", "id", "and", "calculate", "a", "new", "one", "if", "its", "None" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1307-L1321
train
40,618
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_data_flow
def add_data_flow(self, from_state_id, from_data_port_id, to_state_id, to_data_port_id, data_flow_id=None): """Adds a data_flow to the container state :param from_state_id: The id source state of the data_flow :param from_data_port_id: The output_key of the source state :param to_state_id: The id target state of the data_flow :param to_data_port_id: The input_key of the target state :param data_flow_id: an optional id for the data flow """ data_flow_id = self.check_data_flow_id(data_flow_id) self.data_flows[data_flow_id] = DataFlow(from_state_id, from_data_port_id, to_state_id, to_data_port_id, data_flow_id, self) return data_flow_id
python
def add_data_flow(self, from_state_id, from_data_port_id, to_state_id, to_data_port_id, data_flow_id=None): """Adds a data_flow to the container state :param from_state_id: The id source state of the data_flow :param from_data_port_id: The output_key of the source state :param to_state_id: The id target state of the data_flow :param to_data_port_id: The input_key of the target state :param data_flow_id: an optional id for the data flow """ data_flow_id = self.check_data_flow_id(data_flow_id) self.data_flows[data_flow_id] = DataFlow(from_state_id, from_data_port_id, to_state_id, to_data_port_id, data_flow_id, self) return data_flow_id
[ "def", "add_data_flow", "(", "self", ",", "from_state_id", ",", "from_data_port_id", ",", "to_state_id", ",", "to_data_port_id", ",", "data_flow_id", "=", "None", ")", ":", "data_flow_id", "=", "self", ".", "check_data_flow_id", "(", "data_flow_id", ")", "self", ...
Adds a data_flow to the container state :param from_state_id: The id source state of the data_flow :param from_data_port_id: The output_key of the source state :param to_state_id: The id target state of the data_flow :param to_data_port_id: The input_key of the target state :param data_flow_id: an optional id for the data flow
[ "Adds", "a", "data_flow", "to", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1326-L1339
train
40,619
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.remove_data_flow
def remove_data_flow(self, data_flow_id, destroy=True): """ Removes a data flow from the container state :param int data_flow_id: the id of the data_flow to remove :raises exceptions.AttributeError: if the data_flow_id does not exist """ if data_flow_id not in self._data_flows: raise AttributeError("The data_flow_id %s does not exist" % str(data_flow_id)) self._data_flows[data_flow_id].parent = None return self._data_flows.pop(data_flow_id)
python
def remove_data_flow(self, data_flow_id, destroy=True): """ Removes a data flow from the container state :param int data_flow_id: the id of the data_flow to remove :raises exceptions.AttributeError: if the data_flow_id does not exist """ if data_flow_id not in self._data_flows: raise AttributeError("The data_flow_id %s does not exist" % str(data_flow_id)) self._data_flows[data_flow_id].parent = None return self._data_flows.pop(data_flow_id)
[ "def", "remove_data_flow", "(", "self", ",", "data_flow_id", ",", "destroy", "=", "True", ")", ":", "if", "data_flow_id", "not", "in", "self", ".", "_data_flows", ":", "raise", "AttributeError", "(", "\"The data_flow_id %s does not exist\"", "%", "str", "(", "da...
Removes a data flow from the container state :param int data_flow_id: the id of the data_flow to remove :raises exceptions.AttributeError: if the data_flow_id does not exist
[ "Removes", "a", "data", "flow", "from", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1343-L1353
train
40,620
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.remove_data_flows_with_data_port_id
def remove_data_flows_with_data_port_id(self, data_port_id): """Remove an data ports whose from_key or to_key equals the passed data_port_id :param int data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id """ # delete all data flows in parent related to data_port_id and self.state_id = external data flows # checking is_root_state_of_library is only necessary in case of scoped variables, as the scoped variables # they are not destroyed by the library state, as the library state does not have a reference to the scoped vars if not self.is_root_state and not self.is_root_state_of_library: data_flow_ids_to_remove = [] for data_flow_id, data_flow in self.parent.data_flows.items(): if data_flow.from_state == self.state_id and data_flow.from_key == data_port_id or \ data_flow.to_state == self.state_id and data_flow.to_key == data_port_id: data_flow_ids_to_remove.append(data_flow_id) for data_flow_id in data_flow_ids_to_remove: self.parent.remove_data_flow(data_flow_id) # delete all data flows in self related to data_port_id and self.state_id = internal data flows data_flow_ids_to_remove = [] for data_flow_id, data_flow in self.data_flows.items(): if data_flow.from_state == self.state_id and data_flow.from_key == data_port_id or \ data_flow.to_state == self.state_id and data_flow.to_key == data_port_id: data_flow_ids_to_remove.append(data_flow_id) for data_flow_id in data_flow_ids_to_remove: self.remove_data_flow(data_flow_id)
python
def remove_data_flows_with_data_port_id(self, data_port_id): """Remove an data ports whose from_key or to_key equals the passed data_port_id :param int data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id """ # delete all data flows in parent related to data_port_id and self.state_id = external data flows # checking is_root_state_of_library is only necessary in case of scoped variables, as the scoped variables # they are not destroyed by the library state, as the library state does not have a reference to the scoped vars if not self.is_root_state and not self.is_root_state_of_library: data_flow_ids_to_remove = [] for data_flow_id, data_flow in self.parent.data_flows.items(): if data_flow.from_state == self.state_id and data_flow.from_key == data_port_id or \ data_flow.to_state == self.state_id and data_flow.to_key == data_port_id: data_flow_ids_to_remove.append(data_flow_id) for data_flow_id in data_flow_ids_to_remove: self.parent.remove_data_flow(data_flow_id) # delete all data flows in self related to data_port_id and self.state_id = internal data flows data_flow_ids_to_remove = [] for data_flow_id, data_flow in self.data_flows.items(): if data_flow.from_state == self.state_id and data_flow.from_key == data_port_id or \ data_flow.to_state == self.state_id and data_flow.to_key == data_port_id: data_flow_ids_to_remove.append(data_flow_id) for data_flow_id in data_flow_ids_to_remove: self.remove_data_flow(data_flow_id)
[ "def", "remove_data_flows_with_data_port_id", "(", "self", ",", "data_port_id", ")", ":", "# delete all data flows in parent related to data_port_id and self.state_id = external data flows", "# checking is_root_state_of_library is only necessary in case of scoped variables, as the scoped variables...
Remove an data ports whose from_key or to_key equals the passed data_port_id :param int data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id
[ "Remove", "an", "data", "ports", "whose", "from_key", "or", "to_key", "equals", "the", "passed", "data_port_id" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1356-L1384
train
40,621
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.get_scoped_variable_from_name
def get_scoped_variable_from_name(self, name): """ Get the scoped variable for a unique name :param name: the unique name of the scoped variable :return: the scoped variable specified by the name :raises exceptions.AttributeError: if the name is not in the the scoped_variables dictionary """ for scoped_variable_id, scoped_variable in self.scoped_variables.items(): if scoped_variable.name == name: return scoped_variable_id raise AttributeError("Name %s is not in scoped_variables dictionary", name)
python
def get_scoped_variable_from_name(self, name): """ Get the scoped variable for a unique name :param name: the unique name of the scoped variable :return: the scoped variable specified by the name :raises exceptions.AttributeError: if the name is not in the the scoped_variables dictionary """ for scoped_variable_id, scoped_variable in self.scoped_variables.items(): if scoped_variable.name == name: return scoped_variable_id raise AttributeError("Name %s is not in scoped_variables dictionary", name)
[ "def", "get_scoped_variable_from_name", "(", "self", ",", "name", ")", ":", "for", "scoped_variable_id", ",", "scoped_variable", "in", "self", ".", "scoped_variables", ".", "items", "(", ")", ":", "if", "scoped_variable", ".", "name", "==", "name", ":", "retur...
Get the scoped variable for a unique name :param name: the unique name of the scoped variable :return: the scoped variable specified by the name :raises exceptions.AttributeError: if the name is not in the the scoped_variables dictionary
[ "Get", "the", "scoped", "variable", "for", "a", "unique", "name" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1390-L1400
train
40,622
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_scoped_variable
def add_scoped_variable(self, name, data_type=None, default_value=None, scoped_variable_id=None): """ Adds a scoped variable to the container state :param name: The name of the scoped variable :param data_type: An optional data type of the scoped variable :param default_value: An optional default value of the scoped variable :param scoped_variable_id: An optional scoped variable id of the :return: the unique id of the added scoped variable :raises exceptions.ValueError: if the scoped variable is not valid """ if scoped_variable_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state scoped_variable_id = generate_data_port_id(self.get_data_port_ids()) self._scoped_variables[scoped_variable_id] = ScopedVariable(name, data_type, default_value, scoped_variable_id, self) # Check for name uniqueness valid, message = self._check_data_port_name(self._scoped_variables[scoped_variable_id]) if not valid: self._scoped_variables[scoped_variable_id].parent = None del self._scoped_variables[scoped_variable_id] raise ValueError(message) return scoped_variable_id
python
def add_scoped_variable(self, name, data_type=None, default_value=None, scoped_variable_id=None): """ Adds a scoped variable to the container state :param name: The name of the scoped variable :param data_type: An optional data type of the scoped variable :param default_value: An optional default value of the scoped variable :param scoped_variable_id: An optional scoped variable id of the :return: the unique id of the added scoped variable :raises exceptions.ValueError: if the scoped variable is not valid """ if scoped_variable_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state scoped_variable_id = generate_data_port_id(self.get_data_port_ids()) self._scoped_variables[scoped_variable_id] = ScopedVariable(name, data_type, default_value, scoped_variable_id, self) # Check for name uniqueness valid, message = self._check_data_port_name(self._scoped_variables[scoped_variable_id]) if not valid: self._scoped_variables[scoped_variable_id].parent = None del self._scoped_variables[scoped_variable_id] raise ValueError(message) return scoped_variable_id
[ "def", "add_scoped_variable", "(", "self", ",", "name", ",", "data_type", "=", "None", ",", "default_value", "=", "None", ",", "scoped_variable_id", "=", "None", ")", ":", "if", "scoped_variable_id", "is", "None", ":", "# All data port ids have to passed to the id g...
Adds a scoped variable to the container state :param name: The name of the scoped variable :param data_type: An optional data type of the scoped variable :param default_value: An optional default value of the scoped variable :param scoped_variable_id: An optional scoped variable id of the :return: the unique id of the added scoped variable :raises exceptions.ValueError: if the scoped variable is not valid
[ "Adds", "a", "scoped", "variable", "to", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1404-L1427
train
40,623
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.remove_scoped_variable
def remove_scoped_variable(self, scoped_variable_id, destroy=True): """Remove a scoped variable from the container state :param scoped_variable_id: the id of the scoped variable to remove :raises exceptions.AttributeError: if the id of the scoped variable already exists """ if scoped_variable_id not in self._scoped_variables: raise AttributeError("A scoped variable with id %s does not exist" % str(scoped_variable_id)) # delete all data flows connected to scoped_variable if destroy: self.remove_data_flows_with_data_port_id(scoped_variable_id) # delete scoped variable self._scoped_variables[scoped_variable_id].parent = None return self._scoped_variables.pop(scoped_variable_id)
python
def remove_scoped_variable(self, scoped_variable_id, destroy=True): """Remove a scoped variable from the container state :param scoped_variable_id: the id of the scoped variable to remove :raises exceptions.AttributeError: if the id of the scoped variable already exists """ if scoped_variable_id not in self._scoped_variables: raise AttributeError("A scoped variable with id %s does not exist" % str(scoped_variable_id)) # delete all data flows connected to scoped_variable if destroy: self.remove_data_flows_with_data_port_id(scoped_variable_id) # delete scoped variable self._scoped_variables[scoped_variable_id].parent = None return self._scoped_variables.pop(scoped_variable_id)
[ "def", "remove_scoped_variable", "(", "self", ",", "scoped_variable_id", ",", "destroy", "=", "True", ")", ":", "if", "scoped_variable_id", "not", "in", "self", ".", "_scoped_variables", ":", "raise", "AttributeError", "(", "\"A scoped variable with id %s does not exist...
Remove a scoped variable from the container state :param scoped_variable_id: the id of the scoped variable to remove :raises exceptions.AttributeError: if the id of the scoped variable already exists
[ "Remove", "a", "scoped", "variable", "from", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1431-L1446
train
40,624
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.get_data_port
def get_data_port(self, state_id, port_id): """Searches for a data port The data port specified by the state id and data port id is searched in the state itself and in its children. :param str state_id: The id of the state the port is in :param int port_id: The id of the port :return: The searched port or None if it is not found """ if state_id == self.state_id: return self.get_data_port_by_id(port_id) for child_state_id, child_state in self.states.items(): if state_id != child_state_id: continue port = child_state.get_data_port_by_id(port_id) if port: return port return None
python
def get_data_port(self, state_id, port_id): """Searches for a data port The data port specified by the state id and data port id is searched in the state itself and in its children. :param str state_id: The id of the state the port is in :param int port_id: The id of the port :return: The searched port or None if it is not found """ if state_id == self.state_id: return self.get_data_port_by_id(port_id) for child_state_id, child_state in self.states.items(): if state_id != child_state_id: continue port = child_state.get_data_port_by_id(port_id) if port: return port return None
[ "def", "get_data_port", "(", "self", ",", "state_id", ",", "port_id", ")", ":", "if", "state_id", "==", "self", ".", "state_id", ":", "return", "self", ".", "get_data_port_by_id", "(", "port_id", ")", "for", "child_state_id", ",", "child_state", "in", "self"...
Searches for a data port The data port specified by the state id and data port id is searched in the state itself and in its children. :param str state_id: The id of the state the port is in :param int port_id: The id of the port :return: The searched port or None if it is not found
[ "Searches", "for", "a", "data", "port" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1462-L1479
train
40,625
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.get_inputs_for_state
def get_inputs_for_state(self, state): """Retrieves all input data of a state. If several data flows are connected to an input port the most current data is used for the specific input port. :param state: the state of which the input data is determined :return: the input data of the target state """ result_dict = {} tmp_dict = self.get_default_input_values_for_state(state) result_dict.update(tmp_dict) for input_port_key, value in state.input_data_ports.items(): # for all input keys fetch the correct data_flow connection and read data into the result_dict actual_value = None actual_value_time = 0 for data_flow_key, data_flow in self.data_flows.items(): if data_flow.to_key == input_port_key: if data_flow.to_state == state.state_id: # fetch data from the scoped_data list: the key is the data_port_key + the state_id key = str(data_flow.from_key) + data_flow.from_state if key in self.scoped_data: if actual_value is None or actual_value_time < self.scoped_data[key].timestamp: actual_value = deepcopy(self.scoped_data[key].value) actual_value_time = self.scoped_data[key].timestamp if actual_value is not None: result_dict[value.name] = actual_value return result_dict
python
def get_inputs_for_state(self, state): """Retrieves all input data of a state. If several data flows are connected to an input port the most current data is used for the specific input port. :param state: the state of which the input data is determined :return: the input data of the target state """ result_dict = {} tmp_dict = self.get_default_input_values_for_state(state) result_dict.update(tmp_dict) for input_port_key, value in state.input_data_ports.items(): # for all input keys fetch the correct data_flow connection and read data into the result_dict actual_value = None actual_value_time = 0 for data_flow_key, data_flow in self.data_flows.items(): if data_flow.to_key == input_port_key: if data_flow.to_state == state.state_id: # fetch data from the scoped_data list: the key is the data_port_key + the state_id key = str(data_flow.from_key) + data_flow.from_state if key in self.scoped_data: if actual_value is None or actual_value_time < self.scoped_data[key].timestamp: actual_value = deepcopy(self.scoped_data[key].value) actual_value_time = self.scoped_data[key].timestamp if actual_value is not None: result_dict[value.name] = actual_value return result_dict
[ "def", "get_inputs_for_state", "(", "self", ",", "state", ")", ":", "result_dict", "=", "{", "}", "tmp_dict", "=", "self", ".", "get_default_input_values_for_state", "(", "state", ")", "result_dict", ".", "update", "(", "tmp_dict", ")", "for", "input_port_key", ...
Retrieves all input data of a state. If several data flows are connected to an input port the most current data is used for the specific input port. :param state: the state of which the input data is determined :return: the input data of the target state
[ "Retrieves", "all", "input", "data", "of", "a", "state", ".", "If", "several", "data", "flows", "are", "connected", "to", "an", "input", "port", "the", "most", "current", "data", "is", "used", "for", "the", "specific", "input", "port", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1503-L1533
train
40,626
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_input_data_to_scoped_data
def add_input_data_to_scoped_data(self, dictionary): """Add a dictionary to the scoped data As the input_data dictionary maps names to values, the functions looks for the proper data_ports keys in the input_data_ports dictionary :param dictionary: The dictionary that is added to the scoped data :param state: The state to which the input_data was passed (should be self in most cases) """ for dict_key, value in dictionary.items(): for input_data_port_key, data_port in list(self.input_data_ports.items()): if dict_key == data_port.name: self.scoped_data[str(input_data_port_key) + self.state_id] = \ ScopedData(data_port.name, value, type(value), self.state_id, ScopedVariable, parent=self) # forward the data to scoped variables for data_flow_key, data_flow in self.data_flows.items(): if data_flow.from_key == input_data_port_key and data_flow.from_state == self.state_id: if data_flow.to_state == self.state_id and data_flow.to_key in self.scoped_variables: current_scoped_variable = self.scoped_variables[data_flow.to_key] self.scoped_data[str(data_flow.to_key) + self.state_id] = \ ScopedData(current_scoped_variable.name, value, type(value), self.state_id, ScopedVariable, parent=self)
python
def add_input_data_to_scoped_data(self, dictionary): """Add a dictionary to the scoped data As the input_data dictionary maps names to values, the functions looks for the proper data_ports keys in the input_data_ports dictionary :param dictionary: The dictionary that is added to the scoped data :param state: The state to which the input_data was passed (should be self in most cases) """ for dict_key, value in dictionary.items(): for input_data_port_key, data_port in list(self.input_data_ports.items()): if dict_key == data_port.name: self.scoped_data[str(input_data_port_key) + self.state_id] = \ ScopedData(data_port.name, value, type(value), self.state_id, ScopedVariable, parent=self) # forward the data to scoped variables for data_flow_key, data_flow in self.data_flows.items(): if data_flow.from_key == input_data_port_key and data_flow.from_state == self.state_id: if data_flow.to_state == self.state_id and data_flow.to_key in self.scoped_variables: current_scoped_variable = self.scoped_variables[data_flow.to_key] self.scoped_data[str(data_flow.to_key) + self.state_id] = \ ScopedData(current_scoped_variable.name, value, type(value), self.state_id, ScopedVariable, parent=self)
[ "def", "add_input_data_to_scoped_data", "(", "self", ",", "dictionary", ")", ":", "for", "dict_key", ",", "value", "in", "dictionary", ".", "items", "(", ")", ":", "for", "input_data_port_key", ",", "data_port", "in", "list", "(", "self", ".", "input_data_port...
Add a dictionary to the scoped data As the input_data dictionary maps names to values, the functions looks for the proper data_ports keys in the input_data_ports dictionary :param dictionary: The dictionary that is added to the scoped data :param state: The state to which the input_data was passed (should be self in most cases)
[ "Add", "a", "dictionary", "to", "the", "scoped", "data" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1540-L1561
train
40,627
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_state_execution_output_to_scoped_data
def add_state_execution_output_to_scoped_data(self, dictionary, state): """Add a state execution output to the scoped data :param dictionary: The dictionary that is added to the scoped data :param state: The state that finished execution and provide the dictionary """ for output_name, value in dictionary.items(): for output_data_port_key, data_port in list(state.output_data_ports.items()): if output_name == data_port.name: if not isinstance(value, data_port.data_type): if (not ((type(value) is float or type(value) is int) and (data_port.data_type is float or data_port.data_type is int)) and not (isinstance(value, type(None)))): logger.error("The data type of output port {0} should be of type {1}, but is of type {2}". format(output_name, data_port.data_type, type(value))) self.scoped_data[str(output_data_port_key) + state.state_id] = \ ScopedData(data_port.name, value, type(value), state.state_id, OutputDataPort, parent=self)
python
def add_state_execution_output_to_scoped_data(self, dictionary, state): """Add a state execution output to the scoped data :param dictionary: The dictionary that is added to the scoped data :param state: The state that finished execution and provide the dictionary """ for output_name, value in dictionary.items(): for output_data_port_key, data_port in list(state.output_data_ports.items()): if output_name == data_port.name: if not isinstance(value, data_port.data_type): if (not ((type(value) is float or type(value) is int) and (data_port.data_type is float or data_port.data_type is int)) and not (isinstance(value, type(None)))): logger.error("The data type of output port {0} should be of type {1}, but is of type {2}". format(output_name, data_port.data_type, type(value))) self.scoped_data[str(output_data_port_key) + state.state_id] = \ ScopedData(data_port.name, value, type(value), state.state_id, OutputDataPort, parent=self)
[ "def", "add_state_execution_output_to_scoped_data", "(", "self", ",", "dictionary", ",", "state", ")", ":", "for", "output_name", ",", "value", "in", "dictionary", ".", "items", "(", ")", ":", "for", "output_data_port_key", ",", "data_port", "in", "list", "(", ...
Add a state execution output to the scoped data :param dictionary: The dictionary that is added to the scoped data :param state: The state that finished execution and provide the dictionary
[ "Add", "a", "state", "execution", "output", "to", "the", "scoped", "data" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1564-L1580
train
40,628
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.add_default_values_of_scoped_variables_to_scoped_data
def add_default_values_of_scoped_variables_to_scoped_data(self): """Add the scoped variables default values to the scoped_data dictionary """ for key, scoped_var in self.scoped_variables.items(): self.scoped_data[str(scoped_var.data_port_id) + self.state_id] = \ ScopedData(scoped_var.name, scoped_var.default_value, scoped_var.data_type, self.state_id, ScopedVariable, parent=self)
python
def add_default_values_of_scoped_variables_to_scoped_data(self): """Add the scoped variables default values to the scoped_data dictionary """ for key, scoped_var in self.scoped_variables.items(): self.scoped_data[str(scoped_var.data_port_id) + self.state_id] = \ ScopedData(scoped_var.name, scoped_var.default_value, scoped_var.data_type, self.state_id, ScopedVariable, parent=self)
[ "def", "add_default_values_of_scoped_variables_to_scoped_data", "(", "self", ")", ":", "for", "key", ",", "scoped_var", "in", "self", ".", "scoped_variables", ".", "items", "(", ")", ":", "self", ".", "scoped_data", "[", "str", "(", "scoped_var", ".", "data_port...
Add the scoped variables default values to the scoped_data dictionary
[ "Add", "the", "scoped", "variables", "default", "values", "to", "the", "scoped_data", "dictionary" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1583-L1590
train
40,629
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.update_scoped_variables_with_output_dictionary
def update_scoped_variables_with_output_dictionary(self, dictionary, state): """Update the values of the scoped variables with the output dictionary of a specific state. :param: the dictionary to update the scoped variables with :param: the state the output dictionary belongs to """ for key, value in dictionary.items(): output_data_port_key = None # search for the correct output data port key of the source state for o_key, o_port in state.output_data_ports.items(): if o_port.name == key: output_data_port_key = o_key break if output_data_port_key is None: if not key == "error": logger.warning("Output variable %s was written during state execution, " "that has no data port connected to it.", str(key)) for data_flow_key, data_flow in self.data_flows.items(): if data_flow.from_key == output_data_port_key and data_flow.from_state == state.state_id: if data_flow.to_state == self.state_id: # is target of data flow own state id? if data_flow.to_key in self.scoped_variables.keys(): # is target data port scoped? current_scoped_variable = self.scoped_variables[data_flow.to_key] self.scoped_data[str(data_flow.to_key) + self.state_id] = \ ScopedData(current_scoped_variable.name, value, type(value), state.state_id, ScopedVariable, parent=self)
python
def update_scoped_variables_with_output_dictionary(self, dictionary, state): """Update the values of the scoped variables with the output dictionary of a specific state. :param: the dictionary to update the scoped variables with :param: the state the output dictionary belongs to """ for key, value in dictionary.items(): output_data_port_key = None # search for the correct output data port key of the source state for o_key, o_port in state.output_data_ports.items(): if o_port.name == key: output_data_port_key = o_key break if output_data_port_key is None: if not key == "error": logger.warning("Output variable %s was written during state execution, " "that has no data port connected to it.", str(key)) for data_flow_key, data_flow in self.data_flows.items(): if data_flow.from_key == output_data_port_key and data_flow.from_state == state.state_id: if data_flow.to_state == self.state_id: # is target of data flow own state id? if data_flow.to_key in self.scoped_variables.keys(): # is target data port scoped? current_scoped_variable = self.scoped_variables[data_flow.to_key] self.scoped_data[str(data_flow.to_key) + self.state_id] = \ ScopedData(current_scoped_variable.name, value, type(value), state.state_id, ScopedVariable, parent=self)
[ "def", "update_scoped_variables_with_output_dictionary", "(", "self", ",", "dictionary", ",", "state", ")", ":", "for", "key", ",", "value", "in", "dictionary", ".", "items", "(", ")", ":", "output_data_port_key", "=", "None", "# search for the correct output data por...
Update the values of the scoped variables with the output dictionary of a specific state. :param: the dictionary to update the scoped variables with :param: the state the output dictionary belongs to
[ "Update", "the", "values", "of", "the", "scoped", "variables", "with", "the", "output", "dictionary", "of", "a", "specific", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1593-L1617
train
40,630
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.change_state_id
def change_state_id(self, state_id=None): """ Changes the id of the state to a new id. This functions replaces the old state_id with the new state_id in all data flows and transitions. :param state_id: The new state if of the state """ old_state_id = self.state_id super(ContainerState, self).change_state_id(state_id) # Use private variables to change ids to prevent validity checks # change id in all transitions for transition in self.transitions.values(): if transition.from_state == old_state_id: transition._from_state = self.state_id if transition.to_state == old_state_id: transition._to_state = self.state_id # change id in all data_flows for data_flow in self.data_flows.values(): if data_flow.from_state == old_state_id: data_flow._from_state = self.state_id if data_flow.to_state == old_state_id: data_flow._to_state = self.state_id
python
def change_state_id(self, state_id=None): """ Changes the id of the state to a new id. This functions replaces the old state_id with the new state_id in all data flows and transitions. :param state_id: The new state if of the state """ old_state_id = self.state_id super(ContainerState, self).change_state_id(state_id) # Use private variables to change ids to prevent validity checks # change id in all transitions for transition in self.transitions.values(): if transition.from_state == old_state_id: transition._from_state = self.state_id if transition.to_state == old_state_id: transition._to_state = self.state_id # change id in all data_flows for data_flow in self.data_flows.values(): if data_flow.from_state == old_state_id: data_flow._from_state = self.state_id if data_flow.to_state == old_state_id: data_flow._to_state = self.state_id
[ "def", "change_state_id", "(", "self", ",", "state_id", "=", "None", ")", ":", "old_state_id", "=", "self", ".", "state_id", "super", "(", "ContainerState", ",", "self", ")", ".", "change_state_id", "(", "state_id", ")", "# Use private variables to change ids to p...
Changes the id of the state to a new id. This functions replaces the old state_id with the new state_id in all data flows and transitions. :param state_id: The new state if of the state
[ "Changes", "the", "id", "of", "the", "state", "to", "a", "new", "id", ".", "This", "functions", "replaces", "the", "old", "state_id", "with", "the", "new", "state_id", "in", "all", "data", "flows", "and", "transitions", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1624-L1646
train
40,631
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.get_state_for_transition
def get_state_for_transition(self, transition): """Calculate the target state of a transition :param transition: The transition of which the target state is determined :return: the to-state of the transition :raises exceptions.TypeError: if the transition parameter is of wrong type """ if not isinstance(transition, Transition): raise TypeError("transition must be of type Transition") # the to_state is None when the transition connects an outcome of a child state to the outcome of a parent state if transition.to_state == self.state_id or transition.to_state is None: return self else: return self.states[transition.to_state]
python
def get_state_for_transition(self, transition): """Calculate the target state of a transition :param transition: The transition of which the target state is determined :return: the to-state of the transition :raises exceptions.TypeError: if the transition parameter is of wrong type """ if not isinstance(transition, Transition): raise TypeError("transition must be of type Transition") # the to_state is None when the transition connects an outcome of a child state to the outcome of a parent state if transition.to_state == self.state_id or transition.to_state is None: return self else: return self.states[transition.to_state]
[ "def", "get_state_for_transition", "(", "self", ",", "transition", ")", ":", "if", "not", "isinstance", "(", "transition", ",", "Transition", ")", ":", "raise", "TypeError", "(", "\"transition must be of type Transition\"", ")", "# the to_state is None when the transition...
Calculate the target state of a transition :param transition: The transition of which the target state is determined :return: the to-state of the transition :raises exceptions.TypeError: if the transition parameter is of wrong type
[ "Calculate", "the", "target", "state", "of", "a", "transition" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1648-L1661
train
40,632
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.write_output_data
def write_output_data(self, specific_output_dictionary=None): """ Write the scoped data to output of the state. Called before exiting the container state. :param specific_output_dictionary: an optional dictionary to write the output data in :return: """ if isinstance(specific_output_dictionary, dict): output_dict = specific_output_dictionary else: output_dict = self.output_data for output_name, value in self.output_data.items(): output_port_id = self.get_io_data_port_id_from_name_and_type(output_name, OutputDataPort) actual_value = None actual_value_was_written = False actual_value_time = 0 for data_flow_id, data_flow in self.data_flows.items(): if data_flow.to_state == self.state_id: if data_flow.to_key == output_port_id: scoped_data_key = str(data_flow.from_key) + data_flow.from_state if scoped_data_key in self.scoped_data: # if self.scoped_data[scoped_data_key].timestamp > actual_value_time is True # the data of a previous execution of the same state is overwritten if actual_value is None or self.scoped_data[scoped_data_key].timestamp > actual_value_time: actual_value = deepcopy(self.scoped_data[scoped_data_key].value) actual_value_time = self.scoped_data[scoped_data_key].timestamp actual_value_was_written = True else: if not self.backward_execution: logger.debug( "Output data with name {0} of state {1} was not found in the scoped data " "of state {2}. Thus the state did not write onto this output. " "This can mean a state machine design error.".format( str(output_name), str(self.states[data_flow.from_state].get_path()), self.get_path())) if actual_value_was_written: output_dict[output_name] = actual_value
python
def write_output_data(self, specific_output_dictionary=None): """ Write the scoped data to output of the state. Called before exiting the container state. :param specific_output_dictionary: an optional dictionary to write the output data in :return: """ if isinstance(specific_output_dictionary, dict): output_dict = specific_output_dictionary else: output_dict = self.output_data for output_name, value in self.output_data.items(): output_port_id = self.get_io_data_port_id_from_name_and_type(output_name, OutputDataPort) actual_value = None actual_value_was_written = False actual_value_time = 0 for data_flow_id, data_flow in self.data_flows.items(): if data_flow.to_state == self.state_id: if data_flow.to_key == output_port_id: scoped_data_key = str(data_flow.from_key) + data_flow.from_state if scoped_data_key in self.scoped_data: # if self.scoped_data[scoped_data_key].timestamp > actual_value_time is True # the data of a previous execution of the same state is overwritten if actual_value is None or self.scoped_data[scoped_data_key].timestamp > actual_value_time: actual_value = deepcopy(self.scoped_data[scoped_data_key].value) actual_value_time = self.scoped_data[scoped_data_key].timestamp actual_value_was_written = True else: if not self.backward_execution: logger.debug( "Output data with name {0} of state {1} was not found in the scoped data " "of state {2}. Thus the state did not write onto this output. " "This can mean a state machine design error.".format( str(output_name), str(self.states[data_flow.from_state].get_path()), self.get_path())) if actual_value_was_written: output_dict[output_name] = actual_value
[ "def", "write_output_data", "(", "self", ",", "specific_output_dictionary", "=", "None", ")", ":", "if", "isinstance", "(", "specific_output_dictionary", ",", "dict", ")", ":", "output_dict", "=", "specific_output_dictionary", "else", ":", "output_dict", "=", "self"...
Write the scoped data to output of the state. Called before exiting the container state. :param specific_output_dictionary: an optional dictionary to write the output data in :return:
[ "Write", "the", "scoped", "data", "to", "output", "of", "the", "state", ".", "Called", "before", "exiting", "the", "container", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1663-L1699
train
40,633
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.check_data_port_connection
def check_data_port_connection(self, check_data_port): """Checks the connection validity of a data port The method is called by a child state to check the validity of a data port in case it is connected with data flows. The data port does not belong to 'self', but to one of self.states. If the data port is connected to a data flow, the method checks, whether these connect consistent data types of ports. :param rafcon.core.data_port.DataPort check_data_port: The port to check :return: valid, message """ for data_flow in self.data_flows.values(): # Check whether the data flow connects the given port from_port = self.get_data_port(data_flow.from_state, data_flow.from_key) to_port = self.get_data_port(data_flow.to_state, data_flow.to_key) if check_data_port is from_port or check_data_port is to_port: # check if one of the data_types if type 'object'; in this case the data flow is always valid if not (from_port.data_type is object or to_port.data_type is object): if not type_inherits_of_type(from_port.data_type, to_port.data_type): return False, "Connection of two non-compatible data types" return True, "valid"
python
def check_data_port_connection(self, check_data_port): """Checks the connection validity of a data port The method is called by a child state to check the validity of a data port in case it is connected with data flows. The data port does not belong to 'self', but to one of self.states. If the data port is connected to a data flow, the method checks, whether these connect consistent data types of ports. :param rafcon.core.data_port.DataPort check_data_port: The port to check :return: valid, message """ for data_flow in self.data_flows.values(): # Check whether the data flow connects the given port from_port = self.get_data_port(data_flow.from_state, data_flow.from_key) to_port = self.get_data_port(data_flow.to_state, data_flow.to_key) if check_data_port is from_port or check_data_port is to_port: # check if one of the data_types if type 'object'; in this case the data flow is always valid if not (from_port.data_type is object or to_port.data_type is object): if not type_inherits_of_type(from_port.data_type, to_port.data_type): return False, "Connection of two non-compatible data types" return True, "valid"
[ "def", "check_data_port_connection", "(", "self", ",", "check_data_port", ")", ":", "for", "data_flow", "in", "self", ".", "data_flows", ".", "values", "(", ")", ":", "# Check whether the data flow connects the given port", "from_port", "=", "self", ".", "get_data_por...
Checks the connection validity of a data port The method is called by a child state to check the validity of a data port in case it is connected with data flows. The data port does not belong to 'self', but to one of self.states. If the data port is connected to a data flow, the method checks, whether these connect consistent data types of ports. :param rafcon.core.data_port.DataPort check_data_port: The port to check :return: valid, message
[ "Checks", "the", "connection", "validity", "of", "a", "data", "port" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1727-L1747
train
40,634
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_data_flow_validity
def _check_data_flow_validity(self, check_data_flow): """Checks the validity of a data flow Calls further checks to inspect the id, ports and data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ valid, message = self._check_data_flow_id(check_data_flow) if not valid: return False, message valid, message = self._check_data_flow_ports(check_data_flow) if not valid: return False, message return self._check_data_flow_types(check_data_flow)
python
def _check_data_flow_validity(self, check_data_flow): """Checks the validity of a data flow Calls further checks to inspect the id, ports and data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ valid, message = self._check_data_flow_id(check_data_flow) if not valid: return False, message valid, message = self._check_data_flow_ports(check_data_flow) if not valid: return False, message return self._check_data_flow_types(check_data_flow)
[ "def", "_check_data_flow_validity", "(", "self", ",", "check_data_flow", ")", ":", "valid", ",", "message", "=", "self", ".", "_check_data_flow_id", "(", "check_data_flow", ")", "if", "not", "valid", ":", "return", "False", ",", "message", "valid", ",", "messa...
Checks the validity of a data flow Calls further checks to inspect the id, ports and data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid
[ "Checks", "the", "validity", "of", "a", "data", "flow" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1791-L1808
train
40,635
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_data_flow_id
def _check_data_flow_id(self, data_flow): """Checks the validity of a data flow id Checks whether the id of the given data flow is already by anther data flow used within the state. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ data_flow_id = data_flow.data_flow_id if data_flow_id in self.data_flows and data_flow is not self.data_flows[data_flow_id]: return False, "data_flow_id already existing" return True, "valid"
python
def _check_data_flow_id(self, data_flow): """Checks the validity of a data flow id Checks whether the id of the given data flow is already by anther data flow used within the state. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ data_flow_id = data_flow.data_flow_id if data_flow_id in self.data_flows and data_flow is not self.data_flows[data_flow_id]: return False, "data_flow_id already existing" return True, "valid"
[ "def", "_check_data_flow_id", "(", "self", ",", "data_flow", ")", ":", "data_flow_id", "=", "data_flow", ".", "data_flow_id", "if", "data_flow_id", "in", "self", ".", "data_flows", "and", "data_flow", "is", "not", "self", ".", "data_flows", "[", "data_flow_id", ...
Checks the validity of a data flow id Checks whether the id of the given data flow is already by anther data flow used within the state. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid
[ "Checks", "the", "validity", "of", "a", "data", "flow", "id" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1810-L1822
train
40,636
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_data_flow_ports
def _check_data_flow_ports(self, data_flow): """Checks the validity of the ports of a data flow Checks whether the ports of a data flow are existing and whether it is allowed to connect these ports. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ from_state_id = data_flow.from_state to_state_id = data_flow.to_state from_data_port_id = data_flow.from_key to_data_port_id = data_flow.to_key # Check whether to and from port are existing from_data_port = self.get_data_port(from_state_id, from_data_port_id) if not from_data_port: return False, "Data flow origin not existing -> {0}".format(data_flow) to_data_port = self.get_data_port(to_state_id, to_data_port_id) if not to_data_port: return False, "Data flow target not existing -> {0}".format(data_flow) # Data_ports without parents are not allowed to be connected twice if not from_data_port.parent: return False, "Source data port does not have a parent -> {0}".format(data_flow) if not to_data_port.parent: return False, "Target data port does not have a parent -> {0}".format(data_flow) # Check if data ports are identical if from_data_port is to_data_port: return False, "Source and target data ports of data flow must not be identical -> {}".format(data_flow) # Check, whether the origin of the data flow is valid if from_state_id == self.state_id: # data_flow originates in container state if from_data_port_id not in self.input_data_ports and from_data_port_id not in self.scoped_variables: return False, "Data flow origin port must be an input port or scoped variable, when the data flow " \ "starts in the parent state -> {0}".format(data_flow) else: # data flow originates in child state if from_data_port_id not in from_data_port.parent.output_data_ports: return False, "Data flow origin port must be an output port, when the data flow " \ "starts in the child state -> {0}".format(data_flow) # Check, whether the target of a data flow is valid if to_state_id == self.state_id: # data_flow ends in container state if to_data_port_id not in self.output_data_ports and to_data_port_id not in self.scoped_variables: return False, "Data flow target port must be an output port or scoped variable, when the data flow " \ "goes to the parent state -> {0}".format(data_flow) else: # data_flow ends in child state if to_data_port_id not in to_data_port.parent.input_data_ports: return False, "Data flow target port must be an input port, when the data flow goes to a child state" \ " -> {0}".format(data_flow) # Check if data flow connects two scoped variables if isinstance(from_data_port, ScopedVariable) and isinstance(to_data_port, ScopedVariable): return False, "Data flows must not connect two scoped variables -> {}".format(data_flow) # Check, whether the target port is already connected for existing_data_flow in self.data_flows.values(): to_data_port_existing = self.get_data_port(existing_data_flow.to_state, existing_data_flow.to_key) from_data_port_existing = self.get_data_port(existing_data_flow.from_state, existing_data_flow.from_key) if to_data_port is to_data_port_existing and data_flow is not existing_data_flow: if from_data_port is from_data_port_existing: return False, "Exactly the same data flow is already existing -> {0}".format(data_flow) return True, "valid"
python
def _check_data_flow_ports(self, data_flow): """Checks the validity of the ports of a data flow Checks whether the ports of a data flow are existing and whether it is allowed to connect these ports. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ from_state_id = data_flow.from_state to_state_id = data_flow.to_state from_data_port_id = data_flow.from_key to_data_port_id = data_flow.to_key # Check whether to and from port are existing from_data_port = self.get_data_port(from_state_id, from_data_port_id) if not from_data_port: return False, "Data flow origin not existing -> {0}".format(data_flow) to_data_port = self.get_data_port(to_state_id, to_data_port_id) if not to_data_port: return False, "Data flow target not existing -> {0}".format(data_flow) # Data_ports without parents are not allowed to be connected twice if not from_data_port.parent: return False, "Source data port does not have a parent -> {0}".format(data_flow) if not to_data_port.parent: return False, "Target data port does not have a parent -> {0}".format(data_flow) # Check if data ports are identical if from_data_port is to_data_port: return False, "Source and target data ports of data flow must not be identical -> {}".format(data_flow) # Check, whether the origin of the data flow is valid if from_state_id == self.state_id: # data_flow originates in container state if from_data_port_id not in self.input_data_ports and from_data_port_id not in self.scoped_variables: return False, "Data flow origin port must be an input port or scoped variable, when the data flow " \ "starts in the parent state -> {0}".format(data_flow) else: # data flow originates in child state if from_data_port_id not in from_data_port.parent.output_data_ports: return False, "Data flow origin port must be an output port, when the data flow " \ "starts in the child state -> {0}".format(data_flow) # Check, whether the target of a data flow is valid if to_state_id == self.state_id: # data_flow ends in container state if to_data_port_id not in self.output_data_ports and to_data_port_id not in self.scoped_variables: return False, "Data flow target port must be an output port or scoped variable, when the data flow " \ "goes to the parent state -> {0}".format(data_flow) else: # data_flow ends in child state if to_data_port_id not in to_data_port.parent.input_data_ports: return False, "Data flow target port must be an input port, when the data flow goes to a child state" \ " -> {0}".format(data_flow) # Check if data flow connects two scoped variables if isinstance(from_data_port, ScopedVariable) and isinstance(to_data_port, ScopedVariable): return False, "Data flows must not connect two scoped variables -> {}".format(data_flow) # Check, whether the target port is already connected for existing_data_flow in self.data_flows.values(): to_data_port_existing = self.get_data_port(existing_data_flow.to_state, existing_data_flow.to_key) from_data_port_existing = self.get_data_port(existing_data_flow.from_state, existing_data_flow.from_key) if to_data_port is to_data_port_existing and data_flow is not existing_data_flow: if from_data_port is from_data_port_existing: return False, "Exactly the same data flow is already existing -> {0}".format(data_flow) return True, "valid"
[ "def", "_check_data_flow_ports", "(", "self", ",", "data_flow", ")", ":", "from_state_id", "=", "data_flow", ".", "from_state", "to_state_id", "=", "data_flow", ".", "to_state", "from_data_port_id", "=", "data_flow", ".", "from_key", "to_data_port_id", "=", "data_fl...
Checks the validity of the ports of a data flow Checks whether the ports of a data flow are existing and whether it is allowed to connect these ports. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid
[ "Checks", "the", "validity", "of", "the", "ports", "of", "a", "data", "flow" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1824-L1888
train
40,637
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_data_flow_types
def _check_data_flow_types(self, check_data_flow): """Checks the validity of the data flow connection Checks whether the ports of a data flow have matching data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ # Check whether the data types or origin and target fit from_data_port = self.get_data_port(check_data_flow.from_state, check_data_flow.from_key) to_data_port = self.get_data_port(check_data_flow.to_state, check_data_flow.to_key) # Connections from the data port type "object" are always allowed if from_data_port.data_type is object: return True, "valid" if not type_inherits_of_type(from_data_port.data_type, to_data_port.data_type): return False, "Data flow (id: {0}) with origin state \"{1}\" (from data port name: {2}) " \ "and target state \"{3}\" (to data port name: {4}) " \ "do not have matching data types (from '{5}' to '{6}')".format( check_data_flow.data_flow_id, from_data_port.parent.name, from_data_port.name, to_data_port.parent.name, to_data_port.name, from_data_port.data_type, to_data_port.data_type) return True, "valid"
python
def _check_data_flow_types(self, check_data_flow): """Checks the validity of the data flow connection Checks whether the ports of a data flow have matching data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid """ # Check whether the data types or origin and target fit from_data_port = self.get_data_port(check_data_flow.from_state, check_data_flow.from_key) to_data_port = self.get_data_port(check_data_flow.to_state, check_data_flow.to_key) # Connections from the data port type "object" are always allowed if from_data_port.data_type is object: return True, "valid" if not type_inherits_of_type(from_data_port.data_type, to_data_port.data_type): return False, "Data flow (id: {0}) with origin state \"{1}\" (from data port name: {2}) " \ "and target state \"{3}\" (to data port name: {4}) " \ "do not have matching data types (from '{5}' to '{6}')".format( check_data_flow.data_flow_id, from_data_port.parent.name, from_data_port.name, to_data_port.parent.name, to_data_port.name, from_data_port.data_type, to_data_port.data_type) return True, "valid"
[ "def", "_check_data_flow_types", "(", "self", ",", "check_data_flow", ")", ":", "# Check whether the data types or origin and target fit", "from_data_port", "=", "self", ".", "get_data_port", "(", "check_data_flow", ".", "from_state", ",", "check_data_flow", ".", "from_key"...
Checks the validity of the data flow connection Checks whether the ports of a data flow have matching data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives more information especially if the data flow is not valid
[ "Checks", "the", "validity", "of", "the", "data", "flow", "connection" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1890-L1916
train
40,638
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_transition_validity
def _check_transition_validity(self, check_transition): """Checks the validity of a transition Calls further checks to inspect the id, origin, target and connection of the transition. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ valid, message = self._check_transition_id(check_transition) if not valid: return False, message # Separate check for start transitions if check_transition.from_state is None: return self._check_start_transition(check_transition) valid, message = self._check_transition_origin(check_transition) if not valid: return False, message valid, message = self._check_transition_target(check_transition) if not valid: return False, message return self._check_transition_connection(check_transition)
python
def _check_transition_validity(self, check_transition): """Checks the validity of a transition Calls further checks to inspect the id, origin, target and connection of the transition. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ valid, message = self._check_transition_id(check_transition) if not valid: return False, message # Separate check for start transitions if check_transition.from_state is None: return self._check_start_transition(check_transition) valid, message = self._check_transition_origin(check_transition) if not valid: return False, message valid, message = self._check_transition_target(check_transition) if not valid: return False, message return self._check_transition_connection(check_transition)
[ "def", "_check_transition_validity", "(", "self", ",", "check_transition", ")", ":", "valid", ",", "message", "=", "self", ".", "_check_transition_id", "(", "check_transition", ")", "if", "not", "valid", ":", "return", "False", ",", "message", "# Separate check fo...
Checks the validity of a transition Calls further checks to inspect the id, origin, target and connection of the transition. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid
[ "Checks", "the", "validity", "of", "a", "transition" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1918-L1943
train
40,639
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_transition_id
def _check_transition_id(self, transition): """Checks the validity of a transition id Checks whether the transition id is already used by another transition within the state :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ transition_id = transition.transition_id if transition_id in self.transitions and transition is not self.transitions[transition_id]: return False, "transition_id already existing" return True, "valid"
python
def _check_transition_id(self, transition): """Checks the validity of a transition id Checks whether the transition id is already used by another transition within the state :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ transition_id = transition.transition_id if transition_id in self.transitions and transition is not self.transitions[transition_id]: return False, "transition_id already existing" return True, "valid"
[ "def", "_check_transition_id", "(", "self", ",", "transition", ")", ":", "transition_id", "=", "transition", ".", "transition_id", "if", "transition_id", "in", "self", ".", "transitions", "and", "transition", "is", "not", "self", ".", "transitions", "[", "transi...
Checks the validity of a transition id Checks whether the transition id is already used by another transition within the state :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid
[ "Checks", "the", "validity", "of", "a", "transition", "id" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1945-L1957
train
40,640
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_start_transition
def _check_start_transition(self, start_transition): """Checks the validity of a start transition Checks whether the given transition is a start transition a whether it is the only one within the state. :param rafcon.core.transition.Transition start_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ for transition in self.transitions.values(): if transition.from_state is None: if start_transition is not transition: return False, "Only one start transition is allowed" if start_transition.from_outcome is not None: return False, "from_outcome must not be set in start transition" return self._check_transition_target(start_transition)
python
def _check_start_transition(self, start_transition): """Checks the validity of a start transition Checks whether the given transition is a start transition a whether it is the only one within the state. :param rafcon.core.transition.Transition start_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ for transition in self.transitions.values(): if transition.from_state is None: if start_transition is not transition: return False, "Only one start transition is allowed" if start_transition.from_outcome is not None: return False, "from_outcome must not be set in start transition" return self._check_transition_target(start_transition)
[ "def", "_check_start_transition", "(", "self", ",", "start_transition", ")", ":", "for", "transition", "in", "self", ".", "transitions", ".", "values", "(", ")", ":", "if", "transition", ".", "from_state", "is", "None", ":", "if", "start_transition", "is", "...
Checks the validity of a start transition Checks whether the given transition is a start transition a whether it is the only one within the state. :param rafcon.core.transition.Transition start_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid
[ "Checks", "the", "validity", "of", "a", "start", "transition" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1959-L1976
train
40,641
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_transition_target
def _check_transition_target(self, transition): """Checks the validity of a transition target Checks whether the transition target is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ to_state_id = transition.to_state to_outcome_id = transition.to_outcome if to_state_id == self.state_id: if to_outcome_id not in self.outcomes: return False, "to_outcome is not existing" else: if to_state_id not in self.states: return False, "to_state is not existing" if to_outcome_id is not None: return False, "to_outcome must be None as transition goes to child state" return True, "valid"
python
def _check_transition_target(self, transition): """Checks the validity of a transition target Checks whether the transition target is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ to_state_id = transition.to_state to_outcome_id = transition.to_outcome if to_state_id == self.state_id: if to_outcome_id not in self.outcomes: return False, "to_outcome is not existing" else: if to_state_id not in self.states: return False, "to_state is not existing" if to_outcome_id is not None: return False, "to_outcome must be None as transition goes to child state" return True, "valid"
[ "def", "_check_transition_target", "(", "self", ",", "transition", ")", ":", "to_state_id", "=", "transition", ".", "to_state", "to_outcome_id", "=", "transition", ".", "to_outcome", "if", "to_state_id", "==", "self", ".", "state_id", ":", "if", "to_outcome_id", ...
Checks the validity of a transition target Checks whether the transition target is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid
[ "Checks", "the", "validity", "of", "a", "transition", "target" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L1978-L2000
train
40,642
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_transition_origin
def _check_transition_origin(self, transition): """Checks the validity of a transition origin Checks whether the transition origin is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ from_state_id = transition.from_state from_outcome_id = transition.from_outcome if from_state_id == self.state_id: return False, "from_state_id of transition must not be the container state itself." \ " In the case of a start transition both the from state and the from_outcome are None." if from_state_id != self.state_id and from_state_id not in self.states: return False, "from_state not existing" from_outcome = self.get_outcome(from_state_id, from_outcome_id) if from_outcome is None: return False, "from_outcome not existing in from_state" return True, "valid"
python
def _check_transition_origin(self, transition): """Checks the validity of a transition origin Checks whether the transition origin is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ from_state_id = transition.from_state from_outcome_id = transition.from_outcome if from_state_id == self.state_id: return False, "from_state_id of transition must not be the container state itself." \ " In the case of a start transition both the from state and the from_outcome are None." if from_state_id != self.state_id and from_state_id not in self.states: return False, "from_state not existing" from_outcome = self.get_outcome(from_state_id, from_outcome_id) if from_outcome is None: return False, "from_outcome not existing in from_state" return True, "valid"
[ "def", "_check_transition_origin", "(", "self", ",", "transition", ")", ":", "from_state_id", "=", "transition", ".", "from_state", "from_outcome_id", "=", "transition", ".", "from_outcome", "if", "from_state_id", "==", "self", ".", "state_id", ":", "return", "Fal...
Checks the validity of a transition origin Checks whether the transition origin is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid
[ "Checks", "the", "validity", "of", "a", "transition", "origin" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2002-L2025
train
40,643
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState._check_transition_connection
def _check_transition_connection(self, check_transition): """Checks the validity of a transition connection Checks whether the transition is allowed to connect the origin with the target. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ from_state_id = check_transition.from_state from_outcome_id = check_transition.from_outcome to_state_id = check_transition.to_state to_outcome_id = check_transition.to_outcome # check for connected origin for transition in self.transitions.values(): if transition.from_state == from_state_id: if transition.from_outcome == from_outcome_id: if check_transition is not transition: return False, "transition origin already connected to another transition" if from_state_id in self.states and to_state_id in self.states and to_outcome_id is not None: return False, "no transition from one outcome to another one on the same hierarchy allowed" return True, "valid"
python
def _check_transition_connection(self, check_transition): """Checks the validity of a transition connection Checks whether the transition is allowed to connect the origin with the target. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid """ from_state_id = check_transition.from_state from_outcome_id = check_transition.from_outcome to_state_id = check_transition.to_state to_outcome_id = check_transition.to_outcome # check for connected origin for transition in self.transitions.values(): if transition.from_state == from_state_id: if transition.from_outcome == from_outcome_id: if check_transition is not transition: return False, "transition origin already connected to another transition" if from_state_id in self.states and to_state_id in self.states and to_outcome_id is not None: return False, "no transition from one outcome to another one on the same hierarchy allowed" return True, "valid"
[ "def", "_check_transition_connection", "(", "self", ",", "check_transition", ")", ":", "from_state_id", "=", "check_transition", ".", "from_state", "from_outcome_id", "=", "check_transition", ".", "from_outcome", "to_state_id", "=", "check_transition", ".", "to_state", ...
Checks the validity of a transition connection Checks whether the transition is allowed to connect the origin with the target. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives more information especially if the transition is not valid
[ "Checks", "the", "validity", "of", "a", "transition", "connection" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2027-L2051
train
40,644
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.states
def states(self, states): """ Setter for _states field See property :param states: Dictionary of States :raises exceptions.TypeError: if the states parameter is of wrong type :raises exceptions.AttributeError: if the keys of the dictionary and the state_ids in the dictionary do not match """ if not isinstance(states, dict): raise TypeError("states must be of type dict") if [state_id for state_id, state in states.items() if not isinstance(state, State)]: raise TypeError("element of container_state.states must be of type State") if [state_id for state_id, state in states.items() if not state_id == state.state_id]: raise AttributeError("The key of the state dictionary and the id of the state do not match") old_states = self._states self._states = states for state_id, state in states.items(): try: state.parent = self except ValueError: self._states = old_states raise # check that all old_states are no more referencing self as there parent for old_state in old_states.values(): if old_state not in self._states.values() and old_state.parent is self: old_state.parent = None
python
def states(self, states): """ Setter for _states field See property :param states: Dictionary of States :raises exceptions.TypeError: if the states parameter is of wrong type :raises exceptions.AttributeError: if the keys of the dictionary and the state_ids in the dictionary do not match """ if not isinstance(states, dict): raise TypeError("states must be of type dict") if [state_id for state_id, state in states.items() if not isinstance(state, State)]: raise TypeError("element of container_state.states must be of type State") if [state_id for state_id, state in states.items() if not state_id == state.state_id]: raise AttributeError("The key of the state dictionary and the id of the state do not match") old_states = self._states self._states = states for state_id, state in states.items(): try: state.parent = self except ValueError: self._states = old_states raise # check that all old_states are no more referencing self as there parent for old_state in old_states.values(): if old_state not in self._states.values() and old_state.parent is self: old_state.parent = None
[ "def", "states", "(", "self", ",", "states", ")", ":", "if", "not", "isinstance", "(", "states", ",", "dict", ")", ":", "raise", "TypeError", "(", "\"states must be of type dict\"", ")", "if", "[", "state_id", "for", "state_id", ",", "state", "in", "states...
Setter for _states field See property :param states: Dictionary of States :raises exceptions.TypeError: if the states parameter is of wrong type :raises exceptions.AttributeError: if the keys of the dictionary and the state_ids in the dictionary do not match
[ "Setter", "for", "_states", "field" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2101-L2129
train
40,645
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.transitions
def transitions(self, transitions): """ Setter for _transitions field See property :param: transitions: Dictionary transitions[transition_id] of :class:`rafcon.core.transition.Transition` :raises exceptions.TypeError: if the transitions parameter has the wrong type :raises exceptions.AttributeError: if the keys of the transitions dictionary and the transition_ids of the transitions in the dictionary do not match """ if not isinstance(transitions, dict): raise TypeError("transitions must be of type dict") if [t_id for t_id, transition in transitions.items() if not isinstance(transition, Transition)]: raise TypeError("element of transitions must be of type Transition") if [t_id for t_id, transition in transitions.items() if not t_id == transition.transition_id]: raise AttributeError("The key of the transition dictionary and the id of the transition do not match") old_transitions = self._transitions self._transitions = transitions transition_ids_to_delete = [] for transition_id, transition in transitions.items(): try: transition.parent = self except (ValueError, RecoveryModeException) as e: if type(e) is RecoveryModeException: logger.error("Recovery error: {0}\n{1}".format(str(e), str(traceback.format_exc()))) if e.do_delete_item: transition_ids_to_delete.append(transition.transition_id) else: self._transitions = old_transitions raise self._transitions = dict((transition_id, t) for (transition_id, t) in self._transitions.items() if transition_id not in transition_ids_to_delete) # check that all old_transitions are no more referencing self as there parent for old_transition in old_transitions.values(): if old_transition not in self._transitions.values() and old_transition.parent is self: old_transition.parent = None
python
def transitions(self, transitions): """ Setter for _transitions field See property :param: transitions: Dictionary transitions[transition_id] of :class:`rafcon.core.transition.Transition` :raises exceptions.TypeError: if the transitions parameter has the wrong type :raises exceptions.AttributeError: if the keys of the transitions dictionary and the transition_ids of the transitions in the dictionary do not match """ if not isinstance(transitions, dict): raise TypeError("transitions must be of type dict") if [t_id for t_id, transition in transitions.items() if not isinstance(transition, Transition)]: raise TypeError("element of transitions must be of type Transition") if [t_id for t_id, transition in transitions.items() if not t_id == transition.transition_id]: raise AttributeError("The key of the transition dictionary and the id of the transition do not match") old_transitions = self._transitions self._transitions = transitions transition_ids_to_delete = [] for transition_id, transition in transitions.items(): try: transition.parent = self except (ValueError, RecoveryModeException) as e: if type(e) is RecoveryModeException: logger.error("Recovery error: {0}\n{1}".format(str(e), str(traceback.format_exc()))) if e.do_delete_item: transition_ids_to_delete.append(transition.transition_id) else: self._transitions = old_transitions raise self._transitions = dict((transition_id, t) for (transition_id, t) in self._transitions.items() if transition_id not in transition_ids_to_delete) # check that all old_transitions are no more referencing self as there parent for old_transition in old_transitions.values(): if old_transition not in self._transitions.values() and old_transition.parent is self: old_transition.parent = None
[ "def", "transitions", "(", "self", ",", "transitions", ")", ":", "if", "not", "isinstance", "(", "transitions", ",", "dict", ")", ":", "raise", "TypeError", "(", "\"transitions must be of type dict\"", ")", "if", "[", "t_id", "for", "t_id", ",", "transition", ...
Setter for _transitions field See property :param: transitions: Dictionary transitions[transition_id] of :class:`rafcon.core.transition.Transition` :raises exceptions.TypeError: if the transitions parameter has the wrong type :raises exceptions.AttributeError: if the keys of the transitions dictionary and the transition_ids of the transitions in the dictionary do not match
[ "Setter", "for", "_transitions", "field" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2148-L2186
train
40,646
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.data_flows
def data_flows(self, data_flows): """ Setter for _data_flows field See property :param dict data_flows: Dictionary data_flows[data_flow_id] of :class:`rafcon.core.data_flow.DataFlow` :raises exceptions.TypeError: if the data_flows parameter has the wrong type :raises exceptions.AttributeError: if the keys of the data_flows dictionary and the data_flow_ids of the data flows in the dictionary do not match """ if not isinstance(data_flows, dict): raise TypeError("data_flows must be of type dict") if [df_id for df_id, data_flow in data_flows.items() if not isinstance(data_flow, DataFlow)]: raise TypeError("element of data_flows must be of type DataFlow") if [df_id for df_id, data_flow in data_flows.items() if not df_id == data_flow.data_flow_id]: raise AttributeError("The key of the data flow dictionary and the id of the data flow do not match") old_data_flows = self._data_flows self._data_flows = data_flows data_flow_ids_to_delete = [] for data_flow_id, data_flow in data_flows.items(): try: data_flow.parent = self except (ValueError, RecoveryModeException) as e: if type(e) is RecoveryModeException: logger.error("Recovery error: {0}\n{1}".format(str(e), str(traceback.format_exc()))) if e.do_delete_item: data_flow_ids_to_delete.append(data_flow.data_flow_id) else: self._data_flows = old_data_flows raise self._data_flows = dict((data_flow_id, d) for (data_flow_id, d) in self._data_flows.items() if data_flow_id not in data_flow_ids_to_delete) # check that all old_data_flows are no more referencing self as there parent for old_data_flow in old_data_flows.values(): if old_data_flow not in self._data_flows.values() and old_data_flow.parent is self: old_data_flow.parent = None
python
def data_flows(self, data_flows): """ Setter for _data_flows field See property :param dict data_flows: Dictionary data_flows[data_flow_id] of :class:`rafcon.core.data_flow.DataFlow` :raises exceptions.TypeError: if the data_flows parameter has the wrong type :raises exceptions.AttributeError: if the keys of the data_flows dictionary and the data_flow_ids of the data flows in the dictionary do not match """ if not isinstance(data_flows, dict): raise TypeError("data_flows must be of type dict") if [df_id for df_id, data_flow in data_flows.items() if not isinstance(data_flow, DataFlow)]: raise TypeError("element of data_flows must be of type DataFlow") if [df_id for df_id, data_flow in data_flows.items() if not df_id == data_flow.data_flow_id]: raise AttributeError("The key of the data flow dictionary and the id of the data flow do not match") old_data_flows = self._data_flows self._data_flows = data_flows data_flow_ids_to_delete = [] for data_flow_id, data_flow in data_flows.items(): try: data_flow.parent = self except (ValueError, RecoveryModeException) as e: if type(e) is RecoveryModeException: logger.error("Recovery error: {0}\n{1}".format(str(e), str(traceback.format_exc()))) if e.do_delete_item: data_flow_ids_to_delete.append(data_flow.data_flow_id) else: self._data_flows = old_data_flows raise self._data_flows = dict((data_flow_id, d) for (data_flow_id, d) in self._data_flows.items() if data_flow_id not in data_flow_ids_to_delete) # check that all old_data_flows are no more referencing self as there parent for old_data_flow in old_data_flows.values(): if old_data_flow not in self._data_flows.values() and old_data_flow.parent is self: old_data_flow.parent = None
[ "def", "data_flows", "(", "self", ",", "data_flows", ")", ":", "if", "not", "isinstance", "(", "data_flows", ",", "dict", ")", ":", "raise", "TypeError", "(", "\"data_flows must be of type dict\"", ")", "if", "[", "df_id", "for", "df_id", ",", "data_flow", "...
Setter for _data_flows field See property :param dict data_flows: Dictionary data_flows[data_flow_id] of :class:`rafcon.core.data_flow.DataFlow` :raises exceptions.TypeError: if the data_flows parameter has the wrong type :raises exceptions.AttributeError: if the keys of the data_flows dictionary and the data_flow_ids of the data flows in the dictionary do not match
[ "Setter", "for", "_data_flows", "field" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2205-L2243
train
40,647
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.start_state_id
def start_state_id(self): """ The start state is the state to which the first transition goes to. The setter-method creates a unique first transition to the state with the given id. Existing first transitions are removed. If the given state id is None, the first transition is removed. :return: The id of the start state """ for transition_id in self.transitions: if self.transitions[transition_id].from_state is None: to_state = self.transitions[transition_id].to_state if to_state is not None: return to_state else: return self.state_id return None
python
def start_state_id(self): """ The start state is the state to which the first transition goes to. The setter-method creates a unique first transition to the state with the given id. Existing first transitions are removed. If the given state id is None, the first transition is removed. :return: The id of the start state """ for transition_id in self.transitions: if self.transitions[transition_id].from_state is None: to_state = self.transitions[transition_id].to_state if to_state is not None: return to_state else: return self.state_id return None
[ "def", "start_state_id", "(", "self", ")", ":", "for", "transition_id", "in", "self", ".", "transitions", ":", "if", "self", ".", "transitions", "[", "transition_id", "]", ".", "from_state", "is", "None", ":", "to_state", "=", "self", ".", "transitions", "...
The start state is the state to which the first transition goes to. The setter-method creates a unique first transition to the state with the given id. Existing first transitions are removed. If the given state id is None, the first transition is removed. :return: The id of the start state
[ "The", "start", "state", "is", "the", "state", "to", "which", "the", "first", "transition", "goes", "to", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2246-L2261
train
40,648
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.start_state_id
def start_state_id(self, start_state_id, to_outcome=None): """Set the start state of the container state See property :param start_state_id: The state id of the state which should be executed first in the Container state :raises exceptions.ValueError: if the start_state_id does not exist in :py:attr:`rafcon.core.states.container_state.ContainerState.states` """ if start_state_id is not None and start_state_id not in self.states: raise ValueError("start_state_id does not exist") if start_state_id is None and to_outcome is not None: # this is the case if the start state is the state itself if to_outcome not in self.outcomes: raise ValueError("to_outcome does not exist") if start_state_id != self.state_id: raise ValueError("to_outcome defined but start_state_id is not state_id") # First we remove the transition to the start state for transition_id in self.transitions: if self.transitions[transition_id].from_state is None: # If the current start state is the same as the old one, we don't have to do anything if self.transitions[transition_id].to_state == start_state_id: return self.remove_transition(transition_id) break if start_state_id is not None: self.add_transition(None, None, start_state_id, to_outcome)
python
def start_state_id(self, start_state_id, to_outcome=None): """Set the start state of the container state See property :param start_state_id: The state id of the state which should be executed first in the Container state :raises exceptions.ValueError: if the start_state_id does not exist in :py:attr:`rafcon.core.states.container_state.ContainerState.states` """ if start_state_id is not None and start_state_id not in self.states: raise ValueError("start_state_id does not exist") if start_state_id is None and to_outcome is not None: # this is the case if the start state is the state itself if to_outcome not in self.outcomes: raise ValueError("to_outcome does not exist") if start_state_id != self.state_id: raise ValueError("to_outcome defined but start_state_id is not state_id") # First we remove the transition to the start state for transition_id in self.transitions: if self.transitions[transition_id].from_state is None: # If the current start state is the same as the old one, we don't have to do anything if self.transitions[transition_id].to_state == start_state_id: return self.remove_transition(transition_id) break if start_state_id is not None: self.add_transition(None, None, start_state_id, to_outcome)
[ "def", "start_state_id", "(", "self", ",", "start_state_id", ",", "to_outcome", "=", "None", ")", ":", "if", "start_state_id", "is", "not", "None", "and", "start_state_id", "not", "in", "self", ".", "states", ":", "raise", "ValueError", "(", "\"start_state_id ...
Set the start state of the container state See property :param start_state_id: The state id of the state which should be executed first in the Container state :raises exceptions.ValueError: if the start_state_id does not exist in :py:attr:`rafcon.core.states.container_state.ContainerState.states`
[ "Set", "the", "start", "state", "of", "the", "container", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2266-L2293
train
40,649
DLR-RM/RAFCON
source/rafcon/core/states/container_state.py
ContainerState.scoped_variables
def scoped_variables(self, scoped_variables): """ Setter for _scoped_variables field See property :param dict scoped_variables: Dictionary scoped_variables[data_port_id] of :class:`rafcon.core.scope.ScopedVariable` :raises exceptions.TypeError: if the scoped_variables parameter has the wrong type :raises exceptions.AttributeError: if the keys of the scoped_variables dictionary and the ids of the scoped variables in the dictionary do not match """ if not isinstance(scoped_variables, dict): raise TypeError("scoped_variables must be of type dict") if [sv_id for sv_id, sv in scoped_variables.items() if not isinstance(sv, ScopedVariable)]: raise TypeError("element of scope variable must be of type ScopedVariable") if [sv_id for sv_id, sv in scoped_variables.items() if not sv_id == sv.data_port_id]: raise AttributeError("The key of the scope variable dictionary and " "the id of the scope variable do not match") old_scoped_variables = self._scoped_variables self._scoped_variables = scoped_variables for port_id, scoped_variable in scoped_variables.items(): try: scoped_variable.parent = self except ValueError: self._scoped_variables = old_scoped_variables raise # check that all old_scoped_variables are no more referencing self as there parent for old_scoped_variable in old_scoped_variables.values(): if old_scoped_variable not in self._scoped_variables.values() and old_scoped_variable.parent is self: old_scoped_variable.parent = None
python
def scoped_variables(self, scoped_variables): """ Setter for _scoped_variables field See property :param dict scoped_variables: Dictionary scoped_variables[data_port_id] of :class:`rafcon.core.scope.ScopedVariable` :raises exceptions.TypeError: if the scoped_variables parameter has the wrong type :raises exceptions.AttributeError: if the keys of the scoped_variables dictionary and the ids of the scoped variables in the dictionary do not match """ if not isinstance(scoped_variables, dict): raise TypeError("scoped_variables must be of type dict") if [sv_id for sv_id, sv in scoped_variables.items() if not isinstance(sv, ScopedVariable)]: raise TypeError("element of scope variable must be of type ScopedVariable") if [sv_id for sv_id, sv in scoped_variables.items() if not sv_id == sv.data_port_id]: raise AttributeError("The key of the scope variable dictionary and " "the id of the scope variable do not match") old_scoped_variables = self._scoped_variables self._scoped_variables = scoped_variables for port_id, scoped_variable in scoped_variables.items(): try: scoped_variable.parent = self except ValueError: self._scoped_variables = old_scoped_variables raise # check that all old_scoped_variables are no more referencing self as there parent for old_scoped_variable in old_scoped_variables.values(): if old_scoped_variable not in self._scoped_variables.values() and old_scoped_variable.parent is self: old_scoped_variable.parent = None
[ "def", "scoped_variables", "(", "self", ",", "scoped_variables", ")", ":", "if", "not", "isinstance", "(", "scoped_variables", ",", "dict", ")", ":", "raise", "TypeError", "(", "\"scoped_variables must be of type dict\"", ")", "if", "[", "sv_id", "for", "sv_id", ...
Setter for _scoped_variables field See property :param dict scoped_variables: Dictionary scoped_variables[data_port_id] of :class:`rafcon.core.scope.ScopedVariable` :raises exceptions.TypeError: if the scoped_variables parameter has the wrong type :raises exceptions.AttributeError: if the keys of the scoped_variables dictionary and the ids of the scoped variables in the dictionary do not match
[ "Setter", "for", "_scoped_variables", "field" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/container_state.py#L2312-L2342
train
40,650
DLR-RM/RAFCON
source/rafcon/core/states/execution_state.py
ExecutionState._execute
def _execute(self, execute_inputs, execute_outputs, backward_execution=False): """Calls the custom execute function of the script.py of the state """ self._script.build_module() outcome_item = self._script.execute(self, execute_inputs, execute_outputs, backward_execution) # in the case of backward execution the outcome is not relevant if backward_execution: return # If the state was preempted, the state must be left on the preempted outcome if self.preempted: return Outcome(-2, "preempted") # Outcome id was returned if outcome_item in self.outcomes: return self.outcomes[outcome_item] # Outcome name was returned for outcome_id, outcome in self.outcomes.items(): if outcome.name == outcome_item: return self.outcomes[outcome_id] logger.error("Returned outcome of {0} not existing: {1}".format(self, outcome_item)) return Outcome(-1, "aborted")
python
def _execute(self, execute_inputs, execute_outputs, backward_execution=False): """Calls the custom execute function of the script.py of the state """ self._script.build_module() outcome_item = self._script.execute(self, execute_inputs, execute_outputs, backward_execution) # in the case of backward execution the outcome is not relevant if backward_execution: return # If the state was preempted, the state must be left on the preempted outcome if self.preempted: return Outcome(-2, "preempted") # Outcome id was returned if outcome_item in self.outcomes: return self.outcomes[outcome_item] # Outcome name was returned for outcome_id, outcome in self.outcomes.items(): if outcome.name == outcome_item: return self.outcomes[outcome_id] logger.error("Returned outcome of {0} not existing: {1}".format(self, outcome_item)) return Outcome(-1, "aborted")
[ "def", "_execute", "(", "self", ",", "execute_inputs", ",", "execute_outputs", ",", "backward_execution", "=", "False", ")", ":", "self", ".", "_script", ".", "build_module", "(", ")", "outcome_item", "=", "self", ".", "_script", ".", "execute", "(", "self",...
Calls the custom execute function of the script.py of the state
[ "Calls", "the", "custom", "execute", "function", "of", "the", "script", ".", "py", "of", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/execution_state.py#L104-L130
train
40,651
DLR-RM/RAFCON
source/rafcon/core/states/execution_state.py
ExecutionState.run
def run(self): """ This defines the sequence of actions that are taken when the execution state is executed :return: """ if self.is_root_state: self.execution_history.push_call_history_item(self, CallType.EXECUTE, None, self.input_data) logger.debug("Running {0}{1}".format(self, " (backwards)" if self.backward_execution else "")) if self.backward_execution: self.setup_backward_run() else: self.setup_run() try: outcome = self._execute(self.input_data, self.output_data, self.backward_execution) self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE if self.backward_execution: # outcome handling is not required as we are in backward mode and the execution order is fixed result = self.finalize() else: # check output data self.check_output_data_type() result = self.finalize(outcome) if self.is_root_state: self.execution_history.push_return_history_item(self, CallType.EXECUTE, None, self.output_data) return result except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() formatted_exc = traceback.format_exception(exc_type, exc_value, exc_traceback) truncated_exc = [] for line in formatted_exc: if os.path.join("rafcon", "core") not in line: truncated_exc.append(line) logger.error("{0} had an internal error: {1}: {2}\n{3}".format(self, type(e).__name__, e, ''.join(truncated_exc))) # write error to the output_data of the state self.output_data["error"] = e self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE return self.finalize(Outcome(-1, "aborted"))
python
def run(self): """ This defines the sequence of actions that are taken when the execution state is executed :return: """ if self.is_root_state: self.execution_history.push_call_history_item(self, CallType.EXECUTE, None, self.input_data) logger.debug("Running {0}{1}".format(self, " (backwards)" if self.backward_execution else "")) if self.backward_execution: self.setup_backward_run() else: self.setup_run() try: outcome = self._execute(self.input_data, self.output_data, self.backward_execution) self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE if self.backward_execution: # outcome handling is not required as we are in backward mode and the execution order is fixed result = self.finalize() else: # check output data self.check_output_data_type() result = self.finalize(outcome) if self.is_root_state: self.execution_history.push_return_history_item(self, CallType.EXECUTE, None, self.output_data) return result except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() formatted_exc = traceback.format_exception(exc_type, exc_value, exc_traceback) truncated_exc = [] for line in formatted_exc: if os.path.join("rafcon", "core") not in line: truncated_exc.append(line) logger.error("{0} had an internal error: {1}: {2}\n{3}".format(self, type(e).__name__, e, ''.join(truncated_exc))) # write error to the output_data of the state self.output_data["error"] = e self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE return self.finalize(Outcome(-1, "aborted"))
[ "def", "run", "(", "self", ")", ":", "if", "self", ".", "is_root_state", ":", "self", ".", "execution_history", ".", "push_call_history_item", "(", "self", ",", "CallType", ".", "EXECUTE", ",", "None", ",", "self", ".", "input_data", ")", "logger", ".", ...
This defines the sequence of actions that are taken when the execution state is executed :return:
[ "This", "defines", "the", "sequence", "of", "actions", "that", "are", "taken", "when", "the", "execution", "state", "is", "executed" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/execution_state.py#L132-L173
train
40,652
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.register_view
def register_view(self, view): """Called when the view was registered""" super(StateMachineTreeController, self).register_view(view) self.view.connect('button_press_event', self.mouse_click) self.view_is_registered = True self.update(with_expand=True)
python
def register_view(self, view): """Called when the view was registered""" super(StateMachineTreeController, self).register_view(view) self.view.connect('button_press_event', self.mouse_click) self.view_is_registered = True self.update(with_expand=True)
[ "def", "register_view", "(", "self", ",", "view", ")", ":", "super", "(", "StateMachineTreeController", ",", "self", ")", ".", "register_view", "(", "view", ")", "self", ".", "view", ".", "connect", "(", "'button_press_event'", ",", "self", ".", "mouse_click...
Called when the view was registered
[ "Called", "when", "the", "view", "was", "registered" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L84-L89
train
40,653
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.register
def register(self): """Change the state machine that is observed for new selected states to the selected state machine.""" self._do_selection_update = True # relieve old model if self.__my_selected_sm_id is not None: # no old models available self.relieve_model(self._selected_sm_model) # set own selected state machine id self.__my_selected_sm_id = self.model.selected_state_machine_id if self.__my_selected_sm_id is not None: # observe new model self._selected_sm_model = self.model.state_machines[self.__my_selected_sm_id] self.observe_model(self._selected_sm_model) # for selection self.update() else: self._selected_sm_model = None self.state_row_iter_dict_by_state_path.clear() self.tree_store.clear() self._do_selection_update = False
python
def register(self): """Change the state machine that is observed for new selected states to the selected state machine.""" self._do_selection_update = True # relieve old model if self.__my_selected_sm_id is not None: # no old models available self.relieve_model(self._selected_sm_model) # set own selected state machine id self.__my_selected_sm_id = self.model.selected_state_machine_id if self.__my_selected_sm_id is not None: # observe new model self._selected_sm_model = self.model.state_machines[self.__my_selected_sm_id] self.observe_model(self._selected_sm_model) # for selection self.update() else: self._selected_sm_model = None self.state_row_iter_dict_by_state_path.clear() self.tree_store.clear() self._do_selection_update = False
[ "def", "register", "(", "self", ")", ":", "self", ".", "_do_selection_update", "=", "True", "# relieve old model", "if", "self", ".", "__my_selected_sm_id", "is", "not", "None", ":", "# no old models available", "self", ".", "relieve_model", "(", "self", ".", "_...
Change the state machine that is observed for new selected states to the selected state machine.
[ "Change", "the", "state", "machine", "that", "is", "observed", "for", "new", "selected", "states", "to", "the", "selected", "state", "machine", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L104-L121
train
40,654
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.selection_changed
def selection_changed(self, widget, event=None): """Notify state machine about tree view selection""" # do not forward cursor selection updates if state update is running # TODO maybe make this generic for respective abstract controller if self._state_which_is_updated: return super(StateMachineTreeController, self).selection_changed(widget, event)
python
def selection_changed(self, widget, event=None): """Notify state machine about tree view selection""" # do not forward cursor selection updates if state update is running # TODO maybe make this generic for respective abstract controller if self._state_which_is_updated: return super(StateMachineTreeController, self).selection_changed(widget, event)
[ "def", "selection_changed", "(", "self", ",", "widget", ",", "event", "=", "None", ")", ":", "# do not forward cursor selection updates if state update is running", "# TODO maybe make this generic for respective abstract controller", "if", "self", ".", "_state_which_is_updated", ...
Notify state machine about tree view selection
[ "Notify", "state", "machine", "about", "tree", "view", "selection" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L148-L154
train
40,655
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.redo_expansion_state
def redo_expansion_state(self, ignore_not_existing_rows=False): """ Considers the tree to be collapsed and expand into all tree item with the flag set True """ def set_expansion_state(state_path): state_row_iter = self.state_row_iter_dict_by_state_path[state_path] if state_row_iter: # may elements are missing afterwards state_row_path = self.tree_store.get_path(state_row_iter) self.view.expand_to_path(state_row_path) if self.__my_selected_sm_id is not None and self.__my_selected_sm_id in self.__expansion_state: expansion_state = self.__expansion_state[self.__my_selected_sm_id] try: for state_path, state_row_expanded in expansion_state.items(): if state_path in self.state_row_iter_dict_by_state_path: if state_row_expanded: set_expansion_state(state_path) else: if not ignore_not_existing_rows and self._selected_sm_model and \ self._selected_sm_model.state_machine.get_state_by_path(state_path, as_check=True): state = self._selected_sm_model.state_machine.get_state_by_path(state_path) if isinstance(state, LibraryState) or state.is_root_state_of_library or \ state.get_next_upper_library_root_state(): continue logger.error("State not in StateMachineTree but in StateMachine, {0}.".format(state_path)) except (TypeError, KeyError): logger.error("Expansion state of state machine {0} could not be restored" "".format(self.__my_selected_sm_id))
python
def redo_expansion_state(self, ignore_not_existing_rows=False): """ Considers the tree to be collapsed and expand into all tree item with the flag set True """ def set_expansion_state(state_path): state_row_iter = self.state_row_iter_dict_by_state_path[state_path] if state_row_iter: # may elements are missing afterwards state_row_path = self.tree_store.get_path(state_row_iter) self.view.expand_to_path(state_row_path) if self.__my_selected_sm_id is not None and self.__my_selected_sm_id in self.__expansion_state: expansion_state = self.__expansion_state[self.__my_selected_sm_id] try: for state_path, state_row_expanded in expansion_state.items(): if state_path in self.state_row_iter_dict_by_state_path: if state_row_expanded: set_expansion_state(state_path) else: if not ignore_not_existing_rows and self._selected_sm_model and \ self._selected_sm_model.state_machine.get_state_by_path(state_path, as_check=True): state = self._selected_sm_model.state_machine.get_state_by_path(state_path) if isinstance(state, LibraryState) or state.is_root_state_of_library or \ state.get_next_upper_library_root_state(): continue logger.error("State not in StateMachineTree but in StateMachine, {0}.".format(state_path)) except (TypeError, KeyError): logger.error("Expansion state of state machine {0} could not be restored" "".format(self.__my_selected_sm_id))
[ "def", "redo_expansion_state", "(", "self", ",", "ignore_not_existing_rows", "=", "False", ")", ":", "def", "set_expansion_state", "(", "state_path", ")", ":", "state_row_iter", "=", "self", ".", "state_row_iter_dict_by_state_path", "[", "state_path", "]", "if", "st...
Considers the tree to be collapsed and expand into all tree item with the flag set True
[ "Considers", "the", "tree", "to", "be", "collapsed", "and", "expand", "into", "all", "tree", "item", "with", "the", "flag", "set", "True" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L271-L298
train
40,656
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.update
def update(self, changed_state_model=None, with_expand=False): """Checks if all states are in tree and if tree has states which were deleted :param changed_state_model: Model that row has to be updated :param with_expand: The expand flag for the tree """ if not self.view_is_registered: return # define initial state-model for update if changed_state_model is None: # reset all parent_row_iter = None self.state_row_iter_dict_by_state_path.clear() self.tree_store.clear() if self._selected_sm_model: changed_state_model = self._selected_sm_model.root_state else: return else: # pick if changed_state_model.state.is_root_state: parent_row_iter = self.state_row_iter_dict_by_state_path[changed_state_model.state.get_path()] else: if changed_state_model.state.is_root_state_of_library: # because either lib-state or lib-state-root is in tree the next higher hierarchy state is updated changed_upper_state_m = changed_state_model.parent.parent else: changed_upper_state_m = changed_state_model.parent # TODO check the work around of the next 2 lines while refactoring -> it is a check to be more robust while changed_upper_state_m.state.get_path() not in self.state_row_iter_dict_by_state_path: # show Warning because because avoided method states_update logger.warning("Take a parent state because this is not in.") changed_upper_state_m = changed_upper_state_m.parent parent_row_iter = self.state_row_iter_dict_by_state_path[changed_upper_state_m.state.get_path()] # do recursive update self.insert_and_update_recursively(parent_row_iter, changed_state_model, with_expand)
python
def update(self, changed_state_model=None, with_expand=False): """Checks if all states are in tree and if tree has states which were deleted :param changed_state_model: Model that row has to be updated :param with_expand: The expand flag for the tree """ if not self.view_is_registered: return # define initial state-model for update if changed_state_model is None: # reset all parent_row_iter = None self.state_row_iter_dict_by_state_path.clear() self.tree_store.clear() if self._selected_sm_model: changed_state_model = self._selected_sm_model.root_state else: return else: # pick if changed_state_model.state.is_root_state: parent_row_iter = self.state_row_iter_dict_by_state_path[changed_state_model.state.get_path()] else: if changed_state_model.state.is_root_state_of_library: # because either lib-state or lib-state-root is in tree the next higher hierarchy state is updated changed_upper_state_m = changed_state_model.parent.parent else: changed_upper_state_m = changed_state_model.parent # TODO check the work around of the next 2 lines while refactoring -> it is a check to be more robust while changed_upper_state_m.state.get_path() not in self.state_row_iter_dict_by_state_path: # show Warning because because avoided method states_update logger.warning("Take a parent state because this is not in.") changed_upper_state_m = changed_upper_state_m.parent parent_row_iter = self.state_row_iter_dict_by_state_path[changed_upper_state_m.state.get_path()] # do recursive update self.insert_and_update_recursively(parent_row_iter, changed_state_model, with_expand)
[ "def", "update", "(", "self", ",", "changed_state_model", "=", "None", ",", "with_expand", "=", "False", ")", ":", "if", "not", "self", ".", "view_is_registered", ":", "return", "# define initial state-model for update", "if", "changed_state_model", "is", "None", ...
Checks if all states are in tree and if tree has states which were deleted :param changed_state_model: Model that row has to be updated :param with_expand: The expand flag for the tree
[ "Checks", "if", "all", "states", "are", "in", "tree", "and", "if", "tree", "has", "states", "which", "were", "deleted" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L300-L336
train
40,657
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.show_content
def show_content(self, state_model): """Check state machine tree specific show content flag. Is returning true if the upper most library state of a state model has a enabled show content flag or if there is no library root state above this state. :param rafcon.gui.models.abstract_state.AbstractStateModel state_model: The state model to check """ upper_most_lib_state_m = None if isinstance(state_model, LibraryStateModel): uppermost_library_root_state = state_model.state.get_uppermost_library_root_state() if uppermost_library_root_state is None: upper_most_lib_state_m = state_model else: upper_lib_state = uppermost_library_root_state.parent upper_most_lib_state_m = self._selected_sm_model.get_state_model_by_path(upper_lib_state.get_path()) if upper_most_lib_state_m: return upper_most_lib_state_m.show_content() else: return True
python
def show_content(self, state_model): """Check state machine tree specific show content flag. Is returning true if the upper most library state of a state model has a enabled show content flag or if there is no library root state above this state. :param rafcon.gui.models.abstract_state.AbstractStateModel state_model: The state model to check """ upper_most_lib_state_m = None if isinstance(state_model, LibraryStateModel): uppermost_library_root_state = state_model.state.get_uppermost_library_root_state() if uppermost_library_root_state is None: upper_most_lib_state_m = state_model else: upper_lib_state = uppermost_library_root_state.parent upper_most_lib_state_m = self._selected_sm_model.get_state_model_by_path(upper_lib_state.get_path()) if upper_most_lib_state_m: return upper_most_lib_state_m.show_content() else: return True
[ "def", "show_content", "(", "self", ",", "state_model", ")", ":", "upper_most_lib_state_m", "=", "None", "if", "isinstance", "(", "state_model", ",", "LibraryStateModel", ")", ":", "uppermost_library_root_state", "=", "state_model", ".", "state", ".", "get_uppermost...
Check state machine tree specific show content flag. Is returning true if the upper most library state of a state model has a enabled show content flag or if there is no library root state above this state. :param rafcon.gui.models.abstract_state.AbstractStateModel state_model: The state model to check
[ "Check", "state", "machine", "tree", "specific", "show", "content", "flag", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L363-L382
train
40,658
DLR-RM/RAFCON
source/rafcon/gui/controllers/state_machine_tree.py
StateMachineTreeController.get_state_machine_selection
def get_state_machine_selection(self): """Getter state machine selection :return: selection object, filtered set of selected states :rtype: rafcon.gui.selection.Selection, set """ if self._selected_sm_model: return self._selected_sm_model.selection, self._selected_sm_model.selection.states else: return None, set()
python
def get_state_machine_selection(self): """Getter state machine selection :return: selection object, filtered set of selected states :rtype: rafcon.gui.selection.Selection, set """ if self._selected_sm_model: return self._selected_sm_model.selection, self._selected_sm_model.selection.states else: return None, set()
[ "def", "get_state_machine_selection", "(", "self", ")", ":", "if", "self", ".", "_selected_sm_model", ":", "return", "self", ".", "_selected_sm_model", ".", "selection", ",", "self", ".", "_selected_sm_model", ".", "selection", ".", "states", "else", ":", "retur...
Getter state machine selection :return: selection object, filtered set of selected states :rtype: rafcon.gui.selection.Selection, set
[ "Getter", "state", "machine", "selection" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_machine_tree.py#L494-L503
train
40,659
DLR-RM/RAFCON
source/rafcon/core/script.py
Script.execute
def execute(self, state, inputs=None, outputs=None, backward_execution=False): """Execute the user 'execute' function specified in the script :param ExecutionState state: the state belonging to the execute function, refers to 'self' :param dict inputs: the input data of the script :param dict outputs: the output data of the script :param bool backward_execution: Flag whether to run the script in backwards mode :return: Return value of the execute script :rtype: str | int """ if not outputs: outputs = {} if not inputs: inputs = {} if backward_execution: if hasattr(self._compiled_module, "backward_execute"): return self._compiled_module.backward_execute( state, inputs, outputs, rafcon.core.singleton.global_variable_manager ) else: logger.debug("No backward execution method found for state %s" % state.name) return None else: return self._compiled_module.execute(state, inputs, outputs, rafcon.core.singleton.global_variable_manager)
python
def execute(self, state, inputs=None, outputs=None, backward_execution=False): """Execute the user 'execute' function specified in the script :param ExecutionState state: the state belonging to the execute function, refers to 'self' :param dict inputs: the input data of the script :param dict outputs: the output data of the script :param bool backward_execution: Flag whether to run the script in backwards mode :return: Return value of the execute script :rtype: str | int """ if not outputs: outputs = {} if not inputs: inputs = {} if backward_execution: if hasattr(self._compiled_module, "backward_execute"): return self._compiled_module.backward_execute( state, inputs, outputs, rafcon.core.singleton.global_variable_manager ) else: logger.debug("No backward execution method found for state %s" % state.name) return None else: return self._compiled_module.execute(state, inputs, outputs, rafcon.core.singleton.global_variable_manager)
[ "def", "execute", "(", "self", ",", "state", ",", "inputs", "=", "None", ",", "outputs", "=", "None", ",", "backward_execution", "=", "False", ")", ":", "if", "not", "outputs", ":", "outputs", "=", "{", "}", "if", "not", "inputs", ":", "inputs", "=",...
Execute the user 'execute' function specified in the script :param ExecutionState state: the state belonging to the execute function, refers to 'self' :param dict inputs: the input data of the script :param dict outputs: the output data of the script :param bool backward_execution: Flag whether to run the script in backwards mode :return: Return value of the execute script :rtype: str | int
[ "Execute", "the", "user", "execute", "function", "specified", "in", "the", "script" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/script.py#L81-L105
train
40,660
DLR-RM/RAFCON
source/rafcon/core/script.py
Script._load_script
def _load_script(self): """Loads the script from the filesystem :raises exceptions.IOError: if the script file could not be opened """ script_text = filesystem.read_file(self.path, self.filename) if not script_text: raise IOError("Script file could not be opened or was empty: {0}" "".format(os.path.join(self.path, self.filename))) self.script = script_text
python
def _load_script(self): """Loads the script from the filesystem :raises exceptions.IOError: if the script file could not be opened """ script_text = filesystem.read_file(self.path, self.filename) if not script_text: raise IOError("Script file could not be opened or was empty: {0}" "".format(os.path.join(self.path, self.filename))) self.script = script_text
[ "def", "_load_script", "(", "self", ")", ":", "script_text", "=", "filesystem", ".", "read_file", "(", "self", ".", "path", ",", "self", ".", "filename", ")", "if", "not", "script_text", ":", "raise", "IOError", "(", "\"Script file could not be opened or was emp...
Loads the script from the filesystem :raises exceptions.IOError: if the script file could not be opened
[ "Loads", "the", "script", "from", "the", "filesystem" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/script.py#L107-L117
train
40,661
DLR-RM/RAFCON
source/rafcon/core/script.py
Script.build_module
def build_module(self): """Builds a temporary module from the script file :raises exceptions.IOError: if the compilation of the script module failed """ try: imp.acquire_lock() module_name = os.path.splitext(self.filename)[0] + str(self._script_id) # load module tmp_module = imp.new_module(module_name) code = compile(self.script, '%s (%s)' % (self.filename, self._script_id), 'exec') try: exec(code, tmp_module.__dict__) except RuntimeError as e: raise IOError("The compilation of the script module failed - error message: %s" % str(e)) # return the module self.compiled_module = tmp_module finally: imp.release_lock()
python
def build_module(self): """Builds a temporary module from the script file :raises exceptions.IOError: if the compilation of the script module failed """ try: imp.acquire_lock() module_name = os.path.splitext(self.filename)[0] + str(self._script_id) # load module tmp_module = imp.new_module(module_name) code = compile(self.script, '%s (%s)' % (self.filename, self._script_id), 'exec') try: exec(code, tmp_module.__dict__) except RuntimeError as e: raise IOError("The compilation of the script module failed - error message: %s" % str(e)) # return the module self.compiled_module = tmp_module finally: imp.release_lock()
[ "def", "build_module", "(", "self", ")", ":", "try", ":", "imp", ".", "acquire_lock", "(", ")", "module_name", "=", "os", ".", "path", ".", "splitext", "(", "self", ".", "filename", ")", "[", "0", "]", "+", "str", "(", "self", ".", "_script_id", ")...
Builds a temporary module from the script file :raises exceptions.IOError: if the compilation of the script module failed
[ "Builds", "a", "temporary", "module", "from", "the", "script", "file" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/script.py#L119-L141
train
40,662
DLR-RM/RAFCON
source/rafcon/gui/controllers/menu_bar.py
MenuBarController._update_recently_opened_state_machines
def _update_recently_opened_state_machines(self): """Update the sub menu Open Recent in File menu Method clean's first all menu items of the sub menu 'recent open', then insert the user menu item to clean recent opened state machine paths and finally insert menu items for all elements in recent opened state machines list. """ if not self.registered_view: return for item in self.view.sub_menu_open_recently.get_children(): self.view.sub_menu_open_recently.remove(item) menu_item = gui_helper_label.create_menu_item("remove invalid paths", constants.ICON_ERASE, global_runtime_config.clean_recently_opened_state_machines) self.view.sub_menu_open_recently.append(menu_item) self.view.sub_menu_open_recently.append(Gtk.SeparatorMenuItem()) for sm_path in global_runtime_config.get_config_value("recently_opened_state_machines", []): # define label string root_state_name = gui_helper_state_machine.get_root_state_name_of_sm_file_system_path(sm_path) if root_state_name is None and not os.path.isdir(sm_path): root_state_name = 'NOT_ACCESSIBLE' label_string = "'{0}' in {1}".format(root_state_name, sm_path) if root_state_name is not None else sm_path # define icon of menu item is_in_libs = library_manager.is_os_path_within_library_root_paths(sm_path) button_image = constants.SIGN_LIB if is_in_libs else constants.BUTTON_OPEN # prepare state machine open call_back function sm_open_function = partial(self.on_open_activate, path=sm_path) # create and insert new menu item menu_item = gui_helper_label.create_menu_item(label_string, button_image, sm_open_function) self.view.sub_menu_open_recently.append(menu_item) self.view.sub_menu_open_recently.show_all()
python
def _update_recently_opened_state_machines(self): """Update the sub menu Open Recent in File menu Method clean's first all menu items of the sub menu 'recent open', then insert the user menu item to clean recent opened state machine paths and finally insert menu items for all elements in recent opened state machines list. """ if not self.registered_view: return for item in self.view.sub_menu_open_recently.get_children(): self.view.sub_menu_open_recently.remove(item) menu_item = gui_helper_label.create_menu_item("remove invalid paths", constants.ICON_ERASE, global_runtime_config.clean_recently_opened_state_machines) self.view.sub_menu_open_recently.append(menu_item) self.view.sub_menu_open_recently.append(Gtk.SeparatorMenuItem()) for sm_path in global_runtime_config.get_config_value("recently_opened_state_machines", []): # define label string root_state_name = gui_helper_state_machine.get_root_state_name_of_sm_file_system_path(sm_path) if root_state_name is None and not os.path.isdir(sm_path): root_state_name = 'NOT_ACCESSIBLE' label_string = "'{0}' in {1}".format(root_state_name, sm_path) if root_state_name is not None else sm_path # define icon of menu item is_in_libs = library_manager.is_os_path_within_library_root_paths(sm_path) button_image = constants.SIGN_LIB if is_in_libs else constants.BUTTON_OPEN # prepare state machine open call_back function sm_open_function = partial(self.on_open_activate, path=sm_path) # create and insert new menu item menu_item = gui_helper_label.create_menu_item(label_string, button_image, sm_open_function) self.view.sub_menu_open_recently.append(menu_item) self.view.sub_menu_open_recently.show_all()
[ "def", "_update_recently_opened_state_machines", "(", "self", ")", ":", "if", "not", "self", ".", "registered_view", ":", "return", "for", "item", "in", "self", ".", "view", ".", "sub_menu_open_recently", ".", "get_children", "(", ")", ":", "self", ".", "view"...
Update the sub menu Open Recent in File menu Method clean's first all menu items of the sub menu 'recent open', then insert the user menu item to clean recent opened state machine paths and finally insert menu items for all elements in recent opened state machines list.
[ "Update", "the", "sub", "menu", "Open", "Recent", "in", "File", "menu" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/menu_bar.py#L195-L231
train
40,663
DLR-RM/RAFCON
source/rafcon/utils/geometry.py
point_left_of_line
def point_left_of_line(point, line_start, line_end): """Determines whether a point is left of a line :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :return: True if point is left of line, else False """ # determine sign of determinant # ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0 return ((line_end[0] - line_start[0]) * (point[1] - line_start[1]) - (line_end[1] - line_start[1]) * (point[0] - line_start[0])) < 0
python
def point_left_of_line(point, line_start, line_end): """Determines whether a point is left of a line :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :return: True if point is left of line, else False """ # determine sign of determinant # ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0 return ((line_end[0] - line_start[0]) * (point[1] - line_start[1]) - (line_end[1] - line_start[1]) * (point[0] - line_start[0])) < 0
[ "def", "point_left_of_line", "(", "point", ",", "line_start", ",", "line_end", ")", ":", "# determine sign of determinant", "# ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0", "return", "(", "(", "line_end", "[", "0", "]", "-", "line_start", "[", "0", "]", ")...
Determines whether a point is left of a line :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :return: True if point is left of line, else False
[ "Determines", "whether", "a", "point", "is", "left", "of", "a", "line" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/geometry.py#L34-L45
train
40,664
DLR-RM/RAFCON
source/rafcon/utils/geometry.py
point_on_line
def point_on_line(point, line_start, line_end, accuracy=50.): """Checks whether a point lies on a line The function checks whether the point "point" (P) lies on the line defined by its starting point line_start (A) and its end point line_end (B). This is done by comparing the distance of [AB] with the sum of the distances [AP] and [PB]. If the difference is smaller than [AB] / accuracy, the point P is assumed to be on the line. By increasing the value of accuracy (the default is 50), the tolerance is decreased. :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :param accuracy: The higher this value, the less distance is tolerated :return: True if the point is one the line, False if not """ length = dist(line_start, line_end) ds = length / float(accuracy) if -ds < (dist(line_start, point) + dist(point, line_end) - length) < ds: return True return False
python
def point_on_line(point, line_start, line_end, accuracy=50.): """Checks whether a point lies on a line The function checks whether the point "point" (P) lies on the line defined by its starting point line_start (A) and its end point line_end (B). This is done by comparing the distance of [AB] with the sum of the distances [AP] and [PB]. If the difference is smaller than [AB] / accuracy, the point P is assumed to be on the line. By increasing the value of accuracy (the default is 50), the tolerance is decreased. :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :param accuracy: The higher this value, the less distance is tolerated :return: True if the point is one the line, False if not """ length = dist(line_start, line_end) ds = length / float(accuracy) if -ds < (dist(line_start, point) + dist(point, line_end) - length) < ds: return True return False
[ "def", "point_on_line", "(", "point", ",", "line_start", ",", "line_end", ",", "accuracy", "=", "50.", ")", ":", "length", "=", "dist", "(", "line_start", ",", "line_end", ")", "ds", "=", "length", "/", "float", "(", "accuracy", ")", "if", "-", "ds", ...
Checks whether a point lies on a line The function checks whether the point "point" (P) lies on the line defined by its starting point line_start (A) and its end point line_end (B). This is done by comparing the distance of [AB] with the sum of the distances [AP] and [PB]. If the difference is smaller than [AB] / accuracy, the point P is assumed to be on the line. By increasing the value of accuracy (the default is 50), the tolerance is decreased. :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :param accuracy: The higher this value, the less distance is tolerated :return: True if the point is one the line, False if not
[ "Checks", "whether", "a", "point", "lies", "on", "a", "line" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/geometry.py#L48-L67
train
40,665
DLR-RM/RAFCON
source/rafcon/utils/geometry.py
point_in_triangle
def point_in_triangle(p, v1, v2, v3): """Checks whether a point is within the given triangle The function checks, whether the given point p is within the triangle defined by the the three corner point v1, v2 and v3. This is done by checking whether the point is on all three half-planes defined by the three edges of the triangle. :param p: The point to be checked (tuple with x any y coordinate) :param v1: First vertex of the triangle (tuple with x any y coordinate) :param v2: Second vertex of the triangle (tuple with x any y coordinate) :param v3: Third vertex of the triangle (tuple with x any y coordinate) :return: True if the point is within the triangle, False if not """ def _test(p1, p2, p3): return (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]) b1 = _test(p, v1, v2) < 0.0 b2 = _test(p, v2, v3) < 0.0 b3 = _test(p, v3, v1) < 0.0 return (b1 == b2) and (b2 == b3)
python
def point_in_triangle(p, v1, v2, v3): """Checks whether a point is within the given triangle The function checks, whether the given point p is within the triangle defined by the the three corner point v1, v2 and v3. This is done by checking whether the point is on all three half-planes defined by the three edges of the triangle. :param p: The point to be checked (tuple with x any y coordinate) :param v1: First vertex of the triangle (tuple with x any y coordinate) :param v2: Second vertex of the triangle (tuple with x any y coordinate) :param v3: Third vertex of the triangle (tuple with x any y coordinate) :return: True if the point is within the triangle, False if not """ def _test(p1, p2, p3): return (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]) b1 = _test(p, v1, v2) < 0.0 b2 = _test(p, v2, v3) < 0.0 b3 = _test(p, v3, v1) < 0.0 return (b1 == b2) and (b2 == b3)
[ "def", "point_in_triangle", "(", "p", ",", "v1", ",", "v2", ",", "v3", ")", ":", "def", "_test", "(", "p1", ",", "p2", ",", "p3", ")", ":", "return", "(", "p1", "[", "0", "]", "-", "p3", "[", "0", "]", ")", "*", "(", "p2", "[", "1", "]", ...
Checks whether a point is within the given triangle The function checks, whether the given point p is within the triangle defined by the the three corner point v1, v2 and v3. This is done by checking whether the point is on all three half-planes defined by the three edges of the triangle. :param p: The point to be checked (tuple with x any y coordinate) :param v1: First vertex of the triangle (tuple with x any y coordinate) :param v2: Second vertex of the triangle (tuple with x any y coordinate) :param v3: Third vertex of the triangle (tuple with x any y coordinate) :return: True if the point is within the triangle, False if not
[ "Checks", "whether", "a", "point", "is", "within", "the", "given", "triangle" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/geometry.py#L70-L89
train
40,666
DLR-RM/RAFCON
source/rafcon/utils/geometry.py
equal
def equal(t1, t2, digit=None): """ Compare two iterators and its elements on specific digit precision The method assume that t1 and t2 are are list or tuple. :param t1: First element to compare :param t2: Second element to compare :param int digit: Number of digits to compare :rtype bool :return: True if equal and False if different """ if not len(t1) == len(t2): return False for idx in range(len(t1)): if digit is not None: if not round(t1[idx], digit) == round(t2[idx], digit): return False else: if not t1[idx] == t2[idx]: return False return True
python
def equal(t1, t2, digit=None): """ Compare two iterators and its elements on specific digit precision The method assume that t1 and t2 are are list or tuple. :param t1: First element to compare :param t2: Second element to compare :param int digit: Number of digits to compare :rtype bool :return: True if equal and False if different """ if not len(t1) == len(t2): return False for idx in range(len(t1)): if digit is not None: if not round(t1[idx], digit) == round(t2[idx], digit): return False else: if not t1[idx] == t2[idx]: return False return True
[ "def", "equal", "(", "t1", ",", "t2", ",", "digit", "=", "None", ")", ":", "if", "not", "len", "(", "t1", ")", "==", "len", "(", "t2", ")", ":", "return", "False", "for", "idx", "in", "range", "(", "len", "(", "t1", ")", ")", ":", "if", "di...
Compare two iterators and its elements on specific digit precision The method assume that t1 and t2 are are list or tuple. :param t1: First element to compare :param t2: Second element to compare :param int digit: Number of digits to compare :rtype bool :return: True if equal and False if different
[ "Compare", "two", "iterators", "and", "its", "elements", "on", "specific", "digit", "precision" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/geometry.py#L112-L136
train
40,667
DLR-RM/RAFCON
source/rafcon/utils/geometry.py
cal_dist_between_2_coord_frame_aligned_boxes
def cal_dist_between_2_coord_frame_aligned_boxes(box1_pos, box1_size, box2_pos, box2_size): """ Calculate Euclidean distance between two boxes those edges are parallel to the coordinate axis The function decides condition based which corner to corner or edge to edge distance needs to be calculated. :param tuple box1_pos: x and y position of box 1 :param tuple box1_size: x and y size of box 1 :param tuple box2_pos: x and y position of box 2 :param tuple box2_size: x and y size of box 2 :return: """ box1_x_min, box1_y_min = box1_pos box1_x_max, box1_y_max = (box1_pos[0] + box1_size[0], box1_pos[1] + box1_size[1]) box2_x_min, box2_y_min = box2_pos box2_x_max, box2_y_max = (box2_pos[0] + box2_size[0], box2_pos[1] + box2_size[1]) # 1|2|3 +-> x => works also for opengl - both boxes described in same coordinates # 4|5|6 -> 5 is covered by box1 | # 7|8|9 \/ y # - case 1 the right lower corner of box2 is above and left to box1 upper left corner # - case 5 is when the boxes are overlapping so the distance is 0 # - in case 1, 3, 7, 9 respective corners of box1 to box2 are the minimal distance # - 2, 4, 6, 8 can be covered by either simply calculation via either x or y axis if box2_x_max < box1_x_min and box2_y_max < box1_y_min: # case 1 -> box2 is fully in sector 1 distance = sqrt((box1_x_min - box2_x_max)**2 + (box1_y_min - box2_y_max)**2) elif box2_x_min > box1_x_max and box2_y_max < box1_y_min: # case 3 -> box2 is fully in sector 3 distance = sqrt((box2_x_min - box1_x_max)**2 + (box1_y_min - box2_y_max)**2) elif box2_x_max < box1_x_min and box2_y_min > box1_y_max: # case 7 -> box2 is fully in sector 7 distance = sqrt((box1_x_min - box2_x_max)**2 + (box2_y_min - box1_y_max)**2) elif box2_x_min > box1_x_max and box2_y_min > box1_y_max: # case 9 -> box2 is fully in sector 9 distance = sqrt((box2_x_min - box1_x_max)**2 + (box2_y_min - box1_y_max)**2) elif box2_y_max < box1_y_min: # case 2 -> box2 is party in sector 2 and in 1 or 3 distance = box1_y_min - box2_y_max elif box2_x_max < box1_x_min: # case 4 -> box2 is party in sector 4 and in 1 or 7 distance = box1_x_min - box2_x_max elif box2_x_min > box1_x_max: # case 6 -> box2 is party in sector 6 and in 3 or 9 distance = box2_x_min - box1_x_max elif box2_y_min > box1_y_max: # case 8 -> box2 is party in sector 8 and in 7 or 9 distance = box2_y_min - box1_y_max else: # case 5 box2 reach into area of box1 distance = 0. return distance
python
def cal_dist_between_2_coord_frame_aligned_boxes(box1_pos, box1_size, box2_pos, box2_size): """ Calculate Euclidean distance between two boxes those edges are parallel to the coordinate axis The function decides condition based which corner to corner or edge to edge distance needs to be calculated. :param tuple box1_pos: x and y position of box 1 :param tuple box1_size: x and y size of box 1 :param tuple box2_pos: x and y position of box 2 :param tuple box2_size: x and y size of box 2 :return: """ box1_x_min, box1_y_min = box1_pos box1_x_max, box1_y_max = (box1_pos[0] + box1_size[0], box1_pos[1] + box1_size[1]) box2_x_min, box2_y_min = box2_pos box2_x_max, box2_y_max = (box2_pos[0] + box2_size[0], box2_pos[1] + box2_size[1]) # 1|2|3 +-> x => works also for opengl - both boxes described in same coordinates # 4|5|6 -> 5 is covered by box1 | # 7|8|9 \/ y # - case 1 the right lower corner of box2 is above and left to box1 upper left corner # - case 5 is when the boxes are overlapping so the distance is 0 # - in case 1, 3, 7, 9 respective corners of box1 to box2 are the minimal distance # - 2, 4, 6, 8 can be covered by either simply calculation via either x or y axis if box2_x_max < box1_x_min and box2_y_max < box1_y_min: # case 1 -> box2 is fully in sector 1 distance = sqrt((box1_x_min - box2_x_max)**2 + (box1_y_min - box2_y_max)**2) elif box2_x_min > box1_x_max and box2_y_max < box1_y_min: # case 3 -> box2 is fully in sector 3 distance = sqrt((box2_x_min - box1_x_max)**2 + (box1_y_min - box2_y_max)**2) elif box2_x_max < box1_x_min and box2_y_min > box1_y_max: # case 7 -> box2 is fully in sector 7 distance = sqrt((box1_x_min - box2_x_max)**2 + (box2_y_min - box1_y_max)**2) elif box2_x_min > box1_x_max and box2_y_min > box1_y_max: # case 9 -> box2 is fully in sector 9 distance = sqrt((box2_x_min - box1_x_max)**2 + (box2_y_min - box1_y_max)**2) elif box2_y_max < box1_y_min: # case 2 -> box2 is party in sector 2 and in 1 or 3 distance = box1_y_min - box2_y_max elif box2_x_max < box1_x_min: # case 4 -> box2 is party in sector 4 and in 1 or 7 distance = box1_x_min - box2_x_max elif box2_x_min > box1_x_max: # case 6 -> box2 is party in sector 6 and in 3 or 9 distance = box2_x_min - box1_x_max elif box2_y_min > box1_y_max: # case 8 -> box2 is party in sector 8 and in 7 or 9 distance = box2_y_min - box1_y_max else: # case 5 box2 reach into area of box1 distance = 0. return distance
[ "def", "cal_dist_between_2_coord_frame_aligned_boxes", "(", "box1_pos", ",", "box1_size", ",", "box2_pos", ",", "box2_size", ")", ":", "box1_x_min", ",", "box1_y_min", "=", "box1_pos", "box1_x_max", ",", "box1_y_max", "=", "(", "box1_pos", "[", "0", "]", "+", "b...
Calculate Euclidean distance between two boxes those edges are parallel to the coordinate axis The function decides condition based which corner to corner or edge to edge distance needs to be calculated. :param tuple box1_pos: x and y position of box 1 :param tuple box1_size: x and y size of box 1 :param tuple box2_pos: x and y position of box 2 :param tuple box2_size: x and y size of box 2 :return:
[ "Calculate", "Euclidean", "distance", "between", "two", "boxes", "those", "edges", "are", "parallel", "to", "the", "coordinate", "axis" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/geometry.py#L139-L181
train
40,668
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.get_history_item_for_tree_iter
def get_history_item_for_tree_iter(self, child_tree_iter): """Hands history item for tree iter and compensate if tree item is a dummy item :param Gtk.TreeIter child_tree_iter: Tree iter of row :rtype rafcon.core.execution.execution_history.HistoryItem: :return history tree item: """ history_item = self.history_tree_store[child_tree_iter][self.HISTORY_ITEM_STORAGE_ID] if history_item is None: # is dummy item if self.history_tree_store.iter_n_children(child_tree_iter) > 0: child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, 0) history_item = self.history_tree_store[child_iter][self.HISTORY_ITEM_STORAGE_ID] else: logger.debug("In a dummy history should be respective real call element.") return history_item
python
def get_history_item_for_tree_iter(self, child_tree_iter): """Hands history item for tree iter and compensate if tree item is a dummy item :param Gtk.TreeIter child_tree_iter: Tree iter of row :rtype rafcon.core.execution.execution_history.HistoryItem: :return history tree item: """ history_item = self.history_tree_store[child_tree_iter][self.HISTORY_ITEM_STORAGE_ID] if history_item is None: # is dummy item if self.history_tree_store.iter_n_children(child_tree_iter) > 0: child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, 0) history_item = self.history_tree_store[child_iter][self.HISTORY_ITEM_STORAGE_ID] else: logger.debug("In a dummy history should be respective real call element.") return history_item
[ "def", "get_history_item_for_tree_iter", "(", "self", ",", "child_tree_iter", ")", ":", "history_item", "=", "self", ".", "history_tree_store", "[", "child_tree_iter", "]", "[", "self", ".", "HISTORY_ITEM_STORAGE_ID", "]", "if", "history_item", "is", "None", ":", ...
Hands history item for tree iter and compensate if tree item is a dummy item :param Gtk.TreeIter child_tree_iter: Tree iter of row :rtype rafcon.core.execution.execution_history.HistoryItem: :return history tree item:
[ "Hands", "history", "item", "for", "tree", "iter", "and", "compensate", "if", "tree", "item", "is", "a", "dummy", "item" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L251-L265
train
40,669
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController._store_expansion_state
def _store_expansion_state(self): """Iter recursively all tree items and store expansion state""" def store_tree_expansion(child_tree_iter, expansion_state): tree_item_path = self.history_tree_store.get_path(child_tree_iter) history_item = self.get_history_item_for_tree_iter(child_tree_iter) # store expansion state if tree item path is valid and expansion state was not stored already if tree_item_path is not None: # if first element of sub-tree has same history_item as the parent ignore it's expansion state if history_item not in expansion_state: expansion_state[history_item] = self.history_tree.row_expanded(tree_item_path) for n in range(self.history_tree_store.iter_n_children(child_tree_iter)): child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, n) store_tree_expansion(child_iter, expansion_state) root_iter = self.history_tree_store.get_iter_first() if not root_iter: return current_expansion_state = {} # this can be the case when the execution history tree is currently being deleted if not self.get_history_item_for_tree_iter(root_iter).state_reference: return state_machine = self.get_history_item_for_tree_iter(root_iter).state_reference.get_state_machine() self._expansion_state[state_machine.state_machine_id] = current_expansion_state while root_iter: store_tree_expansion(root_iter, current_expansion_state) root_iter = self.history_tree_store.iter_next(root_iter)
python
def _store_expansion_state(self): """Iter recursively all tree items and store expansion state""" def store_tree_expansion(child_tree_iter, expansion_state): tree_item_path = self.history_tree_store.get_path(child_tree_iter) history_item = self.get_history_item_for_tree_iter(child_tree_iter) # store expansion state if tree item path is valid and expansion state was not stored already if tree_item_path is not None: # if first element of sub-tree has same history_item as the parent ignore it's expansion state if history_item not in expansion_state: expansion_state[history_item] = self.history_tree.row_expanded(tree_item_path) for n in range(self.history_tree_store.iter_n_children(child_tree_iter)): child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, n) store_tree_expansion(child_iter, expansion_state) root_iter = self.history_tree_store.get_iter_first() if not root_iter: return current_expansion_state = {} # this can be the case when the execution history tree is currently being deleted if not self.get_history_item_for_tree_iter(root_iter).state_reference: return state_machine = self.get_history_item_for_tree_iter(root_iter).state_reference.get_state_machine() self._expansion_state[state_machine.state_machine_id] = current_expansion_state while root_iter: store_tree_expansion(root_iter, current_expansion_state) root_iter = self.history_tree_store.iter_next(root_iter)
[ "def", "_store_expansion_state", "(", "self", ")", ":", "def", "store_tree_expansion", "(", "child_tree_iter", ",", "expansion_state", ")", ":", "tree_item_path", "=", "self", ".", "history_tree_store", ".", "get_path", "(", "child_tree_iter", ")", "history_item", "...
Iter recursively all tree items and store expansion state
[ "Iter", "recursively", "all", "tree", "items", "and", "store", "expansion", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L267-L296
train
40,670
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController._restore_expansion_state
def _restore_expansion_state(self): """Iter recursively all tree items and restore expansion state""" def restore_tree_expansion(child_tree_iter, expansion_state): tree_item_path = self.history_tree_store.get_path(child_tree_iter) history_item = self.get_history_item_for_tree_iter(child_tree_iter) # restore expansion state if tree item path is valid and expansion state was not stored already if tree_item_path and history_item in expansion_state: if expansion_state[history_item]: self.history_tree.expand_to_path(tree_item_path) for n in range(self.history_tree_store.iter_n_children(child_tree_iter)): child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, n) restore_tree_expansion(child_iter, expansion_state) root_iter = self.history_tree_store.get_iter_first() if not root_iter: return state_machine = self.get_history_item_for_tree_iter(root_iter).state_reference.get_state_machine() if state_machine.state_machine_id not in self._expansion_state: return while root_iter: restore_tree_expansion(root_iter, self._expansion_state[state_machine.state_machine_id]) root_iter = self.history_tree_store.iter_next(root_iter)
python
def _restore_expansion_state(self): """Iter recursively all tree items and restore expansion state""" def restore_tree_expansion(child_tree_iter, expansion_state): tree_item_path = self.history_tree_store.get_path(child_tree_iter) history_item = self.get_history_item_for_tree_iter(child_tree_iter) # restore expansion state if tree item path is valid and expansion state was not stored already if tree_item_path and history_item in expansion_state: if expansion_state[history_item]: self.history_tree.expand_to_path(tree_item_path) for n in range(self.history_tree_store.iter_n_children(child_tree_iter)): child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, n) restore_tree_expansion(child_iter, expansion_state) root_iter = self.history_tree_store.get_iter_first() if not root_iter: return state_machine = self.get_history_item_for_tree_iter(root_iter).state_reference.get_state_machine() if state_machine.state_machine_id not in self._expansion_state: return while root_iter: restore_tree_expansion(root_iter, self._expansion_state[state_machine.state_machine_id]) root_iter = self.history_tree_store.iter_next(root_iter)
[ "def", "_restore_expansion_state", "(", "self", ")", ":", "def", "restore_tree_expansion", "(", "child_tree_iter", ",", "expansion_state", ")", ":", "tree_item_path", "=", "self", ".", "history_tree_store", ".", "get_path", "(", "child_tree_iter", ")", "history_item",...
Iter recursively all tree items and restore expansion state
[ "Iter", "recursively", "all", "tree", "items", "and", "restore", "expansion", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L298-L322
train
40,671
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.notification_selected_sm_changed
def notification_selected_sm_changed(self, model, prop_name, info): """If a new state machine is selected, make sure expansion state is stored and tree updated""" selected_state_machine_id = self.model.selected_state_machine_id if selected_state_machine_id is None: return self.update()
python
def notification_selected_sm_changed(self, model, prop_name, info): """If a new state machine is selected, make sure expansion state is stored and tree updated""" selected_state_machine_id = self.model.selected_state_machine_id if selected_state_machine_id is None: return self.update()
[ "def", "notification_selected_sm_changed", "(", "self", ",", "model", ",", "prop_name", ",", "info", ")", ":", "selected_state_machine_id", "=", "self", ".", "model", ".", "selected_state_machine_id", "if", "selected_state_machine_id", "is", "None", ":", "return", "...
If a new state machine is selected, make sure expansion state is stored and tree updated
[ "If", "a", "new", "state", "machine", "is", "selected", "make", "sure", "expansion", "state", "is", "stored", "and", "tree", "updated" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L325-L330
train
40,672
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.notification_sm_changed
def notification_sm_changed(self, model, prop_name, info): """Remove references to non-existing state machines""" for state_machine_id in list(self._expansion_state.keys()): if state_machine_id not in self.model.state_machines: del self._expansion_state[state_machine_id]
python
def notification_sm_changed(self, model, prop_name, info): """Remove references to non-existing state machines""" for state_machine_id in list(self._expansion_state.keys()): if state_machine_id not in self.model.state_machines: del self._expansion_state[state_machine_id]
[ "def", "notification_sm_changed", "(", "self", ",", "model", ",", "prop_name", ",", "info", ")", ":", "for", "state_machine_id", "in", "list", "(", "self", ".", "_expansion_state", ".", "keys", "(", ")", ")", ":", "if", "state_machine_id", "not", "in", "se...
Remove references to non-existing state machines
[ "Remove", "references", "to", "non", "-", "existing", "state", "machines" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L333-L337
train
40,673
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.execution_history_focus
def execution_history_focus(self, model, prop_name, info): """ Arranges to put execution-history widget page to become top page in notebook when execution starts and stops and resets the boolean of modification_history_was_focused to False each time this notification are observed. """ if state_machine_execution_engine.status.execution_mode in \ [StateMachineExecutionStatus.STARTED, StateMachineExecutionStatus.STOPPED, StateMachineExecutionStatus.FINISHED]: if self.parent is not None and hasattr(self.parent, "focus_notebook_page_of_controller"): # request focus -> which has not have to be satisfied self.parent.focus_notebook_page_of_controller(self) if state_machine_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED: if not self.model.selected_state_machine_id == self.model.state_machine_manager.active_state_machine_id: pass else: self.update()
python
def execution_history_focus(self, model, prop_name, info): """ Arranges to put execution-history widget page to become top page in notebook when execution starts and stops and resets the boolean of modification_history_was_focused to False each time this notification are observed. """ if state_machine_execution_engine.status.execution_mode in \ [StateMachineExecutionStatus.STARTED, StateMachineExecutionStatus.STOPPED, StateMachineExecutionStatus.FINISHED]: if self.parent is not None and hasattr(self.parent, "focus_notebook_page_of_controller"): # request focus -> which has not have to be satisfied self.parent.focus_notebook_page_of_controller(self) if state_machine_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED: if not self.model.selected_state_machine_id == self.model.state_machine_manager.active_state_machine_id: pass else: self.update()
[ "def", "execution_history_focus", "(", "self", ",", "model", ",", "prop_name", ",", "info", ")", ":", "if", "state_machine_execution_engine", ".", "status", ".", "execution_mode", "in", "[", "StateMachineExecutionStatus", ".", "STARTED", ",", "StateMachineExecutionSta...
Arranges to put execution-history widget page to become top page in notebook when execution starts and stops and resets the boolean of modification_history_was_focused to False each time this notification are observed.
[ "Arranges", "to", "put", "execution", "-", "history", "widget", "page", "to", "become", "top", "page", "in", "notebook", "when", "execution", "starts", "and", "stops", "and", "resets", "the", "boolean", "of", "modification_history_was_focused", "to", "False", "e...
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L340-L355
train
40,674
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.clean_history
def clean_history(self, widget, event=None): """Triggered when the 'Clean History' button is clicked. Empties the execution history tree by adjusting the start index and updates tree store and view. """ self.history_tree_store.clear() selected_sm_m = self.model.get_selected_state_machine_model() if selected_sm_m: # the core may continue running without the GUI and for this it needs its execution histories if state_machine_execution_engine.finished_or_stopped(): selected_sm_m.state_machine.destroy_execution_histories() self.update()
python
def clean_history(self, widget, event=None): """Triggered when the 'Clean History' button is clicked. Empties the execution history tree by adjusting the start index and updates tree store and view. """ self.history_tree_store.clear() selected_sm_m = self.model.get_selected_state_machine_model() if selected_sm_m: # the core may continue running without the GUI and for this it needs its execution histories if state_machine_execution_engine.finished_or_stopped(): selected_sm_m.state_machine.destroy_execution_histories() self.update()
[ "def", "clean_history", "(", "self", ",", "widget", ",", "event", "=", "None", ")", ":", "self", ".", "history_tree_store", ".", "clear", "(", ")", "selected_sm_m", "=", "self", ".", "model", ".", "get_selected_state_machine_model", "(", ")", "if", "selected...
Triggered when the 'Clean History' button is clicked. Empties the execution history tree by adjusting the start index and updates tree store and view.
[ "Triggered", "when", "the", "Clean", "History", "button", "is", "clicked", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L357-L368
train
40,675
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.insert_history_item
def insert_history_item(self, parent, history_item, description, dummy=False): """Enters a single history item into the tree store :param Gtk.TreeItem parent: Parent tree item :param HistoryItem history_item: History item to be inserted :param str description: A description to be added to the entry :param None dummy: Whether this is just a dummy entry (wrapper for concurrency items) :return: Inserted tree item :rtype: Gtk.TreeItem """ if not history_item.state_reference: logger.error("This must never happen! Current history_item is {}".format(history_item)) return None content = None if global_gui_config.get_config_value("SHOW_PATH_NAMES_IN_EXECUTION_HISTORY", False): content = (history_item.state_reference.name + " - " + history_item.state_reference.get_path() + " - " + description, None if dummy else history_item, None if dummy else self.TOOL_TIP_TEXT) else: content = (history_item.state_reference.name + " - " + description, None if dummy else history_item, None if dummy else self.TOOL_TIP_TEXT) tree_item = self.history_tree_store.insert_before( parent, None, content) return tree_item
python
def insert_history_item(self, parent, history_item, description, dummy=False): """Enters a single history item into the tree store :param Gtk.TreeItem parent: Parent tree item :param HistoryItem history_item: History item to be inserted :param str description: A description to be added to the entry :param None dummy: Whether this is just a dummy entry (wrapper for concurrency items) :return: Inserted tree item :rtype: Gtk.TreeItem """ if not history_item.state_reference: logger.error("This must never happen! Current history_item is {}".format(history_item)) return None content = None if global_gui_config.get_config_value("SHOW_PATH_NAMES_IN_EXECUTION_HISTORY", False): content = (history_item.state_reference.name + " - " + history_item.state_reference.get_path() + " - " + description, None if dummy else history_item, None if dummy else self.TOOL_TIP_TEXT) else: content = (history_item.state_reference.name + " - " + description, None if dummy else history_item, None if dummy else self.TOOL_TIP_TEXT) tree_item = self.history_tree_store.insert_before( parent, None, content) return tree_item
[ "def", "insert_history_item", "(", "self", ",", "parent", ",", "history_item", ",", "description", ",", "dummy", "=", "False", ")", ":", "if", "not", "history_item", ".", "state_reference", ":", "logger", ".", "error", "(", "\"This must never happen! Current histo...
Enters a single history item into the tree store :param Gtk.TreeItem parent: Parent tree item :param HistoryItem history_item: History item to be inserted :param str description: A description to be added to the entry :param None dummy: Whether this is just a dummy entry (wrapper for concurrency items) :return: Inserted tree item :rtype: Gtk.TreeItem
[ "Enters", "a", "single", "history", "item", "into", "the", "tree", "store" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L414-L441
train
40,676
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.insert_execution_history
def insert_execution_history(self, parent, execution_history, is_root=False): """Insert a list of history items into a the tree store If there are concurrency history items, the method is called recursively. :param Gtk.TreeItem parent: the parent to add the next history item to :param ExecutionHistory execution_history: all history items of a certain state machine execution :param bool is_root: Whether this is the root execution history """ current_parent = parent execution_history_iterator = iter(execution_history) for history_item in execution_history_iterator: if isinstance(history_item, ConcurrencyItem): self.insert_concurrent_execution_histories(current_parent, history_item.execution_histories) elif isinstance(history_item, CallItem): tree_item = self.insert_history_item(current_parent, history_item, "Enter" if is_root else "Call") if not tree_item: return if history_item.call_type is CallType.EXECUTE: # this is necessary that already the CallType.EXECUTE item opens a new hierarchy in the # tree view and not the CallType.CONTAINER item next_history_item = history_item.next if next_history_item and next_history_item.call_type is CallType.CONTAINER: current_parent = tree_item self.insert_history_item(current_parent, next_history_item, "Enter") try: next(execution_history_iterator) # skips the next history item in the iterator except StopIteration as e: # the execution engine does not have another item return else: # history_item is ReturnItem if current_parent is None: # The reasons here can be: missing history items, items in the wrong order etc. # Does not happen when using RAFCON without plugins logger.error("Invalid execution history: current_parent is None") return if history_item.call_type is CallType.EXECUTE: self.insert_history_item(current_parent, history_item, "Return") else: # CONTAINER self.insert_history_item(current_parent, history_item, "Exit") current_parent = self.history_tree_store.iter_parent(current_parent) is_root = False
python
def insert_execution_history(self, parent, execution_history, is_root=False): """Insert a list of history items into a the tree store If there are concurrency history items, the method is called recursively. :param Gtk.TreeItem parent: the parent to add the next history item to :param ExecutionHistory execution_history: all history items of a certain state machine execution :param bool is_root: Whether this is the root execution history """ current_parent = parent execution_history_iterator = iter(execution_history) for history_item in execution_history_iterator: if isinstance(history_item, ConcurrencyItem): self.insert_concurrent_execution_histories(current_parent, history_item.execution_histories) elif isinstance(history_item, CallItem): tree_item = self.insert_history_item(current_parent, history_item, "Enter" if is_root else "Call") if not tree_item: return if history_item.call_type is CallType.EXECUTE: # this is necessary that already the CallType.EXECUTE item opens a new hierarchy in the # tree view and not the CallType.CONTAINER item next_history_item = history_item.next if next_history_item and next_history_item.call_type is CallType.CONTAINER: current_parent = tree_item self.insert_history_item(current_parent, next_history_item, "Enter") try: next(execution_history_iterator) # skips the next history item in the iterator except StopIteration as e: # the execution engine does not have another item return else: # history_item is ReturnItem if current_parent is None: # The reasons here can be: missing history items, items in the wrong order etc. # Does not happen when using RAFCON without plugins logger.error("Invalid execution history: current_parent is None") return if history_item.call_type is CallType.EXECUTE: self.insert_history_item(current_parent, history_item, "Return") else: # CONTAINER self.insert_history_item(current_parent, history_item, "Exit") current_parent = self.history_tree_store.iter_parent(current_parent) is_root = False
[ "def", "insert_execution_history", "(", "self", ",", "parent", ",", "execution_history", ",", "is_root", "=", "False", ")", ":", "current_parent", "=", "parent", "execution_history_iterator", "=", "iter", "(", "execution_history", ")", "for", "history_item", "in", ...
Insert a list of history items into a the tree store If there are concurrency history items, the method is called recursively. :param Gtk.TreeItem parent: the parent to add the next history item to :param ExecutionHistory execution_history: all history items of a certain state machine execution :param bool is_root: Whether this is the root execution history
[ "Insert", "a", "list", "of", "history", "items", "into", "a", "the", "tree", "store" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L443-L487
train
40,677
DLR-RM/RAFCON
source/rafcon/gui/controllers/execution_history.py
ExecutionHistoryTreeController.insert_concurrent_execution_histories
def insert_concurrent_execution_histories(self, parent, concurrent_execution_histories): """Adds the child execution histories of a concurrency state. :param Gtk.TreeItem parent: the parent to add the next history item to :param list[ExecutionHistory] concurrent_execution_histories: a list of all child execution histories :return: """ for execution_history in concurrent_execution_histories: if len(execution_history) >= 1: first_history_item = execution_history[0] # this is just a dummy item to have an extra parent for each branch # gives better overview in case that one of the child state is a simple execution state tree_item = self.insert_history_item(parent, first_history_item, "Concurrency Branch", dummy=True) self.insert_execution_history(tree_item, execution_history)
python
def insert_concurrent_execution_histories(self, parent, concurrent_execution_histories): """Adds the child execution histories of a concurrency state. :param Gtk.TreeItem parent: the parent to add the next history item to :param list[ExecutionHistory] concurrent_execution_histories: a list of all child execution histories :return: """ for execution_history in concurrent_execution_histories: if len(execution_history) >= 1: first_history_item = execution_history[0] # this is just a dummy item to have an extra parent for each branch # gives better overview in case that one of the child state is a simple execution state tree_item = self.insert_history_item(parent, first_history_item, "Concurrency Branch", dummy=True) self.insert_execution_history(tree_item, execution_history)
[ "def", "insert_concurrent_execution_histories", "(", "self", ",", "parent", ",", "concurrent_execution_histories", ")", ":", "for", "execution_history", "in", "concurrent_execution_histories", ":", "if", "len", "(", "execution_history", ")", ">=", "1", ":", "first_histo...
Adds the child execution histories of a concurrency state. :param Gtk.TreeItem parent: the parent to add the next history item to :param list[ExecutionHistory] concurrent_execution_histories: a list of all child execution histories :return:
[ "Adds", "the", "child", "execution", "histories", "of", "a", "concurrency", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/execution_history.py#L489-L502
train
40,678
DLR-RM/RAFCON
source/rafcon/gui/controllers/library_tree.py
LibraryTreeController.select_open_state_machine_of_selected_library_element
def select_open_state_machine_of_selected_library_element(self): """Select respective state machine of selected library in state machine manager if already open """ (model, row_path) = self.view.get_selection().get_selected() if row_path: physical_library_path = model[row_path][self.ITEM_STORAGE_ID] smm = gui_singletons.state_machine_manager_model.state_machine_manager sm = smm.get_open_state_machine_of_file_system_path(physical_library_path) if sm: gui_singletons.state_machine_manager_model.selected_state_machine_id = sm.state_machine_id
python
def select_open_state_machine_of_selected_library_element(self): """Select respective state machine of selected library in state machine manager if already open """ (model, row_path) = self.view.get_selection().get_selected() if row_path: physical_library_path = model[row_path][self.ITEM_STORAGE_ID] smm = gui_singletons.state_machine_manager_model.state_machine_manager sm = smm.get_open_state_machine_of_file_system_path(physical_library_path) if sm: gui_singletons.state_machine_manager_model.selected_state_machine_id = sm.state_machine_id
[ "def", "select_open_state_machine_of_selected_library_element", "(", "self", ")", ":", "(", "model", ",", "row_path", ")", "=", "self", ".", "view", ".", "get_selection", "(", ")", ".", "get_selected", "(", ")", "if", "row_path", ":", "physical_library_path", "=...
Select respective state machine of selected library in state machine manager if already open
[ "Select", "respective", "state", "machine", "of", "selected", "library", "in", "state", "machine", "manager", "if", "already", "open" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/library_tree.py#L279-L287
train
40,679
DLR-RM/RAFCON
source/rafcon/gui/controllers/library_tree.py
LibraryTreeController.menu_item_remove_libraries_or_root_clicked
def menu_item_remove_libraries_or_root_clicked(self, menu_item): """Removes library from hard drive after request second confirmation""" menu_item_text = self.get_menu_item_text(menu_item) logger.info("Delete item '{0}' pressed.".format(menu_item_text)) model, path = self.view.get_selection().get_selected() if path: # Second confirmation to delete library tree_m_row = self.tree_store[path] library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row() # assert isinstance(tree_m_row[self.ITEM_STORAGE_ID], str) library_file_system_path = library_os_path if "root" in menu_item_text: button_texts = [menu_item_text + "from tree and config", "Cancel"] partial_message = "This will remove the library root from your configuration (config.yaml)." else: button_texts = [menu_item_text, "Cancel"] partial_message = "This folder will be removed from hard drive! You really wanna do that?" message_string = "You choose to {2} with " \ "\n\nlibrary tree path: {0}" \ "\n\nphysical path: {1}.\n\n\n"\ "{3}" \ "".format(os.path.join(self.convert_if_human_readable(tree_m_row[self.LIB_PATH_STORAGE_ID]), item_key), library_file_system_path, menu_item_text.lower(), partial_message) width = 8*len("physical path: " + library_file_system_path) dialog = RAFCONButtonDialog(message_string, button_texts, message_type=Gtk.MessageType.QUESTION, parent=self.get_root_window(), width=min(width, 1400)) response_id = dialog.run() dialog.destroy() if response_id == 1: if "root" in menu_item_text: logger.info("Remove library root key '{0}' from config.".format(item_key)) from rafcon.gui.singleton import global_config library_paths = global_config.get_config_value('LIBRARY_PATHS') del library_paths[tree_m_row[self.LIB_KEY_STORAGE_ID]] global_config.save_configuration() self.model.library_manager.refresh_libraries() elif "libraries" in menu_item_text: logger.debug("Remove of all libraries in {} is triggered.".format(library_os_path)) import shutil shutil.rmtree(library_os_path) self.model.library_manager.refresh_libraries() else: logger.debug("Remove of Library {} is triggered.".format(library_os_path)) self.model.library_manager.remove_library_from_file_system(library_path, library_name) elif response_id in [2, -4]: pass else: logger.warning("Response id: {} is not considered".format(response_id)) return True return False
python
def menu_item_remove_libraries_or_root_clicked(self, menu_item): """Removes library from hard drive after request second confirmation""" menu_item_text = self.get_menu_item_text(menu_item) logger.info("Delete item '{0}' pressed.".format(menu_item_text)) model, path = self.view.get_selection().get_selected() if path: # Second confirmation to delete library tree_m_row = self.tree_store[path] library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row() # assert isinstance(tree_m_row[self.ITEM_STORAGE_ID], str) library_file_system_path = library_os_path if "root" in menu_item_text: button_texts = [menu_item_text + "from tree and config", "Cancel"] partial_message = "This will remove the library root from your configuration (config.yaml)." else: button_texts = [menu_item_text, "Cancel"] partial_message = "This folder will be removed from hard drive! You really wanna do that?" message_string = "You choose to {2} with " \ "\n\nlibrary tree path: {0}" \ "\n\nphysical path: {1}.\n\n\n"\ "{3}" \ "".format(os.path.join(self.convert_if_human_readable(tree_m_row[self.LIB_PATH_STORAGE_ID]), item_key), library_file_system_path, menu_item_text.lower(), partial_message) width = 8*len("physical path: " + library_file_system_path) dialog = RAFCONButtonDialog(message_string, button_texts, message_type=Gtk.MessageType.QUESTION, parent=self.get_root_window(), width=min(width, 1400)) response_id = dialog.run() dialog.destroy() if response_id == 1: if "root" in menu_item_text: logger.info("Remove library root key '{0}' from config.".format(item_key)) from rafcon.gui.singleton import global_config library_paths = global_config.get_config_value('LIBRARY_PATHS') del library_paths[tree_m_row[self.LIB_KEY_STORAGE_ID]] global_config.save_configuration() self.model.library_manager.refresh_libraries() elif "libraries" in menu_item_text: logger.debug("Remove of all libraries in {} is triggered.".format(library_os_path)) import shutil shutil.rmtree(library_os_path) self.model.library_manager.refresh_libraries() else: logger.debug("Remove of Library {} is triggered.".format(library_os_path)) self.model.library_manager.remove_library_from_file_system(library_path, library_name) elif response_id in [2, -4]: pass else: logger.warning("Response id: {} is not considered".format(response_id)) return True return False
[ "def", "menu_item_remove_libraries_or_root_clicked", "(", "self", ",", "menu_item", ")", ":", "menu_item_text", "=", "self", ".", "get_menu_item_text", "(", "menu_item", ")", "logger", ".", "info", "(", "\"Delete item '{0}' pressed.\"", ".", "format", "(", "menu_item_...
Removes library from hard drive after request second confirmation
[ "Removes", "library", "from", "hard", "drive", "after", "request", "second", "confirmation" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/library_tree.py#L338-L398
train
40,680
DLR-RM/RAFCON
source/rafcon/gui/controllers/library_tree.py
LibraryTreeController.extract_library_properties_from_selected_row
def extract_library_properties_from_selected_row(self): """ Extracts properties library_os_path, library_path, library_name and tree_item_key from tree store row """ (model, row) = self.view.get_selection().get_selected() tree_item_key = model[row][self.ID_STORAGE_ID] library_item = model[row][self.ITEM_STORAGE_ID] library_path = model[row][self.LIB_PATH_STORAGE_ID] if isinstance(library_item, dict): # sub-tree os_path = model[row][self.OS_PATH_STORAGE_ID] return os_path, None, None, tree_item_key # relevant elements of sub-tree assert isinstance(library_item, string_types) library_os_path = library_item library_name = library_os_path.split(os.path.sep)[-1] return library_os_path, library_path, library_name, tree_item_key
python
def extract_library_properties_from_selected_row(self): """ Extracts properties library_os_path, library_path, library_name and tree_item_key from tree store row """ (model, row) = self.view.get_selection().get_selected() tree_item_key = model[row][self.ID_STORAGE_ID] library_item = model[row][self.ITEM_STORAGE_ID] library_path = model[row][self.LIB_PATH_STORAGE_ID] if isinstance(library_item, dict): # sub-tree os_path = model[row][self.OS_PATH_STORAGE_ID] return os_path, None, None, tree_item_key # relevant elements of sub-tree assert isinstance(library_item, string_types) library_os_path = library_item library_name = library_os_path.split(os.path.sep)[-1] return library_os_path, library_path, library_name, tree_item_key
[ "def", "extract_library_properties_from_selected_row", "(", "self", ")", ":", "(", "model", ",", "row", ")", "=", "self", ".", "view", ".", "get_selection", "(", ")", ".", "get_selected", "(", ")", "tree_item_key", "=", "model", "[", "row", "]", "[", "self...
Extracts properties library_os_path, library_path, library_name and tree_item_key from tree store row
[ "Extracts", "properties", "library_os_path", "library_path", "library_name", "and", "tree_item_key", "from", "tree", "store", "row" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/library_tree.py#L410-L424
train
40,681
DLR-RM/RAFCON
source/rafcon/gui/controllers/library_tree.py
LibraryTreeController._get_selected_library_state
def _get_selected_library_state(self): """Returns the LibraryState which was selected in the LibraryTree :return: selected state in TreeView :rtype: LibraryState """ library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row() if library_path is None: return None logger.debug("Link library state '{0}' (with library tree path: {2} and file system path: {1}) into state " "machine.".format(str(item_key), library_os_path, self.convert_if_human_readable(str(library_path)) + "/" + str(item_key))) library_name = library_os_path.split(os.path.sep)[-1] return LibraryState(library_path, library_name, "0.1", format_folder_name_human_readable(library_name))
python
def _get_selected_library_state(self): """Returns the LibraryState which was selected in the LibraryTree :return: selected state in TreeView :rtype: LibraryState """ library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row() if library_path is None: return None logger.debug("Link library state '{0}' (with library tree path: {2} and file system path: {1}) into state " "machine.".format(str(item_key), library_os_path, self.convert_if_human_readable(str(library_path)) + "/" + str(item_key))) library_name = library_os_path.split(os.path.sep)[-1] return LibraryState(library_path, library_name, "0.1", format_folder_name_human_readable(library_name))
[ "def", "_get_selected_library_state", "(", "self", ")", ":", "library_os_path", ",", "library_path", ",", "library_name", ",", "item_key", "=", "self", ".", "extract_library_properties_from_selected_row", "(", ")", "if", "library_path", "is", "None", ":", "return", ...
Returns the LibraryState which was selected in the LibraryTree :return: selected state in TreeView :rtype: LibraryState
[ "Returns", "the", "LibraryState", "which", "was", "selected", "in", "the", "LibraryTree" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/library_tree.py#L426-L440
train
40,682
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.start
def start(self, execution_history, backward_execution=False, generate_run_id=True): """ Starts the execution of the state in a new thread. :return: """ self.execution_history = execution_history if generate_run_id: self._run_id = run_id_generator() self.backward_execution = copy.copy(backward_execution) self.thread = threading.Thread(target=self.run) self.thread.start()
python
def start(self, execution_history, backward_execution=False, generate_run_id=True): """ Starts the execution of the state in a new thread. :return: """ self.execution_history = execution_history if generate_run_id: self._run_id = run_id_generator() self.backward_execution = copy.copy(backward_execution) self.thread = threading.Thread(target=self.run) self.thread.start()
[ "def", "start", "(", "self", ",", "execution_history", ",", "backward_execution", "=", "False", ",", "generate_run_id", "=", "True", ")", ":", "self", ".", "execution_history", "=", "execution_history", "if", "generate_run_id", ":", "self", ".", "_run_id", "=", ...
Starts the execution of the state in a new thread. :return:
[ "Starts", "the", "execution", "of", "the", "state", "in", "a", "new", "thread", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L247-L257
train
40,683
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.join
def join(self): """ Waits until the state finished execution. """ if self.thread: self.thread.join() self.thread = None else: logger.debug("Cannot join {0}, as the state hasn't been started, yet or is already finished!".format(self))
python
def join(self): """ Waits until the state finished execution. """ if self.thread: self.thread.join() self.thread = None else: logger.debug("Cannot join {0}, as the state hasn't been started, yet or is already finished!".format(self))
[ "def", "join", "(", "self", ")", ":", "if", "self", ".", "thread", ":", "self", ".", "thread", ".", "join", "(", ")", "self", ".", "thread", "=", "None", "else", ":", "logger", ".", "debug", "(", "\"Cannot join {0}, as the state hasn't been started, yet or i...
Waits until the state finished execution.
[ "Waits", "until", "the", "state", "finished", "execution", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L262-L270
train
40,684
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.recursively_preempt_states
def recursively_preempt_states(self): """Preempt the state """ self.preempted = True self.paused = False self.started = False
python
def recursively_preempt_states(self): """Preempt the state """ self.preempted = True self.paused = False self.started = False
[ "def", "recursively_preempt_states", "(", "self", ")", ":", "self", ".", "preempted", "=", "True", "self", ".", "paused", "=", "False", "self", ".", "started", "=", "False" ]
Preempt the state
[ "Preempt", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L296-L301
train
40,685
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.get_default_input_values_for_state
def get_default_input_values_for_state(self, state): """ Computes the default input values for a state :param State state: the state to get the default input values for """ from rafcon.core.states.library_state import LibraryState result_dict = {} for input_port_key, value in state.input_data_ports.items(): if isinstance(state, LibraryState): if state.use_runtime_value_input_data_ports[input_port_key]: default = state.input_data_port_runtime_values[input_port_key] else: default = value.default_value else: default = value.default_value # if the user sets the default value to a string starting with $, try to retrieve the value # from the global variable manager if isinstance(default, string_types) and len(default) > 0 and default[0] == '$': from rafcon.core.singleton import global_variable_manager as gvm var_name = default[1:] if not gvm.variable_exist(var_name): logger.error("The global variable '{0}' does not exist".format(var_name)) global_value = None else: global_value = gvm.get_variable(var_name) result_dict[value.name] = global_value else: # set input to its default value result_dict[value.name] = copy.copy(default) return result_dict
python
def get_default_input_values_for_state(self, state): """ Computes the default input values for a state :param State state: the state to get the default input values for """ from rafcon.core.states.library_state import LibraryState result_dict = {} for input_port_key, value in state.input_data_ports.items(): if isinstance(state, LibraryState): if state.use_runtime_value_input_data_ports[input_port_key]: default = state.input_data_port_runtime_values[input_port_key] else: default = value.default_value else: default = value.default_value # if the user sets the default value to a string starting with $, try to retrieve the value # from the global variable manager if isinstance(default, string_types) and len(default) > 0 and default[0] == '$': from rafcon.core.singleton import global_variable_manager as gvm var_name = default[1:] if not gvm.variable_exist(var_name): logger.error("The global variable '{0}' does not exist".format(var_name)) global_value = None else: global_value = gvm.get_variable(var_name) result_dict[value.name] = global_value else: # set input to its default value result_dict[value.name] = copy.copy(default) return result_dict
[ "def", "get_default_input_values_for_state", "(", "self", ",", "state", ")", ":", "from", "rafcon", ".", "core", ".", "states", ".", "library_state", "import", "LibraryState", "result_dict", "=", "{", "}", "for", "input_port_key", ",", "value", "in", "state", ...
Computes the default input values for a state :param State state: the state to get the default input values for
[ "Computes", "the", "default", "input", "values", "for", "a", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L326-L356
train
40,686
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.create_output_dictionary_for_state
def create_output_dictionary_for_state(state): """Return empty output dictionary for a state :param state: the state of which the output data is determined :return: the output data of the target state """ from rafcon.core.states.library_state import LibraryState result_dict = {} for key, data_port in state.output_data_ports.items(): if isinstance(state, LibraryState) and state.use_runtime_value_output_data_ports[key]: result_dict[data_port.name] = copy.copy(state.output_data_port_runtime_values[key]) else: result_dict[data_port.name] = copy.copy(data_port.default_value) return result_dict
python
def create_output_dictionary_for_state(state): """Return empty output dictionary for a state :param state: the state of which the output data is determined :return: the output data of the target state """ from rafcon.core.states.library_state import LibraryState result_dict = {} for key, data_port in state.output_data_ports.items(): if isinstance(state, LibraryState) and state.use_runtime_value_output_data_ports[key]: result_dict[data_port.name] = copy.copy(state.output_data_port_runtime_values[key]) else: result_dict[data_port.name] = copy.copy(data_port.default_value) return result_dict
[ "def", "create_output_dictionary_for_state", "(", "state", ")", ":", "from", "rafcon", ".", "core", ".", "states", ".", "library_state", "import", "LibraryState", "result_dict", "=", "{", "}", "for", "key", ",", "data_port", "in", "state", ".", "output_data_port...
Return empty output dictionary for a state :param state: the state of which the output data is determined :return: the output data of the target state
[ "Return", "empty", "output", "dictionary", "for", "a", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L359-L372
train
40,687
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.add_input_data_port
def add_input_data_port(self, name, data_type=None, default_value=None, data_port_id=None): """Add a new input data port to the state. :param str name: the name of the new input data port :param data_type: the type of the new output data port considered of class :class:`type` or :class:`str` which has to be convertible to :class:`type` :param default_value: the default value of the data port :param int data_port_id: the data_port_id of the new data port :return: data_port_id of new input data port :rtype: int :raises exceptions.ValueError: if name of the input port is not unique """ if data_port_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state data_port_id = generate_data_port_id(self.get_data_port_ids()) self._input_data_ports[data_port_id] = InputDataPort(name, data_type, default_value, data_port_id, self) # Check for name uniqueness valid, message = self._check_data_port_name(self._input_data_ports[data_port_id]) if not valid: self._input_data_ports[data_port_id].parent = None del self._input_data_ports[data_port_id] raise ValueError(message) return data_port_id
python
def add_input_data_port(self, name, data_type=None, default_value=None, data_port_id=None): """Add a new input data port to the state. :param str name: the name of the new input data port :param data_type: the type of the new output data port considered of class :class:`type` or :class:`str` which has to be convertible to :class:`type` :param default_value: the default value of the data port :param int data_port_id: the data_port_id of the new data port :return: data_port_id of new input data port :rtype: int :raises exceptions.ValueError: if name of the input port is not unique """ if data_port_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state data_port_id = generate_data_port_id(self.get_data_port_ids()) self._input_data_ports[data_port_id] = InputDataPort(name, data_type, default_value, data_port_id, self) # Check for name uniqueness valid, message = self._check_data_port_name(self._input_data_ports[data_port_id]) if not valid: self._input_data_ports[data_port_id].parent = None del self._input_data_ports[data_port_id] raise ValueError(message) return data_port_id
[ "def", "add_input_data_port", "(", "self", ",", "name", ",", "data_type", "=", "None", ",", "default_value", "=", "None", ",", "data_port_id", "=", "None", ")", ":", "if", "data_port_id", "is", "None", ":", "# All data port ids have to passed to the id generation as...
Add a new input data port to the state. :param str name: the name of the new input data port :param data_type: the type of the new output data port considered of class :class:`type` or :class:`str` which has to be convertible to :class:`type` :param default_value: the default value of the data port :param int data_port_id: the data_port_id of the new data port :return: data_port_id of new input data port :rtype: int :raises exceptions.ValueError: if name of the input port is not unique
[ "Add", "a", "new", "input", "data", "port", "to", "the", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L379-L403
train
40,688
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.remove_input_data_port
def remove_input_data_port(self, data_port_id, force=False, destroy=True): """Remove an input data port from the state :param int data_port_id: the id or the output data port to remove :param bool force: if the removal should be forced without checking constraints :raises exceptions.AttributeError: if the specified input data port does not exist """ if data_port_id in self._input_data_ports: if destroy: self.remove_data_flows_with_data_port_id(data_port_id) self._input_data_ports[data_port_id].parent = None return self._input_data_ports.pop(data_port_id) else: raise AttributeError("input data port with name %s does not exit", data_port_id)
python
def remove_input_data_port(self, data_port_id, force=False, destroy=True): """Remove an input data port from the state :param int data_port_id: the id or the output data port to remove :param bool force: if the removal should be forced without checking constraints :raises exceptions.AttributeError: if the specified input data port does not exist """ if data_port_id in self._input_data_ports: if destroy: self.remove_data_flows_with_data_port_id(data_port_id) self._input_data_ports[data_port_id].parent = None return self._input_data_ports.pop(data_port_id) else: raise AttributeError("input data port with name %s does not exit", data_port_id)
[ "def", "remove_input_data_port", "(", "self", ",", "data_port_id", ",", "force", "=", "False", ",", "destroy", "=", "True", ")", ":", "if", "data_port_id", "in", "self", ".", "_input_data_ports", ":", "if", "destroy", ":", "self", ".", "remove_data_flows_with_...
Remove an input data port from the state :param int data_port_id: the id or the output data port to remove :param bool force: if the removal should be forced without checking constraints :raises exceptions.AttributeError: if the specified input data port does not exist
[ "Remove", "an", "input", "data", "port", "from", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L407-L420
train
40,689
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.remove_data_flows_with_data_port_id
def remove_data_flows_with_data_port_id(self, data_port_id): """Remove all data flows whose from_key or to_key equals the passed data_port_id :param data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id """ if not self.is_root_state: # delete all data flows in parent related to data_port_id and self.state_id data_flow_ids_to_remove = [] for data_flow_id, data_flow in self.parent.data_flows.items(): if data_flow.from_state == self.state_id and data_flow.from_key == data_port_id or \ data_flow.to_state == self.state_id and data_flow.to_key == data_port_id: data_flow_ids_to_remove.append(data_flow_id) for data_flow_id in data_flow_ids_to_remove: self.parent.remove_data_flow(data_flow_id)
python
def remove_data_flows_with_data_port_id(self, data_port_id): """Remove all data flows whose from_key or to_key equals the passed data_port_id :param data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id """ if not self.is_root_state: # delete all data flows in parent related to data_port_id and self.state_id data_flow_ids_to_remove = [] for data_flow_id, data_flow in self.parent.data_flows.items(): if data_flow.from_state == self.state_id and data_flow.from_key == data_port_id or \ data_flow.to_state == self.state_id and data_flow.to_key == data_port_id: data_flow_ids_to_remove.append(data_flow_id) for data_flow_id in data_flow_ids_to_remove: self.parent.remove_data_flow(data_flow_id)
[ "def", "remove_data_flows_with_data_port_id", "(", "self", ",", "data_port_id", ")", ":", "if", "not", "self", ".", "is_root_state", ":", "# delete all data flows in parent related to data_port_id and self.state_id", "data_flow_ids_to_remove", "=", "[", "]", "for", "data_flow...
Remove all data flows whose from_key or to_key equals the passed data_port_id :param data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id
[ "Remove", "all", "data", "flows", "whose", "from_key", "or", "to_key", "equals", "the", "passed", "data_port_id" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L423-L439
train
40,690
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.add_output_data_port
def add_output_data_port(self, name, data_type, default_value=None, data_port_id=None): """Add a new output data port to the state :param str name: the name of the new output data port :param data_type: the type of the new output data port considered of class :class:`type` or :class:`str` which has to be convertible to :class:`type` :param default_value: the default value of the data port :param int data_port_id: the data_port_id of the new data port :return: data_port_id of new output data port :rtype: int :raises exceptions.ValueError: if name of the output port is not unique """ if data_port_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state data_port_id = generate_data_port_id(self.get_data_port_ids()) self._output_data_ports[data_port_id] = OutputDataPort(name, data_type, default_value, data_port_id, self) # Check for name uniqueness valid, message = self._check_data_port_name(self._output_data_ports[data_port_id]) if not valid: self._output_data_ports[data_port_id].parent = None del self._output_data_ports[data_port_id] raise ValueError(message) return data_port_id
python
def add_output_data_port(self, name, data_type, default_value=None, data_port_id=None): """Add a new output data port to the state :param str name: the name of the new output data port :param data_type: the type of the new output data port considered of class :class:`type` or :class:`str` which has to be convertible to :class:`type` :param default_value: the default value of the data port :param int data_port_id: the data_port_id of the new data port :return: data_port_id of new output data port :rtype: int :raises exceptions.ValueError: if name of the output port is not unique """ if data_port_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state data_port_id = generate_data_port_id(self.get_data_port_ids()) self._output_data_ports[data_port_id] = OutputDataPort(name, data_type, default_value, data_port_id, self) # Check for name uniqueness valid, message = self._check_data_port_name(self._output_data_ports[data_port_id]) if not valid: self._output_data_ports[data_port_id].parent = None del self._output_data_ports[data_port_id] raise ValueError(message) return data_port_id
[ "def", "add_output_data_port", "(", "self", ",", "name", ",", "data_type", ",", "default_value", "=", "None", ",", "data_port_id", "=", "None", ")", ":", "if", "data_port_id", "is", "None", ":", "# All data port ids have to passed to the id generation as the data port i...
Add a new output data port to the state :param str name: the name of the new output data port :param data_type: the type of the new output data port considered of class :class:`type` or :class:`str` which has to be convertible to :class:`type` :param default_value: the default value of the data port :param int data_port_id: the data_port_id of the new data port :return: data_port_id of new output data port :rtype: int :raises exceptions.ValueError: if name of the output port is not unique
[ "Add", "a", "new", "output", "data", "port", "to", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L443-L467
train
40,691
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.remove_output_data_port
def remove_output_data_port(self, data_port_id, force=False, destroy=True): """Remove an output data port from the state :param int data_port_id: the id of the output data port to remove :raises exceptions.AttributeError: if the specified input data port does not exist """ if data_port_id in self._output_data_ports: if destroy: self.remove_data_flows_with_data_port_id(data_port_id) self._output_data_ports[data_port_id].parent = None return self._output_data_ports.pop(data_port_id) else: raise AttributeError("output data port with name %s does not exit", data_port_id)
python
def remove_output_data_port(self, data_port_id, force=False, destroy=True): """Remove an output data port from the state :param int data_port_id: the id of the output data port to remove :raises exceptions.AttributeError: if the specified input data port does not exist """ if data_port_id in self._output_data_ports: if destroy: self.remove_data_flows_with_data_port_id(data_port_id) self._output_data_ports[data_port_id].parent = None return self._output_data_ports.pop(data_port_id) else: raise AttributeError("output data port with name %s does not exit", data_port_id)
[ "def", "remove_output_data_port", "(", "self", ",", "data_port_id", ",", "force", "=", "False", ",", "destroy", "=", "True", ")", ":", "if", "data_port_id", "in", "self", ".", "_output_data_ports", ":", "if", "destroy", ":", "self", ".", "remove_data_flows_wit...
Remove an output data port from the state :param int data_port_id: the id of the output data port to remove :raises exceptions.AttributeError: if the specified input data port does not exist
[ "Remove", "an", "output", "data", "port", "from", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L471-L483
train
40,692
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.get_io_data_port_id_from_name_and_type
def get_io_data_port_id_from_name_and_type(self, name, data_port_type): """Returns the data_port_id of a data_port with a certain name and data port type :param name: the name of the target data_port :param data_port_type: the data port type of the target data port :return: the data port specified by the name and the type :raises exceptions.AttributeError: if the specified data port does not exist in the input or output data ports """ if data_port_type is InputDataPort: for ip_id, output_port in self.input_data_ports.items(): if output_port.name == name: return ip_id raise AttributeError("Name '{0}' is not in input_data_ports".format(name)) elif data_port_type is OutputDataPort: for op_id, output_port in self.output_data_ports.items(): if output_port.name == name: return op_id # 'error' is an automatically generated output port in case of errors and exception and doesn't have an id if name == "error": return raise AttributeError("Name '{0}' is not in output_data_ports".format(name))
python
def get_io_data_port_id_from_name_and_type(self, name, data_port_type): """Returns the data_port_id of a data_port with a certain name and data port type :param name: the name of the target data_port :param data_port_type: the data port type of the target data port :return: the data port specified by the name and the type :raises exceptions.AttributeError: if the specified data port does not exist in the input or output data ports """ if data_port_type is InputDataPort: for ip_id, output_port in self.input_data_ports.items(): if output_port.name == name: return ip_id raise AttributeError("Name '{0}' is not in input_data_ports".format(name)) elif data_port_type is OutputDataPort: for op_id, output_port in self.output_data_ports.items(): if output_port.name == name: return op_id # 'error' is an automatically generated output port in case of errors and exception and doesn't have an id if name == "error": return raise AttributeError("Name '{0}' is not in output_data_ports".format(name))
[ "def", "get_io_data_port_id_from_name_and_type", "(", "self", ",", "name", ",", "data_port_type", ")", ":", "if", "data_port_type", "is", "InputDataPort", ":", "for", "ip_id", ",", "output_port", "in", "self", ".", "input_data_ports", ".", "items", "(", ")", ":"...
Returns the data_port_id of a data_port with a certain name and data port type :param name: the name of the target data_port :param data_port_type: the data port type of the target data port :return: the data port specified by the name and the type :raises exceptions.AttributeError: if the specified data port does not exist in the input or output data ports
[ "Returns", "the", "data_port_id", "of", "a", "data_port", "with", "a", "certain", "name", "and", "data", "port", "type" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L485-L505
train
40,693
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.get_path
def get_path(self, appendix=None, by_name=False): """ Recursively create the path of the state. The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates either State.state_id (always unique) or State.name (maybe not unique but human readable) as state identifier for the path. :param str appendix: the part of the path that was already calculated by previous function calls :param bool by_name: The boolean enables name usage to generate the path :rtype: str :return: the full path to the root state """ if by_name: state_identifier = self.name else: state_identifier = self.state_id if not self.is_root_state: if appendix is None: return self.parent.get_path(state_identifier, by_name) else: return self.parent.get_path(state_identifier + PATH_SEPARATOR + appendix, by_name) else: if appendix is None: return state_identifier else: return state_identifier + PATH_SEPARATOR + appendix
python
def get_path(self, appendix=None, by_name=False): """ Recursively create the path of the state. The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates either State.state_id (always unique) or State.name (maybe not unique but human readable) as state identifier for the path. :param str appendix: the part of the path that was already calculated by previous function calls :param bool by_name: The boolean enables name usage to generate the path :rtype: str :return: the full path to the root state """ if by_name: state_identifier = self.name else: state_identifier = self.state_id if not self.is_root_state: if appendix is None: return self.parent.get_path(state_identifier, by_name) else: return self.parent.get_path(state_identifier + PATH_SEPARATOR + appendix, by_name) else: if appendix is None: return state_identifier else: return state_identifier + PATH_SEPARATOR + appendix
[ "def", "get_path", "(", "self", ",", "appendix", "=", "None", ",", "by_name", "=", "False", ")", ":", "if", "by_name", ":", "state_identifier", "=", "self", ".", "name", "else", ":", "state_identifier", "=", "self", ".", "state_id", "if", "not", "self", ...
Recursively create the path of the state. The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates either State.state_id (always unique) or State.name (maybe not unique but human readable) as state identifier for the path. :param str appendix: the part of the path that was already calculated by previous function calls :param bool by_name: The boolean enables name usage to generate the path :rtype: str :return: the full path to the root state
[ "Recursively", "create", "the", "path", "of", "the", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L527-L553
train
40,694
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.get_storage_path
def get_storage_path(self, appendix=None): """ Recursively create the storage path of the state. The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates the concatenation of (State.name and State.state_id) as state identifier for the path. :param str appendix: the part of the path that was already calculated by previous function calls :rtype: str :return: the full path to the root state """ state_identifier = storage.get_storage_id_for_state(self) if not self.is_root_state: if appendix is None: return self.parent.get_storage_path(state_identifier) else: return self.parent.get_storage_path(state_identifier + PATH_SEPARATOR + appendix) else: if appendix is None: return state_identifier else: return state_identifier + PATH_SEPARATOR + appendix
python
def get_storage_path(self, appendix=None): """ Recursively create the storage path of the state. The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates the concatenation of (State.name and State.state_id) as state identifier for the path. :param str appendix: the part of the path that was already calculated by previous function calls :rtype: str :return: the full path to the root state """ state_identifier = storage.get_storage_id_for_state(self) if not self.is_root_state: if appendix is None: return self.parent.get_storage_path(state_identifier) else: return self.parent.get_storage_path(state_identifier + PATH_SEPARATOR + appendix) else: if appendix is None: return state_identifier else: return state_identifier + PATH_SEPARATOR + appendix
[ "def", "get_storage_path", "(", "self", ",", "appendix", "=", "None", ")", ":", "state_identifier", "=", "storage", ".", "get_storage_id_for_state", "(", "self", ")", "if", "not", "self", ".", "is_root_state", ":", "if", "appendix", "is", "None", ":", "retur...
Recursively create the storage path of the state. The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates the concatenation of (State.name and State.state_id) as state identifier for the path. :param str appendix: the part of the path that was already calculated by previous function calls :rtype: str :return: the full path to the root state
[ "Recursively", "create", "the", "storage", "path", "of", "the", "state", "." ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L555-L576
train
40,695
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.get_state_machine
def get_state_machine(self): """Get a reference of the state_machine the state belongs to :rtype rafcon.core.state_machine.StateMachine :return: respective state machine """ if self.parent: if self.is_root_state: return self.parent else: return self.parent.get_state_machine() return None
python
def get_state_machine(self): """Get a reference of the state_machine the state belongs to :rtype rafcon.core.state_machine.StateMachine :return: respective state machine """ if self.parent: if self.is_root_state: return self.parent else: return self.parent.get_state_machine() return None
[ "def", "get_state_machine", "(", "self", ")", ":", "if", "self", ".", "parent", ":", "if", "self", ".", "is_root_state", ":", "return", "self", ".", "parent", "else", ":", "return", "self", ".", "parent", ".", "get_state_machine", "(", ")", "return", "No...
Get a reference of the state_machine the state belongs to :rtype rafcon.core.state_machine.StateMachine :return: respective state machine
[ "Get", "a", "reference", "of", "the", "state_machine", "the", "state", "belongs", "to" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L578-L590
train
40,696
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.file_system_path
def file_system_path(self, file_system_path): """Setter for file_system_path attribute of state :param str file_system_path: :return: """ if not isinstance(file_system_path, string_types): raise TypeError("file_system_path must be a string") self._file_system_path = file_system_path
python
def file_system_path(self, file_system_path): """Setter for file_system_path attribute of state :param str file_system_path: :return: """ if not isinstance(file_system_path, string_types): raise TypeError("file_system_path must be a string") self._file_system_path = file_system_path
[ "def", "file_system_path", "(", "self", ",", "file_system_path", ")", ":", "if", "not", "isinstance", "(", "file_system_path", ",", "string_types", ")", ":", "raise", "TypeError", "(", "\"file_system_path must be a string\"", ")", "self", ".", "_file_system_path", "...
Setter for file_system_path attribute of state :param str file_system_path: :return:
[ "Setter", "for", "file_system_path", "attribute", "of", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L605-L613
train
40,697
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.add_outcome
def add_outcome(self, name, outcome_id=None): """Add a new outcome to the state :param str name: the name of the outcome to add :param int outcome_id: the optional outcome_id of the new outcome :return: outcome_id: the outcome if of the generated state :rtype: int """ if outcome_id is None: outcome_id = generate_outcome_id(list(self.outcomes.keys())) if name in self._outcomes: logger.error("Two outcomes cannot have the same names") return if outcome_id in self.outcomes: logger.error("Two outcomes cannot have the same outcome_ids") return outcome = Outcome(outcome_id, name, self) self._outcomes[outcome_id] = outcome return outcome_id
python
def add_outcome(self, name, outcome_id=None): """Add a new outcome to the state :param str name: the name of the outcome to add :param int outcome_id: the optional outcome_id of the new outcome :return: outcome_id: the outcome if of the generated state :rtype: int """ if outcome_id is None: outcome_id = generate_outcome_id(list(self.outcomes.keys())) if name in self._outcomes: logger.error("Two outcomes cannot have the same names") return if outcome_id in self.outcomes: logger.error("Two outcomes cannot have the same outcome_ids") return outcome = Outcome(outcome_id, name, self) self._outcomes[outcome_id] = outcome return outcome_id
[ "def", "add_outcome", "(", "self", ",", "name", ",", "outcome_id", "=", "None", ")", ":", "if", "outcome_id", "is", "None", ":", "outcome_id", "=", "generate_outcome_id", "(", "list", "(", "self", ".", "outcomes", ".", "keys", "(", ")", ")", ")", "if",...
Add a new outcome to the state :param str name: the name of the outcome to add :param int outcome_id: the optional outcome_id of the new outcome :return: outcome_id: the outcome if of the generated state :rtype: int
[ "Add", "a", "new", "outcome", "to", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L624-L643
train
40,698
DLR-RM/RAFCON
source/rafcon/core/states/state.py
State.remove_outcome
def remove_outcome(self, outcome_id, force=False, destroy=True): """Remove an outcome from the state :param int outcome_id: the id of the outcome to remove :raises exceptions.AttributeError: if the specified outcome does not exist or equals the aborted or preempted outcome """ if outcome_id not in self.outcomes: raise AttributeError("There is no outcome_id %s" % str(outcome_id)) if not force: if outcome_id == -1 or outcome_id == -2: raise AttributeError("You cannot remove the outcomes with id -1 or -2 as a state must always be able" "to return aborted or preempted") # Remove internal transitions to this outcome self.remove_outcome_hook(outcome_id) # delete possible transition connected to this outcome if destroy and not self.is_root_state: for transition_id, transition in self.parent.transitions.items(): if transition.from_outcome == outcome_id and transition.from_state == self.state_id: self.parent.remove_transition(transition_id) break # found the one outgoing transition # delete outcome it self self._outcomes[outcome_id].parent = None return self._outcomes.pop(outcome_id)
python
def remove_outcome(self, outcome_id, force=False, destroy=True): """Remove an outcome from the state :param int outcome_id: the id of the outcome to remove :raises exceptions.AttributeError: if the specified outcome does not exist or equals the aborted or preempted outcome """ if outcome_id not in self.outcomes: raise AttributeError("There is no outcome_id %s" % str(outcome_id)) if not force: if outcome_id == -1 or outcome_id == -2: raise AttributeError("You cannot remove the outcomes with id -1 or -2 as a state must always be able" "to return aborted or preempted") # Remove internal transitions to this outcome self.remove_outcome_hook(outcome_id) # delete possible transition connected to this outcome if destroy and not self.is_root_state: for transition_id, transition in self.parent.transitions.items(): if transition.from_outcome == outcome_id and transition.from_state == self.state_id: self.parent.remove_transition(transition_id) break # found the one outgoing transition # delete outcome it self self._outcomes[outcome_id].parent = None return self._outcomes.pop(outcome_id)
[ "def", "remove_outcome", "(", "self", ",", "outcome_id", ",", "force", "=", "False", ",", "destroy", "=", "True", ")", ":", "if", "outcome_id", "not", "in", "self", ".", "outcomes", ":", "raise", "AttributeError", "(", "\"There is no outcome_id %s\"", "%", "...
Remove an outcome from the state :param int outcome_id: the id of the outcome to remove :raises exceptions.AttributeError: if the specified outcome does not exist or equals the aborted or preempted outcome
[ "Remove", "an", "outcome", "from", "the", "state" ]
24942ef1a904531f49ab8830a1dbb604441be498
https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/states/state.py#L676-L702
train
40,699