示例#1
0
 def __save_fsms(self, caption):
     msg = "Deleting a %s will save any modified " \
                 "finite state machine.\n\n" \
                 "Continue anyway?" % caption
     result = cjr.confirm_yes_no(self, msg)
     delete = (result == wx.ID_YES)
     if delete:
         # Save modified FSMs
         fsm_paths = fsm.get_fsms()
         for fsm_path in fsm_paths:
             state_machine = pynebula.lookup(fsm_path)
             if state_machine.isdirty():
                 servers.get_fsm_server().savefsm(state_machine)
                 state_machine.setdirty(False)
                 app.get_top_window().emit_app_event(
                     events.FSMSaved(fsm_path))
     return delete
示例#2
0
 def _save_fsms(self):
     msg = "Deleting a %s will save any modified finite state machine.\n\n" % self.caption
     msg = msg + "Continue anyway?"
     result = cjr.confirm_yes_no(self, msg)
     delete = (result == wx.ID_YES)
     if delete:
         # Save modified FSMs
         fsm_paths = fsm.get_fsms()
         for fsm_path in fsm_paths:
             sm = pynebula.lookup( fsm_path )
             if sm.isdirty():
                 servers.get_fsm_server().savefsm( sm )
                 sm.setdirty( False )
                 app.get_top_window(self).emit_app_event(
                     events.FSMSaved( fsm_path )
                     )
     return delete
示例#3
0
 def __update_attach_ctrls(self):
     # Update FSM choicer
     type = self.__get_selected_list_item( self.ID_AgentType )
     self.choice_fsm.Enable( type != "" )
     if type != "":
         # Fill choice with all available FSMs
         self.choice_fsm.Clear()
         self.choice_fsm.Append("<none>")
         fsm_paths = fsm.get_fsms()
         for fsm_path in fsm_paths:
             fsm_name = format.get_name( fsm_path )
             self.choice_fsm.Append( fsm_name )
         # Select current FSM
         entity_class = servers.get_entity_class_server().getentityclass( str(type) )
         current_fsm = entity_class.getparentfsm()
         if current_fsm == None:
             self.choice_fsm.SetStringSelection("<none>")
         else:
             self.choice_fsm.SetStringSelection( current_fsm.getname() )
示例#4
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)
示例#5
0
 def __update_attach_ctrls(self):
     # Update FSM choicer
     type = self.__get_selected_list_item(self.ID_AgentType)
     self.choice_fsm.Enable(type != "")
     if type != "":
         # Fill choice with all available FSMs
         self.choice_fsm.Clear()
         self.choice_fsm.Append("<none>")
         fsm_paths = fsm.get_fsms()
         for fsm_path in fsm_paths:
             fsm_name = format.get_name(fsm_path)
             self.choice_fsm.Append(fsm_name)
         # Select current FSM
         entity_class = servers.get_entity_class_server().getentityclass(
             str(type))
         current_fsm = entity_class.getparentfsm()
         if current_fsm == None:
             self.choice_fsm.SetStringSelection("<none>")
         else:
             self.choice_fsm.SetStringSelection(current_fsm.getname())
示例#6
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)
示例#7
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)
示例#8
0
 def erase_object(self, action_script):
     # Forbid deleting the script if some FSM references it
     log = []
     fsm_paths = fsm.get_fsms()
     for fsm_path in fsm_paths:
         self.__find_action( pynebula.lookup(fsm_path), action_script, log )
     if len(log) > 0:
         dlg = DeleteErrorDialog(
             self.GetParent(),
             "action script '%s'" % action_script.getname(),
             ['FSM', 'State'],
             log
             )
         dlg.Show()
         return False
     # Save FSMs to avoid inconsistences between memory and persisted states
     # (and make the previous check valid)
     if not self._save_fsms():
         return
     # Delete the script
     servers.get_fsm_server().eraseactionscript( action_script )
     return True