Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 352 lines (312 sloc) 9.787 kb
08e7965 @sowbug Reunited hypnagogo-hw with the firmware.
authored
1 #usage "Export partlist to html and wiki'\n"
2 "Export images to png\n"
3 "Both Board and Schematic must be open\n"
4 string cmdx=""; // debugging
5 int YES= 1;
6 int NO = 0;
7 int found,n;
8 string cmds = "";
9 string temp="";
10 int prevseq;
11 int Resolution,len;
12 string fileName1="";
13 string fileName2;
14 string workdir;
15 string SourceFname;
16 string leftopr,rightopr;
17 string Ename[],Evalue[],Epackagename[];
18 int Equantity[];
19 string a[];
20 int nrightopr,nlastseq;
21 string srightopr,slastseq;
22 int counter=0;
23 int j,k,m,i=0;
24 int Result=0;
25 int startOfseq,dummy_written;
26 string dummy,lasttoken;
27 // default parameters in the dialog
28
29 int dphtml=NO;
30 int no_htmldups=YES;
31 int dpwiki=NO;
32 int no_wikidups=YES;
33 int dpSchPng=YES;
34 int schValue=600;
35 int dpBoardPng=YES;
36 int brdValue=600;
37
38
39 void range_it()
40 {
41 if(Equantity[j] > 5) {
42 startOfseq=YES;
43 dummy="";
44 dummy_written=NO;
45 n = strsplit(a, Ename[j], ',');
46 if (n !=0) {
47 dummy+=a[0];
48 for (k=1;k < n;k++){
49 cmdx+=" Token: "+a[k]+" \n";
50 len=strlen(a[k]);
51 string temp=a[k];
52 for (m=0;m < len;m++) { //find first occurance of a digit
53
54 if(isdigit(temp[m])!=0) {
55 break;
56 }
57 }
58 // m got the first digit position
59 //split characters and numbers
60 leftopr= strsub(a[k], 0, m);
61 rightopr=strsub(a[k], m);
62 cmdx+="Debug: " +a[k]+ " Leftopr: "+leftopr+" rightopr: "+rightopr+";\n";
63
64 nrightopr=strtol(rightopr); //sequence
65
66 if (startOfseq==YES) {
67 if (dummy_written=NO) {
68 if (strlen(dummy) !=0) {
69 dummy+="-";
70 }
71 dummy+=leftopr+rightopr;
72 }
73 cmdx+="Dummy start seq: "+dummy+"\n";
74 prevseq=nrightopr;
75 startOfseq=NO;
76 } else {
77
78 if(nrightopr==prevseq+1) { //got a sequence.
79
80 nlastseq=nrightopr; // store it for reference
81 slastseq=rightopr;
82 prevseq=nrightopr;
83 lasttoken="-"+leftopr+slastseq; // write at end of loop
84
85 startOfseq=NO;
86 cmdx+=" Lastseq: "+slastseq;
87
88 } else { // not sequence, write the previous one
89 dummy+="-";
90 dummy+=leftopr+slastseq;
91 startOfseq=YES; //start the sequence again
92 lasttoken=","+leftopr+rightopr;
93 dummy+=lasttoken;
94 dummy_written=YES; // dummy variables was written as last token
95 cmdx+= "dummy last seq: "+dummy+" \n";
96
97 }
98
99
100 }
101
102 }
103 }
104 dummy+= lasttoken;
105 Ename[j]=dummy;
106
107 }
108
109 }
110 if (project.board) project.board(B) {
111 workdir=filedir(B.name);
112 SourceFname=filename(B.name);
113 // remove extension
114 string s = SourceFname;
115 char c = '.';
116 int pos = strrchr(s, c);
117 if (pos >= 0) {
118 s[pos]='\0';
119 SourceFname=s;
120 }
121
122 Result = dlgDialog("DP Projects Exporter") {
123 dlgHBoxLayout {
124 dlgStretch(1);
125 dlgLabel("Dangerous Prototypes Projects Export");
126 dlgStretch(1);
127 }
128
129 dlgHBoxLayout {
130 dlgLabel("Enter output file&name without extension:");
131 dlgStringEdit(SourceFname);
132 dlgPushButton("Bro&wse") {
133 SourceFname = dlgFileOpen("Select a file", SourceFname);
134 }
135 }
136
137 dlgHBoxLayout {
138 dlgGroup("Select Output") {
139 dlgHBoxLayout {
140 dlgCheckBox("Create html : "+SourceFname+".htm", dphtml);
141 dlgGroup("Group Duplicates") {
142 dlgRadioButton("No", no_htmldups);
143 dlgRadioButton("Yes", no_htmldups);
144 }
145 }
146 dlgHBoxLayout {
147 dlgCheckBox("Create wiki : "+SourceFname+".wik", dpwiki);
148 dlgGroup("Group Duplicates") {
149 dlgRadioButton("No", no_wikidups);
150 dlgRadioButton("Yes", no_wikidups);
151 }
152 }
153 dlgHBoxLayout {
154 dlgCheckBox("Create Schematic png: "+SourceFname+".sch.png", dpSchPng);
155 dlgLabel(" Resolution: ");
156 dlgSpinBox(schValue, 50, 2400);
157 dlgLabel(" DPI ");
158 }
159 dlgHBoxLayout {
160 dlgCheckBox("Create Board png : "+SourceFname+".brd.png", dpBoardPng);
161 dlgLabel(" Resolution: ");
162 dlgSpinBox(brdValue, 50, 2400);
163 dlgLabel(" DPI ");
164 }
165
166 }
167 }
168 dlgHBoxLayout {
169 dlgLabel("Enter output Directory:");
170 dlgStringEdit(workdir);
171 dlgPushButton("Bro&wse") {
172 string dirName;
173 dirName = dlgDirectory("Select a directory", workdir);
174 workdir=dirName;
175 }
176 }
177
178 dlgSpacing(10);
179 dlgHBoxLayout {
180 dlgStretch(1);
181 dlgPushButton("+OK") dlgAccept();
182 dlgPushButton("Cancel") dlgReject();
183 }
184 };
185 if (Result==1){
186 string fileName1=workdir+"/"+SourceFname;
187 if (dphtml==1) {
188 counter=0;
189 fileName1+=".htm";
190 output(fileName1) {
191 printf("<table>\n");
192 printf("<tr><td>Part</td><td>Quantity</td><td>Value</td><td>Package</td></tr>\n");
193 if (no_htmldups==NO){
194 B.elements(E) {
195 printf("<tr><td>%s</td><td>1</td><td>%s</td><td>%s</td></tr>\n", E.name,E.value,E.package.name);
196 }
197 }
198 else {
199
200 B.elements(E) {
201 found=NO;
202 if (counter==0) {
203 Evalue[counter]=E.value;
204 Ename[counter]=E.name;
205 Epackagename[counter]=E.package.name;
206 Equantity[counter]=1;
207 counter++;
208 } else {
209 found=NO;
210 for (j=0; j< counter;j++) {
211
212 if (E.package.name=="LED-805") {
213 found=NO;
214 } else {
215 if ((Evalue[j]==E.value) && (Epackagename[j]==E.package.name) ) {
216 Ename[j]+=",";
217 Ename[j]+=E.name;
218 Equantity[j]=Equantity[j] + 1;
219 found=YES;
220 break;
221 }
222 }
223 }
224 if (found==NO) {
225 Evalue[counter]=E.value;
226 Ename[counter]=E.name;
227 Epackagename[counter]=E.package.name;
228 Equantity[counter]=1;
229 counter++;
230 }
231 }
232 }
233
234 for (j=0;j<counter;j++) {
235 range_it();
236 printf("<tr><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n", Ename[j],Equantity[j],Evalue[j],Epackagename[j]);
237 }
238 }
239 printf("</table>\n");
240
241 }
242 }
243 if(dpwiki==1) {
244 counter=0;
245 fileName1=workdir+"/"+SourceFname;
246 fileName1+=".wik";
247 output(fileName1) {
248 printf("{| class=\"wikitable\" border=\"1\"\n");
249 printf("|+ %s\n", B.name);
250 printf("!Part!!Quantity!!Value!!Package\n");
251 if (no_wikidups==NO){
252 B.elements(E) {
253 printf("|-\n");
254 printf("|%s||1||%s||%s\n", E.name,E.value,E.package.name);
255 }
256 }
257 else {
258 B.elements(E) {
259 found=NO;
260 if (counter==0) {
261 Evalue[counter]=E.value;
262 Ename[counter]=E.name;
263 Epackagename[counter]=E.package.name;
264 Equantity[counter]=1;
265 counter++;
266 } else {
267 found=NO;
268 for (j=0; j< counter;j++) {
269 if (E.package.name=="LED-805") {
270 found=NO;
271 } else {
272 if ((Evalue[j]==E.value) && (Epackagename[j]==E.package.name)) {
273 Ename[j]+=",";
274 Ename[j]+=E.name;
275 Equantity[j]=Equantity[j] + 1;
276 found=YES;
277 break;
278 }
279 }
280
281 }
282 if (found==NO) {
283 Evalue[counter]=E.value;
284 Ename[counter]=E.name;
285 Epackagename[counter]=E.package.name;
286 Equantity[counter]=1;
287 counter++;
288
289 }
290
291 }
292
293 }
294
295
296
297 for (j=0;j<counter;j++) {
298 range_it();
299 printf("|-\n");
300 printf("|%s||%d||%s||%s\n",Ename[j],Equantity[j],Evalue[j],Epackagename[j]);
301 }
302
303
304 }
305 printf("|}\n");
306 }
307 }
308
309
310 /* from sjaak
311 EXPORT PARTLIST project.parts
312 EXPORT IMAGE project.sch.png 150
313 BOARD
314 EXPORT IMAGE project.brd.png 150
315 */
316 if(dpSchPng==1) {
317 fileName2=workdir+"/"+SourceFname;
318 temp="";
319 sprintf(temp,"edit .sch;\n");
320 cmds+=temp;
321 Resolution=schValue;
322 sprintf(temp, "EXPORT IMAGE '%s%s%s' %d;\n",fileName2,".sch",".png", Resolution);
323 cmds+= temp;
324
325 }
326 if(dpBoardPng==1) {
327 fileName2=workdir+"/"+SourceFname;
328
329 sprintf(temp,"BOARD;\n");
330 cmds+= temp;
331 Resolution=brdValue;
332 sprintf(temp, "EXPORT IMAGE '%s%s%s' %d;\n",fileName2,".brd",".png", Resolution);
333 cmds+= temp;
334 }
335 }
336 } else {
337
338 int ok= dlgMessageBox("!Board and Schematic must be both open\n Goto File->switch to [Board|Schematic] ", "&OK") ;
339 cmds="";
340 }
341 // dlgMessageBox(cmds, "&OK") ;
342 // enable for debugging
343 /*
344 Result = dlgDialog("DP Projects Exporter") {
345 dlgVBoxLayout {
346 dlgLabel("Debug result ");
347 dlgTextEdit(cmdx);
348 }
349 };
350 */
351 exit(cmds);
Something went wrong with that request. Please try again.