Ejemplo n.º 1
0
    def on_show_outputs_change(self):
        print('in on_show_outputs_change')
        show_outs_str = self.get_grid_val('show_outputs')
        show_outs_bool = xml_utils.str_to_bool(show_outs_str)
        if show_outs_bool:
            self.append_rows_if_missing(output_opts)
            #try to determine sensible defaults
            #
            # ? how do I determine info about the active block?
            #
            # output_opts = ['show_output_arrows','output_distances','output_angles']
            output_str = self.get_grid_val('sensors')
            show_arrows = [True]
            out_distances = [1.0]
            out_angles = [0]
            out_labels = ['']

            if output_str:
                my_outputs = xml_utils.full_clean(output_str)
                if type(my_outputs) == list:
                    num_out = len(my_outputs)
                    show_arrows = [True]*num_out
                    out_distances = [1.0]*num_out
                    out_labels = ['']*num_out
                    if num_out == 1:
                        out_angles = [0]
                    elif num_out == 2:
                        out_angles = [-30,30]
                    elif num_out == 3:
                        out_angles = [-45,0,45]
                    elif num_out == 4:
                        out_angles =[-45, -15, 15, 45]

            self.set_grid_val('output_angles', out_angles)
            self.set_grid_val('output_distances', out_distances)
            self.set_grid_val('show_output_arrows', show_arrows)
            self.set_grid_val('output_labels', out_labels)
        else:
            self.delete_grid_rows(output_opts)
    def on_show_outputs_change(self):
        print('in on_show_outputs_change')
        show_outs_str = self.get_grid_val('show_outputs')
        show_outs_bool = xml_utils.str_to_bool(show_outs_str)
        if show_outs_bool:
            self.append_rows_if_missing(output_opts)
            #try to determine sensible defaults
            #
            # ? how do I determine info about the active block?
            #
            # output_opts = ['show_output_arrows','output_distances','output_angles']
            output_str = self.get_grid_val('sensors')
            show_arrows = [True]
            out_distances = [1.0]
            out_angles = [0]
            out_labels = ['']

            if output_str:
                my_outputs = xml_utils.full_clean(output_str)
                if type(my_outputs) == list:
                    num_out = len(my_outputs)
                    show_arrows = [True] * num_out
                    out_distances = [1.0] * num_out
                    out_labels = [''] * num_out
                    if num_out == 1:
                        out_angles = [0]
                    elif num_out == 2:
                        out_angles = [-30, 30]
                    elif num_out == 3:
                        out_angles = [-45, 0, 45]
                    elif num_out == 4:
                        out_angles = [-45, -15, 15, 45]

            self.set_grid_val('output_angles', out_angles)
            self.set_grid_val('output_distances', out_distances)
            self.set_grid_val('show_output_arrows', show_arrows)
            self.set_grid_val('output_labels', out_labels)
        else:
            self.delete_grid_rows(output_opts)
    def create_output_lines(self):
        mylines = ['%output lines/arrows']
        out = mylines.append

        for block in self.bd_parent.blocklist:
            if block.params.has_key('show_outputs'):
                show_outputs = block.params['show_outputs']
                if type(show_outputs) == str:
                    show_outputs = xml_utils.str_to_bool(show_outputs)

                if show_outputs:
                    output_nodes = []
                    # define the output node near the block
                    # define the output node iteself (eventually need to care about direction, I think)
                    #  ? can I get direction out of output angle ?
                    # define the arrow tip node if necessary
                    # draw the output line
                    # draw the output arrow
                    # add the label if given

                    #\node [output] at (serial_plant.-30) (output0) {};
                    basename = block.name
                    num_outputs = block.get_num_outputs()

                    startline = '\\node [output] at (%s.%0.4g) (%s) {};'
                    outline = '\\node [emptynode, %s=%s, node distance=%0.4gcm] (%s) {};'
                    arrowline = '\\draw [->] (%s) -- (%s);'
                    nonarrowline = '\\draw [-] (%s) -- (%s);'
                    labelline = '\\node [mylabel, above of=%s, node distance=0cm] (%s) {%s};'


                    #\node [myarrow, right of=output0, emptynode, node distance=1cm] (serial_plant_out0) {};
                    for i in range(num_outputs):
                        startname = basename + '_out%i_start' % i
                        curangle = float(block.params['output_angles'][i])
                        outputname = basename + '_out%i' % i
                        out(startline % (basename, curangle, startname))
                        if abs(curangle) < 95.0 or curangle > 265.0:
                            direction = 'right of'
                        else:
                            direction = 'left of'

                        curdistance = float(block.params['output_distances'][i])
                        out(outline % (direction, startname, curdistance, outputname))

                        show_arrow = xml_utils.str_to_bool(block.params['show_output_arrows'][i])
                        if show_arrow:
                            arrowname = basename + '_out%i_arrow' % i
                            arrowdist = 0.7# bad, bad hard coding
                            out(outline % (direction, outputname, arrowdist, arrowname))
                            out(arrowline % (startname, arrowname))
                        else:
                            out(nonarrowline % (startname, outputname))

                        curlabel = block.params['output_labels'][i]
                        if curlabel:
                            labelname = basename + '_out%i_label' % i
                            out(labelline % (outputname, labelname, curlabel))

                        output_nodes.append(outputname)

                    block.output_nodes = output_nodes

        return mylines