def __on_change_type(self, event): if self.state_path != None and not self.skip_change_type_event: # Rename the old state to keep it while building the new one old_state = self.__get_state() old_state.setname('_tmp') # Create new state for the new state type if self.GetSelection() == self.ID_NodeStatePanel: new_state = create_default_state(self.state_path, 'nnodestate') elif self.GetSelection() == self.ID_LeafStatePanel: new_state = create_default_state(self.state_path, 'nleafstate') else: new_state = create_default_state(self.state_path, 'nendstate') if new_state == None: # If creating a default state fails abort and restore old state old_state.setname(str(format.get_name(self.state_path))) self.skip_change_type_event = True self.SetSelection(event.GetOldSelection()) self.skip_change_type_event = False return fsm_ = self.__get_fsm() fsm_.addstate(new_state) # Copy info that's independent of the state type old_trans_path = fsm.get_transitions_dir_of_state( old_state.getfullname()) new_trans_path = fsm.get_transitions_dir_of_state( new_state.getfullname(), False) pynebula.lookup(str(old_trans_path)).clone(str(new_trans_path)) transitions = fsm.get_transitions(new_state.getfullname()) for t in transitions: t_obj = pynebula.lookup(t) new_state.addtransition(t_obj) if fsm_.getinitialstate() == old_state: fsm_.setinitialstate(new_state) # Update all transitions to point to the new state if pointing the old one states = fsm.get_states(fsm_.getfullname()) for s in states: transitions = fsm.get_transitions(s) for t in transitions: t_obj = pynebula.lookup(t) for i in range(t_obj.gettargetsnumber()): if t_obj.gettargetstatebyindex(i) == old_state: t_obj.settargetstatebyindex(i, new_state) # Delete old state fsm_.deletestate(old_state) old_state = None # Python, release that #$%&/)?! reference NOW! # Update type specific controls self.__update_controls() # Signal change fsmevents.signal_fsm_change(self, self.state_path)
def __on_change_type(self, event): if self.state_path != None and not self.skip_change_type_event: # Rename the old state to keep it while building the new one old_state = self.__get_state() old_state.setname("_tmp") # Create new state for the new state type if self.GetSelection() == self.ID_NodeStatePanel: new_state = create_default_state(self.state_path, "nnodestate") elif self.GetSelection() == self.ID_LeafStatePanel: new_state = create_default_state(self.state_path, "nleafstate") else: new_state = create_default_state(self.state_path, "nendstate") if new_state == None: # If creating a default state fails abort and restore old state old_state.setname(str(format.get_name(self.state_path))) self.skip_change_type_event = True self.SetSelection(event.GetOldSelection()) self.skip_change_type_event = False return fsm_ = self.__get_fsm() fsm_.addstate(new_state) # Copy info that's independent of the state type old_trans_path = fsm.get_transitions_dir_of_state(old_state.getfullname()) new_trans_path = fsm.get_transitions_dir_of_state(new_state.getfullname(), False) pynebula.lookup(str(old_trans_path)).clone(str(new_trans_path)) transitions = fsm.get_transitions(new_state.getfullname()) for t in transitions: t_obj = pynebula.lookup(t) new_state.addtransition(t_obj) if fsm_.getinitialstate() == old_state: fsm_.setinitialstate(new_state) # Update all transitions to point to the new state if pointing the old one states = fsm.get_states(fsm_.getfullname()) for s in states: transitions = fsm.get_transitions(s) for t in transitions: t_obj = pynebula.lookup(t) for i in range(t_obj.gettargetsnumber()): if t_obj.gettargetstatebyindex(i) == old_state: t_obj.settargetstatebyindex(i, new_state) # Delete old state fsm_.deletestate(old_state) old_state = None # Python, release that #$%&/)?! reference NOW! # Update type specific controls self.__update_controls() # Signal change fsmevents.signal_fsm_change(self, self.state_path)
def __on_delete_state(self, event): """Ask to confirm the state deletion and delete it if so""" state_name = self.list_states.GetStringSelection() if state_name != "": msg = "Deleting a state cannot be undone.\n" msg = msg + "Are you sure that you want to delete the " msg = msg + "'" + state_name + "' state?" result = cjr.warn_yes_no(self, msg) if result == wx.ID_YES: # Delete all transition targets pointing to the state to be deleted state = self.__get_current_state() fsm_ = fsm.get_fsm_of_state( state.getfullname() ) states = fsm.get_states( fsm_ ) for s in states: transitions = fsm.get_transitions(s) for t in transitions: t_obj = pynebula.lookup(t) t_obj.removetarget(state) # Delete the transition if it's emmpty after deleting the target if t_obj.gettargetsnumber() == 0: s_obj = pynebula.lookup(s) s_obj.deletetransition(t_obj) t_obj = None # Delete the state self.__get_fsm().deletestate( state ) state = None self.list_states.Delete( self.list_states.GetSelection() ) self.__on_select_state(None) fsmevents.signal_fsm_change(self)
def get_free_event_conditions(state, allowed_condition=None): """ Return a paths list of those event conditions which the given state doesn't already have a transition for. \param state State (path) to gather the free event conditions for \param allowed_condition Condition (path) allowed as a free condition, even if it's already taken \return List of event conditions paths not found in any transition of the given state """ allowed_event = None if allowed_condition != None: cond = pynebula.lookup(allowed_condition) if cond.isa('neventcondition'): allowed_event = cond.getevent() conds_paths = fsm.get_event_conditions() ## conds_paths = [] ## cond = pynebula.lookup( fsm.get_event_conditions_lib() ).gethead() ## while cond is not None: ## if cond.getname().startswith( "event" ): ## conds_paths.append( cond.getfullname() ) ## cond = cond.getsucc() trans_paths = fsm.get_transitions(state) for trans_path in trans_paths: trans_obj = pynebula.lookup(trans_path) cond_obj = trans_obj.getcondition() if cond_obj.isa('neventcondition'): if cond_obj.getevent() != allowed_event: cond_path = get_event_condition(cond_obj.getevent()) ## if cond_path == fsm.get_filteredcondition_of_transition( trans_path ): ## conds_paths.remove( get_event_condition( cond_obj.getevent() ) ) ## else: conds_paths.remove(cond_path) return conds_paths
def get_free_event_conditions(state, allowed_condition=None): """ Return a paths list of those event conditions which the given state doesn't already have a transition for. \param state State (path) to gather the free event conditions for \param allowed_condition Condition (path) allowed as a free condition, even if it's already taken \return List of event conditions paths not found in any transition of the given state """ allowed_event = None if allowed_condition != None: cond = pynebula.lookup( allowed_condition ) if cond.isa('neventcondition'): allowed_event = cond.getevent() conds_paths = fsm.get_event_conditions() ## conds_paths = [] ## cond = pynebula.lookup( fsm.get_event_conditions_lib() ).gethead() ## while cond is not None: ## if cond.getname().startswith( "event" ): ## conds_paths.append( cond.getfullname() ) ## cond = cond.getsucc() trans_paths = fsm.get_transitions( state ) for trans_path in trans_paths: trans_obj = pynebula.lookup( trans_path ) cond_obj = trans_obj.getcondition() if cond_obj.isa('neventcondition'): if cond_obj.getevent() != allowed_event: cond_path = get_event_condition( cond_obj.getevent() ) ## if cond_path == fsm.get_filteredcondition_of_transition( trans_path ): ## conds_paths.remove( get_event_condition( cond_obj.getevent() ) ) ## else: conds_paths.remove( cond_path ) return conds_paths
def get_free_script_conditions(state, allowed_condition=None): """ Return a paths list of those script conditions which the given state doesn't already have a transition for. \param state State (path) to gather the free script conditions for \param allowed_condition Condition (path) allowed as a free condition, even if it's already taken \return List of script conditions paths not found in any transition of the given state """ conds_paths = fsm.get_script_conditions() trans_paths = fsm.get_transitions(state) for trans_path in trans_paths: trans_obj = pynebula.lookup(trans_path) cond_obj = trans_obj.getcondition() cond_path = cond_obj.getfullname() if cond_obj.isa('nscriptcondition') and cond_path != allowed_condition: conds_paths.remove(cond_path) return conds_paths
def get_free_script_conditions(state, allowed_condition=None): """ Return a paths list of those script conditions which the given state doesn't already have a transition for. \param state State (path) to gather the free script conditions for \param allowed_condition Condition (path) allowed as a free condition, even if it's already taken \return List of script conditions paths not found in any transition of the given state """ conds_paths = fsm.get_script_conditions() trans_paths = fsm.get_transitions( state ) for trans_path in trans_paths: trans_obj = pynebula.lookup( trans_path ) cond_obj = trans_obj.getcondition() cond_path = cond_obj.getfullname() if cond_obj.isa('nscriptcondition') and cond_path != allowed_condition: conds_paths.remove( cond_path ) return conds_paths
def find_transition_condition(condition_class): columns = ['FSM', 'State', 'Transition'] rows = [] # Look for the condition in all the FSMs fsm_paths = fsm.get_fsms() for fsm_path in fsm_paths: state_mc = pynebula.lookup( fsm_path ) # Look for the condition in all the script transitions of # the FSM (and event filters) state_paths = fsm.get_states( state_mc.getfullname() ) for state_path in state_paths: trans_paths = fsm.get_transitions( state_path ) for trans_path in trans_paths: trans = pynebula.lookup( trans_path ) trans_cond = trans.getcondition() if trans_cond.isa( str(condition_class) ): rows.append( [ state_mc.getname(), fsmstates.get_state_gui_name( state_path ), fsmtransitions.get_transition_gui_name( trans_path ) ] ) elif trans_cond.isa('neventcondition'): filter_cond = trans_cond.getfiltercondition() if filter_cond is not None: if filter_cond.isa( str(condition_class) ): rows.append( [ state_mc.getname(), fsmstates.get_state_gui_name( state_path ), fsmtransitions.get_transition_gui_name( trans_path ) ] ) return (columns, rows)
def __find_condition(self, sm, condition, log): # Look for the condition in all the script transitions of the FSM (and event filters) state_paths = fsm.get_states( sm.getfullname() ) for state_path in state_paths: trans_paths = fsm.get_transitions( state_path ) for trans_path in trans_paths: trans = pynebula.lookup( trans_path ) trans_cond = trans.getcondition() if condition == trans_cond: log.append( [ sm.getname(), fsmstates.get_state_gui_name( state_path ), fsmtransitions.get_transition_gui_name( trans_path ) ] ) elif trans_cond.isa('neventcondition'): if condition == trans_cond.getfiltercondition(): log.append( [ sm.getname(), fsmstates.get_state_gui_name( state_path ), fsmtransitions.get_transition_gui_name( trans_path ) ] )