def add_element(x_min,y_min,x_max,y_max,name,accuracy="100%"):
    '''
    description : add element of label(name), defined by 2 points
    draw the rectangle on the image based on p1 and p2
    add this element to xml file

    :param x_min: point 1 xmin
    :param y_min: point 1 ymin
    :param x_max: point 2 xmax
    :param y_max: point 2 ymax
    :param name: label name
    :param accuracy: accuracy optional
    :return: text "added +" the name of the label
    '''
    # adding this anchor
    if str(name)=="incline arrow":
        if x_min>x_max:
            x_min,x_max=x_max,x_min
            y_min,y_max=y_max,y_min


    object_file.all_objects_as_dic[str(name)].append(object_file.DC.Data(str(name),str(x_min),str(y_min),str(x_max),str(y_max),str(accuracy),object_file.object_id))
    #update the object id
    object_file.object_id=object_file.object_id+1
    update_image()
    return log_config.start_of_log()+"added "+ name+log_config.end_of_log()
Ejemplo n.º 2
0
def predict_main(input_path):
    '''
    description : this function is main function, the GUI call it and it's predict the anchors and draw on the image
    :param input_path: the image input path, text(str)
    :return: string "predict"
    '''
    image_path = input_path
    _main_(image_path,object_file.model_1,object_file.model_2,object_file.model_3,object_file.model_4,object_file.model_5) # call the main
    #=====================================================================#
    image_operations.update_image()
    #---------------------------------------------------------------------#
    return log_config.start_of_log()+"predict done"+log_config.end_of_log()
Ejemplo n.º 3
0
def remove_element(remove_header,remove_element):
    '''
    description : remove element from a given header, taking it's header name and the element type

    :param remove_header : the name of the dictionary key, string
    :param remove_element: the element to remove from the dictionary
    :return: text " removed "+ the element that was removed
    '''

    element_name=remove_element.get_name()
    object_file.all_objects_as_dic[remove_header].remove(remove_element)  # remove this anchor from my anchor dictionary

    update_image()

    return log_config.start_of_log()+"removed " + element_name+log_config.end_of_log()
def predict_main(input_path):
    '''
    description : this function is main function, the GUI call it and it's predict the anchors and draw on the image
    :param input_path: the image input path, text(str)
    :return: string "predict"
    '''
    image_path = input_path
    _main_(image_path, object_file.model_1, object_file.model_2,
           object_file.model_3, object_file.model_4,
           object_file.model_5)  # call the main
    #=====================================================================#
    #image_operations.set_anchors_to_display_image_1600_1200()
    clean_straight_arrow_with_other_arrows_or_state()
    clean_incline_arrow_with_state()
    image_operations.update_image()
    #---------------------------------------------------------------------#
    return log_config.start_of_log() + "predict done" + log_config.end_of_log()
Ejemplo n.º 5
0
            set_inputpath_and_image(image,image_path)#get the input image path as array removing the image name.type
            #=====================================================================#
#======================================================================================================================#
def predict_main(input_path):
    '''
    description : this function is main function, the GUI call it and it's predict the anchors and draw on the image
    :param input_path: the image input path, text(str)
    :return: string "predict"
    '''
    image_path = input_path
    _main_(image_path,object_file.model_1,object_file.model_2,object_file.model_3,object_file.model_4,object_file.model_5) # call the main
    #=====================================================================#
    image_operations.update_image()
    #---------------------------------------------------------------------#
    return log_config.start_of_log()+"predict done"+log_config.end_of_log()
#======================================================================================================================#
if __name__ == '__main__':
    reset_object_file()
    first_step_config()

    print(log_config.start_of_log(),log_config.start_up_log())
    print(predict_main("test.png"))
    xml_creator.xml_output_path("test.xml")
    image_operations.set_output_path("predicted.png")
    image_operations.export_image()
    matching.connect_anchors()
    passed, text, img =matching.connect_transactions()
    print(text)
    transactionToVerilog.transactionToVerilog("Moudel_0",object_file.transaction)

def transactionToVerilog(moduleName="Module_0", listOfTransactions=[]):
    if object_file.valid_verilog:
        # listOfTransactions element[0]={"src_id":value , "dst_id":value , "input":value , "output": value}
        states = []

        for transaction in listOfTransactions:
            tempSrc = 0
            tempDst = 0
            srcExist = False
            dstExist = False

            for index, state in enumerate(states):
                if state.state_id == transaction["src_id"]:
                    tempSrc = index
                    srcExist = True
                    break
            if srcExist == False:
                tempSrc = len(states)
                states.append(Node(transaction["src_id"]))

            for index, state in enumerate(states):
                if state.state_id == transaction["dst_id"]:
                    tempDst = index
                    dstExist = True
                    break
            if dstExist == False:
                tempDst = len(states)
                states.append(Node(transaction["dst_id"]))

            stateCndtn = (transaction["input"], transaction["output"])

            states[tempSrc].state_conditions.append(stateCndtn)
            states[tempSrc].connected_nodes.append(states[tempDst].state_id)

            if tempDst == tempSrc:
                states[tempSrc].connected_nodes_type.append(conn_node_types.LoopBack)

            else:
                states[tempSrc].connected_nodes_type.append(conn_node_types.Destination)

                states[tempDst].state_conditions.append(stateCndtn)
                states[tempDst].connected_nodes.append(states[tempSrc].state_id)
                states[tempDst].connected_nodes_type.append(conn_node_types.Source)

        ##########################Output verilog file########################

        output_file = 'module ' + moduleName + '( clk , INPUT , OUTPUT );\n'
        output_file = output_file + 'parameter\n'
        i = 0
        for state in states:
            output_file = output_file + ' \tstate_' + state.state_id + ' = ' + str(i) + ' ,\n '
            i = i + 1
        output_file = output_file.rstrip(' ,\n ')
        output_file = output_file + ' ;\n'
        output_file = output_file + 'input\n\tclk;\ninput '

        if not len(states[0].state_conditions[0][0]) == 1:
            output_file = output_file + '[' + str(len(states[0].state_conditions[0][0]) - 1) + ':0]'
        output_file = output_file + 'INPUT;\n'

        output_file = output_file + 'output reg\t'
        if not len(states[0].state_conditions[0][1]) == 1:
            output_file = output_file + '[' + str(len(states[0].state_conditions[0][1]) - 1) + ':0]'
        output_file = output_file + ' OUTPUT;'

        output_file = output_file + ' reg state;\n'
        output_file = output_file + '\n initial\t state = state_' + str(states[0].state_id) + ';\n'
        output_file = output_file + '\n always@ (posedge clk)\n'
        output_file = output_file + '\n case(state)\n'
        for state in states:
            output_file = output_file + '\tstate_' + str(state.state_id) + ':\n'
            output_file = output_file + '\tbegin\n'
            for index, dest in enumerate(state.connected_nodes):
                if not state.connected_nodes_type[index] == conn_node_types.Source:
                    output_file = output_file + '\t\tif(INPUT == '
                    output_file = output_file + str(len(state.state_conditions[index][0])) + "'b" + str(state.state_conditions[index][0])
                    output_file = output_file + ')\n'
                    output_file = output_file + '\t\tbegin\n'
                    output_file = output_file + '\t\t\tOUTPUT = ' + str(len(state.state_conditions[index][1])) + "'b" + str(state.state_conditions[index][1])
                    output_file = output_file + ";\n\t\t\tstate = state_" + str(dest) + ';\n'
                    output_file = output_file + '\t\tend\n'
            output_file = output_file + '\tend\n\n'
        output_file = output_file + ' endcase\nendmodule\n'

        output_file_v=open('Verilog_code.v',"w")
        output_file_v.write(output_file)
        output_file_v.close()
        return log_config.start_of_log()+"verilog code exported"+log_config.end_of_log()

    else:
        return log_config.start_of_log()+"error please check again before generating the verilog code"+log_config.end_of_log()
def connect_transactions():
    '''
    description : this function match and find what is the src state , the dst state and the state condition for it.
    using arrow head as the only anchor that connect everything together (state with arrows), to find the src state
    and the line which is connected with this src state.
    from the arrow we find the state condition connected with it using get_state_condition_element function.
    if the arrow is loop back arrow the src state is the dst state.

    :return: a text of the current transaction or an error msg, string

    '''

    connected_transaction_as_string = "check transactions done :- \n"  # the output text
    dump_id = 0  # the dump id for a state without id
    object_file.transaction = [
    ]  # reset transaction before using this function
    object_file.valid_verilog = False
    changed = -1  # flag variable to determine update the image or no
    passed = -1  # the passing condition -1 failed, 1 success
    for element in object_file.all_objects_as_dic[
            "arrow head"]:  # for every arrow head, as it's the connecting element of the state and the line
        src_element = None
        dst_element = None
        con_element = None

        src_element_id = []
        dst_element_id = []
        con_element_input_output = []  # condition element inputs and outputs

        # search in state
        for x_element in element.get_connected_anchor(
        ):  # for every element in the arrow head
            if x_element.get_name(
            ) == "state":  # if this element is a state take it
                dst_element = x_element  # this element is the dst element as the arrow connected with this state
                dst_element_id = get_state_id(
                    dst_element)  # get the state id as list of anchors
                break  #break this loop

        for x_element in element.get_connected_anchor(
        ):  # for every element in the arrow head
            if x_element.get_name(
            ) != "state":  # if this element not a state, thus it's an straight arrow or loop back arrow or any kind of arrow
                if x_element.get_name(
                ) == "loop back arrow":  #if it's loop back arrow
                    src_element = dst_element  # the src element is the dst element
                    con_element = get_state_condition(
                        x_element)  # get the state condition for this arrow
                else:  # if it's not an loop back arrow
                    src_element = get_src_element(
                        dst_element.get_id(), x_element.get_connected_anchor()
                    )  # get the src element as the another satet of this arrow
                    con_element = get_state_condition(
                        x_element)  # get the state condition for this arrow

                if src_element != None:  # if the src element  not None, we found a src state
                    src_element_id = get_state_id(
                        src_element)  # get the src state id as list of anchors

                if con_element != None:  # if the state condition not None, we found a state condition for this arrow
                    con_element_input_output = get_state_condition_input_output(
                        con_element
                    )  # get the input and output as a list of anchors

        passed, error_msg, highlight_image = error_checking(
            src_element, dst_element, con_element, src_element_id,
            dst_element_id, con_element_input_output)  #check for error
        if passed == -1:  #not passed
            return passed, log_config.start_of_log() + (
                error_msg) + log_config.end_of_log(), highlight_image

        else:
            #passed
            con_element_input_output = sort_anchors(
                con_element_input_output
            )  # sort the anchors of the input and output from left to right
            src_element_id = sort_anchors(
                src_element_id
            )  #sort the anchors of the src state id from left to right
            dst_element_id = sort_anchors(
                dst_element_id
            )  #sort the anchors of the dst state id from left to right

            transaction_input, transaction_output = get_input_get_output(
                con_element_input_output
            )  #get the input and the output of the state from the anchors as string
            transaction_src_id = get_state_id_as_string(
                src_element_id)  #get the src state id as string
            transaction_dst_id = get_state_id_as_string(
                dst_element_id)  #get the dst state id as string

            #============================== another non fatel error checking ==============================================#
            if transaction_src_id == "" and transaction_dst_id != "":  # if the src state id string is empty, but we have dst state id as string
                # if the state has no id generate one for it
                transaction_src_id = "g_" + str(
                    dump_id)  # generating the id with tag g_ as string
                dump_id = dump_id + 1  # increment the dummy id
                gen_element_src_id = generate_state_id_dumy(
                    transaction_src_id,
                    src_element)  # generate the id as element
                add_state_id(gen_element_src_id
                             )  # append this element in the dictionary
                changed = 1  # mark we changed on the image
                #=============================================================#
            if transaction_dst_id == "" and transaction_src_id != "":  # if the dst state id string is empty, but we have src state id as string
                # if the state has no id generate one for it
                transaction_dst_id = "g_" + str(
                    dump_id)  # generating the id with tag g_ as string
                dump_id = dump_id + 1  # increment the dummy id
                gen_element_dst_id = generate_state_id_dumy(
                    transaction_dst_id,
                    dst_element)  # generate the id as element
                add_state_id(
                    gen_element_dst_id)  #append this element in the dictionary
                changed = 1  # mark we changed on the image
                #=============================================================#
            if transaction_src_id == "" and transaction_dst_id == "":  # if we didn't find a src id elements or dst id elements
                transaction_src_id = "g_" + str(
                    dump_id)  # generate dump id as string 1
                dump_id = dump_id + 1  #update the dump id
                transaction_dst_id = "g_" + str(
                    dump_id)  # generate dump id as string 2
                dump_id = dump_id + 1  #update the dump id

                if src_element.get_xmin() == dst_element.get_xmin(
                ) and src_element.get_ymin() == dst_element.get_ymin(
                ):  # if the src state and the dst state have the same xmin and ymin,thus this is the same condition
                    gen_element_src_id = generate_state_id_dumy(
                        transaction_src_id, src_element)  #just add one id
                    transaction_dst_id = transaction_src_id  # the dst id is the src id
                    add_state_id(
                        gen_element_src_id)  #add this id as an element
                    dump_id = dump_id - 1  #remove the extra dump id as not used

                else:  # the two states are diffrent, not the same state
                    gen_element_src_id = generate_state_id_dumy(
                        transaction_src_id,
                        src_element)  #generate the first id element
                    gen_element_dst_id = generate_state_id_dumy(
                        transaction_dst_id,
                        dst_element)  #generate the second id element
                    add_state_id(gen_element_src_id)  #add this element
                    add_state_id(gen_element_dst_id)  #add this element
                changed = 1  # mark that, we changed in the image
            #==============================================================================================================#

            if changed == 1:  # if we changed the image
                image_operations.update_image(
                )  # update the image this for error pop up widget

            # we made it!!!, just add this transaction
            object_file.transaction.append({
                "src_id":
                "state_" + (transaction_src_id),
                "dst_id":
                "state_" + (transaction_dst_id),
                "input":
                str(transaction_input),
                "output":
                str(transaction_output)
            })

            #add this transaction to the output msg
            connected_transaction_as_string = connected_transaction_as_string + "src state : " + (
                transaction_src_id) + ", dst state : " + (
                    transaction_dst_id
                ) + ",input : " + str(transaction_input) + ", output : " + str(
                    transaction_output) + "\n"

    #---------------------------------------------------------------------------#
    # we passed in every transaction #
    if changed == 1:  #if we changed the image
        image_operations.update_image()  #update the image

    object_file.valid_verilog = True  #we can generate verilog code

    return passed, log_config.start_of_log(
    ) + connected_transaction_as_string + log_config.end_of_log(
    ), object_file.image