A packaging model naming method and device, electronic equipment and storage medium
By using an automated packaging model naming method, packaging model files are obtained and information text is constructed to determine the name information, solving the problem of low efficiency in manual naming, achieving unified and accurate packaging model naming, and improving PCB design efficiency.
Patent Information
- Application Number
- CN202510447026.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-04-10
AI Technical Summary
In existing technologies, the naming of encapsulated models relies on manual operation, resulting in low naming efficiency, inconsistent formats, and a high risk of errors.
By acquiring the encapsulated model file, reading the encapsulated model information, constructing information text, and determining the name information based on the information text, the automatic naming of the encapsulated model is achieved.
Automatic naming of package models has been implemented, which improves naming efficiency, ensures naming consistency and reduces errors, thereby improving PCB design efficiency.
Smart Images

Figure CN120509374B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of package model naming, in particular to a package model naming method, a package model naming device, an electronic device and a computer readable storage medium. BACKGROUND
[0002] EDA is the abbreviation of Electronic Design Automation, which means "electronic design automation" in Chinese. Simply put, EDA software is a series of computer software tools used to assist electronic engineers in designing, analyzing, verifying and manufacturing electronic products (such as integrated circuits, printed circuit boards, etc.).
[0003] PCB circuit board, full name is Printed Circuit Board, Chinese name is printed circuit board, simply put, PCB circuit board is a kind of board used to connect electronic components and provide electrical connection. It is like the "skeleton" of electronic equipment, carrying various electronic components and connecting them through pre-designed circuit traces to form a complete circuit.
[0004] With the rapid development of technology, circuit schematic design has been fully dependent on EDA software tools. In schematic design, the modeling of components is crucial.
[0005] In the modeling process, the correct package needs to be identified from the package library and then assigned to the corresponding component. This method needs to obtain package model information through the name of the package to identify the correct package, so the standard package naming is crucial. At present, the related art names the package model by manual method, which leads to low naming efficiency. SUMMARY
[0006] The embodiments of the present application provide a package model naming method, device, electronic device and computer readable storage medium to overcome the above problems or at least partially solve the above problems.
[0007] The embodiments of the present application disclose a package model naming method, comprising:
[0008] obtaining a package model file of a package model;
[0009] reading the package model file to obtain package model information of the package model;
[0010] constructing an information text based on the package model information;
[0011] determining name information for the package model through the information text.
[0012] Optionally, before the step of reading the packaging model information of the packaging model file, the method further comprises:
[0013] determining whether the packaging model file conforms to a preset packaging format;
[0014] when it is determined that the packaging model file conforms to the preset packaging format, performing the step of reading the packaging model information of the packaging model file.
[0015] Optionally, the step of reading the packaging model file to obtain the packaging model information of the packaging model comprises:
[0016] reading first packaging element sub-information of a component from the packaging model file based on a lexical analysis and a syntax analysis;
[0017] reading second packaging element sub-information of the component from the packaging model file based on a regular expression matching;
[0018] reading third packaging element sub-information of the component from the packaging model file based on a parsing library pre-constructed for the packaging model file;
[0019] determining the packaging model information using the first packaging element sub-information, and / or the second packaging element sub-information, and / or the third packaging element sub-information.
[0020] Optionally, the step of reading first packaging element sub-information of a component from the packaging model file based on a lexical analysis and a syntax analysis comprises:
[0021] decomposing a text stream of the packaging model file into independent lexical units;
[0022] determining a syntax rule of the packaging model file, and organizing the lexical units into an abstract syntax tree according to the syntax rule;
[0023] traversing the abstract syntax tree to extract the first packaging element sub-information for expressing the component.
[0024] Optionally, the step of reading second packaging element sub-information of a component from the packaging model file based on a regular expression matching comprises:
[0025] determining a target pattern of the second packaging element sub-information in the packaging model file;
[0026] determining a regular expression corresponding to the target pattern;
[0027] reading the second packaging element sub-information of the component from the packaging model file based on the regular expression.
[0028] Optionally, the packaging model information comprises a plurality of type information, and the step of constructing the information text based on the packaging model information comprises:
[0029] determining a text format of the type information;
[0030] constructing the information text based on the text format and the packaging model information.
[0031] Optionally, the method further comprises:
[0032] generating a target packaging model file containing the name information.
[0033] The embodiment of the application further discloses a packaging model naming device, comprising:
[0034] a packaging model file acquisition module, configured to acquire a packaging model file of a packaging model;
[0035] a packaging model information acquisition module, configured to read the packaging model file and acquire packaging model information of the packaging model;
[0036] an information text construction module, configured to construct an information text based on the packaging model information;
[0037] a name information determination module, configured to determine name information of the packaging model through the information text.
[0038] The embodiment of the application further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus;
[0039] the memory is configured to store a computer program;
[0040] the processor is configured to execute the program stored on the memory, and implement the method according to the embodiment of the application.
[0041] The embodiment of the application further discloses a computer readable storage medium, which stores instructions, and when executed by one or more processors, causes the processor to execute the method according to the embodiment of the application.
[0042] The embodiment of the application has the following advantages:
[0043] The embodiment of the application acquires a packaging model file of a packaging model, reads the packaging model file, acquires packaging model information of the packaging model, constructs an information text based on the packaging model information, and determines name information of the packaging model through the information text, so that automatic naming of the packaging model is realized, manual operation is avoided, and efficiency is improved. Attached Figure Description
[0044] Figure 1 This is a flowchart illustrating the steps of a naming method for an encapsulated model provided in an embodiment of the present invention;
[0045] Figure 2 This is a schematic diagram of the structure of an automatic naming system for encapsulation models provided in an embodiment of the present invention;
[0046] Figure 3 This is a functional schematic diagram of a KiCad encapsulation preprocessing module provided in an embodiment of the present invention;
[0047] Figure 4 This is a functional diagram of a packaging model naming module provided in an embodiment of the present invention;
[0048] Figure 5 This is a structural block diagram of a packaging model naming device provided in an embodiment of the present invention;
[0049] Figure 6 This is a hardware structure block diagram of an electronic device provided in an embodiment of the present invention;
[0050] Figure 7 This is a schematic diagram of a computer-readable medium provided in an embodiment of the present invention. Detailed Implementation
[0051] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0052] In practical applications, with the rapid development of technology, PCB design has become almost entirely reliant on EDA software tools. Among these tools, component package modeling is a crucial step, as its accuracy directly impacts the success or failure of the entire PCB design. Before PCB design begins in the electronics design industry, component packages must be assigned and specified; assigning the correct package models to electronic components is fundamental to ensuring the correctness of the PCB design.
[0053] Currently, manufacturers primarily use manual methods to identify and assign the correct package to the corresponding component from a package library. This method relies on the package name to obtain information and identify the correct package; therefore, standardized package naming is crucial. However, the current method of manually naming package models has significant shortcomings: firstly, the naming format is inconsistent among different personnel; secondly, manual naming is prone to errors; and thirdly, manual naming is inefficient and time-consuming.
[0054] Reference Figure 1, a step flow chart of a packaging model naming method provided in an embodiment of the present application is shown, and can specifically include the following steps:
[0055] Step 101, obtaining a packaging model file of a packaging model;
[0056] Step 102, reading the packaging model file to obtain packaging model information of the packaging model;
[0057] Step 103, constructing an information text based on the packaging model information;
[0058] Step 104, determining name information for the packaging model through the information text.
[0059] In a specific implementation, the embodiment of the present application can be applied to a packaging model automatic naming system, hereinafter referred to as the system. The system is used to efficiently and accurately name electronic component packaging models through an automated and standardized process.
[0060] The embodiment of the present application can obtain a packaging model file of a packaging model;
[0061] Packaging model: In PCB design, a model representing information such as physical dimensions, pin arrangement, and pad shape of an electronic component.
[0062] Packaging model file: An electronic file storing packaging model information. For KiCad software, it is usually a file with the extension.KiCad_mod.
[0063] Obtaining the packaging model file of the packaging model is the starting point of the entire process. By obtaining the packaging model file of the packaging model, the data source of the packaging model that needs to be named can be obtained. Only after obtaining the packaging model file, can subsequent reading and information extraction be performed.
[0064] The embodiment of the present application, by obtaining the packaging model file of the packaging model, clearly defines the input, providing an operation object for the subsequent steps.
[0065] The embodiment of the present application can read the packaging model file to obtain packaging model information of the packaging model, so as to extract key information for naming from the packaging model file. By reading the file content, the system can identify various properties of the packaging.
[0066] Packaging model information: refers to various properties of the packaging contained in the packaging model file, such as packaging title, pin definition, pad information, and packaging outline.
[0067] The embodiment of the application acquires the packaging model information of the packaging model by reading the packaging model file, converts the original data in the packaging model file into information that can be understood and processed by the system, and lays a foundation for subsequent construction of information text and determination of name information.
[0068] The embodiment of the application can construct information text based on the packaging model information to structure the extracted packaging model information, facilitate reading and processing of the subsequent naming module, and facilitate information extraction and matching by arranging the information into a text format.
[0069] Information text: refers to a text file, such as a TXT file or other format, which is arranged from the extracted packaging model information according to a preset format.
[0070] The embodiment of the application converts complex packaging model information into a text format that is easy to process by constructing information text based on the packaging model information, reduces the analysis difficulty of the subsequent naming module, and improves the efficiency. At the same time, the information text can also be stored and viewed as intermediate data.
[0071] The embodiment of the application determines the name information of the packaging model based on the information text, automatically generates a packaging model name that meets the specifications according to a preset naming rule, and uses information in the information text.
[0072] Name information: refers to a new name of a packaging model that is generated by extracting key information from the information text and combining according to a preset naming rule.
[0073] Advantages:
[0074] The embodiment of the application determines the name information of the packaging model based on the information text, realizes automatic naming of the packaging model, avoids manual operation, and improves the efficiency.
[0075] Further, the following advantages are achieved:
[0076] Standardized naming: ensures the uniformity of the packaging model naming through a preset naming rule, and solves the problem of inconsistent manual naming format.
[0077] Reduce errors: the automated process reduces errors caused by manual operation and improves naming accuracy.
[0078] Improve efficiency: greatly shortens the packaging naming time and improves the efficiency of PCB design.
[0079] Exemplarily, refer to Figure 2 , Figure 2 is a structural schematic diagram of a packaging model automatic naming system provided in the embodiment of the application;
[0080] The package model automatic naming system can include a KiCad package preprocessing module and a package model naming module.
[0081] 1) KiCad package preprocessing module: determine the package model file format of the EDA software of KiCad, for example, the extension of the KiCad software 7.0 version is.KiCad_mod, and the file content includes the attribute content, label text, pattern drawing content, package pin definition, etc. of the package model design.
[0082] (1) Read the KiCad_mod package model file of KiCad, identify the package title, package pin, pad, package pattern, etc. of the PCB package design by judging the expression structure of the file.
[0083] (2) The package model information identified in (1) is arranged into a TXT text or other format file according to a certain format.
[0084] 2) Package model naming module: automatically name the package model according to the rules, and the naming rules need to be set in advance.
[0085] (1) Read the TXT file output by the KiCad package preprocessing module, identify the necessary information according to the naming rules, and update the name of the package model to a new name through this module according to the naming rules.
[0086] In the embodiment of the application, the package model file of the package model is obtained, the package model information of the package model is obtained by reading the package model file, the information text is constructed based on the package model information, and the name information of the package model is determined through the information text, so that the automatic naming of the package model is realized, manual operation is avoided, and the efficiency is improved.
[0087] On the basis of the above-mentioned embodiment, a variant embodiment of the above-mentioned embodiment is proposed, and it should be noted that, in order to make the description brief, only the differences from the above-mentioned embodiment are described in the variant embodiment.
[0088] In an optional embodiment of the application, before the step of reading the package model information of the package model file, the following steps are further included:
[0089] Determine whether the package model file conforms to the preset package format;
[0090] When it is determined that the package model file conforms to the preset package format, the step of reading the package model information of the package model file is performed.
[0091] Before reading the package model file, first do format judgment, can effectively avoid because of file format error caused by reading failure or error. This is like checking the label of a package before opening it, to ensure that it is the type you expect to receive.
[0092] Exemplarily, the judgment process can be implemented as follows.
[0093]
[0094]
[0095]
[0096] process_kicad_mod_file(file1)
[0097] process_kicad_mod_file(file2)
[0098] process_kicad_mod_file(file3)
[0099] Code explanation:
[0100] 1、is_kicad_mod_file(filepath) function:
[0101] Receive file path filepath as input.
[0102] Check if the file exists: use os.path.exists() to check if the file exists, if not, output error information and return False.
[0103] Check file extension: convert the file path to lowercase using filepath.lower().endswith(".kicad_mod"), then check if it ends with.kicad_mod. If it does, output a prompt and return True.
[0104] Handle cases that do not meet the requirements: if the file extension does not meet the requirements, output a warning and return False.
[0105] 2、Example usage:
[0106] Create three example file paths, representing a correct KiCad_mod file, a non-KiCad_mod file, and a non-existent file.
[0107] Call the is_kicad_mod_file() function to judge these three file paths, and print the results.
[0108] 3. Practical application example:
[0109] The process_kicad_mod_file() function demonstrates how to call the is_kicad_mod_file() function in a practical application.
[0110] Only when the file is a KiCad_mod file, the subsequent reading and processing logic is executed. Otherwise, the file is skipped and a prompt is given.
[0111] The above example mainly embodies the following points:
[0112] Default package format: It is clear that.kicad_mod files need to be processed.
[0113] Judgment method: Mainly through checking the file extension.
[0114] Error handling: Handles the cases where the file does not exist and the extension does not match, and outputs the corresponding prompt information.
[0115] In an optional embodiment of the present application:
[0116] More rigorous judgment can be performed: The header information of the file can be further checked, such as reading the first few bytes of the file to see if it matches the specific identifier of the KiCad file. But this will increase the complexity of the code.
[0117] More detailed error information can also be provided: More detailed error information can be output according to different error situations, such as prompting the user to check the file name.
[0118] Exception handling can also be performed: try...except block can be used to handle possible exceptions, such as file reading errors.
[0119] Specifically, before the step of reading the package model information of the package model file, it is determined whether the package model file conforms to the preset package format, and only when it is determined that the package model file conforms to the preset package format, the step of reading the package model information of the package model file is executed. The following beneficial effects can be achieved.
[0120] Ensure the correct type of file: You can preset to only process KiCad_mod files, and by judging the file extension or other identifiers, you can ensure that the file read is indeed a KiCad package model file. This can avoid misreading other types of files and causing program errors.
[0121] Compatibility with different versions or formats: Even KiCad_mod files can differ in file structure due to version updates or other reasons. By presetting the package format, you can parse for a specific format or choose different parsing strategies after determining the format.
[0122] Improved system stability: Without format determination, reading operations may fail or even cause program crashes if unexpected files are encountered. Adding format determination can filter out non-compliant files in advance, ensuring system stability.
[0123] Better user feedback: If the file format is incorrect, the system can give clear prompts such as "This file is not a KiCad package model file", helping users quickly locate the problem.
[0124] In an optional embodiment of the present application, the step of reading the package model file to obtain the package model information of the package model includes:
[0125] Based on lexical analysis and syntax analysis, the first package element sub-information of the component is read from the package model file;
[0126] Based on regular expression matching, the second package element sub-information of the component is read from the package model file;
[0127] Based on the pre-constructed parsing library for the package model file, the third package element sub-information of the component is read from the package model file;
[0128] The first package element sub-information, and / or the second package element sub-information, and / or the third package element sub-information is used to determine the package model information.
[0129] In practical applications, the package model file can be a KiCad_mod file, which stores the package model information of the component, i.e. the physical size, pin shape, pad information, etc. of the component on the actual PCB board. It focuses on the physical layout and connection of the component.
[0130] 1. Based on lexical analysis and syntax analysis:
[0131] Implementation:
[0132] Use the lexical analyzer (Lexer) to decompose the text stream of KiCad_mod file into individual lexical units (Token).
[0133] The Parser organizes the lexical units into an Abstract Syntax Tree (AST) or other intermediate representation form according to the syntax rules of the KiCad_mod file.
[0134] Traverse the AST and extract the required first package element sub-information, which can include package property content, package label text, package pattern drawing, and package pin definition.
[0135] Advantages:
[0136] High accuracy: strictly according to the syntax rules of the KiCad package model file for parsing, ensuring the accuracy of the information.
[0137] Strong scalability: when the format of the KiCad package model file changes, only the rules of the lexical analyzer and the syntax analyzer need to be updated.
[0138] Structured data: parse the file content into structured data, facilitating subsequent processing and conversion.
[0139] Applicable scenarios: when in-depth understanding and accurate parsing of KiCad package model files are required.
[0140] 2. Regular expression matching-based method:
[0141] Implementation:
[0142] Use regular expression matching to match specific patterns in the KiCad_mod file, which correspond to the syntax structures of package property content, package label text, package pattern drawing, and package pin definition.
[0143] Based on the specific pattern, extract the matched text information as the second package element sub-information.
[0144] Advantages:
[0145] Simple implementation: compared with lexical analysis and syntax analysis, regular expression matching is usually easier to implement.
[0146] High efficiency: for simple file structures, regular expression matching can be more efficient.
[0147] Applicable scenarios: when the structure of the KiCad package model file is relatively simple and stable, or as a method for rapid prototype verification.
[0148] 3. Method based on existing KiCad package model file parsing library:
[0149] Implementation:
[0150] Pre-built KiCad_mod file parsing libraries are used. These parsing libraries have implemented the parsing function of KiCad_mod files.
[0151] Call the interface provided by the parsing library to obtain the required third packaging element sub-information.
[0152] Advantages:
[0153] High development efficiency: No need to write parsing code from scratch, can save development time.
[0154] Proven: Existing parsing libraries are usually extensively tested and used, with high reliability.
[0155] Applicable scenarios: When there is a suitable KiCad package model file parsing library available, the reading of packaging information can be quickly implemented.
[0156] 4. Mixed use of multiple methods:
[0157] Implementation:
[0158] In the first packaging element sub-information, the second packaging element sub-information and the third packaging element sub-information, any element sub-information may be part of the packaging model information, or it may be all the packaging model information. The above method can be used alone, or the above method can be combined, for example, first use regular expressions to quickly locate the key areas in the text stream in the KiCad_mod file, and then use lexical analysis and syntax analysis to more accurately parse these areas.
[0159] Advantages:
[0160] Balance efficiency and accuracy: You can choose the right method according to your actual needs, and balance between efficiency and accuracy.
[0161] Improve robustness: Combine the advantages of multiple methods to improve adaptability to different format changes.
[0162] Applicable scenarios: When the structure of the KiCad package model file is complex and needs to balance efficiency and accuracy.
[0163] In the embodiment of the application, the method based on lexical analysis and syntax analysis comprises the following steps:
[0164] The text stream of the packaging model file is decomposed into independent lexical units;
[0165] Determine the syntax rules of the packaging model file, and organize the lexical units into an abstract syntax tree according to the syntax rules;
[0166] Traverse the abstract syntax tree, extract the first package element sub-information for expressing the component.
[0167] Suppose there is the following simplified KiCad_mod file fragment:
[0168]
[0169] Embodiments of the present application can decompose the text stream of the package model file into independent lexical units;
[0170] In a specific implementation, a lexical analyzer (such as the ply.lex library of Python) can be used to read the above file fragment and decompose it into individual lexical units.
[0171] The lexical analyzer can identify keywords (such as module, layer, attr, pin, line, start, end, width), identifiers (such as MyComponent, F.Cu), strings (such as normal), numbers (such as 1, 2, 0, 5.08, -1, 6.08, 0.15), parentheses (()), etc.
[0172] The sequence of decomposed lexical units can be as follows:
[0173]
[0174]
[0175] Embodiments of the present application can determine the syntax rules of the package model file, and organize the lexical units into an abstract syntax tree according to the syntax rules;
[0176] In a specific implementation, the syntax rules of the KiCad_mod file fragment can be defined, for example, using the Backus-Naur Form (BNF) or similar representation methods.
[0177] module::='(”module'IDENTIFIER'(”layer'IDENTIFIER')'attr*pin*line*')'
[0178] attr::='(”attr'IDENTIFIER')'
[0179] pin::='(”pin'NUMBER'(”num'NUMBER')”(”at'NUMBER NUMBER')”(”length'NUMBER')”)'
[0180] line ::= '(' 'line' '(''start' NUMBER NUMBER ')' '(' 'end' NUMBER NUMBER ')' '(' 'width' NUMBER ')')'
[0181] The sequence of lexemes generated above is organized into an Abstract Syntax Tree (AST) using a parser (e.g. the ply.yacc library for Python) according to these grammar rules.
[0182] The structure of the AST will reflect the grammar rules, e.g. there will be a root node representing module, whose children will represent layer, attr, pin, line, etc. Each node will contain the corresponding information, e.g. the children of the module node will contain the name of the module, layer information, etc.
[0183] A simplified AST structure might look like this (for illustration only):
[0184]
[0185] Embodiments of the present application can traverse the Abstract Syntax Tree and extract the first package element sub-information for expressing the component.
[0186] In a specific implementation, code can be written to traverse the AST generated above.
[0187] Starting from the root node, each node of the AST is recursively visited.
[0188] For each node, the required information is extracted. For example:
[0189] The module name is extracted from the ModuleNode.
[0190] The pin number, position, and length are extracted from the PinNode.
[0191] The start point, end point, and width of the line segment are extracted from the LineNode.
[0192] The extracted information is stored in a suitable data structure, e.g. a dictionary or an object.
[0193] The extracted first package element sub-information might look like this:
[0194]
[0195] It should be noted that the above example is only an example, in actual application, a KiCad_mod file containing other content can be used as a package model file to obtain package model information, and the embodiments of the present application are not limited in this regard.
[0196] By lexical analysis and syntax analysis, the text stream of the KiCad_mod file can be converted into a structured data representation (AST), and then the AST is traversed to extract the required information. This method can accurately understand the structure and content of the file, and provide a reliable data basis for subsequent automatic naming of the package model or other operations.
[0197] In an optional embodiment of the present application, the method based on regular expression matching comprises the following steps:
[0198] Determining the target pattern of the second package element sub-information in the package model file;
[0199] Determining the regular expression corresponding to the target pattern;
[0200] Reading the second package element sub-information of the component from the package model file based on the regular expression.
[0201] An example of a KiCad_mod file fragment:
[0202]
[0203] The embodiment of the present application can determine the target pattern of the second package element sub-information in the package model file;
[0204] In a specific implementation, if you want to extract the name of the module, the number and position information of the pin, you can observe the file structure and determine the following target patterns:
[0205] Module name: the first identifier after (module...).
[0206] Pin information: contained in the (pin...) structure, the number after (num...) and the two numbers after (at...) need to be extracted.
[0207] The embodiment of the present application can determine the regular expression corresponding to the target pattern;
[0208] In a specific implementation, the corresponding regular expression can be written according to the determined target pattern:
[0209] Module name: r"\(module\s+([A-Za-z0-9_]+)"
[0210] \(module\s+: matches "(module" followed by one or more spaces.
[0211] ([A-Za-z0-9_]+): matches one or more letters, numbers or underscores and captures them as the module name.
[0212] pin\s+\d+\s*\(num\s+(\d+)\)\s*\(at\s+([-\d.]+)\s+([-\d.]+)\)
[0213] \(pin\s+\d+\s*: matches "(pin" followed by one or more whitespace characters, then one or more digits (representing the pin number), followed by zero or more whitespace characters.
[0214] \(num\s+(\d+)\): matches "(num" followed by one or more whitespace characters, then one or more digits (representing the pin number), and captures it.
[0215] \s*\(at\s+([-\d.]+)\s+([-\d.]+)\): matches zero or more whitespace characters, then "(at" followed by one or more whitespace characters, then two digits (representing the x and y coordinates), and captures them separately.
[0216] The embodiments of the invention can read the second packaging element sub-information of the component from the packaging model file based on the regular expression.
[0217] In a specific implementation, the re module of Python can be used to apply the regular expression and extract information.
[0218]
[0219]
[0220] Code explanation:
[0221] Import the re module: used for processing regular expressions.
[0222] Define kicad_mod_content: store the KiCad_mod file fragment.
[0223] Extract the module name:
[0224] Use re.search() to find the first matching module name pattern.
[0225] If a match is found, use group(1) to get the captured module name.
[0226] Extract pin information:
[0227] Use re.findall() to find all matching pin information patterns.
[0228] Iterate through all matches, extracting pin number, x coordinate, and y coordinate from each match.
[0229] Store the extracted information in a list.
[0230] Output result second package element sub-information:
[0231] Module name: MyComponent
[0232] Pin information: [{'number':1,'at':(0.0,0.0)},{'number':2,'at':(5.08,0.0)}]
[0233] By matching with regular expressions, specific information can be easily extracted from KiCad_mod files. This method is simple and efficient, especially suitable for processing structured text data.
[0234] In an optional embodiment of the present application, the package model information includes multiple type information, and the step of constructing information text based on the package model information includes:
[0235] Determining the text format of the type information;
[0236] Constructing information text based on the package model information according to the text format.
[0237] In a specific implementation, the embodiments of the present application can first determine the text format of the output TXT (information text), for example, for different types of package model information such as package title, package pin, pad, surface mount pad, and plug-in pad, different text formats can be determined, and then the package model information is used to construct information text based on the corresponding text format.
[0238] Exemplarily, for different types of information, the format of the output TXT can be:
[0239] Package title format: Footprint(Name "①")
[0240] The content of the package title format is shown in Table 1.
[0241] Table 1:
[0242] Format Description Footprint Package opening control statement Name Name instruction ① Package name
[0243] Package pin, pad format, surface mount pad format:
[0244] Pad(Name "①") (Location x, y) (Surface True) (Rotation ③) (ExpandMask ④) (ExpandPaste ⑤)
[0245] PadShape(Size A,B)(Shape⑥)(Layer⑦)
[0246] EndPad
[0247] PadShape(Size A,B)(Shape⑥)(Layer⑦)
[0248] PadShape(Size A,B)(Shape⑥)(Layer⑦)
[0249] PadShape(Size A,B)(Shape⑥)(Layer⑦)
[0250] EndPad
[0251] The contents of "package pin, pad format, surface mount pad format" and "plug-in pad format" are shown in Table 2.
[0252] Table 2:
[0253]
[0254]
[0255] In this way, the information text can achieve the following beneficial effects:
[0256] Standardized output: defining the format in advance can ensure that the output TXT text has a unified structure, which facilitates the subsequent packaging model naming module for parsing and processing. This eliminates the ambiguity that may be caused by different packaging model information organization methods.
[0257] Improve parsing efficiency: the naming module can parse the pre-defined format, without the need to handle various information organization methods, thereby improving parsing efficiency and accuracy.
[0258] Enhance readability: the pre-defined format can make the TXT text easier to read and understand, facilitating manual inspection and debugging.
[0259] Easy to maintain and extend: if the output format needs to be modified, only the pre-defined format rules need to be modified, without the need to modify the entire pre-processing module logic.
[0260] Lay the foundation for more complex processing: standardized TXT text can be used as intermediate data, facilitating subsequent more complex analysis and processing, such as data verification, format conversion, etc.
[0261] Optionally, it further comprises:
[0262] A target package model file containing the name information is generated.
[0263] Exemplarily, the target package model file containing the name information can be generated in the following way.
[0264] Suppose the format of the TXT file is as follows:
[0265] TITLE: MyComponent
[0266] LAYER: F.Cu
[0267] ATTRIBUTES: normal
[0268] PAD_TH: J1-1 Circle 1.6 1.6 2.54 0 1.0
[0269] PAD_SMD: R1-1 Rectangle 0.8 1.6 1.27 0 F.Cu
[0270] PAD_SMD: R1-2 Rectangle 0.8 1.6 3.81 0 F.Cu
[0271] Step 1: Read the TXT file and parse the package model information;
[0272] Implementation: Write code to read each line of the TXT file and parse the information of each package according to the predefined format. String processing, regular expressions, etc. can be used.
[0273] Example code (Python):
[0274]
[0275]
[0276] Step 2: Determine the name information of the package model;
[0277] Implementation: According to the preset naming rules, extract the key information from the parsed package model information and combine to generate a new name. The naming rules can be based on the type, size, pin number, pitch, etc. of the package.
[0278] Example naming rule: [type]-[size X]x[size Y]-[pin number]P (for example, RES-0805-2P) Example code (Python):
[0279]
[0280] Step 3: Based on the new name information, generate new package model information;
[0281] Implementation: Update the new name information into the package model information. This may involve modifying the title field in the package_data dictionary.
[0282] Example code (Python):
[0283]
[0284]
[0285] Step 4: Optionally, write the updated package model information back to the file (e.g., update the KiCad_mod file or generate a new file)
[0286] Implementation: Regenerate the.KiCad_mod file content of KiCad according to the new package model information, or store the information in other formats (such as JSON, XML).
[0287] Example code (Python) - only demonstrate how to update the title field of the KiCad_mod file content (need more complete KiCad_mod format generation logic):
[0288]
[0289]
[0290] By generating a new target package model file after determining the name information, the naming of the package model can be automatically implemented, thereby increasing the design efficiency for PCB.
[0291] In order to make those skilled in the art better understand the embodiments of the present application, the following uses an example to illustrate the embodiments of the present application.
[0292] Reference Figure 3 , Figure 3 is a functional schematic diagram of a KiCad package preprocessing module provided in the embodiments of the present application;
[0293] (1) Input the KiCad package model into the KiCad package preprocessing module.
[0294] (2) The KiCad package preprocessing module reads and outputs the package title, package pin, pad, package pattern, etc. in the package model to the TXT file according to the following format.
[0295] Reference Figure 4 , Figure 4is a functional schematic diagram of a packaging model naming module provided in the embodiment of the application;
[0296] (1) input the TXT text into the packaging model naming module.
[0297] (2) the packaging model naming module reads, according to the attribute content of the packaging model, the label text, the packaging pin definition, and the pattern drawing content in the TXT file, outputs a new name of the packaging model file in the KiCad format according to the naming rule.
[0298] It should be noted that, for the method embodiment, in order to simply describe, it is expressed as a series of action combinations, but those skilled in the art should know that the embodiment of the application is not limited by the described action sequence, because according to the embodiment of the application, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions involved are not necessarily the necessary of the embodiment of the application.
[0299] Referring to Figure 5 , a structural block diagram of a packaging model naming device provided in the embodiment of the application is shown, which can specifically include the following modules:
[0300] The packaging model file acquisition module 501 is configured to acquire the packaging model file of the packaging model.
[0301] The packaging model information acquisition module 502 is configured to read the packaging model file and acquire the packaging model information of the packaging model.
[0302] The information text construction module 503 is configured to construct an information text based on the packaging model information.
[0303] The name information determination module 504 is configured to determine the name information of the packaging model through the information text.
[0304] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts refer to the part of the method embodiment.
[0305] In addition, the embodiment of the application further provides an electronic device, as shown in Figure 6 , including a processor 601, a communication interface 602, a memory 603, and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 complete mutual communication through the communication bus 604,
[0306] The memory 603 is configured to store a computer program.
[0307] When the processor 601 executes the program stored in the memory 603, it implements any of the packaging model naming methods described in the above embodiments:
[0308] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0309] The communication interface is used for communication between the aforementioned terminal and other devices.
[0310] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0311] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0312] like Figure 7 As shown, in another embodiment of the present invention, a computer-readable storage medium 701 is also provided, which stores instructions that, when executed on a computer, cause the computer to execute the encapsulation model naming method described in the above embodiments.
[0313] The embodiments of the present application are described above with reference to the accompanying drawings, but the present application is not limited to the specific embodiments described above, and the specific embodiments described above are merely illustrative, but not restrictive, and those skilled in the art can make many forms under the inspiration of the present application without departing from the purpose of the present application and the scope protected by the claims, which all belong to the protection of the present application.
[0314] Those skilled in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the embodiments of the present application can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software mode depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0315] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
[0316] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0317] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present application.
[0318] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0319] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the present application that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes various storage media that can store program codes, such as a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk.
[0320] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for naming a package model, characterized by, The method comprises the following steps: obtaining a package model file of a package model; reading the package model file to obtain package model information of the package model; constructing an information text based on the package model information; determining name information of the package model through the information text; the step of reading the package model file to obtain the package model information comprises: reading first package element sub-information of a component from the package model file based on a lexical analysis and a syntax analysis method; reading second package element sub-information of the component from the package model file based on a regular expression matching method; reading third package element sub-information of the component from the package model file based on a pre-constructed analysis library for the package model file; determining package model information by using the first package element sub-information, the second package element sub-information and the third package element sub-information.
2. The method of claim 1, wherein, Before the step of reading the package model information of the package model file, the method further comprises the following steps: determining whether the package model file conforms to a preset package format; when it is determined that the package model file conforms to the preset package format, performing the step of reading the package model information of the package model file.
3. The method of claim 1, wherein, The step of reading the first package element sub-information of the component from the package model file based on the lexical analysis and the syntax analysis method comprises the following steps: decomposing a text stream of the package model file into independent lexical units; determining a syntax rule of the package model file, and organizing the lexical units into an abstract syntax tree according to the syntax rule; traversing the abstract syntax tree to extract the first package element sub-information for expressing the component.
4. The method of claim 1, wherein, The step of reading the second package element sub-information of the component from the package model file based on the regular expression matching method comprises the following steps: determining a target mode of the second package element sub-information in the package model file; determining a regular expression corresponding to the target mode; reading the second package element sub-information of the component from the package model file based on the regular expression.
5. The method of claim 1, wherein, The package model information comprises a plurality of type information, and the step of constructing the information text based on the package model information comprises the following steps: determining a text format of the type information; constructing the information text based on the text format and the package model information.
6. The method of claim 1, wherein, The method further comprises the following step: generating a target package model file containing the name information.
7. A package model naming apparatus characterized by comprising: The method comprises the following steps: a package model file obtaining module is configured to obtain a package model file of a package model; a package model information obtaining module is configured to read the package model file to obtain package model information of the package model; an information text constructing module is configured to construct an information text based on the package model information; a name information determining module is configured to determine name information of the package model through the information text; the package model information obtaining module is further configured to read first package element sub-information of a component from the package model file based on a lexical analysis and a syntax analysis method; The method based on the regular expression matching reads the second package element sub-information of the component from the package model file; reads the third package element sub-information of the component from the package model file based on the analysis library pre-constructed for the package model file; and determines the package model information by using the first package element sub-information, the second package element sub-information and the third package element sub-information.
8. An electronic device, comprising: The device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus. The memory is used for storing a computer program. The processor is used for executing the program stored on the memory, and the method in any one of claims 1-6 is implemented. 9.A computer readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method in any one of claims 1-6.
Citation Information
Patent Citations
Text transformation method and device and server
CN110110299A
Abstract text extraction method and device
CN114510563A