Example #1
0
 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)
Example #2
0
    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)
Example #3
0
 def __find_selector(self, sm, selector, log):
     # Look for the FSM selector in all the state nodes of the FSM
     state_paths = fsm.get_states( sm.getfullname() )
     for state_path in state_paths:
         state = pynebula.lookup( state_path )
         if state.isa('nnodestate'):
             if state.getfsmselector() == selector:
                 log.append( [
                     sm.getname(),
                     fsmstates.get_state_gui_name( state_path )
                     ] )
Example #4
0
    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)
Example #5
0
 def __find_action(self, sm, action_script, log):
     # Look for the action script in all the leaf nodes of the FSM
     state_paths = fsm.get_states( sm.getfullname() )
     for state_path in state_paths:
         state = pynebula.lookup( state_path )
         if state.isa('nleafstate'):
             action = state.getbehaviouralaction()
             if action.getactiontype() == 999:
                 action.rewindargs()
                 if action.getstringarg() == action_script.getname():
                     log.append( [
                         sm.getname(),
                         fsmstates.get_state_gui_name( state_path )
                         ] )
Example #6
0
def get_free_targets(transition, allowed_target=None):
    """
    Return a paths list of those states which the given transition doesn't
    already have a target for.
    
    \param transition Transition (path) to gather the free targets for
    \param allowed_target Target state (path) allowed as a free target, even if it's already taken
    \return List of states paths not found as targets for the given transition
    """
    fsm_path = fsm.get_fsm_of_transition(transition)
    states_paths = fsm.get_states(fsm_path)
    trans_obj = pynebula.lookup(transition)
    for i in range(trans_obj.gettargetsnumber()):
        state_path = trans_obj.gettargetstatebyindex(i).getfullname()
        if allowed_target != state_path:
            states_paths.remove(state_path)
    return states_paths
Example #7
0
def get_free_targets(transition, allowed_target=None):
    """
    Return a paths list of those states which the given transition doesn't
    already have a target for.
    
    \param transition Transition (path) to gather the free targets for
    \param allowed_target Target state (path) allowed as a free target, even if it's already taken
    \return List of states paths not found as targets for the given transition
    """
    fsm_path = fsm.get_fsm_of_transition( transition )
    states_paths = fsm.get_states( fsm_path )
    trans_obj = pynebula.lookup( transition )
    for i in range( trans_obj.gettargetsnumber() ):
        state_path = trans_obj.gettargetstatebyindex(i).getfullname()
        if allowed_target != state_path:
            states_paths.remove( state_path )
    return states_paths
Example #8
0
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)
Example #9
0
 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 )
                         ] )
Example #10
0
def find_fsm_selector(selector_class):
    columns = ['FSM', 'State']
    rows = []
    
    # Look for the selector in all the FSMs
    fsm_paths = fsm.get_fsms()
    for fsm_path in fsm_paths:
        state_mc = pynebula.lookup( fsm_path )
        
        # Look for the selector in all the state nodes of the FSM
        state_paths = fsm.get_states( state_mc.getfullname() )
        for state_path in state_paths:
            state = pynebula.lookup( state_path )
            if state.isa('nnodestate'):
                selector = state.getfsmselector()
                if selector.isa( str(selector_class) ):
                    rows.append( [
                        state_mc.getname(),
                        fsmstates.get_state_gui_name( state_path )
                        ] )
    
    return (columns, rows)
Example #11
0
def find_behaviour_action(action_class):
    columns = ['FSM', 'State']
    rows = []
    
    # Look for the action in all the FSMs
    fsm_paths = fsm.get_fsms()
    for fsm_path in fsm_paths:
        state_mc = pynebula.lookup( fsm_path )
        
        # Look for the action in all the leaf nodes of the FSM
        state_paths = fsm.get_states( state_mc.getfullname() )
        for state_path in state_paths:
            state = pynebula.lookup( state_path )
            if state.isa('nleafstate'):
                action = state.getbehaviouralaction()
                if action.getactionclass() == action_class:
                    rows.append( [
                        state_mc.getname(),
                        fsmstates.get_state_gui_name( state_path )
                        ] )
    
    return (columns, rows)