This diff has been collapsed as it changes many lines, (544 lines changed) Show them Hide them | |||||
@@ -1,200 +1,698 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the Kicad Tools Software |
|
2 | -- This file is a part of the Kicad Tools Software | |
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "qicadnetlist.h" |
|
22 | #include "qicadnetlist.h" | |
23 | #include <QRegularExpression> |
|
23 | #include <QRegularExpression> | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | const char* root_c ="(export"; |
|
26 | const char* root_c ="(export"; | |
27 | const char* version_c ="(version"; |
|
27 | const char* version_c ="(version"; | |
28 | const char* design_c ="(design"; |
|
28 | const char* design_c ="(design"; | |
29 | const char* source_c ="(source"; |
|
29 | const char* source_c ="(source"; | |
30 | const char* date_c ="(date"; |
|
30 | const char* date_c ="(date"; | |
31 | const char* tool_c ="(tool"; |
|
31 | const char* tool_c ="(tool"; | |
32 | const char* components_c ="(components"; |
|
32 | const char* components_c ="(components"; | |
33 | const char* component_c ="(comp"; |
|
33 | const char* component_c ="(comp"; | |
34 | const char* ref_c ="(ref"; |
|
34 | const char* ref_c ="(ref"; | |
35 | const char* value_c ="(value"; |
|
35 | const char* value_c ="(value"; | |
36 | const char* libsource_c ="(libsource"; |
|
36 | const char* libsource_c ="(libsource"; | |
37 | const char* lib_c ="(lib"; |
|
37 | const char* lib_c ="(lib"; | |
38 | const char* part_c ="(part"; |
|
38 | const char* part_c ="(part"; | |
39 | const char* sheetpath_c ="(sheetpath"; |
|
39 | const char* sheetpath_c ="(sheetpath"; | |
40 | const char* names_c ="(names"; |
|
40 | const char* names_c ="(names"; | |
41 | const char* tstamps_c ="(tstamps"; |
|
41 | const char* tstamps_c ="(tstamps"; | |
42 | const char* tstamp_c ="(tstamp"; |
|
42 | const char* tstamp_c ="(tstamp"; | |
43 | const char* libparts_c ="(libparts"; |
|
43 | const char* libparts_c ="(libparts"; | |
44 | const char* libpart_c ="(libpart"; |
|
44 | const char* libpart_c ="(libpart"; | |
45 | const char* fields_c ="(fields"; |
|
45 | const char* fields_c ="(fields"; | |
46 | const char* field_c ="(field"; |
|
46 | const char* field_c ="(field"; | |
47 | const char* name_c ="(name"; |
|
47 | const char* name_c ="(name"; | |
48 | const char* pins_c ="(pins"; |
|
48 | const char* pins_c ="(pins"; | |
49 | const char* pin_c ="(pin"; |
|
49 | const char* pin_c ="(pin"; | |
50 | const char* num_c ="(num"; |
|
50 | const char* num_c ="(num"; | |
51 | const char* type_c ="(type"; |
|
51 | const char* type_c ="(type"; | |
52 | const char* libraries_c ="(libraries"; |
|
52 | const char* libraries_c ="(libraries"; | |
53 | const char* library_c ="(library"; |
|
53 | const char* library_c ="(library"; | |
54 | const char* logical_c ="(logical"; |
|
54 | const char* logical_c ="(logical"; | |
55 | const char* uri_c ="(uri"; |
|
55 | const char* uri_c ="(uri"; | |
56 | const char* nets_c ="(nets"; |
|
56 | const char* nets_c ="(nets"; | |
57 | const char* net_c ="(net"; |
|
57 | const char* net_c ="(net"; | |
58 | const char* code_c ="(code"; |
|
58 | const char* code_c ="(code"; | |
59 | const char* node_c ="(node"; |
|
59 | const char* node_c ="(node"; | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | QIlib::QIcadNetList::QIcadNetList() |
|
62 | QIlib::QIcadNetList::QIcadNetList() | |
|
63 | :netlistRoot(NULL) | |||
63 | { |
|
64 | { | |
64 |
|
65 | |||
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 |
|
68 | |||
68 | bool QIlib::QIcadNetList::parseNetList(const QString &netlist) |
|
69 | bool QIlib::QIcadNetList::parseNetList(const QString &netlist) | |
69 | { |
|
70 | { | |
70 |
|
71 | |||
71 | parse(netlist.toStdString().c_str()); |
|
72 | parse(netlist.toStdString().c_str()); | |
72 | updateConcreteTree(); |
|
73 | updateConcreteTree(); | |
73 | return false; |
|
74 | return false; | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | QString QIlib::QIcadNetList::print() |
|
77 | QString QIlib::QIcadNetList::print() | |
77 | { |
|
78 | { | |
78 | return rootNode.print(); |
|
79 | return rootNode.print(); | |
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 | QIlib::AbstractNode *QIlib::QIcadNetList::getAbstractNode(const QString &node, int index) |
|
82 | QIlib::AbstractNode *QIlib::QIcadNetList::getAbstractNode(const QString &node, int index) | |
82 | { |
|
83 | { | |
83 | return getAbstractNode(&rootNode,node,&index); |
|
84 | return getAbstractNode(&rootNode,node,&index); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | QIlib::AbstractNode *QIlib::QIcadNetList::getAbstractNode(QIlib::AbstractNode *rootNode, const QString &node, int* index) |
|
87 | QIlib::AbstractNode *QIlib::QIcadNetList::getAbstractNode(QIlib::AbstractNode *rootNode, const QString &node, int* index) | |
87 | { |
|
88 | { | |
88 | for(int i=0;i<rootNode->nodes.count();i++) |
|
89 | for(int i=0;i<rootNode->nodes.count();i++) | |
89 | { |
|
90 | { | |
90 | if(rootNode->nodes.at(i)->name==node) |
|
91 | if(rootNode->nodes.at(i)->name==node) | |
91 | { |
|
92 | { | |
92 | if((*index)==0) |
|
93 | if((*index)==0) | |
93 | { |
|
94 | { | |
94 | return rootNode->nodes.at(i); |
|
95 | return rootNode->nodes.at(i); | |
95 | } |
|
96 | } | |
96 | (*index)-=1; |
|
97 | (*index)-=1; | |
97 | } |
|
98 | } | |
98 | else |
|
99 | else | |
99 | { |
|
100 | { | |
100 | if(0<rootNode->nodes.at(i)->nodes.count()) |
|
101 | if(0<rootNode->nodes.at(i)->nodes.count()) | |
101 | { |
|
102 | { | |
102 | QIlib::AbstractNode *result=getAbstractNode(rootNode->nodes.at(i),node,index); |
|
103 | QIlib::AbstractNode *result=getAbstractNode(rootNode->nodes.at(i),node,index); | |
103 | if(NULL!=result)return result; |
|
104 | if(NULL!=result)return result; | |
104 | } |
|
105 | } | |
105 | } |
|
106 | } | |
106 | } |
|
107 | } | |
107 | return NULL; |
|
108 | return NULL; | |
108 | } |
|
109 | } | |
109 |
|
110 | |||
110 | /* |
|
|||
111 | QString version; |
|
|||
112 | QIcadNetListDesign design; |
|
|||
113 | QList<QIcadNetListComponent*> components; |
|
|||
114 | QList<QIcadNetListLibPart*> libparts; |
|
|||
115 | QIcadNetListLevel rootSheet; |
|
|||
116 | */ |
|
|||
117 |
|
||||
118 | #define setVal(dest,node,name,index) \ |
|
|||
119 | (node) = getAbstractNode((name),(index));\ |
|
|||
120 | if(((node)!=NULL)&&(0<(node)->Values.count())) \ |
|
|||
121 | {\ |
|
|||
122 | (dest) = (node)->Values.at(0); \ |
|
|||
123 | } \ |
|
|||
124 |
|
||||
125 |
|
111 | |||
126 | void QIlib::QIcadNetList::updateConcreteTree() |
|
112 | void QIlib::QIcadNetList::updateConcreteTree() | |
127 | { |
|
113 | { | |
128 | QIlib::AbstractNode *node; |
|
114 | if(this->rootNode.nodes.count()) | |
129 | setVal(this->version,node,QIlib::Lexique::version_c,0); |
|
115 | { | |
130 | setVal(this->design.date,node,QIlib::Lexique::date_c,0); |
|
116 | if(this->rootNode.nodes.at(0)->name==QIlib::Lexique::root_c) | |
131 | setVal(this->design.source,node,QIlib::Lexique::source_c,0); |
|
117 | { | |
132 | setVal(this->design.tool,node,QIlib::Lexique::tool_c,0); |
|
118 | if(this->netlistRoot==NULL) | |
133 | this->design.date.clear(); |
|
119 | { | |
|
120 | this->netlistRoot = new QIcadNetListRoot(this->rootNode.nodes.at(0)); | |||
|
121 | } | |||
|
122 | } | |||
|
123 | } | |||
134 | } |
|
124 | } | |
135 |
|
125 | |||
136 |
|
126 | |||
137 |
|
127 | |||
138 |
|
||||
139 |
|
||||
140 | QIlib::QIcadAbstractNodeWrapper::QIcadAbstractNodeWrapper(AbstractNode *node) |
|
128 | QIlib::QIcadAbstractNodeWrapper::QIcadAbstractNodeWrapper(AbstractNode *node) | |
141 | { |
|
129 | { | |
142 | this->p_node = node; |
|
130 | this->p_node = node; | |
143 | } |
|
131 | } | |
144 |
|
132 | |||
145 | QIlib::QIcadAbstractNodeWrapper::~QIcadAbstractNodeWrapper() |
|
133 | QIlib::QIcadAbstractNodeWrapper::~QIcadAbstractNodeWrapper() | |
146 | { |
|
134 | { | |
147 | /*First delete all the childs*/ |
|
135 | /*First delete all the childs*/ | |
148 | for(int i=0;i<this->childs.count();i++) |
|
136 | for(int i=0;i<this->childs.count();i++) | |
149 | { |
|
137 | { | |
150 | if(this->childs.at(i)) |
|
138 | if(this->childs.at(i)) | |
151 | delete this->childs.at(i); |
|
139 | delete this->childs.at(i); | |
152 | } |
|
140 | } | |
153 | } |
|
141 | } | |
154 |
|
142 | |||
155 | QString QIlib::QIcadAbstractNodeWrapper::value() |
|
143 | QString QIlib::QIcadAbstractNodeWrapper::value() | |
156 | { |
|
144 | { | |
157 | if((p_node->Values.count()>0) && p_node) |
|
145 | if((p_node->Values.count()>0) && p_node) | |
158 | return p_node->Values.at(0); |
|
146 | return p_node->Values.at(0); | |
159 | return QString(""); |
|
147 | return QString(""); | |
160 | } |
|
148 | } | |
161 |
|
149 | |||
162 | QString QIlib::QIcadAbstractNodeWrapper::value(int index) |
|
150 | QString QIlib::QIcadAbstractNodeWrapper::value(int index) | |
163 | { |
|
151 | { | |
164 | if((p_node->Values.count()>index) && p_node) |
|
152 | if((p_node->Values.count()>index) && p_node) | |
165 | return p_node->Values.at(index); |
|
153 | return p_node->Values.at(index); | |
166 | return QString(""); |
|
154 | return QString(""); | |
167 | } |
|
155 | } | |
168 |
|
156 | |||
169 | QString QIlib::QIcadAbstractNodeWrapper::catValues() |
|
157 | QString QIlib::QIcadAbstractNodeWrapper::catValues() | |
170 | { |
|
158 | { | |
171 | if(p_node) |
|
159 | if(p_node) | |
172 | { |
|
160 | { | |
173 | QString result(""); |
|
161 | QString result(""); | |
174 | for(int i=0;i<p_node->Values.count();i++) |
|
162 | for(int i=0;i<p_node->Values.count();i++) | |
175 | { |
|
163 | { | |
176 | result.append(p_node->Values.at(i)); |
|
164 | result.append(p_node->Values.at(i)); | |
177 | } |
|
165 | } | |
178 | return result; |
|
166 | return result; | |
179 | } |
|
167 | } | |
180 | } |
|
168 | } | |
181 |
|
169 | |||
182 | void QIlib::QIcadAbstractNodeWrapper::setNode(QIlib::AbstractNode *node) |
|
170 | void QIlib::QIcadAbstractNodeWrapper::setNode(QIlib::AbstractNode *node) | |
183 | { |
|
171 | { | |
184 | this->p_node = node; |
|
172 | this->p_node = node; | |
185 | } |
|
173 | } | |
186 |
|
174 | |||
187 |
|
175 | |||
188 |
|
176 | |||
189 | QIlib::QIcadNetListRoot::QIcadNetListRoot(QIlib::AbstractNode *node) |
|
177 | QIlib::QIcadNetListRoot::QIcadNetListRoot(QIlib::AbstractNode *node) | |
190 | :QIcadAbstractNodeWrapper(node) |
|
178 | :QIcadAbstractNodeWrapper(node) | |
191 | { |
|
179 | { | |
|
180 | this->setNode(node); | |||
|
181 | } | |||
192 |
|
182 | |||
|
183 | void QIlib::QIcadNetListRoot::setNode(QIlib::AbstractNode *node) | |||
|
184 | { | |||
|
185 | this->p_node = node; | |||
|
186 | if(node->name==QIlib::Lexique::root_c) | |||
|
187 | { | |||
|
188 | for(int i=0;i<node->nodes.count();i++) | |||
|
189 | { | |||
|
190 | if(node->nodes.at(i)->name==QIlib::Lexique::design_c) | |||
|
191 | { | |||
|
192 | this->design.setNode(node->nodes.at(i)); | |||
|
193 | } | |||
|
194 | if(node->nodes.at(i)->name==QIlib::Lexique::components_c) | |||
|
195 | { | |||
|
196 | this->setComponents(node->nodes.at(i)); | |||
|
197 | } | |||
|
198 | if(node->nodes.at(i)->name==QIlib::Lexique::libparts_c) | |||
|
199 | { | |||
|
200 | this->setLibParts(node->nodes.at(i)); | |||
|
201 | } | |||
|
202 | if(node->nodes.at(i)->name==QIlib::Lexique::libraries_c) | |||
|
203 | { | |||
|
204 | this->setLibraries(node->nodes.at(i)); | |||
|
205 | } | |||
|
206 | if(node->nodes.at(i)->name==QIlib::Lexique::nets_c) | |||
|
207 | { | |||
|
208 | this->setNets(node->nodes.at(i)); | |||
|
209 | } | |||
|
210 | } | |||
|
211 | } | |||
|
212 | } | |||
|
213 | ||||
|
214 | void QIlib::QIcadNetListRoot::setComponents(QIlib::AbstractNode *node) | |||
|
215 | { | |||
|
216 | while(components.count()) | |||
|
217 | { | |||
|
218 | QIcadNetListComponent* component; | |||
|
219 | component = components.last(); | |||
|
220 | components.removeLast(); | |||
|
221 | delete component; | |||
|
222 | } | |||
|
223 | apendComponents(node); | |||
|
224 | } | |||
|
225 | ||||
|
226 | void QIlib::QIcadNetListRoot::apendComponents(QIlib::AbstractNode *node) | |||
|
227 | { | |||
|
228 | if(node->name==QIlib::Lexique::components_c) | |||
|
229 | { | |||
|
230 | for(int i=0;i<node->nodes.count();i++) | |||
|
231 | { | |||
|
232 | if(node->nodes.at(i)->name==QIlib::Lexique::component_c) | |||
|
233 | { | |||
|
234 | this->components.append(new QIcadNetListComponent(node->nodes.at(i))); | |||
|
235 | } | |||
|
236 | } | |||
|
237 | } | |||
|
238 | } | |||
|
239 | ||||
|
240 | void QIlib::QIcadNetListRoot::setLibParts(QIlib::AbstractNode *node) | |||
|
241 | { | |||
|
242 | while(libparts.count()) | |||
|
243 | { | |||
|
244 | QIcadNetListLibPart* libpart; | |||
|
245 | libpart = libparts.last(); | |||
|
246 | libparts.removeLast(); | |||
|
247 | delete libpart; | |||
|
248 | } | |||
|
249 | apendLibParts(node); | |||
|
250 | } | |||
|
251 | ||||
|
252 | void QIlib::QIcadNetListRoot::apendLibParts(QIlib::AbstractNode *node) | |||
|
253 | { | |||
|
254 | if(node->name==QIlib::Lexique::libparts_c) | |||
|
255 | { | |||
|
256 | for(int i=0;i<node->nodes.count();i++) | |||
|
257 | { | |||
|
258 | if(node->nodes.at(i)->name==QIlib::Lexique::libpart_c) | |||
|
259 | { | |||
|
260 | this->libparts.append(new QIcadNetListLibPart(node->nodes.at(i))); | |||
|
261 | } | |||
|
262 | } | |||
|
263 | } | |||
|
264 | } | |||
|
265 | ||||
|
266 | void QIlib::QIcadNetListRoot::setLibraries(QIlib::AbstractNode *node) | |||
|
267 | { | |||
|
268 | while(libraries.count()) | |||
|
269 | { | |||
|
270 | QIcadNetListLibrary* lib; | |||
|
271 | lib = libraries.last(); | |||
|
272 | libraries.removeLast(); | |||
|
273 | delete lib; | |||
|
274 | } | |||
|
275 | apendLibraries(node); | |||
|
276 | } | |||
|
277 | ||||
|
278 | void QIlib::QIcadNetListRoot::apendLibraries(QIlib::AbstractNode *node) | |||
|
279 | { | |||
|
280 | if(node->name==QIlib::Lexique::libraries_c) | |||
|
281 | { | |||
|
282 | for(int i=0;i<node->nodes.count();i++) | |||
|
283 | { | |||
|
284 | if(node->nodes.at(i)->name==QIlib::Lexique::library_c) | |||
|
285 | { | |||
|
286 | this->libraries.append(new QIcadNetListLibrary(node->nodes.at(i))); | |||
|
287 | } | |||
|
288 | } | |||
|
289 | } | |||
|
290 | } | |||
|
291 | ||||
|
292 | void QIlib::QIcadNetListRoot::setNets(QIlib::AbstractNode *node) | |||
|
293 | { | |||
|
294 | while(nets.count()) | |||
|
295 | { | |||
|
296 | QIcadNetListNet* net; | |||
|
297 | net = nets.last(); | |||
|
298 | nets.removeLast(); | |||
|
299 | delete net; | |||
|
300 | } | |||
|
301 | apendNets(node); | |||
|
302 | } | |||
|
303 | ||||
|
304 | void QIlib::QIcadNetListRoot::apendNets(QIlib::AbstractNode *node) | |||
|
305 | { | |||
|
306 | if(node->name==QIlib::Lexique::nets_c) | |||
|
307 | { | |||
|
308 | for(int i=0;i<node->nodes.count();i++) | |||
|
309 | { | |||
|
310 | if(node->nodes.at(i)->name==QIlib::Lexique::net_c) | |||
|
311 | { | |||
|
312 | this->nets.append(new QIcadNetListNet(node->nodes.at(i))); | |||
|
313 | } | |||
|
314 | } | |||
|
315 | } | |||
193 | } |
|
316 | } | |
194 |
|
317 | |||
195 |
|
318 | |||
196 | QIlib::QIcadNetListComponent::QIcadNetListComponent(QIlib::AbstractNode *node) |
|
319 | QIlib::QIcadNetListComponent::QIcadNetListComponent(QIlib::AbstractNode *node) | |
197 | :QIcadAbstractNodeWrapper(node) |
|
320 | :QIcadAbstractNodeWrapper(node) | |
198 | { |
|
321 | { | |
|
322 | setNode(node); | |||
|
323 | } | |||
199 |
|
324 | |||
|
325 | void QIlib::QIcadNetListComponent::setNode(QIlib::AbstractNode *node) | |||
|
326 | { | |||
|
327 | if(node->name==QIlib::Lexique::component_c) | |||
|
328 | { | |||
|
329 | for(int i=0;i<node->nodes.count();i++) | |||
|
330 | { | |||
|
331 | if(node->nodes.at(i)->name==QIlib::Lexique::ref_c) | |||
|
332 | { | |||
|
333 | this->ref.setNode(node->nodes.at(i)); | |||
|
334 | } | |||
|
335 | if(node->nodes.at(i)->name==QIlib::Lexique::value_c) | |||
|
336 | { | |||
|
337 | this->value.setNode(node->nodes.at(i)); | |||
|
338 | } | |||
|
339 | if(node->nodes.at(i)->name==QIlib::Lexique::libsource_c) | |||
|
340 | { | |||
|
341 | this->libsource.setNode(node->nodes.at(i)); | |||
|
342 | } | |||
|
343 | if(node->nodes.at(i)->name==QIlib::Lexique::sheetpath_c) | |||
|
344 | { | |||
|
345 | this->sheetpath.setNode(node->nodes.at(i)); | |||
|
346 | } | |||
|
347 | if(node->nodes.at(i)->name==QIlib::Lexique::tstamp_c) | |||
|
348 | { | |||
|
349 | this->tstamp.setNode(node->nodes.at(i)); | |||
|
350 | } | |||
|
351 | } | |||
|
352 | } | |||
200 | } |
|
353 | } | |
|
354 | ||||
|
355 | ||||
|
356 | QIlib::QIcadNetListDesign::QIcadNetListDesign(QIlib::AbstractNode *node) | |||
|
357 | :QIcadAbstractNodeWrapper(node) | |||
|
358 | { | |||
|
359 | this->setNode(node); | |||
|
360 | } | |||
|
361 | ||||
|
362 | void QIlib::QIcadNetListDesign::setNode(QIlib::AbstractNode *node) | |||
|
363 | { | |||
|
364 | if(node->name==QIlib::Lexique::design_c) | |||
|
365 | { | |||
|
366 | this->p_node = node; | |||
|
367 | for(int i=0;i<node->nodes.count();i++) | |||
|
368 | { | |||
|
369 | if(node->nodes.at(i)->name==QIlib::Lexique::source_c) | |||
|
370 | { | |||
|
371 | this->source.setNode(node->nodes.at(i)); | |||
|
372 | } | |||
|
373 | if(node->nodes.at(i)->name==QIlib::Lexique::date_c) | |||
|
374 | { | |||
|
375 | this->date.setNode(node->nodes.at(i)); | |||
|
376 | } | |||
|
377 | if(node->nodes.at(i)->name==QIlib::Lexique::tool_c) | |||
|
378 | { | |||
|
379 | this->tool.setNode(node->nodes.at(i)); | |||
|
380 | } | |||
|
381 | } | |||
|
382 | } | |||
|
383 | } | |||
|
384 | ||||
|
385 | QIlib::QIcadNetListLibPart::QIcadNetListLibPart(QIlib::AbstractNode *node) | |||
|
386 | { | |||
|
387 | setNode(node); | |||
|
388 | } | |||
|
389 | /* | |||
|
390 | (libparts | |||
|
391 | (libpart (lib guan) (part 24L-MOD-8) | |||
|
392 | (fields | |||
|
393 | (field (name Reference) IC) | |||
|
394 | (field (name Value) 24L-MOD-8)) | |||
|
395 | (pins | |||
|
396 | (pin (num 1) (name GND) (type power_in)) | |||
|
397 | (pin (num 2) (name VCC) (type power_in)) | |||
|
398 | */ | |||
|
399 | void QIlib::QIcadNetListLibPart::setNode(QIlib::AbstractNode *node) | |||
|
400 | { | |||
|
401 | if(node->name==QIlib::Lexique::libpart_c) | |||
|
402 | { | |||
|
403 | this->p_node = node; | |||
|
404 | for(int i=0;i<node->nodes.count();i++) | |||
|
405 | { | |||
|
406 | if(node->nodes.at(i)->name==QIlib::Lexique::lib_c) | |||
|
407 | { | |||
|
408 | this->lib.setNode(node->nodes.at(i)); | |||
|
409 | } | |||
|
410 | if(node->nodes.at(i)->name==QIlib::Lexique::part_c) | |||
|
411 | { | |||
|
412 | this->part.setNode(node->nodes.at(i)); | |||
|
413 | } | |||
|
414 | if(node->nodes.at(i)->name==QIlib::Lexique::fields_c) | |||
|
415 | { | |||
|
416 | setFields(node->nodes.at(i)); | |||
|
417 | } | |||
|
418 | if(node->nodes.at(i)->name==QIlib::Lexique::pins_c) | |||
|
419 | { | |||
|
420 | setPins(node->nodes.at(i)); | |||
|
421 | } | |||
|
422 | } | |||
|
423 | } | |||
|
424 | } | |||
|
425 | ||||
|
426 | void QIlib::QIcadNetListLibPart::setFields(QIlib::AbstractNode *node) | |||
|
427 | { | |||
|
428 | while(fields.count()) | |||
|
429 | { | |||
|
430 | QIcadNetListField* field; | |||
|
431 | field = fields.last(); | |||
|
432 | fields.removeLast(); | |||
|
433 | delete field; | |||
|
434 | } | |||
|
435 | apendFields(node); | |||
|
436 | } | |||
|
437 | ||||
|
438 | void QIlib::QIcadNetListLibPart::apendFields(QIlib::AbstractNode *node) | |||
|
439 | { | |||
|
440 | if(node->name==QIlib::Lexique::fields_c) | |||
|
441 | { | |||
|
442 | for(int i=0;i<node->nodes.count();i++) | |||
|
443 | { | |||
|
444 | if(node->nodes.at(i)->name==QIlib::Lexique::field_c) | |||
|
445 | { | |||
|
446 | this->fields.append(new QIcadNetListField(node->nodes.at(i))); | |||
|
447 | } | |||
|
448 | } | |||
|
449 | } | |||
|
450 | } | |||
|
451 | ||||
|
452 | void QIlib::QIcadNetListLibPart::setPins(QIlib::AbstractNode *node) | |||
|
453 | { | |||
|
454 | while(pins.count()) | |||
|
455 | { | |||
|
456 | QIcadNetListPin* pin; | |||
|
457 | pin = pins.last(); | |||
|
458 | pins.removeLast(); | |||
|
459 | delete pin; | |||
|
460 | } | |||
|
461 | apendPins(node); | |||
|
462 | } | |||
|
463 | ||||
|
464 | void QIlib::QIcadNetListLibPart::apendPins(QIlib::AbstractNode *node) | |||
|
465 | { | |||
|
466 | if(node->name==QIlib::Lexique::pins_c) | |||
|
467 | { | |||
|
468 | for(int i=0;i<node->nodes.count();i++) | |||
|
469 | { | |||
|
470 | if(node->nodes.at(i)->name==QIlib::Lexique::pin_c) | |||
|
471 | { | |||
|
472 | this->pins.append(new QIcadNetListPin(node->nodes.at(i))); | |||
|
473 | } | |||
|
474 | } | |||
|
475 | } | |||
|
476 | } | |||
|
477 | ||||
|
478 | ||||
|
479 | QIlib::QIcadNetListLibrary::QIcadNetListLibrary(QIlib::AbstractNode *node) | |||
|
480 | { | |||
|
481 | setNode(node); | |||
|
482 | } | |||
|
483 | ||||
|
484 | void QIlib::QIcadNetListLibrary::setNode(QIlib::AbstractNode *node) | |||
|
485 | { | |||
|
486 | /* | |||
|
487 | (library (logical guan) | |||
|
488 | (uri /home/guan/boards/guan.lib)) | |||
|
489 | */ | |||
|
490 | if(node->name==QIlib::Lexique::library_c) | |||
|
491 | { | |||
|
492 | this->p_node = node; | |||
|
493 | for(int i=0;i<node->nodes.count();i++) | |||
|
494 | { | |||
|
495 | if(node->nodes.at(i)->name==QIlib::Lexique::logical_c) | |||
|
496 | { | |||
|
497 | this->logical.setNode(node->nodes.at(i)); | |||
|
498 | } | |||
|
499 | if(node->nodes.at(i)->name==QIlib::Lexique::uri_c) | |||
|
500 | { | |||
|
501 | this->uri.setNode(node->nodes.at(i)); | |||
|
502 | } | |||
|
503 | } | |||
|
504 | } | |||
|
505 | } | |||
|
506 | ||||
|
507 | ||||
|
508 | ||||
|
509 | QIlib::QIcadNetListField::QIcadNetListField(QIlib::AbstractNode *node) | |||
|
510 | { | |||
|
511 | setNode(node); | |||
|
512 | } | |||
|
513 | ||||
|
514 | void QIlib::QIcadNetListField::setNode(QIlib::AbstractNode *node) | |||
|
515 | { | |||
|
516 | if(node->name==QIlib::Lexique::field_c) | |||
|
517 | { | |||
|
518 | this->p_node = node; | |||
|
519 | for(int i=0;i<node->nodes.count();i++) | |||
|
520 | { | |||
|
521 | if(node->nodes.at(i)->name==QIlib::Lexique::name_c) | |||
|
522 | { | |||
|
523 | this->name.setNode(node->nodes.at(i)); | |||
|
524 | } | |||
|
525 | } | |||
|
526 | } | |||
|
527 | } | |||
|
528 | ||||
|
529 | ||||
|
530 | QIlib::QIcadNetListLibPart::QIcadNetListPin::QIcadNetListPin(QIlib::AbstractNode *node) | |||
|
531 | { | |||
|
532 | setNode(node); | |||
|
533 | } | |||
|
534 | ||||
|
535 | void QIlib::QIcadNetListLibPart::QIcadNetListPin::setNode(QIlib::AbstractNode *node) | |||
|
536 | { | |||
|
537 | //(pin (num 1) (name GND) (type power_in)) | |||
|
538 | if(node->name==QIlib::Lexique::pin_c) | |||
|
539 | { | |||
|
540 | this->p_node = node; | |||
|
541 | for(int i=0;i<node->nodes.count();i++) | |||
|
542 | { | |||
|
543 | if(node->nodes.at(i)->name==QIlib::Lexique::name_c) | |||
|
544 | { | |||
|
545 | this->name.setNode(node->nodes.at(i)); | |||
|
546 | } | |||
|
547 | if(node->nodes.at(i)->name==QIlib::Lexique::num_c) | |||
|
548 | { | |||
|
549 | this->num.setNode(node->nodes.at(i)); | |||
|
550 | } | |||
|
551 | if(node->nodes.at(i)->name==QIlib::Lexique::type_c) | |||
|
552 | { | |||
|
553 | this->type.setNode(node->nodes.at(i)); | |||
|
554 | } | |||
|
555 | } | |||
|
556 | } | |||
|
557 | } | |||
|
558 | ||||
|
559 | QIlib::QIcadNetListComponent::QIcadNetListLibSource::QIcadNetListLibSource(QIlib::AbstractNode *node) | |||
|
560 | { | |||
|
561 | setNode(node); | |||
|
562 | } | |||
|
563 | ||||
|
564 | void QIlib::QIcadNetListComponent::QIcadNetListLibSource::setNode(QIlib::AbstractNode *node) | |||
|
565 | { | |||
|
566 | //(libsource (lib guan) (part 24L-MOD-8)) | |||
|
567 | if(node->name==QIlib::Lexique::libsource_c) | |||
|
568 | { | |||
|
569 | this->p_node = node; | |||
|
570 | for(int i=0;i<node->nodes.count();i++) | |||
|
571 | { | |||
|
572 | if(node->nodes.at(i)->name==QIlib::Lexique::lib_c) | |||
|
573 | { | |||
|
574 | this->lib.setNode(node->nodes.at(i)); | |||
|
575 | } | |||
|
576 | if(node->nodes.at(i)->name==QIlib::Lexique::part_c) | |||
|
577 | { | |||
|
578 | this->part.setNode(node->nodes.at(i)); | |||
|
579 | } | |||
|
580 | } | |||
|
581 | } | |||
|
582 | } | |||
|
583 | ||||
|
584 | QIlib::QIcadNetListComponent::QIcadNetListSheetPath::QIcadNetListSheetPath(QIlib::AbstractNode *node) | |||
|
585 | { | |||
|
586 | setNode(node); | |||
|
587 | } | |||
|
588 | ||||
|
589 | void QIlib::QIcadNetListComponent::QIcadNetListSheetPath::setNode(QIlib::AbstractNode *node) | |||
|
590 | { | |||
|
591 | //(sheetpath (names /) (tstamps /)) | |||
|
592 | if(node->name==QIlib::Lexique::sheetpath_c) | |||
|
593 | { | |||
|
594 | this->p_node = node; | |||
|
595 | for(int i=0;i<node->nodes.count();i++) | |||
|
596 | { | |||
|
597 | if(node->nodes.at(i)->name==QIlib::Lexique::names_c) | |||
|
598 | { | |||
|
599 | this->names.setNode(node->nodes.at(i)); | |||
|
600 | } | |||
|
601 | if(node->nodes.at(i)->name==QIlib::Lexique::tstamps_c) | |||
|
602 | { | |||
|
603 | this->tstamps.setNode(node->nodes.at(i)); | |||
|
604 | } | |||
|
605 | } | |||
|
606 | } | |||
|
607 | } | |||
|
608 | ||||
|
609 | QIlib::QIcadNetListNet::QIcadNetListNet(QIlib::AbstractNode *node) | |||
|
610 | { | |||
|
611 | setNode(node); | |||
|
612 | } | |||
|
613 | ||||
|
614 | void QIlib::QIcadNetListNet::setNode(QIlib::AbstractNode *node) | |||
|
615 | { | |||
|
616 | /* | |||
|
617 | (nets | |||
|
618 | (net (code 15) (name "") | |||
|
619 | (node (ref C4) (pin 1)) | |||
|
620 | (node (ref U2) (pin 4))) | |||
|
621 | (net (code 16) (name GND) | |||
|
622 | (node (ref D1) (pin 2)) | |||
|
623 | (node (ref C1) (pin 2)) | |||
|
624 | (node (ref IC1) (pin 1)) | |||
|
625 | */ | |||
|
626 | if(node->name==QIlib::Lexique::net_c) | |||
|
627 | { | |||
|
628 | this->p_node = node; | |||
|
629 | while(NetNodes.count()) | |||
|
630 | { | |||
|
631 | QIcadNetListNetNode* net; | |||
|
632 | net = NetNodes.last(); | |||
|
633 | NetNodes.removeLast(); | |||
|
634 | delete net; | |||
|
635 | } | |||
|
636 | for(int i=0;i<node->nodes.count();i++) | |||
|
637 | { | |||
|
638 | if(node->nodes.at(i)->name==QIlib::Lexique::name_c) | |||
|
639 | { | |||
|
640 | this->name.setNode(node->nodes.at(i)); | |||
|
641 | } | |||
|
642 | if(node->nodes.at(i)->name==QIlib::Lexique::code_c) | |||
|
643 | { | |||
|
644 | this->code.setNode(node->nodes.at(i)); | |||
|
645 | } | |||
|
646 | if(node->nodes.at(i)->name==QIlib::Lexique::node_c) | |||
|
647 | { | |||
|
648 | NetNodes.append(new QIcadNetListNetNode(node->nodes.at(i))); | |||
|
649 | } | |||
|
650 | } | |||
|
651 | } | |||
|
652 | } | |||
|
653 | ||||
|
654 | QIlib::QIcadNetListNet::QIcadNetListNetNode::QIcadNetListNetNode(QIlib::AbstractNode *node) | |||
|
655 | { | |||
|
656 | setNode(node); | |||
|
657 | } | |||
|
658 | ||||
|
659 | void QIlib::QIcadNetListNet::QIcadNetListNetNode::setNode(QIlib::AbstractNode *node) | |||
|
660 | { | |||
|
661 | //(node (ref D1) (pin 2)) | |||
|
662 | if(node->name==QIlib::Lexique::node_c) | |||
|
663 | { | |||
|
664 | this->p_node = node; | |||
|
665 | for(int i=0;i<node->nodes.count();i++) | |||
|
666 | { | |||
|
667 | if(node->nodes.at(i)->name==QIlib::Lexique::ref_c) | |||
|
668 | { | |||
|
669 | this->ref.setNode(node->nodes.at(i)); | |||
|
670 | } | |||
|
671 | if(node->nodes.at(i)->name==QIlib::Lexique::pin_c) | |||
|
672 | { | |||
|
673 | this->pin.setNode(node->nodes.at(i)); | |||
|
674 | } | |||
|
675 | } | |||
|
676 | } | |||
|
677 | } | |||
|
678 | ||||
|
679 | ||||
|
680 | ||||
|
681 | ||||
|
682 | ||||
|
683 | ||||
|
684 | ||||
|
685 | ||||
|
686 | ||||
|
687 | ||||
|
688 | ||||
|
689 | ||||
|
690 | ||||
|
691 | ||||
|
692 | ||||
|
693 | ||||
|
694 | ||||
|
695 | ||||
|
696 | ||||
|
697 | ||||
|
698 |
@@ -1,279 +1,268 | |||||
1 | #ifndef QICADNETLIST_H |
|
1 | #ifndef QICADNETLIST_H | |
2 | #define QICADNETLIST_H |
|
2 | #define QICADNETLIST_H | |
3 | #include <QString> |
|
3 | #include <QString> | |
4 | #include <QStringList> |
|
4 | #include <QStringList> | |
5 | /*------------------------------------------------------------------------------ |
|
5 | /*------------------------------------------------------------------------------ | |
6 | -- This file is a part of the Kicad Tools Software |
|
6 | -- This file is a part of the Kicad Tools Software | |
7 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS |
|
7 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
8 | -- |
|
8 | -- | |
9 | -- This program is free software; you can redistribute it and/or modify |
|
9 | -- This program is free software; you can redistribute it and/or modify | |
10 | -- it under the terms of the GNU General Public License as published by |
|
10 | -- it under the terms of the GNU General Public License as published by | |
11 | -- the Free Software Foundation; either version 2 of the License, or |
|
11 | -- the Free Software Foundation; either version 2 of the License, or | |
12 | -- (at your option) any later version. |
|
12 | -- (at your option) any later version. | |
13 | -- |
|
13 | -- | |
14 | -- This program is distributed in the hope that it will be useful, |
|
14 | -- This program is distributed in the hope that it will be useful, | |
15 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | -- GNU General Public License for more details. |
|
17 | -- GNU General Public License for more details. | |
18 | -- |
|
18 | -- | |
19 | -- You should have received a copy of the GNU General Public License |
|
19 | -- You should have received a copy of the GNU General Public License | |
20 | -- along with this program; if not, write to the Free Software |
|
20 | -- along with this program; if not, write to the Free Software | |
21 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | -------------------------------------------------------------------------------*/ |
|
22 | -------------------------------------------------------------------------------*/ | |
23 | /*-- Author : Alexis Jeandet |
|
23 | /*-- Author : Alexis Jeandet | |
24 | -- Mail : alexis.jeandet@member.fsf.org |
|
24 | -- Mail : alexis.jeandet@member.fsf.org | |
25 | ----------------------------------------------------------------------------*/ |
|
25 | ----------------------------------------------------------------------------*/ | |
26 | #include <QList> |
|
26 | #include <QList> | |
27 | #include <QFile> |
|
27 | #include <QFile> | |
28 | #include <parsers/lispLike_driver.h> |
|
28 | #include <parsers/lispLike_driver.h> | |
29 | #include <qicadnet.h> |
|
29 | #include <qicadnet.h> | |
30 |
|
30 | |||
31 | namespace QIlib{ |
|
31 | namespace QIlib{ | |
32 |
|
32 | |||
33 | namespace Lexique |
|
33 | namespace Lexique | |
34 | { |
|
34 | { | |
35 | extern "C" const char* root_c ; |
|
35 | extern "C" const char* root_c ; | |
36 | extern "C" const char* version_c ; |
|
36 | extern "C" const char* version_c ; | |
37 | extern "C" const char* design_c ; |
|
37 | extern "C" const char* design_c ; | |
38 | extern "C" const char* source_c ; |
|
38 | extern "C" const char* source_c ; | |
39 | extern "C" const char* date_c ; |
|
39 | extern "C" const char* date_c ; | |
40 | extern "C" const char* tool_c ; |
|
40 | extern "C" const char* tool_c ; | |
41 | extern "C" const char* components_c ; |
|
41 | extern "C" const char* components_c ; | |
42 | extern "C" const char* component_c ; |
|
42 | extern "C" const char* component_c ; | |
43 | extern "C" const char* ref_c ; |
|
43 | extern "C" const char* ref_c ; | |
44 | extern "C" const char* value_c ; |
|
44 | extern "C" const char* value_c ; | |
45 | extern "C" const char* libsource_c ; |
|
45 | extern "C" const char* libsource_c ; | |
46 | extern "C" const char* lib_c ; |
|
46 | extern "C" const char* lib_c ; | |
47 | extern "C" const char* part_c ; |
|
47 | extern "C" const char* part_c ; | |
48 | extern "C" const char* sheetpath_c ; |
|
48 | extern "C" const char* sheetpath_c ; | |
49 | extern "C" const char* names_c ; |
|
49 | extern "C" const char* names_c ; | |
50 | extern "C" const char* tstamps_c ; |
|
50 | extern "C" const char* tstamps_c ; | |
51 | extern "C" const char* tstamp_c ; |
|
51 | extern "C" const char* tstamp_c ; | |
52 | extern "C" const char* libparts_c ; |
|
52 | extern "C" const char* libparts_c ; | |
53 | extern "C" const char* libpart_c ; |
|
53 | extern "C" const char* libpart_c ; | |
54 | extern "C" const char* fields_c ; |
|
54 | extern "C" const char* fields_c ; | |
55 | extern "C" const char* field_c ; |
|
55 | extern "C" const char* field_c ; | |
56 | extern "C" const char* name_c ; |
|
56 | extern "C" const char* name_c ; | |
57 | extern "C" const char* pins_c ; |
|
57 | extern "C" const char* pins_c ; | |
58 | extern "C" const char* pin_c ; |
|
58 | extern "C" const char* pin_c ; | |
59 | extern "C" const char* num_c ; |
|
59 | extern "C" const char* num_c ; | |
60 | extern "C" const char* type_c ; |
|
60 | extern "C" const char* type_c ; | |
61 | extern "C" const char* libraries_c ; |
|
61 | extern "C" const char* libraries_c ; | |
62 | extern "C" const char* library_c ; |
|
62 | extern "C" const char* library_c ; | |
63 | extern "C" const char* logical_c ; |
|
63 | extern "C" const char* logical_c ; | |
64 | extern "C" const char* uri_c ; |
|
64 | extern "C" const char* uri_c ; | |
65 | extern "C" const char* nets_c ; |
|
65 | extern "C" const char* nets_c ; | |
66 | extern "C" const char* net_c ; |
|
66 | extern "C" const char* net_c ; | |
67 | extern "C" const char* code_c ; |
|
67 | extern "C" const char* code_c ; | |
68 | extern "C" const char* node_c ; |
|
68 | extern "C" const char* node_c ; | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | class QIcadNetListLevel |
|
|||
73 | { |
|
|||
74 | public: |
|
|||
75 | QIcadNetListLevel() {} |
|
|||
76 | QList<QIcadNetListLevel*> sublevels; |
|
|||
77 | QList<QIcadNet*> nets; |
|
|||
78 | }; |
|
|||
79 |
|
72 | |||
80 | class QIcadNetListDesign |
|
|||
81 | { |
|
|||
82 | public: |
|
|||
83 | QIcadNetListDesign(){} |
|
|||
84 | QString source; |
|
|||
85 | QString date; |
|
|||
86 | QString tool; |
|
|||
87 | }; |
|
|||
88 |
|
||||
89 | class QIcadNetListComponent |
|
|||
90 | { |
|
|||
91 | public: |
|
|||
92 | typedef struct libsource_t |
|
|||
93 | { |
|
|||
94 | QString lib; |
|
|||
95 | QString part; |
|
|||
96 | }libsource_t; |
|
|||
97 | typedef struct sheetpath_t |
|
|||
98 | { |
|
|||
99 | QString names; |
|
|||
100 | QString tstamp; |
|
|||
101 | }sheetpath_t; |
|
|||
102 | QIcadNetListComponent(){} |
|
|||
103 | QString ref; |
|
|||
104 | QString value; |
|
|||
105 | QString tstamp; |
|
|||
106 | libsource_t libsource; |
|
|||
107 | sheetpath_t sheetpath; |
|
|||
108 | }; |
|
|||
109 |
|
||||
110 | class QIcadNetListLibPart |
|
|||
111 | { |
|
|||
112 | public: |
|
|||
113 | typedef struct fields_t |
|
|||
114 | { |
|
|||
115 | QString ref; |
|
|||
116 | QString value; |
|
|||
117 | QString footprint; |
|
|||
118 | QString datasheet; |
|
|||
119 | }fields_t; |
|
|||
120 | typedef struct pin_t |
|
|||
121 | { |
|
|||
122 | int num; |
|
|||
123 | QString name; |
|
|||
124 | QString type; |
|
|||
125 | }pin_t; |
|
|||
126 | QIcadNetListLibPart(); |
|
|||
127 | QString lib; |
|
|||
128 | QString part; |
|
|||
129 | QStringList footprints; |
|
|||
130 | fields_t fields; |
|
|||
131 | QList<pin_t*> pins; |
|
|||
132 | }; |
|
|||
133 |
|
73 | |||
134 | class QIcadAbstractNodeWrapper |
|
74 | class QIcadAbstractNodeWrapper | |
135 | { |
|
75 | { | |
136 | public: |
|
76 | public: | |
137 | QIcadAbstractNodeWrapper(QIlib::AbstractNode* node); |
|
77 | QIcadAbstractNodeWrapper(QIlib::AbstractNode* node); | |
|
78 | QIcadAbstractNodeWrapper(){} | |||
138 | ~QIcadAbstractNodeWrapper(); |
|
79 | ~QIcadAbstractNodeWrapper(); | |
139 | QString value(); |
|
80 | QString value(); | |
140 | QString value(int index); |
|
81 | QString value(int index); | |
141 | QString catValues(); |
|
82 | QString catValues(); | |
142 | void setNode(QIlib::AbstractNode* node); |
|
|||
143 | QList<QIcadAbstractNodeWrapper*> childs; |
|
83 | QList<QIcadAbstractNodeWrapper*> childs; | |
144 | QIcadAbstractNodeWrapper* parent; |
|
84 | QIcadAbstractNodeWrapper* parent; | |
|
85 | virtual void setNode(QIlib::AbstractNode* node); | |||
145 |
|
86 | |||
146 | private: |
|
|||
147 | QIlib::AbstractNode* p_node; |
|
87 | QIlib::AbstractNode* p_node; | |
148 | }; |
|
88 | }; | |
149 |
|
89 | |||
150 |
class QIcadNetList |
|
90 | class QIcadNetListDesign : public QIcadAbstractNodeWrapper | |
151 | { |
|
91 | { | |
152 | public: |
|
92 | public: | |
153 |
QIcadNetList |
|
93 | QIcadNetListDesign(QIlib::AbstractNode* node); | |
|
94 | QIcadNetListDesign(){} | |||
154 | QIcadAbstractNodeWrapper source; |
|
95 | QIcadAbstractNodeWrapper source; | |
155 | QIcadAbstractNodeWrapper date; |
|
96 | QIcadAbstractNodeWrapper date; | |
156 | QIcadAbstractNodeWrapper tool; |
|
97 | QIcadAbstractNodeWrapper tool; | |
157 | QList<QIcadNetListComponent*> components; |
|
98 | void setNode(QIlib::AbstractNode* node); | |
158 | QList<QIcadNetListLibPart*> libparts; |
|
|||
159 | QList<QIcadNetListLibrary*> libraries; |
|
|||
160 | }; |
|
99 | }; | |
161 |
|
100 | |||
162 |
|
101 | |||
|
102 | ||||
163 | /* |
|
103 | /* | |
164 | * (comp (ref IC1) |
|
104 | * (comp (ref IC1) | |
165 | (value 24L-MOD-8) |
|
105 | (value 24L-MOD-8) | |
166 | (libsource (lib guan) (part 24L-MOD-8)) |
|
106 | (libsource (lib guan) (part 24L-MOD-8)) | |
167 | (sheetpath (names /) (tstamps /)) |
|
107 | (sheetpath (names /) (tstamps /)) | |
168 | (tstamp 52533BBE)) |
|
108 | (tstamp 52533BBE)) | |
169 | */ |
|
109 | */ | |
170 | class QIcadNetListComponent:public QIcadAbstractNodeWrapper |
|
110 | class QIcadNetListComponent:public QIcadAbstractNodeWrapper | |
171 | { |
|
111 | { | |
|
112 | class QIcadNetListLibSource : QIcadAbstractNodeWrapper | |||
|
113 | { | |||
|
114 | public: | |||
|
115 | QIcadNetListLibSource(AbstractNode* node); | |||
|
116 | QIcadNetListLibSource(){} | |||
|
117 | QIcadAbstractNodeWrapper lib; | |||
|
118 | QIcadAbstractNodeWrapper part; | |||
|
119 | void setNode(AbstractNode* node); | |||
|
120 | }; | |||
|
121 | class QIcadNetListSheetPath : QIcadAbstractNodeWrapper | |||
|
122 | { | |||
|
123 | public: | |||
|
124 | QIcadNetListSheetPath(AbstractNode* node); | |||
|
125 | QIcadNetListSheetPath(){} | |||
|
126 | QIcadAbstractNodeWrapper names; | |||
|
127 | QIcadAbstractNodeWrapper tstamps; | |||
|
128 | void setNode(AbstractNode* node); | |||
|
129 | }; | |||
172 | public: |
|
130 | public: | |
173 | QIcadNetListComponent(AbstractNode* node); |
|
131 | QIcadNetListComponent(AbstractNode* node); | |
174 | QIcadAbstractNodeWrapper ref; |
|
132 | QIcadAbstractNodeWrapper ref; | |
175 | QIcadAbstractNodeWrapper value; |
|
133 | QIcadAbstractNodeWrapper value; | |
176 |
QIcad |
|
134 | QIcadNetListLibSource libsource; | |
177 |
QIcad |
|
135 | QIcadNetListSheetPath sheetpath; | |
178 | QIcadAbstractNodeWrapper tstamp; |
|
136 | QIcadAbstractNodeWrapper tstamp; | |
|
137 | void setNode(QIlib::AbstractNode* node); | |||
179 | }; |
|
138 | }; | |
180 |
|
139 | |||
181 |
|
140 | |||
182 | /* |
|
141 | /* | |
183 | (libparts |
|
142 | (libparts | |
184 | (libpart (lib guan) (part 24L-MOD-8) |
|
143 | (libpart (lib guan) (part 24L-MOD-8) | |
185 | (fields |
|
144 | (fields | |
186 | (field (name Reference) IC) |
|
145 | (field (name Reference) IC) | |
187 | (field (name Value) 24L-MOD-8)) |
|
146 | (field (name Value) 24L-MOD-8)) | |
188 | (pins |
|
147 | (pins | |
189 | (pin (num 1) (name GND) (type power_in)) |
|
148 | (pin (num 1) (name GND) (type power_in)) | |
190 | (pin (num 2) (name VCC) (type power_in)) |
|
149 | (pin (num 2) (name VCC) (type power_in)) | |
191 | */ |
|
150 | */ | |
192 | class QIcadNetListField : QIcadAbstractNodeWrapper |
|
151 | class QIcadNetListField : QIcadAbstractNodeWrapper | |
193 | { |
|
152 | { | |
194 | public: |
|
153 | public: | |
195 | QIcadNetListField(AbstractNode* node); |
|
154 | QIcadNetListField(AbstractNode* node); | |
196 | QIcadAbstractNodeWrapper name; |
|
155 | QIcadAbstractNodeWrapper name; | |
|
156 | void setNode(AbstractNode* node); | |||
197 | }; |
|
157 | }; | |
198 |
|
158 | |||
199 |
|
159 | |||
200 | class QIcadNetListLibPart : QIcadAbstractNodeWrapper |
|
160 | class QIcadNetListLibPart : QIcadAbstractNodeWrapper | |
201 | { |
|
161 | { | |
202 | class QIcadNetListPin : QIcadAbstractNodeWrapper |
|
162 | class QIcadNetListPin : QIcadAbstractNodeWrapper | |
203 | { |
|
163 | { | |
204 | public: |
|
164 | public: | |
205 | QIcadNetListPin(AbstractNode* node); |
|
165 | QIcadNetListPin(AbstractNode* node); | |
206 | QIcadAbstractNodeWrapper type; |
|
166 | QIcadAbstractNodeWrapper type; | |
207 | QIcadAbstractNodeWrapper num; |
|
167 | QIcadAbstractNodeWrapper num; | |
208 | QIcadAbstractNodeWrapper name; |
|
168 | QIcadAbstractNodeWrapper name; | |
|
169 | void setNode(AbstractNode* node); | |||
209 | }; |
|
170 | }; | |
210 | public: |
|
171 | public: | |
211 | QIcadNetListLibPart(AbstractNode* node); |
|
172 | QIcadNetListLibPart(AbstractNode* node); | |
|
173 | QIcadAbstractNodeWrapper lib; | |||
|
174 | QIcadAbstractNodeWrapper part; | |||
212 | QList<QIcadNetListField*> fields; |
|
175 | QList<QIcadNetListField*> fields; | |
213 | QList<QIcadNetListPin*> pins; |
|
176 | QList<QIcadNetListPin*> pins; | |
|
177 | void setNode(AbstractNode* node); | |||
|
178 | void setFields(QIlib::AbstractNode* node); | |||
|
179 | void apendFields(QIlib::AbstractNode* node); | |||
|
180 | void setPins(QIlib::AbstractNode* node); | |||
|
181 | void apendPins(QIlib::AbstractNode* node); | |||
214 | }; |
|
182 | }; | |
215 |
|
183 | |||
216 | /* |
|
184 | /* | |
217 | (libraries |
|
185 | (libraries | |
218 | (library (logical guan) |
|
186 | (library (logical guan) | |
219 | (uri /home/guan/boards/guan.lib)) |
|
187 | (uri /home/guan/boards/guan.lib)) | |
220 | (library (logical device) |
|
188 | (library (logical device) | |
221 | (uri /usr/share/kicad/library/device.lib)) |
|
189 | (uri /usr/share/kicad/library/device.lib)) | |
222 | (library (logical conn) |
|
190 | (library (logical conn) | |
223 | (uri /usr/share/kicad/library/conn.lib))) |
|
191 | (uri /usr/share/kicad/library/conn.lib))) | |
224 | */ |
|
192 | */ | |
225 |
|
193 | |||
226 | class QIcadNetListLibrary : QIcadAbstractNodeWrapper |
|
194 | class QIcadNetListLibrary : QIcadAbstractNodeWrapper | |
227 | { |
|
195 | { | |
228 | public: |
|
196 | public: | |
229 | QIcadNetListLibrary(AbstractNode* node); |
|
197 | QIcadNetListLibrary(AbstractNode* node); | |
230 | QIcadAbstractNodeWrapper uri; |
|
198 | QIcadAbstractNodeWrapper uri; | |
|
199 | QIcadAbstractNodeWrapper logical; | |||
|
200 | void setNode(AbstractNode* node); | |||
231 | }; |
|
201 | }; | |
232 | /* |
|
202 | /* | |
233 | (nets |
|
203 | (nets | |
234 | (net (code 15) (name "") |
|
204 | (net (code 15) (name "") | |
235 | (node (ref C4) (pin 1)) |
|
205 | (node (ref C4) (pin 1)) | |
236 | (node (ref U2) (pin 4))) |
|
206 | (node (ref U2) (pin 4))) | |
237 | (net (code 16) (name GND) |
|
207 | (net (code 16) (name GND) | |
238 | (node (ref D1) (pin 2)) |
|
208 | (node (ref D1) (pin 2)) | |
239 | (node (ref C1) (pin 2)) |
|
209 | (node (ref C1) (pin 2)) | |
240 | (node (ref IC1) (pin 1)) |
|
210 | (node (ref IC1) (pin 1)) | |
241 | */ |
|
211 | */ | |
242 |
|
212 | |||
243 | class QIcadNetListNet : QIcadAbstractNodeWrapper |
|
213 | class QIcadNetListNet : QIcadAbstractNodeWrapper | |
244 | { |
|
214 | { | |
245 | class QIcadNetListNetNode: QIcadAbstractNodeWrapper |
|
215 | class QIcadNetListNetNode: QIcadAbstractNodeWrapper | |
246 | { |
|
216 | { | |
247 | public: |
|
217 | public: | |
248 | QIcadNetListNetNode(AbstractNode* node); |
|
218 | QIcadNetListNetNode(AbstractNode* node); | |
249 | QIcadAbstractNodeWrapper ref; |
|
219 | QIcadAbstractNodeWrapper ref; | |
250 | QIcadAbstractNodeWrapper pin; |
|
220 | QIcadAbstractNodeWrapper pin; | |
|
221 | void setNode(AbstractNode* node); | |||
251 | }; |
|
222 | }; | |
252 | public: |
|
223 | public: | |
253 | QIcadNetListNet(AbstractNode* node); |
|
224 | QIcadNetListNet(AbstractNode* node); | |
254 | QList<QIcadNetListNetNode*> NetNodes; |
|
225 | QList<QIcadNetListNetNode*> NetNodes; | |
|
226 | QIcadAbstractNodeWrapper code; | |||
|
227 | QIcadAbstractNodeWrapper name; | |||
|
228 | void setNode(AbstractNode* node); | |||
|
229 | ||||
255 | }; |
|
230 | }; | |
256 |
|
231 | |||
|
232 | class QIcadNetListRoot : public QIcadAbstractNodeWrapper | |||
|
233 | { | |||
|
234 | public: | |||
|
235 | QIcadNetListRoot(QIlib::AbstractNode* node); | |||
|
236 | QIcadNetListDesign design; | |||
|
237 | QList<QIcadNetListComponent*> components; | |||
|
238 | QList<QIcadNetListLibPart*> libparts; | |||
|
239 | QList<QIcadNetListLibrary*> libraries; | |||
|
240 | QList<QIcadNetListNet*> nets; | |||
|
241 | void setNode(QIlib::AbstractNode* node); | |||
|
242 | void setComponents(QIlib::AbstractNode* node); | |||
|
243 | void apendComponents(QIlib::AbstractNode* node); | |||
|
244 | void setLibParts(QIlib::AbstractNode* node); | |||
|
245 | void apendLibParts(QIlib::AbstractNode* node); | |||
|
246 | void setLibraries(QIlib::AbstractNode* node); | |||
|
247 | void apendLibraries(QIlib::AbstractNode* node); | |||
|
248 | void setNets(QIlib::AbstractNode* node); | |||
|
249 | void apendNets(QIlib::AbstractNode* node); | |||
|
250 | }; | |||
257 |
|
251 | |||
258 |
|
252 | |||
259 | class QIcadNetList : private lispLike_Driver |
|
253 | class QIcadNetList : private lispLike_Driver | |
260 | { |
|
254 | { | |
261 | public: |
|
255 | public: | |
262 | QIcadNetList(); |
|
256 | QIcadNetList(); | |
263 | bool parseNetList(const QString& netlist); |
|
257 | bool parseNetList(const QString& netlist); | |
264 | QString toString(); |
|
258 | QString toString(); | |
265 | QString fileName; |
|
259 | QString fileName; | |
266 | QString version; |
|
|||
267 | QIcadNetListDesign design; |
|
|||
268 | QList<QIcadNetListComponent*> components; |
|
|||
269 | QList<QIcadNetListLibPart*> libparts; |
|
|||
270 | QIcadNetListLevel rootSheet; |
|
|||
271 | QString print(); |
|
260 | QString print(); | |
272 |
QIcad |
|
261 | QIcadNetListRoot* netlistRoot; | |
273 | private: |
|
262 | private: | |
274 | QIlib::AbstractNode* getAbstractNode(const QString& node,int index); |
|
263 | QIlib::AbstractNode* getAbstractNode(const QString& node,int index); | |
275 | QIlib::AbstractNode* getAbstractNode(QIlib::AbstractNode* rootNode,const QString& node,int* index); |
|
264 | QIlib::AbstractNode* getAbstractNode(QIlib::AbstractNode* rootNode,const QString& node,int* index); | |
276 | void updateConcreteTree(); |
|
265 | void updateConcreteTree(); | |
277 | }; |
|
266 | }; | |
278 | } |
|
267 | } | |
279 | #endif // QICADNETLIST_H |
|
268 | #endif // QICADNETLIST_H |
@@ -1,48 +1,59 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the Kicad Tools Software |
|
2 | -- This file is a part of the Kicad Tools Software | |
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include <QDir> |
|
22 | #include <QDir> | |
23 | #include <QFile> |
|
23 | #include <QFile> | |
24 | #include <QApplication> |
|
24 | #include <QApplication> | |
25 | #include <qicadnetlist.h> |
|
25 | #include <qicadnetlist.h> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 | /* |
|
28 | /* | |
29 | #include <lispLike_driver.h> |
|
29 | #include <lispLike_driver.h> | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | int main(int argc, char *argv[]) |
|
32 | int main(int argc, char *argv[]) | |
33 | { |
|
33 | { | |
34 | QApplication ap(argc,argv); |
|
34 | QApplication ap(argc,argv); | |
35 | QIlib::QIcadNetList NetListdriver; |
|
35 | QIlib::QIcadNetList NetListdriver; | |
36 | if(argc>1) |
|
36 | if(argc>1) | |
37 | { |
|
37 | { | |
38 | if(QFile::exists(argv[1])) |
|
38 | if(QFile::exists(argv[1])) | |
39 | { |
|
39 | { | |
40 | QTime tm; |
|
40 | QTime tm; | |
41 | tm.start(); |
|
41 | tm.start(); | |
42 | NetListdriver.parseNetList(argv[1]); |
|
42 | NetListdriver.parseNetList(argv[1]); | |
43 | qDebug()<<"File parsed in "<<tm.elapsed()<<"ms"; |
|
43 | qDebug()<<"File parsed in "<<tm.elapsed()<<"ms"; | |
44 | std::cout<<NetListdriver.print().toStdString(); |
|
44 | if(ap.arguments().contains("--print")) | |
|
45 | { | |||
|
46 | std::cout<<NetListdriver.print().toStdString(); | |||
|
47 | } | |||
|
48 | else | |||
|
49 | { | |||
|
50 | for(int i=0;i<NetListdriver.netlistRoot->nets.count();i++) | |||
|
51 | { | |||
|
52 | std::cout<<"Found net:"<<NetListdriver.netlistRoot->nets.at(i)->name.value().toStdString()<<" "<<NetListdriver.netlistRoot->nets.at(i)->code.value().toStdString()<<"\n"; | |||
|
53 | } | |||
|
54 | } | |||
45 | } |
|
55 | } | |
|
56 | ||||
46 | } |
|
57 | } | |
47 | return 0; |
|
58 | return 0; | |
48 | } |
|
59 | } |
General Comments 0
You need to be logged in to leave comments.
Login now