Qt code generation method based on UML class diagram and sequence diagram monitoring source simulation software
By building UML class diagrams and timing diagrams, parsing XMI files to generate Qt code, solving the efficiency and quality problems of existing tools when generating Qt framework code, and achieving efficient and accurate automated code generation.
Patent Information
- Application Number
- CN202510175768.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-06-13
AI Technical Summary
When generating Qt framework code, existing UML model generation tools cannot effectively handle the dynamic behavior of the system, resulting in the generated code requiring a lot of manual adjustments, affecting efficiency and quality.
By building UML class diagrams and timing diagrams of monitoring source simulation software, obtaining XMI files, parsing and converting them into data models, class models and timing diagram models, generating Qt's class code, object call relationships, signal and slot codes, and realizing automated code generation.
It improves the automation and quality of code generation, simplifies the conversion process from UML model to Qt code, and improves the accuracy and generation efficiency of code.
Smart Images

Figure CN120144101A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software development, and particularly relates to a Qt code generation method for monitoring source simulation software based on UML class diagrams and sequence diagrams. Background Art
[0002] In the field of software development, improving development efficiency and software quality has always been the pursuit. The Unified Modeling Language (UML), as a standardized modeling tool, is widely used in the analysis, design, and documentation processes of software engineering. UML provides various diagrams, including class diagrams and sequence diagrams, which are used to describe the static structure and dynamic behavior of the system respectively. Class diagrams show the classes, attributes, methods of the system, and the relationships among them. Sequence diagrams, on the other hand, describe the interaction order between objects, which is crucial for understanding and designing complex systems.
[0003] UML class diagrams and sequence diagrams provide software developers with an intuitive way to understand and design software systems. They help developers establish a clear system architecture and behavior model before coding, thus reducing misunderstandings and errors during the development process.
[0004] With the development of software engineering, the technology of automatically generating code from UML models has received increasing attention. This technology can significantly improve development efficiency, reduce the workload of manual coding, and help maintain the consistency between the model and the code. However, most existing code generation tools focus on a single UML diagram and lack comprehensive consideration of the system's dynamic behavior, especially when generating code for specific frameworks such as the Qt framework.
[0005] Qt is a cross-platform C++ application framework widely used for developing applications with rich graphical user interfaces. It provides a complete set of tools and libraries, supports multiple programming paradigms, and allows developers to create high-performance and responsive user interfaces. However, the complexity and flexibility of Qt also mean that developers need to write a large amount of code to implement these functions, which is not only time-consuming but also error-prone.
[0006] Although there are some tools in the market for generating code from UML models, they usually cannot handle the elements and architecture unique to the Qt framework well. The code generated by these tools often requires a large amount of manual adjustment to adapt to the Qt programming model and best practices. Summary of the Invention
[0007] Aiming at the deficiencies of the above-mentioned existing technologies, the purpose of the present invention is to provide a Qt code generation method for monitoring source simulation software based on UML class diagrams and sequence diagrams, so as to improve the degree of code generation automation and ensure the quality and consistency of the code.
[0008] To achieve the above object, the technical solution adopted by the present invention is as follows:
[0009] A method for generating Qt code for monitoring source simulation software based on UML class diagrams and sequence diagrams of the present invention is as follows:
[0010] 1) Construct UML class diagrams and sequence diagrams of the monitoring source simulation software;
[0011] 2) Obtain XMI files corresponding to the class diagrams and sequence diagrams;
[0012] 3) Construct a set based on the XMI files;
[0013] 4) Generate class code for Qt;
[0014] 5) Generate the object call relationship for Qt;
[0015] 6) Generate signal and slot code;
[0016] 7) Generate Qt code files.
[0017] Further, the step 1) specifically includes:
[0018] 11) Construct the basic UML class diagram of the monitoring source simulation software: Identify the basic objects in the monitoring source simulation software, clarify their functions and roles, and based on the identified basic objects, construct the basic UML class diagram of the monitoring source simulation software. In the class diagram, describe in detail the attributes and operations of each class, including the attribute name, attribute type, method name, and method return type; accurately represent the relationships between classes, covering relationship types such as association, inheritance, dependency, aggregation, and composition, so as to show the interaction and hierarchical structure between objects;
[0019] 12) Construct the interface UML class diagram of the monitoring source simulation software: Identify the objects in the interface of the monitoring source simulation software, focus on the interface-related functions and elements, and construct the UML class diagram of the interface of the monitoring source simulation software, including the interface-related classes and their relationships; in the class diagram, describe in detail the attributes, operations, signals, and slot functions of each class, ensuring that the names and types of attributes, methods, signals, and slot functions are accurate; add labels to the classes, define the label of the class as interface, and define the method label of the slot function as slots;
[0020] 13) Construct the UML sequence diagram of the monitoring source simulation software: Identify the call relationships between the basic objects of the monitoring source simulation software, clarify the mutual cooperation and communication between objects, identify the binding relationships between signals and slots of the interface objects of the monitoring source simulation software, and determine the corresponding slot function responses when signals are triggered; based on the above call relationships and binding relationships, construct the UML sequence diagram of the monitoring source simulation software, and accurately represent the interaction order and time relationship between objects in the sequence diagram, so as to show the dynamic behavior during the operation of the system.
[0021] Further, step 2) specifically includes:
[0022] 21) Obtain the XMI files of the UML class diagram and sequence diagram of the monitoring source simulation software;
[0023] Use StarUML software to export the UML class diagram and sequence diagram of the monitoring source simulation software constructed in step 1) into the XMI file format. The information required for generating the code is defined within the packagedElement tag of the XMI file;
[0024] 22) Parse the key information within the packagedElement tag in the XMI file;
[0025] Identify and parse the content with the attribute type of xmi:type=uml:DataType in the XMI file. This content is generated based on the UML class diagram and describes the basic data types used in the basic UML classes of the monitoring source simulation software (such as int, bool, string, etc.) and the basic types provided by Qt used in the UML classes of the monitoring source simulation software interface (such as QString, QFile, etc.);
[0026] Identify and parse the content with the attribute type of xmi:type=uml:Class in the XMI file. This content is generated based on the UML class diagram and defines classes, class attributes, class methods, and class inheritance relationships;
[0027] Identify and parse the content with the attribute type of xmi:type=uml:Collaboration in the XMI file. This content is generated based on the UML sequence diagram and describes the relationships between objects, including objects, the methods called by objects, the call relationships between objects, and the signal-slot binding relationships.
[0028] Further, step 3) specifically includes:
[0029] 31) Convert the content with the attribute type of xmi:type=uml:DataType identified and parsed in the XMI file into a data model, and define a data model set D, D=(id1, name1), where id1 represents the unique type identifier and name1 represents the data type name;
[0030] 32) Convert the content with the attribute type of xmi:type=uml:Class in the XMI file, which is recognized and parsed, into a class model. Define a class model set C, where C = (I, A, O, G, M, stereotype2). Here, I represents the set of class information, A represents the set of class attributes, O represents the set of class methods, G represents the set of superclasses of the class, M represents the set of free members of the class, and stereotype2 represents the identification type of the class. The set of class information I = (id3, name3, type3, visibility3, abstract3), where id3 represents the unique identifier of the class, name3 represents the name of the class, type3 represents the type of the class, visibility3 represents the access visibility of the class, and abstract3 represents the abstractness of the class. The set of class attributes A = (id4, name4, type4, visibility4, static4), where id4 represents the unique identifier of the class attribute, name4 represents the name of the class attribute, type4 represents the type of the class attribute, visibility4 represents the access visibility of the class attribute, and static4 represents the static nature of the class attribute. The set of class methods O = (OI, RP, IP). OI represents the set of basic information of the class methods, and OI = (id5, name5, visibility5, static5, abstract5, stereotype5), where id5 represents the unique identifier of the class method, name5 represents the name of the class method, visibility5 represents the access visibility of the class method, static5 represents the static nature of the class method, abstract5 represents the abstractness of the class method, and stereotype5 represents the identification type of the class method. RP represents the set of return parameters of the class method, and RP = (id6, type6), where id6 represents the unique identifier of the class method return parameter, and type6 represents the data type name of the class method return parameter. IP represents the set of input parameters of the class method, and IP = (id7, type7, name7), where id7 represents the unique identifier of the class method input parameter, type7 represents the data type name of the class method input parameter, and name7 represents the name of the class method input parameter. The set of superclasses of the class G = (id8, visibility8, specific8, general8), where id8 represents the unique identifier of the inheritance relationship, visibility8 represents the access visibility of the inheritance relationship, specific8 represents the unique identifier of the subclass corresponding to the inheritance relationship, and general8 represents the unique identifier of the superclass corresponding to the inheritance relationship;The set of free members of the class M = (id9, name9, type9, visibility9), where id9 represents the unique identifier of the free member, name9 represents the name of the free member, type9 represents the type of the free member, and visibility9 represents the access visibility of the free member;
[0031] 33) Convert the content with the attribute type xmi:type = uml:Collaboration in the XMI file that is recognized and parsed into a sequence diagram model. Define the set of sequence diagram models T, T = (TI, TM, TA), where TI represents the set of sequence diagram information, TM represents the set of free members of the sequence diagram, and TA represents the set of attributes of the sequence diagram; the set of sequence diagram information
[0032] TI = (id10, name10, visibility10, abstract10), where id10 represents the unique identifier of the sequence diagram, name10 represents the name of the sequence diagram, visibility10 represents the access visibility of the sequence diagram, and abstract10 represents the abstractness of the sequence diagram; the set of free members of the sequence diagram TM = (TMI, L, E, F), where TMI represents the set of basic information of the free members, L represents the set of lifeline elements, E represents the set of message elements, and F represents the set of fragment elements; the set of basic information of the free members
[0033] TMI = (id11, name11, type11, visibility11), where id11 represents the unique identifier of the free member, name11 represents the name of the free member, type11 represents the type of the free member, and visibility11 represents the access visibility of the free member; the set of lifeline elements L = (id12, name12, type12, visibility12, represents12), where id12 represents the unique identifier of the lifeline element, name12 represents the name of the lifeline element, type12 represents the type of the lifeline element, visibility12 represents the access visibility of the lifeline element, and represents12 represents the unique identifier corresponding to the set of attributes TA of the sequence diagram for the lifeline element;
[0034] E = (id13, name13, type13, visibility13, signature13, receiveEvent13, sendEvent13, messageSort13), where id13 represents the unique identifier of the message element, name13 represents the name of the message element, type13 represents the type of the message element, visibility13 represents the access visibility of the message element, signature13 represents the unique identifier of the method of the class corresponding to the message element, receiveEvent13 represents the unique identifier of the set of fragment elements corresponding to the message element, sendEvent13 represents the unique identifier of the set of fragment elements corresponding to the message element, and messageSort13 represents the call type information of the message element; F = (id14, covered14, type14), where id14 represents the unique identifier of the fragment element, covered14 represents the unique identifier of the set of lifeline elements corresponding to the fragment element, and type14 represents the type of the fragment element; the attribute set TA of the sequence diagram = (id15, name15, type15, visibility15, static15), where id15 represents the unique identifier of the attribute of the sequence diagram, name15 represents the name of the attribute of the sequence diagram, type15 represents the type of the attribute of the sequence diagram, visibility15 represents the access visibility of the attribute of the sequence diagram, and static15 represents the staticity of the attribute of the sequence diagram.
[0035] Further, step 31) specifically includes:
[0036] 311) Identify all tags with the attribute xmi:type = "uml:DataType" in the XMI file, and form a set of data models with these tags, denoted as D; for each tag, extract the values of its xmi:id and name attributes, and store these values in set D respectively to form a set of data models containing the attributes (id1, name1).
[0037] Further, step 32) specifically includes:
[0038] 321) Identify all nodes with the attribute xmi:type = "uml:Class" in the XMI file, and form a set of class models with these nodes, denoted as C; in the set C, create a set of class information as an element of the set C, denoted as C.I. For each class node in the set C, extract the values of its attributes xmi:id, name, xmi:type, visibility, and isAbstract, and store these values in the set C.I respectively, forming a set of class information containing the attributes (id3, name3, type3, visibility3, abstract3);
[0039] 322) Under the nodes with the attribute xmi:type = "uml:Class", identify all child nodes with the label ownedAttribute; create a set of class attributes in the set C, denoted as C.A; for each ownedAttribute node, extract the values of its attributes xmi:id, name, type, visibility, and isStatic, and store these values in the set of class attributes C.A respectively, forming a set containing the attributes (id4, name4, type4, visibility4, static4);
[0040] 323) Under the nodes with the attribute xmi:type = "uml:Class", identify all child nodes with the label ownedOperation; in the set C, create a set of class methods, denoted as C.O; in the set C.O, create a subset of basic class method information, denoted as C.O.OI; for each ownedOperation node, extract the values of its attributes xmi:id, name, visibility, isStatic, isAbstract, and xmi:type, and store these values in the set of basic class method information C.O.OI respectively, forming a set containing the attributes (id5, name5, visibility5, static5, abstract5);
[0041] Under the ownedOperation node, identify all child nodes with the tag ownedParameter; create a subset of the method return parameters of a class in the set C.O, denoted as C.O.RP; create a subset of the method input parameters of a class in the set C.O, denoted as C.O.IP; for each ownedParameter node, classify and process it according to the value of its direction attribute: if the value of direction is return, extract the values of the xmi:id and type attributes of the node and store the values in the set of method return parameters C.O.RP of the class, forming a set containing the attributes (id6, type6); if the value of direction is in, extract the values of the xmi:id, type, and name attributes of the node and store the values in the set of method input parameters C.O.IP of the class, forming a set containing the attributes (id7, type7, name7).
[0042] Under the ownedOperation node, identify the stereotype nodes of all child nodes with the tag xmi:Extension; for each stereotype node, extract the value of its value attribute and store these values in the set of basic information of the class method C.O.OI, forming a set containing the attribute (stereotype5).
[0043] 324) Under the node with the xmi:type = "uml:Class" attribute, identify all child nodes with the tag generalization; create a set of the superclasses of a class in the set C, denoted as C.G; for each generalization node, extract the values of its xmi:id, visibility, specific, and general attributes and store these values in the set of class attributes C.G respectively, forming a set containing the attributes (id8, visibility8, specific8, general8).
[0044] 325) Under the node with the xmi:type = "uml:Class" attribute, identify all child nodes with the tag ownedMember; create a set of the free members of a class in the set C, denoted as C.M; for each ownedMember node, extract the values of its xmi:id, name, type, and visibility attributes and store these values in the set of class attributes C.M respectively, forming a set containing the attributes (id9, name9, type9, visibility9).
[0045] 326) Under the node with the attribute xmi:type = "uml:Class", identify all stereotype nodes that are children with the tag xmi:Extension; for each stereotype node, extract the value of its value attribute and store these values in the stereotype subset of the class model set C to form a set containing the stereotype2 values.
[0046] Further, step 33) specifically includes:
[0047] 331) In the XMI file, identify all nodes with the attribute xmi:type = "uml:Collaboration" and form a set of sequence diagram models with these nodes, denoted as T; in the set T, create a set of sequence diagram information TI, denoted as T.TI; for each sequence diagram node in the set T, extract the values of its attributes xmi:id, name, visibility, and isAbstract and store these values in the set T.TI respectively to form a set of sequence diagram information containing the attributes (id10, name10, visibility10, abstract10).
[0048] 332) Under the node with the attribute xmi:type = "uml:Collaboration", identify all child nodes with the tag ownedMember; in the set T, create a set of free members of the sequence diagram, denoted as T.TM;
[0049] In the set of free members TM of the sequence diagram, create a set of basic information of free members TMI, denoted as T.TM.TMI; for each ownedMember node, extract the values of its xmi:id, name, type, and visibility attributes and store these values in the set of basic information of free members T.TM.TMI respectively to form a set containing the attributes (id11, name11, type11, visibility11).
[0050] Under the child nodes of ownedMember, identify all child nodes with the tag lifeline; in the set TM, create a sub - set L of lifeline elements, denoted as T.TM.L; for each lifeline node, extract the values of its xmi:id, name, xmi:type, visibility, and represents attributes, and store these values respectively in the free - member basic information set T.TM.L, forming a set containing the attributes (id12, name12, type12, visibility12, represents12).
[0051] Under the child nodes of ownedMember, identify all child nodes with the tag message; in the set TM, create a sub - set E of message elements, denoted as T.TM.E; for each message node, extract the values of its xmi:id, name, xmi:type, visibility, signature, receiveEvent, sendEvent, and messageSort attributes, and store these values respectively in the free - member basic information set T.TM.E, forming a set containing the attributes (id13, name13, type13, visibility13, signature13, receiveEvent13, sendEvent13, messageSort13).
[0052] Under the child nodes of ownedMember, identify all child nodes with the tag fragment; in the set TM, create a sub - set F of fragment elements, denoted as T.TM.F; for each fragment node, extract the values of its xmi:id, covered, and xmi:type attributes, and store these values respectively in the free - member basic information set T.TM.F, forming a set containing the attributes (id14, covered14, type14).
[0053] 333) Under the node with the attribute xmi:type = "uml:Collaboration", identify all child nodes with the tag ownedAttribute; in the set T, create a set TA of sequence diagram attributes, denoted as T.TA; for each ownedAttribute node, extract the values of its attributes xmi:id, name, type, visibility, and isStatic, and store these values in T.TA respectively, forming a set of sequence diagram attributes containing the attributes (id15, name15, type15, visibility15, static15).
[0054] Further, step 4) specifically includes:
[0055] 41) Convert the name element of the element set I in the set C into a class name string [C.I.name3] of Qt code, and define a Qt class header file string;
[0056] 42) Define a Qt class source code file string and initialize it to be empty.
[0057] Further, step 41) specifically includes:
[0058] 411) Define a macro definition code [s_def] string and initialize it to be empty; convert all letters of the Qt code class name string [C.I.name3] to uppercase characters to form a string [C.I.NAME]; concatenate the strings "#ifndef", [C.I.NAME], "_H\n#define", [C.I.NAME], "H\n" in sequence to form the macro definition Qt code [s_def] string;
[0059] 412) Define the string [s_include_g] for introducing inheritance relationship code and initialize it to be empty; convert the id3 element of the element set I in the set C to the unique identifier string of the class [C.I.id3], and convert the type3 element of the set I in the set C to the type string of the class [C.I.type3]; convert the general8 element of the set G of the set C to the parent class string of the class in Qt code [C.G.general8]; traverse all sets C, check whether there is a subset C_TEMP in the set C such that [C_TEMP.I.id3] == [C.G.general8], if the subset C_TEMP exists and the content of the [C_TEMP.I.type3] string is the string form corresponding to the built-in data type in Qt (such as QString, QChar, etc.), the [s_include_g] string is concatenated with "#include<", [C_TEMP.I.name3], ">" in sequence; otherwise the [s_include_g] string is concatenated with "#include", [C_TEMP.I.name3], "\" in sequence;
[0060] 413) Define the string [s_include_d] for introducing data type code and initialize it to be empty; convert the id1 element in the set D to the data type identifier string of Qt code [D.id1]; convert the type4 element of the set A of the element in the set C to the attribute type string of the class in Qt code [C.A.type4], convert the type7 element of the set IP of the element O of the element in the set C to the input parameter type string of the class method, and convert the type6 element of the set RP of the element O of the element in the set C to the return parameter type string of the class method [C.O.RP.type6];
[0061] Traverse the set of element A in set C. For each set of element A, check whether there is a subset C_TEMP in set C such that C_TEMP.I.id3 == C.A.type4. If there is a subset C_TEMP and the content of the string [C_TEMP.I.type3] is the string form corresponding to the built-in data type of Qt (such as QString, QChar, etc.), the string [s_include_d] is concatenated with "#include<", [C_TEMP.I.name3], and ">", otherwise the string [s_include_d] is concatenated with "#include\"", [C_TEMP.I.name3], and "\""; if not, traverse all sets D and check whether there is a subset D_TEMP in set D such that _D_TEMP.id1 == C.A.type4. If there is a subset D_TEMP and the content of the string [D_TEMP.name1] is the string form corresponding to the built-in data type of Qt (such as QString, QChar, etc.), the string [s_include_d] is concatenated with "#include<", [D_TEMP.name1], and ">", otherwise the string [s_include_d] is concatenated with "#include\"", [D_TEMP.name1], and "\"";
[0062] Traverse the set of element IP in the set of element O in the current set C. For each set of element IP, check whether there is a subset C_TEMP in set C such that C_TEMP.I.id3 == C.O.IP.type7. If there is C_TEMP and C_TEMP.I.type3 is a built-in type of Qt, the string [s_include_d] is concatenated with "#include<", [C_TEMP.I.name3], and ">", otherwise the string [s_include_d] is concatenated with "#include\"", [C_TEMP.I.name3], and "\""; if not, traverse all sets D and check whether there is a subset D_TEMP in set D such that D_TEMP.id1 == C.O.IP.type7. If there is a subset D_TEMP and the content of the string [D_TEMP.name1] is the string form corresponding to the built-in data type of Qt (such as QString, QChar, etc.), the string [s_include_d] is concatenated with "#include<", [D_TEMP.name1], and ">", otherwise the string [s_include_d] is concatenated with "#include\"", [D_TEMP.name1], and "\"";
[0063] Traverse the element RP set of element O in the current set C. For each element RP set, check whether there is a subset C_TEMP in the set C, so that C_TEMP.I.id3 == CORP.type6. If the subset C_TEMP exists and C_TEMP.I.type3 is a Qt built-in type, the [s_include_d] string is connected in sequence to "#include<", [C_TEMP.I.name3], ">", otherwise the [s_include_d] string is connected in sequence to "#include"", [C_TEMP.I.name3], """; if it does not exist, Then traverse all sets D and check whether there is a subset D_TEMP in set D, so that D_TEMP.id1 == CORP.type6. If the subset D_TEMP exists, and the content of the [D_TEMP.name1] string is the string form corresponding to the data type provided by Qt (such as QString, QChar, etc.), the [s_include_d] string is sequentially connected to "#include<", [D_TEMP.name1], ">", otherwise the [s_include_d] string is sequentially connected to "#include", """, [D_TEMP.name1], """;
[0064] 414) Define the introduction class start code [s_class_b] string and initialize it to empty, and add the class start code according to the class type;
[0065] If the content of the [CGgeneral8] string is QObejct, the [s_class_b] string is connected in sequence: "class", [CIname3], ":public QObject{\n\tQ_OBJECT\npublic:\n\texplicit", [CIname3], "(QObject*parent=nullptr);\n";
[0066] If the content of the [C.G.general8] string is the string form corresponding to the Qt GUI class, traverse the set C to check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.G.general8. If the subset C_TEMP exists, the [s_class_b] string is concatenated in sequence with "namespace Ui{\nclass", [C.I.name3], ";\n}\n\nclass", [C.I.name3], ":public", [C_TEMP.I.name3], "{\n\tQ_OBJECT\npublic:\n\texplicit", [C.I.name3], "(", [C_TEMP.I.name3], "*parent = nullptr);\n\t~", [C.I.name3], "();\nprivate:\n\tUi::", [C.I.name3], "*ui;\n";
[0067] If the content of the [C.G.general8] string is empty, the [s_class_b] string is "class", [C.I.name3], "{\npublic:\n\t", [C.I.name3], "();\n";
[0068] 415) Define the class attribute code [s_attributes] string and initialize it to be empty; the [s_attributes] attribute string is divided into three strings: [s_attributes_public], [s_attributes_protected], and [s_attributes_private] according to the access permission, and they are initialized to be empty respectively; convert the name4 element of the element A set in the set C to the class attribute name string [C.A.name4] in Qt code; convert the visibility4 element of the element A set in the set C to the string [C.A.visibility4]; convert the static4 element of the element A set in the set C to the string [C.A.static4];
[0069] Traverse the element A set in the class set C. If there is C.A.visibility4 == public, the [s_attributes_public] string is concatenated with "public:\n";
[0070] Traverse the set of elements A in the class set C. If there exists C.A.visibility4 == protected, concatenate the string "protected:\n" to [s_attributes_protected];
[0071] Traverse the set of elements A in the class set C. If there exists C.A.visibility4 == private, concatenate the string "private:\n" to [s_attributes_private];
[0072] Define the string of a single attribute code [s_attribute]. If the set A satisfies C.A.static4 == true, concatenate the string "static" to [s_attribute], otherwise concatenate the empty string. Then, concatenate the strings \t, [C.A.type4], [C.A.name4], and ;\n in sequence. If C.A.visibility4 == public, concatenate [s_attribute] to the string [s_attributes_public]; if C.A.visibility4 == protected, concatenate [s_attribute] to the string [s_attributes_protected]; if C.A.visibility4 == private, concatenate [s_attribute] to the string [s_attributes_private];
[0073] Concatenate [s_attributes_public], [s_attributes_protected], and [s_attributes_private] to the string [s_attributes];
[0074] 416) Define the string of the class's method code [s_functions] and initialize it to empty. This string stores the basic methods of the class; Convert the stereotype5 element of the element OI set in the element O set of the set C to the string [C.O.OI.stereotype5];
[0075] Define the signal code string [s_signals] of the class, which stores class signals, and initialize [s_signals] = "signals:\n"; Convert the name9 element of the M set in the set C to the free member name string [C.M.name9] of the class; Convert the type9 element of the M set in the set C to the free member type string [C.M.type9] of the class; Traverse the M set of elements in the class set C. If C.M.type9 == uml:Signal, then concatenate the [s_signals] string with "\t void", [C.M.name9], "();\n";
[0076] 418) Define the slot function code string [s_slots] of the class, which stores class slot functions; The [s_slots] string is divided into three strings [s_slots_public], [s_slots_protected], and [s_slots_private] according to access permissions; Traverse the set O of elements of the method C.O.OI.stereotype5 == slots in the class set C. If there is C.O.OI.visibility5 == public, then concatenate the [s_slots_public] string with "public, slots:\n"; If there is C.O.OI.visibility5 == protected, then concatenate the [s_slots_protected] string with "protected, slots:\n"; If there is C.O.OI.visibility5 == private, then concatenate the [s_slots_private] string with "private, slots:\n", and then concatenate [s_slots_public] and [s_function], [s_slots_protected] and [s_function], [s_slots_private] and [s_function] into the [s_slots] string;
[0077] 419) Define the macro definition end code string [s_def_end] and initialize it to be empty; Concatenate the strings "#endif / / ", [C.I.NAME], "_H\n" in sequence to form the macro definition end code string [s_def_end].
[0078] Furthermore, the step 416) specifically includes:
[0079] 4161) [s_functions] strings are divided into three types according to access rights: [s_functions_public], [s_functions_protected], and [s_functions_private]; traverse the method set O in the class set C. If there is C.O.OI.visibility5 == public, the [s_functions_public] string concatenates "public:\n"; traverse the method set O in the class set C. If there is C.O.OI.visibility5 == protected, the [s_functions_protected] string concatenates "protected:\n"; traverse the method set O in the class set C. If there is C.O.OI.visibility5 == private, the [s_functions_private] string concatenates "private:\n";
[0080] 4162) Define the [s_function] string for the code of a single method. If an element in the set O satisfies C.O.OI.static5 == true, the [s_function] string concatenates "static";
[0081] 4163) Define the method return type string [s_function_returnP], initialized to be empty; traverse the RP set of elements in the O set of elements in the set C, and at the same time traverse the set C to check if there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.RP.type6. If there is a subset C_TEMP, the [s_function_returnP] string concatenates [C_TEMP.I.name3]; if not, traverse all sets D to check if there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.RP.type6. If there is a subset D_TEMP, the [s_function_returnP] string concatenates [D_TEMP.name1];
[0082] 4164) Define the method input parameter string [s_function_inPs], initialized to be empty; traverse the elements of the IP set of the O set of elements in the set C, and at the same time traverse the set C to check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.IP.type7. If the subset C_TEMP exists, concatenate the string [C_TEMP.I.name3] to the [s_function_inPs]; if not, traverse all sets D to check whether there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.IP.type7. If the subset D_TEMP exists, concatenate the string [D_TEMP.name1] and C.O.IP.name7 to the [s_function_inPs]; if there are multiple elements in the C.O.IP set, except for the last one, a comma needs to be concatenated in the [s_function_inPs] string; concatenate the string formed by sequentially concatenating [C.O.OI.name5], "(", [s_function_inPs], ");" to the [s_function] string.
[0083] 4165) If C.O.OI.visibility5 == public, concatenate the [s_function] to the string [s_functions_public]; if C.O.OI.visibility5 == protected, concatenate the [s_function] to the string [s_functions_protected]; if C.O.OI.visibility5 == private, concatenate the [s_function] to the string [s_functions_private].
[0084] 4166) Finally, concatenate [s_functions_public], [s_functions_protected] and [s_functions_private] into the [s_functions] string.
[0085] Furthermore, the step 42) specifically includes:
[0086] 421) Define the string [s_include_g] for the introduced class code and initialize it to be empty; concatenate the string [s_include_g] with "#include", [C.I.name3], and "h\n" in sequence; if the content of the string [C.G.general8] is the string form corresponding to the QtGUI class, concatenate the string [s_include_g] with "#include ui_", [C.I.name3], and "h\n".
[0087] 422) Define the string [s_functions_constructor] for the constructor code and initialize it to be empty; define the string [s_signal_slots_connects] for the signal and slot binding code and initialize it to be empty; if the content of the string [C.G.general8] is the string form corresponding to the QObject class, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "(QObject*parent):QObject(parent)\n{", [s_signal_slots_connects], "\n}\n"; if the content of the string [C.G.general8] is the string form corresponding to the Qt GUI class, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "(QWidget*parent):\nQWidget(parent),\nui(newUi::", [C.I.name3], ")\n{", [s_signal_slots_connects], "\nui->setupUi(this);\n}\n"; otherwise, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "()\n{\n}\n" in sequence.
[0088] 423) Define the string [s_functions_destructor] for the destructor code and initialize it to be empty; if the content of the string [C.G.general8] is the string form corresponding to the Qt GUI class, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "()\n{\n\tdelete ui;\n}\n".
[0089] Define the member function code [s_functions] string and initialize it to be empty; define the single method code [s_function] string and initialize it to be empty; define the [s_function_returnP] method return type string and initialize it to be empty; define [s_function_inPs] as the method parameter string and initialize it to be empty; the string composed of all the contents within the corresponding C.O set of [s_functions]; the string composed of the content of one element in the corresponding C.O set of [s_function]; traverse the set C to check if there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.RP.type6. If the subset C_TEMP exists, concatenate the string [C_TEMP.I.name3] to [s_function_returnP]; if not, traverse all the sets D to check if there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.RP.type6. If the subset D_TEMP exists, concatenate the string [D_TEMP.name1] to [s_function_returnP]; traverse the set C to check if there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.IP.type7. If the subset C_TEMP exists, concatenate the string [C_TEMP.I.name3] to [s_function_inPs]; if not, traverse all the sets D to check if there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.IP.type7. If the subset D_TEMP exists, concatenate the string [D_TEMP.name1] and C.O.IP.name7 to [s_function_inPs]; if there are multiple subsets in the C.O.IP set, except for the last one, a comma needs to be concatenated to [s_function_inPs]; define the function implementation content code [s_function_body] string, which stores the object call relationship code of Qt; concatenate [s_function] with [s_function_returnP], [C.I.name3], "::", [C.O.OI.name5], "(", [s_function_inPs], ")\n{\n", [s_function_body], "}\n" in sequence.
[0090] Further, the step 5) specifically includes:
[0091] 51) Define the object call relationship code as the string [s_function_body] and initialize it to be empty; define [s_define_variable] as the local variable definition string and initialize it to be empty; define [s_call_function] as the call function code and initialize it to be empty;
[0092] 52) Traverse the set T.TM, and then traverse the set T.TM.E; convert the messageSort13 element of the E set of the TM set of the element in the set T to the string [T.TM.E.messageSort13]; convert the signature13 element of the E set of the TM set of the element in the set T to the string [T.TM.E.signature13]; if there exists T.TM.E.messageSort13 == synchCall and it is found that C.O.OI.id5 == T.TM.E.signature13, then proceed to step 53); otherwise, return to step 52);
[0093] 53) Traverse the set T.TM.F; convert the id14 element of the F set of the TM set of the element in the set T to the string [T.TM.F.id14]; convert the sendEvent13 element of the E set of the TM set of the element in the set T to the string [T.TM.E.sendEvent13], if there exists T.TM.F.id14 == T.TM.E.sendEvent13, then traverse the set T.TM.L; convert the covered14 element of the F set of the TM set of the element in the set T to the string [T.TM.F.covered14]; convert the id12 element of the L set of the TM set of the element in the set T to the string [T.TM.L.id12], if there exists T.TM.F.covered14 == T.TM.L.id12, then traverse the set T.TA; convert the represents12 element of the L set of the TM set of the element in the set T to the string [T.TM.L.represents12]; convert the id15 element of the TA set of the element in the set T to the string [T.TA.id15], if there exists T.TM.L.represents12 == T.TA.id15, then traverse the set C.I; convert the type15 element of the TA set of the element in the set T to the string [T.TA.type15]; if there exists C.I.id3 == T.TA.type15, then store the matched I element and O element in the set C in the set C_Send, denoted as C_Send = [I,O];
[0094] 54) Traverse the set T.TM.F; convert the receiveEvent13 element of the E set of the TM set of the elements in the set T into a string [T.TM.E.receiveEvent13]; if there exists T.TM.F.id14 == T.TM.E.receiveEvent13, then traverse the set T.TM.L; if there exists T.TM.F.covered14 == T.TM.L.id12, then traverse the set T.TA; if there exists T.TM.L.represents12 == T.TA.id15, then traverse the set C.I; if there exists C.I.id3 == T.TA.type15; then store the matched I element and O element in the set C in the set C_Receive, C_Receive = [I, O];
[0095] 55) Traverse the I set and O set of the elements in the set C, and concatenate [C.I.name3], ": :", and [C.O.OI.name5] into a string [s_function_name];
[0096] 56) Define the [s_rtn_params] return code string and initialize it to empty; define the [s_rtn_type] return type string and initialize it to empty; convert the type6 element of the RP set of the O set of the elements in the set C_Receive into a string [C_Receive.O.RP.type6]; traverse the set C, if there exists a subset C_TEMP and it satisfies C_TEMP.I.id3 == C_Receive.O.RP.type6, then concatenate the [s_rtn_type] string with [C_TEMP.I.name3]; if not found, traverse all sets D, if there exists a subset D_TEMP and it satisfies D_TEMP.id1 == C.O.RP.type6, then concatenate the [s_rtn_type] string with [D_TEMP.name1]; judge whether the [s_rtn_type] string is void, if not, then the string [s_rtn_params] concatenates [s_rtn_type], "_rtn_", [no], " = " in turn, where no represents the nth [s_rtn_type] type variable in the current function, and in the declaration of the local variable string [s_define_variable], concatenate [s_rtn_type], "", [s_rtn_type], "_rtn_", [no], "; \n" in turn;
[0097] 57) Define the parameter code string [s_in_params] and initialize it to be empty; convert the type7 element of the IP set of the element set of the element O in the set C_Receive to a string [C_Receive.O.IP.type7]; find other subsets C_TEMP other than the set C from the set C. If C_TEMP.I.id3 == C_Receive.O.IP.type7 exists, concatenate the string [C_TEMP.I.name3] to [s_in_type]; if not found, traverse all sets D. If there exists a subset D_TEMP and D_TEMP.id1 == C.O.IP.type7 is satisfied, concatenate the string [D_TEMP.name1] to [s_in_type]; concatenate the string [s_in_params] with [s_in_type], "_in_", and [no] in sequence, where no represents the number of variables of the [s_in_type] type in the current function, and when declaring the local variable string [s_define_variable], concatenate [s_in_type], "", [s_in_type], "_in_", [no], and ";\n" in sequence;
[0098] 58) Convert the name3 element of the element set I in the set C_Receive to a string [C_Receive.I.name3]; if C_Receive.I.name3 == C.I.name3, concatenate the string "\t", [s_rtn_params], C.O.OI.name5, "(", [s_in_params], ") ;\n" to [s_call_function];
[0099] 59) Convert the static5 element of the OI element set of the element set O in the set C_Receive to a string [C.O.OI.static5]; if C.O.OI.static5 == true, concatenate the string "\t", [s_rtn_params], [C_Receive.I.name3], "::", [C.O.OI.name5], "(", [s_in_params], ") ;\n" to [s_call_function];
[0100] When C.O.OI.static5 = false, the string [s_temp_object] is concatenated with [C_Receive.I.name3], _object_, and [no], where no represents the number of variables of type [C_Receive.I.name3] in the current function. And when declaring the local variable string [s_define_variable], it is successively concatenated with [C_Receive.I.name3], [C_Receive.I.name3], "_object_", [no], and "; \n"; then [s_call_function] concatenates the string \t, [s_rtn_params], [s_temp_object], [C.O.OI.name5], "(", [s_in_params], ") ; \n";
[0101] 511) Concatenate [s_function_body] with [s_define_variable] and multiple [s_call_function] strings in sequence, and assign the result to [s_function_body] in step 424).
[0102] Furthermore, step 6) specifically includes:
[0103] 61) The signal-slot binding relationship code is the string [s_signal_slots_connects], initialized to be empty; define the string [s_signal_slots_connect], initialized to be empty, representing a string of the signal-slot binding relationship code;
[0104] 62) While traversing set T, traverse set C.M at the same time. If the string formed by successively connecting C.I.name3 with :: and C.M.name9 is the same as T.TI.name10, then go to step 63);
[0105] 63) Traverse set T.TM and set T.TM.E. If there exists T.TM.E.messageSort13 == asynchSignal and C.M.id9 == T.TM.E.signature13, then store the matched I element and M element in set C in the C_Signal set, denoted as C_Signal = [I, M];
[0106] 64) Traverse the set T.TM and the set T.TM.E. If there exists C.O.OI.id5 == T.TM.E.signature13, then store the I element and the O element in the set C in the C_Slot set, denoted as C_Slot = [I, O];
[0107] 65) Traverse the set T.TM.E and at the same time traverse the set T.TM.F. If there exists T.TM.F.id14 == T.TM.E.receiveEvent13, then traverse the set T.TM.L; if there exists T.TM.F.covered14 == T.TM.L.id12, then go to step 66);
[0108] 66) Convert the name12 element of the L set of the TM set of the elements in the set T to a string [T.TM.L.name12], convert the name3 element of the I set of the elements in the set C_Signal to a string [C_Signal.I.name3], convert the name9 element of the M set of the elements in the set C_Signal to a string [C_Signal.M.name9], convert the name3 element of the I set of the elements in the set C_Slot to a string [C_Slot.I.name3], and convert the name5 element of the OI set of the O element of the elements in the set C_Slot to a string [C_Slot.O.OI.name5]; if the character "*" is included in T.TM.L.name12, then [s_signal_slots_connect] sequentially concatenates "\t", "connect(this, &", [C_Signal.I.name3], "::", [C_Signal.M.name9], ",", [T.TM.L.name12], "&", [C_Slot.I.name3], "::", [C_Slot.O.OI.name5], ");\n"; otherwise [s_signal_slots_connect] sequentially concatenates "\tconnect(this, &", [C_Signal.I.name3], "::", [C_Signal.M.name9], "&", [T.TM.L.name12], "&", [C_Slot.I.name3], "::", [C_Slot.O.OI.name5], ");\n";
[0109] 67) Connect multiple [s_signal_slots_connect] in sequence to form a [s_signal_slots_connects] string, and assign it to [s_signal_slots_connects] in step 422).
[0110] Further, step 7) specifically includes:
[0111] 71) Create a Qt code header file [C.I.name3].h: Concatenate the macro definition code [s_def] string, the code string for introducing inheritance relationship [s_include_g], the code string for introducing data types [s_include_d], the class start code [s_class_b], the class attribute code [s_attributes], the class method code [s_functions], the class signal code [s_signals], the class slot function code [s_slots], and the macro definition end code [s_def_end] in sequence, and store them in the [C.I.name3].h file.
[0112] 72) Create a Qt code source file [C.I.name3].cpp: Concatenate the code string for introducing the class [s_include_g], the constructor code [s_functions_constructor] containing the signal and slot binding relationship code [s_signal_slots_connects], the destructor code [s_functions_destructor], and the member function code [s_functions] containing the object call relationship code [s_function_body] in sequence, and store them in the [C.I.name3].cpp file.
[0113] Advantages of the present invention:
[0114] 1. In the present invention, the UML class diagram and sequence diagram of the monitoring source simulation software are constructed, the XMI files corresponding to the class diagram and sequence diagram are obtained, and the data model set, class model set, and sequence diagram model set are defined based on the XMI files. Then, according to the disassembly of the model set, the set is converted into class code, object call relationship code, and signal and slot code in the Qt code of the monitoring source simulation software. Finally, the class code, object call relationship code, and signal and slot code are connected to obtain the complete Qt code of the monitoring source simulation software, completing the conversion from the UML class diagram and sequence diagram to the Qt code of the monitoring source simulation software. The present invention specifies the model of the monitoring source simulation software to the UML class diagram and sequence diagram, simplifies the process of establishing the model of the monitoring source simulation software, has a clear design and an indirect structure, and enables better efficiency from the model to the generated code.
[0115] 2. The method of the present invention parses the model file with a set model to ensure a clear structure, simplifies the process from the UML class diagram and sequence diagram to the generation of the Qt code of the monitoring source simulation software, making it both simple and accurate. It not only improves the correctness of the code but also significantly enhances the efficiency and quality of the generated Qt code, effectively enhancing the accuracy and efficiency of code generation compared with the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0116] Figure 1 It is a principle flow chart of the method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0117] For the convenience of those skilled in the art, the present invention will be further described below in conjunction with the embodiments and the drawings. The content mentioned in the embodiments does not limit the present invention.
[0118] Refer to Figure 1 As shown, a method for generating the Qt code of a monitoring source simulation software based on the UML class diagram and sequence diagram of the present invention is as follows:
[0119] 1) Construct the UML class diagram and sequence diagram of the monitoring source simulation software; specifically including:
[0120] 11) Construct the basic UML class diagram of the monitoring source simulation software: Identify the basic objects in the monitoring source simulation software, clarify their functions and roles, and based on the identified basic objects, construct the basic UML class diagram of the monitoring source simulation software. Describe in detail the attributes and operations of each class in the class diagram, including the attribute name, attribute type, method name, and method return type; accurately represent the relationships between classes, covering the relationship types of association, inheritance, dependency, aggregation, and composition, so as to show the interaction and hierarchical structure between objects;
[0121] 12) Construct the UML class diagram for the monitoring source simulation software interface: Identify the objects in the monitoring source simulation software interface, focus on the functions and elements related to the interface, and construct the UML class diagram for the monitoring source simulation software interface, including the classes related to the interface and their relationships; In the class diagram, describe the attributes, operations, signals, and slot functions of each class in detail, ensuring that the names and types of the attributes, methods, signals, and slot functions are accurate; Add labels to the classes, define the label of the class as interface, and define the method label of the slot function as slots;
[0122] 13) Construct the UML sequence diagram for the monitoring source simulation software: Identify the call relationships between the basic objects of the monitoring source simulation software, clarify the mutual cooperation and communication between objects, identify the binding relationships between signals and slots among the interface objects of the monitoring source simulation software, and determine the corresponding slot function responses when signals are triggered; Based on the above call relationships and binding relationships, construct the UML sequence diagram for the monitoring source simulation software, and accurately represent the interaction sequence and time relationships between objects in the sequence diagram to show the dynamic behavior during the system operation.
[0123] 2) Obtain the XMI files corresponding to the class diagram and sequence diagram; Specifically include:
[0124] 21) Obtain the XMI files of the UML class diagram and sequence diagram of the monitoring source simulation software;
[0125] Use StarUML software to export the UML class diagram and sequence diagram of the monitoring source simulation software constructed in step 1) into the XMI file format. The information required for generating the code is defined within the packagedElement tag of the XMI file;
[0126] 22) Parse the key information within the packagedElement tag of the XMI file;
[0127] Identify and parse the content with the attribute type of xmi:type = uml:DataType in the XMI file. This content is generated based on the UML class diagram and describes the basic data types used in the basic UML classes of the monitoring source simulation software (such as int, bool, string, etc.) and the basic types provided by Qt used in the UML classes of the monitoring source simulation software interface (such as QString, QFile, etc.);
[0128] Identify and parse the content with the attribute type of xmi:type = uml:Class in the XMI file. This content is generated based on the UML class diagram and defines the classes, class attributes, class methods, and class inheritance relationships;
[0129] Identify and parse the content in the XMI file with the attribute type of xmi:type=uml:Collaboration. The content is generated based on the UML sequence diagram and describes the relationships between objects, including objects, the methods called by objects, the call relationships between objects, and the signal-slot binding relationships.
[0130] 3) Build a set based on the XMI file; specifically including:
[0131] 31) Convert the content in the XMI file with the attribute type of xmi:type=uml:DataType that is identified and parsed into a data model, and define a data model set D, D=(id1, name1), where id1 represents the unique type identifier and name1 represents the data type name;
[0132] 32) Convert the content with the attribute type of xmi:type=uml:Class in the XMI file into a class model, define a set of class models C, C=(I, A, O, G, M, stereotype2), where I represents the set of class information, A represents the set of class attributes, O represents the set of class methods, G represents the set of superclasses of the class, M represents the set of free members of the class, and stereotype2 represents the identification type of the class; the set of class information I=(id3, name3, type3, visibility3, abstract3), where id3 represents the unique identifier of the class, name3 represents the name of the class, type3 represents the type of the class, visibility3 represents the access visibility of the class, and abstract3 represents the abstractness of the class; the set of class attributes A=(id4, name4, type4, visibility4, static4), where id4 represents the unique identifier of the class attribute, name4 represents the name of the class attribute, type4 represents the type of the class attribute, visibility4 represents the access visibility of the class attribute, and static4 represents the static property of the class attribute; the set of class methods O=(OI, RP, IP), OI represents the set of basic information of the class method, OI=(id5, name5, visibility5, static5, abstract5, stereotype5), where id5 represents the unique identifier of the class method, name5 represents the name of the class method, visibility5 represents the access visibility of the class method, static5 represents the static property of the class method, abstract5 represents the abstractness of the class method, and stereotype5 represents the identification type of the class method; RP represents the set of return parameters of the class method, RP=(id6, type6), where id6 represents the unique identifier of the return parameter of the class method, and type6 represents the data type name of the return parameter of the class method; IP represents the set of input parameters of the class method, IP=(id7, type7, name7), where id7 represents the unique identifier of the input parameter of the class method, type7 represents the data type name of the input parameter of the class method, and name7 represents the name of the input parameter of the class method; the set of superclasses of the class G=(id8, visibility8, specific8, general8), where id8 represents the unique identifier of the inheritance relationship, visibility8 represents the access visibility of the inheritance relationship, specific8 represents the unique identifier of the subclass corresponding to the inheritance relationship, and general8 represents the unique identifier of the superclass corresponding to the inheritance relationship;The set of free members of the class M = (id9, name9, type9, visibility9), where id9 represents the unique identifier of the free member, name9 represents the name of the free member, type9 represents the type of the free member, and visibility9 represents the access visibility of the free member;
[0133] 33) Identify and parse the content with the attribute type xmi:type = uml:Collaboration in the XMI file and convert it into a sequence diagram model. Define the set of sequence diagram models T, T = (TI, TM, TA), where TI represents the set of sequence diagram information, TM represents the set of free members of the sequence diagram, and TA represents the set of attributes of the sequence diagram; the set of sequence diagram information
[0134] TI = (id10, name10, visibility10, abstract10), where id10 represents the unique identifier of the sequence diagram, name10 represents the name of the sequence diagram, visibility10 represents the access visibility of the sequence diagram, and abstract10 represents the abstractness of the sequence diagram; the set of free members of the sequence diagram TM = (TMI, L, E, F), where TMI represents the set of basic information of the free member, L represents the set of lifeline elements, E represents the set of message elements, and F represents the set of fragment elements; the set of basic information of the free member
[0135] TMI = (id11, name11, type11, visibility11), where id11 represents the unique identifier of the free member, name11 represents the name of the free member, type11 represents the type of the free member, and visibility11 represents the access visibility of the free member; the set of lifeline elements L = (id12, name12, type12, visibility12, represents12), where id12 represents the unique identifier of the lifeline element, name12 represents the name of the lifeline element, type12 represents the type of the lifeline element, visibility12 represents the access visibility of the lifeline element, and represents12 represents the unique identifier corresponding to the set of attributes TA of the sequence diagram for the lifeline element;
[0136] E = (id13, name13, type13, visibility13, signature13, receiveEvent13, sendEvent13, messageSort13), where id13 represents the unique identifier of the message element, name13 represents the name of the message element, type13 represents the type of the message element, visibility13 represents the access visibility of the message element, signature13 represents the unique identifier of the method of the class corresponding to the message element, receiveEvent13 represents the unique identifier of the set of fragment elements corresponding to the message element, sendEvent13 represents the unique identifier of the set of fragment elements corresponding to the message element, and messageSort13 represents the call type information of the message element; F = (id14, covered14, type14), where id14 represents the unique identifier of the fragment element, covered14 represents the unique identifier of the set of lifeline elements corresponding to the fragment element, and type14 represents the type of the fragment element; the attribute set TA of the sequence diagram = (id15, name15, type15, visibility15, static15), where id15 represents the unique identifier of the attribute of the sequence diagram, name15 represents the name of the attribute of the sequence diagram, type15 represents the type of the attribute of the sequence diagram, visibility15 represents the access visibility of the attribute of the sequence diagram, and static15 represents the staticity of the attribute of the sequence diagram.
[0137] Specifically, step 31) specifically includes:
[0138] 311) Identify all tags with the attribute xmi:type = "uml:DataType" in the XMI file, and form a set of data models with these tags, denoted as D; for each tag, extract the values of its xmi:id and name attributes, and store these values in set D respectively, forming a set of data models containing the attributes (id1, name1).
[0139] Specifically, step 32) specifically includes:
[0140] 321) Identify all nodes with the attribute xmi:type = "uml:Class" in the XMI file, and form a set of class models with these nodes, denoted as C; in set C, create a set of class information as an element of set C, denoted as C.I. For each class node in set C, extract the values of its attributes xmi:id, name, xmi:type, visibility, and isAbstract, and store these values in set C.I respectively, forming a set of class information containing the attributes (id3, name3, type3, visibility3, abstract3);
[0141] 322) Under the nodes with the attribute xmi:type = "uml:Class", identify all child nodes with the label ownedAttribute; create a set of class attributes in set C, denoted as C.A; for each ownedAttribute node, extract the values of its attributes xmi:id, name, type, visibility, and isStatic, and store these values in the set of class attributes C.A respectively, forming a set containing the attributes (id4, name4, type4, visibility4, static4);
[0142] 323) Under the nodes with the attribute xmi:type = "uml:Class", identify all child nodes with the label ownedOperation; in set C, create a set of class methods, denoted as C.O; in set C.O, create a subset of basic class method information, denoted as C.O.OI; for each ownedOperation node, extract the values of its attributes xmi:id, name, visibility, isStatic, isAbstract, and xmi:type, and store these values in the set of basic class method information C.O.OI respectively, forming a set containing the attributes (id5, name5, visibility5, static5, abstract5);
[0143] Under the ownedOperation node, identify all child nodes with the tag ownedParameter; create a subset of the method return parameters of a class in the set C.O, denoted as C.O.RP; create a subset of the method input parameters of a class in the set C.O, denoted as C.O.IP; for each ownedParameter node, classify and process it according to the value of its direction attribute: if the value of direction is return, extract the values of the xmi:id and type attributes of the node, and store the values in the method return parameter set C.O.RP of the class, forming a set containing the attributes (id6, type6); if the value of direction is in, extract the values of the xmi:id, type, and name attributes of the node, and store the values in the method input parameter set C.O.IP of the class, forming a set containing the attributes (id7, type7, name7).
[0144] Under the ownedOperation node, identify the stereotype nodes of all child nodes with the tag xmi:Extension; for each stereotype node, extract the value of its value attribute, and store these values in the basic information set C.O.OI of the class, forming a set containing the attribute (stereotype5).
[0145] 324) Under the node with the xmi:type = "uml:Class" attribute, identify all child nodes with the tag generalization; create a set of the superclasses of a class in the set C, denoted as C.G; for each generalization node, extract the values of its xmi:id, visibility, specific, and general attributes, and store these values in the attribute set C.G of the class respectively, forming a set containing the attributes (id8, visibility8, specific8, general8).
[0146] 325) Under the node with the xmi:type = "uml:Class" attribute, identify all child nodes with the tag ownedMember; create a set of the free members of a class in the set C, denoted as C.M; for each ownedMember node, extract the values of its xmi:id, name, type, and visibility attributes, and store these values in the attribute set C.M of the class respectively, forming a set containing the attributes (id9, name9, type9, visibility9).
[0147] 326) Under the node with the attribute xmi:type = "uml:Class", identify all stereotype nodes of the child nodes with the tag xmi:Extension; for each stereotype node, extract the value of its value attribute and store these values in the stereotype subset of the class model set C to form a set containing the stereotype2 values.
[0148] Specifically, step 33) specifically includes:
[0149] 331) In the XMI file, identify all nodes with the attribute xmi:type = "uml:Collaboration" and form a set of sequence diagram models with these nodes, denoted as T; in the set T, create a set of sequence diagram information TI, denoted as T.TI; for each sequence diagram node in the set T, extract the values of its attributes xmi:id, name, visibility, and isAbstract and store these values in the set T.TI respectively to form a set of sequence diagram information containing the attributes (id10, name10, visibility10, abstract10).
[0150] 332) Under the node with the attribute xmi:type = "uml:Collaboration", identify all child nodes with the tag ownedMember; in the set T, create a set of free members of the sequence diagram, denoted as T.TM;
[0151] In the set of free members TM of the sequence diagram, create a set of basic information of free members TMI, denoted as T.TM.TMI; for each ownedMember node, extract the values of its xmi:id, name, type, and visibility attributes and store these values in the set of basic information of free members T.TM.TMI respectively to form a set containing the attributes (id11, name11, type11, visibility11).
[0152] Under the child nodes of ownedMember, identify all child nodes with the tag lifeline; in the set TM, create a sub - set L of lifeline elements, denoted as T.TM.L; for each lifeline node, extract the values of its xmi:id, name, xmi:type, visibility, and represents attributes, and store these values respectively in the free - member basic information set T.TM.L, forming a set containing the attributes (id12, name12, type12, visibility12, represents12).
[0153] Under the child nodes of ownedMember, identify all child nodes with the tag message; in the set TM, create a sub - set E of message elements, denoted as T.TM.E; for each message node, extract the values of its xmi:id, name, xmi:type, visibility, signature, receiveEvent, sendEvent, and messageSort attributes, and store these values respectively in the free - member basic information set T.TM.E, forming a set containing the attributes (id13, name13, type13, visibility13, signature13, receiveEvent13, sendEvent13, messageSort13).
[0154] Under the child nodes of ownedMember, identify all child nodes with the tag fragment; in the set TM, create a sub - set F of fragment elements, denoted as T.TM.F; for each fragment node, extract the values of its xmi:id, covered, and xmi:type attributes, and store these values respectively in the free - member basic information set T.TM.F, forming a set containing the attributes (id14, covered14, type14).
[0155] 333) Under the node with the attribute xmi:type = "uml:Collaboration", identify all child nodes with the tag ownedAttribute; in the set T, create a set TA of sequence diagram attributes, denoted as T.TA; for each ownedAttribute node, extract the values of its attributes xmi:id, name, type, visibility, and isStatic, and store these values in T.TA respectively, forming a set of sequence diagram attributes containing the attributes (id15, name15, type15, visibility15, static15).
[0156] 4) Generate the class code for Qt; specifically including:
[0157] 41) Convert the name element of the element set I in the set C into a class name string [C.I.name3] of Qt code, and define the string of the Qt class header file;
[0158] 42) Define the string of the Qt class source code file and initialize it to be empty.
[0159] Specifically, step 41) specifically includes:
[0160] 411) Define a macro definition code [s_def] string and initialize it to be empty; convert all letters of the Qt code class name string [C.I.name3] to uppercase characters to form a string [C.I.NAME]; concatenate the strings "#ifndef", [C.I.NAME], "_H\n#define", [C.I.NAME], "H\n" in sequence to form the macro definition Qt code [s_def] string;
[0161] 412) Define the string [s_include_g] for introducing inheritance relationship code and initialize it to be empty; convert the id3 element of the element set I in the set C into the unique identifier string of the class [C.I.id3], and convert the type3 element of the set I in the set C into the type string of the class [C.I.type3]; convert the general8 element of the set G of the set C into the parent class string of the class in Qt code [C.G.general8]; traverse all sets C, check whether there is a subset C_TEMP in the set C such that [C_TEMP.I.id3] == [C.G.general8], if the subset C_TEMP exists and the content of the [C_TEMP.I.type3] string is the string form corresponding to the built-in data types in Qt (such as QString, QChar, etc.), the [s_include_g] string is concatenated with "#include<", [C_TEMP.I.name3], ">" in sequence; otherwise the [s_include_g] string is concatenated with "#include", [C_TEMP.I.name3], "" in sequence;
[0162] 413) Define the string [s_include_d] for introducing data type code and initialize it to be empty; convert the id1 element in the set D into the data type identifier string of Qt code [D.id1]; convert the type4 element of the set A of the element in the set C into the attribute type string of the class in Qt code [C.A.type4], convert the type7 element of the IP set of the element O set of the element in the set C into the input parameter type string of the class method, and convert the type6 element of the RP set of the element O set of the element in the set C into the return parameter type string of the class method [C.O.RP.type6];
[0163] Traverse the set of element A in set C. For each set of element A, check whether there is a subset C_TEMP in set C such that C_TEMP.I.id3 == C.A.type4. If there is a subset C_TEMP and the content of the string [C_TEMP.I.type3] is the string form corresponding to the built-in data type of Qt (such as QString, QChar, etc.), the string [s_include_d] is concatenated in sequence as "#include<", [C_TEMP.I.name3], ">"; otherwise, the string [s_include_d] is concatenated in sequence as "#include\"", [C_TEMP.I.name3], "\""; if not, traverse all sets D and check whether there is a subset D_TEMP in set D such that _D_TEMP.id1 == C.A.type4. If there is a subset D_TEMP and the content of the string [D_TEMP.name1] is the string form corresponding to the built-in data type of Qt (such as QString, QChar, etc.), the string [s_include_d] is concatenated in sequence as "#include<", [D_TEMP.name1], ">"; otherwise, the string [s_include_d] is concatenated in sequence as "#include\"", [D_TEMP.name1], "\"".
[0164] Traverse the set of element IP in the set of element O in the current set C. For each set of element IP, check whether there is a subset C_TEMP in set C such that C_TEMP.I.id3 == C.O.IP.type7. If there is C_TEMP and C_TEMP.I.type3 is a built-in type of Qt, the string [s_include_d] is concatenated in sequence as "#include<", [C_TEMP.I.name3], ">"; otherwise, the string [s_include_d] is concatenated in sequence as "#include\"", [C_TEMP.I.name3], "\""; if not, traverse all sets D and check whether there is a subset D_TEMP in set D such that D_TEMP.id1 == C.O.IP.type7. If there is a subset D_TEMP and the content of the string [D_TEMP.name1] is the string form corresponding to the built-in data type of Qt (such as QString, QChar, etc.), the string [s_include_d] is concatenated in sequence as "#include<", [D_TEMP.name1], ">"; otherwise, the string [s_include_d] is concatenated in sequence as "#include\"", [D_TEMP.name1], "\"".
[0165] Traverse the elements of the RP set of the O set of elements in the current set C. For each RP set of elements, check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.RP.type6. If there is a subset C_TEMP and C_TEMP.I.type3 is a type provided by Qt, the [s_include_d] string is concatenated in sequence as "#include<", [C_TEMP.I.name3], ">"; otherwise, the [s_include_d] string is concatenated in sequence as "#include\"", [C_TEMP.I.name3], "\""; if not, traverse all sets D and check whether there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.RP.type6. If there is a subset D_TEMP and the content of the [D_TEMP.name1] string is the string form corresponding to a data type provided by Qt (such as QString, QChar, etc.), the [s_include_d] string is concatenated in sequence as "#include<", [D_TEMP.name1], ">"; otherwise, the [s_include_d] string is concatenated in sequence as "#include", "\"", [D_TEMP.name1], "\";
[0166] 414) Define the [s_class_b] string for the beginning code of the introduced class and initialize it to be empty, and add the beginning code of the class according to the type of the class;
[0167] If the content of the [C.G.general8] string is QObejct, the [s_class_b] string is concatenated in sequence as "class", [C.I.name3], ":public QObject{\n\tQ_OBJECT\npublic:\n\texplicit", [C.I.name3], "(QObject*parent = nullptr);\n";
[0168] If the content of the [C.G.general8] string is the string form corresponding to the Qt GUI class, traverse the set C and check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.G.general8. If the subset C_TEMP exists, the [s_class_b] string is concatenated in sequence with "namespace Ui{\nclass", [C.I.name3], ";\n}\n\nclass", [C.I.name3], ":public", [C_TEMP.I.name3], "{\n\tQ_OBJECT\npublic:\n\texplicit", [C.I.name3], "(", [C_TEMP.I.name3], "*parent = nullptr);\n\t~", [C.I.name3], "();\nprivate:\n\tUi::", [C.I.name3], "*ui;\n";
[0169] If the content of the [C.G.general8] string is empty, the [s_class_b] string is "class", [C.I.name3], "{\npublic:\n\t", [C.I.name3], "();\n";
[0170] 415) Define the class attribute code [s_attributes] string and initialize it to be empty; the [s_attributes] attribute string is divided into three strings: [s_attributes_public], [s_attributes_protected], and [s_attributes_private] according to the access permission, and they are initialized to be empty respectively; convert the name4 element of the element A set in the set C to the class attribute name string [C.A.name4] in Qt code; convert the visibility4 element of the element A set in the set C to the string [C.A.visibility4]; convert the static4 element of the element A set in the set C to the string [C.A.static4];
[0171] Traverse the element A set in the class set C. If there is C.A.visibility4 == public, the [s_attributes_public] string is concatenated with "public:\n";
[0172] Traverse the set of elements A in class set C. If there exists C.A.visibility4 == protected, concatenate the string "protected:\n" to [s_attributes_protected];
[0173] Traverse the set of elements A in class set C. If there exists C.A.visibility4 == private, concatenate the string "private:\n" to [s_attributes_private];
[0174] Define the single attribute code [s_attribute] string. If set A satisfies C.A.static4 == true, concatenate the string "static" to [s_attribute], otherwise concatenate the empty string. Then sequentially concatenate the strings \t, [C.A.type4], [C.A.name4], ;\n; If C.A.visibility4 == public, concatenate [s_attribute] to the string [s_attributes_public]; If C.A.visibility4 == protected, concatenate [s_attribute] to the string [s_attributes_protected]; If C.A.visibility4 == private, concatenate [s_attribute] to the string [s_attributes_private];
[0175] Concatenate [s_attributes_public], [s_attributes_protected], and [s_attributes_private] to the [s_attributes] string;
[0176] 416) Define the method code [s_functions] string of the class and initialize it to empty. This string stores the basic methods of the class; Convert the stereotype5 element of the element OI set in the element O set of set C to the string [C.O.OI.stereotype5];
[0177] Define the string [s_signals] of the signal code of the class, which stores the class signals, and initialize [s_signals] = "signals:\n"; convert the name9 element of the M set in the set C to the string [C.M.name9] of the free member name of the class; convert the type9 element of the M set in the set C to the string [C.M.type9] of the free member type of the class; traverse the M set of elements in the class set C, if C.M.type9 == uml:Signal, then concatenate the string [s_signals] with "\t void", [C.M.name9], "();\n";
[0178] 418) Define the string [s_slots] of the slot function code of the class, which stores the class slot functions; the string [s_slots] is divided into three strings [s_slots_public], [s_slots_protected], and [s_slots_private] according to the access permission; traverse the set O of elements of the method C.O.OI.stereotype5 == slots in the class set C, if there is C.O.OI.visibility5 == public, then concatenate the string [s_slots_public] with "public, slots:\n"; if there is C.O.OI.visibility5 == protected, then concatenate the string [s_slots_protected] with "protected, slots:\n"; if there is C.O.OI.visibility5 == private, then concatenate the string [s_slots_private] with "private, slots:\n", and then concatenate [s_slots_public] and [s_function], [s_slots_protected] and [s_function], [s_slots_private] and [s_function] into the string [s_slots];
[0179] 419) Define the string [s_def_end] of the macro definition end code and initialize it to be empty; concatenate the strings "#endif / / ", [C.I.NAME], "_H\n" in sequence to form the macro definition end code [s_def_end] string.
[0180] Specifically, step 416) specifically includes:
[0181] 4161) [s_functions] strings are divided into three types according to access rights: [s_functions_public], [s_functions_protected], and [s_functions_private]; traverse the method set O in the class set C. If there is C.O.OI.visibility5 == public, the [s_functions_public] string concatenates "public:\n"; traverse the method set O in the class set C. If there is C.O.OI.visibility5 == protected, the [s_functions_protected] string concatenates "protected:\n"; traverse the method set O in the class set C. If there is C.O.OI.visibility5 == private, the [s_functions_private] string concatenates "private:\n";
[0182] 4162) Define the single method code [s_function] string. If an element in the set O satisfies C.O.OI.static5 == true, the [s_function] string concatenates "static";
[0183] 4163) Define the method return type string [s_function_returnP], initialized to be empty; traverse the RP set of the elements of the O set of the elements in the set C, and at the same time traverse the set C to check if there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.RP.type6. If there is a subset C_TEMP, the [s_function_returnP] string concatenates [C_TEMP.I.name3]; if not, traverse all sets D to check if there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.RP.type6. If there is a subset D_TEMP, the [s_function_returnP] string concatenates [D_TEMP.name1];
[0184] Define the method input parameter string [s_function_inPs], initialized to empty; traverse the elements of the IP set of the O set of elements in the set C, and at the same time traverse the set C to check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.IP.type7. If the subset C_TEMP exists, concatenate the string [C_TEMP.I.name3] to the [s_function_inPs]; if not, traverse all sets D to check whether there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.IP.type7. If the subset D_TEMP exists, concatenate the string [D_TEMP.name1] and C.O.IP.name7 to the [s_function_inPs]; if there are multiple elements in the C.O.IP set, except for the last one, a comma needs to be concatenated in the [s_function_inPs] string; concatenate the string obtained by sequentially concatenating [C.O.OI.name5], "(", [s_function_inPs], ") ;" to the end of the [s_function] string.
[0185] 4165) If C.O.OI.visibility5 == public, concatenate [s_function] to the string [s_functions_public]; if C.O.OI.visibility5 == protected, concatenate [s_function] to the string [s_functions_protected]; if C.O.OI.visibility5 == private, concatenate [s_function] to the string [s_functions_private].
[0186] 4166) Finally, concatenate [s_functions_public], [s_functions_protected] and [s_functions_private] into the [s_functions] string.
[0187] Specifically, the step 42) specifically includes:
[0188] 421) Define the string [s_include_g] for the introduced class code and initialize it to be empty; concatenate the string [s_include_g] with "#include", [C.I.name3], and "h\n" in sequence; if the content of the string [C.G.general8] is the string form corresponding to the QtGUI class, concatenate the string [s_include_g] with "#include ui_", [C.I.name3], and "h\n".
[0189] 422) Define the string [s_functions_constructor] for the constructor code and initialize it to be empty; define the string [s_signal_slots_connects] for the signal and slot binding code and initialize it to be empty; if the content of the string [C.G.general8] is the string form corresponding to the QObject class, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "(QObject* parent):QObject(parent)\n{", [s_signal_slots_connects], "\n}\n"; if the content of the string [C.G.general8] is the string form corresponding to the Qt GUI class, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "(QWidget* parent):\nQWidget(parent),\nui(new Ui::", [C.I.name3], ")\n{", [s_signal_slots_connects], "\nui->setupUi(this);\n}\n"; otherwise, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "()\n{\n}\n" in sequence.
[0190] 423) Define the string [s_functions_destructor] for the destructor code and initialize it to be empty; if the content of the string [C.G.general8] is the string form corresponding to the Qt GUI class, concatenate the string [s_functions_constructor] with [C.I.name3], "::", [C.I.name3], "()\n{\n\tdelete ui;\n}\n".
[0191] Define the member function code [s_functions] as a string and initialize it to be empty; define the single method code [s_function] as a string and initialize it to be empty; define the [s_function_returnP] method return type string and initialize it to be empty; define [s_function_inPs] as the method parameter string and initialize it to be empty; [s_functions] is the string composed of all the contents within the corresponding C.O set; [s_function] is the string composed of the content of one element in the C.O set; traverse the set C to check if there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.RP.type6. If the subset C_TEMP exists, concatenate the string [C_TEMP.I.name3] to [s_function_returnP]; if not, traverse all the sets D to check if there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.RP.type6. If the subset D_TEMP exists, concatenate the string [D_TEMP.name1] to [s_function_returnP]; traverse the set C to check if there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == C.O.IP.type7. If the subset C_TEMP exists, concatenate the string [C_TEMP.I.name3] to [s_function_inPs]; if not, traverse all the sets D to check if there is a subset D_TEMP in the set D such that D_TEMP.id1 == C.O.IP.type7. If the subset D_TEMP exists, concatenate the string [D_TEMP.name1] and C.O.IP.name7 to [s_function_inPs]; if there are multiple subsets in the C.O.IP set, except for the last one, a comma needs to be concatenated to [s_function_inPs]; define the function implementation content code [s_function_body] as a string, and this string stores the object call relationship code of Qt; concatenate [s_function] with [s_function_returnP], [C.I.name3], "::", [C.O.OI.name5], "(", [s_function_inPs], ")\n{\n", [s_function_body], "}\n" in sequence.
[0192] 5) Generate the object call relationship of Qt; specifically including:
[0193] Define the object call relationship code as the string [s_function_body] and initialize it to be empty; define [s_define_variable] as the local variable definition string and initialize it to be empty; define [s_call_function] as the call function code and initialize it to be empty;
[0194] 52) Traverse the set T.TM, and then traverse the set T.TM.E; convert the messageSort13 element of the E set of the TM set of the elements in the set T into the string [T.TM.E.messageSort13]; convert the signature13 element of the E set of the TM set of the elements in the set T into the string [T.TM.E.signature13]; if there exists T.TM.E.messageSort13 == synchCall and C.O.OI.id5 == T.TM.E.signature13 is found, then proceed to step 53); otherwise, return to step 52);
[0195] 53) Traverse the set T.TM.F; convert the id14 element of the F set of the TM set of the elements in the set T into the string [T.TM.F.id14]; convert the sendEvent13 element of the E set of the TM set of the elements in the set T into the string [T.TM.E.sendEvent13], if there exists T.TM.F.id14 == T.TM.E.sendEvent13, then traverse the set T.TM.L; convert the covered14 element of the F set of the TM set of the elements in the set T into the string [T.TM.F.covered14]; convert the id12 element of the L set of the TM set of the elements in the set T into the string [T.TM.L.id12], if there exists T.TM.F.covered14 == T.TM.L.id12, then traverse the set T.TA; convert the represents12 element of the L set of the TM set of the elements in the set T into the string [T.TM.L.represents12]; convert the id15 element of the TA set of the elements in the set T into the string [T.TA.id15], if there exists T.TM.L.represents12 == T.TA.id15, then traverse the set C.I; convert the type15 element of the TA set of the elements in the set T into the string [T.TA.type15]; if there exists C.I.id3 == T.TA.type15, then store the matched I element and O element in the set C in the set C_Send, denoted as C_Send = [I, O];
[0196] 54) Traverse the set T.TM.F; convert the receiveEvent13 element of the E set of the TM set of the elements in the set T into a string [T.TM.E.receiveEvent13]; if there exists T.TM.F.id14 == T.TM.E.receiveEvent13, then traverse the set T.TM.L; if there exists T.TM.F.covered14 == T.TM.L.id12, then traverse the set T.TA; if there exists T.TM.L.represents12 == T.TA.id15, then traverse the set C.I; if there exists C.I.id3 == T.TA.type15; then store the I element and O element of the matching set C in the set C_Receive, C_Receive = [I, O];
[0197] 55) Traverse the I set and O set of the elements in the set C, and concatenate [C.I.name3], "::", and [C.O.OI.name5] into a string [s_function_name];
[0198] 56) Define a [s_rtn_params] return code string and initialize it to empty; define a [s_rtn_type] return type string and initialize it to empty; convert the type6 element of the RP set of the O set of the elements in the set C_Receive into a string [C_Receive.O.RP.type6]; traverse the set C, if there exists a subset C_TEMP and it satisfies C_TEMP.I.id3 == C_Receive.O.RP.type6, then concatenate the [s_rtn_type] string with [C_TEMP.I.name3]; if not found, traverse all sets D, if there exists a subset D_TEMP and it satisfies D_TEMP.id1 == C.O.RP.type6, then concatenate the [s_rtn_type] string with [D_TEMP.name1]; judge whether the [s_rtn_type] string is void, if not, then the string [s_rtn_params] is concatenated with [s_rtn_type], "_rtn_", [no], "=", where no represents the nth [s_rtn_type] type variable in the current function, and in the declaration of the local variable string [s_define_variable], it is concatenated with [s_rtn_type], "", [s_rtn_type], "_rtn_", [no], ";\n";
[0199] 57) Define the parameter code string [s_in_params] and initialize it to be empty; convert the type7 element of the IP set of the O set of elements in the set C_Receive to a string [C_Receive.O.IP.type7]; find other subsets C_TEMP other than the set C from the set C. If there is a C_TEMP.I.id3 == C_Receive.O.IP.type7, concatenate the string [s_in_type] with [C_TEMP.I.name3]; if not found, traverse all sets D. If there is a subset D_TEMP that satisfies D_TEMP.id1 == C.O.IP.type7, concatenate the string [s_in_type] with [D_TEMP.name1]; concatenate the string [s_in_params] with [s_in_type], "_in_", and [no] in sequence, where no represents the number of variables of the [s_in_type] type in the current function, and when declaring the local variable string [s_define_variable], concatenate [s_in_type], "", [s_in_type], "_in_", [no], and ";\n" in sequence;
[0200] 58) Convert the name3 element of the I set of elements in the set C_Receive to a string [C_Receive.I.name3]; if C_Receive.I.name3 == C.I.name3, concatenate the string [s_call_function] with "\t", [s_rtn_params], C.O.OI.name5, "(", [s_in_params], ") ;\n";
[0201] 59) Convert the static5 element of the OI element set of the O set of elements in the set C_Receive to a string [C.O.OI.static5]; if C.O.OI.static5 == true, concatenate the string [s_call_function] with "\t", [s_rtn_params], [C_Receive.I.name3], "::", [C.O.OI.name5], "(", [s_in_params], ") ;\n";
[0202] When C.O.OI.static5 = false, the string [s_temp_object] is concatenated with [C_Receive.I.name3], _object_, and [no], where no represents the number of variables of type [C_Receive.I.name3] in the current function. And when declaring the local variable string [s_define_variable], it is sequentially concatenated with [C_Receive.I.name3], [C_Receive.I.name3], "_object_", [no], and "; \n"; then [s_call_function] is used to concatenate the string \t, [s_rtn_params], [s_temp_object], [C.O.OI.name5], "(", [s_in_params], ") ; \n";
[0203] 511) Connect the [s_function_body] with the [s_define_variable] and multiple [s_call_function] strings in sequence, and assign the result to the [s_function_body] in step 424).
[0204] 6) Generate signal and slot code; specifically including:
[0205] 61) The signal and slot binding relationship code is the string [s_signal_slots_connects], initialized to be empty; define the string [s_signal_slots_connect], initialized to be empty, representing a string of the signal and slot binding relationship code;
[0206] 62) While traversing the set T and the set C.M, if the string formed by sequentially connecting C.I.name3 with :: and C.M.name9 is the same as T.TI.name10, then go to step 63);
[0207] 63) Traverse the set T.TM and the set T.TM.E. If there exists T.TM.E.messageSort13 == asynchSignal and C.M.id9 == T.TM.E.signature13, then store the matched I element and M element in the set C into the C_Signal set, denoted as C_Signal = [I, M];
[0208] 64) Traverse the set T.TM and the set T.TM.E. If there exists C.O.OI.id5 == T.TM.E.signature13, then store the I element and the O element in the set C in the C_Slot set, denoted as C_Slot = [I, O];
[0209] 65) Traverse the set T.TM.E and at the same time traverse the set T.TM.F. If there exists T.TM.F.id14 == T.TM.E.receiveEvent13, then traverse the set T.TM.L; if there exists T.TM.F.covered14 == T.TM.L.id12, then go to step 66);
[0210] 66) Convert the name12 element of the L set of the TM set of elements in the set T to a string [T.TM.L.name12], convert the name3 element of the I set of elements in the C_Signal set to a string [C_Signal.I.name3], convert the name9 element of the M set of elements in the C_Signal set to a string [C_Signal.M.name9], convert the name3 element of the I set of elements in the C_Slot set to a string [C_Slot.I.name3], and convert the name5 element of the OI set of elements of the O set in the C_Slot set to a string [C_Slot.O.OI.name5]; if the character "*" is included in T.TM.L.name12, then [s_signal_slots_connect] concatenates "\t", "connect(this, &", [C_Signal.I.name3], "::", [C_Signal.M.name9], ",", [T.TM.L.name12], "&", [C_Slot.I.name3], "::", [C_Slot.O.OI.name5], ");\n" in sequence; otherwise [s_signal_slots_connect] concatenates "\tconnect(this, &", [C_Signal.I.name3], "::", [C_Signal.M.name9], "&", [T.TM.L.name12], "&", [C_Slot.I.name3], "::", [C_Slot.O.OI.name5], ");\n" in sequence;
[0211] 67) Connect multiple [s_signal_slots_connect] in sequence to form a [s_signal_slots_connects] string, and assign it to [s_signal_slots_connects] in step 422).
[0212] 7) Generate a Qt code file; specifically including:
[0213] 71) Create a Qt code header file [C.I.name3].h: Concatenate the macro definition code [s_def] string, the code for introducing inheritance relationship [s_include_g] string, the code for introducing data types [s_include_d] string, the class start code [s_class_b] string, the class attribute code [s_attributes] string, the class method code [s_functions] string, the class signal code [s_signals] string, the class slot function code [s_slots] string, and the macro definition end code [s_def_end] string in sequence, and store them in the [C.I.name3].h file.
[0214] 72) Create a Qt code source file [C.I.name3].cpp: Concatenate the code for introducing the class [s_include_g] string, the constructor code [s_functions_constructor] string containing the signal and slot binding relationship code [s_signal_slots_connects] string, the destructor code [s_functions_destructor] string, and the member function code [s_functions] string containing the object call relationship code [s_function_body] string in sequence, and store them in the [C.I.name3].cpp file.
[0215] There are many specific application ways of the present invention. The above is only the preferred embodiment of the present invention. It should be pointed out that for those of ordinary skill in the art in this technical field, without departing from the principle of the present invention, several improvements can still be made, and these improvements should also be regarded as the protection scope of the present invention.
Claims
1. A Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software, characterized in that, Here are the steps: 1) Construct UML class diagram and sequence diagram of monitoring source simulation software; 2) Get the XMI files corresponding to the class diagram and sequence diagram; 3) Build a collection based on the XMI file; 4) Generate Qt class code; 5) Generate Qt object calling relationship; 6) Generate signal and slot code; 7) Generate Qt code files.
2. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 1, characterized in that: The step 1) specifically includes: 11) Construct the basic UML class diagram of the monitoring source simulation software: Identify the basic objects in the monitoring source simulation software, clarify their functions and roles, and construct the basic UML class diagram of the monitoring source simulation software based on the identified basic objects. Describe the attributes and operations of each class in the class diagram, including attribute name, attribute type, method name and method return type; accurately represent the relationship between classes to show the interaction and hierarchy between objects; 12) Construct the UML class diagram of the monitoring source simulation software interface: Identify the objects in the monitoring source simulation software interface, focus on the functions and elements related to the interface, and construct the UML class diagram of the monitoring source simulation software interface, including the classes related to the interface and their relationships; describe the attributes, operations, signals and slot functions of each class in detail in the class diagram, and ensure that the names and types of the attributes, methods, signals and slot functions are correct; add labels to the classes, define the class labels as interfaces, and define the method labels of the slot functions as slots; 13) Construct a UML timing diagram for the monitoring source simulation software: Identify the calling relationships between the basic objects of the monitoring source simulation software, clarify the mutual collaboration and communication between objects, identify the binding relationships between signals and slots between the interface objects of the monitoring source simulation software, and determine the corresponding slot function response when the signal is triggered; Based on the above calling relationships and binding relationships, construct a UML timing diagram for the monitoring source simulation software, accurately represent the interaction sequence and time relationship between objects in the timing diagram, so as to show the dynamic behavior during the system operation.
3. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 1, characterized in that: The step 2) specifically includes: 21) Obtain the XMI files of the UML class diagram and sequence diagram of the monitoring source simulation software; Use StarUML software to export the UML class diagram and sequence diagram of the monitoring source simulation software constructed in step 1) into XMI file format. The information required for code generation is defined in the packagedElement tag of the XMI file. 22) Parse the key information in the packagedElement tag in the XMI file; Identify and parse the content of the attribute type xmi:type=uml:DataType in the XMI file, which is generated based on the UML class diagram, and describes the basic data types used in the basic UML class of the monitoring source simulation software and the basic types provided by Qt used in the UML class of the monitoring source simulation software interface; Identify and parse the content of the attribute type xmi:type=uml:Class in the XMI file, which is generated based on the UML class diagram and defines the class, the class's attributes, the class's methods, and the class's inheritance relationship; Identify and parse the content of the attribute type xmi:type=uml:Collaboration in the XMI file, which is generated based on the UML sequence diagram and describes the relationship between objects, including objects, methods called by objects, calling relationships between objects, and signal and slot binding relationships.
4. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 1, characterized in that: The step 3) specifically includes: 31) Identify and parse the content of the attribute type xmi:type=uml:DataType in the XMI file and convert it into a data model, define a data model set D, D=(id1,name1), where id1 represents the type unique identifier and name1 represents the data type name; 32) Convert the content of the attribute type xmi:type=uml:Class in the XMI file that is identified and parsed into a class model, and define a class model set C, C=(I,A,O,G,M,stereotype2), where I represents the class information set, A represents the attribute set of the class, O represents the method set of the class, G represents the parent class set of the class, M represents the free member set of the class, and stereotype2 represents the identification type of the class; the class information set I=(id3,name3,type3,visibility3,abstract3), where id3 represents the unique identifier of the class, name3 represents the name of the class, ype3 represents the type of the class, visibility3 represents the access visibility of the class, and abstract3 represents the abstractness of the class; the attribute set A of the class = (id4, name4, type4, visibility4, static4), where id4 represents the unique identifier of the class attribute, name4 represents the name of the class attribute, type4 represents the type of the class attribute, visibility4 represents the access visibility of the class attribute, and static4 represents the staticness of the class attribute; the method set O of the class = (OI, RP, IP), OI represents the basic information set of the class method, OI = (id5, name5, vis5 ibility5,static5,abstract5,stereotype5), where id5 represents the unique identifier of the class method, name5 represents the name of the class method, visibility5 represents the access visibility of the class method, static5 represents the static nature of the class method, abstract5 represents the abstract nature of the class method, and stereotype5 represents the identification type of the class method; RP represents the set of class method return parameters, RP=(id6,type6), where id6 represents the unique identifier of the class method return parameter, and type6 represents the data type name of the class method return parameter; IP represents the set of class method input parameters, IP=(id7,type7,name7), where id7 represents the unique identifier of the class method input parameter, type7 represents the data type name of the class method input parameter, and name7 represents the class method input parameter name; the parent class set G=(id8,visibility8,specific8,general8), where id8 represents the unique identifier of the inheritance relationship, visibility8 represents the access visibility of the inheritance relationship, specific8 represents the unique identifier of the child class corresponding to the inheritance relationship, and general8 represents the unique identifier of the parent class corresponding to the inheritance relationship;The free member set M of the class = (id9, name9, type9, visibility9), where id9 represents the unique identifier of the free member, name9 represents the name of the free member, type9 represents the type of the free member, and visibility9 represents the access visibility of the free member; 33) Identify and parse the content of the attribute type xmi:type=uml:Collaboration in the XMI file and convert it into a timing diagram model, define a timing diagram model set T, T=(TI, TM, TA), where TI represents the timing diagram information set, TM represents the free member set of the timing diagram, and TA represents the attribute set of the timing diagram; the timing diagram information set TI=(id10,name10,visibility10,abstract10), where id10 represents the unique identifier of the timing diagram, name10 represents the name of the timing diagram, visibility10 represents the access visibility of the timing diagram, and abstract10 represents the abstractness of the timing diagram; the free member set TM of the timing diagram=(TMI,L,E,F), where TMI represents the basic information set of free members, L represents the lifeline element set, E represents the message element set, and F represents the fragment element set; the basic information set of free members TMI=(id11,name11,type11,visibility11), where id11 represents the free The unique identifier of the member, name11 indicates the name of the free member, type11 indicates the type of the free member, and visibility11 indicates the access visibility of the free member; the lifeline element set L = (id12, name12, type12, visibility12, represents12), where id12 indicates the unique identifier of the lifeline element, name12 indicates the name of the lifeline element, type12 indicates the type of the lifeline element, visibility12 indicates the access visibility of the lifeline element, and represents12 indicates the unique identifier of the time series diagram attribute set TA corresponding to the lifeline element; E = (id13, name13, type13, visibility13, signature13, receiveEvent13, sendEvent13, messageSort13), where id13 represents the unique identifier of the message element, name13 represents the name of the message element, type13 represents the type of the message element, visibility13 represents the access visibility of the message element, signature13 represents the unique identifier of the method of the class corresponding to the message element, receiveEvent13 represents the unique identifier of the fragment element set corresponding to the message element, and sendEvent13 represents the unique identifier of the fragment element set corresponding to the message element , messageSort13 represents the call type information of the message element; F = (id14, covered14, type14), where id14 represents the unique identifier of the fragment element, covered14 represents the unique identifier of the lifeline element set corresponding to the fragment element, and type14 represents the type of the fragment element; the attribute set of the timing diagram TA = (id15, name15, type15, visibility15, static15), where id15 represents the unique identifier of the attribute of the timing diagram, name15 represents the name of the attribute of the timing diagram, type15 represents the type of the attribute of the timing diagram, visibility15 represents the access visibility of the attribute of the timing diagram, and static15 represents the staticity of the attribute of the timing diagram.
5. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 4 is characterized in that: The step 32) specifically includes: 321) Identify all nodes with the attribute xmi:type="uml:Class" in the XMI file, and form a class model set with these nodes, denoted as C; in set C, create a class information set as an element of set C, denoted as CI, and for each class node in set C, extract the values of its attributes xmi:id, name, xmi:type, visibility and isAbstract, and store these values in set CI respectively, to form a class information set containing the attributes (id3, name3, type3, visibility3, abstract3); 322) Under the node with xmi:type="uml:Class" attribute, identify all child nodes with label ownedAttribute; create a class attribute set in set C, denoted as CA; for each ownedAttribute node, extract the values of its xmi:id, name, type, visibility and isStatic attributes, and store these values in the class attribute set CA respectively, forming a set containing attributes (id4, name4, type4, visibility4, static4); 323) Under the node with xmi:type="uml:Class" attribute, identify all child nodes with label ownedOperation; in set C, create a class method set, denoted as CO; in set CO, create a class method basic information sub-set, denoted as COOI; for each ownedOperation node, extract the values of its xmi:id, name, visibility, isStatic, isAbstract and xmi:type attributes, and store these values in the class method basic information set COOI, forming a set containing attributes (id5, name5, visibility5, static5, abstract5); Under the ownedOperation node, identify all child nodes with the label ownedParameter; create a class method return parameter sub-collection in the collection CO, denoted as CORP; create a class method input parameter sub-collection in the collection CO, denoted as COIP; for each ownedParameter node, classify it according to the value of its direction attribute: if the value of direction is return, extract the node's xmi:id and type attribute values, and store the values in the class method return parameter collection CORP, forming a collection containing the attributes (id6, type6); if the value of direction is in, extract the node's xmi:id, type, and name attribute values, and store the values in the class method input parameter collection COIP, forming a collection containing the attributes (id7, type7, name7); Under the ownedOperation node, identify all stereotype nodes of child nodes with the label xmi:Extension; for each stereotype node, extract the value of its value attribute and store these values in the class method basic information set COOI to form a set containing attributes (stereotype5); 324) Under the node with xmi:type="uml:Class" attribute, identify all child nodes with label "generalization"; create a parent class set of a class in set C, denoted as CG; for each generalization node, extract the values of its xmi:id, visibility, specific and general attributes, and store these values in the attribute set CG of the class, forming a set containing attributes (id8, visibility8, specific8, general8); 325) Under the node with xmi:type="uml:Class" attribute, identify all child nodes with label ownedMember; create a free member set of the class in set C, denoted as CM; for each ownedMember node, extract the values of its xmi:id, name, type and visibility attributes, and store these values in the class attribute set CM respectively, forming a set containing attributes (id9, name9, type9, visibility9); 326) Under the node with xmi:type="uml:Class" attribute, identify all stereotype nodes with child nodes labeled xmi:Extension; for each stereotype node, extract the value of its value attribute and store these values in the stereotype subcollection of the class model collection C to form a collection containing stereotype2 values.
6. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 5, characterized in that: The step 4) specifically includes: 41) Convert the name element of the element set I in the set C into the class name string [CIname3] of the Qt code, and define the class header file string of Qt; 42) Define the Qt class source code file string and initialize it to empty.
7. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 6 is characterized in that: The step 41) specifically includes: 411) Define the macro definition code [s_def] string and initialize it to empty; convert all letters of the Qt code class name string [CIname3] to uppercase characters to form a string [CINAME]; concatenate the strings "#ifndef", [CINAME], "_H\n#define", [CINAME], and "H\n" in sequence to form the macro definition Qt code [s_def] string; 412) Define the introduction inheritance relationship code [s_include_g] string and initialize it to empty; convert the id3 element of the element set I in the set C into the class's unique identification string [CIid3], and convert the type3 element of the set I in the set C into the class's type string [CItype3]; convert the general8 element of the set G of the set C into the parent class string [CGgeneral8] of the Qt code class; traverse all sets C and check whether there is a subset C_TEMP in the set C, so that [C_TEMP.I.id3] == [CGgeneral8], if there is a subset C_TEMP, and the content of the [C_TEMP.I.type3] string is the string format corresponding to the data type that comes with Qt, the [s_include_g] string is sequentially connected to "#include<", [C_TEMP.I.name3], ">"; otherwise, the [s_include_g] string is sequentially connected to "#include"", [C_TEMP.I.name3], """; 413) Define the import data type code [s_include_d] string and initialize it to empty; convert the id1 element in the set D to the data type identification string [D.id1] of the Qt code; convert the type4 element of the element A set in the set C to the attribute type string [CAtype4] of the class in the Qt code, convert the type7 element of the element IP set of the element O set in the set C to the class method input parameter type string [COIP.type7], and convert the type6 element of the element RP set of the element O set in the set C to the class method return parameter type string [CORP.type6]; Traverse the set of elements A in the set C. For each set of elements A, check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == CAtype4. If there is a subset C_TEMP, and the content of the [C_TEMP.I.type3] string is the string format corresponding to the data type that comes with Qt, the [s_include_d] string is sequentially connected to "#include<", [C_TEMP.I.name3], ">". Otherwise, the [s_include_d] string is sequentially connected to "#include"", [C_TEMP.I.name 3], """; If it does not exist, traverse all sets D and check whether there is a subset D_TEMP in set D, so that _D_TEMP.id1 == CAtype4. If the subset D_TEMP exists, and the content of the [D_TEMP.name1] string is the string format corresponding to the data type provided by Qt, the [s_include_d] string is sequentially connected to "#include<", [D_TEMP.name1], ">", otherwise the [s_include_d] string is sequentially connected to "#include"", [D_TEMP.name1], """; Traverse the element IP sets of element O in the current set C. For each element IP set, check whether there is a subset C_TEMP in set C such that C_TEMP.I.id3 == COIP.type7. If C_TEMP exists and C_TEMP.I.type3 is a Qt built-in type, the [s_include_d] string is sequentially connected to "#include<", [C_TEMP.I.name3], ">". Otherwise, the [s_include_d] string is sequentially connected to "#include"", [C_TEMP.I.name3], " ""; If it does not exist, then traverse all sets D and check whether there is a subset D_TEMP in set D, so that D_TEMP.id1 == COIP.type7. If the subset D_TEMP exists, and the content of the [D_TEMP.name1] string is the string format corresponding to the data type provided by Qt, the [s_include_d] string is sequentially connected to "#include<", [D_TEMP.name1], ">", otherwise the [s_include_d] string is sequentially connected to "#include"", [D_TEMP.name1], """; Traverse the element RP set of element O in the current set C. For each element RP set, check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == CORP.type6. If there is a subset C_TEMP and C_TEMP.I.type3 is a Qt built-in type, the [s_include_d] string is connected in sequence to "#include<", [C_TEMP.I.name3], ">", otherwise the [s_include_d] string is connected in sequence to "#include"", [C_TEMP.I.name3], "" "; If it does not exist, then traverse all sets D and check whether there is a subset D_TEMP in set D, so that D_TEMP.id1 == CORP.type6. If the subset D_TEMP exists, and the content of the [D_TEMP.name1] string is the string format corresponding to the data type that comes with Qt, the [s_include_d] string is sequentially connected to "#include<", [D_TEMP.name1], ">", otherwise the [s_include_d] string is sequentially connected to "#include", """, [D_TEMP.name1], """; 414) Define the introduction class start code [s_class_b] string and initialize it to empty, and add the class start code according to the class type; If the content of the [CGgeneral8] string is QObejct, the [s_class_b] string is connected in sequence: "class", [CIname3], ":public QObject{\n\tQ_OBJECT\npublic:\n\texplicit", [CIname3], "(QObject*parent=nullptr);\n"; If the content of the [CGgeneral8] string is in the string format corresponding to the Qt GUI class, then traverse the set C and check whether there is a subset C_TEMP in the set C such that C_TEMP.I.id3 == CGgeneral8. If there is a subset C_TEMP, then the [s_class_b] string is sequentially connected to "namespace Ui{\nclass", [CIname3], ";\n}\n\nclass", [CIname3], ":public", [C_TEMP.I.name3], "{\n\tQ_OBJECT\npublic:\n\texplicit", [CIname3], "(", [C_TEMP.I.name3], "*parent=nullptr);\n\t~", [CIname3], "();\nprivate:\n\tUi::", [CIname3], "*ui;\n"; If the content of the [CGgeneral8] string is empty, the [s_class_b] string is "class", [CIname3], "{\npublic:\n\t", [CIname3], "();\n"; 415) Define the attribute code [s_attributes] string of the class and initialize it to empty; [s_attributes] attribute string is divided into three strings [s_attributes_public], [s_attributes_protected], and [s_attributes_private] according to access rights, and each is initialized to empty; convert the name4 element of the element A set in the set C to the class attribute name string [CAname4] of the Qt code; convert the visibility4 element of the element A set in the set C to the string [CAvisibility4]; convert the static4 element of the element A set in the set C to the string [CAstatic4]; Traverse the element A set in the class set C. If CAvisibility4 == public exists, then [s_attributes_public] string is concatenated to "public:\n"; Traverse the element A set in the class set C. If CAvisibility4 == protected exists, then [s_attributes_protected] string is concatenated to "protected:\n"; Traverse the element A set in the class set C. If CAvisibility4 == private exists, then [s_attributes_private] string concatenates "private:\n"; Define a single attribute code [s_attribute] string. If set A satisfies CAstatic4==true, the [s_attribute] string is connected to static, otherwise the string is connected to "", and then the strings \t, [CAtype4], [CAname4], ;\n are connected in sequence; if CAvisibility4==public, connect [s_attribute] to the string [s_attributes_public]; if CAvisibility4==protected, connect [s_attribute] to the string [s_attributes_protected]; if CAvisibility4==private, connect [s_attribute] to the string [s_attributes_private]; Concatenate [s_attributes_public], [s_attributes_protected], and [s_attributes_private] to the [s_attributes] string; 416) Define the method code [s_functions] string of the class and initialize it to empty. The string stores the basic methods of the class; convert the stereotype5 element of the element OI set in the element O set in the set C to the string [COOI.stereotype5]; 417) Define the signal code [s_signals] string of the class, which stores the class signal, and initialize [s_signals] = "signals:\n"; convert the name9 element of the element M set in the set C to the free member name string [CMname9] of the class; convert the type9 element of the element M set in the set C to the free member type string [CMtype9] of the class; traverse the element M set in the class set C, if CMtype9 = uml:Signal, then the [s_signals] string is connected to "\t void", [CMname9], "();\n"; 418) Define the slot function code [s_slots] string of the class, which stores the class slot function; the [s_slots] string is divided into three strings [s_slots_public], [s_slots_protected], and [s_slots_private] according to access rights; traverse the COOI.stereotype5 == slots method element O set in the class set C, if COOI.visibility5 == public exists, then the [s_slots_public] string is connected to "public, slots:\n"; if COOI.visibilit y5==protected, then [s_slots_protected] string is concatenated with "protected, slots:\n"; if COOI.visibility5==private exists, then [s_slots_private] string is concatenated with "private, slots:\n", and then [s_slots_public] and [s_function], [s_slots_protected] and [s_function], [s_slots_private] and [s_function] are concatenated into [s_slots] string; 419) Define the macro definition end code [s_def_end] string and initialize it to empty; concatenate the strings "#endif / / ", [CINAME], and "_H\n" in sequence to form the macro definition end code [s_def_end] string.
8. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 7, characterized in that: The step 5) specifically includes: 51) Define the object call relationship code as the [s_function_body] string and initialize it to empty; define [s_define_variable] as the local variable definition string and initialize it to empty; define [s_call_function] as the calling function code and initialize it to empty; 52) Traverse the set T.TM, and then traverse the set T.TM.E; convert the messageSort13 element of the element E set of the element TM set in the set T to the string [T.TM.E.messageSort13]; convert the signature13 element of the element E set of the element TM set in the set T to the string [T.TM.E.signature13]; if T.TM.E.messageSort13 == synchCall exists, and COOI.id5 == T.TM.E.signature13 is found, proceed to step 53); otherwise, return to step 52); 53) Traverse the set T.TM.F; convert the id14 element of the element F set of the element TM set in the set T to the string [T.TM.F.id14]; convert the sendEvent13 element of the element E set of the element TM set in the set T to the string [T.TM.E.sendEvent13]. If T.TM.F.id14 == T.TM.E.sendEvent13 exists, traverse the set T.TM.L; convert the covered14 element of the element F set of the element TM set in the set T to the string [T.TM.F.covered14]; convert the id12 element of the element L set of the element TM set in the set T to the string [T.TM.L.id12]. If T.TM.F.cov exists ered14==T.TM.L.id12, then traverse the set T.TA; convert the represents12 element of the element L set of the element TM set in the set T to the string [T.TM.L.represent12]; convert the id15 element of the element TA set in the set T to the string [T.TA.id15], if T.TM.L.represents12==T.TA.id15 exists, then traverse the set CI; convert the type15 element of the element TA set in the set T to the string [T.TA.type15]; if CIid3==T.TA.type15 exists, store the matched I element and O element in the set C in the set C_Send, and record C_Send=[I,O]; 54) Traverse the set T.TM.F; convert the receiveEvent13 element of the element E set of the element TM set in the set T to the string [T.TM.E.receiveEvent13]; if T.TM.F.id14==T.TM.E.receiveEvent13 exists, traverse the set T.TM.L, if T.TM.F.covered14==T.TM.L.id12 exists, traverse the set T.TA; if T.TM.L.represents12==T.TA.id15 exists, traverse the set CI; if CIid3==T.TA.type15 exists; then store the matched I element and O element in the set C in the set C_Receive, C_Receive=[I,O]; 55) Traverse the elements I and O in set C, and concatenate [CIname3], "::", and [COOI.name5] into a string [s_function_name]; 56) Define [s_rtn_params] to return a code string and initialize it to empty; define [s_rtn_type] to return a type string and initialize it to empty; convert the type6 element of the element RP set of the element O set in the set C_Receive to the string [C_Receive.O.RP.type6]; traverse the set C, if there is a subset C_TEMP, and C_TEMP.I.id3 == C_Receive.O.RP.type6, then connect the [s_rtn_type] string to [C_TEMP.I.name3]; if not found, traverse all sets D, if there is a subset D_TEMP, and it satisfies If D_TEMP.id1 == CORP.type6, then [s_rtn_type] string is connected to [D_TEMP.name1]; determine whether [s_rtn_type] string is void, if not, then string [s_rtn_params] is connected to [s_rtn_type], "_rtn_", [no], "=" in sequence, where no indicates the variable of the [s_rtn_type] type in the current function, and in declaring local variables string [s_define_variable], it is connected to [s_rtn_type], "", [s_rtn_type], "_rtn_", [no], ";\n" in sequence; 57) Define the parameter code string [s_in_params] and initialize it to empty; convert the type7 element of the element IP set of the element O set in the set C_Receive to the string [C_Receive.O.IP.type7]; search for other subsets C_TEMP except the set C from the set C, if C_TEMP.I.id3 == C_Receive.O.IP.type7 exists, then connect the [s_in_type] string to [C_TEMP.I.name3]; if not found, traverse all sets D, if a subset D exists _TEMP, and D_TEMP.id1 == COIP.type7, then [s_in_type] string is connected to [D_TEMP.name1]; string [s_in_params] is connected to [s_in_type], "_in_", [no] in sequence, where no indicates the variable of type [s_in_type] in the current function, and in declaring local variables string [s_define_variable], it is connected to [s_in_type], "", [s_in_type], "_in_", [no], ";\n" in sequence; 58) Convert the name3 element of the element I set in the set C_Receive to the string [C_Receive.I.name3]; if C_Receive.I.name3 == CIname3, concatenate the string [s_call_function] "\t", [s_rtn_params], COOI.name5, "(", [s_in_params], "); \n"; 59) Convert the static5 element of the element O set OI set in the set C_Receive to the string [COOI.static5]; if COOI.static5 = true, concatenate the string [s_call_function] "\t", [s_rtn_params], [C_Receive.I.name3], "::", [COOI.name5], "(", [s_in_params], "); \n"; 510) When COOI.static5 = false, the string [s_temp_object] is concatenated with [C_Receive.I.name3], _object_, and [no], where no represents the variable of the [C_Receive.I.name3] type in the current function, and the string [s_define_variable] used to declare local variables is concatenated with [C_Receive.I.name3], [C_Receive.I.name3], "_object_", [no], ";\n"; and the string [s_call_function] is concatenated with \t, [s_rtn_params], [s_temp_object], [COOI.name5], "(", [s_in_params], ");\n"; 511) Connect [s_function_body] to [s_define_variable] and multiple [s_call_function] strings in sequence, and assign them to [s_function_body] in step 424).
9. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 8, characterized in that: The step 6) specifically includes: 61) The signal and slot binding relationship code is the [s_signal_slots_connects] string, which is initialized to empty; define the [s_signal_slots_connect] string, initialized to empty, which represents a string of signal and slot binding relationship code; 62) While traversing the set T, traverse the set CM. If the string formed by connecting CIname3, ::, and CMname9 in sequence is the same as T.TI.name10, go to step 63); 63) Traverse the set T.TM and the set T.TM.E. If there is T.TM.E.messageSort13==asynchSignal, and CMid9==T.TM.E.signature13, then store the matched I element and M element in the set C in the C_Signal set, recorded as C_Signal=[I,M]; 64) Traverse the set T.TM and the set T.TM.E. If COOI.id5 == T.TM.E.signature13 exists, store the I element and O element in the matching set C in the C_Slot set, recorded as C_Slot = [I, O]; 65) Traverse the set T.TM.E and the set T.TM.F at the same time. If T.TM.F.id14==T.TM.E.receiveEvent13 exists, then traverse the set T.TM.L; if T.TM.F.covered14==T.TM.L.id12 exists, then go to step 66); 66) Convert the name12 element of the element L of the element TM set in the set T to the string [T.TM.L.name12], convert the name3 element of the element I set in the set C_Signal to the string [C_Signal.I.name3], convert the name9 element of the element M set in the set C_Signal to the string [C_Signal.M.name9], convert the name3 element of the element I set in the set C_Slot to the string [C_Slot.I.name3], and convert the name5 element of the element OI set in the set C_Slot to the string [C_Slot.O.OI.name5]; if T.TM.L.name12 contains the character "*", then [s_signal_slots_connect] connects them in sequence "\t", "connect(this,&", [C_Signal.I.name3], "::", [C_Signal.M.name9], ",", [T.TM.L.name12], ",&", [C_Slot.I.name3], "::", [C_Slot.O.OI.name5], "); \n"; otherwise [s_signal_sl ots_connect] Connect "\tconnect(this,&", [C_Signal.I.name3], "::", [C_Signal.M.name9], ",&", [T.TM.L.name12], ",&", [C_Slot.I.name3], "::", [C_Slot.O.OI.name5], ");\n" in sequence; 67) Connect multiple [s_signal_slots_connect] in sequence into the [s_signal_slots_connects] string and assign it to [s_signal_slots_connects].
10. The Qt code generation method based on UML class diagram and timing diagram monitoring source simulation software according to claim 9, characterized in that: The step 7) specifically includes: 71) Create Qt code header file [CIname3].h: concatenate the macro definition code [s_def] string, the inheritance relationship code [s_include_g] string, the data type code [s_include_d] string, the class start code [s_class_b] string, the class attribute code [s_attributes] string, the class method code [s_functions] string, the class signal code [s_signals] string, the class slot function code [s_slots] string, and the macro definition end code [s_def_end] string together in sequence and store them in the [CIname3].h file; 72) Create the Qt code source file [CIname3].cpp: splice together the import class code [s_include_g] string, the constructor code [s_functions_constructor] string containing the signal and slot binding relationship code [s_signal_slots_connects] string, the destructor code [s_functions_destructor] string, and the member function code [s_functions] string containing the object call relationship code [s_function_body] string, and store them in the [CIname3].cpp file.