brd_to_dsn.ulp 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718
  1. //=====================================
  2. //
  3. // Converter of CadSoft-Eagle board designs to the Specctra DSN-Textformat.
  4. //
  5. // Created by ConnectEDA extended and modified by Thomas Kaeubler and Alfons Wirtz.
  6. //
  7. // Many thanks to ConnectEDA for allowing us to use their pcb_to_dsn ulp-file.
  8. //
  9. //
  10. // Last change November 23th 2008
  11. //
  12. //=====================================
  13. int preprotect = 0;
  14. int string_quote = 1;
  15. real polyline_endpoint_tolerance = 0.001; // The tolerance for regarding 2 line endpoints as equal.
  16. enum {false,true};
  17. int Units;
  18. string layer_name[];
  19. string TopLayer, BotLayer;
  20. real default_wire_width, default_via_size, default_drill_size, default_clearance, rv_pad_inner, min_via_inner, min_pad_inner, max_pad_inner;
  21. real clearance_wire_pad, clearance_wire_smd, clearance_wire_via, clearance_pad_pad, clearance_pad_via;
  22. real clearance_via_via, clearance_smd_pad, clearance_smd_via, clearance_smd_smd;
  23. void write_Db2Unit(int Length)
  24. //----------------------------
  25. {
  26. real Value;
  27. switch (Units)
  28. {
  29. case GRID_UNIT_MM :
  30. Value = u2mm(Length);
  31. break;
  32. case GRID_UNIT_MIL :
  33. Value = u2mil(Length);
  34. break;
  35. case GRID_UNIT_INCH :
  36. Value = u2inch(Length);
  37. break;
  38. case GRID_UNIT_MIC :
  39. Value = u2mic(Length);
  40. break;
  41. }
  42. string String;
  43. sprintf(String,"%f",Value);
  44. printf(String);
  45. }
  46. void write_Int(int Val)
  47. //---------------------
  48. {
  49. string String;
  50. sprintf(String,"%d",Val);
  51. printf(String);
  52. }
  53. void write_Real(real Val)
  54. //-----------------------
  55. {
  56. string String;
  57. sprintf(String,"%f",Val);
  58. printf(String);
  59. }
  60. void write_qStr(string String)
  61. //----------------------------
  62. {
  63. if (string_quote)
  64. printf("\"");
  65. printf(String);
  66. if (string_quote)
  67. printf("\"");
  68. }
  69. void write_Str(string String)
  70. //---------------------------
  71. {
  72. printf(String);
  73. }
  74. real Db2Unit(int Length)
  75. //---------------------
  76. {
  77. real Value = 0;
  78. switch (Units)
  79. {
  80. case GRID_UNIT_MM :
  81. Value = u2mm(Length);
  82. break;
  83. case GRID_UNIT_MIL :
  84. Value = u2mil(Length);
  85. break;
  86. case GRID_UNIT_INCH :
  87. Value = u2inch(Length);
  88. break;
  89. case GRID_UNIT_MIC :
  90. Value = u2mic(Length);
  91. break;
  92. }
  93. return Value;
  94. }
  95. real mm2u(real val)
  96. //-----------------
  97. {
  98. real Value = 0;
  99. switch (Units)
  100. {
  101. case GRID_UNIT_MM :
  102. Value = val;
  103. break;
  104. case GRID_UNIT_MIL :
  105. Value = val*39.3700787402;
  106. break;
  107. case GRID_UNIT_INCH :
  108. Value = val*0.0393700787402;
  109. break;
  110. case GRID_UNIT_MIC :
  111. Value = val*0.001;
  112. break;
  113. }
  114. return Value;
  115. }
  116. real mil2u(real val)
  117. //-----------------
  118. {
  119. real Value = 0;
  120. switch (Units)
  121. {
  122. case GRID_UNIT_MM :
  123. Value = val*0.0254;
  124. break;
  125. case GRID_UNIT_MIL :
  126. Value = val;
  127. break;
  128. case GRID_UNIT_INCH :
  129. Value = val*0.001;
  130. break;
  131. case GRID_UNIT_MIC :
  132. Value = val*0.0000254;
  133. break;
  134. }
  135. return Value;
  136. }
  137. real inch2u(real val)
  138. //-----------------
  139. {
  140. real Value = 0;
  141. switch (Units)
  142. {
  143. case GRID_UNIT_MM :
  144. Value = val*25.4;
  145. break;
  146. case GRID_UNIT_MIL :
  147. Value = val*1000;
  148. break;
  149. case GRID_UNIT_INCH :
  150. Value = val;
  151. break;
  152. case GRID_UNIT_MIC :
  153. Value = val*0.0254;
  154. break;
  155. }
  156. return Value;
  157. }
  158. real mic2u(real val)
  159. //-----------------
  160. {
  161. real Value = 0;
  162. switch (Units)
  163. {
  164. case GRID_UNIT_MM :
  165. Value = val*0.001;
  166. break;
  167. case GRID_UNIT_MIL :
  168. Value = val*0.0393700787402;
  169. break;
  170. case GRID_UNIT_INCH :
  171. Value = val*0.0000393700787402;
  172. break;
  173. case GRID_UNIT_MIC :
  174. Value = val;
  175. break;
  176. }
  177. return Value;
  178. }
  179. int u2int_u(real val)
  180. //-----------------
  181. {
  182. int Value = 0;
  183. switch (Units)
  184. {
  185. case GRID_UNIT_MM :
  186. Value = val*10000;
  187. break;
  188. case GRID_UNIT_MIL :
  189. Value = val*254;
  190. break;
  191. case GRID_UNIT_INCH :
  192. Value = val*254000;
  193. break;
  194. case GRID_UNIT_MIC :
  195. Value = val;
  196. break;
  197. }
  198. return Value;
  199. }
  200. real Unit2Value(real val, string s)
  201. //---------------------
  202. {
  203. real Value = 0;
  204. if( s=="m" )
  205. {
  206. Value = mm2u(val);
  207. }
  208. else
  209. if( s=="l" )
  210. {
  211. Value = mil2u(val);
  212. }
  213. else
  214. if( s=="h" )
  215. {
  216. Value = inch2u(val);
  217. }
  218. else
  219. if( s=="c" )
  220. {
  221. Value = mic2u(val);
  222. }
  223. else
  224. {
  225. Value = val;
  226. }
  227. return Value;
  228. }
  229. // Returns the new x coordinate of the point (p_x, p_y) after rotating around the zero point by p_degree degrees.
  230. real rotate_x( real p_x, real p_y, real p_degree)
  231. {
  232. real angle = p_degree * PI / 180.0;
  233. real rotated_x = p_x * cos(angle) - p_y * sin(angle);
  234. return rotated_x;
  235. }
  236. // Returns the new x coordinate of the point (p_x, p_y) after rotating around the zero point by p_degree degrees.
  237. real rotate_y( real p_x, real p_y, real p_degree)
  238. {
  239. real angle = p_degree * PI / 180.0;
  240. real rotated_y = p_x * sin(angle) + p_y * cos(angle);
  241. return rotated_y;
  242. }
  243. //=================================================================
  244. int NumberPadTypes = 0;
  245. numeric string PadTypeName[];
  246. string ViaTypeName[];
  247. int PadTypeshape[];
  248. int PadTypeDrill[];
  249. int PadTypeX[];
  250. int PadTypeY[];
  251. int PadTypeE[];
  252. int PadTypeAngle[];
  253. int PadTypeLayer[];
  254. int PadShapeRectangle=99;
  255. //Erweiterung---------------------------------------
  256. int ViaTypeStart[];
  257. int ViaTypeEnd[];
  258. //--------------------------------------------------
  259. int ViaType = 0;
  260. string layer_setup; // = "(1*16)";
  261. int Layer_No[];
  262. int Layer_count=0;
  263. string LayerSetup[];
  264. int LayerSetup_rk[];
  265. int LayerSetup_ek[];
  266. int NumberLayer=0;
  267. int ViaBracketLevel[];
  268. int ViaBracketPos[];
  269. int ViaTypeDrill[];
  270. int rgw;
  271. int read_layer_setup(UL_BOARD B)
  272. //----------------------------
  273. {
  274. int i;
  275. int n = strlen(layer_setup);
  276. int ek=0;
  277. int rk=0;
  278. int no=0;
  279. int count=0;
  280. for (i=0; i<n; i++)
  281. {
  282. string tmp_s = strsub(layer_setup, i, 1);
  283. if (tmp_s == "[")
  284. {
  285. ek++;
  286. LayerSetup_ek[count]=ek;
  287. }
  288. if (tmp_s == "(")
  289. {
  290. rk++;
  291. LayerSetup_rk[count]=rk;
  292. }
  293. if (tmp_s == "]")
  294. {
  295. LayerSetup_ek[count]=ek;
  296. ek--;
  297. }
  298. if (tmp_s == ")")
  299. {
  300. LayerSetup_rk[count]=rk;
  301. rk--;
  302. }
  303. if (tmp_s=="0"||tmp_s=="1"||tmp_s=="2"||tmp_s=="3"||tmp_s=="4"||tmp_s=="5"||
  304. tmp_s=="6"||tmp_s=="7"||tmp_s=="8"||tmp_s=="9")
  305. {
  306. if(no==1)
  307. {
  308. tmp_s = strsub(layer_setup, i-1, 2);
  309. count--;
  310. }
  311. no=1;
  312. }
  313. else
  314. {
  315. no=0;
  316. }
  317. LayerSetup[count]=tmp_s;
  318. count++;
  319. }
  320. return count;
  321. }
  322. string NewPadTypeName(int ShapeType)
  323. //----------------------------------
  324. {
  325. string Name;
  326. int i=0;
  327. int Highest=-1;
  328. if (ShapeType == PAD_SHAPE_SQUARE)
  329. {
  330. Name = "Square";
  331. }
  332. else
  333. if (ShapeType == PAD_SHAPE_ROUND)
  334. {
  335. Name = "Round";
  336. }
  337. else
  338. if (ShapeType == PAD_SHAPE_OCTAGON)
  339. {
  340. Name = "Octagon";
  341. }
  342. else
  343. if (ShapeType == PadShapeRectangle)
  344. {
  345. Name = "Rectangle";
  346. }
  347. else
  348. if (ShapeType == PAD_SHAPE_LONG)
  349. {
  350. Name = "Oblong";
  351. }
  352. if (ShapeType == PAD_SHAPE_OFFSET)
  353. {
  354. Name = "Offset";
  355. }
  356. for (i = 0; i < NumberPadTypes; i++)
  357. {
  358. if (PadTypeshape[i] == ShapeType)
  359. {
  360. Highest = i;
  361. }
  362. }
  363. int Index = 1;
  364. if (Highest >= 0)
  365. {
  366. string IndexString = strsub(PadTypeName[Highest], strlen(Name));
  367. Index = strtol(IndexString) + 1;
  368. }
  369. sprintf(Name, "%s%d", Name, Index);
  370. return(Name);
  371. }
  372. int write_ViaType(UL_BOARD B, int n)
  373. //----------------------------
  374. {
  375. int i=0;
  376. //----Blinde Via from Top
  377. for (i=0; i<n; i++)
  378. {
  379. if (LayerSetup[i] == "[" && LayerSetup[i+1]!="[" && LayerSetup[i+1]!="(")
  380. {
  381. if (LayerSetup[i+2]==":")
  382. {
  383. ViaTypeEnd[ViaType++]=strtol(LayerSetup[i+1]);
  384. for (int j=i+1; j<n; j++)
  385. {
  386. if (
  387. LayerSetup[j]==":"
  388. &&
  389. (strtol(LayerSetup[j+1])>0 && strtol(LayerSetup[j+1])<17)
  390. &&
  391. (LayerSetup[j+2]=="+" || LayerSetup[j+2]=="*")
  392. )
  393. {
  394. ViaTypeStart[ViaType-1]=strtol(LayerSetup[j+1]);
  395. break;
  396. }
  397. if (
  398. LayerSetup[j]==":"
  399. &&
  400. ( LayerSetup[j+1]=="[" || LayerSetup[j+1]=="(" )
  401. &&
  402. (strtol(LayerSetup[j+2])>0 && strtol(LayerSetup[j+2])<17)
  403. &&
  404. (LayerSetup[j+3]=="+" || LayerSetup[j+3]=="*")
  405. )
  406. {
  407. ViaTypeStart[ViaType-1]=strtol(LayerSetup[j+2]);
  408. break;
  409. }
  410. }
  411. }
  412. }
  413. }
  414. //----Blinde Via from Bottom
  415. for (i=n; i>0; i--)
  416. {
  417. if (LayerSetup[i] == "]" && LayerSetup[i-1]!="]" && LayerSetup[i-1]!=")")
  418. {
  419. if (LayerSetup[i-2]==":")
  420. {
  421. ViaTypeStart[ViaType++]=strtol(LayerSetup[i-1]);
  422. for (int j=i-1; j>=0; j--)
  423. {
  424. if (
  425. LayerSetup[j]==":"
  426. &&
  427. (strtol(LayerSetup[j-1])>0 && strtol(LayerSetup[j-1])<17)
  428. &&
  429. (LayerSetup[j-2]=="+" || LayerSetup[j-2]=="*")
  430. )
  431. {
  432. ViaTypeEnd[ViaType-1]=strtol(LayerSetup[j-1]);
  433. break;
  434. }
  435. if (
  436. LayerSetup[j]==":"
  437. &&
  438. ( LayerSetup[j-1]=="]" || LayerSetup[j-1]==")" )
  439. &&
  440. (strtol(LayerSetup[j-2])>0 && strtol(LayerSetup[j-2])<17)
  441. &&
  442. (LayerSetup[j-3]=="+" || LayerSetup[j-3]=="*")
  443. )
  444. {
  445. ViaTypeEnd[ViaType-1]=strtol(LayerSetup[j-2]);
  446. break;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. //----Buried Via from Top
  453. int BracketStart[];
  454. int BracketEnd[];
  455. // Offene Klammern zu denen noch keine passende geschlossene Klammer gefunden wurde.
  456. // Temporärer Array, der nur während der Berechnung benötigt wird.
  457. int unhandeled_open_brackets [];
  458. int unhandeled_open_bracket_count = 0;
  459. // Arrays der gefundenen Positionen der zueinander passenen offenen und geschlossenen Klammern.
  460. int bracket_count;
  461. int open_brackets[];
  462. int closed_brackets[];
  463. // Berechnet Paare von offenen und geschlossenen Klammern und speichert das Ergebnis in
  464. // den Arrays open_brackets und closed_brackets
  465. // Schleife über den ganzen String
  466. for (i=0; i<n ; i++)
  467. {
  468. // gehe bis zur nächsten geschlossenen Klammer und paare sie mit der letzen
  469. // offenen Klammer im Array unhandeled_open_brackets.
  470. if(LayerSetup[i]=="(")
  471. {
  472. unhandeled_open_brackets[unhandeled_open_bracket_count] = i;
  473. ++unhandeled_open_bracket_count;
  474. }
  475. else if(LayerSetup[i]==")")
  476. {
  477. // Geschlossene Klammer gefunden.
  478. closed_brackets[bracket_count] = i;
  479. if (unhandeled_open_bracket_count <= 0)
  480. {
  481. // Fehler, der geschlossenen Klammer geht keine offene Klammer vorous
  482. }
  483. // Die passende offenne Klammer ist die letzte im Array unhandeled_open_brackets
  484. // Füge sie zum Array open_brackets hinzu und entferne sie aus dem Array unhandeled_open_brackets
  485. --unhandeled_open_bracket_count;
  486. open_brackets[bracket_count] = unhandeled_open_brackets [unhandeled_open_bracket_count];
  487. ++bracket_count;
  488. }
  489. }
  490. if (unhandeled_open_bracket_count != 0)
  491. {
  492. // Fehler, Anzahl der offenen und geschlossenen Klammern ist nicht gleich
  493. }
  494. for( i=0; i<bracket_count; i++)
  495. {
  496. int j;
  497. for( j=open_brackets[i]; j<=closed_brackets[i]; j++)
  498. {
  499. if( LayerSetup[j]=="(" && (strtol(LayerSetup[j+1])>0 && strtol(LayerSetup[j+1])<17))
  500. {
  501. ViaTypeStart[ViaType]=strtol(LayerSetup[j+1]);
  502. break;
  503. }
  504. }
  505. for(j=closed_brackets[i]; j>=open_brackets[i]; j--)
  506. {
  507. if( LayerSetup[j]==")" && (strtol(LayerSetup[j-1])>0 && strtol(LayerSetup[j-1])<17))
  508. {
  509. ViaTypeEnd[ViaType++]=strtol(LayerSetup[j-1]);
  510. break;
  511. }
  512. }
  513. }
  514. NumberPadTypes = ViaType;
  515. for (i=0; i<ViaType; i++)
  516. {
  517. PadTypeshape[i]=1;
  518. PadTypeX[i] = u2int_u(default_via_size);
  519. PadTypeDrill[i] = u2int_u(default_drill_size);
  520. PadTypeY[i] = 0;
  521. PadTypeE[i] = 0;
  522. PadTypeAngle[i] = 0;
  523. PadTypeLayer[i] = 0;
  524. sprintf(PadTypeName[i], "%s%d$%f", "Round", i+1, Db2Unit(PadTypeDrill[i]));
  525. ViaTypeName[i] = PadTypeName[i];
  526. }
  527. return n;
  528. }
  529. int find_layer(UL_BOARD B,int n)
  530. //----------------------------
  531. {
  532. string tmp;
  533. for (int i=0; i<n; i++)
  534. {
  535. int Found=-1;
  536. if(strtol(LayerSetup[i])>0 && strtol(LayerSetup[i])<17)
  537. {
  538. for (int j=0; (j<Layer_count); j++)
  539. {
  540. if (Layer_No[j]==strtol(LayerSetup[i]))
  541. {
  542. Found=j;
  543. break;
  544. }
  545. }
  546. if(Found==-1)
  547. {
  548. Layer_No[Layer_count++]=strtol(LayerSetup[i]);
  549. }
  550. }
  551. }
  552. sort( Layer_count, Layer_No);
  553. for (int j=0; (j<Layer_count); j++)
  554. {
  555. sprintf(tmp, "%d", Layer_No[j]);
  556. }
  557. return Layer_count;
  558. }
  559. void PTHPadType(UL_PAD Pad)
  560. //-------------------------
  561. {
  562. int i=0;
  563. int Found=-1;
  564. for (i=0; (i<NumberPadTypes) && (Found==-1); i++)
  565. {
  566. if (PadTypeshape[i] == Pad.shape[LAYER_TOP] &&
  567. PadTypeX[i] == Pad.diameter[LAYER_TOP] &&
  568. PadTypeE[i] == Pad.elongation &&
  569. PadTypeAngle[i] == Pad.angle &&
  570. PadTypeDrill[i] == Pad.drill &&
  571. PadTypeY[i] == 0 &&
  572. PadTypeLayer[i] == 0)
  573. {
  574. Found = i;
  575. }
  576. }
  577. if (Found==-1)
  578. {
  579. PadTypeName[NumberPadTypes] = NewPadTypeName(Pad.shape[LAYER_TOP]);
  580. PadTypeshape[NumberPadTypes] = Pad.shape[LAYER_TOP];
  581. PadTypeX[NumberPadTypes] = Pad.diameter[LAYER_TOP];
  582. PadTypeE[NumberPadTypes] = Pad.elongation;
  583. PadTypeAngle[NumberPadTypes] = Pad.angle;
  584. PadTypeDrill[NumberPadTypes] = Pad.drill;
  585. PadTypeY[NumberPadTypes] = 0;
  586. PadTypeLayer[NumberPadTypes] = 0;
  587. NumberPadTypes++;
  588. }
  589. }
  590. void SMDPadType(UL_SMD Pad)
  591. //-------------------------
  592. {
  593. int i=0;
  594. int Found=-1;
  595. int ShapeType = PadShapeRectangle;
  596. // Fehlerhaft bei rechteckigen SMD-Pads mit Roundness 100 20050620 thk
  597. if (Pad.roundness == 100)
  598. ShapeType = PAD_SHAPE_ROUND;
  599. for (i=0; (i<NumberPadTypes) && (Found==-1); i++)
  600. {
  601. if (PadTypeshape[i] == ShapeType &&
  602. PadTypeX[i] == Pad.dx &&
  603. PadTypeY[i] == Pad.dy &&
  604. PadTypeAngle[i] == Pad.angle &&
  605. PadTypeLayer[i] == Pad.layer)
  606. {
  607. Found = i;
  608. }
  609. }
  610. if (Found == -1)
  611. {
  612. PadTypeName[NumberPadTypes] = NewPadTypeName(ShapeType);
  613. PadTypeshape[NumberPadTypes] = ShapeType;
  614. PadTypeX[NumberPadTypes] = Pad.dx;
  615. PadTypeY[NumberPadTypes] = Pad.dy;
  616. PadTypeE[NumberPadTypes] = 0;
  617. PadTypeAngle[NumberPadTypes] = Pad.angle;
  618. PadTypeDrill[NumberPadTypes] = 0;
  619. PadTypeLayer[NumberPadTypes] = Pad.layer;
  620. NumberPadTypes++;
  621. }
  622. }
  623. void ViaPadType(UL_VIA Via)
  624. //-------------------------
  625. {
  626. int i=0;
  627. int Found=-1;
  628. for (i=0; (i<NumberPadTypes) && (Found==-1); i++)
  629. {
  630. if (PadTypeshape[i] == Via.shape[LAYER_TOP] &&
  631. PadTypeX[i] == Via.diameter[LAYER_TOP] &&
  632. PadTypeDrill[i] == Via.drill &&
  633. //Erweiterung---------------------------------------
  634. ViaTypeStart[i] == Via.start &&
  635. ViaTypeEnd[i] == Via.end &&
  636. //--------------------------------------------------
  637. PadTypeY[i] == 0 &&
  638. PadTypeLayer[i] == 0)
  639. {
  640. Found = i;
  641. }
  642. }
  643. if (Found==-1)
  644. {
  645. //Erweiterung---------------------------------------
  646. ViaTypeStart[NumberPadTypes] = Via.start;
  647. ViaTypeEnd[NumberPadTypes] = Via.end;
  648. //--------------------------------------------------
  649. PadTypeshape[NumberPadTypes] = Via.shape[LAYER_TOP];
  650. PadTypeX[NumberPadTypes] = Via.diameter[LAYER_TOP];
  651. PadTypeDrill[NumberPadTypes] = Via.drill;
  652. PadTypeY[NumberPadTypes] = 0;
  653. PadTypeE[NumberPadTypes] = 0;
  654. PadTypeAngle[NumberPadTypes] = 0;
  655. PadTypeLayer[NumberPadTypes] = 0;
  656. sprintf(PadTypeName[NumberPadTypes], "%s$%f", NewPadTypeName(Via.shape[LAYER_VIAS]), Db2Unit(PadTypeDrill[NumberPadTypes]));
  657. ViaTypeName[ViaType] = PadTypeName[NumberPadTypes];
  658. ViaType++;
  659. NumberPadTypes++;
  660. }
  661. }
  662. string FindPadType(int ShapeType, int XSize, int YSize, int drill, int Layer, int Elongation, int Angle)
  663. //------------------------------------------------------------------------------------------------------
  664. {
  665. int i=0;
  666. int Found=-1;
  667. for (i=0; (i<NumberPadTypes) && (Found==-1); i++)
  668. {
  669. if (PadTypeshape[i] == ShapeType &&
  670. PadTypeX[i] == XSize &&
  671. PadTypeY[i] == YSize &&
  672. PadTypeAngle[i] == Angle &&
  673. PadTypeDrill[i] == drill &&
  674. PadTypeE[i] == Elongation &&
  675. PadTypeLayer[i] == Layer)
  676. {
  677. Found = i;
  678. }
  679. }
  680. return(PadTypeName[Found]);
  681. }
  682. string FindViaType(int ShapeType, int XSize, int YSize, int drill, int Layer, int Elongation, int Angle, int start, int end)
  683. //--------------------------------------------------------------------------------------------------------------------------
  684. {
  685. int i=0;
  686. int Found=-1;
  687. for (i=0; (i<NumberPadTypes) && (Found==-1); i++)
  688. {
  689. if (PadTypeshape[i] == ShapeType &&
  690. ViaTypeStart[i] == start &&
  691. ViaTypeEnd[i] == end &&
  692. PadTypeX[i] == XSize &&
  693. PadTypeY[i] == YSize &&
  694. PadTypeAngle[i] == Angle &&
  695. PadTypeDrill[i] == drill &&
  696. PadTypeE[i] == Elongation &&
  697. PadTypeLayer[i] == Layer)
  698. {
  699. Found = i;
  700. }
  701. }
  702. return(PadTypeName[Found]);
  703. }
  704. void FPPadTypes(UL_PACKAGE FP)
  705. //----------------------------
  706. {
  707. FP.contacts(C)
  708. {
  709. if (C.pad)
  710. {
  711. PTHPadType(C.pad);
  712. }
  713. if (C.smd)
  714. {
  715. SMDPadType(C.smd);
  716. }
  717. }
  718. }
  719. string LayerFromId_old(int Id)
  720. //------------------------
  721. {
  722. string LayerName;
  723. if ((Id < 1) || (Id > 16))
  724. return "signal";
  725. board(Board)
  726. {
  727. Board.layers(Layer)
  728. {
  729. if (Layer.number == Id)
  730. {
  731. LayerName = Layer.name;
  732. return LayerName;
  733. }
  734. }
  735. }
  736. return "signal";
  737. }
  738. string LayerFromId(int Id)
  739. //------------------------
  740. {
  741. string LayerName;
  742. if ((Id < 1) || (Id > 16))
  743. return "signal";
  744. for (int i = 0; i < rgw; i++)
  745. {
  746. if (Layer_No[i] == Id)
  747. {
  748. sprintf(LayerName,"%d#%s", Layer_No[i], LayerFromId_old(Layer_No[i]));
  749. if(string_quote)
  750. sprintf(LayerName,"%c%s%c",'"', LayerName, '"');
  751. return LayerName;
  752. }
  753. }
  754. return "signal";
  755. }
  756. void write_Octagon(int o, int i, real a, real b)
  757. //------------------
  758. {
  759. printf("\n (shape ");
  760. printf("(polygon ");
  761. printf(LayerFromId(o));
  762. printf(" 0 ");
  763. printf("%f %f ", a, b );// 1
  764. printf("%f %f ", b, a );// 2
  765. printf("%f %f ", -b, a );// 3
  766. printf("%f %f ", -a, b );// 4
  767. printf("%f %f ", -a, -b );// 5
  768. printf("%f %f ", -b, -a );// 6
  769. printf("%f %f ", b, -a );// 7
  770. printf("%f %f ", a, -b );// 8
  771. printf("))");
  772. }
  773. void Padstacks()
  774. //--------------
  775. {
  776. int i, j, l;
  777. real a, b;
  778. string tmp;
  779. printf(" (padstack ");
  780. sprintf(tmp, "ViaDefault$%f", default_drill_size);
  781. write_qStr(tmp); printf("\n");
  782. printf(" (shape (circle signal %f", default_via_size);
  783. printf(" 0 0))\n");
  784. printf(" )\n");
  785. for (i=0; i<NumberPadTypes; i++)
  786. {
  787. l=0;
  788. printf(" (padstack ");
  789. write_qStr(PadTypeName[i]); printf(" ");// "\n"
  790. if (PadTypeshape[i]==PAD_SHAPE_ROUND)
  791. {
  792. if (PadTypeLayer[i]==0)
  793. {
  794. for( j=0; j <rgw; j++)
  795. {
  796. if(ViaTypeStart[i] <= Layer_No[j])
  797. {
  798. if(Layer_No[j] > ViaTypeEnd[i])
  799. {
  800. if(l==0)
  801. {
  802. printf("\n (shape ");
  803. printf("(circle ");
  804. printf(LayerFromId(ViaTypeStart[i]));
  805. printf(" ");
  806. write_Db2Unit(PadTypeX[i]);
  807. printf(" 0 0))");
  808. }
  809. break;
  810. }
  811. else
  812. {
  813. l=1;
  814. printf("\n (shape ");
  815. printf("(circle ");
  816. printf(LayerFromId(Layer_No[j]));
  817. printf(" ");
  818. write_Db2Unit(PadTypeX[i]);
  819. printf(" 0 0))");
  820. }
  821. }
  822. }
  823. }
  824. else
  825. {
  826. printf(" (shape ");
  827. printf("(circle ");
  828. printf(LayerFromId(PadTypeLayer[i]));
  829. printf(" ");
  830. write_Db2Unit(PadTypeX[i]);
  831. printf(" 0 0))");
  832. }
  833. }
  834. else
  835. if (PadTypeshape[i]==PAD_SHAPE_OCTAGON)
  836. {
  837. a=Db2Unit(PadTypeX[i])/2;
  838. b=(Db2Unit(PadTypeX[i])/2)*0.4142135;
  839. if (PadTypeLayer[i]==0)
  840. {
  841. for( j=0; j <rgw; j++)
  842. {
  843. if(ViaTypeStart[i] <= Layer_No[j])
  844. {
  845. if(Layer_No[j] > ViaTypeEnd[i])
  846. {
  847. if(l==0)
  848. {
  849. if(Layer_No[j]==Layer_No[0])
  850. write_Octagon(Layer_No[j], i, a, b);
  851. if((j > 0) && (j < rgw-1))
  852. {
  853. printf("\n (shape ");
  854. printf("(circle ");
  855. printf(LayerFromId(Layer_No[j]));
  856. printf(" ");
  857. if(Db2Unit(PadTypeDrill[i])+(min_pad_inner*2) >= Db2Unit(PadTypeDrill[i])*(1+rv_pad_inner*2))
  858. {
  859. printf("%f",Db2Unit(PadTypeDrill[i])+(min_pad_inner*2));
  860. }
  861. else if(Db2Unit(PadTypeDrill[i])*(1+rv_pad_inner*2) <= Db2Unit(PadTypeDrill[i])+(max_pad_inner*2))
  862. {
  863. printf("%f",Db2Unit(PadTypeDrill[i])*(1+rv_pad_inner*2));
  864. }
  865. else
  866. {
  867. printf("%f",Db2Unit(PadTypeDrill[i])+(max_pad_inner*2));
  868. }
  869. printf(" 0 0))");
  870. }
  871. if(Layer_No[j]==Layer_No[rgw-1])
  872. write_Octagon(Layer_No[j], i, a, b);
  873. }
  874. // break;
  875. }
  876. else
  877. {
  878. l=1;
  879. if(Layer_No[j]==Layer_No[0])
  880. write_Octagon(Layer_No[j], i, a, b);
  881. if((j > 0) && (j < rgw-1))
  882. {
  883. printf("\n (shape ");
  884. printf("(circle ");
  885. printf(LayerFromId(Layer_No[j]));
  886. printf(" ");
  887. printf("%f",Db2Unit(PadTypeDrill[i])+(min_via_inner*2));
  888. printf(" 0 0))");
  889. }
  890. if(Layer_No[j]==Layer_No[rgw-1])
  891. write_Octagon(Layer_No[j], i, a, b);
  892. }
  893. }
  894. }
  895. }
  896. else
  897. {
  898. write_Octagon(Layer_No[0], i, a, b);
  899. for( j=1; j < (rgw-1); j++)
  900. {
  901. printf("\n (shape ");
  902. printf("(circle ");
  903. printf(LayerFromId(Layer_No[j]));
  904. printf(" ");
  905. write_Db2Unit(PadTypeX[i]);
  906. printf(" 0 0))");
  907. }
  908. write_Octagon(Layer_No[j], i, a, b);
  909. }
  910. }
  911. else
  912. if (PadTypeshape[i]==PAD_SHAPE_LONG || PadTypeshape[i]==PAD_SHAPE_OFFSET)
  913. {
  914. printf("\n (shape ");
  915. printf("(path ");
  916. if (PadTypeLayer[i]==0)
  917. {
  918. printf("signal");
  919. }
  920. else
  921. {
  922. printf(LayerFromId(PadTypeLayer[i]));
  923. }
  924. printf(" ");
  925. l = PadTypeX[i];
  926. if (l < PadTypeY[i])
  927. l = PadTypeY[i];
  928. real Side = (0.02 * PadTypeE[i] - 1) * l;
  929. write_Db2Unit(l);
  930. printf(" ");
  931. real x1, x2, y1, y2;
  932. if (PadTypeshape[i]==PAD_SHAPE_LONG)
  933. {
  934. real half_widht = Side / 2;
  935. if (PadTypeAngle[i] == 90 || PadTypeAngle[i] == 270)
  936. {
  937. x1 = 0;
  938. y1 = -half_widht;
  939. x2 = 0;
  940. y2 = half_widht;
  941. }
  942. else if (PadTypeAngle[i] == 0 || PadTypeAngle[i] == 180)
  943. {
  944. x1 = -half_widht;
  945. y1 = 0;
  946. x2 = half_widht;
  947. y2 = 0;
  948. }
  949. else
  950. {
  951. x2 = rotate_x (half_widht, 0, PadTypeAngle[i]);
  952. y2 = rotate_y (half_widht, 0, PadTypeAngle[i]);
  953. x1 = -x2;
  954. y1 = y2;
  955. }
  956. }
  957. else
  958. {
  959. if (PadTypeAngle[i] == 0)
  960. {
  961. x1 = 0;
  962. y1 = 0;
  963. x2 = Side;
  964. y2 = 0;
  965. }
  966. else if (PadTypeAngle[i] == 180)
  967. {
  968. x1 = -Side;
  969. y1 = 0;
  970. x2 = 0;
  971. y2 = 0;
  972. }
  973. if (PadTypeAngle[i] == 90)
  974. {
  975. x1 = 0;
  976. y1 = 0;
  977. x2 = 0;
  978. y2 = Side;
  979. }
  980. else if (PadTypeAngle[i] == 270)
  981. {
  982. x1 = 0;
  983. y1 = -Side;
  984. x2 = 0;
  985. y2 = 0;
  986. }
  987. else
  988. {
  989. x1 = 0;
  990. y1 = 0;
  991. x2 = rotate_x (Side, 0, PadTypeAngle[i]);
  992. y2 = rotate_y (Side, 0, PadTypeAngle[i]);
  993. }
  994. }
  995. write_Db2Unit(x1);
  996. printf(" ");
  997. write_Db2Unit(y1);
  998. printf(" ");
  999. write_Db2Unit(x2);
  1000. printf(" ");
  1001. write_Db2Unit(y2);
  1002. printf("))");
  1003. }
  1004. else
  1005. if (PadTypeshape[i]==PAD_SHAPE_SQUARE)
  1006. {
  1007. if (PadTypeLayer[i]==0)
  1008. {
  1009. for( j=0; j <rgw; j++)
  1010. {
  1011. if(ViaTypeStart[i] <= Layer_No[j])
  1012. {
  1013. if(Layer_No[j] > ViaTypeEnd[i])
  1014. {
  1015. if(l==0)
  1016. {
  1017. printf("\n (shape ");
  1018. printf("(rect ");
  1019. printf(LayerFromId(ViaTypeStart[i]));
  1020. printf(" ");
  1021. write_Db2Unit(-(PadTypeX[i]/2));
  1022. printf(" ");
  1023. write_Db2Unit(-(PadTypeX[i]/2));
  1024. printf(" ");
  1025. write_Db2Unit(PadTypeX[i]/2);
  1026. printf(" ");
  1027. write_Db2Unit(PadTypeX[i]/2);
  1028. printf("))");
  1029. }
  1030. break;
  1031. }
  1032. else
  1033. {
  1034. l=1;
  1035. printf("\n (shape ");
  1036. printf("(rect ");
  1037. printf(LayerFromId(Layer_No[j]));
  1038. printf(" ");
  1039. write_Db2Unit(-(PadTypeX[i]/2));
  1040. printf(" ");
  1041. write_Db2Unit(-(PadTypeX[i]/2));
  1042. printf(" ");
  1043. write_Db2Unit(PadTypeX[i]/2);
  1044. printf(" ");
  1045. write_Db2Unit(PadTypeX[i]/2);
  1046. printf("))");
  1047. }
  1048. }
  1049. }
  1050. }
  1051. else
  1052. {
  1053. printf("\n (shape ");
  1054. printf("(rect ");
  1055. printf(LayerFromId(PadTypeLayer[i]));
  1056. printf(" ");
  1057. write_Db2Unit(-(PadTypeX[i]/2));
  1058. printf(" ");
  1059. write_Db2Unit(-(PadTypeX[i]/2));
  1060. printf(" ");
  1061. write_Db2Unit(PadTypeX[i]/2);
  1062. printf(" ");
  1063. write_Db2Unit(PadTypeX[i]/2);
  1064. printf("))");
  1065. }
  1066. }
  1067. else
  1068. if (PadTypeshape[i]==PadShapeRectangle)
  1069. {
  1070. printf("\n (shape ");
  1071. printf("(rect ");
  1072. if (PadTypeLayer[i]==0)
  1073. {
  1074. printf("signal");
  1075. }
  1076. else
  1077. {
  1078. printf(LayerFromId(PadTypeLayer[i]));
  1079. }
  1080. if (PadTypeAngle[i] == 90 || PadTypeAngle[i] == 270)
  1081. {
  1082. printf(" ");
  1083. write_Db2Unit(-(PadTypeY[i]/2));
  1084. printf(" ");
  1085. write_Db2Unit(-(PadTypeX[i]/2));
  1086. printf(" ");
  1087. write_Db2Unit(PadTypeY[i]/2);
  1088. printf(" ");
  1089. write_Db2Unit(PadTypeX[i]/2);
  1090. printf("))");
  1091. }
  1092. else
  1093. {
  1094. printf(" ");
  1095. write_Db2Unit(-(PadTypeX[i]/2));
  1096. printf(" ");
  1097. write_Db2Unit(-(PadTypeY[i]/2));
  1098. printf(" ");
  1099. write_Db2Unit(PadTypeX[i]/2);
  1100. printf(" ");
  1101. write_Db2Unit(PadTypeY[i]/2);
  1102. printf("))");
  1103. }
  1104. }
  1105. else
  1106. {
  1107. printf("\n (shape ");
  1108. printf("(rect ");
  1109. if (PadTypeLayer[i]==0)
  1110. {
  1111. printf("signal");
  1112. }
  1113. else
  1114. {
  1115. printf(LayerFromId(PadTypeLayer[i]));
  1116. }
  1117. if (PadTypeAngle[i] == 90 || PadTypeAngle[i] == 270)
  1118. {
  1119. printf(" ");
  1120. write_Db2Unit(-(PadTypeY[i]/2));
  1121. printf(" ");
  1122. write_Db2Unit(-(PadTypeX[i]/2));
  1123. printf(" ");
  1124. write_Db2Unit(PadTypeY[i]/2);
  1125. printf(" ");
  1126. write_Db2Unit(PadTypeX[i]/2);
  1127. printf("))");
  1128. }
  1129. else
  1130. {
  1131. printf(" ");
  1132. write_Db2Unit(-(PadTypeX[i]/2));
  1133. printf(" ");
  1134. write_Db2Unit(-(PadTypeY[i]/2));
  1135. printf(" ");
  1136. write_Db2Unit(PadTypeX[i]/2);
  1137. printf(" ");
  1138. write_Db2Unit(PadTypeY[i]/2);
  1139. printf("))");
  1140. }
  1141. }
  1142. printf("\n");
  1143. printf(" (attach off)\n");
  1144. printf(" )\n");
  1145. }
  1146. }
  1147. char IsKeepoutLayer(int LayerNumber)
  1148. //----------------------------------
  1149. {
  1150. if (LayerNumber >= 39 && LayerNumber <= 43)
  1151. {
  1152. return true;
  1153. }
  1154. return false;
  1155. }
  1156. string KeepoutType(int LayerNumber)
  1157. //---------------------------------
  1158. {
  1159. if (LayerNumber == 43)
  1160. {
  1161. return "via_keepout";
  1162. }
  1163. if (LayerNumber == 41 || LayerNumber == 42)
  1164. {
  1165. return "wire_keepout";
  1166. }
  1167. if (LayerNumber == 39 || LayerNumber == 40)
  1168. {
  1169. return "place_keepout";
  1170. }
  1171. return "keepout";
  1172. }
  1173. // Calculates the square of the distance between the points (x1, y1) and (x2, y2).
  1174. real dist_square ( int x1, int y1, int x2, int y2)
  1175. //---------------------------------
  1176. {
  1177. real dx = x2 - x1;
  1178. real dy = y2 - y1;
  1179. return (dx * dx + dy * dy);
  1180. }
  1181. // Calculates the distance between the points (x1, y1) and (x2, y2).
  1182. real distance ( int x1, int y1, int x2, int y2)
  1183. //---------------------------------
  1184. {
  1185. real d2 = dist_square (x1, y1, x2, y2);
  1186. return sqrt (d2);
  1187. }
  1188. int boundary_lines_a_x[], boundary_lines_a_y[]; // The coordinates of the start points of the lines of the boundary.
  1189. int boundary_lines_b_x[], boundary_lines_b_y[]; // The coordinates of the end points of the lines of the boundary.
  1190. int line_handeled[]; // Describes, if a line is already handeled while creating
  1191. // the polygons of the boundary.
  1192. int approximate_boundary_arc(UL_ARC arc, int line_no)
  1193. //---------------------------------
  1194. {
  1195. real max_piece_length = 1000;
  1196. real arc_length = distance(arc.x1, arc.y1, arc.x2, arc.y2);
  1197. int approx_count = arc_length / max_piece_length;
  1198. approx_count = max (approx_count, 1);
  1199. real delta_angle = arc.angle2 - arc.angle1;
  1200. if (delta_angle < 0)
  1201. {
  1202. delta_angle += 360;
  1203. }
  1204. real angle_inc = delta_angle / approx_count;
  1205. int prev_x = arc.x1;
  1206. int prev_y = arc.y1;
  1207. for (int i = 1; i <= approx_count; ++i)
  1208. {
  1209. int next_x;
  1210. int next_y;
  1211. if (i == approx_count)
  1212. {
  1213. next_x = arc.x2;
  1214. next_y = arc.y2;
  1215. }
  1216. else
  1217. {
  1218. real curr_angle = arc.angle1 + i * angle_inc;
  1219. if (curr_angle > 360)
  1220. {
  1221. curr_angle -= 360;
  1222. }
  1223. real radian_angle = curr_angle * PI / 180.0;
  1224. next_x = arc.xc + arc.radius * cos(radian_angle);
  1225. next_y = arc.yc + arc.radius * sin(radian_angle);
  1226. }
  1227. boundary_lines_a_x[line_no]= prev_x;
  1228. boundary_lines_a_y[line_no]= prev_y;
  1229. boundary_lines_b_x[line_no]= next_x;
  1230. boundary_lines_b_y[line_no]= next_y;
  1231. ++line_no;
  1232. prev_x = next_x;
  1233. prev_y = next_y;
  1234. }
  1235. return line_no;
  1236. }
  1237. int process_next_wire (UL_WIRE p_wire, int p_corner_count)
  1238. {
  1239. int new_corner_count;
  1240. if (p_wire.arc)
  1241. {
  1242. new_corner_count = approximate_boundary_arc(p_wire.arc, p_corner_count);
  1243. }
  1244. else
  1245. {
  1246. boundary_lines_a_x[p_corner_count] = p_wire.x1;
  1247. boundary_lines_a_y[p_corner_count] = p_wire.y1;
  1248. boundary_lines_b_x[p_corner_count] = p_wire.x2;
  1249. boundary_lines_b_y[p_corner_count] = p_wire.y2;
  1250. new_corner_count = p_corner_count + 1;
  1251. }
  1252. return new_corner_count;
  1253. }
  1254. // Collects the lines of the board outline.
  1255. int collectOutlineLines(UL_BOARD Board)
  1256. //-------------------------
  1257. {
  1258. int i=0;
  1259. Board.wires(W)
  1260. {
  1261. if (W.layer == LAYER_DIMENSION)
  1262. {
  1263. i = process_next_wire(W, i);
  1264. }
  1265. }
  1266. return i;
  1267. }
  1268. int polygon_corner_count; // The numer of corners of the polygon.
  1269. int polygon_part_corners_x[], polygon_part_corners_y[]; // A connected part of a keepout described as a polygon.
  1270. int polygon_part_corner_count; // The number of corners of the connected part.
  1271. // Combines all connected unhandeled lines of a list of lines to a polygon.
  1272. // Returns false, if there are no more unhandled lines.
  1273. int combineLines(real p_end_point_tolerance)
  1274. {
  1275. int index_of_first_unhandeled_line = -1;
  1276. for (int j = 0; j < polygon_corner_count; ++j)
  1277. {
  1278. if (!line_handeled[j])
  1279. {
  1280. index_of_first_unhandeled_line = j;
  1281. }
  1282. }
  1283. if (index_of_first_unhandeled_line < 0)
  1284. {
  1285. return false;
  1286. }
  1287. int searchx = boundary_lines_b_x[index_of_first_unhandeled_line];
  1288. int searchy = boundary_lines_b_y[index_of_first_unhandeled_line];
  1289. polygon_part_corners_x[0] = boundary_lines_a_x[index_of_first_unhandeled_line];
  1290. polygon_part_corners_y[0] = boundary_lines_a_y[index_of_first_unhandeled_line];
  1291. line_handeled[index_of_first_unhandeled_line] = true;
  1292. int resultcornercount = 1;
  1293. for (j = 0; j < polygon_corner_count; ++j)
  1294. {
  1295. real min_distance = p_end_point_tolerance;
  1296. int next_line_found = false;
  1297. int nearest_line_index;
  1298. char nearest_point_is_start;
  1299. // Search the nearest endpoint of the other lines to (searchx, searchy)
  1300. // and add it to the result polygon.
  1301. // In general this point should be equal to (searchx, searchy).
  1302. for (int i = 0; i < polygon_corner_count; ++i)
  1303. {
  1304. if (line_handeled[i])
  1305. {
  1306. continue;
  1307. }
  1308. real curr_distance = dist_square(searchx, searchy, boundary_lines_a_x[i], boundary_lines_a_y [i]);
  1309. if ( curr_distance < min_distance)
  1310. {
  1311. min_distance = curr_distance;
  1312. nearest_line_index = i;
  1313. nearest_point_is_start = true;
  1314. next_line_found = true;
  1315. }
  1316. curr_distance = dist_square(searchx, searchy, boundary_lines_b_x[i], boundary_lines_b_y[i]);
  1317. if ( curr_distance < min_distance)
  1318. {
  1319. min_distance = curr_distance;
  1320. nearest_line_index = i;
  1321. nearest_point_is_start = false;
  1322. next_line_found = true;
  1323. }
  1324. }
  1325. if (!next_line_found)
  1326. {
  1327. break;
  1328. }
  1329. polygon_part_corners_x[resultcornercount] = searchx;
  1330. polygon_part_corners_y[resultcornercount] = searchy;
  1331. ++resultcornercount;
  1332. // Take the other endpoint of the line of the found nearestpoint
  1333. // as new seach point.
  1334. if (nearest_point_is_start)
  1335. {
  1336. searchx = boundary_lines_b_x[nearest_line_index];
  1337. searchy = boundary_lines_b_y[nearest_line_index];
  1338. }
  1339. else
  1340. {
  1341. searchx = boundary_lines_a_x[nearest_line_index];
  1342. searchy = boundary_lines_a_y[nearest_line_index];
  1343. }
  1344. line_handeled[nearest_line_index] = true;
  1345. }
  1346. if (resultcornercount == 1)
  1347. {
  1348. // no matching lines found, descripe the result shape as line with a width
  1349. polygon_part_corners_x[1] = boundary_lines_b_x[index_of_first_unhandeled_line];
  1350. polygon_part_corners_y[1] = boundary_lines_b_y[index_of_first_unhandeled_line];
  1351. resultcornercount = 2;
  1352. }
  1353. polygon_part_corner_count = resultcornercount;
  1354. return true;
  1355. }
  1356. void MakeBoundary ()
  1357. //-------------------------
  1358. {
  1359. board(Board)
  1360. {
  1361. polygon_corner_count = collectOutlineLines(Board);
  1362. }
  1363. for (int i = 0; i < polygon_corner_count; ++i)
  1364. {
  1365. printf(" (boundary ");
  1366. printf("(path ");
  1367. printf("signal 0 ");
  1368. write_Db2Unit(boundary_lines_a_x[i]);
  1369. printf(" ");
  1370. write_Db2Unit(boundary_lines_a_y[i]);
  1371. printf(" ");
  1372. write_Db2Unit(boundary_lines_b_x[i]);
  1373. printf(" ");
  1374. write_Db2Unit(boundary_lines_b_y[i]);
  1375. printf("))\n");
  1376. }
  1377. }
  1378. void board_dimension()
  1379. //-------------------------
  1380. {
  1381. int i=0;
  1382. int ox=0;
  1383. int oy=0;
  1384. int mx=0;
  1385. int my=0;
  1386. int dimx1[], dimy1[]; // coordinate od Dimension
  1387. int dimx2[], dimy2[]; // coordinate od Dimension
  1388. int index[];
  1389. board(B)
  1390. {
  1391. B.wires(W)
  1392. {
  1393. if (W.layer==LAYER_DIMENSION)
  1394. {
  1395. dimx1[i]=W.x1;
  1396. dimy1[i]=W.y1;
  1397. dimx2[i]=W.x2;
  1398. dimy2[i]=W.y2;
  1399. i++;
  1400. }
  1401. }
  1402. }
  1403. sort(i, index, dimx1, dimx2, dimy1, dimy2);
  1404. ox=dimx1[0];
  1405. oy=dimy1[0];
  1406. for (int n = 0; n < i; n++)
  1407. {
  1408. if (dimx1[n]<ox) {ox=dimx1[n];}
  1409. if (dimy1[n]<oy) {oy=dimy1[n];}
  1410. if (dimx2[n]>mx) {mx=dimx2[n];}
  1411. if (dimy2[n]>my) {my=dimy2[n];}
  1412. }
  1413. printf(" (boundary \n");
  1414. printf(" (rect pcb ");
  1415. printf(" "); write_Db2Unit(ox);
  1416. printf(" "); write_Db2Unit(oy);
  1417. printf(" "); write_Db2Unit(mx);
  1418. printf(" "); write_Db2Unit(my);
  1419. printf(")\n )\n");
  1420. }
  1421. void LineDesc(UL_WIRE Line)
  1422. //-------------------------
  1423. {
  1424. write_Db2Unit(Line.width);
  1425. printf(" ");
  1426. write_Db2Unit(Line.x1);
  1427. printf(" ");
  1428. write_Db2Unit(Line.y1);
  1429. printf(" ");
  1430. write_Db2Unit(Line.x2);
  1431. printf(" ");
  1432. write_Db2Unit(Line.y2);
  1433. }
  1434. void ArcDesc(UL_ARC Arc)
  1435. //-------------------------
  1436. {
  1437. write_Db2Unit(Arc.width);
  1438. printf(" ");
  1439. write_Db2Unit(Arc.x1);
  1440. printf(" ");
  1441. write_Db2Unit(Arc.y1);
  1442. printf(" ");
  1443. write_Db2Unit(Arc.x2);
  1444. printf(" ");
  1445. write_Db2Unit(Arc.y2);
  1446. }
  1447. void CircleDesc(UL_CIRCLE Circle)
  1448. //-------------------------------
  1449. {
  1450. write_Db2Unit(Circle.radius * 2);
  1451. printf(" ");
  1452. write_Db2Unit(Circle.x);
  1453. printf(" ");
  1454. write_Db2Unit(Circle.y);
  1455. }
  1456. void RectangleDesc(UL_RECTANGLE Rectangle)
  1457. //----------------------------------------
  1458. {
  1459. write_Db2Unit(Rectangle.x1);
  1460. printf(" ");
  1461. write_Db2Unit(Rectangle.y1);
  1462. printf(" ");
  1463. write_Db2Unit(Rectangle.x2);
  1464. printf(" ");
  1465. write_Db2Unit(Rectangle.y2);
  1466. }
  1467. void PolygonDesc(UL_POLYGON Polygon)
  1468. //----------------------------------
  1469. {
  1470. printf(" ");
  1471. write_Db2Unit(Polygon.width);
  1472. Polygon.wires(Wire)
  1473. {
  1474. printf(" ");
  1475. write_Db2Unit(Wire.x1);
  1476. printf(" ");
  1477. write_Db2Unit(Wire.y1);
  1478. }
  1479. }
  1480. void PTHPad(UL_PAD Pad)
  1481. //---------------------
  1482. {
  1483. string Style;
  1484. Style = FindPadType(Pad.shape[LAYER_TOP], Pad.diameter[LAYER_TOP], 0, Pad.drill, 0, Pad.elongation, Pad.angle);
  1485. write_qStr(Style); printf(" ");
  1486. }
  1487. void SMDPad(UL_SMD Pad)
  1488. //---------------------
  1489. {
  1490. string Style;
  1491. if (Pad.roundness == 100)
  1492. Style = FindPadType(PAD_SHAPE_ROUND, Pad.dx, Pad.dy, 0, Pad.layer, 0, Pad.angle);
  1493. else
  1494. Style = FindPadType(PadShapeRectangle, Pad.dx, Pad.dy, 0, Pad.layer, 0, Pad.angle);
  1495. write_qStr(Style); printf(" ");
  1496. }
  1497. void make_component_keepout(int p_layer, string p_layer_name)
  1498. {
  1499. if (polygon_corner_count <= 0 || !IsKeepoutLayer(p_layer))
  1500. {
  1501. return;
  1502. }
  1503. for (int i = 0; i < polygon_corner_count; ++i)
  1504. {
  1505. line_handeled[i] = false;
  1506. }
  1507. for (;;)
  1508. {
  1509. int more_parts = combineLines(polyline_endpoint_tolerance);
  1510. if (!more_parts)
  1511. {
  1512. break;
  1513. }
  1514. printf(" (%s", KeepoutType(p_layer));
  1515. p_layer_name = "signal";
  1516. if (p_layer == 39 || p_layer == 41)
  1517. p_layer_name = TopLayer;
  1518. if (p_layer == 40 || p_layer == 42)
  1519. p_layer_name = BotLayer;
  1520. printf("(path ");
  1521. write_Str(p_layer_name);
  1522. printf(" 0 ");
  1523. for (i = 0; i< polygon_part_corner_count; ++i)
  1524. {
  1525. write_Db2Unit(polygon_part_corners_x[i]);
  1526. printf(" ");
  1527. write_Db2Unit(polygon_part_corners_y[i]);
  1528. printf(" ");
  1529. }
  1530. printf("))\n");
  1531. }
  1532. }
  1533. void FPOutline(UL_PACKAGE FP, UL_LAYER Layer)
  1534. //-------------------------------------------
  1535. {
  1536. string LayerName;
  1537. if (Layer.number == LAYER_TPLACE || IsKeepoutLayer(Layer.number))
  1538. {
  1539. LayerName = LayerFromId(Layer.number);
  1540. board(Board)
  1541. {
  1542. Board.layers(Layer)
  1543. {
  1544. if (Layer.number == 1)
  1545. LayerName = LayerFromId(Layer.number);
  1546. }
  1547. }
  1548. polygon_corner_count = 0;
  1549. int width = 0;
  1550. FP.wires(W)
  1551. {
  1552. if (W.layer == Layer.number)
  1553. {
  1554. polygon_corner_count = process_next_wire (W, polygon_corner_count);
  1555. width = W.width;
  1556. }
  1557. }
  1558. make_component_keepout(Layer.number, LayerName);
  1559. FP.circles(Circle)
  1560. {
  1561. if (Circle.layer==Layer.number)
  1562. {
  1563. if (IsKeepoutLayer(Layer.number))
  1564. {
  1565. printf(" (%s", KeepoutType(Layer.number));
  1566. LayerName ="signal";
  1567. if (Layer.number == 39 || Layer.number == 41)
  1568. LayerName = TopLayer;
  1569. if (Layer.number == 40 || Layer.number == 42)
  1570. LayerName = BotLayer;
  1571. }
  1572. else
  1573. printf(" (outline");
  1574. printf("(circ ");
  1575. write_Str(LayerName); printf(" ");
  1576. CircleDesc(Circle);
  1577. printf("))\n");
  1578. }
  1579. }
  1580. FP.rectangles(Rectangle)
  1581. {
  1582. if (Rectangle.layer==Layer.number)
  1583. {
  1584. if (IsKeepoutLayer(Layer.number))
  1585. {
  1586. printf(" (%s", KeepoutType(Layer.number));
  1587. LayerName ="signal";
  1588. if (Layer.number == 39 || Layer.number == 41)
  1589. LayerName = TopLayer;
  1590. if (Layer.number == 40 || Layer.number == 42)
  1591. LayerName = BotLayer;
  1592. }
  1593. else
  1594. printf(" (outline");
  1595. printf("(rect ");
  1596. write_Str(LayerName); printf(" ");
  1597. RectangleDesc(Rectangle);
  1598. printf("))\n");
  1599. }
  1600. }
  1601. FP.polygons(Polygon)
  1602. {
  1603. if (Polygon.layer == Layer.number)
  1604. {
  1605. Polygon.wires(W)
  1606. {
  1607. polygon_corner_count = process_next_wire (W, polygon_corner_count);
  1608. width = W.width;
  1609. }
  1610. for (int i = 0; i < polygon_corner_count; ++i)
  1611. {
  1612. printf(" (outline ");
  1613. printf("(path ");
  1614. printf("signal 0 ");
  1615. write_Db2Unit(boundary_lines_a_x[i]);
  1616. printf(" ");
  1617. write_Db2Unit(boundary_lines_a_y[i]);
  1618. printf(" ");
  1619. write_Db2Unit(boundary_lines_b_x[i]);
  1620. printf(" ");
  1621. write_Db2Unit(boundary_lines_b_y[i]);
  1622. printf("))\n");
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. void Image(UL_PACKAGE FP)
  1629. //-----------------------
  1630. {
  1631. int hi = 1;
  1632. string HName;
  1633. printf(" (image ");
  1634. write_qStr(FP.name + "$" + FP.library); printf("\n");
  1635. board(Board)
  1636. {
  1637. Board.layers(Layer)
  1638. {
  1639. FPOutline(FP,Layer);
  1640. }
  1641. }
  1642. FP.holes(Hole)
  1643. {
  1644. printf(" (keepout (circ signal ");
  1645. write_Db2Unit(Hole.diameter[LAYER_TSTOP]);
  1646. printf(" ");
  1647. write_Db2Unit(Hole.x);
  1648. printf(" ");
  1649. write_Db2Unit(Hole.y);
  1650. printf("))\n");
  1651. }
  1652. FP.contacts(Pad)
  1653. {
  1654. printf(" (pin ");
  1655. if (Pad.pad)
  1656. {
  1657. PTHPad(Pad.pad);
  1658. }
  1659. if (Pad.smd)
  1660. {
  1661. SMDPad(Pad.smd);
  1662. }
  1663. write_qStr(Pad.name);
  1664. printf(" ");
  1665. write_Db2Unit(Pad.x);
  1666. printf(" ");
  1667. write_Db2Unit(Pad.y);
  1668. printf(")\n");
  1669. }
  1670. printf(" )\n");
  1671. }
  1672. void GetUsedFPs()
  1673. //---------------
  1674. {
  1675. int UsedFPCount=0;
  1676. numeric string UsedFPs[];
  1677. board(Board)
  1678. {
  1679. Board.elements(Component)
  1680. {
  1681. string FPName=Component.package.name;
  1682. char Found=false;
  1683. int i;
  1684. for (i=0; (i<UsedFPCount) &&!Found; i++)
  1685. {
  1686. if (UsedFPs[i] == FPName)
  1687. {
  1688. Found = true;
  1689. }
  1690. }
  1691. if (!Found)
  1692. {
  1693. UsedFPs[UsedFPCount++]=FPName;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. void PadTypes(void)
  1699. //------------------
  1700. {
  1701. board(Board)
  1702. {
  1703. Board.libraries(Library)
  1704. {
  1705. Library.packages(FP)
  1706. {
  1707. FPPadTypes(FP);
  1708. }
  1709. }
  1710. Board.signals(Net)
  1711. {
  1712. Net.vias(Via)
  1713. {
  1714. ViaPadType(Via);
  1715. }
  1716. }
  1717. }
  1718. }
  1719. void Images()
  1720. //----------
  1721. {
  1722. GetUsedFPs();
  1723. printf(" (library\n");
  1724. board(Board)
  1725. {
  1726. Board.libraries(Library)
  1727. {
  1728. Library.packages(FP)
  1729. {
  1730. Image(FP);
  1731. }
  1732. }
  1733. }
  1734. Padstacks();
  1735. printf(" )\n");
  1736. }
  1737. void Header()
  1738. //-----------
  1739. {
  1740. board(Board)
  1741. {
  1742. Units = Board.grid.unit;
  1743. printf("(PCB ");
  1744. printf("\"");
  1745. printf(Board.name);
  1746. printf("\"");
  1747. printf("\n");
  1748. printf(" (parser\n");
  1749. printf(" (string_quote \")\n");
  1750. printf(" (space_in_quoted_tokens on)\n");
  1751. printf(" (host_cad CadSoft)\n");
  1752. printf(" (host_version '%s')\n", EAGLE_SIGNATURE);
  1753. printf(" )\n");
  1754. printf(" (resolution ");
  1755. if (Units == GRID_UNIT_MM)
  1756. {
  1757. printf("mm 10000)");
  1758. printf("\n (unit mm)");
  1759. }
  1760. else
  1761. if (Units == GRID_UNIT_MIL)
  1762. {
  1763. printf("mil 254)");
  1764. printf("\n (unit mil)");
  1765. }
  1766. else
  1767. if (Units == GRID_UNIT_INCH)
  1768. {
  1769. printf("inch 254000)");
  1770. printf("\n (unit inch)");
  1771. }
  1772. else
  1773. if (Units == GRID_UNIT_MIC)
  1774. {
  1775. printf("um 10)");
  1776. printf("\n (unit mm)");
  1777. }
  1778. printf("\n");
  1779. }
  1780. }
  1781. void FromTo(UL_CONTACTREF Node)
  1782. //-----------------------------
  1783. {
  1784. /*
  1785. printf(" \"");
  1786. printf(Node.element.name);
  1787. printf("\"-");
  1788. printf("\"");
  1789. printf(Node.contact.name);
  1790. printf("\"");*/
  1791. printf(" ");
  1792. write_qStr(Node.element.name);
  1793. printf("-");
  1794. write_qStr(Node.contact.name);
  1795. }
  1796. int net_count = 0;
  1797. string net_name_arr[];
  1798. int net_class_no_arr[];
  1799. void Network()
  1800. //------------
  1801. {
  1802. printf(" (network\n");
  1803. board(Board)
  1804. {
  1805. // write the nets
  1806. Board.signals(Net)
  1807. {
  1808. printf(" (net ");
  1809. write_qStr(Net.name);
  1810. printf("\n");
  1811. printf(" (pins ");
  1812. Net.contactrefs(Node)
  1813. {
  1814. FromTo(Node);
  1815. }
  1816. printf(")\n");
  1817. printf(" )\n");
  1818. net_name_arr[net_count] = Net.name;
  1819. net_class_no_arr[net_count] = Net.class.number;
  1820. ++net_count;
  1821. }
  1822. // write the classes
  1823. Board.classes(curr_class)
  1824. {
  1825. if ((curr_class.width == 0) && (curr_class.clearance == 0))
  1826. {
  1827. continue;
  1828. }
  1829. printf(" (class ");
  1830. write_qStr(curr_class.name);
  1831. printf("\n ");
  1832. for(int i = 0; i < net_count; ++i)
  1833. {
  1834. if (net_class_no_arr[i] == curr_class.number)
  1835. {
  1836. printf(" ");
  1837. write_qStr(net_name_arr[i]);
  1838. }
  1839. }
  1840. printf("\n (rule");
  1841. if (curr_class.width != 0)
  1842. {
  1843. printf("\n (width ");
  1844. real wire_width = curr_class.width;
  1845. if (wire_width <= 0)
  1846. {
  1847. wire_width = default_wire_width;
  1848. }
  1849. write_Db2Unit(wire_width);
  1850. printf(")");
  1851. }
  1852. if (curr_class.clearance != 0)
  1853. {
  1854. printf("\n (clearance ");
  1855. real clearance = curr_class.clearance;
  1856. if (clearance <= 0)
  1857. {
  1858. clearance = default_clearance;
  1859. }
  1860. write_Db2Unit(clearance);
  1861. printf(")");
  1862. }
  1863. printf("\n )\n");
  1864. printf(" )\n");
  1865. }
  1866. }
  1867. printf(" )\n");
  1868. }
  1869. int arc_approx_corners_x[], arc_approx_corners_y[];
  1870. int approximate_wire_arc(UL_ARC arc)
  1871. //---------------------------------
  1872. {
  1873. real max_piece_length = 10000;
  1874. real arc_length = distance(arc.x1, arc.y1, arc.x2, arc.y2);
  1875. int approx_count = arc_length / max_piece_length;
  1876. approx_count = max (approx_count, 1);
  1877. real delta_angle = arc.angle2 - arc.angle1;
  1878. if (delta_angle < 0)
  1879. {
  1880. delta_angle += 360;
  1881. }
  1882. real angle_inc = delta_angle / approx_count;
  1883. arc_approx_corners_x[0] = arc.x1;
  1884. arc_approx_corners_y[0] = arc.y1;
  1885. int corner_no = 1;
  1886. for (int i = 1; i <= approx_count; ++i)
  1887. {
  1888. int next_x;
  1889. int next_y;
  1890. if (i == approx_count)
  1891. {
  1892. next_x = arc.x2;
  1893. next_y = arc.y2;
  1894. }
  1895. else
  1896. {
  1897. real curr_angle = arc.angle1 + i * angle_inc;
  1898. if (curr_angle > 360)
  1899. {
  1900. curr_angle -= 360;
  1901. }
  1902. real radian_angle = curr_angle * PI / 180.0;
  1903. next_x = arc.xc + arc.radius * cos(radian_angle);
  1904. next_y = arc.yc + arc.radius * sin(radian_angle);
  1905. }
  1906. arc_approx_corners_x[corner_no]= next_x;
  1907. arc_approx_corners_y[corner_no]= next_y;
  1908. ++corner_no;
  1909. }
  1910. return corner_no;
  1911. }
  1912. void Wiring()
  1913. //-----------
  1914. {
  1915. int hi = 1;
  1916. string Name;
  1917. printf(" (wiring\n");
  1918. board(Board)
  1919. {
  1920. Board.signals(Net)
  1921. {
  1922. Net.wires(Wire)
  1923. {
  1924. if ((Wire.layer >= 1) && (Wire.layer <= 16))
  1925. {
  1926. if (Wire.arc)
  1927. {
  1928. int corner_count = approximate_wire_arc(Wire.arc);
  1929. printf(" (wire\n");
  1930. printf(" (path ");
  1931. printf("%s ", LayerFromId(Wire.layer));
  1932. write_Db2Unit(Wire.arc.width);
  1933. for (int i = 0; i < corner_count; ++i)
  1934. {
  1935. printf(" ");
  1936. write_Db2Unit(arc_approx_corners_x[i]);
  1937. printf(" ");
  1938. write_Db2Unit(arc_approx_corners_y[i]);
  1939. }
  1940. }
  1941. else
  1942. {
  1943. printf(" (wire\n");
  1944. printf(" (path ");
  1945. printf("%s ", LayerFromId(Wire.layer));
  1946. LineDesc(Wire);
  1947. }
  1948. printf(") \n");
  1949. printf(" (net ");
  1950. write_qStr(Net.name);
  1951. if (preprotect)
  1952. printf(") (type protect)\n");
  1953. else
  1954. printf(")\n");
  1955. printf(" )\n");
  1956. }
  1957. }
  1958. Net.polygons(Poly)
  1959. {
  1960. if ((Poly.layer >= 1) && (Poly.layer <= 16))
  1961. {
  1962. printf(" (wire\n");
  1963. printf(" (poly ");
  1964. printf("%s ", LayerFromId(Poly.layer));
  1965. PolygonDesc(Poly);
  1966. printf(") \n");
  1967. printf(" (net ");
  1968. write_qStr(Net.name);
  1969. if (preprotect)
  1970. printf(") (type protect)\n");
  1971. else
  1972. printf(")\n");
  1973. printf(" )\n");
  1974. }
  1975. }
  1976. Net.vias(Via)
  1977. {
  1978. printf(" (via\n ");
  1979. write_qStr(FindViaType(Via.shape[LAYER_TOP], Via.diameter[LAYER_TOP], 0, Via.drill, 0, 0, 0, Via.start, Via.end));
  1980. printf(" ");
  1981. write_Db2Unit(Via.x);
  1982. printf(" ");
  1983. write_Db2Unit(Via.y);
  1984. printf("\n (net ");
  1985. write_qStr(Net.name);
  1986. if (preprotect)
  1987. printf(") (type protect)\n");
  1988. else
  1989. printf(")\n");
  1990. printf(" )\n");
  1991. }
  1992. }
  1993. }
  1994. printf(" )\n");
  1995. }
  1996. void Layers(UL_BOARD p_board)
  1997. //---------------------
  1998. {
  1999. int IsSignal;
  2000. string tmp;
  2001. int i;
  2002. for (i = 0; i < rgw; i++)
  2003. {
  2004. tmp = LayerFromId(Layer_No[i]);
  2005. printf(" (layer ");
  2006. printf("%s ", tmp);
  2007. if (!strchr(LayerFromId(Layer_No[i]),'$'))
  2008. {
  2009. printf(" (type power)");
  2010. printf(" (use_net ");
  2011. printf(strsub(LayerFromId(Layer_No[i]) , 1));
  2012. printf(")");
  2013. }
  2014. else
  2015. {
  2016. printf(" (type signal))\n");
  2017. }
  2018. }
  2019. }
  2020. void Vias(UL_SIGNAL Net)
  2021. //----------------------
  2022. {
  2023. Net.vias(Via)
  2024. {
  2025. printf("(via ");
  2026. write_qStr(FindPadType(Via.shape[LAYER_TOP], Via.diameter[LAYER_TOP], 0, Via.drill, 0, 0, 0));
  2027. printf(" ");
  2028. write_Db2Unit(Via.x);
  2029. printf(" ");
  2030. write_Db2Unit(Via.y);
  2031. printf("\n");
  2032. }
  2033. }
  2034. void CmpInstance(UL_ELEMENT Component)
  2035. //------------------------------------
  2036. {
  2037. printf(" (component ");
  2038. write_qStr(Component.package.name + "$" + Component.package.library); printf(" \n");
  2039. printf(" (place ");
  2040. write_qStr(Component.name);
  2041. printf(" ");
  2042. write_Db2Unit(Component.x);
  2043. printf(" ");
  2044. write_Db2Unit(Component.y);
  2045. printf(" ");
  2046. if (Component.mirror)
  2047. {
  2048. printf("Back");
  2049. }
  2050. else
  2051. {
  2052. printf("Front");
  2053. }
  2054. printf(" ");
  2055. write_Real(Component.angle);
  2056. printf(")\n )\n");
  2057. }
  2058. void Placement()
  2059. //--------------
  2060. {
  2061. board(Board)
  2062. {
  2063. printf(" (placement\n");
  2064. printf(" (place_control (flip_style rotate_first))\n");
  2065. Board.elements(Component)
  2066. {
  2067. CmpInstance(Component);
  2068. }
  2069. printf(" )\n");
  2070. }
  2071. }
  2072. // Creates an keepout, which is made by lines.
  2073. // If p_polygon != null, the wires of p_polygon are processed, else all wires on p_board on layer p_layer
  2074. void make_keepout_shape(int p_layer, string p_layer_name, int p_width)
  2075. {
  2076. if (polygon_corner_count <= 0)
  2077. {
  2078. return;
  2079. }
  2080. for (int i = 0; i < polygon_corner_count; ++i)
  2081. {
  2082. line_handeled[i] = false;
  2083. }
  2084. for (;;)
  2085. {
  2086. int more_parts = combineLines(polyline_endpoint_tolerance);
  2087. if (!more_parts)
  2088. {
  2089. break;
  2090. }
  2091. printf(" (%s", KeepoutType(p_layer));
  2092. p_layer_name = "signal";
  2093. if (p_layer == 39 || p_layer == 41)
  2094. p_layer_name = TopLayer;
  2095. if (p_layer == 40 || p_layer == 42)
  2096. p_layer_name = BotLayer;
  2097. printf("(path ");
  2098. write_Str(p_layer_name);
  2099. printf(" ");
  2100. write_Db2Unit(p_width);
  2101. printf(" ");
  2102. for (i = 0; i< polygon_part_corner_count; ++i)
  2103. {
  2104. write_Db2Unit(polygon_part_corners_x[i]);
  2105. printf(" ");
  2106. write_Db2Unit(polygon_part_corners_y[i]);
  2107. printf(" ");
  2108. }
  2109. printf("))\n");
  2110. }
  2111. }
  2112. void Structure()
  2113. //--------------
  2114. {
  2115. board(Board)
  2116. {
  2117. // print the vias
  2118. printf(" (via");
  2119. for (int i = 0; i < ViaType; i++)
  2120. {
  2121. printf("\n ");
  2122. write_qStr(ViaTypeName[i]);
  2123. }
  2124. if (ViaType == 0)
  2125. {
  2126. // create a default via padstack
  2127. string tmp;
  2128. sprintf(tmp, "ViaDefault$%f", default_drill_size);
  2129. printf("\n "); write_qStr(tmp);
  2130. }
  2131. printf("\n )\n");
  2132. // print the rules
  2133. printf(" (rule (width %f", default_wire_width);
  2134. printf(")(clearance %f", default_clearance);
  2135. printf("))\n");
  2136. if (clearance_wire_pad > 0 && clearance_wire_pad != default_clearance)
  2137. {
  2138. printf(" (rule (clearance %f", clearance_wire_pad);
  2139. printf(" (type wire_pin)))\n");
  2140. }
  2141. if (clearance_wire_smd > 0 && clearance_wire_smd != default_clearance)
  2142. {
  2143. printf(" (rule (clearance %f", clearance_wire_smd);
  2144. printf(" (type wire_smd)))\n");
  2145. }
  2146. if (clearance_wire_via > 0 && clearance_wire_via != default_clearance)
  2147. {
  2148. printf(" (rule (clearance %f", clearance_wire_via);
  2149. printf(" (type wire_via)))\n");
  2150. }
  2151. if (clearance_pad_pad > 0 && clearance_pad_pad != default_clearance)
  2152. {
  2153. printf(" (rule (clearance %f", clearance_pad_pad);
  2154. printf(" (type pin_pin)))\n");
  2155. }
  2156. if (clearance_pad_via > 0 && clearance_pad_via != default_clearance)
  2157. {
  2158. printf(" (rule (clearance %f", clearance_pad_via);
  2159. printf(" (type pin_via)))\n");
  2160. }
  2161. if (clearance_via_via > 0 && clearance_via_via != default_clearance)
  2162. {
  2163. printf(" (rule (clearance %f", clearance_via_via);
  2164. printf(" (type via_via)))\n");
  2165. }
  2166. if (clearance_smd_pad > 0 && clearance_smd_pad != default_clearance)
  2167. {
  2168. printf(" (rule (clearance %f", clearance_smd_pad);
  2169. printf(" (type smd_pin)))\n");
  2170. }
  2171. if (clearance_smd_via > 0 && clearance_smd_via != default_clearance)
  2172. {
  2173. printf(" (rule (clearance %f", clearance_smd_via);
  2174. printf(" (type smd_via)))\n");
  2175. }
  2176. if (clearance_smd_smd > 0 && clearance_smd_smd != default_clearance)
  2177. {
  2178. printf(" (rule (clearance %f", clearance_smd_smd);
  2179. printf(" (type smd_smd)))\n");
  2180. }
  2181. // print the keepouts
  2182. Board.layers(Layer)
  2183. {
  2184. if (Layer.number == LAYER_TOP)
  2185. TopLayer = LayerFromId(Layer.number);
  2186. else
  2187. if (Layer.number == LAYER_BOTTOM)
  2188. BotLayer = LayerFromId(Layer.number);
  2189. if (IsKeepoutLayer(Layer.number))
  2190. {
  2191. string LayerName;
  2192. LayerName = LayerFromId(Layer.number); // Layer.name;
  2193. if (Layer.number == LAYER_DIMENSION)
  2194. LayerName = "signal";
  2195. else
  2196. if (Layer.number == LAYER_TSTOP)
  2197. LayerName = TopLayer;
  2198. else
  2199. LayerName = BotLayer;
  2200. int width = 0;
  2201. polygon_corner_count = 0;
  2202. Board.wires(W)
  2203. {
  2204. if (W.layer == Layer.number)
  2205. {
  2206. polygon_corner_count = process_next_wire(W, polygon_corner_count);
  2207. width = W.width;
  2208. }
  2209. }
  2210. make_keepout_shape(Layer.number, LayerName, width);
  2211. Board.circles(Circle)
  2212. {
  2213. if (Circle.layer == Layer.number)
  2214. {
  2215. printf(" (%s", KeepoutType(Layer.number));
  2216. LayerName = "signal";
  2217. if (Layer.number == 39 || Layer.number == 41)
  2218. LayerName = TopLayer;
  2219. if (Layer.number == 40 || Layer.number == 42)
  2220. LayerName = BotLayer;
  2221. printf("(circ ");
  2222. write_Str(LayerName); printf(" ");
  2223. CircleDesc(Circle);
  2224. printf("))\n");
  2225. }
  2226. }
  2227. Board.rectangles(Rectangle)
  2228. {
  2229. if (Rectangle.layer == Layer.number)
  2230. {
  2231. printf(" (%s", KeepoutType(Layer.number));
  2232. LayerName = "signal";
  2233. if (Layer.number == 39 || Layer.number == 41)
  2234. LayerName = TopLayer;
  2235. if (Layer.number == 40 || Layer.number == 42)
  2236. LayerName = BotLayer;
  2237. printf("(rect ");
  2238. write_Str(LayerName); printf(" ");
  2239. RectangleDesc(Rectangle);
  2240. printf("))\n");
  2241. }
  2242. }
  2243. Board.polygons(Polygon)
  2244. {
  2245. if (Polygon.layer==Layer.number)
  2246. {
  2247. LayerName = TopLayer;
  2248. if (Layer.number == 40 || Layer.number == 42)
  2249. LayerName = BotLayer;
  2250. Polygon.wires(W)
  2251. {
  2252. polygon_corner_count = process_next_wire(W, polygon_corner_count);
  2253. width = W.width;
  2254. }
  2255. make_keepout_shape(Layer.number, LayerName, width);
  2256. }
  2257. }
  2258. }
  2259. }
  2260. Board.holes(Hole)
  2261. {
  2262. printf(" (keepout (circ signal ");
  2263. write_Db2Unit(Hole.diameter[LAYER_TSTOP]);
  2264. printf(" ");
  2265. write_Db2Unit(Hole.x);
  2266. printf(" ");
  2267. write_Db2Unit(Hole.y);
  2268. printf("))\n");
  2269. }
  2270. }
  2271. }
  2272. real get_drufile_value(string p_line, string p_separator)
  2273. {
  2274. return Unit2Value( strtod(strsub(p_line, strrstr(p_line, p_separator)+2, strlen(p_line))), strsub(p_line, strlen(p_line)-1, 1) );
  2275. }
  2276. board(Board)
  2277. //----------
  2278. {
  2279. string DruFile = filesetext(Board.name, ".dru");
  2280. if(argv[1]!="f")
  2281. {
  2282. string ScrFile = filesetext(Board.name, "_gen_drufile.scr");
  2283. // Because the dru_file cannot be read from an ulp-file,
  2284. // a script file is created, which creates the dru_file
  2285. // and then calls this ulp-file again with the option f.
  2286. output(ScrFile, "wtD")
  2287. {
  2288. string tmp;
  2289. tmp = filename(argv[0]);
  2290. printf("DRC SAVE '%s';\n", DruFile);
  2291. printf("RUN %s f;", tmp);
  2292. exit("script '" + ScrFile + "';");
  2293. }
  2294. }
  2295. clearance_wire_pad = clearance_wire_smd = clearance_wire_via = clearance_pad_pad = clearance_pad_via
  2296. = clearance_via_via = clearance_smd_pad = clearance_smd_via
  2297. = clearance_smd_smd = -1;
  2298. Units = Board.grid.unit;
  2299. string default_name = filesetext(Board.name, ".dsn");
  2300. string Filename = dlgFileSave("Eagle to DSN Format", default_name, "*.dsn");
  2301. if (filesize(DruFile))
  2302. {
  2303. string Lines[];
  2304. int nLines = fileread(Lines, DruFile);
  2305. string separator = "= ";
  2306. int line_no;
  2307. real min_via_outer;
  2308. for (line_no == 0; line_no < nLines; ++line_no)
  2309. {
  2310. string curr_line = Lines[line_no];
  2311. if (strstr(curr_line, "layerSetup") == 0)
  2312. {
  2313. layer_setup = strsub( curr_line, strrstr(curr_line, separator)+2, strlen(curr_line) );
  2314. }
  2315. else if (strstr(curr_line, "msWidth") == 0)
  2316. {
  2317. default_wire_width = get_drufile_value(curr_line, separator);
  2318. }
  2319. else if (strstr(curr_line, "mdWireWire") == 0)
  2320. {
  2321. default_clearance = get_drufile_value(curr_line, separator);
  2322. }
  2323. else if (strstr(curr_line, "mdWirePad") == 0)
  2324. {
  2325. clearance_wire_pad = get_drufile_value(curr_line, separator);
  2326. clearance_wire_smd = clearance_wire_pad;
  2327. }
  2328. else if (strstr(curr_line, "mdWireVia") == 0)
  2329. {
  2330. clearance_wire_via = get_drufile_value(curr_line, separator);
  2331. }
  2332. else if (strstr(curr_line, "mdPadPad") == 0)
  2333. {
  2334. clearance_pad_pad = get_drufile_value(curr_line, separator);
  2335. }
  2336. else if (strstr(curr_line, "mdPadVia") == 0)
  2337. {
  2338. clearance_pad_via = get_drufile_value(curr_line, separator);
  2339. }
  2340. else if (strstr(curr_line, "mdViaViaSameLayer") == 0)
  2341. {
  2342. ; // not implemented
  2343. }
  2344. else if (strstr(curr_line, "mdViaVia") == 0)
  2345. {
  2346. clearance_via_via = get_drufile_value(curr_line, separator);
  2347. }
  2348. else if (strstr(curr_line, "mdSmdPad") == 0)
  2349. {
  2350. clearance_smd_pad = get_drufile_value(curr_line, separator);
  2351. }
  2352. else if (strstr(curr_line, "mdSmdVia") == 0)
  2353. {
  2354. clearance_smd_via = get_drufile_value(curr_line, separator);
  2355. }
  2356. else if (strstr(curr_line, "mdSmdSmd") == 0)
  2357. {
  2358. clearance_smd_smd = get_drufile_value(curr_line, separator);
  2359. }
  2360. else if (strstr(curr_line, "msDrill") == 0)
  2361. {
  2362. default_drill_size = get_drufile_value(curr_line, separator);
  2363. }
  2364. else if (strstr(curr_line, "rvPadInner") == 0)
  2365. {
  2366. rv_pad_inner = get_drufile_value(curr_line, separator);
  2367. }
  2368. else if (strstr(curr_line, "rlMaxPadInner") == 0)
  2369. {
  2370. max_pad_inner = get_drufile_value(curr_line, separator);
  2371. }
  2372. else if (strstr(curr_line, "rlMinViaOuter") == 0)
  2373. {
  2374. min_via_outer = get_drufile_value(curr_line, separator);
  2375. }
  2376. else if (strstr(curr_line, "rlMinViaInner") == 0)
  2377. {
  2378. min_via_inner = get_drufile_value(curr_line, separator);
  2379. }
  2380. else if (strstr(curr_line, "rlMinPadInner") == 0)
  2381. {
  2382. min_pad_inner = get_drufile_value(curr_line, separator);
  2383. }
  2384. }
  2385. default_via_size = default_drill_size + 2 * min_via_outer;
  2386. }
  2387. else
  2388. {
  2389. string Tmp;
  2390. sprintf(Tmp, "%s%s%s", "File ", DruFile, " not exists!");
  2391. if (dlgMessageBox(Tmp, "&Close") == 0)
  2392. exit(0);
  2393. }
  2394. if (strlen(Filename))
  2395. {
  2396. rgw=read_layer_setup(Board);
  2397. rgw=write_ViaType(Board, rgw);
  2398. rgw=find_layer(Board, rgw);
  2399. output(Filename)
  2400. {
  2401. Header();
  2402. PadTypes();
  2403. printf(" (structure\n");
  2404. Layers(Board);
  2405. board_dimension();
  2406. MakeBoundary();
  2407. Structure();
  2408. printf(" (control\n (via_at_smd on)\n )\n");
  2409. printf(" )\n");
  2410. Placement();
  2411. Images();
  2412. Network();
  2413. Wiring();
  2414. printf(")");
  2415. }
  2416. }
  2417. }