Packaging model naming method and device, electronic equipment and storage medium
By automatically extracting and constructing package model information text, the problem of inefficient manual naming is solved, and unified and accurate automatic naming of package models is achieved, improving PCB design efficiency.
Patent Information
- Application Number
- CN202510447026.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2045-04-10
AI Technical Summary
In the prior art, the naming of the packaging model relies on manual methods, resulting in inefficient naming, inconsistent formats and error-prone, affecting the efficiency and accuracy of PCB circuit board design.
By obtaining the encapsulation model file, extracting the encapsulation model information using lexical analysis, syntax analysis and regular expression matching methods, constructing information text and automatically determining the name of the encapsulation model according to preset rules, realizing automatic naming of the encapsulation model.
Automatic naming of the encapsulated model is realized, naming efficiency is improved, naming uniformity and accuracy is ensured, errors caused by manual operations are reduced, and the efficiency of PCB design is improved.
Smart Images

Figure CN120509374A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of package model naming, and in particular to a package model naming method, a package model naming device, an electronic device, and a computer-readable storage medium. Background Art
[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] A PCB, short for Printed Circuit Board, is a board used to connect electronic components and provide electrical connections. It's like the "skeleton" of an electronic device, carrying various electronic components and connecting them through pre-designed traces to form a complete circuit.
[0004] With the rapid development of technology, circuit schematic design has become fully dependent on EDA software tools. In schematic design, component modeling is crucial.
[0005] During the modeling process, the correct package must be identified from the package library and then assigned to the corresponding component. This method requires obtaining package model information through the package name to identify the correct package, so standardized package naming is crucial. Currently, related technologies use manual naming methods to name package models, which leads to inefficient naming. Summary of the Invention
[0006] The embodiments of the present invention provide a package model naming method, apparatus, electronic device, and computer-readable storage medium to overcome the above-mentioned problems or at least partially solve the above-mentioned problems.
[0007] An embodiment of the present invention discloses a method for naming a package model, comprising:
[0008] Get the package model file of the package model;
[0009] Read the package model file to obtain package model information of the package model;
[0010] Constructing information text based on the package model information;
[0011] Name information for the package model is determined through the information text.
[0012] Optionally, before the step of reading the package model information of the package model file, the method further includes:
[0013] Determining whether the package model file conforms to a preset package format;
[0014] 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.
[0015] Optionally, the step of reading the package model file and obtaining the package model information of the package model includes:
[0016] Reading the first package element sub-information of the component from the package model file based on the lexical analysis and syntax analysis method;
[0017] Reading the second package element sub-information of the component from the package model file based on a regular expression matching method;
[0018] Reading the third package element sub-information of the component from the package model file based on a parsing library pre-built for the package model file;
[0019] The first package element sub-information, and / or the second package element sub-information, and / or the third package element sub-information are used to determine package model information.
[0020] Optionally, the step of reading the first package element sub-information of a component from the package model file based on the lexical analysis and syntax analysis method includes:
[0021] Decomposing the text stream of the encapsulated model file into independent lexical units;
[0022] Determining grammatical rules of the encapsulation model file, and organizing the lexical units into an abstract syntax tree according to the grammatical rules;
[0023] The abstract syntax tree is traversed to extract the first package element sub-information used to express the component.
[0024] Optionally, 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 includes:
[0025] determining a target mode of the second package element sub-information in the package model file;
[0026] Determine a regular expression corresponding to the target pattern;
[0027] The second package element sub-information of the component is read from the package model file based on the regular expression.
[0028] Optionally, the package model information includes multiple types of information, and the step of constructing the information text based on the package model information includes:
[0029] Determining the text format of the type information;
[0030] The information text is constructed based on the text format using the package model information.
[0031] Optionally, it also includes:
[0032] Generate a target package model file containing the name information.
[0033] The embodiment of the present invention further discloses a package model naming device, comprising:
[0034] A package model file acquisition module is used to obtain the package model file of the package model;
[0035] A package model information acquisition module, configured to read the package model file and acquire package model information of the package model;
[0036] An information text construction module, configured to construct an information text based on the package model information;
[0037] A name information determination module is used to determine the name information for the package model through the information text.
[0038] An embodiment of the present invention 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 communicate with each other via the communication bus;
[0039] The memory is used to store computer programs;
[0040] The processor is configured to implement the method described in the embodiment of the present invention when executing the program stored in the memory.
[0041] An embodiment of the present invention further discloses a computer-readable storage medium having instructions stored thereon. When executed by one or more processors, the processors are enabled to execute the method according to the embodiment of the present invention.
[0042] The embodiments of the present invention include the following advantages:
[0043] An embodiment of the present invention obtains a packaging model file of a packaging model; reads the packaging model file to obtain packaging model information of the packaging model; constructs an information text based on the packaging model information; and determines name information for the packaging model through the information text, thereby realizing automatic naming of the packaging model, avoiding manual operation, and improving efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a flowchart of a method for naming a package model provided in an embodiment of the present invention;
[0045] Figure 2 1 is a schematic diagram of the structure of an automatic naming system for package models provided in an embodiment of the present invention;
[0046] Figure 3 1 is a functional schematic diagram of a KiCad package preprocessing module provided in an embodiment of the present invention;
[0047] Figure 4 This is a functional schematic diagram of a package model naming module provided in an embodiment of the present invention;
[0048] Figure 5 This is a structural block diagram of a package model naming device provided in an embodiment of the present invention;
[0049] Figure 6 is a hardware structure block diagram of an electronic device provided in an embodiment of the present invention;
[0050] Figure 7 is a schematic diagram of a computer-readable medium provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0051] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0052] In practical applications, with the rapid advancement of technology, PCB design has become almost entirely dependent on EDA software tools. Component package modeling is a crucial step, and its accuracy is directly related to the success or failure of the entire PCB design. Before PCB design begins in the electronics industry, component package assignments must be made. Assigning the correct package model to electronic components is fundamental to ensuring PCB design accuracy.
[0053] Currently, manufacturers primarily rely on manual methods to identify and assign the correct package to the corresponding component from the package library. This method relies on the package name to obtain information and identify the correct package, so standardized package naming is crucial. However, the current manual naming method has significant shortcomings: first, the naming format is inconsistent among different personnel; second, manual naming is prone to errors; and third, manual naming is inefficient and time-consuming.
[0054] Reference Figure 1, shows a flowchart of a package model naming method provided in an embodiment of the present invention, which may specifically include the following steps:
[0055] Step 101, obtaining a package model file of a package model;
[0056] Step 102: read the package model file to obtain package model information of the package model;
[0057] Step 103: constructing information text based on the package model information;
[0058] Step 104: Determine name information for the package model through the information text.
[0059] In a specific implementation, the embodiments of the present invention can be applied to a package model automatic naming system, hereinafter referred to as the system. The system is used to efficiently and accurately name electronic component package models through an automated and standardized process.
[0060] The embodiment of the present invention can obtain the package model file of the package model;
[0061] Package model: In PCB design, a model that represents the physical size, pin arrangement, pad shape, and other information of electronic components.
[0062] Package model file: An electronic file that stores package model information. For KiCad software, this is usually a file with the extension .KiCad_mod.
[0063] Obtaining the package model file is the starting point of the entire process. By obtaining the package model file, you can obtain the package model data source that needs to be named. Only after obtaining the package model file can you proceed with subsequent reading and information extraction.
[0064] In the embodiment of the present invention, the input is clarified by acquiring the package model file of the package model, thereby providing an operation object for subsequent steps.
[0065] The embodiment of the present invention can read the package model file, obtain the package model information of the package model, and extract key information for naming from the package model file. By reading the file content, the system can identify various properties of the package.
[0066] Package model information: refers to the various properties about the package contained in the package model file, such as package title, pin definition, pad information, package outline, etc.
[0067] The embodiment of the present invention reads the package model file, obtains the package model information of the package model, and converts the original data in the package model file into information that can be understood and processed by the system, laying the foundation for subsequent construction of information text and determination of name information.
[0068] The embodiment of the present invention can construct information text based on the package model information to structure the extracted package model information, which is convenient for reading and processing by the subsequent naming module. By arranging the information into a text format, information extraction and matching can be conveniently performed.
[0069] Information text: refers to a text file in which the extracted package model information is organized according to a preset format, such as a TXT file or other formats.
[0070] The embodiment of the present invention constructs information text based on the package model information, converting the complex package model information into an easy-to-process text format, thereby reducing the difficulty of subsequent naming module parsing and improving efficiency. At the same time, the information text can also be stored and viewed as intermediate data.
[0071] In the embodiment of the present invention, the name information for the package model is determined through the information text, so as to automatically generate a package model name that complies with the specification by using the information in the information text according to a preset naming rule.
[0072] Name information: refers to the new name of the package model generated by extracting key information from the information text and combining them according to the preset naming rules.
[0073] Beneficial effects:
[0074] The embodiment of the present invention determines the name information of the package model through the information text, thereby realizing automatic naming of the package model, avoiding manual operation and improving efficiency.
[0075] Furthermore, the following beneficial effects are achieved:
[0076] Standardized naming: Through preset naming rules, the uniformity of package model naming is ensured, solving the problem of inconsistent manual naming formats.
[0077] Reduce errors: The automated process reduces errors caused by manual operations and improves naming accuracy.
[0078] Improve efficiency: Greatly shorten the package naming time and improve the efficiency of PCB design.
[0079] For example, refer to Figure 2 , Figure 2 1 is a schematic diagram of the structure of an automatic naming system for package models provided in an embodiment of the present invention;
[0080] The package model automatic naming system may include a KiCad package preprocessing module and a package model naming module.
[0081] 1) KiCad package preprocessing module: Identify the package model file format of KiCad's EDA software. Taking KiCad software version 7.0 as an example, its extension is .KiCad_mod. Its file content includes the attribute content of the package model design, label text, pattern drawing content, package pin definition, etc.
[0082] (1) Read the KiCad_mod package model file of KiCad, and identify the package model information such as package title, package pins, pads, 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 organized into a TXT text or other format file according to a certain format.
[0084] 2) Package model naming module: automatically names the package model according to the rules. 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 use this module to update the name of the package model to the new name according to the naming rules.
[0086] An embodiment of the present invention obtains a packaging model file of a packaging model; reads the packaging model file to obtain packaging model information of the packaging model; constructs an information text based on the packaging model information; and determines name information for the packaging model through the information text, thereby realizing automatic naming of the packaging model, avoiding manual operation, and improving efficiency.
[0087] Based on the above embodiment, a modified embodiment of the above embodiment is proposed. It should be noted that, in order to simplify the description, only the differences from the above embodiment are described in the modified embodiment.
[0088] In an optional embodiment of the present invention, before the step of reading the package model information of the package model file, the method further includes:
[0089] Determining whether the package model file conforms to a 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, you can effectively avoid reading failures or errors caused by incorrect file formats by first determining the format. This is like checking the label of a package before opening it to ensure it is the type you expect to receive.
[0092] Exemplarily, the judgment process can be implemented in the following manner.
[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] Receives a file path filepath as input.
[0102] Check if the file exists: Use os.path.exists() to check if the file exists. If it does not exist, it will output an error message and return False.
[0103] Check the file extension: Use filepath.lower().endswith(".kicad_mod") to convert the file path to lowercase, and then check whether it ends with .kicad_mod. If it does, output a prompt message and return True.
[0104] Handle non-compliant situations: If the file extension does not match, output a warning message and return False.
[0105] 2. Example usage:
[0106] Three example file paths are created, 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 the three file paths and print the results.
[0108] 3. Practical application examples:
[0109] The process_kicad_mod_file() function demonstrates how to call the is_kicad_mod_file() function in a real application.
[0110] Only when the file is a KiCad_mod file, the subsequent reading and processing logic will be executed. Otherwise, the file will be skipped and a prompt will be given.
[0111] The above example mainly reflects the following points:
[0112] Preset package format: clarified the need to process .kicad_mod files.
[0113] Judgment method: mainly judge by checking the file extension.
[0114] Error handling: The system handles the situations 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 invention:
[0116] A stricter judgment can be made: the file header information can be further checked, for example, the first few bytes of the file can be read to see if it matches the specific identifier of the KiCad file. However, this will increase the complexity of the code.
[0117] More detailed error messages can also be output: More detailed error messages can be output according to different error situations, such as prompting the user to check whether the file name is correct.
[0118] You can also perform exception handling: you can use the try...except block to handle possible exceptions, such as file read 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, which can achieve the following beneficial effects.
[0120] Ensure the file type is correct: You can set the program to process only KiCad_mod files. By checking the file extension or other identifiers, you can ensure that the file being read is indeed a KiCad package model file. This can prevent misreading other types of files and causing program errors.
[0121] Compatibility with different versions or formats: Even KiCad_mod files may have different file structures due to version updates or other reasons. By presetting the package format, you can parse for a specific format, or select different parsing strategies after determining the format.
[0122] Improve system stability: Without format verification, reading files that do not meet expectations may fail, or even cause the program to crash. Adding format verification can filter out non-compliant files in advance, ensuring system stability.
[0123] Provide better user feedback: If the file format is incorrect, the system can give a clear prompt, such as "This file is not a KiCad package model file", to help users quickly locate the problem.
[0124] In an optional embodiment of the present invention, the step of reading the package model file and obtaining the package model information of the package model includes:
[0125] Reading the first package element sub-information of the component from the package model file based on the lexical analysis and syntax analysis method;
[0126] Reading the second package element sub-information of the component from the package model file based on a regular expression matching method;
[0127] Reading the third package element sub-information of the component from the package model file based on a parsing library pre-built for 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 are used to determine package model information.
[0129] In actual applications, the package model file can be a KiCad_mod file, which stores the package model information of the components, that is, the physical size, pin shape, pad information, etc. of the components on the actual PCB board. It focuses on the physical layout and connection of the components.
[0130] 1. Methods based on lexical analysis and grammatical analysis:
[0131] Implementation method:
[0132] Use the lexical analyzer (Lexer) to decompose the text stream of the KiCad_mod file into lexical units (Tokens).
[0133] Use a parser to organize lexical units into an abstract syntax tree (AST) or other intermediate representations according to the grammatical rules of the KiCad_mod file.
[0134] Traverse the AST and extract the required first package element sub-information, which may include package attribute content, package label text, package pattern drawing, and package pin definition.
[0135] advantage:
[0136] High accuracy: It can strictly parse according to the syntax rules of KiCad package model files to ensure the accuracy of information.
[0137] Strong scalability: When the format of the KiCad package model file changes, only the rules of the lexical analyzer and syntax analyzer need to be updated.
[0138] Structured data: Parse file content into structured data to facilitate subsequent processing and conversion.
[0139] Applicable scenarios: When you need to deeply understand and accurately parse the KiCad package model file.
[0140] 2. Method based on regular expression matching:
[0141] Implementation method:
[0142] Use regular expressions to match specific patterns in the KiCad_mod file that correspond to the syntax structure of package attribute content, package label text, package pattern drawing, and package pin definition.
[0143] Based on the specific pattern, the matched text information is extracted as the second encapsulation element sub-information.
[0144] advantage:
[0145] Simple implementation: Regular expression matching is usually easier to implement than lexical analysis and syntax analysis.
[0146] Higher 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 prototyping verification.
[0148] 3. Method based on the existing KiCad package model file parsing library:
[0149] Implementation method:
[0150] Use pre-built KiCad_mod file parsing libraries. 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-encapsulation element sub-information.
[0152] advantage:
[0153] High development efficiency: No need to write parsing code from scratch, which can save development time.
[0154] Proven: Existing parsing libraries have generally been extensively tested and used, and are therefore highly reliable.
[0155] Applicable scenarios: When a suitable KiCad package model file parsing library is available, package information can be quickly read.
[0156] 4. Mix multiple methods:
[0157] Implementation method:
[0158] In the first package element sub-information, the second package element sub-information and the third package element sub-information, any element sub-information may be part of the package model information or all of the package model information. The above method can be used alone or in combination. For example, first use regular expressions to quickly locate key areas in the text stream in the KiCad_mod file, and then use lexical analysis and syntactic analysis to parse these areas more accurately.
[0159] advantage:
[0160] Balance efficiency and accuracy: You can choose the appropriate method based on actual needs to strike a balance between efficiency and accuracy.
[0161] Improved robustness: Combining the advantages of multiple methods can improve adaptability to different format changes.
[0162] Applicable scenarios: When the structure of the KiCad package model file is complex and both efficiency and accuracy need to be taken into account.
[0163] In an embodiment of the present invention, the step of reading the first package element sub-information of a component from the package model file based on the lexical analysis and syntax analysis method includes:
[0164] Decomposing the text stream of the encapsulated model file into independent lexical units;
[0165] Determining grammatical rules of the encapsulation model file, and organizing the lexical units into an abstract syntax tree according to the grammatical rules;
[0166] The abstract syntax tree is traversed to extract the first package element sub-information used to express the component.
[0167] Assume the following simplified KiCad_mod file snippet:
[0168]
[0169] The embodiment of the present invention can decompose the text stream of the encapsulated model file into independent lexical units;
[0170] In a specific implementation, a lexical analyzer (such as Python's ply.lex library) can be used to read the above file fragment and decompose it into lexical units.
[0171] The lexical analyzer recognizes 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), brackets (), etc.
[0172] The decomposed token sequence may be as follows:
[0173]
[0174]
[0175] The embodiment of the present invention can determine the grammatical rules of the encapsulation model file and organize the lexical units into an abstract syntax tree according to the grammatical rules;
[0176] In a specific implementation, the grammatical rules of the KiCad_mod file fragment may be defined, for example, using Backus-Naur Form (BNF) or a similar representation method.
[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] A grammar analyzer (such as Python's ply.yacc library) is used to organize the generated token sequence into an abstract syntax tree (AST) according to these grammar rules.
[0182] The structure of the AST reflects the grammatical rules. For example, there will be a root node representing module, and its child nodes will represent layer, attr, pin, line, etc. Each node will contain corresponding information. For example, the child nodes of the module node will contain the module name, layer information, etc.
[0183] A simplified AST structure might be as follows (for illustration only):
[0184]
[0185] The embodiment of the present invention can traverse the abstract syntax tree to extract the first package element sub-information used to express the component.
[0186] In a specific implementation, you can write code to traverse the AST generated above.
[0187] Starting from the root node, recursively visit each node of the AST.
[0188] For each node, extract the required information. For example:
[0189] Extract the module name from a ModuleNode.
[0190] Extract the pin number, position and length from a PinNode.
[0191] Extract the start, end, and width of a line segment from a LineNode.
[0192] Store the extracted information in a suitable data structure, such as a dictionary or object.
[0193] The extracted first encapsulated element sub-information may be as follows:
[0194]
[0195] It should be noted that the above examples are only examples. In actual applications, those skilled in the art may use the KiCad_mod file containing other content as a package model file to obtain package model information. This is not limited in the embodiments of the present invention.
[0196] Through 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 can be traversed to extract the required information. This method can accurately understand the structure and content of the file, providing a reliable data foundation for subsequent automatic naming of package models or other operations.
[0197] In an optional embodiment of the present invention, 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 includes:
[0198] determining a target mode of the second package element sub-information in the package model file;
[0199] Determine a regular expression corresponding to the target pattern;
[0200] The second package element sub-information of the component is read from the package model file based on the regular expression.
[0201] Example of a KiCad_mod file snippet:
[0202]
[0203] The embodiment of the present invention may determine the target mode of the second package element sub-information in the package model file;
[0204] In the specific implementation, if you want to extract the module name, pin number and location information, you can determine the following target mode by observing the file structure:
[0205] Module name: The first identifier after (module...).
[0206] Pin information: Contained in the (pin...) structure, you need to extract the number after (num...) and the two numbers after (at...).
[0207] The embodiment of the present invention can determine the regular expression corresponding to the target pattern;
[0208] In the specific implementation, you can write the corresponding regular expression according to the determined target pattern:
[0209] Module name: r"\(module\s+([A-Za-z0-9_]+)"
[0210] \(module\s+: Match "(module" followed by one or more spaces.
[0211] ([A-Za-z0-9_]+): Match one or more letters, numbers, or underscores and capture them as a module name.
[0212] Pin information: r"\(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 spaces, then one or more digits (representing the pin number), followed by zero or more spaces.
[0214] \(num\s+(\d+)\): matches "(num" followed by one or more spaces and then one or more digits (representing the pin numbers), and captures it.
[0215] \s*\(at\s+([-\d.]+)\s+([-\d.]+)\): matches zero or more spaces, then "(at" followed by one or more spaces, then two numbers (representing x and y coordinates), and captures them separately.
[0216] The embodiment of the present invention can read the second package element sub-information of the component from the package model file based on the regular expression.
[0217] In the specific implementation, Python's re module can be used to apply regular expressions and extract information.
[0218]
[0219]
[0220] Code Explanation:
[0221] Import the re module: used to process regular expressions.
[0222] Define kicad_mod_content: stores KiCad_mod file fragments.
[0223] Extract module name:
[0224] Use re.search() to find the first match of a pattern for a module name.
[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 over all matches and extract the pin number, x-coordinate, and y-coordinate from each match.
[0229] Store the extracted information in a list.
[0230] Output result: Second encapsulated 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 regular expressions, you can easily extract specific information from KiCad_mod files. This method is simple and efficient, and is particularly suitable for processing structured text data.
[0234] In an optional embodiment of the present invention, the package model information includes multiple types of information, and the step of constructing the information text based on the package model information includes:
[0235] Determining the text format of the type information;
[0236] The information text is constructed based on the text format using the package model information.
[0237] In a specific implementation, an embodiment of the present invention can first determine the text format of the output TXT (information text). For example, different text formats can be determined for different types of package model information such as package title, package pin, pad, surface mount pad, plug-in pad, etc., and then the package model information can be used to construct the information text based on the corresponding text format.
[0238] For example, for different types of information, the TXT format can be output:
[0239] Package title format: Footprint(Name"①")
[0240] The encapsulation header format is shown in Table 1;
[0241] Table 1:
[0242] Format describe Footprint Encapsulates the beginning control statement Name Name directive ① Package Name
[0243] Package pins, 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] Plug-in pad format:
[0248] Pad(Name"①")(Location x,y)(HoleSize②)(Surface False)(Rotation③)(ExpandMask④)(ExpandPaste⑤)
[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] Determining the information text in this way can achieve the following beneficial effects:
[0256] Standardized output: Defining the format in advance ensures that the output TXT text has a unified structure, which is convenient for subsequent package model naming modules to parse and process. This eliminates ambiguity that may arise from different package model information organization methods.
[0257] Improve parsing efficiency: Naming modules can parse predefined formats without having to deal with various different information organization methods, thereby improving parsing efficiency and accuracy.
[0258] Enhanced readability: Predefined formats can make TXT text easier to read and understand, facilitating manual inspection and debugging.
[0259] Easy to maintain and expand: If you need to modify the output format, you only need to modify the predefined format rules without modifying the logic of the entire preprocessing module.
[0260] Lay the foundation for more complex processing: Standardized TXT text can be used as intermediate data to facilitate subsequent more complex analysis and processing, such as data verification and format conversion.
[0261] Optionally, it also includes:
[0262] Generate a target package model file containing the name information.
[0263] Exemplarily, the target package model file containing name information may be generated in the following manner.
[0264] Assume that 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 0F.Cu
[0270] PAD_SMD:R1-2 Rectangle 0.8 1.6 3.81 0F.Cu
[0271] Step 1: Read the TXT file and parse the package model information;
[0272] Implementation: Write code to read each line of a TXT file and parse the encapsulated information according to a predefined format. You can use string processing, regular expressions, and other methods.
[0273] Example code (Python):
[0274]
[0275]
[0276] Step 2: Determine the name information of the package model;
[0277] Implementation: According to preset naming rules, key information is extracted from the parsed package model information and combined to generate a new name. The naming rules can be based on the package type, size, number of pins, pitch, etc.
[0278] Example naming convention: [Type]-[Size X]x[Size Y]-[Number of Pins]P (for example, RES-0805-2P) Example code (Python):
[0279]
[0280] Step 3: Generate new package model information based on the new name information;
[0281] Implementation: Update the new name information to 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 footprint model information back to the file (e.g., update the KiCad_mod file or generate a new one)
[0286] Implementation method: 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 demonstrates how to update the KiCad_mod file content of the title field (more complete KiCad_mod format generation logic is needed):
[0288]
[0289]
[0290] By generating a new target package model file after determining the name information, the package model can be automatically named, thereby increasing the design efficiency for the PCB.
[0291] In order to enable those skilled in the art to better understand the embodiments of the present invention, an example is used below to illustrate the embodiments of the present invention.
[0292] refer to Figure 3 , Figure 3 1 is a functional schematic diagram of a KiCad package preprocessing module provided in an embodiment of the present invention;
[0293] (1) Input the KiCad package model into the KiCad package preprocessing module.
[0294] (2) The KiCad package preprocessing module reads and organizes the package title, package pins, pads, package patterns, etc. in the package model into a TXT file in the following format.
[0295] refer to Figure 4 , Figure 4This is a functional schematic diagram of a package model naming module provided in an embodiment of the present invention;
[0296] (1) Input the TXT text into the package model naming module.
[0297] (2) The package model naming module reads and outputs a package model file in KiCad format with a new name according to the naming rules based on the attribute content, label text, package pin definition, and pattern drawing content of the package model in the TXT file.
[0298] It should be noted that for the sake of simplicity, the method embodiments are described as a series of actions. However, those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0299] Reference Figure 5 , shows a structural block diagram of a package model naming device provided in an embodiment of the present invention, which may specifically include the following modules:
[0300] The package model file acquisition module 501 is used to obtain the package model file of the package model;
[0301] The package model information acquisition module 502 is used to read the package model file and acquire the package model information of the package model;
[0302] An information text construction module 503 is used to construct an information text based on the package model information;
[0303] The name information determining module 504 is configured to determine the name information for the package model through the information text.
[0304] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0305] In addition, an embodiment of the present invention further provides an electronic device, such as Figure 6 As shown, it includes 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 communicate with each other through the communication bus 604.
[0306] Memory 603, used for storing computer programs;
[0307] The processor 601 is configured to implement the package model naming method described in any one of the above embodiments when executing the program stored in the memory 603:
[0308] The communication bus mentioned in the terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0309] The communication interface is used for communication between the above terminal and other devices.
[0310] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0311] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0312] like Figure 7 As shown, in another embodiment provided by the present invention, a computer-readable storage medium 701 is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the packaging model naming method described in the above embodiment.
[0313] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are protected by the present invention.
[0314] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0315] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0316] In the embodiments provided in this 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 schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0317] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0318] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0319] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard drive, ROM, RAM, a magnetic disk, or an optical disk.
[0320] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A method for naming a package model, characterized in that: include: Get the package model file of the package model; Read the package model file to obtain package model information of the package model; Constructing information text based on the package model information; Name information for the package model is determined through the information text.
2. The method according to claim 1, characterized in that Before the step of reading the package model information of the package model file, the method further includes: 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, the step of reading the package model information of the package model file is performed.
3. The method according to claim 1, characterized in that The step of reading the package model file and obtaining the package model information of the package model includes: Reading the first package element sub-information of the component from the package model file based on the lexical analysis and syntax analysis method; Reading the second package element sub-information of the component from the package model file based on a regular expression matching method; Reading the third package element sub-information of the component from the package model file based on a parsing library pre-built for the package model file; The first package element sub-information, and / or the second package element sub-information, and / or the third package element sub-information are used to determine package model information.
4. The method according to claim 3, characterized in that The method based on lexical analysis and syntax analysis comprises the following steps: Decomposing the text stream of the encapsulated model file into independent lexical units; Determining grammatical rules of the encapsulation model file, and organizing the lexical units into an abstract syntax tree according to the grammatical rules; The abstract syntax tree is traversed to extract the first package element sub-information used to express the component.
5. The method according to claim 3, characterized in that 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 includes: determining a target mode of the second package element sub-information in the package model file; Determine a regular expression corresponding to the target pattern; The second package element sub-information of the component is read from the package model file based on the regular expression.
6. The method according to claim 1, characterized in that The package model information includes multiple types of information, and the step of constructing the information text based on the package model information includes: Determining the text format of the type information; The information text is constructed based on the text format using the package model information.
7. The method according to claim 1, characterized in that Also includes: Generate a target package model file containing the name information.
8. A package model naming device, characterized in that: include: A package model file acquisition module is used to obtain the package model file of the package model; A package model information acquisition module, configured to read the package model file and acquire package model information of the package model; An information text construction module, configured to construct an information text based on the package model information; A name information determination module is used to determine the name information for the package model through the information text.
9. An electronic device, characterized in that: comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is configured to implement the method according to any one of claims 1 to 7 when executing a program stored in the memory.
10. A computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Text transformation method and device and server
CN110110299A
Abstract text extraction method and device
CN114510563A
Service model packaging method, device and equipment and computer readable storage medium
CN115167845A
Model renaming method and device and storage medium
CN115495911A