A method and system for graphical editing undo and redo
By creating undo and redo stacks in the GIS system, managing user operations, and generating reverse operation statements, the problem of inconsistent primary key IDs was solved, improving the efficiency and consistency of data editing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SOUTH SURVEYING & MAPPING INSTR
- Filing Date
- 2025-03-31
- Publication Date
- 2026-07-21
AI Technical Summary
Existing GIS systems struggle to effectively manage the consistency and correctness of primary key IDs when performing frequent geometric editing across layers, resulting in inefficient undo and redo operations.
By creating undo and redo stacks, user operations are recorded and reverse operation statements are generated. Auto-incrementing IDs are used to manage primary key IDs, ensuring data consistency during undo or redo.
It enables efficient undo and redo operations in the GIS system, improving the flexibility and efficiency of data editing and ensuring data consistency and integrity.
Smart Images

Figure CN120523818B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and specifically to a method and system for undoing and redoing graphic editing. Background Technology
[0002] Geographic Information System (GIS) is a set of tools for collecting, storing, querying, transforming, and displaying spatial data. The core function of GIS lies in processing geospatial data, typically involving operations on different types of geometric features. Common geometric operations include drawing, moving, copying, and deleting, and it also supports post-calculation operations on features, such as breaking, extending, zooming in, and zooming out. These operations involve not only the geometric data itself but also its storage and updating. To efficiently store and process this data, many GIS systems use relational database systems to store spatial data and employ auto-incrementing primary key IDs to ensure the uniqueness of entities and data consistency. In this way, GIS systems can efficiently query and manipulate large amounts of spatial data.
[0003] In existing GIS systems, frequent cross-layer geometric editing requires each layer to be opened and closed in edit mode, a process that is often cumbersome and inefficient, significantly reducing productivity. To improve ease of operation, many GIS tools have implemented a no-open-edit-mode function. In this mode, geometric data operations are updated to the database in real time after completion, including the execution of add, delete, and update statements. However, when performing undo and redo operations, relational databases typically use auto-incrementing primary key IDs to ensure entity integrity and logical consistency of relationships. Therefore, properly managing primary key IDs and ensuring their consistency and correctness during undo or redo operations becomes a challenge. Existing technologies cannot effectively solve this problem; therefore, a new data recording model is needed that can efficiently support the reverse execution of add, delete, and update operations, ensuring that stored data can be quickly restored to its correct state during undo or redo operations. Summary of the Invention
[0004] To overcome the shortcomings of the prior art, which causes inconsistencies in primary key IDs in the database when editing graphics, this invention provides a method and system for undoing and redoing graphic editing.
[0005] To achieve the above-mentioned technical effects, the technical solution of the present invention is as follows:
[0006] This invention proposes a method for undoing and redoing graphic editing, comprising the following steps:
[0007] Undo and redo stacks are created based on layer objects; layer objects are stored in a relational database, and when a layer object is stored in the relational database, an auto-incrementing ID is used as the primary key ID corresponding to the layer object;
[0008] When a user interacts with a layer, the interaction record is saved into the undo stack.
[0009] When a user's undo command is detected, the operation record is retrieved from the undo stack, transferred to the redo stack, and then a reverse operation statement is generated and executed based on the operation record.
[0010] When a user's redo instruction is detected, the operation record is retrieved from the redo stack and executed;
[0011] When completing an undo or redo instruction, record the new primary key ID of the current operation record in the relational database, traverse the undo and redo stacks, find the operation record that is the same as the current operation record, and change its primary key ID to the new primary key ID.
[0012] As a preferred embodiment, the operation record includes operation records of one or more entities within a layer. Multiple entities in the same operation record have the same feature identifier and are sequentially saved into the undo stack or redo stack.
[0013] As a preferred embodiment, when executing the undo or redo instruction, during the popping process, entities whose feature identifiers match those of the entity at the end of the stack are popped one by one until all entities at the end of the stack have different feature identifiers.
[0014] As a preferred embodiment, the operation record includes the entity's feature identifier, geometric information, attribute information, operation type, and primary key ID.
[0015] As a preferred embodiment, saving the operation record into the undo stack includes:
[0016] When the operation record is of type "new", it is entered into the undo stack after the primary key ID is generated in the database;
[0017] When the operation record type is modification, the modified entity is deep copied and then stored in the undo stack;
[0018] When the operation record type is deletion, the primary key ID of the operation record is set to null and then stored in the revocation stack.
[0019] As a preferred option, when an operation record is saved and added to the undo stack, the redo stack is cleared.
[0020] As a preferred embodiment, the step of generating and executing reverse operation statements based on operation records includes: generating corresponding reverse SQL operation statements at the database layer based on operation records.
[0021] This invention also proposes a graphical editing undo and redo system, comprising:
[0022] Operation record saving module: used to detect user operations on the layer and save the operation record into the undo stack;
[0023] Undo module: It is equipped with an undo stack, which is used to extract the operation record from the undo stack when the user's undo command is detected, transfer the operation record to the redo stack, and generate and execute the reverse operation statement based on the operation record.
[0024] Redo module: It is equipped with a redo stack, which is used to retrieve operation records from the redo stack and execute them when a user's redo command is detected;
[0025] Primary Key ID Synchronization Module: When an undo or redo instruction is completed, it records the new primary key ID of the current operation record in the relational database, traverses the undo stack and redo stack, and changes the primary key ID of the operation record that is the same as the current operation record to the new primary key ID.
[0026] The present invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement a graphical editing undo and redo method as described in the present invention.
[0027] The present invention also proposes a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements a graphical editing undo and redo method as described in the present invention.
[0028] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0029] This invention enables effective reverse processing of add, delete, and modify operations, ensuring that geometric feature or attribute data stored in the database can be quickly restored to the correct state when undoing or redoing operations. The implementation of this technology significantly improves the flexibility and efficiency of data editing in GIS systems, especially in scenarios involving large amounts of data and complex operations. It effectively reduces the tedium of manual operations and ensures data consistency and integrity. Attached Figure Description
[0030] Figure 1 This is a flowchart of a graphical editing undo and redo method for Example 1.
[0031] Figure 2This is an architecture diagram of a graphical editing undo and redo system according to Example 2. Detailed Implementation
[0032] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the invention.
[0033] It will be understood by those skilled in the art that some well-known descriptions may be omitted in the accompanying drawings.
[0034] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0035] Example 1
[0036] This embodiment proposes a method for undoing and redoing graphic editing, such as... Figure 1 The diagram shown is a flowchart of a graphical editing undo and redo method according to this embodiment.
[0037] This embodiment proposes a method for undoing and redoing graphic editing, including the following steps:
[0038] Undo and redo stacks are created based on layer objects; layer objects are stored in a relational database, and when a layer object is stored in the relational database, an auto-incrementing ID is used as the primary key ID corresponding to the layer object;
[0039] When a user interacts with a layer, the interaction record is saved into the undo stack.
[0040] When a user's undo command is detected, the operation record is retrieved from the undo stack, transferred to the redo stack, and then a reverse operation statement is generated and executed based on the operation record.
[0041] When a user's redo instruction is detected, the operation record is retrieved from the redo stack and executed;
[0042] When completing an undo or redo instruction, record the new primary key ID of the current operation record in the relational database, traverse the undo and redo stacks, find the operation record that is the same as the current operation record, and change its primary key ID to the new primary key ID.
[0043] In this embodiment, when a layer object changes, the system sequentially saves the operation records to the undo stack. When the user issues an undo or redo command, the stack data structure is used to reverse or repeat the operation. Secondly, by recording the new primary key ID of the current operation record, the system iterates through the undo and redo stacks, changing the primary key ID of the same operation record to the new primary key ID to ensure data consistency and correctness during undo or redo operations.
[0044] In one optional embodiment, the operation record includes operation records of one or more entities within a layer, wherein multiple entities in the same operation record have the same feature identifier and are sequentially saved into the undo stack or redo stack.
[0045] In this embodiment, batch operation management is achieved through feature identification. When a user performs consecutive operations on multiple entities with the same feature, the system automatically identifies the feature identification and stores it in association, thereby improving the processing efficiency of batch operations.
[0046] Further optionally, when executing the undo or redo instruction, during the popping process, entities whose feature identifiers match those of the entity at the end of the stack are popped one by one until all entities at the end of the stack have different feature identifiers.
[0047] In this embodiment, a feature identifier matching mechanism is used to realize the pop-up recovery of batch operations, ensuring that entities with the same feature identifier maintain operational consistency when canceling / redoing, and avoiding the problem of inconsistent states of some entities.
[0048] In one optional embodiment, the operation record includes the entity's feature identifier, geometric information, attribute information, operation type, and primary key ID.
[0049] In this embodiment, by constructing a multi-dimensional operation record data structure, the reverse operation can accurately restore the entity state, ensuring the accuracy of data recovery.
[0050] In an optional embodiment, saving the operation record into the undo stack includes:
[0051] When the operation record is of type "new", it is entered into the undo stack after the primary key ID is generated in the database;
[0052] When the operation record type is modification, the modified entity is deep copied and then stored in the undo stack;
[0053] When the operation record type is deletion, the primary key ID of the operation record is set to null and then stored in the revocation stack.
[0054] In this embodiment, a differentiated storage strategy is used to effectively distinguish the data storage methods for different operation types. The primary key pre-generation mechanism for new operations enables reverse operations to accurately locate database entities, and deep copy technology ensures the reversibility of modification operations.
[0055] In an optional embodiment, when an operation record is saved into the undo stack, the redo stack is cleared.
[0056] In this embodiment, when a new operation record is saved into the undo stack, the system automatically clears the redo stack to prevent conflicts between redo operations and new operations. This ensures that the operation records in the redo stack are always up-to-date after each undo, avoiding data redundancy and errors.
[0057] In an optional embodiment, the step of generating and executing a reverse operation statement based on the operation record includes: generating a corresponding reverse SQL operation statement at the database layer based on the operation record.
[0058] In this embodiment, by generating reverse SQL directly at the database level, undo / redo operations can be directly applied to the database storage layer, which improves data processing efficiency compared to traditional application layer processing methods.
[0059] Example 2
[0060] This embodiment proposes a graphic editing undo and redo system, applying a graphic editing undo and redo method proposed in Embodiment 1. For example... Figure 2 The diagram shown is an architecture diagram of a graphical editing undo and redo system according to this embodiment.
[0061] This embodiment proposes a graphical editing undo and redo system, which includes:
[0062] Operation record saving module: used to detect user operations on the layer and save the operation record into the undo stack;
[0063] Undo module: It is equipped with an undo stack, which is used to extract the operation record from the undo stack when the user's undo command is detected, transfer the operation record to the redo stack, and generate and execute the reverse operation statement based on the operation record.
[0064] Redo module: It is equipped with a redo stack, which is used to retrieve operation records from the redo stack and execute them when a user's redo command is detected;
[0065] Primary Key ID Synchronization Module: When an undo or redo instruction is completed, it records the new primary key ID of the current operation record in the relational database, traverses the undo stack and redo stack, and changes the primary key ID of the operation record that is the same as the current operation record to the new primary key ID.
[0066] It is understood that the system in this embodiment corresponds to the method in Embodiment 1 above, and the options in Embodiment 1 above are also applicable to this embodiment, so they will not be described again here.
[0067] Example 3
[0068] This embodiment proposes a computer device, including a memory and a processor. The memory stores computer-readable instructions, wherein when the computer-readable instructions are executed by the processor, the processor performs the steps of a graphical editing undo and redo method proposed in Embodiment 1.
[0069] Example 4
[0070] This embodiment proposes a storage medium storing computer-readable instructions, wherein when the computer-readable instructions are executed by a processor, they implement the steps of a graphical editing undo and redo method proposed in Embodiment 1.
Claims
1. A method for undoing and redoing graphic editing, characterized in that, Includes the following steps: Undo and redo stacks are created based on layer objects; layer objects are stored in a relational database, and when a layer object is stored in the relational database, an auto-incrementing ID is used as the primary key ID corresponding to the layer object; When a user interacts with a layer, the interaction record is saved into the undo stack. When a user's undo command is detected, the operation record is retrieved from the undo stack, transferred to the redo stack, and then a reverse operation statement is generated and executed based on the operation record. When a user's redo instruction is detected, the operation record is retrieved from the redo stack and executed; When completing an undo or redo instruction, record the new primary key ID of the current operation record in the relational database, traverse the undo and redo stacks, find the operation record that is the same as the current operation record, and change its primary key ID to the new primary key ID.
2. The graphic editing undo and redo method according to claim 1, characterized in that, The operation record includes operation records of one or more entities within a layer. Multiple entities in the same operation record have the same feature identifier and are saved sequentially into the undo stack or redo stack.
3. The method for undoing and redoing graphic editing according to claim 2, characterized in that, When executing the undo or redo instruction, during the pop operation, entities whose feature identifiers match the feature identifiers of the entity at the end of the stack are popped one by one until the entity at the end of the stack has a different feature identifier.
4. The graphic editing undo and redo method according to claim 2, characterized in that, The operation record includes the entity's feature identifier, geometric information, attribute information, operation type, and primary key ID.
5. A method for undoing and redoing graphic editing according to claim 2, characterized in that, Saving the operation record into the undo stack includes: When the operation record is of type "new", it is entered into the undo stack after the primary key ID is generated in the database; When the operation record type is modification, the modified entity is deep copied and then stored in the undo stack; When the operation record type is deletion, the primary key ID of the operation record is set to null and then stored in the revocation stack.
6. A method for undoing and redoing graphic editing according to any one of claims 1 to 5, characterized in that, When an operation record is saved and added to the undo stack, the redo stack is cleared.
7. A method for undoing and redoing graphic editing according to any one of claims 1 to 5, characterized in that, The step of generating and executing reverse operation statements based on operation records includes: generating corresponding reverse SQL operation statements at the database layer based on operation records.
8. A graphic editing undo and redo system, applied to the graphic editing undo and redo method according to any one of claims 1 to 7, characterized in that, The system includes: Operation record saving module: used to detect user operations on the layer and save the operation record into the undo stack; Undo module: It is equipped with an undo stack, which is used to extract the operation record from the undo stack when the user's undo command is detected, transfer the operation record to the redo stack, and generate and execute the reverse operation statement based on the operation record. Redo module: It is equipped with a redo stack, which is used to retrieve operation records from the redo stack and execute them when a user's redo command is detected; Primary Key ID Synchronization Module: When an undo or redo instruction is completed, it records the new primary key ID of the current operation record in the relational database, traverses the undo stack and redo stack, and changes the primary key ID of the operation record that is the same as the current operation record to the new primary key ID.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements a graphical editing undo and redo method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements a graphical editing undo and redo method as described in any one of claims 1-7.