Method for drawing electronic drawing sheet based on android mobile platform
By converting the world coordinate system to an absolute coordinate system and then to a relative coordinate system on Android devices, and combining this with rectangular area division, the problems of determining the scaling ratio and excessive hardware resource consumption in electronic drawing on Android devices are solved, achieving efficient drawing and dynamic interaction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HENAN SPLENDOR SCI & TECH
- Filing Date
- 2026-03-11
- Publication Date
- 2026-05-29
AI Technical Summary
When drawing electronic drawings on Android devices, there are problems such as the inability to determine the optimal scaling ratio and excessive hardware resource consumption, especially during element editing, which can easily cause the dimension chain to be interrupted.
By transforming from the world coordinate system to the absolute coordinate system and then to the relative coordinate system, and combining this with rectangular area division, the system enables the editing and scaling of graphic elements, and uses the Android Canvas drawing layer for graphic drawing and rendering.
It enables efficient drawing and dynamic interactive electronic drawings on Android devices, balances the convenience of scaling and editing, and solves the problem of excessive hardware resource consumption.
Abstract
Description
Technical Field
[0001] This invention relates to Android mobile terminal technology, electronic drawing data parsing and display technology, and in particular to a method for drawing electronic drawings based on the Android mobile platform. Background Technology
[0002] In the traditional engineering drawing management method, especially in the fields of railway signal equipment, there are the following significant problems: (1) Paper drawings are inefficient to consult and cannot meet the needs of rapid decision-making on site. (2) Equipment status updates rely on on-site paper and pen records, which are difficult to synchronize with electronic systems. Information cannot be directly input into the computer system on site, and station equipment information is separated from electronic drawings. (3) Drawings and equipment data lack correlation and cannot achieve real-time sharing across multiple terminals. Station drawings are stored as files on the computer. After printing and binding the station drawings for a line, it is impossible to establish a correlation between the drawings and the equipment information recorded on site. In projects that require the participation of multiple people, the modification and approval process of drawings is cumbersome and prone to errors due to version inconsistencies. (4) When the drawings do not match the actual situation on site, it is necessary to record the current situation on site in other auxiliary ways, and then edit and modify the drawings on the computer with the recorded information. If it is necessary to check with the situation on site after modification, the drawings need to be printed again and brought to the site. If there are discrepancies, this process needs to be repeated.
[0003] To achieve real-time sharing of drawings and equipment across multiple devices, electronic drawings can be created on the device itself. Existing methods exist, such as the Chinese invention patent application CN115495416A, published on December 20, 2022, which provides a method for parsing and displaying CAD drawings and for electronic information management of equipment CAD drawings. This method enables the display of CAD drawings in a browser and allows for the extraction of textual information from the CAD drawings, facilitating later retrieval and matching, and enabling functional expansion of the CAD drawings.
[0004] However, most portable devices currently use the Android system, and there are two main challenges to overcome when creating electronic drawings on Android devices: First, common electronic drawings (such as DWG format) usually use the world coordinate system and have no defined boundaries. In other words, such drawings are usually a sheet of paper that is laid flat and infinitely large in the computer logic. However, for the Android system, it does not know the range of useful information in this drawing, so it cannot display it at the optimal scaling ratio because it simply does not know what the optimal scaling ratio is. Secondly, electronic drawings contain too many elements, while Android devices have limited performance and screen size, making element movement and scaling inconvenient. Therefore, converting the world coordinate system to a relative coordinate system is necessary to determine the relationships between some elements, thereby reducing hardware resource consumption when scaling some elements. While relative coordinate systems have advantages in selecting and positioning display elements, they can easily cause interruptions in the dimension chain during element editing.
[0005] To address the aforementioned problems, this invention proposes an innovative solution that aims to achieve efficient drawing and dynamic interaction of electronic drawings through the Android platform, thereby improving the level of intelligence in drawing management. Summary of the Invention
[0006] The purpose of this invention is to overcome the shortcomings of existing technologies and propose a method for drawing electronic drawings based on the Android mobile platform.
[0007] In a first aspect, the present invention proposes a method for drawing electronic drawings based on data collected from the Android mobile platform, comprising: Load the electronic drawing and perform format conversion to obtain a formatted data file containing an array of graphic elements and the world coordinate system coordinates of each graphic element; Parse the formatted data file and use a recursive function to generate an array collection containing graphic elements; loop through the array collection containing graphic elements, separate the template object and data object in the array collection, and store them in different array collections respectively; Based on the nested reference relationships of the data and the relative coordinate relationships of the elements in the world coordinate system, after converting the world coordinate system to the absolute coordinate system, the array collection containing the graphic elements and the absolute coordinate system coordinates of the graphic elements are integrated into a tree structure. Traverse all graphic elements in the tree structure, determine the anchor point coordinates of each graphic element, and simultaneously calculate the size of the rectangular display area where the element is located. Dynamically compare to obtain the boundary of the entire electronic drawing. Each graphic element is displayed on the drawing as a rectangular icon with an area. Select the center point of the rectangular icon as the positioning point of the graphic element, that is, the anchor point of the graphic element. Convert the absolute coordinate system of a graphic element to a relative coordinate system for editing and / or scaling operations. Based on the Android origin coordinates, the relative coordinate system is converted to the absolute coordinate system applicable to Android display. Based on the screen length and width data, the scaling factor of the electronic drawing is calculated to initialize on the screen, and the coordinates of all graphic elements are scaled according to this scaling factor. Graphics are drawn using the Android Canvas drawing layer. Once completed, the rendering component is called to render the graphic element objects within the drawing layer's scope, thus displaying the graphics.
[0008] This invention achieves a balance between the number of conversion steps and the amount of computation by using a conversion scheme from the world coordinate system to the absolute coordinate system, the relative coordinate system, and the Android absolute coordinate system, combined with rectangular region division.
[0009] Preferably, the method for converting the absolute coordinate system of a graphic element to a relative coordinate system is as follows: Create a new drawing layer A, divide the entire drawing layer into n*m rectangles of equal size, where n and m are both odd numbers, and copy all displayable graphic elements of the original electronic drawing to the new drawing layer A according to their original absolute coordinate system positions. Iterate through and examine each graphic element inside the rectangle, and determine whether the display rectangular area of all graphic elements inside the rectangle is contained within the rectangle. If not, expand the area of the rectangle until the rectangular display area of all graphic elements with anchor points inside the rectangle is contained within the rectangle. In each rectangle, select the graphic element whose anchor point is closest to the center of the rectangle as the core graphic element of the rectangle, and convert the anchor point coordinates of other graphic elements inside the rectangle but outside the core graphic element into relative coordinates relative to the anchor point of the core graphic element. The rectangle at the center of drawing layer A is taken as the core rectangle. The anchor point of the core graphic element of the core rectangle is taken as the reference point of the entire drawing layer A. Starting from the core rectangle, the coordinates of the anchor points of the core graphic elements of other adjacent rectangles are converted into relative coordinates with respect to the anchor point of the core graphic element of the core rectangle. This process is gradually expanded outward until the relative positions of the anchor points of the core graphic elements of all rectangles are determined.
[0010] Preferably, the method for converting the absolute coordinate system of a graphic element to a relative coordinate system is as follows: Create a new drawing layer A, divide the entire drawing layer into n*m rectangles of equal size, where n and m are both odd numbers, and copy all displayable graphic elements of the original electronic drawing to the new drawing layer A according to their original absolute coordinate system positions. Iterate through and examine each graphic element inside the rectangle, and determine whether the display rectangular area of all graphic elements inside the rectangle is contained within the rectangle. If not, expand the area of the rectangle until the rectangular display area of all graphic elements with anchor points inside the rectangle is contained within the rectangle. In each rectangle, select the graphic element whose anchor point is closest to the center of the rectangle as the core graphic element of the rectangle, and convert the anchor point coordinates of other graphic elements inside the rectangle but outside the core graphic element into relative coordinates relative to the anchor point of the core graphic element. The rectangle at the center of drawing layer A is taken as the core rectangle. The anchor point of the core graphic element of the core rectangle is taken as the reference point of the entire drawing layer A. Starting from the core rectangle, the coordinates of the anchor points of the core graphic elements of other adjacent rectangles are converted into relative coordinates with respect to the anchor points of the core graphic elements of the adjacent rectangles. This process is gradually expanded outward until the relative positions of the anchor points of the core graphic elements of all rectangles are determined.
[0011] This invention transforms layers into multi-rectangular canvases, implements a relative coordinate system within the rectangles, and flexibly uses relative / absolute coordinate systems between rectangles, balancing the convenience of scaling and scrolling display (relative coordinate system) and editing (absolute coordinate system). Furthermore, by using variable-size rectangular spaces, it solves the problem of displaying cross-boundary elements within bounded rectangles.
[0012] Specifically, the method for editing graphic elements is as follows: When creating a new graphic element, execute: If the anchor point of the newly created graphic element is closer to the center of the rectangle than the anchor point of the core graphic element, then the newly created graphic element is set as the new core graphic element, and the relative coordinates of all other graphic elements in the rectangle are recalculated; the new core graphic element relinks the core graphic elements of adjacent rectangles and calculates their relative coordinates. If the newly created graphic element is not eligible to become a core graphic element, you only need to determine its relative coordinates to the core graphic element. When deleting a graphic element, execute: If the graphic element to be deleted is a core graphic element, first select candidate core graphic elements. The selection principle is that the anchor point of the graphic element is the second farthest from the center of the rectangle. Set the selected candidate core graphic elements as new core graphic elements, and re-establish the relative coordinates within the rectangle and between adjacent rectangles according to the new creation method. Then delete the graphic element to be deleted. If the graphic element to be deleted is not a core graphic element, it can be deleted directly; When editing graphic elements, execute: If the graphic element to be edited is an attribute text element, then you can directly modify the attribute text of the element in the database; When editing the position of a graphic element, first create a new graphic element in the new position using the new creation method, and then delete the graphic element in the old position using the delete method. Check if the rectangular display area of the edited graphic element is completely contained within its own rectangle. If not, expand the area of the rectangle until it is completely contained.
[0013] Specifically, the method for scaling graphic elements is as follows: Create a second new drawing layer B. The size of B can be varied, specifically the size of the area that the operator wants after zooming in and out with their finger. Create a third new drawing layer C. If there are rectangles in B that are not fully displayed, make those rectangles in B fully displayed and then transform them into C. The drawing software first displays the core graphic elements of all rectangles in C according to relative coordinates, then displays each element inside each rectangle according to relative coordinates, cuts out the parts that exceed the screen display range, and transmits them to the Android Canvas software for display on the screen.
[0014] Specifically, the method for parsing formatted data files and using recursive functions to generate an array collection containing graphical elements is as follows: The data in the graphic element array is parsed according to the element definition to obtain the element attribute data; The array of graphical elements includes, but is not limited to, the following: 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; Iterate through the array collection containing graphic elements, filter template elements and graphic elements, put the template elements in the collection into a reuse array collection, and put the graphic element objects into a drawing array collection.
[0015] Specifically, based on the nested reference relationships of the data and the relative coordinate system of the elements, the steps for integrating the array collection containing graphic elements into a tree structure and simultaneously calculating the rectangular area where the element is located are as follows: Based on the nested reference relationships of the data and the relative coordinate system of the elements, the tree-structured data is integrated, the block reference objects are parsed, a reference tree is generated according to the mapping relationship of the graphic block objects, and the text objects in the reference tree are copied. Extract all text objects to form a text object array, extract the coordinates of ellipse objects, arc objects, polyline objects, shadow objects, shadow polyline objects, graphic block objects, and block reference objects to form a graphic object array, calculate the relative coordinates / relative rotation angles on the drawing into absolute coordinates and absolute rotation angles, and simultaneously calculate the rectangular area where the element or combination of elements is located. Iterate through all elements in the graphic element array set, and dynamically compare them to obtain the minimum and maximum X and Y coordinates of the entire electronic drawing. These coordinates are the boundaries of the electronic drawing.
[0016] Specifically, the steps for coordinate transformation based on the Android origin coordinates, calculating the initial scaling factor of the electronic drawing on the screen based on the screen's length and width data, and scaling all graphic element coordinates according to this scaling factor are as follows: Based on the Android coordinate system, with the top left corner of the screen as (0,0), coordinate transformation is performed to convert the coordinate system of the data elements to the Android Canvas coordinate system. Based on the screen width and height data of the mobile device, the initial scaling factor of the electronic drawing on the screen is calculated, as well as the optimal scaling factor for landscape and portrait modes. Based on this factor, the coordinates of all graphic elements are scaled by the same factor to achieve the goal of placing the drawing in the center of the screen and filling the entire screen.
[0017] Specifically, the graphics are drawn based on the Android Canvas drawing layer. After completion, the rendering component is called to render the graphic element objects within the drawing layer. The specific steps to achieve graphic display are as follows: Based on the different attributes of each graphic element in different array collections, the graphics are drawn according to the drawing methods and parameters provided by Canvas. After completion, the rendering component is called to render the graphic element objects within the drawing layer range to achieve graphic display.
[0018] Secondly, the present invention provides a mobile terminal, comprising: At least one processor; A memory that is communicatively connected to the at least one processor; The memory stores instructions that can be executed by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the steps of the method for drawing electronic drawings based on the Android mobile platform.
[0019] This invention has outstanding substantive features and significant progress compared to the prior art, specifically: This invention determines the outer boundary by traversing all elements in the world coordinate system; it transforms the layer into a multi-rectangular canvas, implementing a relative coordinate system within the rectangles and flexibly using relative / absolute coordinate systems between rectangles, balancing the convenience of scaling and scrolling display (relative coordinate system) and editing (absolute coordinate system). By using a variable-size rectangular space, it addresses the challenge of displaying cross-boundary elements within bounded rectangles. Through a conversion scheme from the world coordinate system to the absolute coordinate system, then to the relative coordinate system, and finally to the Android absolute coordinate system, combined with rectangular region division, a balance is achieved between the number of conversion steps and the amount of computation involved. Detailed Implementation
[0020] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the embodiments of this application. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0021] The terms “comprising” and “having”, and any variations thereof, in the specification and claims of this application are intended to cover non-exclusive inclusion. Example 1
[0022] This embodiment proposes a method for drawing electronic drawings based on data collected from the Android mobile platform, including: S1: Load the electronic drawing and perform format conversion to obtain a formatted data file containing an array of graphic elements and the world coordinate system coordinates of each graphic element.
[0023] Specifically, a custom parser needs to be developed that supports input of various electronic drawing formats and can convert them into a unified data format. During the conversion process, the attribute information of graphic elements, such as color, line type, and layers, must be preserved.
[0024] The array of graphical elements includes, but is not limited to, the following: 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.
[0025] S2 parses the formatted data file and uses a recursive function to generate an array collection containing graphic elements; it iterates through the array collection containing graphic elements, separates the template object and data object in the array collection, and stores them in different array collections.
[0026] The method for generating an array collection containing graphic elements using a recursive function is as follows: parse the data in the graphic element array according to the element definition and obtain the attribute data of the elements.
[0027] Iterate through the array collection containing graphic elements, filter template elements and graphic elements, put the template elements in the collection into a reuse array collection, and put the graphic element objects into a drawing array collection.
[0028] S3, based on the nested reference relationship of the data and the relative coordinate relationship of the elements in the world coordinate system, after converting the world coordinate system to the absolute coordinate system, integrates the array collection containing graphic elements and the absolute coordinate system coordinates of the graphic elements into a tree structure.
[0029] Specifically, based on the nested reference relationships of the data and the relative coordinate system of the elements, the tree-structured data is integrated, the block reference objects are parsed, a reference tree is generated according to the mapping relationship of the graphic block objects, and the text objects in the reference tree are copied. Extract all text objects to form a text object array, extract the coordinates of ellipse objects, arc objects, polyline objects, shadow objects, shadow polyline objects, graphic block objects, and block reference objects to form a graphic object array, calculate the relative coordinates / relative rotation angles on the drawing into absolute coordinates and absolute rotation angles, and simultaneously calculate the rectangular area where the element or combination of elements is located. Iterate through all elements in the graphic element array set, and dynamically compare them to obtain the minimum and maximum X and Y coordinates of the entire electronic drawing. These coordinates are the boundaries of the electronic drawing.
[0030] S4: Traverse all graphic elements in the tree structure, determine the anchor point coordinates of each graphic element, and simultaneously calculate the size of the rectangular display area where the element is located, dynamically comparing to determine the boundary of the entire electronic drawing; where each graphic element is displayed on the drawing as a rectangular icon with an area, and the center point of the rectangular icon is selected as the positioning point of the graphic element, that is, the anchor point of the graphic element.
[0031] S5 converts the absolute coordinate system of a graphic element to a relative coordinate system for editing and / or scaling operations.
[0032] In some exemplary embodiments, the method for converting the absolute coordinate system of a graphic element to a relative coordinate system can be: Create a new drawing layer A, divide the entire drawing layer into n*m rectangles of equal size, where n and m are both odd numbers, and copy all displayable graphic elements of the original electronic drawing to the new drawing layer A according to their original absolute coordinate system positions. Iterate through and examine each graphic element inside the rectangle, and determine whether the display rectangular area of all graphic elements inside the rectangle is contained within the rectangle. If not, expand the area of the rectangle until the rectangular display area of all graphic elements with anchor points inside the rectangle is contained within the rectangle. In each rectangle, select the graphic element whose anchor point is closest to the center of the rectangle as the core graphic element of the rectangle, and convert the anchor point coordinates of other graphic elements inside the rectangle but outside the core graphic element into relative coordinates relative to the anchor point of the core graphic element. The rectangle at the center of drawing layer A is taken as the core rectangle. The anchor point of the core graphic element of the core rectangle is taken as the reference point of the entire drawing layer A. Starting from the core rectangle, the coordinates of the anchor points of the core graphic elements of other adjacent rectangles are converted into relative coordinates with respect to the anchor point of the core graphic element of the core rectangle. This process is gradually expanded outward until the relative positions of the anchor points of the core graphic elements of all rectangles are determined.
[0033] In some exemplary embodiments, the method for converting the absolute coordinate system of a graphic element to a relative coordinate system can be: Create a new drawing layer A, divide the entire drawing layer into n*m rectangles of equal size, where n and m are both odd numbers, and copy all displayable graphic elements of the original electronic drawing to the new drawing layer A according to their original absolute coordinate system positions. Iterate through and examine each graphic element inside the rectangle, and determine whether the display rectangular area of all graphic elements inside the rectangle is contained within the rectangle. If not, expand the area of the rectangle until the rectangular display area of all graphic elements with anchor points inside the rectangle is contained within the rectangle. In each rectangle, select the graphic element whose anchor point is closest to the center of the rectangle as the core graphic element of the rectangle, and convert the anchor point coordinates of other graphic elements inside the rectangle but outside the core graphic element into relative coordinates relative to the anchor point of the core graphic element. The rectangle at the center of drawing layer A is taken as the core rectangle. The anchor point of the core graphic element of the core rectangle is taken as the reference point of the entire drawing layer A. Starting from the core rectangle, the coordinates of the anchor points of the core graphic elements of other adjacent rectangles are converted into relative coordinates with respect to the anchor points of the core graphic elements of the adjacent rectangles. This process is gradually expanded outward until the relative positions of the anchor points of the core graphic elements of all rectangles are determined.
[0034] Specifically, the method for editing graphic elements is as follows: When creating a new graphic element, execute: If the anchor point of the newly created graphic element is closer to the center of the rectangle than the anchor point of the core graphic element, then the newly created graphic element is set as the new core graphic element, and the relative coordinates of all other graphic elements in the rectangle are recalculated; the new core graphic element relinks the core graphic elements of adjacent rectangles and calculates their relative coordinates. If the newly created graphic element is not eligible to become a core graphic element, you only need to determine its relative coordinates to the core graphic element. When deleting a graphic element, execute: If the graphic element to be deleted is a core graphic element, first select candidate core graphic elements. The selection principle is that the anchor point of the graphic element is the second farthest from the center of the rectangle. Set the selected candidate core graphic elements as new core graphic elements, and re-establish the relative coordinates within the rectangle and between adjacent rectangles according to the new creation method. Then delete the graphic element to be deleted. If the graphic element to be deleted is not a core graphic element, it can be deleted directly; When editing graphic elements, execute: If the graphic element to be edited is an attribute text element, then you can directly modify the attribute text of the element in the database; When editing the position of a graphic element, first create a new graphic element in the new position using the new creation method, and then delete the graphic element in the old position using the delete method. Check if the rectangular display area of the edited graphic element is completely contained within its own rectangle. If not, expand the area of the rectangle until it is completely contained.
[0035] Specifically, the method for scaling graphic elements is as follows: Create a second new drawing layer B. The size of B can be varied, specifically the size of the area that the operator wants after zooming in and out with their finger. Create a third new drawing layer C. If there are rectangles in B that are not fully displayed, make those rectangles in B fully displayed and then transform them into C. The drawing software first displays the core graphic elements of all rectangles in C according to relative coordinates, then displays each element inside each rectangle according to relative coordinates, cuts out the parts that exceed the screen display range, and transmits them to the Android Canvas software for display on the screen.
[0036] S6 converts the relative coordinate system to the absolute coordinate system applicable to Android display based on the Android origin coordinates. Based on the screen length and width data, it calculates the initial scaling factor of the electronic drawing on the screen and scales the coordinates of all graphic elements according to this scaling factor.
[0037] Specifically, the steps for coordinate transformation based on the Android origin coordinates, calculating the initial scaling factor of the electronic drawing on the screen based on the screen's length and width data, and scaling all graphic element coordinates according to this scaling factor are as follows: Based on the Android coordinate system, with the top left corner of the screen as (0,0), coordinate transformation is performed to convert the coordinate system of the data elements to the Android Canvas coordinate system. Based on the screen width and height data of the mobile device, the initial scaling factor of the electronic drawing on the screen is calculated, as well as the optimal scaling factor for landscape and portrait modes. Based on this factor, the coordinates of all graphic elements are scaled by the same factor to achieve the goal of placing the drawing in the center of the screen and filling the entire screen.
[0038] S7 uses the Android Canvas drawing layer to draw graphics. After completion, it calls the rendering component to render the graphic element objects within the drawing layer to achieve graphic display.
[0039] Specifically, based on the different attributes of each graphic element in different array collections, the graphics are drawn according to the drawing methods and parameters provided by Canvas. After completion, the rendering component is called to render the graphic element objects within the drawing layer to achieve graphic display. Example 2
[0040] The difference between this embodiment and Embodiment 1 is that it provides a specific method for converting the absolute coordinate system of a graphic element into a relative coordinate system.
[0041] (1) Overview of the overall architecture In this embodiment, three independent drawing layer objects are first created when the Android application starts: The raw drawing layer (Layer-0) is responsible for loading and rendering all graphical elements parsed from lightweight data exchange formats (such as JSON and XML). This layer maintains the complete graphical set without performing any coordinate transformations or tile processing.
[0042] Layer A (or Layer-A): Based on Layer-0, the canvas is geometrically divided into n rows and m columns of rectangular grid blocks (n and m are both odd numbers), and the core graphic element is determined within each rectangular grid. All graphic elements in this drawing layer are stored in coordinates relative to the core graphic element.
[0043] The drawing layer (Layer-Display) extracts several rectangular blocks corresponding to the current window from Layer-A based on the user's zoom and pan operations, restores the graphic elements within the rectangular blocks to absolute coordinates, and then draws them onto the AndroidCanvas.
[0044] (2) Canvas division and mesh generation Canvas size acquisition: In the onSurfaceCreated callback, call DisplayMetrics to get the device screen width, height and density.
[0045] Canvas logical dimensions: Calculate the logical width W and height H based on the parsed electronic drawing boundaries (minimum X, Y and maximum X, Y), and record the coordinates of the lower left corner origin (X0, Y0).
[0046] Determine the number of grid rows and columns: To ensure that the size of each rectangular block is relatively uniform after division and can cover the entire drawing, the default values are n=2k+1 and m=2. l +1(k, l (where k is a positive integer), where k = ceil(sqrt(W / S)) and l = ceil(sqrt(H / S)), and S is the preset rectangular block size (e.g., 5000 units). This ensures that even if the drawing size is abnormally large, it can automatically adapt by increasing n and m.
[0047] Rectangular block definition: Each rectangular block is represented by the coordinates of its lower left corner (x_i, y_j) and its width and height (Δx, Δy), where Δx = W / n and Δy = H / m. The coordinate system of all blocks is based on the original coordinate system of the drawing.
[0048] (3) Selection of core graphic elements The set of elements within a block: Traverse all graphic elements (including points, lines, arcs, text, etc.) in Layer-0, and determine the rectangular block to which the graphic element belongs based on the coordinates of its geometric center point. Each block maintains a temporary list E_ij.
[0049] Geometric center calculation: For each graphic element, calculate the geometric center C(e) according to its type: Point types (dots, symbols) can be used directly using their coordinates; A line segment is defined by the midpoint between its two endpoints; The midpoint of the arc is taken (after polar coordinate transformation). The polygon is calculated by averaging the values of all its vertices. The text box is centered at the bounding rectangle.
[0050] Core graphic element determination: Within the rectangular block R_ij, calculate the Euclidean distance d(e) = sqrt[(C_x(e)-x_center)^2+(C_y(e)-y_center)^2] from the center point of all points e∈E_ij to the block's exact center (x_i+Δx / 2, y_j+Δy / 2). The element with the smallest distance is the core graphic element Core_ij of that block. If there are no elements in the block, the core graphic element of that block is set to a null pointer and will be automatically removed during subsequent extraction in the viewport of the display layer.
[0051] (4) Establishment of a relative coordinate system Relative coordinates within a block: For each non-core graphic element e∈E_ij\{Core_ij} in block R_ij, calculate its relative coordinates (dx,dy)=(C_x(e)-C_x(Core_ij),C_y(e)-C_y(Core_ij)), and write these relative coordinates along with the element's geometric attributes (color, line width, layer, etc.) into the Layer-A data structure Block_ij.
[0052] Inter-block coordinate relationships: The relative relationship between block R_ij and its four adjacent blocks (top, bottom, left, and right) is achieved through coordinate transformation of core graphic elements. The system uses block R_c (i.e., i=(n+1) / 2, j=(m+1) / 2) at the center of the canvas as a reference, recording the absolute coordinates P_c=(Xc,Yc) of the core graphic element of that block. Then, it expands outwards from R_c using Breadth-First Search (BFS): For adjacent blocks R_i'j', if the absolute coordinates P_i'j' of its core graphic element Core_i'j' are known, then the relative coordinates of Core_i'j' are marked as (P_i'j'−P_c), and P_i'j' is set as the new reference point to continue expanding outward.
[0053] This progressive approach ensures that the relative positions of the core graphic elements in all blocks form a unified relative coordinate network. Once the network is built, each element within a block only needs to store its coordinates relative to the core graphic element of that block.
[0054] (5) Establishment of benchmark points Core Rectangle: The rectangular block located at the exact center of the canvas (i=(n+1) / 2, j=(m+1) / 2) is defined as the core rectangle. The geometric center of its core graphical element Core_c is located exactly at the geometric center of the entire canvas. The absolute coordinates of Core_c are set as the reference point O_g, and the global ID of this point is stored in Layer-A.
[0055] Unification of relative coordinates: During the process of expanding from the core rectangle to the surrounding areas, at each step, the coordinates of the core graphic elements of adjacent blocks are converted into relative coordinates with respect to the determined reference point O_g. In this way, when the user performs any translation or scaling, only one coordinate transformation needs to be done on the reference point of the core rectangle, and the relative coordinates inside all blocks can be updated synchronously, greatly reducing the computational amount during real-time rendering.
[0056] (6) Block-level display during runtime When the user performs a pan or zoom gesture on the touch screen, first capture the zoom factor s and the translation vector (tx, ty) of the gesture in onTouchEvent, and then calculate the set of rectangular blocks B = {R_ij | R_ij intersects with the viewport} to be presented according to the logical range of the current viewport.
[0057] For each block to be presented, read the relative coordinates (dx_c, dy_c) of the core graphic elements from Layer-A, add them back to the reference point O_g (which has been transformed by scaling s and translation (tx, ty)), and obtain the absolute display coordinates of all graphic elements inside the block.
[0058] Finally, draw the restored geometric information into Layer-Display using the Canvas.draw* series of APIs, and let the Android system complete the screen refresh. Embodiment 3
[0059] This embodiment provides a specific method for implementing the editing of graphic elements.
[0060] (1) Editing entry: When the user long-presses a certain position in the drawing editing interface on the Android side, a "Edit / Delete / Add" shortcut menu pops up. After the user selects the corresponding operation, first locate the rectangle block R_ij where it is located through Hit-Test (map the touch point back to the original logical coordinates according to the magnification factor of the current viewport in Layer-Display), and obtain the core graphic element Core_ij of this block.
[0061] (2) Adding (new) elements Creation of new elements: The user draws a point or text near the center of the block R_ij, and the system generates a corresponding graphic object E_new and immediately calculates the geometric center C_new of this object.
[0062] Determination of core eligibility: The system compares the distance d_new between C_new and the center of the block (x_i + Δx / 2, y_j + Δy / 2) with the distance d_core of the current core graphic element Core_ij. If d_new < d_core, then E_new is eligible to become the new core graphic element.
[0063] Switching between core graphic elements: ① Update the core identifier: Clear the marker for Core_ij and change it to E_new.
[0064] ② Recalculate the internal coordinates of the block: Traverse all elements e_k in block R_ij except for the new core, recalculate the relative coordinates Rel(e_k)=(C_x(e_k)-C_x(E_new),C_y(e_k)-C_y(E_new)), and overwrite them into the data structure corresponding to Layer-A.
[0065] ③ Interlocking of Adjacent Block Coordinates: Because the replacement of the core graphics element affects the relative coordinate network between blocks, the system must traverse the connection relationships between the four neighboring blocks R_i±1,j and R_i,j±1 of R_ij. For each adjacent block R_pq, the coordinates of its core graphics element Core_pq are re-expressed as relative coordinates with respect to the new reference E_new: Rel(Core_pq)=(C_x(Core_pq)-C_x(E_new),C_y(Core_pq)-C_y(E_new)). This step can be completed with a single BFS update, ensuring that the connectivity of the network is not disrupted.
[0066] Persistence: All changes to relative coordinates are immediately written back to the local SQLite database block table after completion and synchronized to the cloud (if in collaborative mode).
[0067] If the new element does not have core qualifications: the system only records the relative coordinates between the element and the current core graphic element Rel(E_new)=(C_x(E_new)-C_x(Core_ij),C_y(E_new)-C_y(Core_ij)), and writes this information into the element list of block R_ij, without triggering any repositioning of core graphic elements.
[0068] (3) Delete element Locate the element to be deleted: Similarly, use Hit-Test to confirm the block R_ij where the graphic object E_del to be deleted is located, and determine whether it is the core graphic element of the block.
[0069] Deletion of non-core graphics elements: If E_del≠Core_ij, the system directly removes the object from the block's internal list and updates the status of the corresponding record in the database (marked as deleted or directly deleted row), without affecting the block's relative coordinate system.
[0070] Core graphics element deletion: If E_del = Core_ij, the system enters the core replacement process: ① Selection of candidate core: Iterate through all remaining elements in block R_ij, calculate their distances to the block center, and select the element with the second smallest distance, Core_ij', as a candidate. If only one element remains in the block, that element will inevitably become the new core.
[0071] ② Update the block: Change the Core_ij flag to Core_ij', and then recalculate the relative coordinates (relative to the new core) for all remaining elements inside the block, which is the same as steps ① and ② of the add operation.
[0072] ③ Inter-block coordinate network correction: Corresponding to the core replacement, the system retraces the adjacent blocks connected to R_ij and re-expresses their core graphical element coordinates relative to the new Core_ij'. This step is also completed using BFS to ensure that the entire relative coordinate network remains connected and acyclic.
[0073] Synchronization: After all changes are completed, the system immediately commits the transaction to ensure database consistency and sends a block core update message to the collaboration server so that other ends can synchronize the coordinate network.
[0074] (4) Edit element attributes Attribute Modification: Users can modify attributes such as color, line width, and text content of graphic objects. Because these attributes do not involve changes in geometric position, the system only needs to write the new values to the attribute fields of the corresponding elements in block R_ij.
[0075] Position Editing: If a user drags an existing element, the system will update the element's geometric center C(e) in real time. At this point, its relative coordinates must be reassessed. ① Calculate the new relative coordinates: Rel(e) = (C_x(e) - C_x(Core_ij), C_y(e) - C_y(Core_ij)).
[0076] ② Core Qualification Reassessment: If the element becomes smaller from the center of the block after dragging, the system will upgrade it to a core graphic element and execute the core graphic element switching step in (2). Otherwise, only the relative coordinates need to be updated.
[0077] Transaction control: All editing operations are performed within an SQLite transaction to prevent inconsistencies in block coordinates due to exceptions. Example 4
[0078] This embodiment provides a mobile terminal, including: At least one processor; A memory that is communicatively connected to the at least one processor; The memory stores instructions that can be executed by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the steps of the method for drawing electronic drawings based on the Android mobile platform as described in any one of Embodiments 1-3.
[0079] The methods and systems provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for collecting data and drawing electronic drawings based on the Android mobile platform, characterized in that: Load the electronic drawing and perform format conversion to obtain a formatted data file containing an array of graphic elements and the world coordinate system coordinates of each graphic element; Parse the formatted data file and use a recursive function to generate an array collection containing graphic elements; loop through the array collection containing graphic elements, separate the template object and data object in the array collection, and store them in different array collections respectively; Based on the nested reference relationships of the data and the relative coordinate relationships of the elements in the world coordinate system, after converting the world coordinate system to the absolute coordinate system, the array collection containing the graphic elements and the absolute coordinate system coordinates of the graphic elements are integrated into a tree structure. Traverse all graphic elements in the tree structure, determine the anchor point coordinates of each graphic element, and simultaneously calculate the size of the rectangular display area where the element is located. Dynamically compare to obtain the boundary of the entire electronic drawing. Each graphic element is displayed on the drawing as a rectangular icon with an area. Select the center point of the rectangular icon as the positioning point of the graphic element, that is, the anchor point of the graphic element. Convert the absolute coordinate system of a graphic element to a relative coordinate system for editing and / or scaling operations. Based on the Android origin coordinates, the relative coordinate system is converted to the absolute coordinate system applicable to Android display. Based on the screen length and width data, the scaling factor of the electronic drawing is calculated to initialize on the screen, and the coordinates of all graphic elements are scaled according to this scaling factor. Graphics are drawn using the Android Canvas drawing layer. Once completed, the rendering component is called to render the graphic element objects within the drawing layer's scope, thus displaying the graphics.
2. The method for drawing electronic drawings based on data acquisition using the Android mobile platform according to claim 1, characterized in that, The method for converting the absolute coordinate system of a graphic element to a relative coordinate system is as follows: Create a new drawing layer A, divide the entire drawing layer into n*m rectangles of equal size, where n and m are both odd numbers, and copy all displayable graphic elements of the original electronic drawing to the new drawing layer A according to their original absolute coordinate system positions. Iterate through and examine each graphic element inside the rectangle, and determine whether the display rectangular area of all graphic elements inside the rectangle is contained within the rectangle. If not, expand the area of the rectangle until the rectangular display area of all graphic elements with anchor points inside the rectangle is contained within the rectangle. In each rectangle, select the graphic element whose anchor point is closest to the center of the rectangle as the core graphic element of the rectangle, and convert the anchor point coordinates of other graphic elements inside the rectangle but outside the core graphic element into relative coordinates relative to the anchor point of the core graphic element. The rectangle at the center of drawing layer A is taken as the core rectangle. The anchor point of the core graphic element of the core rectangle is taken as the reference point of the entire drawing layer A. Starting from the core rectangle, the coordinates of the anchor points of the core graphic elements of other adjacent rectangles are converted into relative coordinates with respect to the anchor point of the core graphic element of the core rectangle. This process is gradually expanded outward until the relative positions of the anchor points of the core graphic elements of all rectangles are determined.
3. The method for drawing electronic drawings based on data acquisition using the Android mobile platform according to claim 1, characterized in that, The method for converting the absolute coordinate system of a graphic element to a relative coordinate system is as follows: Create a new drawing layer A, divide the entire drawing layer into n*m rectangles of equal size, where n and m are both odd numbers, and copy all displayable graphic elements of the original electronic drawing to the new drawing layer A according to their original absolute coordinate system positions. Iterate through and examine each graphic element inside the rectangle, and determine whether the display rectangular area of all graphic elements inside the rectangle is contained within the rectangle. If not, expand the area of the rectangle until the rectangular display area of all graphic elements with anchor points inside the rectangle is contained within the rectangle. In each rectangle, select the graphic element whose anchor point is closest to the center of the rectangle as the core graphic element of the rectangle, and convert the anchor point coordinates of other graphic elements inside the rectangle but outside the core graphic element into relative coordinates relative to the anchor point of the core graphic element. The rectangle at the center of drawing layer A is taken as the core rectangle. The anchor point of the core graphic element of the core rectangle is taken as the reference point of the entire drawing layer A. Starting from the core rectangle, the coordinates of the anchor points of the core graphic elements of other adjacent rectangles are converted into relative coordinates with respect to the anchor points of the core graphic elements of the adjacent rectangles. This process is gradually expanded outward until the relative positions of the anchor points of the core graphic elements of all rectangles are determined.
4. The method for drawing electronic drawings based on data acquisition using the Android mobile platform according to any one of claims 1-3, characterized in that, The method to edit graphic elements is as follows: When creating a new graphic element, execute: If the anchor point of the newly created graphic element is closer to the center of the rectangle than the anchor point of the core graphic element, then the newly created graphic element is set as the new core graphic element, and the relative coordinates of all other graphic elements in the rectangle are recalculated; the new core graphic element relinks the core graphic elements of adjacent rectangles and calculates their relative coordinates. If the newly created graphic element is not eligible to become a core graphic element, you only need to determine its relative coordinates to the core graphic element. When deleting a graphic element, execute: If the graphic element to be deleted is a core graphic element, first select candidate core graphic elements. The selection principle is that the anchor point of the graphic element is the second farthest from the center of the rectangle. Set the selected candidate core graphic elements as new core graphic elements, and re-establish the relative coordinates within the rectangle and between adjacent rectangles according to the new creation method. Then delete the graphic element to be deleted. If the graphic element to be deleted is not a core graphic element, it can be deleted directly; When editing graphic elements, execute: If the graphic element to be edited is an attribute text element, then you can directly modify the attribute text of the element in the database; When editing the position of a graphic element, first create a new graphic element in the new position using the new creation method, and then delete the graphic element in the old position using the delete method. Check if the rectangular display area of the edited graphic element is completely contained within its own rectangle. If not, expand the area of the rectangle until it is completely contained.
5. The method for drawing electronic drawings based on data acquisition using the Android mobile platform according to any one of claims 1-3, characterized in that, The method to scale graphic elements is as follows: Create a second new drawing layer B. The size of B can be varied, specifically the size of the area that the operator wants after zooming in and out with their finger. Create a third new drawing layer C. If there are rectangles in B that are not fully displayed, make those rectangles in B fully displayed and then transform them into C. The drawing software first displays the core graphic elements of all rectangles in C according to relative coordinates, then displays each element inside each rectangle according to relative coordinates, cuts out the parts that exceed the screen display range, and transmits them to the AndroidCanvas software for display on the screen.
6. The method for drawing electronic drawings based on the Android mobile platform according to claim 1, characterized in that, The method for parsing a formatted data file and using a recursive function to generate an array collection containing graphic elements is as follows: The data in the graphic element array is parsed according to the element definition to obtain the element attribute data; The array of graphical elements includes, but is not limited to, the following: 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; Iterate through the array collection containing graphic elements, filter template elements and graphic elements, put the template elements in the collection into a reuse array collection, and put the graphic element objects into a drawing array collection.
7. The method for drawing electronic drawings based on the Android mobile platform according to claim 1, characterized in that, Based on the nested references of the data and the relative coordinates of the elements, the specific steps for integrating the array collection containing graphic elements into a tree structure and simultaneously calculating the rectangular area where the element is located are as follows: Based on the nested reference relationships of the data and the relative coordinate system of the elements, the tree-structured data is integrated, the block reference objects are parsed, a reference tree is generated according to the mapping relationship of the graphic block objects, and the text objects in the reference tree are copied. Extract all text objects to form a text object array, extract the coordinates of ellipse objects, arc objects, polyline objects, shadow objects, shadow polyline objects, graphic block objects, and block reference objects to form a graphic object array, calculate the relative coordinates / relative rotation angles on the drawing into absolute coordinates and absolute rotation angles, and simultaneously calculate the rectangular area where the element or combination of elements is located. Iterate through all elements in the graphic element array set, and dynamically compare them to obtain the minimum and maximum X and Y coordinates of the entire electronic drawing. These coordinates are the boundaries of the electronic drawing.
8. The method for drawing electronic drawings based on the Android mobile platform according to claim 1, characterized in that, The specific steps for performing coordinate transformation based on the Android origin coordinates, calculating the initial scaling factor of the electronic drawing on the screen based on the screen's length and width data, and scaling the coordinates of all graphic elements according to this scaling factor are as follows: Based on the Android coordinate system, with the top left corner of the screen as (0,0), coordinate transformation is performed to convert the coordinate system of the data elements to the Android Canvas coordinate system. Based on the screen width and height data of the mobile device, the initial scaling factor of the electronic drawing on the screen is calculated, as well as the optimal scaling factor for landscape and portrait modes. Based on this factor, the coordinates of all graphic elements are scaled by the same factor to achieve the goal of placing the drawing in the center of the screen and filling the entire screen.
9. The method for drawing electronic drawings based on the Android mobile platform according to claim 1, characterized in that, The graphics are drawn using the Android Canvas drawing layer. After completion, the rendering component is called to render the graphic element objects within the drawing layer. The specific steps to achieve graphic display are as follows: Based on the different attributes of each graphic element in different array collections, the graphics are drawn according to the drawing methods and parameters provided by Canvas. After completion, the rendering component is called to render the graphic element objects within the drawing layer range to achieve graphic display.
10. A mobile terminal, comprising: At least one processor; A memory that is communicatively connected to the at least one processor; The memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the steps of the method for drawing electronic drawings based on the Android mobile platform as described in any one of claims 1 to 9.