Method for parsing and displaying CAD drawing

By converting CAD drawings into JSON format and parsing them into graphic and text objects, and combining this with regular expression matching technology, the problems of low efficiency and information separation in railway signal equipment drawing management have been solved, enabling efficient display and association of equipment information in a browser.

CN115495416BActive Publication Date: 2025-12-05HENAN SPLENDOR SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210757396.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-30
Publication Date
2025-12-05
Estimated Expiration
2042-06-30

AI Technical Summary

Technical Problem

In existing technologies, railway signal equipment drawing management is inefficient, station as-built drawings are inconvenient to view, information systems cannot parse and recognize CAD drawings, equipment information is separated from drawings and requires manual drawing to link them, and text information cannot be displayed and retrieved in a browser.

Method used

By loading CAD drawings and converting them to JSON format, parsing arrays of graphic and text objects, drawing graphics using canvas tags, displaying text using text tags, and displaying the drawings in the browser, while extracting equipment information through regular expression matching to generate equipment ledger information.

Benefits of technology

It enables efficient display of CAD drawings in a browser, supports the association of drawings with equipment ledgers, reduces manual drawing workload, improves the efficiency of information management, and supports interactive operation of graphics and text.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115495416B_ABST
    Figure CN115495416B_ABST
Patent Text Reader

Abstract

The application provides a CAD drawing analysis and display method, which comprises the following steps: S1, loading a CAD drawing and performing format conversion to obtain a first JSON file containing a graphic element array; S2, analyzing the graphic element array in the first JSON file to generate a second JSON file containing a text object array and a graphic object array; S3, reading the second JSON file, traversing the text object array and the graphic object array, performing graphic object drawing based on a canvas label, performing text object drawing based on a text label, and calling a rendering component to render the graphic objects and the text objects in the canvas range after the drawing is completed, so that graphic display is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to CAD drawing parsing and display technology, specifically, to a method for parsing and displaying CAD drawings. Background Technology

[0002] In the current railway signaling equipment drawing management process, after a station is newly built, overhauled, or modified, the construction unit provides the signaling section with the station's as-built signaling drawings. The signaling section prints the drawings and binds them into a drawing manual. When the drawings need to be consulted for troubleshooting or other purposes, the drawing manual is temporarily consulted. After opening it, the corresponding station is found according to the table of contents, and then the corresponding equipment location is found in the station's drawings, and the surrounding situation of the equipment is observed. If it is necessary to find cable route information or indoor wiring information, the cable route diagram or indoor wiring diagram drawing manual needs to be consulted. Signaling equipment ledger information is generally stored in Excel or in a separate information system (such as a signaling equipment history book system). Such systems generally only provide equipment ledger management. Station drawings are generally Visio drawings redrawn by the signaling section, and the location binding of equipment on the station drawings can only be done manually by drawing or placing them.

[0003] This management approach has the following drawbacks:

[0004] 1. Viewing the station's as-built drawings is inconvenient. The electronic version of the station's as-built drawings is a CAD drawing in DWG format, which requires the installation of CAD viewing software on the computer beforehand. The printed version of the drawings is bound into a book, requiring a trip to the archives to find and browse through them, which is very inefficient.

[0005] 2. The drawings in the information system need to be redrawn. Currently, the signaling section uses a signaling equipment history book system to manage equipment information and station drawings. However, this system cannot parse and recognize CAD drawings in DWG format. Signaling section personnel need to redraw the drawings using Visio software within the system based on the as-built drawings, resulting in a huge workload for maintenance staff.

[0006] 3. Station equipment information is separated from station as-built drawings. Equipment information is stored in Excel or a separate information system, while station as-built drawings are stored as files on a computer. The station drawings for a line are printed and bound together, making it impossible to establish a link between the drawings and the equipment.

[0007] The invention patent application document with publication number CN107239266A discloses a method for displaying CAD drawings on a web front-end without plugins. By parsing the CAD drawings on the server, the front-end client uses the Javascript scripting language to draw the CAD drawings in a Canvas control, thus achieving the display of CAD drawings on the front-end client without plugins. However, during the drawing process, the Canvas control also draws text elements as graphic primitives, so it is impossible to obtain the text information from the CAD drawings, and therefore it is impossible to associate and bind the station equipment information with the CAD drawings.

[0008] In order to solve the above problems, people have been seeking an ideal technological solution. Summary of the Invention

[0009] The purpose of this invention is to address the shortcomings of existing technologies by providing a method for parsing and displaying CAD drawings.

[0010] To achieve the above objectives, the technical solution adopted by this invention is: a method for parsing and displaying CAD drawings, comprising the following steps:

[0011] Step S1: Load the CAD drawing and perform format conversion to obtain the first JSON file containing an array of graphic elements;

[0012] Step S2: Parse the array of graphic elements in the first JSON file to generate a second JSON file containing an array of text objects and an array of graphic objects;

[0013] Step S3: Read the second JSON file, iterate through the array of text objects and the array of graphic objects, draw graphic objects based on the canvas tag, draw text objects based on the text tag, and after drawing is completed, call the rendering component to render the graphic objects and text objects within the canvas area to achieve graphic display.

[0014] The present invention also provides an electronic information method for equipment CAD drawings, comprising the following steps: drawing railway signal equipment CAD drawings using the aforementioned CAD drawing parsing and display method;

[0015] During the graphic drawing process, the second JSON file is read and parsed to obtain text objects and graphic objects. Then, the text objects are matched with regular expressions based on the device names in the received device ledger information, and the device ledger information is bound to the corresponding text objects through mouse click events.

[0016] This invention also provides another method for electronic information processing of equipment CAD drawings, comprising the following steps:

[0017] The aforementioned methods for parsing and displaying CAD drawings are used to create CAD drawings for railway signaling equipment.

[0018] During the graphic drawing process, the second JSON file is read and parsed to obtain text objects and graphic objects. Then, the text objects are matched using a preset regular expression to extract equipment information and automatically generate basic equipment ledger information, which is then uploaded to the information system.

[0019] The present invention also provides a device for parsing and redrawing CAD drawings, comprising:

[0020] The drawing format conversion unit is used to load CAD drawings and convert their formats to obtain a first JSON file containing an array of graphic elements.

[0021] The graphics element parsing unit is used to parse the array of graphics elements in the first JSON file and generate a second JSON file containing an array of text objects and an array of graphics objects;

[0022] The graphics drawing unit is used to read the second JSON file, traverse the array of text objects and the array of graphics objects, draw graphics objects using the canvas tag, draw text objects using the text tag, and call the rendering component to render the graphics and text objects within the canvas area after drawing is completed, so as to realize the graphic display.

[0023] This invention has outstanding substantive features and significant progress compared to the prior art. Specifically, this invention provides a method and apparatus for parsing and redrawing CAD drawings of railway signaling equipment. By parsing the content of the CAD drawing, the parsed elements such as lines, ellipses, arcs, text, blocks, and insertion points are saved in JSON format, and graphic objects and text objects are generated based on the elements. Then, the canvas tag is used to draw the graphics, and the text tag is used to draw the text, so as to achieve the purpose of displaying the CAD drawing on the browser. At the same time, the text information in the CAD drawing can be extracted separately to facilitate later retrieval and matching, and realize the functional expansion of the CAD drawing.

[0024] This invention provides an electronic information method for equipment CAD drawings. During the process of displaying CAD drawings on a browser, regular expressions are used to match the text information in the drawings to automatically extract equipment information from the drawings and save it as basic information for the equipment ledger.

[0025] This invention also provides another method for electronic information processing of equipment CAD drawings. This method combines the display of CAD drawings on a browser with equipment ledgers, and provides the function of adding equipment binding to text information, which facilitates the expansion of functions in the drawings. Attached Figure Description

[0026] Figure 1 This is a schematic flowchart of Embodiment 1 of the present invention.

[0027] Figure 2 This is a schematic diagram of the structure of Embodiment 3 of the present invention. Detailed Implementation

[0028] The technical solution of the present invention will be further described in detail below through specific embodiments.

[0029] like Figure 1 As shown, a method for parsing and displaying CAD drawings includes the following steps:

[0030] Step S1: Load the CAD drawing and perform format conversion to obtain the first JSON file containing an array of graphic elements.

[0031] Preferably, the array of graphic elements includes circle elements, ellipse elements, arc elements, line segment elements, polyline elements, shadow elements, shadowed polyline elements, graphic block elements, insertion point elements, text line elements, text block elements, and attribute text elements. Since JSON is a lightweight data exchange format based on a subset of ECMAScript and is the mainstream data format for modern browsers, it is more suitable for parsing and displaying in browsers. Therefore, the third-party plugin DM_CAD2JSON_TOOL.exe is used to convert the DWG format CAD drawing and generate a first JSON file, which includes a JSON array of graphic elements.

[0032] Step S2: Parse the array of graphic elements in the first JSON file to generate a second JSON file containing an array of text objects and an array of graphic objects.

[0033] Specifically, in step S21, the graphic element array in the first JSON file is traversed, and the elements in the graphic element array are parsed according to the element definition to obtain the attribute data of the elements.

[0034] In practice, each element object has the following fixed properties: category (etype), element handle (handle), reference point coordinates (x, y), and color (stroke). Different categories (etype) also have different properties.

[0035] Line: array of inflection points on the line segment (points), line weight (lineWeight), dash type (dash), and whether to display with a fill shadow (shadow);

[0036] Ellipse: Horizontal axis radius r, vertical axis radius r2, whether to display with fill shadow;

[0037] Arc: Horizontal axis radius r, vertical axis radius r2, start angle startAngle, end angle endAngle, whether to display with fill shadow;

[0038] Text: Text content (text), font size (textSize), alignment (textAlign), number of lines (lines), rotation angle (angle), and whether the text is vertical;

[0039] Shadow: an array of child elements ents;

[0040] ShadowPolyLine: The array of points (inflection points) on the line segment;

[0041] Block element: unique identifier id, array of child elements ents;

[0042] Use: Refers to the block identifier blockId, the graphics transformation matrix mat, and the sub-element array ents.

[0043] Step S22: Create an element object based on the element's attribute data and preset creation rules. The preset creation rules are: create an ellipse object based on a circle element and / or an ellipse element; create an arc object based on an arc element; create a polyline object based on a line segment element and / or a polyline element; create a shadow object based on a shadow element; create a shadow polyline object based on a shadow polyline element; create a graphic block object based on a graphic block element; create a text object based on a text line element, a text block element, and / or attribute text element; and create a block reference object based on an insertion point element.

[0044] Step S23: After the traversal is completed, the block reference object is parsed, and a reference tree is generated according to the mapping relationship of the graphic block object. At the same time, the text objects in the reference tree are copied. Since there are also text objects in the block reference object, the text objects in the reference tree are copied, so that a one-to-one text object can be achieved during drawing.

[0045] Step S24: Extract all text objects to form a text object array, and extract ellipse objects, arc objects, polyline objects, shadow objects, shadow polyline objects, graphic block objects, and block reference objects to form a graphic object array;

[0046] Step S25: Store the text object array and the graphic object array in JSON format to form a second JSON file.

[0047] Step S3: Read the second JSON file, iterate through the array of text objects and the array of graphic objects, draw graphic objects based on the canvas tag, draw text objects based on the text tag, and after drawing is completed, call the rendering component to render the graphic objects and text objects within the canvas area to achieve graphic display.

[0048] This method parses the content of CAD drawings, saves the parsed elements such as lines, ellipses, arcs, text, blocks, and insertion points in JSON format, and generates graphic and text objects based on these elements. Then, the canvas tag is used to draw the graphics, and the text tag is used to draw the text, achieving the goal of displaying the CAD drawings in the browser. At the same time, the text information in the CAD drawings can be extracted separately for later retrieval and matching, and it is also convenient to add interactive events to the text objects in HTML, realizing the functional expansion of the CAD drawings.

[0049] In practice, step 3 involves the following steps:

[0050] Read the second JSON file, traverse the array of graphical objects and the array of text objects, parse the block reference objects, and generate a reference tree based on the mapping relationship of the graphical block objects;

[0051] Each graphic object is processed using the canvas tag in HTML5, generating a canvas drawing object and converting the local coordinates of the graphic object to canvas coordinates. The relevant API methods of the drawing object are called at the corresponding positions to draw the canvas drawing object, and its rendering range is calculated based on the attribute data of the graphic object.

[0052] The text object is processed using HTML5 text tags to generate HTML elements, and the local coordinates of the text object are converted into HTML coordinates. The HTML element is then displayed at the corresponding HTML coordinates, and its rendering range is calculated based on the attribute data of the text object.

[0053] After drawing is completed, the rendering range of the entire graphic and text objects is determined based on the rendering range of all graphic and text objects. The canvas size is then determined based on the rendering range of the entire graphic. The rendering component is then called to render the graphic and text objects within the canvas range to achieve graphic display.

[0054] In practical implementation, HTML rules can be used to add mouse drag events or scroll wheel events. When a mouse drag event or scroll wheel event is triggered, the displayable area of ​​the drawing is determined based on the size of the canvas, the position of the mouse center point, and the preset graphic scaling ratio. The rendering range of each graphic object and text object is compared with the displayable area, and graphic objects and / or text objects whose rendering range overlaps with the displayable area are displayed.

[0055] Example 2

[0056] The first JSON file contains only the information defined in the CAD drawing file. The position and dimensions of each element in the drawing need to be calculated during the drawing process. However, since viewing the drawing requires frequent zooming and dragging operations, the content of the visible area needs to be drawn every time you zoom or drag.

[0057] To reduce the computational load when drawing graphics each time, in this embodiment, when traversing the graphic element array in the first JSON file in step S2, the elements in the graphic element array are parsed according to the element definition to obtain the attribute data of the elements, and the rendering range is calculated based on the attribute data of the elements and added to the attribute data; specifically, the rendering range is the outer frame information of each element, that is, the coordinate information of the upper left and lower right corners.

[0058] Therefore, each element object has the following fixed properties:

[0059] Line: array of inflection points on the line segment (points), line weight (lineWeight), dash type (dash), rendering range (rect), and whether to display with a fill shadow (shadow);

[0060] Ellipse: horizontal axis radius r, vertical axis radius r2, rendering range rect, whether to display with fill shadow;

[0061] Arc: Horizontal axis radius r, vertical axis radius r2, start angle startAngle, end angle endAngle, rendering range rect, whether to display as fill shadow;

[0062] Text: Text content (text), font size (textSize), alignment (textAlign), number of lines (lines), rotation angle (angle), whether text is vertical (vertical), and rendering area (rect).

[0063] Shadow: array of child elements ents, rendering range rect;

[0064] ShadowPolyLine: An array of inflection points on the line segment (points) and a rendering range (rect);

[0065] Block element: unique identifier id, array of child elements ents, rendering range rect;

[0066] Use: Refers to the block identifier blockId, the graphics transformation matrix mat, the child element array ents, and the rendering range rect.

[0067] When processing each graphic object using the canvas tag in step S3, the rendering range in the attribute data of the graphic object is read; when processing a text object using the text tag, the rendering range in the attribute data of the text object is read.

[0068] After drawing is completed, the rendering range of the entire graphic object and text object is determined according to the rendering range of all graphic objects and text objects. The canvas size is determined according to the rendering range of the entire graphic object. The rendering component is called to render the graphic objects and text objects within the canvas range to realize the graphic display.

[0069] Add mouse drag events or scroll wheel events using HTML rules. When a mouse drag event or scroll wheel event is triggered, determine the displayable area of ​​the drawing based on the canvas size, the mouse center point position, and the preset graphic scaling ratio. Compare the rendering range of each graphic object and text object with the displayable area, and display the graphic objects and / or text objects whose rendering range overlaps with the displayable area.

[0070] Understandably, this speeds up graphics display because it eliminates the need to recalculate the rendering extent of graphic and text objects after each zoom and drag.

[0071] Example 3

[0072] This embodiment provides a device for parsing and displaying CAD drawings, such as... Figure 2 As shown, it includes:

[0073] The drawing format conversion unit is used to load CAD drawings and convert their formats to obtain a first JSON file containing an array of graphic elements.

[0074] The graphics element parsing unit is used to parse the array of graphics elements in the first JSON file and generate a second JSON file containing an array of text objects and an array of graphics objects;

[0075] The graphics drawing unit is used to read the second JSON file, traverse the array of text objects and the array of graphics objects, draw graphics objects based on the canvas tag, draw text objects based on the text tag, and call the rendering component to render the graphics and text objects within the canvas area after the drawing is completed, so as to realize the graphic display.

[0076] In practice, the graphic element parsing unit parses the graphic element array in the first JSON file and generates a second JSON file containing both an array of text objects and an array of graphic objects. The specific steps are as follows:

[0077] Traverse the graphic element array in the first JSON file, parse the elements in the graphic element array according to the element definition, and obtain the attribute data of the elements; the graphic element array includes circle elements, ellipse elements, arc elements, line segment elements, polyline elements, shadow elements, shadow polyline elements, graphic block elements, insertion point elements, text line elements, text block elements, and attribute text elements;

[0078] Element objects are created based on element attribute data and preset creation rules. The preset creation rules are as follows: ellipse objects are created based on circle elements and / or ellipse elements; arc objects are created based on arc elements; polyline objects are created based on line segment elements and / or polyline elements; shadow objects are created based on shadow elements; shadow polyline objects are created based on shadow polyline elements; graphic block objects are created based on graphic block elements; text objects are created based on text line elements, text block elements, and / or attribute text elements; and block reference objects are created based on insertion point elements.

[0079] After the traversal is complete, the block reference object is parsed, a reference tree is generated based on the mapping relationship of the graphic block objects, and the text objects in the reference tree are copied.

[0080] Extract all text objects to form a text object array, and extract ellipse objects, arc objects, polyline objects, shadow objects, shadow polyline objects, graphic block objects, and block reference objects to form a graphic object array;

[0081] The text object array and the graphic object array are stored in JSON format to form a second JSON file.

[0082] In practical implementation, the graphics drawing unit is used to read the second JSON file, traverse the text object array and the graphics object array, draw graphics objects based on canvas tags, draw text objects based on text tags, and after drawing is completed, call the rendering component to render the graphics objects and text objects within the canvas area to achieve graphics display. Specifically, the following is executed:

[0083] Read the second JSON file, traverse the array of graphical objects and the array of text objects, parse the block reference objects, and generate a reference tree based on the mapping relationship of the graphical block objects;

[0084] The canvas tag is used to process each graphic object, generate a canvas drawing object, convert the local coordinates of the graphic object to canvas coordinates, call the relevant API methods of the drawing object at the corresponding position to draw the canvas drawing object, and calculate its rendering range based on the attribute data of the graphic object;

[0085] The text object is processed using text tags to generate HTML elements, and the local coordinates of the text object are converted into HTML coordinates. The HTML element is displayed at the corresponding HTML coordinates, and its rendering range is calculated based on the attribute data of the text object.

[0086] After the drawing is completed, the rendering range of the entire graphic object and text object is determined according to the rendering range of all graphic objects and text objects. The canvas size is determined according to the rendering range of the entire graphic object. The rendering component is called to render the graphic objects and text objects within the canvas range to realize the graphic display.

[0087] In specific implementation, when the graphic element parsing unit traverses the graphic element array in the first JSON file, it parses the elements in the graphic element array according to the element definition, obtains the attribute data of the elements, calculates its rendering range based on the attribute data of the elements, and adds the rendering range to the attribute data.

[0088] When the graphics drawing unit processes each graphic object using the canvas tag, it reads the rendering range from the attribute data of the graphic object; when it processes a text object using the text tag, it reads the rendering range from the attribute data of the text object.

[0089] Since there is no need to recalculate the rendering extent after each zoom and drag, graphics display can be accelerated.

[0090] In specific implementation, it also includes a mouse event handling module, which uses HTML rules to add mouse drag events or scroll wheel events.

[0091] When a mouse drag event or scroll wheel event is triggered, the graphics drawing unit determines the displayable area of ​​the drawing based on the size of the canvas, the position of the mouse center point, and the preset graphics scaling ratio; it compares the rendering range of each graphic object and text object with the displayable area, and displays graphic objects and / or text objects whose rendering range overlaps with the displayable area.

[0092] Understandably, this speeds up graphics display because it eliminates the need to recalculate the rendering extent of graphic and text objects after each zoom and drag.

[0093] Example 4

[0094] This embodiment provides a method for electronic information processing of equipment CAD drawings, including the following steps:

[0095] The CAD drawing parsing and display method described in Example 1 or Example 2 is used to draw CAD drawings of railway signaling equipment;

[0096] During the graphic drawing process, the second JSON file is read and parsed to obtain text objects and graphic objects. Then, the text objects are matched using a preset regular expression to extract equipment information and automatically generate basic equipment ledger information, which is then uploaded to the information system.

[0097] Specifically, a preset regular expression is set according to the equipment naming rules to automatically extract equipment information from CAD drawings from text objects. It can be understood that the naming rules for different types of equipment are different, and the corresponding preset regular expressions are also different. In this embodiment, naming rules are given for three types of railway signal equipment: signals, turnouts, and track circuits. For example, the name of a signal starts with X, S, or D, or consists of 4-6 digits of pure numbers; turnouts consist of pure numbers or pure numbers + #; and track circuits end with G, or GA, GB, or G + numbers. The preset regular expression specified according to this naming rule can parse the equipment information of the station. If the parsing is incorrect, the user can manually adjust it.

[0098] This method is applied to the electrical engineering section's business data information system. It allows for the import of completed CAD drawings of stations into the system, parsing the graphic elements to generate intermediate JSON files. Real-time drawing is then performed in an HTML5-enabled browser, eliminating the need for electrical engineering personnel to redraw the drawings using Visio within the system, thus reducing the workload of maintenance staff. The method also supports graphical interface interaction using a mouse and keyboard in the browser. Furthermore, it can extract equipment information from the CAD drawings, automatically generating basic equipment ledger information, thereby linking the completed CAD drawings of the station with the equipment ledger and establishing a relationship between the CAD drawings and the equipment.

[0099] Example 5

[0100] This embodiment provides a method for electronic information processing of equipment CAD drawings, including the following steps:

[0101] The CAD drawing is drawn using the CAD drawing parsing and display method described in Example 1 or Example 2;

[0102] During the graphic rendering process, the second JSON file is read and parsed to obtain text and graphic objects. Then, the text objects are matched with regular expressions based on the device names in the received device ledger information. HTML rules are used to bind the device ledger information with the corresponding text objects through mouse click events. The browser's DOM objects and event mechanisms are invoked to respond to the user's mouse click events, such as displaying the device ledger information in a window. At the same time, CSS styles can be added to the text information according to the association relationship to display the abnormal status of the device.

[0103] Specifically, a preset regular expression is set according to the equipment naming rules to match text objects and find matching text objects. It can be understood that the naming rules for different types of equipment are different, and the corresponding preset regular expressions are also different. In this embodiment, naming rules are given for three types of railway signal equipment: signals, switches, and track circuits. For example, the name of a signal starts with X, S, or D, or consists of 4-6 digits of pure numbers; the name of a switch consists of pure numbers or pure numbers + #; and the name of a track circuit ends with G, or GA, GB, or G + numbers. The preset regular expression set according to this naming rule can find the text objects corresponding to the equipment information of the station, and thus bind the equipment ledger information with the corresponding text objects through mouse click events.

[0104] This method is applied to the electrical engineering section's business data information system. It allows for the import of completed CAD drawings of stations into the system, parsing the graphic elements to generate a JSON intermediate file. Real-time drawing is then performed in an HTML5-enabled browser, eliminating the need for personnel to redraw the drawings using Visio within the system, thus reducing maintenance workload. The method also supports graphical interface interaction via mouse and keyboard. Furthermore, it extracts equipment information from the CAD drawings. By performing regular expression matching on text objects based on equipment names in the received equipment ledger information, the method binds the equipment ledger information to the corresponding text objects via mouse click events, thus linking the completed CAD drawings to the equipment ledger and establishing a connection between them. When a mouse click event is executed, the bound equipment ledger information is displayed, further linking it to the CAD drawings for easy viewing and maintenance by construction personnel.

[0105] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them; although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications can still be made to the specific implementation of the present invention or equivalent substitutions can be made to some technical features without departing from the spirit of the technical solutions of the present invention, and all such modifications and substitutions should be covered within the scope of the technical solutions claimed in the present invention.

Claims

1. A method for parsing and displaying a CAD drawing, characterized by, The method comprises the following steps: Step S1, loading a CAD drawing and performing format conversion to obtain a first JSON file containing an array of graphic elements; Step S2, parsing the array of graphic elements in the first JSON file to generate a second JSON file containing an array of text objects and an array of graphic objects; Step S3, reading the second JSON file, traversing the array of text objects and the array of graphic objects, performing graphic object drawing based on a canvas tag, and performing text object drawing based on a text tag; When traversing the array of text objects, performing regular matching on the text objects based on a preset regular expression, extracting device information, and automatically generating device account basic information and uploading the device account basic information to an information system; or performing regular matching on the text objects according to a device name in received device account information, binding the device account information and the corresponding text objects through a mouse click event using an HTML rule, and calling a DOM object and an event mechanism of a browser to respond to a mouse click event of a user; After the drawing is completed, a rendering component is called to render the graphic objects and the text objects within the canvas range to realize graphic display.

2. The method for analyzing and displaying CAD drawings according to claim 1, wherein, The specific steps of step S2 are as follows: traversing the array of graphic elements in the first JSON file, parsing the elements in the array of graphic elements according to element definitions to obtain attribute data of the elements; the array of graphic elements comprises a circle element, an ellipse element, an arc element, a line segment element, a polyline element, a shadow element, a shadow polyline element, a graphic block element, an insertion point element, a text line element, a text block element, and an attribute text element; creating element objects based on the attribute data of the elements and a preset creation rule; the preset creation rule is that an ellipse object is created based on the circle element and / or the ellipse element, an arc object is created based on the arc element, a polyline object is created based on the line segment element and / or the polyline element, a shadow object is created based on the shadow element, a shadow polyline object is created based on the shadow polyline element, a graphic block object is created based on the graphic block element, a text object is created based on the text line element, the text block element, and / or the attribute text element, and a block reference object is created based on the insertion point element; after the traversal is completed, parsing the block reference object, generating a reference tree according to a mapping relationship of the graphic block object, and performing copy processing on the text objects in the reference tree; extracting all the text objects to form an array of text objects, and extracting the ellipse object, the arc object, the polyline object, the shadow object, the shadow polyline object, the graphic block object, and the block reference object to form an array of graphic objects; storing the array of text objects and the array of graphic objects in a JSON format to form the second JSON file.

3. The method of parsing and displaying a CAD drawing according to claim 2, wherein, The specific steps of step S3 are as follows: reading the second JSON file, traversing the array of graphic objects and the array of text objects, parsing the block reference object, and generating a reference tree according to a mapping relationship of the graphic block object; The canvas tag is used to process each graphic object, generate a canvas drawing object, and convert the local coordinates of the graphic object into canvas coordinates, and the relevant API method of the drawing object is called at the corresponding position to draw the canvas drawing object, and the rendering range of the graphic object is calculated according to the attribute data of the graphic object; The text tag is used to process the text object, generate an HTML element, and convert the local coordinates of the text object into HTML coordinates, and the HTML element is displayed at the corresponding HTML coordinates, and the rendering range of the text object is calculated according to the attribute data of the text object; After drawing, the rendering range of the entire graph is determined according to the rendering ranges of all graphic objects and text objects, the canvas size is determined according to the rendering range of the entire graph, and the rendering component is called to render the graphic objects and text objects within the canvas range to realize graph display.

4. The method of parsing and displaying a CAD drawing according to claim 3, wherein: In step S2, when traversing the graphic element array in the first JSON file, the elements in the graphic element array are parsed according to the element definition, the attribute data of the elements is obtained, and the rendering range of the elements is calculated based on the attribute data of the elements, and the rendering range is added to the attribute data; In step S3, when each graphic object is processed using the canvas tag, the rendering range in the attribute data of the graphic object is read; when the text object is processed using the text tag, the rendering range in the attribute data of the text object is read; After drawing, the rendering range of the entire graph is determined according to the rendering ranges of all graphic objects and text objects.

5. The method of parsing and displaying a CAD drawing according to claim 3 or 4, characterized in that: The mouse drag event or the scroll wheel event is added using the HTML rule, and when the mouse drag event or the scroll wheel event is triggered, the displayable area of the drawing is determined according to the size of the canvas, the position of the mouse center point, and the preset graphic zoom ratio; the rendering range of each graphic object and text object is compared with the displayable area, and the graphic objects and / or text objects whose rendering ranges overlap with the displayable area are displayed.

6. An apparatus for parsing and displaying a CAD drawing, characterized by comprising: The method comprises the steps of: The drawing format conversion unit is used to load the CAD drawing and perform format conversion to obtain a first JSON file containing a graphic element array; The graphic element parsing unit is used to parse the graphic element array in the first JSON file to generate a second JSON file containing a text object array and a graphic object array; The graphic drawing unit is used to read the second JSON file, traverse the text object array and the graphic object array, draw the graphic objects based on the canvas tag, draw the text objects based on the text tag, and call the rendering component to render the graphic objects and text objects within the canvas range after drawing is completed to realize graph display. In the process of performing the graphic drawing, when traversing the text object array, the text object is subjected to regular matching based on a preset regular expression, device information is extracted, and device account basic information is automatically generated and uploaded to an information system; or the text object is subjected to regular matching according to a device name in received device account information, the device account information and the corresponding text object are bound through a mouse click event using an HTML rule, and a DOM object and an event mechanism of a browser are called to respond to a mouse click event of a user.

7. The CAD drawing parsing and displaying device according to claim 6, wherein, The graphic element parsing unit parses the graphic element array in the first JSON file to generate a second JSON file containing a text object array and a graphic object array. The specific steps are as follows: Traverse the graphic element array in the first JSON file, parse the elements in the graphic element array according to element definitions, and obtain attribute data of the elements; the graphic element array includes a circle element, an ellipse element, a circular arc element, a line segment element, a polyline element, a shadow element, a shadow polyline element, a graphic block element, an insertion point element, a text line element, a text block element, and an attribute text element; Create element objects based on attribute data of the elements and preset creation rules; the preset creation rules are as follows: create an ellipse object based on a circle element and / or an ellipse element, create a circular arc object based on a circular arc element, create a polyline object based on a line segment element and / or a polyline element, create a shadow object based on a shadow element, create a shadow polyline object based on a shadow polyline element, create a graphic block object based on a graphic block element, create a text object based on a text line element, a text block element, and / or an attribute text element, and create a block reference object based on an insertion point element; After the traversal is completed, parse the block reference object, generate a reference tree according to a mapping relationship of the graphic block object, and perform copy processing on the text object in the reference tree; Extract all text objects to form a text object array, and extract ellipse objects, circular arc objects, polyline objects, shadow objects, shadow polyline objects, graphic block objects, and block reference objects to form a graphic object array; Store the text object array and the graphic object array in a JSON format to form a second JSON file.

8. The CAD drawing parsing and displaying apparatus according to claim 7, wherein, The graphic drawing unit is configured to read the second JSON file, traverse the text object array and the graphic object array, perform graphic object drawing based on a canvas tag, perform text object drawing based on a text tag, and call a rendering component to render the graphic objects and the text objects within a canvas range after the drawing is completed, so as to realize graphic display. Specifically, the following steps are performed: Read the second JSON file, traverse the graphic object array and the text object array, parse the block reference object, and generate a reference tree according to a mapping relationship of the graphic block object; Use the canvas tag to process each graphic object, generate a canvas drawing object, convert local coordinates of the graphic object into canvas coordinates, call a related API method of the drawing object to draw the canvas drawing object at a corresponding position, and calculate a rendering range of the graphic object according to attribute data of the graphic object. The text object is processed using a text label, an HTML element is generated, local coordinates of the text object are converted into HTML coordinates, the HTML element is displayed at the corresponding HTML coordinates, and a rendering range of the text object is calculated according to attribute data of the text object; After the drawing is completed, a rendering range of the entire graph is determined according to the rendering ranges of all the graphic objects and the text objects, a canvas size is determined according to the rendering range of the entire graph, the rendering component is called to render the graphic objects and the text objects in the canvas range, and the graph display is realized.

9. The CAD drawing parsing and displaying device according to claim 8, characterized in that: When the graphic element parsing unit traverses the graphic element array in the first JSON file, the elements in the graphic element array are parsed according to element definitions, attribute data of the elements are obtained, and a rendering range of each element is calculated based on the attribute data of the element, and the rendering range is added to the attribute data of the element; When the graphic drawing unit processes each graphic object using a canvas label, the rendering range in the attribute data of the graphic object is read; when a text object is processed using a text label, the rendering range in the attribute data of the text object is read.

Citation Information

Patent Citations

  • Method and device for carrying out no-plugin display of CAD (Computer-Aided Design) drawing on WEB front end

    CN107239266A

  • Webpage end CAD drawing viewing system and method based on WebGL technology

    CN111524212A