Error-proof loading method, system and device of NC file and storage medium

By embedding a preview image of the machining model and integrity verification information in the header of the NC file, the problems of erroneous machining and integrity verification during the NC file loading process are solved, and visual confirmation and safe loading are achieved.

CN122284443APending Publication Date: 2026-06-26YUNJIA (CHONGQING) MEDICAL EQUIP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
YUNJIA (CHONGQING) MEDICAL EQUIP CO LTD
Filing Date
2026-03-31
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Existing NC files are prone to misprocessing during loading due to similar filenames or human error, and lack integrity verification, posing a processing risk.

Method used

A preview image of the machining model and integrity verification information are embedded in the header of the NC file. The two-dimensional preview image and verification value are used as metadata blocks through text encoding, marked with start and end identifiers, and parsed and compared in the CNC software to control the machining operation.

Benefits of technology

It enables visual confirmation and integrity verification of the NC file loading process, avoids erroneous processing, ensures that the file has not been tampered with, and has good backward compatibility and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122284443A_ABST
    Figure CN122284443A_ABST
Patent Text Reader

Abstract

This application relates to the technical field of Computer Numerical Control (NC) systems, specifically to a method, system, device, and storage medium for preventing NC file misloading. The method includes: acquiring an NC file; rendering a two-dimensional preview image in a CAM (Computer-Aided Design) system; converting the two-dimensional preview image into image-encoded data and calculating a first checksum of the NC file according to a preset verification algorithm; determining metadata blocks, adding start and end identifiers to the beginning and end of the metadata blocks respectively, and writing the metadata blocks into the header of the NC file; scanning the file header, extracting the metadata blocks based on the start and end identifiers, and parsing the image-encoded data and the first checksum from the metadata blocks; calculating a second checksum using a preset verification algorithm, and comparing the second checksum with the first checksum. This method can effectively prevent equipment damage or material waste caused by corrupted or maliciously modified NC files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of computer numerical control, and in particular to a method, system, device and storage medium for preventing erroneous loading of NC files. Background Technology

[0002] CNC machining typically relies on CAD / CAM systems to generate NC files (such as G-code) containing toolpaths. Operators then select and load the NC file on the CNC terminal before executing the machining process. In existing workflows, filenames, file paths, or simple text annotations are often used to distinguish different workpieces or processes. However, with multiple versions of files coexisting, similar names, or human oversight, incorrect imports and erroneous machining can easily occur. Most general-purpose CNC control software has limited visualization support for NC files, making it difficult to directly present a preview of the finished product's appearance before import, thus hindering accurate judgments based solely on experience or textual information.

[0003] To mitigate the risk of misoperation, existing technologies include associating preview images with NC files as independent files or database records, or relying on MES / PLM systems and barcodes / QR codes for management-level control. However, these solutions suffer from drawbacks such as the inability to visually confirm offline on the controller, the susceptibility to mismatches in the external association between files and previews, high deployment costs, and strong intrusion into existing systems. Some manufacturers also use proprietary encapsulation formats to package NC code and thumbnails, but these are incompatible with universal G-code, resulting in poor reusability across devices and software environments. Furthermore, existing NC files typically lack built-in integrity verification mechanisms, making it difficult to detect accidental or malicious modifications during transmission, editing, or copying, further amplifying processing risks.

[0004] Therefore, there is an urgent need for a method that embeds machining preview images and file verification information into the header of NC files in a way compatible with comment syntax without changing the semantics of the main NC machining code. This would allow systems without integrated parsing functions to automatically ignore the metadata, while CNC software with parsing capabilities could extract and display the preview images and perform integrity checks during import, and control the start of machining based on the comparison results. This would achieve visual confirmation and prevent accidental loading, while also ensuring versatility and compatibility. Summary of the Invention

[0005] One objective of this application is to provide a method, apparatus, device, and storage medium for preventing accidental loading of NC files of dental models, in order to solve the technical problems of cumbersome and difficult process of editing denture features and high requirements for users in related technologies.

[0006] In a first aspect, embodiments of this application provide a method for preventing accidental loading of NC files, comprising: Obtain the NC file, which contains machining code; In CAM, a two-dimensional preview image of the machining model corresponding to the NC file is generated by rendering. The two-dimensional preview image is converted into image encoded data according to a preset text encoding method, and the first verification value of the NC file is calculated according to a preset verification algorithm. The first verification value is calculated based on the main content of the NC file excluding metadata. The metadata block is determined based on the image encoding data and the first check value. A start identifier and an end identifier are added to the beginning and end of the metadata block, respectively. The metadata block is written into the header of the NC file. The metadata block is located before the processing code to generate an enhanced NC file. When importing the enhanced NC file into the CNC, the file header is scanned, the metadata block is extracted based on the start identifier and end identifier, and the image encoding data and the first check value are parsed from the metadata block. The parsed image encoding data is decoded to generate a preview image, which is then displayed on the CNC software interface. Based on the main content of the enhanced NC file excluding the metadata block, the preset verification algorithm is used to calculate the second verification value, and the second verification value is compared with the first verification value. If the comparison is consistent, the processing operation is performed; if the comparison is inconsistent, the processing operation is prohibited.

[0007] In conjunction with the first aspect, in one possible implementation, the step of rendering and generating a two-dimensional preview image of the machining model corresponding to the NC file in CAM includes: Based on the layout, machining path, and tool information in the CAM software, a vector graphic representing the appearance of the finished product after machining is generated. The vector graphics are rendered into image data in a predetermined format.

[0008] In conjunction with the first aspect, in one possible implementation, the preset verification algorithm is a hash algorithm or a cyclic redundancy check algorithm; When calculating the first verification value, the calculation scope includes the machining code portion of the NC file, but excludes the metadata block to be written.

[0009] In conjunction with the first aspect, in one possible implementation, the start identifier and end identifier are uniquely identifiable annotation identifiers, and the format of the start identifier and end identifier is compatible with the annotation syntax of the NC file, so that CNC software without integrated parsing function can ignore the metadata block.

[0010] In a second aspect, embodiments of this application provide a system for preventing accidental loading of NC files, comprising: The CAM processing module is configured to: acquire an NC file containing machining code; render and generate a two-dimensional preview image of the machining model corresponding to the NC file; convert the two-dimensional preview image into image encoded data according to a preset text encoding method; calculate a first verification value based on the machining code content in the NC file excluding metadata according to a preset verification algorithm; encapsulate the image encoded data and the first verification value into a metadata block; add preset start identifiers and end identifiers to the beginning and end of the metadata block and write it into the header of the NC file before the machining code to generate an enhanced NC file. The CNC-side parsing and verification module is configured as follows: when importing the enhanced NC file, it identifies the start identifier and end identifier in the file header, extracts and parses the metadata block to obtain image encoded data and a first verification value, decodes the image encoded data to generate a preview image and displays it, calculates a second verification value based on the machining code content in the imported enhanced NC file other than the metadata block using the preset verification algorithm, compares the second verification value with the first verification value, and determines whether to allow the machining operation based on the comparison result.

[0011] In conjunction with the second aspect, in one possible implementation, the CAM end processing module includes: The image rendering unit is configured to generate a two-dimensional vector preview image based on the layout information, toolpath and tool parameters in the CAM software, and render the two-dimensional vector preview image into image data in a predetermined format; The encoding unit is configured to convert the image data into image encoded data according to a preset text encoding method; The verification calculation unit is configured to calculate a verification value as the first verification value based on the machining code portion of the NC file according to a preset verification algorithm before inserting the metadata block; The file writing unit is configured to encapsulate the image encoding data and the first check value according to a preset format, and add a start identifier and an end identifier before writing them into the header of the NC file.

[0012] In conjunction with the second aspect, in one possible implementation, the CNC-side parsing and verification module includes: The file scanning unit is configured to scan the file header line by line during the import of the enhanced NC file, identify the start identifier and the end identifier, and extract the metadata content between the start identifier and the end identifier. The image decoding unit is configured to decode the image encoded data in the metadata into image data and transmit it to the CNC software interface for display. The verification and comparison unit is configured to calculate the verification value based on the machining code content other than the metadata block in the imported enhanced NC file, and compare the calculated verification value with the first verification value extracted from the metadata block to generate a comparison result signal. The execution control unit is configured to control the start or stop of the processing operation based on the comparison result signal, and to output a warning message when the comparison is inconsistent.

[0013] In conjunction with the second aspect, in one possible implementation, the start identifier and end identifier adopt a format compatible with NC file comment syntax, including bracket comment form or semicolon comment form, so that CNC software without integrated parsing function ignores the metadata block.

[0014] In a third aspect, embodiments of this application provide an electronic device including a memory and a processor, the memory being connected to the processor, the processor being configured to execute one or more computer programs stored in the memory, and the processor, when executing the one or more computer programs, causing the electronic device to perform the method as described in any of the first aspects above.

[0015] In a fourth aspect, embodiments of this application provide a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method described in any of the preceding claims.

[0016] The embodiments of this application can achieve the following technical effects: Based on the method proposed in this application, firstly, an NC file containing machining code is obtained, and a two-dimensional preview image of the machining model corresponding to the NC file is generated in the CAM. Then, the two-dimensional preview image is converted into image encoded data, and a first check value of the NC file is calculated. The image encoded data and the first check value constitute a metadata block, and the metadata block is written into the header of the NC file to generate an enhanced NC file. Then, when the enhanced NC file is imported into the CNC, the metadata block is extracted and parsed from the file header, decoded to generate a preview image and displayed on the CNC software interface. At the same time, a second check value is calculated based on the main content of the imported enhanced NC file other than the metadata block, and the second check value is compared with the parsed first check value. Finally, the execution of the machining operation is controlled according to the comparison result.

[0017] This method embeds a preview image of the machining model and integrity verification information into the header of the NC file, allowing operators to visually confirm the machining content before machining, thus avoiding mismachining due to file confusion. Simultaneously, automatic comparison of verification values ​​ensures that the NC file has not been tampered with during transmission or storage, preventing equipment damage or material waste caused by file corruption or malicious modification. Furthermore, this method does not require changes to the existing NC file's main structure or machining process, possesses good backward compatibility, and achieves secure and reliable control over the NC file loading process. Attached Figure Description

[0018] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 A flowchart illustrating a method for preventing accidental loading of NC files provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0021] It should be noted that, unless there is a conflict, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than the module division in the device or the order in the flowchart. Moreover, the terms "first," "second," and "third" used in this application do not limit the data or execution order, but only distinguish identical or similar items with essentially the same function and effect.

[0022] In the first aspect, please refer to Figure 1 This application provides a method for preventing accidental loading of NC files, the method comprising: Step S10: Obtain the NC file, which contains machining code; Step S10: Render a two-dimensional preview image of the machining model corresponding to the NC file in CAM; Step S30: Convert the two-dimensional preview image into image encoded data according to a preset text encoding method, and calculate the first verification value of the NC file according to a preset verification algorithm. The first verification value is calculated based on the main content of the NC file excluding metadata. Step S40: Determine a metadata block based on the image encoding data and the first check value; add a start identifier and an end identifier to the beginning and end of the metadata block respectively; and write the metadata block into the header of the NC file. The metadata block is located before the processing code to generate an enhanced NC file. Step S50: When importing the enhanced NC file into the CNC, scan the file header, extract the metadata block according to the start identifier and end identifier, and parse the image encoding data and the first check value from the metadata block; Step S60: Decode the parsed image encoding data to generate a preview image, and display the preview image on the CNC software interface; Step S70: Based on the main content of the enhanced NC file excluding the metadata block, calculate the second verification value using the preset verification algorithm, and compare the second verification value with the first verification value. If the comparison matches, perform the processing operation; if the comparison does not match, prohibit the processing operation.

[0023] This embodiment provides a method for preventing accidental loading of NC files, which can be applied to computer numerical control (CNC) machining systems. In practical applications, after the operator completes the layout of the machining model and the generation of toolpaths in the computer-aided manufacturing software, the system automatically starts executing this method.

[0024] First, the system acquires the NC file to be processed. This NC file is a standard text format file containing a series of G-code instructions, which constitute the main content controlling the CNC machine to perform machining operations. Acquisition can be achieved either by the system automatically locating and reading the file from the storage path according to a preset workflow, or by the operator manually selecting it through a file selection dialog box. Regardless of the method used, the acquired NC file contains complete machining code. This machining code is the basis for subsequent verification value calculations and the instruction basis for the final machining operation performed by the CNC machine.

[0025] Subsequently, in the computer-aided manufacturing environment, the system renders and generates a two-dimensional preview image of the machining model corresponding to the NC file. The system reads the three-dimensional data of the machining model and, combined with information such as layout and toolpath, generates a two-dimensional image through a graphics rendering engine. This image displays the appearance of the machined workpiece from a top-down or isometric perspective, including its contour shape, surface features, and detailed structure. During rendering, the system automatically sets appropriate resolution and color depth to ensure image clarity while controlling data size. The generated preview image reflects the appearance of the finished product, providing operators with an intuitive visual reference.

[0026] Next, the system converts the generated 2D preview image into image-encoded data according to a preset text encoding method. The choice of text encoding method must consider the characteristics of NC files as text files; the encoded data should be able to be embedded in the NC file in plain text form without compromising the file's format integrity. Simultaneously, the system calculates the first checksum of the current NC file according to a preset verification algorithm. When calculating the first checksum, the system reads all existing machining code content in the NC file, but explicitly excludes the metadata portion to be written later, using this as the basis for calculating the first checksum. This design ensures the consistency of the checksum before and after metadata insertion, making subsequent integrity verification possible.

[0027] Then, the system determines the metadata block based on the image encoding data and the first checksum. Specifically, the system combines the image encoding data and the first checksum into a complete metadata block according to a preset format. At the beginning and end of the metadata block, the system adds a start identifier and an end identifier, respectively, to mark the boundaries of the metadata block. The system writes the metadata block with the identifiers into the header of the NC file, ensuring that the metadata block precedes the machining code. After the above processing, the original NC file is converted into an enhanced NC file, which, while retaining the integrity of the original machining code, additionally includes preview image information and integrity verification information.

[0028] During the CNC machining stage, the operator imports the enhanced NC file into the CNC control software. In response to the file import operation, the CNC software begins parsing the file. The software scans the file header line by line; when it detects a start identifier, it begins recording the subsequent content; when it detects an end identifier, it stops recording and extracts all content between the start and end identifiers as a metadata block. Subsequently, the software parses the image encoding data and the first checksum from the metadata block according to a preset metadata block format.

[0029] The CNC software decodes the parsed image encoding data to generate a preview image. Since the image encoding data is obtained using a specific encoding method, the corresponding decoding method is used to restore the encoded string to the original bitmap image data. After decoding, the software displays the generated preview image in a designated area of ​​the CNC software interface. Through this preview image, the operator can visually confirm whether the content to be processed matches the expectations before machining begins, thus avoiding erroneous processing due to file confusion.

[0030] Simultaneously, the CNC software calculates a second checksum based on the main content of the enhanced NC file, excluding the metadata block, using the same preset verification algorithm as described above. Specifically, the software extracts all machining code portions after the metadata block in the enhanced NC file, calculates checksums for these code contents, and obtains the second checksum. The software compares the calculated second checksum with the first checksum parsed from the metadata block. When the second checksum matches the first checksum, it indicates that the file has not been tampered with during transmission or storage, the file integrity is good, and the software allows machining operations to be performed; when the two do not match, it indicates that the file may have been modified or corrupted, the software outputs a warning message and prohibits machining operations to prevent equipment damage or material waste due to file errors.

[0031] Thus, this embodiment achieves visual confirmation and integrity verification of the NC file loading process, significantly improving processing safety and operational reliability.

[0032] As a feasible implementation method, the step of rendering and generating a two-dimensional preview image of the machining model corresponding to the NC file in CAM includes: generating vector graphics representing the appearance of the finished product after machining based on the layout, machining path and tool information in the CAM software; and rendering the vector graphics into image data in a predetermined format.

[0033] In this embodiment, the process of rendering and generating a two-dimensional preview image includes two specific steps.

[0034] Firstly, the system generates vector graphics. At this stage, the system acquires layout information from the computer-aided manufacturing software, reflecting the workpiece's position and orientation on the machining platform. For example, the layout might include parameters such as the workpiece's coordinate position on the platform, rotation angle, and spacing between multiple workpieces. The system also acquires machining path information, reflecting the tool's movement trajectory, including the entry point, retraction point, cutting path, and tool lift-off path. Simultaneously, the system acquires tool information, including parameters such as tool type, diameter, cutting edge length, and depth of cut. Combining all this information, the system generates a vector graphic using a graphics rendering algorithm. This vector graphic mathematically describes the workpiece's contour and surface features, accurately reflecting the finished workpiece's appearance.

[0035] Secondly, the vector graphics are converted into bitmap images. In this process, the system renders the vector graphics as image data in a predetermined format. During this process, the system sets an appropriate resolution, such as 320×240 pixels or 640×480 pixels, to ensure image clarity while controlling data size. The system also sets an appropriate color depth, such as 24-bit true color or 256 levels of grayscale, to accurately reflect the surface features of the workpiece. After rendering, the system outputs a bitmap image in a predetermined format. This bitmap image can be in common formats such as portable web graphics formats or Joint Image Experts Group (JIE) formats to facilitate subsequent encoding processing.

[0036] Through the above two steps, this embodiment further generates a preview image that can be encoded and embedded, which accurately reflects the appearance of the finished product.

[0037] As a feasible implementation method, the preset verification algorithm is a hash algorithm or a cyclic redundancy check algorithm; when calculating the first verification value, the calculation range includes the processing code part in the NC file, but does not include the metadata block to be written.

[0038] In this embodiment, the preset verification algorithm can be a hash algorithm. A hash algorithm is an algorithm that maps data of arbitrary length to a fixed-length hash value, possessing uniqueness and irreversibility. Specifically, the MD5 algorithm can be used, which calculates a 128-bit hash value from data of arbitrary length; the SHA-1 algorithm can be used, which generates a 160-bit hash value; or the SHA-256 algorithm can be used, which generates a 256-bit hash value. These hash algorithms ensure that any minor modification to the file content will result in a significant change in the hash value, thus effectively detecting file tampering or corruption.

[0039] In addition, the preset verification algorithm can also employ the Cyclic Redundancy Check (CRC) algorithm. The Cyclic Redundancy Check (CRC) algorithm is a verification algorithm based on polynomial division that can generate a fixed-length check value. For example, the CRC32 algorithm can be used, which generates a 32-bit check value. It features fast computation speed and simple implementation, making it suitable for applications with high real-time requirements.

[0040] It should be noted that, in this embodiment, regardless of the algorithm used, the precise limitation of the calculation range is crucial when calculating the first checksum. The system reads the machining code portion of the original NC file, i.e., the G-code instruction sequence. These instructions constitute the main content controlling the CNC equipment to perform machining. When calculating the checksum, the system explicitly excludes the metadata block to be written: if the calculation of the checksum includes the metadata to be written, then the file content will change after the metadata is written, and the checksum will change accordingly, making it unusable for verifying the integrity of the file. Therefore, the calculation range is limited to the machining code portion, ensuring that the machining code portion remains unchanged before and after the metadata is written, and the first checksum is always valid, accurately reflecting the characteristics of the original machining code.

[0041] As a possible implementation, the start identifier and end identifier are uniquely identifiable annotation identifiers, and the format of the start identifier and end identifier is compatible with the annotation syntax of the NC file, so that CNC software without integrated parsing function can ignore the metadata block.

[0042] In this embodiment, the start and end identifiers use comment-type identifiers, whose format is compatible with the standard comment syntax of NC files. In the standard syntax of NC files, comment content is usually identified by a specific sequence of characters. One common comment format is bracket form, that is, the comment content is enclosed in left and right brackets, such as "(This is a comment content)". Another common comment format is semicolon form, that is, the comment content is identified by starting with a semicolon, such as ";This is a comment content".

[0043] Therefore, this embodiment can adopt various specific identifier formats. For example, the start identifier can be in the format "(PREVIEW_BEGIN)"; For the end identifier, you can use the format "(PREVIEW_END)", with the entire metadata block enclosed in a pair of parentheses.

[0044] As another specific implementation, the start identifier can be in the format ";PREVIEW_BEGIN", the end identifier can be in the format ";PREVIEW_END", and each line of the metadata block begins with a semicolon.

[0045] Furthermore, new CNC software with integrated parsing capabilities can identify these unique identifiers and extract the content of metadata blocks for decoding and verification. For traditional CNC software without integrated parsing capabilities, since these identifiers conform to the NC file comment syntax, the software automatically treats all content between the start and end identifiers as ordinary comments and ignores them, executing only the subsequent machining code. This mechanism ensures the backward compatibility of enhanced NC files, allowing the technical solution of this embodiment to be gradually promoted and applied without affecting the use of existing equipment. Users can enjoy some of the advantages of the new technology without upgrading all their equipment.

[0046] In a second aspect, embodiments of this application also propose an anti-misloading system for NC files, including a computer-aided manufacturing end processing module and a computer numerical control end parsing and verification module. The two modules work together to achieve secure control over the NC file loading process.

[0047] The computer-aided manufacturing (CAD) processing module is deployed within the CAD system. This module first acquires the NC file containing machining codes, a standard file obtained after the user has completed layout and toolpath generation. Then, the module automatically invokes the graphics rendering function to generate a 2D preview image based on the machining model. The module converts the preview image into a text-encoded format and simultaneously calculates checksums for the machining codes in the original NC file. The module encapsulates the encoded image data and the calculated checksums into a metadata block, adding preset identifiers to the beginning and end of the metadata block. Finally, the module writes the metadata block with identifiers to the header of the NC file, ensuring that the metadata block precedes the machining codes, thus outputting an enhanced NC file.

[0048] The CNC terminal parsing and verification module is deployed within the CNC control software. When an operator imports an enhanced NC file, this module begins operation. First, the module scans the file header, locating the metadata block by identifying the start and end identifiers, and extracting the entire content of the metadata block. The module parses the image-encoded data and the first checksum from the metadata block. The module decodes the image-encoded data, generates a preview image, and displays it in the software interface for the operator to preview and confirm. Simultaneously, the module extracts the machining code portion of the enhanced NC file, excluding the metadata block, and calculates the second checksum using the same verification algorithm. The module compares the second checksum with the first checksum and determines whether to allow the machining operation based on the comparison result.

[0049] Through the collaborative work of the two modules mentioned above, this system achieves full-process security control from NC file generation to loading.

[0050] As a feasible implementation, the CAM-side processing module includes: an image rendering unit configured to generate a two-dimensional vector preview image based on the layout information, toolpath trajectory, and tool parameters in the CAM software, and render the two-dimensional vector preview image into image data in a predetermined format; an encoding unit configured to convert the image data into image encoded data according to a preset text encoding method; a verification calculation unit configured to calculate a verification value as a first verification value based on the machining code portion of the NC file according to a preset verification algorithm before inserting the metadata block; and a file writing unit configured to encapsulate the image encoded data and the first verification value according to a preset format, and add a start identifier and an end identifier before writing them into the header of the NC file.

[0051] In this embodiment, the computer-aided manufacturing end-processing module is composed of four functional units working together.

[0052] The image rendering unit is responsible for generating the preview image. This unit acquires layout information from the computer-aided manufacturing software, including the position and orientation of the workpiece on the platform and the layout relationship between multiple workpieces; acquires toolpath information, including the tool's movement path, entry point, and retraction point; and acquires tool parameter information, including tool type, diameter, and cutting edge length. Based on this information, the image rendering unit generates a two-dimensional vector preview image through a graphics rendering engine. This vector image mathematically and accurately describes the appearance of the workpiece after machining. Subsequently, the image rendering unit renders the vector image into a bitmap image of a predetermined format, sets an appropriate resolution and color depth, and outputs image data that can be encoded.

[0053] The encoding unit is responsible for encoding and converting image data. This unit receives bitmap image data output from the image rendering unit and converts it into a plain text encoded string using a preset text encoding method. This conversion allows image data originally in binary format to be embedded in the NC file as text without violating the NC file's basic text file format. The output of the encoding unit is a string of printable ASCII characters that can be directly written to the NC file.

[0054] The verification calculation unit is responsible for calculating the verification value. Before inserting the metadata block, this unit reads the machining code portion of the original NC file, i.e., the G-code instruction sequence. The verification calculation unit uses a preset verification algorithm to perform hash calculations or cyclic redundancy check calculations on these code contents, generating a verification value as the first verification value. This unit ensures that the calculation scope is precisely limited to the machining code portion and does not include the metadata to be written.

[0055] The file writing unit is responsible for encapsulating and writing metadata blocks. This unit receives the image encoding data output by the encoding unit and the first checksum output by the checksum calculation unit, and combines them into a metadata block according to a preset format. The unit adds a start identifier and an end identifier to the beginning and end of the metadata block, respectively, and then writes the complete metadata block to the header of the NC file, ensuring that the metadata block is placed before the processing code, ultimately generating an enhanced NC file.

[0056] Through the collaborative work of the above four units, the computer-aided manufacturing end-processing module can automatically and efficiently generate enhanced NC files.

[0057] As a feasible implementation, the CNC-side parsing and verification module includes: a file scanning unit, configured to scan the file header line by line when the enhanced NC file is imported, identify the start identifier and the end identifier, and extract the metadata content between the start identifier and the end identifier; an image decoding unit, configured to decode the image encoded data in the metadata into image data and transmit it to the CNC software interface for display; a verification and comparison unit, configured to calculate a verification value based on the machining code content other than the metadata block in the imported enhanced NC file, and compare the calculated verification value with the first verification value extracted from the metadata block to generate a comparison result signal; and an execution control unit, configured to control the start or stop of machining operations based on the comparison result signal, and output a warning message when the comparison is inconsistent.

[0058] In this embodiment, the computer numerical control terminal parsing and verification module is composed of four functional units working together.

[0059] The file scanning unit is responsible for locating and extracting metadata blocks. When an enhanced NC file is imported, this unit begins scanning the file header line by line. The unit reads the file content line by line, and when it detects a start identifier, it enters metadata acquisition mode and begins recording the content of each subsequent line; when it detects an end identifier, it stops recording and outputs all content between the start and end identifiers as a metadata block. This line-by-line scanning method ensures that metadata blocks can be accurately extracted, unaffected by changes in file format, and that the presence of other comments in the file will not interfere with the extraction of metadata blocks.

[0060] The image decoding unit is responsible for the restoration and display of the preview image. This unit receives the metadata block output by the file scanning unit and parses out the image encoding data. The unit uses a decoding algorithm corresponding to the encoding method to restore the encoded string to the original bitmap image data. After decoding, the unit transmits the image data to a designated area on the CNC software interface for rendering and display by the software, allowing the operator to preview and confirm.

[0061] The verification and comparison unit is responsible for verifying and comparing the integrity of the file. This unit extracts all machining code sections after the metadata block from the enhanced NC file, and uses the same verification algorithm as the computer-aided manufacturing end to calculate verification values ​​for these machining codes, obtaining a second verification value. The unit compares the second verification value with the first verification value parsed from the metadata block. If the two are equal, the unit generates a "pass" comparison result signal; if they are not equal, the unit generates a "fail" comparison result signal.

[0062] The execution control unit is responsible for controlling the machining operation. This unit receives the comparison result signal output by the verification and comparison unit. When a "pass" signal is received, the unit allows the CNC software to start the machining operation, that is, sends the execution command to the CNC equipment to begin machining according to the machining code. When a "fail" signal is received, the unit prevents the machining operation from starting and outputs a warning message on the CNC software interface, indicating to the operator that the file integrity verification failed and suggesting checking the file source or obtaining a correct NC file again.

[0063] Through the collaborative work of the above four units, the CNC terminal parsing and verification module can automatically complete the parsing, previewing and verification of enhanced NC files, providing a guarantee for safe machining.

[0064] As a possible implementation, the start identifier and end identifier adopt a format compatible with NC file comment syntax, including bracket comment form or semicolon comment form, so that CNC software without integrated parsing function ignores the metadata block.

[0065] In this embodiment, the specific formats of the start identifier and the end identifier can be selected according to the comment syntax of the NC file to ensure compatibility with existing systems.

[0066] As a specific implementation method, bracket comments can be used. In this format, the start identifier is "(PREVIEW_BEGIN)" and the end identifier is "(PREVIEW_END)". The entire metadata block is enclosed within these brackets, for example: "(PREVIEW_BEGIN)...(PREVIEW_END)". Since brackets are the comment identifier in the NC file standard, any software conforming to the NC file format specification will treat the content within the brackets as a comment and ignore it.

[0067] As another specific implementation method, semicolon comments can be used. In this format, the start identifier is ";PREVIEW_BEGIN", and the end identifier is ";PREVIEW_END". Each line of the metadata block begins with a semicolon, for example: ";PREVIEW_BEGIN", ";Image Encoded Data", ";MD5 Checksum", ";PREVIEW_END". Since the semicolon is a commonly used line comment identifier in NC files, any software conforming to the NC file format specification will treat lines beginning with a semicolon as comments and ignore them.

[0068] See Figure 2 , Figure 2 This is a schematic diagram of the structure of an electronic device 300 provided in an embodiment of this application. The electronic device 300 includes one or more processors 31 and a memory 32. The memory 32 is connected to one or more processors 31, for example, via a bus.

[0069] Processor 31 is configured to support the electronic device 300 in performing the corresponding functions in the methods described in the above method embodiments. Processor 31 may be a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof. The aforementioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The aforementioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0070] Memory 32 is used to store program code, etc. Memory may include volatile memory (VM), such as random access memory (RAM); memory may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); memory 32 may also include combinations of the above types of memory.

[0071] The memory 32 can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions / modules corresponding to the method for preventing misloading of the NC file of the dental model in the embodiments of this application. The processor 31 executes the method for preventing misloading of the NC file of the dental model and various functional applications and data processing of the buccal width editing device of the dental model by running the non-volatile software programs, instructions, and modules stored in the memory 32, that is, it realizes the functions of the method for preventing misloading of the NC file of the dental model and the various modules or units of the buccal width editing device of the dental model provided in the above method embodiments.

[0072] The memory 32 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function. The data storage area may store data created based on the use of the buccal width editing device of the dental model. In some embodiments, the memory 32 may optionally include memory remotely located relative to the processor 31, which can be connected to the buccal width editing device of the dental model via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0073] One or more modules are stored in memory 32. When executed by one or more processors 31, they execute the method for preventing erroneous loading of the NC file of the tooth model in any of the above method embodiments. For example, they execute the method steps described in the above method embodiments to realize the functions of the modules described in the above device embodiments.

[0074] This application also provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the method as described in the foregoing embodiments.

[0075] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0076] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.

Claims

1. A method for preventing accidental loading of NC files, characterized in that, include: Obtain the NC file, which contains machining code; In CAM, a two-dimensional preview image of the machining model corresponding to the NC file is generated by rendering. The two-dimensional preview image is converted into image encoded data according to a preset text encoding method, and the first verification value of the NC file is calculated according to a preset verification algorithm. The first verification value is calculated based on the main content of the NC file excluding metadata. The metadata block is determined based on the image encoding data and the first check value. A start identifier and an end identifier are added to the beginning and end of the metadata block, respectively. The metadata block is then written into the header of the NC file to generate an enhanced NC file. The metadata block is located before the machining code. When importing the enhanced NC file into the CNC, the file header is scanned, the metadata block is extracted based on the start identifier and end identifier, and the image encoding data and the first check value are parsed from the metadata block. The parsed image encoding data is decoded to generate a preview image, which is then displayed on the CNC software interface. Based on the main content of the enhanced NC file excluding the metadata block, the preset verification algorithm is used to calculate the second verification value, and the second verification value is compared with the first verification value. If the comparison is consistent, the processing operation is performed; if the comparison is inconsistent, the processing operation is prohibited.

2. The method according to claim 1, characterized in that, The step of rendering and generating a two-dimensional preview image of the machining model corresponding to the NC file in CAM includes: Based on the layout, machining path, and tool information in the CAM software, a vector graphic representing the appearance of the finished product after machining is generated. The vector graphics are rendered into image data in a predetermined format.

3. The method according to claim 1, characterized in that, The preset verification algorithm is a hash algorithm or a cyclic redundancy check algorithm; When calculating the first verification value, the calculation scope includes the machining code portion of the NC file, but excludes the metadata block to be written.

4. The method according to claim 1, characterized in that, The start identifier and end identifier are unique annotation identifiers, and their format is compatible with the annotation syntax of NC files so that CNC software without integrated parsing functions can ignore the metadata block.

5. A system for preventing accidental loading of NC files, characterized in that, include: The CAM processing module is configured to: acquire an NC file containing machining code; render and generate a two-dimensional preview image of the machining model corresponding to the NC file; convert the two-dimensional preview image into image encoded data according to a preset text encoding method; calculate a first verification value based on the machining code content in the NC file excluding metadata according to a preset verification algorithm; encapsulate the image encoded data and the first verification value into a metadata block; add preset start identifiers and end identifiers to the beginning and end of the metadata block and write it into the header of the NC file before the machining code to generate an enhanced NC file. The CNC-side parsing and verification module is configured as follows: when importing the enhanced NC file, it identifies the start identifier and end identifier in the file header, extracts and parses the metadata block to obtain image encoded data and a first verification value, decodes the image encoded data to generate a preview image and displays it, calculates a second verification value based on the machining code content in the imported enhanced NC file other than the metadata block using the preset verification algorithm, compares the second verification value with the first verification value, and determines whether to allow the machining operation based on the comparison result.

6. The system according to claim 5, characterized in that, The CAM terminal processing module includes: The image rendering unit is configured to generate a two-dimensional vector preview image based on the layout information, toolpath and tool parameters in the CAM software, and render the two-dimensional vector preview image into image data in a predetermined format; The encoding unit is configured to convert the image data into image encoded data according to a preset text encoding method; The verification calculation unit is configured to calculate a verification value as the first verification value based on the machining code portion of the NC file according to a preset verification algorithm before inserting the metadata block; The file writing unit is configured to encapsulate the image encoding data and the first check value according to a preset format, and add a start identifier and an end identifier before writing them into the header of the NC file.

7. The system according to claim 5, characterized in that, The CNC-side parsing and verification module includes: The file scanning unit is configured to scan the file header line by line during the import of the enhanced NC file, identify the start identifier and the end identifier, and extract the metadata content between the start identifier and the end identifier. The image decoding unit is configured to decode the image encoded data in the metadata into image data and transmit it to the CNC software interface for display. The verification and comparison unit is configured to calculate the verification value based on the machining code content other than the metadata block in the imported enhanced NC file, and compare the calculated verification value with the first verification value extracted from the metadata block to generate a comparison result signal. The execution control unit is configured to control the start or stop of the processing operation based on the comparison result signal, and to output a warning message when the comparison is inconsistent.

8. The system according to claim 5, characterized in that, The start and end identifiers adopt a format compatible with NC file comment syntax, including bracket comment or semicolon comment, so that CNC software without integrated parsing function can ignore the metadata block.

9. An electronic device, characterized in that, The device includes a memory and a processor, the memory being connected to the processor, the processor being configured to execute one or more computer programs stored in the memory, the processor causing the electronic device to perform the method as described in any one of claims 1-4 when executing the one or more computer programs.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1-4.