A method and system for displaying DWG two-dimensional drawings
By traversing layer by layer and recursively splitting vector objects in DWG files, the problem of text annotation affecting smoothness in large-scale DWG drawings is solved, and efficient rendering and smooth display of DWG files on the web are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEI JING YOU NUO KE JI GU FEN YOU XIAN GONG SI
- Filing Date
- 2022-05-20
- Publication Date
- 2026-05-26
AI Technical Summary
In large-scale DWG 2D drawings, text annotations affect the smoothness of the model. Existing lightweight methods do not fully reuse the text, especially when dealing with multi-line text (MText), which has a low reuse rate and causes the rendering process to lag or crash.
By traversing the DWG file layer by layer, non-text and text vector objects are separated, and the explode function is used for recursive splitting to construct a set of unit elements. Combined with the transformation matrix, efficient reuse is achieved.
The parsing and rendering of image data has been significantly optimized, improving the smoothness of displaying 2D vector models in DWG files on the web and enabling efficient geometric reuse of the smallest 2D elements.
Smart Images

Figure CN115203602B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of mechanical engineering technology, and in particular to a DWG two-dimensional drawing display method and system. Background Technology
[0002] In the engineering field, web-based viewing of DWG (Digital Graphics) drawings is widely used. This includes online viewing of drawings in project management systems, online annotation of issues on drawings in collaborative platforms, and real-time online comparison of design drawings in product maintenance systems. Currently, in addition to supporting functions such as layer management and graphic element operations (zooming in / out, measuring, labeling, setting graphic element colors, searching, etc.), this technology must also meet the requirements of integrating business data and business management logic. Therefore, DWG drawings are mostly rendered in vector format for web-based display.
[0003] When DWG (Dual Frame Works) drawings are very large, the number of primitives is enormous. The front-end rendering process involves drawing a large number of vector graphics, which can cause the rendering process to lag or crash. This is especially true for text annotations within the drawing, which significantly impact the smoothness of the model. Currently, commonly used lightweight DWG methods only achieve block reference reuse and instantiation-based rendering. While this improves rendering efficiency, the reuse effect is not thorough enough, especially when dealing with multi-line text (MText), where the reuse rate becomes extremely low. Summary of the Invention
[0004] In view of this, the present invention proposes a DWG two-dimensional drawing display method and system, which makes DWG two-dimensional drawings more suitable for web-based loading and storage, and realizes efficient reuse of two-dimensional vector elements on the web.
[0005] This invention provides a method for displaying a DWG (Digital Graphics File) 2D image. The method includes: receiving a DWG file and traversing the DWG file layer by layer to obtain all 2D vector objects; parsing each 2D vector object and dividing it into non-text vector objects and text vector objects; splitting the non-text vector objects and constructing a first set; drawing non-text vector objects based on the first set; splitting the text vector objects and constructing a second set; and drawing text vector objects based on the second set.
[0006] Furthermore, the step of traversing the DWG file layer by layer to obtain all two-dimensional vector objects includes: obtaining the hierarchical structure of the DWG file, including layer information and block reference information; traversing the DWG file layer by layer to obtain all two-dimensional vector objects and their corresponding transformation matrices.
[0007] Furthermore, the step of traversing the DWG file layer by layer includes: obtaining the minimum two-dimensional element information of all block references recursively using the explode function, while passing the transformation matrix between block references, to obtain the two-dimensional vector objects of all block references and the corresponding transformation matrix; obtaining the minimum two-dimensional element information of all entities recursively using the explode function, to obtain the two-dimensional vector objects of all entities.
[0008] Furthermore, the non-textual vector objects include lines, polylines, circles, ellipses, and arcs.
[0009] Furthermore, the step of splitting non-text vector objects and constructing a first set includes: recursively splitting polylines in non-text vector objects using the explode function until they are split into straight lines; converting circles and ellipses in non-text vector objects into equilateral polygons and splitting them into multiple straight lines; converting arcs in non-text vector objects into polylines of equal length at multiple points and splitting them into multiple straight lines; splitting all the obtained straight lines to obtain multiple unit lines, and performing transformation matrix calculations on all lines to obtain a first transformation matrix; and forming a first set based on the multiple unit lines and the corresponding first transformation matrix.
[0010] Furthermore, the step of drawing non-text vector objects based on the first set includes: creating line objects based on the coordinates of the two vertices of all unit lines in the first set; generating geometric objects by combining the material information of the line objects, and setting the generated geometric objects as reusable objects; and using the first transformation matrix information in the first set to copy and generate all non-text vector objects.
[0011] Furthermore, the text-type vector objects include single-line text and multi-line text.
[0012] Furthermore, the step of splitting the text-type vector object and constructing the second set includes: recursively splitting the multi-line text in the text-type vector object into multiple single-line texts based on the explode function; traversing the text content of each single-line text and splitting it into individual letters; splitting all the obtained letters to obtain multiple unit letters, and performing transformation matrix calculation on all letters to obtain the second transformation matrix; and forming the second set based on the multiple unit letters and the corresponding second transformation matrix.
[0013] Furthermore, the step of drawing text-type vector objects based on the second set includes: creating graphic objects based on all unit letters in the second set; generating geometric objects by combining the material information of the graphic objects, and setting the generated geometric objects as reusable objects; and copying and generating all text-type vector objects through the second transformation matrix information in the second set.
[0014] A second aspect of the present invention provides a DWG two-dimensional image display system, the system comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the steps of the DWG two-dimensional image display method as described above.
[0015] The aforementioned DWG 2D image display method and system uses the explode function to iteratively read the geometry, material, and attribute information of the smallest 2D element of the root node of the hierarchical structure, achieving efficient geometric reuse of the smallest 2D element, significantly optimizing the parsing and rendering of image data, and greatly improving the smoothness of displaying 2D vector models in DWG files on the web. Attached Figure Description
[0016] For illustrative and not limiting purposes, the invention will now be described with reference to preferred embodiments thereof, particularly the accompanying drawings, in which:
[0017] Figure 1 This is a flowchart of a DWG two-dimensional image display method provided in an embodiment of the present invention;
[0018] Figure 2 This is a schematic diagram of a DWG two-dimensional image display system provided in another embodiment of the present invention. Detailed Implementation
[0019] To better understand the above-mentioned objects, features, and advantages of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments of the present invention and the features thereof can be combined with each other.
[0020] Numerous specific details are set forth in the following description to provide a thorough understanding of the invention. The described embodiments are merely some, not all, of the embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0021] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0022] Figure 1This is a flowchart of a DWG two-dimensional image display method provided in an embodiment of the present invention. The DWG two-dimensional image display method receives and traverses a DWG file to obtain all two-dimensional vector objects, parses each two-dimensional vector object, and divides it into non-text vector objects and text vector objects. It then splits and draws the non-text vector objects and text vector objects, achieving efficient reuse of two-dimensional vector objects on the web.
[0023] Please see Figure 1 The method for displaying a DWG 2D image includes the following steps:
[0024] S100 receives a DWG file in binary format, traverses the DWG file layer by layer, and obtains all two-dimensional vector objects.
[0025] In this embodiment, the specific implementation of receiving binary format DWG files and traversing DWG files in step S100 is as follows:
[0026] S101 receives a DWG file in binary format and obtains the hierarchical structure of the DWG file.
[0027] Obtain the layer structure of the DWG file, including layer information and block reference information.
[0028] S102, traverse the hierarchical structure of the DWG file layer by layer to obtain all two-dimensional vector objects and their corresponding transformation matrices.
[0029] In this embodiment, the hierarchical structure of the DWG file is traversed layer by layer according to the database, layout, block reference, and entity to obtain all two-dimensional vector objects and their corresponding transformation matrices.
[0030] The specific implementation method for traversing the hierarchical structure of a DWG file layer by layer according to Database, Layout, Block, and Entity is as follows:
[0031] Since block references are nested within block references, the explore function is used to recursively obtain the minimum two-dimensional element information of all block references, while passing the transformation matrix between block references.
[0032] When encountering an entity, the exploit function is used to recursively obtain the minimum two-dimensional element information of all entities.
[0033] Through the above two recursive methods, a two-dimensional vector object (Object) and its corresponding transformation matrix (Transform) are finally obtained.
[0034] S200 parses each two-dimensional vector object and categorizes them into non-text vector objects and text vector objects.
[0035] In this embodiment, each two-dimensional vector object is parsed, and all two-dimensional vector objects are divided into non-text vector objects and text vector objects.
[0036] Non-text vector objects include lines, polylines, circles, ellipses, and arcs.
[0037] Among them, text-type vector objects mainly include single-line text (Text) and multi-line text (MText).
[0038] S300, split the non-text vector objects and construct the first set.
[0039] In this embodiment, non-text vector objects are split and constructed into a first set consisting of a unit line and a first transformation matrix (Transform). The non-text vector objects include lines, polylines, circles, ellipses, arcs, etc.
[0040] The specific implementation of splitting non-text vector objects and constructing a first set of unit lines (Line) + first transformation matrix (Transform) is as follows:
[0041] S301, for polylines, uses the explode function to recursively break down the polyline until it is broken down into lines.
[0042] S302 approximates a circle or ellipse into an equilateral 24-sided polygon and then divides it into 24 lines.
[0043] S303 approximates an arc as a polyline of equal length with 24 points, and then breaks it down into 24 lines.
[0044] S304. Split all the obtained lines to get multiple unit lines, and calculate the transformation matrix for all the lines, converting them into unit lines (the coordinates of vertex 1 are [0, 0, 0], and the coordinates of vertex 2 are [1, 0, 0]) + the first set of the first transformation matrix. Among them, the information of the first transformation matrix (Transform) includes scale, rotation, and translation.
[0045] S400. Split the text - type vector objects and construct the second set.
[0046] In this embodiment, split the text - type vector objects and construct them into the second set of letters + the second transformation matrix. Among them, the text - type vector objects include single - line text (Text) and multi - line text (MText), etc.
[0047] The specific implementation method of splitting the text - type vector objects and constructing them into the second set of letters (Letter) + transformation matrix (Transform) is as follows:
[0048] S401. When encountering multi - line text (MText), further recursively split the multi - line text into multiple single - line texts (Text) based on the explode function.
[0049] S402. Traverse the text content of each single - line text (Text) and split it into individual letters (Letter), including all the text and symbols.
[0050] S403. Split all the obtained letters (Letter) to get multiple unit letters, and calculate the transformation matrix for all the letters, converting them into unit letters with unit height and unit width (height 1m, width 1m) + the second set of the second transformation matrix (Transform).
[0051] When calculating the transformation matrix (Transform), consider the spaces between the characters and convert them into the transformation matrix.
[0052] S404. For each letter (Letter), convert it into a combination of "region + hole" through the SharpFont algorithm. For example, for the character "口", this letter is converted into a combination of a closed square plane and a closed square hole.
[0053] S500. Based on the first set, draw non - text - type vector objects.
[0054] In this embodiment, in Threejs, based on the unit lines and transformation matrix information in the first set, draw non - text - type vector objects.
[0055] Based on the first set, the specific implementation method for drawing non-text vector objects is as follows:
[0056] S501, when drawing a unit line in Three.js, generates a line object in Three.js using vertex 1 with coordinates [0,0,0] and vertex 2 with coordinates [1,0,0].
[0057] S502, combine the material information of the line object to generate a geometric object, and set the generated geometric object as a reuse object (Instance).
[0058] S503, using the first transformation matrix (Transform) information in the first set, copies and generates all non-text vector objects.
[0059] In this embodiment, line-level reuse is implemented for all non-text objects of the two-dimensional vector model in the DWG file. Only one copy of each material is recorded during storage, and the corresponding transformation matrix is added to improve loading capability.
[0060] S600, based on the second set, draws text-type vector objects.
[0061] In this embodiment, in Three.js, a vector object of the text class is drawn based on the second collection.
[0062] Based on the second set, the specific implementation of drawing vector objects of the text class is as follows:
[0063] S601, when drawing unit letters in Three.js, in the corresponding combination of "region + hole", the "region" is created as a graphic object in Three.js, while the "hole" is generated as a hole object and added to the holes of the graphic object.
[0064] S602, Combine the material information of the graphic object to generate a geometric object, and set the generated geometric object as a reusable object (Instance).
[0065] S603 uses the information from the second transformation matrix in the second set to copy and generate all text-type vector objects.
[0066] In this embodiment, letter-level reuse is implemented for all text objects in the two-dimensional vector model of the DWG file. Only one copy of each material is recorded during storage, and the corresponding transformation matrix is added to improve loading capacity.
[0067] In this embodiment, for a 2M large DWG file of design drawings, a material information only records one unit line object and more than 2,000 letter objects.
[0068] This embodiment uses the `explode` function to iteratively read the geometry, material, and attribute information of the smallest two-dimensional element of the root node of the hierarchical structure. Finally, it achieves efficient geometric reuse of the smallest two-dimensional element, significantly optimizes the parsing and rendering of image data, and greatly improves the smoothness of displaying two-dimensional vector models in DWG files on Three.js.
[0069] The above-described method for displaying DWG 2D images retains conventional geometric and material information while enabling full reuse of the smallest 2D elements, significantly improving the web client's ability to handle DWG 2D images and its rendering efficiency.
[0070] The above-mentioned DWG 2D image display method, combined with the splitting of CAD text graphics and the Three.js API interface, cleverly realizes the splitting and reuse of text at the individual text level, which can meet the needs of previewing larger DWG models on the web.
[0071] For the method embodiments described above, see [link to relevant documentation]. Figure 2 , Figure 2 This is a schematic diagram of a DWG two-dimensional image display system provided in another embodiment of the present invention. The device 100 may include:
[0072] Memory 101 is used to store computer programs;
[0073] When processor 102 executes the computer program stored in memory 101, it can perform the following steps:
[0074] Receive the DWG file and traverse the DWG file layer by layer to obtain all two-dimensional vector objects; parse each two-dimensional vector object and divide it into non-text vector objects and text vector objects; split the non-text vector objects and construct a first set; draw the non-text vector objects based on the first set; split the text vector objects and construct a second set; draw the text vector objects based on the second set.
[0075] For a description of the system provided by this invention, please refer to the above method embodiments; the invention itself will not be described in detail here.
[0076] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatuses, devices, and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.
[0077] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for displaying a DWG two-dimensional image, characterized in that, include: Receive the DWG file and traverse the DWG file layer by layer to obtain all two-dimensional vector objects; Each 2D vector object is parsed and divided into non-text vector objects and text vector objects; Split non-text vector objects and construct a first set; draw non-text vector objects based on the first set; Split the text-type vector objects and construct a second set; Based on the second set, draw a text-type vector object; The steps of splitting non-text vector objects and constructing the first set include: The explode function is used to recursively split polylines in non-text vector objects until they are broken down into straight lines. Convert circles and ellipses in non-text vector objects into equilateral polygons and then break them down into multiple straight lines; Convert the arc in a non-text vector object into a polyline of equal length with multiple points, and then break it down into multiple straight lines; All the obtained straight lines are split into multiple unit lines, and the transformation matrix is calculated for all the lines to obtain the first transformation matrix; A first set is formed based on multiple unit lines and their corresponding first transformation matrices; The step of drawing non-text vector objects based on the first set includes: Create line objects based on the coordinates of the two endpoints of all unit lines in the first set; Combine the material information of the line object to generate a geometric object, and set the generated geometric object as a reusable object; Using the information from the first transformation matrix in the first set, all non-text vector objects are copied and generated. The steps of splitting the text-type vector objects and constructing the second set include: Based on the explode function, multi-line text in a text vector object is recursively split into multiple single-line texts; Iterate through the text content of each single line of text and break it down into individual letters; All the obtained letters are split into multiple unit letters, and the transformation matrix is calculated for all letters to obtain the second transformation matrix; A second set is formed based on multiple unit letters and their corresponding second transformation matrices; Create a graphic object based on all unit letters in the second set; Combine the material information of the graphic object to generate a geometric object, and set the generated geometric object as a reusable object; Using the information from the second transformation matrix in the second set, all text-type vector objects are copied and generated.
2. The DWG two-dimensional image display method according to claim 1, characterized in that, The step of traversing the DWG file layer by layer to obtain all two-dimensional vector objects includes: Obtain the layer structure of the DWG file, including layer information and block reference information; By traversing the DWG file layer by layer, all two-dimensional vector objects and their corresponding transformation matrices are obtained.
3. The DWG two-dimensional image display method according to claim 2, characterized in that, The steps of traversing the DWG file layer by layer include: The minimum two-dimensional element information of all block references is obtained recursively using the explode function, while passing the transformation matrix between block references to obtain the two-dimensional vector objects of all block references and their corresponding transformation matrices. The `explode` function is used to recursively obtain the minimum two-dimensional element information of all entities, resulting in a two-dimensional vector object of all entities.
4. The DWG two-dimensional image display method according to claim 1, characterized in that, The non-text vector objects include lines, polylines, circles, ellipses, and arcs.
5. The DWG two-dimensional image display method according to claim 1, characterized in that, The text-type vector objects include single-line text and multi-line text.
6. A DWG two-dimensional image display system, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the DWG two-dimensional drawing display method as described in any one of claims 1 to 5 when executing the computer program.