Method for generating embedded man-machine interface code based on OpenGL
By parsing the human-computer interface model data of the OnModel tool, and using an XML parser and adapter layer interface to generate OpenGL-based embedded C code, the problems of cumbersome human-computer interface design and cross-platform compatibility are solved, and efficient, concise and easy-to-maintain code generation is achieved.
Patent Information
- Application Number
- CN202510187515.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2045-02-20
AI Technical Summary
Existing technologies often involve cumbersome human-computer interface designs that are prone to errors, make it difficult to achieve cross-platform compatibility, and require time-consuming and labor-intensive manual code modification, while lacking self-developed, efficient code generation tools.
By parsing the human-computer interface model data of the OnModel tool, the model data is divided into different modules using an XML parser, and a code framework is generated using recursive functions. The code is supplemented by the adapter layer interface to generate embedded C code based on OpenGL.
It achieves cross-platform compatible embedded C code generation, simplifies the code generation process, improves the conciseness and accuracy of generated code, reduces code complexity, and enhances code maintainability and reusability.
Smart Images

Figure CN120029620B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of code automatic generation, and particularly relates to an embedded man-machine interface code generation method based on OpenGL. BACKGROUND
[0002] In the field of aerospace, the importance of man-machine interface in software system is increasingly prominent. As the bridge for user and computer system interaction, the design quality of man-machine interface directly affects user experience and system operation convenience. The traditional manual coding process is tedious, error-prone and difficult to realize cross-platform compatibility. When the interface needs to be optimized, it is time-consuming and laborious to manually modify the code. Based on the above problems, the man-machine interface is designed through modeling, and then the cross-platform code is automatically generated. This way can improve the design efficiency and reduce the development cost.
[0003] Current mature tools such as SCADE DISPLAY are monopolized by foreign countries. With the improvement of China's industrial software independent research and development ability, the benchmarking tools of man-machine interface design software are also developing rapidly. OnModel, as a model-based detailed design tool independently developed by our unit, provides a multifunctional graphic design and development environment for embedded man-machine interface. The automatic generation of man-machine interface code is a key function of the tool.
[0004] The application aims at the man-machine interface code generation requirement of OnModel tool, and realizes the automatic generation of C code based on the self-developed adaptation layer by analyzing the man-machine interface model data created in the OnModel tool. On this basis, the function of OnModel tool is perfected and optimized. SUMMARY
[0005] (I) Technical problem to be solved
[0006] The technical problem to be solved by the application is how to provide an embedded man-machine interface code generation method based on OpenGL to solve the problem of automatically generating embedded C code from man-machine interface model.
[0007] (II) Technical scheme
[0008] In order to solve the above technical problems, the application provides an embedded man-machine interface code generation method based on OpenGL, which comprises the following steps:
[0009] Firstly, parse the file and divide the model data into different modules
[0010] The tags in the XML file are parsed by the XML parser, and the elements in the XML are divided into data of different modules;
[0011] Secondly, generate code according to different data
[0012] According to different data obtained by the first step, different functions are used for processing, and a recursive function is used to generate a code framework for the sub-graph element information;
[0013] In the third step, the model code is supplemented according to the interface provided by the adaptation layer
[0014] In order to simplify the generation process, the instructions of OpenGL are encapsulated in the adaptation layer, and the adaptation layer provides an interface matched with the sub-graph element type, the adaptation layer interface is called according to the sub-graph element type, the code is supplemented, and the code generation is completed.
[0015] (Three) beneficial effects
[0016] The application provides an OpenGL-based embedded man-machine interface code generation method, which has the following characteristics:
[0017] (1) By analyzing the content of the XML file, the data is divided into different modules, and the compliance of the data is checked, and then the data is generated into corresponding C code through the corresponding generation function, so that the analysis and code generation of the man-machine interface file of the OnModel tool are realized, and the key function of the OnModel tool is supported.
[0018] (2) The encapsulated adaptation layer is used, and the complex call of OpenGL is avoided in the code generation process, and the adaptation layer interface matched with the graph element type is directly called, and then the OpenGL instruction is called by the adaptation layer, so that the code generation process is simplified, and the simplicity and accuracy of the generated code are improved.
[0019] (3) The XML file obtained by parsing is generated into multiple header files and source files according to functions, the files are called with each other, the modular code generation is completed, the coupling between various functions is reduced, the code complexity is reduced, the maintainability is improved, and the code integration of subsequent users is facilitated. DETAILED DESCRIPTION
[0020] Figure 1 The man-machine interface code generation and use process of the application;
[0021] Figure 2 The XML file and the generated code file relationship diagram;
[0022] Figure 3 The generation function and the calling relationship diagram;
[0023] Figure 4 The line width XML content and code diagram;
[0024] Figure 5 The texture XML content and code diagram;
[0025] Figure 6 XML content and code diagram is defined for data;
[0026] Figure 7 Code diagram is defined for configuration data;
[0027] Figure 8 XML content and code diagram is defined for input and output;
[0028] Figure 9 Function diagram is defined for initialization;
[0029] Figure 10 Framework diagram is defined for drawing function;
[0030] Figure 11 Function diagram is defined for interaction;
[0031] Figure 12 Code file call relationship diagram is defined;
[0032] Figure 13 Arc XML content and generated code diagram;
[0033] Figure 14 Reference model XML content and generated code diagram. DETAILED DESCRIPTION
[0034] In order to make the purpose, content and advantages of the present application more clear, the specific embodiments of the present application are described in further detail below in combination with the drawings and examples.
[0035] Based on the actual function and performance requirements of the model-based software analysis design and verification tool OnModel, after the user completes the human-computer interface design through the modeling method in the tool, the model needs to be generated and embedded into C code, the generated C code calls OpenGL for graphic rendering, and cross-platform compatibility is achieved. Through the modeling method to design the human-computer interface, and then automatically generate embedded code, the time of manual coding can be significantly reduced, so that the user can pay more attention to the design and improve the efficiency. The designed model and code can be reused, and the reusability is improved.
[0036] The application provides an OpenGL-based embedded man-machine interface code generation method. The generation method can generate an OpenGL-based graphic rendering C code from a man-machine interface model in an onModel tool. Since the OpenGL has a cross-platform feature, the generated C code can be applied to any target platform, reducing code repetitive writing. The man-machine interface code model in the onModel tool is stored as an XML format file, and the application provides a method for automatically generating a C code from the model file, comprising: using an XML parser to parse the file, dividing the model data into different modules; calling a code generation function according to different module data to generate the code; and calling an adaptation layer interface to complete the code generation.
[0037] The application aims to solve the problem of automatically generating embedded C code for the man-machine interface model of the self-developed tool OnModel of the unit in the field of MBSE.
[0038] The whole man-machine interface code generation and use process of onModel is as shown in Figure 1 The man-machine interface model data in onModel can be divided into three files according to functions: a resource file, a data definition file and a model file. The resource file stores five resource tables of font, texture, gradient, line width and line type, the data definition file stores a custom data type used in the model, and the model file stores the graphic primitive data of the model. These files are stored in XML format. The C code corresponding to the man-machine interface model is automatically generated from the files, and the code includes resource code, model drawing code, interactive code, configuration code and data definition code. In the generated code, the adaptation layer interface encapsulated by onModel according to the graphic primitive and the OpenGL feature is called to complete the graphic rendering. When the user needs to use the generated code, the user needs to manually write the window initialization and context initialization code, and the interface drawing part directly calls the automatically generated code.
[0039] The application mainly focuses on the implementation of the process from the onModel man-machine interface file to the C code.
[0040] The first step is to parse the file and divide the model data into different modules
[0041] The tags in the XML file are parsed by the XML parser, and the elements in the XML are divided into different module data, including:
[0042] The resource file is parsed using the XML parser to obtain resource data, and then the data definition is obtained from the data definition file. The model file is parsed, and the model data is divided into configuration data, interactive data, referenced model, sub-graphic primitive data and input and output according to the keywords in the model file.
[0043] Configuration data describes the canvas size, canvas zoom ratio. Interaction data refers to mouse, keyboard, etc. Reference model refers to other models referenced in the top-level model. The reference model can also include reference models, input and output, and primitive data, which are traversed recursively. Sub-primitive data is the primitive data in the model, such as lines, polygons, circles, etc. Input and output are the input and output of the top-level model, as well as local variables.
[0044] During the parsing of the model file, the model data is checked according to the resource data and data definition data. If there is no defined resource data or data type in the model data, an error prompt is given and the code generation is aborted.
[0045] Step 2, generate code according to different data
[0046] According to the different data obtained in the first step, different functions are used for processing. For the sub-primitive information, a recursive function is used to generate the code framework, including:
[0047] Generate resource code. For each resource type, a header file and a source file are generated separately. Simple data is declared in array form, and complex data is directly loaded into OpenGL. When resources are used in primitives, resources are obtained through array indexing.
[0048] Generate data definition code. All data definitions are generated into a header file and a source file for other code files.
[0049] Configuration data is separately generated into a header file and a source file for user window initialization and context initialization.
[0050] The top-level model and each reference model are separately generated into corresponding header files and source files. For each model, the header file is divided into three parts: macro definition for obtaining and setting input and output, model structure body definition, and model initialization and drawing function declaration. The input parameters of the function are the model structure body. The source file is the implementation of the function. In the initialization function, the initialization of the model input and output variables is performed, and the initial value is obtained from the input and output data. In the drawing function, according to the number of sub-primitives and the hierarchical structure of the model, annotations and parentheses are generated. The annotations include the name, type and unique identifier of the sub-primitive.
[0051] If there is an interactive type of primitive in the primitive, interactive code is generated separately. All interactive code implementations are in a source file, which includes mouse position acquisition, keyboard key information acquisition, mouse event setting, and keyboard event setting functions. Interactive code does not change with the model, and the interactive event processing logic is in the model code.
[0052] Step 3, supplement the model code according to the interface provided by the adaptation layer
[0053] In order to simplify the generation process, the instructions of OpenGL are all encapsulated in the adaptation layer, and the adaptation layer provides an interface matching the sub primitive type. The adaptation layer interface is called according to the sub primitive type, the code is supplemented, and the code generation is completed. In this way,
[0054] In the second step, the drawing function of the model code generates a hierarchical structure according to the sub primitive information. This step needs to match the adaptation layer interface according to the sub primitive type. The sub primitive attribute is used to determine the resources, mode, and input parameters of the interface used by the drawing primitive, so as to generate the drawing code.
[0055] Embodiment 1
[0056] The matching relationship between the onModel file and the generated code file is shown in Figure 2 The color, font, gradient, line width, and line type are resources, and each resource file is stored by using a separate xml to generate a corresponding header file and a source file. The data definition file also generates a header file and a source file. The top-level model file generates a top-level model code and a configuration code. If a reference model is used in the top-level model, the code is generated by using the reference model file. If an interactive primitive is used in the top-level model, the interactive code and the interactive code function declaration header file are generated, which are used by other code files.
[0057] The specific implementation steps of the embedded human-computer interface code generation based on OpenGL are as follows:
[0058] First step, parsing the file and dividing the model data into different modules
[0059] The resource files are parsed by using an XML parser and are divided into colors, fonts, gradients, line widths, and line types according to the resource type. Among them, the color, gradient, and line type resource XML and the data storage structure are shown in the following table:
[0060]
[0061]
[0062] The data definition file is parsed, and the data definition file and the storage structure are shown in the following table:
[0063]
[0064] The top-level model file is parsed, and the model data is divided into configuration data, reference model, sub primitive data, and input and output according to the XML tag.
[0065] The configuration data includes canvas size and scaling ratio. The reference model refers to the data of the type "referenceContainer" in the sub-graph element. This type of element gives the position, size, scaling, and modifiable attribute information in the top-level model file. The specific model definition needs to obtain the file address of the reference model through the "file" tag, and then parse the reference model file to obtain the reference model data separately. The parsing of the reference model file does not need to parse the configuration data again, and the other parsing methods are consistent with the top-level model file. The sub-graph data refers to the data obtained through the "children" tag in the top-level model file. There are several sub-graphs in a top-level model, and the sub-graphs can also have a next-level sub-graph. The input and output data refers to the input and output of the top-level model, as well as local variables. The matching relationship between the key tags in XML and the data is as follows:
[0066]
[0067]
[0068] Second step: generate code according to different data
[0069] Based on the results of the first step, different functions are used to generate corresponding code files according to different types of data. Figure 3 Main functions and call relationships for generating code.
[0070] 1. Resource data
[0071] The line width, line type, color, and font data in the resource data are relatively small, and constant arrays are generated directly when generating code. The texture and gradient are directly called to adapt to the OpenGL interface when generating code. Figure 4 XML content and generated code for line width, Figure 5 Texture XML content and generated code.
[0072] 2. Data definition
[0073] The data definition code is generated using the "generateDefinition" function. The generated file is named "om_global_definition.h", and the XML content and generated code are as shown in Figure 6
[0074] 3. Configuration data
[0075] The configuration data includes canvas width, height, horizontal coordinate scaling ratio, and vertical coordinate scaling ratio. A header file and a source file are generated respectively, with the file names "target_configuration.h / c". The function is to complete the definition of the configuration data. The generated code is as followsFigure 7 Figure 1 shows.
[0076] 4. Input and output data
[0077] For each input and output, a set and get method is generated using macro definition, and no local variable is needed. A structure containing input, output and local variable is also generated, which is the parameter of the subsequent graph drawing function. Figure 8 Figure 2 shows the XML content and the generated code of input and output.
[0078] 5. Sub-graph element
[0079] A model contains two main functions: initialization and drawing. The initialization function is called at the beginning, and the drawing function is called once in each running cycle. The function of the initialization function is to initialize the input and output and local variable according to the initial value in the XML. Figure 9 Figure 3 shows the generated initialization function.
[0080] The function of the drawing function is to call the adaptation layer to complete the graph drawing according to the sub-graph element information. According to the hierarchical structure of the sub-graph element, the corresponding structure framework is generated. The sub-graph element can be nested, and the traversal of all sub-graph elements is realized by recursion. The positioning of the graph element is realized by using the unique identifier OID. Figure 10 Figure 4 shows the XML content and the generated framework.
[0081] 6. Reference model
[0082] In order to improve the code modularization, a header file and a source file are generated for each reference model, which are called in the top-level model code. The generation method is consistent with the top-level model.
[0083] 7. Interaction data
[0084] If there is an interactive graph element in the model, a source file independent of the model is generated to obtain mouse and keyboard events. This file contains functions to obtain the position of the mouse and keyboard key events. This file is directly copied from the template library of the onModel tool. The functions needed in the actual sub-graph element are declared in "om_imported_function.h" for the model code to call. Figure 11 Figure 5 shows part of the source code.
[0085] Finally, the calling relationship between all generated code files is shown in Figure 12 Figure 6.
[0086] Third step, according to the interface provided by the adaptation layer, supplement the model code
[0087] In the second step, the function framework of the rendering function is generated according to the hierarchical relationship between the subgraph elements, and on this basis, the interface corresponding to the adaptive layer is matched according to each subgraph element type, and the code position is determined by the unique identifier. The following table lists the matching relationship between some subgraph element types and interfaces:
[0088]
[0089] The properties of the subgraph element match the resource selection, mode setting and interface input. Taking the arc graph element as an example, "lineWidth" in "properties" indicates the line width, which corresponds to "mglIndexLineWidthi" in the code. Figure 13 For the XML of the arc and the generated code, the attribute matching relationship is shown in the following table. Since "fillColor" is -1, only the outer contour is drawn, and the texture and gradient attributes are not used.
[0090]
[0091]
[0092] When the subgraph element is a reference model, the properties part is generated into the code as the input value of the reference model. Figure 14 For the XML content of a reference model and the generated code, the matching relationship is shown in the following table.
[0093]
[0094] Example 2:
[0095] The OpenGL-based embedded human-computer interface code generation method mainly based on the following steps:
[0096] First step, parse the file and divide the model data into different modules
[0097] The tags in the XML file are parsed by the XML parser, and the elements in the XML are divided into data of different modules;
[0098] Second step, generate code according to different data
[0099] According to the different data obtained by the first step, different functions are used for processing, and for the subgraph element information, a recursive function is used to generate the code framework;
[0100] Third step, according to the interface provided by the adaptive layer, supplement the model code
[0101] In order to simplify the generation process, the instructions of OpenGL are all encapsulated in the adaptation layer, and the adaptation layer provides an interface matched with the sub primitive type, the adaptation layer interface is called according to the sub primitive type, the code is supplemented, and the code generation is completed.
[0102] Technical advantages and effects:
[0103] The application provides an embedded man-machine interface code generation method based on OpenGL, and the method has the following characteristics:
[0104] (1) By analyzing the content of the XML file, the data is divided into different modules, and the compliance of the data is checked, then the data is generated into corresponding C code through the corresponding generation function, the man-machine interface file of the OnModel tool is parsed and code generation is realized, and the key function of the OnModel tool is supported.
[0105] (2) The encapsulated adaptation layer is used, and the complex call of OpenGL is avoided in the code generation process, the adaptation layer interface matched with the primitive type is directly called, and then the OpenGL instruction is called by the adaptation layer, so that the code generation process is simplified, and the simplicity and accuracy of the generated code are improved.
[0106] (3) The XML file parsed is generated into multiple header files and source files according to functions, the files are called each other, the modular code generation is completed, the coupling between various functions is reduced, the code complexity is reduced, the maintainability is improved, and the code integration of subsequent users is facilitated.
[0107] The above only describes the preferred embodiments of the application, and it should be pointed out that, for ordinary skilled in the art, without departing from the technical principles of the application, a plurality of improvements and modifications can be made, and these improvements and modifications should be regarded as the protection scope of the application.
Claims
1. A method for generating embedded human-computer interface code based on OpenGL, characterized in that, The method includes the following steps: The first step is to parse the file and divide the model data into different modules. The XML parser parses the tags in the XML file, dividing the elements in the XML file into different modules of data; Step 2: Generate code based on different data. Based on the different data obtained from the first step of parsing, different functions are used for processing. For the sub-primitive information, a recursive function is used to generate the code framework. The third step is to supplement the model code based on the interfaces provided by the adaptation layer. The OpenGL instructions are encapsulated in the adapter layer, which also provides interfaces that match the sub-primitive types. By calling the adapter layer interface according to the sub-primitive type, the code is supplemented and the code generation is completed. in, The second step includes: Generate resource code, and generate a separate header file and source file for each resource type; Generate data definition code, generating all data definitions into a header file and a source file for use by other code files; The configuration data is generated into a separate header file and source file for users to use when initializing the window and context. The top-level model and each referenced model generate their own header and source files. For each model, the header file is divided into three parts: macro definitions for getting and setting input and output, model structure definition, and model initialization and drawing function declarations, where the input parameters of the functions are all model structures. The source file implements the initialization and drawing functions. In the initialization function, the model's input and output variables are initialized, with initial values obtained from the input and output data. In the drawing function, comments and parentheses are generated based on the number of sub-primitives and the hierarchical structure of the model. The comments include the name, type, and unique identifier of the sub-primitives. If there are interactive elements, separate interaction code is generated. All interaction code implementations are in one source file, which includes functions for obtaining mouse position, obtaining keyboard key information, setting mouse events, and setting keyboard events. The interaction code does not change with the model; the interaction event handling logic is performed in the model code. The third step includes: In the second step, the drawing function of the model code generates a hierarchical structure according to the sub-primitive information; the third step requires matching the adaptation layer interface according to the sub-primitive type. The sub-primitive attributes are used to determine the resources, modes, and input parameters of the interface used to draw the primitives, thereby generating the drawing code. In the third step, a function framework for drawing functions is generated based on the hierarchical relationship between sub-primitives. According to the type of each sub-primitive, the interface corresponding to the adaptation layer is matched, and the code location is determined by a unique identifier. The attributes of the sub-primitives are matched with resource selection, mode settings, and interface inputs. When the sub-primitive is a reference model, the attribute part is generated into the code as the input value of the reference model.
2. The method for generating embedded human-computer interface code based on OpenGL as described in claim 1, characterized in that, The first step includes: The XML parser first parses the resource file to obtain the resource data; then it obtains the data definition from the data definition file; it parses the model file and, based on the keywords in the model file, decomposes the model data into configuration data, interaction data, reference models, subgraph metadata, and input / output data. The configuration data describes the canvas size and canvas scaling ratio; Interactive data refers to mouse and keyboard data; A reference model refers to other models referenced in the top-level model, which are traversed recursively. Subgraph metadata is graph metadata in the model; Input and output data include the input and output data of the top-level model, as well as local variables; During the parsing of the model file, the model data is checked based on the resource data and data definition data. If undefined resource data or data types are found in the model data, an error message is given and code generation is stopped.
3. The method for generating embedded human-computer interface code based on OpenGL as described in claim 1, characterized in that, The human-computer interface model data is divided into three types of files according to function: resource files, data definition files, and model files. The resource files store five resource tables: fonts, textures, gradients, line widths, and line types. The data definition files store the custom data types used in the model. The model files store the model's graphic data. All three types of files are stored in XML format.
4. The method for generating embedded human-computer interface code based on OpenGL as described in claim 1, characterized in that, In the first step, the reference model refers to the data of type "referenceContainer" in the sub-primitives. Primitives of type "referenceContainer" are given position, size, scaling, and modifiable attribute information in the top-level model file. The specific model definition needs to obtain the file address of the reference model through the "file" tag, and then parse the reference model file to obtain the reference model data separately. The sub-primitive data refers to the data obtained through the "children" tag in the top-level model file. A top-level model has several sub-primitives, and sub-primitives can also have sub-primitives in the next layer.
5. The method for generating embedded human-computer interface code based on OpenGL as described in claim 1, characterized in that, The data definition code is generated using the "generateDefinition" function; the generated file is named "om_global_definition.h".
6. The method for generating embedded human-computer interface code based on OpenGL as described in claim 1, characterized in that, Configuration data: The configuration data includes canvas width and height, horizontal scaling ratio and vertical scaling ratio; a header file and a source file are generated respectively, named "target_configuration.h / c", which complete the definition of the configuration data; Input / output data: For each input / output, generate setup and retrieval methods using macro definitions; also, generate a structure containing input, output, and local variables, which will serve as the formal parameters for subsequent graphics drawing functions; Sub-primitives: The top-level model and each reference model contain two functions: an initialization function and a drawing function. The initialization function is called at the beginning, and the drawing function is called once in each runtime cycle. The initialization function initializes the input, output, and local variables according to the initial values in the XML. The drawing function calls the adaptation layer to complete the graphic drawing based on the sub-primitive information and generates the corresponding structural framework according to the hierarchical structure of the sub-primitives. When sub-primitives are nested, recursion is used to traverse all sub-primitives. Unique identifiers (OIDs) are used to locate the primitives. Reference Model: Each reference model generates a separate header file and source file, which are then called in the top-level model code; Interactive Data: If there are interactive primitives in the model, a source file for obtaining mouse and keyboard events, independent of the model, is generated. The source file contains functions for obtaining the mouse position and keyboard key events. The source file is copied directly from the template library of the onModel tool. The functions that need to be used in the actual sub-primitives are declared in "om_imported_function.h" for the model code to call.
Citation Information
Patent Citations
DAC adaptation layer in MATLAB and CCS combined development mode and design method thereof
CN116578286A
XML-based Lustre code online generation tool design method
CN118916012A