Background
In the existing software development, if a rich interface effect is required, a design scheme of separating data from display is generally adopted, and particularly situation software, especially situation software developed based on a GIS platform, has the requirement of frequently needing to be displayed in a copy mode besides normal real-time data generation promotion.
For the multi-disc function, besides direct data recording and reading, sub-functions such as high speed, low speed, progress jump and the like are involved, and a powerful data storage mechanism is necessary to realize the functions, such as:
(1) From the perspective of saving storage space, the storage change data is saved most, but the data retrieval is required to be added during the jump to ensure that all information of the current situation can be loaded at any time point of the jump, so that additional development work is obviously added, the data reading time is prolonged, and the burden is also caused on the flexibility of secondary processing of data storage;
(2) From the viewpoint of data storage format, in order to save storage space and shorten parsing time, a hexadecimal data storage format with a fixed frame length and a fixed structure is usually most suitable, but in the actual situation, due to the influence of business requirements, during development, even after software delivery, the data content is still likely to have a modification requirement, which affects the compatibility and stability of software.
For the above two problems, the prior art solutions usually solve the above two problems by saving the complete situation at regular time, so that the situation can be completely restored when reading from any record; however, as described above, this method requires a fixed field structure to be designed for storage, and cannot expand a program.
In summary, the conventional development method is tested by both the storage method and the storage format when the multi-disk requirement is met and the service requirement is not clear.
Disclosure of Invention
The purpose of the invention is as follows: the invention aims to solve the defects in the prior art, and provides a method for realizing situation copy under a GIS platform, which can provide a scheme mechanism with simple storage and convenient expansion aiming at the disadvantages of poor data storage compatibility, complex data reading and retrieving work, influence on version compatibility due to data structure change caused by service change and the like of the traditional scheme under the condition of copy requirements and variable service requirements.
The technical scheme is as follows: the invention relates to a method for realizing a situation reply under a GIS platform, which comprises the following steps:
step (1), defining a function template capable of mutually converting any data type and JSON character strings, and specializing the function template according to a built-in data type of a C + + standard and a commonly used data type (such as QString, qvector and the like) in a development background;
step (2), defining two macros which can serialize and deserialize any data type instance and JSON character strings, so that a developer can use the two macros to perform data conversion regardless of the parameter type and only pay attention to the parameter content in the data type;
designing a corresponding data type representing scene information, wherein the data type comprises a class and a structural body;
step (4), defining and obtaining a conversion function between the scene information data type and the JSON character string by using the macro in the step (2); specifically, the macro in the step (2) is used as a function statement for the scene information data type, the template function in the step (1) is called for all members of the scene information data type in the function body respectively to obtain the definition of a conversion function, and the function can complete the interconversion between the scene information data type and the JSON character string;
step (5), the scene information generator creates a corresponding scene information data type object by taking each data refresh period (for example, 1 second) as a time unit, serializes the object to generate a JSON character string by using the function defined in the step (4), stores the JSON character string in data and generates a data record;
step (6), reading the stored JSON character string record according to time points during the multi-disk control; here the point in time is determined by the actual situation,
and (7) the situation display renderer deserializes and restores the JSON character strings into scene information data type objects by using the conversion functions defined in the step (4), and rendering control is performed on a display layer to realize situation display.
Further, the step (2) carries out serialization and deserialization conversion between any data type instance and the JSON character string through two macros; the user-defined data type is mainly a user-defined type or a structural body, wherein one macro carries out an integral encapsulation function, and the user-defined data type is determined to be serialized or deserialized according to parameters; the other macro calls a function template in a text replacement mode to complete the conversion between the member variables of the user-defined data type object and the JSON character strings; the developer uses the two macros in combination to complete conversion definition of the custom data type and the JSON character string, and data conversion which only focuses on the variable content of the member of the data type object and does not depend on the variable type of the member is carried out.
Has the beneficial effects that: the invention can be used for situation display under a GIS platform, and has a high-efficiency and flexible data exchange mode (suitable for C + + language). The method can be used for updating the parameters in real time, is also suitable for scene replication allowing the user to perform progress control after storage, and has strong applicability. In comparison with the prior art, the method specifically comprises the following advantages,
1) By utilizing the technical modes of macro definition, templates and the like, a uniform conversion function capable of serializing and deserializing various custom types (including built-in data types) and JSON character strings is realized;
2) For the data generation module, the object of the scene information data type generated in each time unit is converted into a JSON character string for storage or directly forwarded.
3) For the rendering module, the JSON character strings which are received in butt joint need to be analyzed and reduced into scene information data type objects, and situation display is achieved according to object parameters.
Detailed Description
The technical solution of the present invention is described in detail below, but the scope of the present invention is not limited to the embodiments.
As shown in fig. 1 and fig. 2, the method for implementing a situation copy under a GIS platform of this embodiment includes the following steps:
step (1), defining a function template capable of mutually converting any data type and JSON character strings, and specializing the function template according to a built-in data type of a C + + standard and a commonly used data type (such as QString, qvector and the like) in a development background;
step (2), two macros which can carry out serialization and deserialization between any data type instance and the JSON character string are defined, so that a developer can use the two macros to carry out data conversion only paying attention to parameter contents in the data type regardless of the parameter type; the user-defined data type is mainly a user-defined type or a structural body, wherein one macro carries out an integral encapsulation function, and the user-defined data type is determined to be serialized or deserialized according to parameters; the other macro calls a function template through a text replacement mode to complete conversion between the user-defined data type object member variables and JSON character strings;
the developer uses the two macros in a combined mode to complete conversion definition of a custom data type and a JSON character string, and data conversion which only concerns the member variable content of the data type object and does not consider the member variable type is carried out;
designing corresponding data types representing scene information, wherein the data types comprise classes (such as data types of a design scene snapshot class, a navigation device class, a satellite class, an interference device class and the like) and a structural body;
step (4), defining and obtaining a conversion function between the scene information data type and the JSON character string by using the macro in the step (2);
step (5), the scene information generator creates a corresponding scene information data type object by taking each data refreshing period (for example, 1 second) as a time unit, serializes the object to generate a JSON character string by using the function defined in the step (4), stores the JSON character string in data and generates a data record;
step (6), reading the stored JSON character string record according to time points during the multi-disk control;
and (7) the situation display renderer deserializes and restores the JSON character strings into scene information data type objects by using the conversion functions defined in the step (4), and rendering control is performed on a display layer to realize situation display.
The invention is simple and convenient to use, and is convenient for developers to concentrate on the service rather than data conversion; meanwhile, the data storage and retrieval are simpler; the data format for interaction has strong robustness, flexibility and expandability, and even if the requirements are changed at different stages of a project, the parameter content or the organization mode of the scene information data type is changed, and the development and deployment work is minimally influenced.
Example 1:
in this embodiment, taking performance evaluation software of a navigation device as an example, the initial functions of the performance evaluation software of the navigation device include:
taking a single navigation device as a core;
devices that can affect their performance are: an interference device;
factors that can affect its efficacy are: the distance between the satellite, the interference device and the navigation equipment, the included angle between the transmitting signal and the direction of the receiving antenna and the like;
and setting an experiment parameter script by a user, automatically executing the script after specifying the information parameters of the device, updating scene information according to time change, rendering the situation, automatically recording process data and supporting playback.
Next, taking the Qt platform as an example for demonstration, as shown in fig. 3 and 5, the method for implementing a situation replication under a GIS platform includes the following steps:
step 1, defining function template
This embodiment defines a function template, and converts any data type and JSON character string into each other through the function template, for example, saveToJsonObject, loadFromJsonObject. And specializing the built-in type of the C + + standard and common data types used in development in a Qt framework, such as QString, qvector and the like, based on the function template.
Step 2, defining macro capable of converting custom data type and JSON character string
Two macros are defined, and any data type instance and JSON character string can be converted into a serialization mode and an deserialization mode. The user-defined data type is mainly a user-defined type or a structure body, and one macro is responsible for an integral encapsulation function and determines to carry out serialization or deserialization on the user-defined data type according to parameters; and the other macro is responsible for calling the function template in a text replacement mode to finish the conversion between the member variables of the custom data type object and the JSON character strings.
The developer can complete the conversion definition of the custom data type and the JSON character string by using the two macros in a combined mode, and data conversion which only concerns the member variable content of the data type object and does not consider the member variable type is carried out.
Step 3, designing various data types representing scene information
And designing data types such as scene snapshot types, navigation equipment types, satellite types, interference equipment types and the like according to software requirements. The design scene snapshot class comprises member variables of types such as a navigation device class, a satellite class and an interference device class.
Step 4, defining a conversion function between the scene information data type and the JSON character string
And defining a conversion method from self-defined data types such as scene snapshot types, navigation equipment types, satellite types, interference equipment types and the like to JSON character strings by using the existing macro to obtain a serialization/deserialization conversion function.
Step 5, the scene information generator starts to work
The scene information generator starts to work, generates an object of a scene snapshot class every second, serializes the object by using a conversion function to generate a JSON character string, and stores the JSON character string.
Step 6, reading record during disc duplication
When the disk is copied, the stored JSON character string record is read according to the time point.
Step 7, deserializing JSON character strings and displaying situation
And after receiving the JSON character string, the situation display renderer performs deserialization reduction on the JSON character string by using a conversion function to obtain a scene snapshot object, and performs rendering control on a display layer according to the member variable value of the scene snapshot object to realize situation display.
The following examples were conducted to analyze the effects of the above embodiments
Because the function template and the macro definition are used and the uniform conversion function interface is encapsulated, the serialization and the deserialization become very simple and convenient for different user-defined types and are consistent with the member variable statement of the user-defined type;
as the JSON form data of the scene snapshot class is stored, the data at a specific time can be directly positioned in a copy scene without more data retrieval, and the storage and secondary processing of the data are simpler;
when the service changes, for example, signal enhancement equipment needs to be added, only corresponding class definitions need to be added, and corresponding members need to be added in the scene snapshot class. As the scene snapshot class used for interaction is encapsulated into JSON character strings, the basic syntax format of the scene snapshot class is not changed, the scene snapshot class is completely compatible with the previous version, and remarkable robustness and expandability are realized.