Esempio n. 1
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)
Esempio n. 2
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 )
                         ] )
Esempio n. 3
0
    def __generate_dot_file(self):
        # Begin
        dot_file = open( self.dot_path, 'w' )
        dot_file.write( 'digraph G {\n' )
        
        # States
        fsm = pynebula.lookup( self.fsm_path )
        initial_state = fsm.getinitialstate()
        state = fsm.gethead()
        while state is not None:
            line = '    ' + state.getname()
            label = fsmstates.get_state_gui_name( state.getfullname() )
            line = line + ' [label="' + label + '"'
            line = line + ' , URL="state:' + state.getfullname() + '"'
            if state.isa('nnodestate'):
                line = line + ', style=dashed'
            elif state.isa('nendstate'):
                line = line + ', peripheries=2'
            else:
                line = line + ', style=solid'
            if state == initial_state:
                line = line + ', shape=box'
            line = line + '];\n'
            dot_file.write(line)
            
            # State transitions
            try:
                transition = pynebula.lookup( str(state.getfullname() +
                    "/transitions") ).gethead()
            except:
                transition = None
            while transition is not None:
                condition = transition.getcondition()
                for i in range( transition.gettargetsnumber() ):
                    line = '    ' + state.getname() + ' -> '
                    line = line + transition.gettargetstatebyindex(i).getname()
                    probability = transition.gettargetprobabilitybyindex(i)
                    label = fsmtransitions.get_transition_gui_name( transition.getfullname() ).split(' ',1)[1]
                    if probability != 100:
                        label = label + '\\n(' + str(probability) + '%)'
                    line = line + ' [label="' + label + '"'
                    line = line + ' URL="transition:' + transition.getfullname()
                    line = line + '/' + str(i) + '"'
                    if condition.isa('nscriptcondition'):
                        line = line + ', arrowhead=onormal'
                    if probability != 100:
                        line = line + ', style=dotted'
                    line = line + '];\n'
                    dot_file.write(line)
                transition = transition.getsucc()
            
            state = state.getsucc()
##        dot_file.write( '    B [label="Attack", style=dashed];\n' )
##        dot_file.write( '    A -> B [label="True", arrowhead=onormal];\n' )
##        dot_file.write( '    B -> A [label="Done"];\n' )
##        dot_file.write( '    \n' )
##        dot_file.write( '    C [label="Shoot", style=bold]\n' );
##        dot_file.write( '    D [label="End shooting", peripheries=2];\n' )
##        dot_file.write( '    C -> D [label="True", arrowhead=onormal];\n' )
        
        # End
        dot_file.write( '}\n' )
        dot_file.close()
Esempio n. 4
0
    def __generate_dot_file(self):
        # Begin
        dot_file = open(self.dot_path, 'w')
        dot_file.write('digraph G {\n')

        # States
        fsm = pynebula.lookup(self.fsm_path)
        initial_state = fsm.getinitialstate()
        state = fsm.gethead()
        while state is not None:
            line = '    ' + state.getname()
            label = fsmstates.get_state_gui_name(state.getfullname())
            line = line + ' [label="' + label + '"'
            line = line + ' , URL="state:' + state.getfullname() + '"'
            if state.isa('nnodestate'):
                line = line + ', style=dashed'
            elif state.isa('nendstate'):
                line = line + ', peripheries=2'
            else:
                line = line + ', style=solid'
            if state == initial_state:
                line = line + ', shape=box'
            line = line + '];\n'
            dot_file.write(line)

            # State transitions
            try:
                transition = pynebula.lookup(
                    str(state.getfullname() + "/transitions")).gethead()
            except:
                transition = None
            while transition is not None:
                condition = transition.getcondition()
                for i in range(transition.gettargetsnumber()):
                    line = '    ' + state.getname() + ' -> '
                    line = line + transition.gettargetstatebyindex(i).getname()
                    probability = transition.gettargetprobabilitybyindex(i)
                    label = fsmtransitions.get_transition_gui_name(
                        transition.getfullname()).split(' ', 1)[1]
                    if probability != 100:
                        label = label + '\\n(' + str(probability) + '%)'
                    line = line + ' [label="' + label + '"'
                    line = line + ' URL="transition:' + transition.getfullname(
                    )
                    line = line + '/' + str(i) + '"'
                    if condition.isa('nscriptcondition'):
                        line = line + ', arrowhead=onormal'
                    if probability != 100:
                        line = line + ', style=dotted'
                    line = line + '];\n'
                    dot_file.write(line)
                transition = transition.getsucc()

            state = state.getsucc()
##        dot_file.write( '    B [label="Attack", style=dashed];\n' )
##        dot_file.write( '    A -> B [label="True", arrowhead=onormal];\n' )
##        dot_file.write( '    B -> A [label="Done"];\n' )
##        dot_file.write( '    \n' )
##        dot_file.write( '    C [label="Shoot", style=bold]\n' );
##        dot_file.write( '    D [label="End shooting", peripheries=2];\n' )
##        dot_file.write( '    C -> D [label="True", arrowhead=onormal];\n' )

# End
        dot_file.write('}\n')
        dot_file.close()