UNPKG

@typecad/typecad

Version:

🤖programmatically 💥create 🛰️hardware

1 lines 11.4 kB
import a18_0x2c5607 from'chalk';import{generateUuid}from'./pcb_utils';function a18_0x3fff52(_0x508d3d,_0x1e853d){return a18_0x13c7(_0x1e853d-0x24a,_0x508d3d);}function a18_0x13c7(_0x43ff51,_0x13c793){const _0x47610c=a18_0x43ff();return a18_0x13c7=function(_0x368fae,_0x5a9dda){_0x368fae=_0x368fae-0x0;let _0x5c9019=_0x47610c[_0x368fae];return _0x5c9019;},a18_0x13c7(_0x43ff51,_0x13c793);}function a18_0x43ff(){const _0x30d874=['currentWidth','lastOperationSuccessful','locked','net','_deferStaging','powerInfo','_powerInfo','copper_thickness','line','Previous\x20track\x20operation\x20failed','currentPosition','maxTempRise','mm\x20is\x20too\x20narrow\x20for\x20','.\x20Minimum\x20width\x20should\x20be\x20','mm.','red','[TrackBuilder]\x20ERROR:\x20','_net','debug',')\x20->\x20(','),\x20layer=',',\x20net=','push','track','strokeWidth','layer','length','match','pcb.ts','node_modules','\x5cdist\x5c','trim','log','\x20\x20-\x20Annular\x20ring:\x20','via','getCallSite','\x20(called\x20from\x20','\x27from()\x27\x20must\x20be\x20called\x20before\x20\x27via()\x27','calculateMinViaSize','thickness','drill','pcb','viaData','layers','F.Cu','includes','find','currentLayer','warn'];a18_0x43ff=function(){return _0x30d874;};return a18_0x43ff();}export class TrackBuilder{constructor(_0x4efc44,_0x5a47db){this['currentLayer']='F.Cu',this[_0x534098(-0x25e,-0x268)]=0.2,this['elements']=[],this[_0x534098(-0x27c,-0x267)]=!![],this['_locked']=![],this['_deferStaging']=![],this['_debug']=![],this['pcb']=_0x4efc44;function _0x534098(_0x8e66cc,_0x2f2b88){return a18_0x13c7(_0x2f2b88- -0x268,_0x8e66cc);}this['_locked']=_0x5a47db?.[_0x534098(-0x27e,-0x266)]??![],this['_debug']=_0x5a47db?.['debug']??![],this['_net']=_0x5a47db?.[_0x534098(-0x257,-0x265)],this[_0x534098(-0x27c,-0x264)]=_0x5a47db?.['deferStaging']??![];}['from'](_0x33f54b,_0x555d78,_0x18d349){if(!this['lastOperationSuccessful'])return this;this['currentPosition']={'x':_0x33f54b['x'],'y':_0x33f54b['y']},this['currentLayer']=_0x555d78??this['currentLayer'];function _0x1ba3bc(_0x2f5eab,_0x4b25c2){return a18_0x13c7(_0x4b25c2- -0x394,_0x2f5eab);}return this['currentWidth']=_0x18d349??this[_0x1ba3bc(-0x3a4,-0x394)],this;}[a18_0x3fff52(0x263,0x24f)](_0x4a0f12){this[_0x5a1212(-0x2c4,-0x2d4)]={..._0x4a0f12,'maxTempRise':_0x4a0f12['maxTempRise']??0xa,'thickness':_0x4a0f12['thickness']??this['pcb']['copper_thickness']};function _0x5a1212(_0x1287b8,_0x27229c){return a18_0x13c7(_0x27229c- -0x2da,_0x1287b8);}return this;}['calculateMinTrackWidth'](_0x4ebad7,_0x2edbef,_0x337c05,_0x5b2c19){const _0x3afa03=_0x5b2c19??this['pcb'][_0x358c50(-0x273,-0x26a)],_0x3aea41=_0x2edbef==='F.Cu'||_0x2edbef==='B.Cu'?0.048:0.024,_0x140ecd=0.44,_0x10723d=0.725,_0x1171e0=1.378,_0xae9594=_0x3afa03/0x23,_0x50bee6=Math['pow'](_0x4ebad7/(_0x3aea41*Math['pow'](_0x337c05,_0x140ecd)),0x1/_0x10723d),_0x202042=_0x50bee6/(_0xae9594*_0x1171e0);function _0x358c50(_0x2268d5,_0x404b22){return a18_0x13c7(_0x2268d5- -0x27a,_0x404b22);}const _0x1ca10e=_0x202042*0.0254;return _0x1ca10e;}['to'](_0x45cf27){if(!this['lastOperationSuccessful']){const _0x4e3af8=this['getCallSite'](),_0x580ebf=_0x4e3af8?'\x20(called\x20from\x20'+_0x4e3af8['file']+':'+_0x4e3af8[_0x5ef87c(-0x1e6,-0x1d5)]+')':'';throw new Error(_0x5ef87c(-0x1e5,-0x1da)+_0x580ebf);}if(!this[_0x5ef87c(-0x1e4,-0x1f1)]){const _0x4727a0=this['getCallSite'](),_0x547c4d=_0x4727a0?'\x20(called\x20from\x20'+_0x4727a0['file']+':'+_0x4727a0['line']+')':'';throw new Error('\x27from()\x27\x20must\x20be\x20called\x20before\x20\x27to()\x27'+_0x547c4d);}const _0x12a7a7=_0x45cf27['layer']??this['currentLayer'],_0x4677a6=_0x45cf27['width']??this[_0x5ef87c(-0x1ee,-0x1f5)],_0x1874af=_0x45cf27['x']-this[_0x5ef87c(-0x1e4,-0x1d9)]['x'],_0x30cf58=_0x45cf27['y']-this['currentPosition']['y'],_0x209a44=Math['sqrt'](_0x1874af*_0x1874af+_0x30cf58*_0x30cf58);if(this['_powerInfo']){const _0x14d308=this['calculateMinTrackWidth'](this['_powerInfo']['current'],_0x12a7a7,this['_powerInfo'][_0x5ef87c(-0x1e3,-0x1dc)],this[_0x5ef87c(-0x1e8,-0x1da)]['thickness']),_0x2c408d=Math['round'](_0x14d308*0x3e8)/0x3e8,_0x275602=Math['round'](_0x4677a6*0x3e8)/0x3e8;if(_0x275602<_0x2c408d){const _0x8b5da2=this['getCallSite'](),_0xe64652=_0x8b5da2?'\x20(called\x20from\x20'+_0x8b5da2['file']+':'+_0x8b5da2['line']+')':'',_0x162ea8='Track\x20width\x20'+_0x275602+_0x5ef87c(-0x1e2,-0x1d9)+this['_powerInfo']['current']+'A\x20current\x20on\x20'+_0x12a7a7+_0x5ef87c(-0x1e1,-0x1d5)+_0x2c408d['toFixed'](0x3)+_0x5ef87c(-0x1e0,-0x1d7)+_0xe64652;console['error'](a18_0x2c5607[_0x5ef87c(-0x1df,-0x1df)](_0x5ef87c(-0x1de,-0x1df)+_0x162ea8));}}let _0x386878,_0x3d70b8=null;if(!this[_0x5ef87c(-0x1ea,-0x1f4)]){_0x386878=this['pcb']['_track'](this[_0x5ef87c(-0x1e4,-0x1e6)],{'x':_0x45cf27['x'],'y':_0x45cf27['y']},_0x4677a6,_0x12a7a7,this['_locked'],undefined,this[_0x5ef87c(-0x1dd,-0x1e9)]);if(this['_debug'])try{const _0x3c101b=require('../logging');_0x3c101b[_0x5ef87c(-0x1dc,-0x1e3)]('[TrackBuilder][DEBUG]\x20Staged\x20track:\x20uuid='+_0x386878+',\x20from=('+this['currentPosition']['x']+','+this['currentPosition']['y']+_0x5ef87c(-0x1db,-0x1d0)+_0x45cf27['x']+','+_0x45cf27['y']+_0x5ef87c(-0x1da,-0x1dd)+_0x12a7a7+',\x20width='+_0x4677a6+_0x5ef87c(-0x1d9,-0x1d6)+this['_net']);}catch(_0x56b65c){}_0x3d70b8=this['pcb']['_getTrackData'](_0x386878);}else _0x386878=generateUuid();this['elements'][_0x5ef87c(-0x1d8,-0x1e2)]({'type':_0x5ef87c(-0x1d7,-0x1e5),'uuid':_0x386878,'details':{'start':{...this[_0x5ef87c(-0x1e4,-0x1cd)]},'end':{'x':_0x45cf27['x'],'y':_0x45cf27['y']},'width':_0x3d70b8?_0x3d70b8[_0x5ef87c(-0x1d6,-0x1ed)]:_0x4677a6,'layer':_0x3d70b8?_0x3d70b8[_0x5ef87c(-0x1d5,-0x1da)]:_0x12a7a7,'locked':_0x3d70b8?.[_0x5ef87c(-0x1ec,-0x1da)]??![],'powerInfo':this['_powerInfo']}}),this[_0x5ef87c(-0x1e4,-0x1f0)]={'x':_0x45cf27['x'],'y':_0x45cf27['y']};function _0x5ef87c(_0x532361,_0x313783){return a18_0x13c7(_0x532361- -0x1ee,_0x313783);}return this['currentLayer']=_0x12a7a7,this['currentWidth']=_0x4677a6,this;}['getCallSite'](){function _0x4a4230(_0x3f1bd4,_0x3a3b14){return a18_0x13c7(_0x3a3b14- -0x120,_0x3f1bd4);}const _0x44c575=new Error()['stack'];if(!_0x44c575)return null;const _0x235224=_0x44c575['split']('\x0a');for(let _0x2e4ca0=0x3;_0x2e4ca0<_0x235224[_0x4a4230(-0xf7,-0x106)];_0x2e4ca0++){const _0x2b0951=_0x235224[_0x2e4ca0];if(_0x2b0951){const _0x5e0bea=_0x2b0951[_0x4a4230(-0xf0,-0x105)](/at\s+(?:(.+?)\s+\()?(.+):(\d+):(\d+)\)?/);if(_0x5e0bea){const _0x19f56f=_0x5e0bea[0x2];if(!_0x19f56f['includes']('pcb_track_builder')&&!_0x19f56f['includes'](_0x4a4230(-0xf8,-0x104))&&!_0x19f56f['includes']('pcb.js')&&!_0x19f56f['includes'](_0x4a4230(-0x114,-0x103))&&!_0x19f56f['includes'](_0x4a4230(-0xef,-0x102))&&!_0x19f56f['includes']('/dist/'))return{'function':_0x5e0bea[0x1]?.['trim']()||'anonymous','file':_0x19f56f,'line':parseInt(_0x5e0bea[0x3],0xa),'column':parseInt(_0x5e0bea[0x4],0xa)};}}}if(_0x235224[0x2]){const _0x56640f=_0x235224[0x2]['match'](/at\s+(?:(.+?)\s+\()?(.+):(\d+):(\d+)\)?/);if(_0x56640f)return{'function':_0x56640f[0x1]?.[_0x4a4230(-0xeb,-0x101)]()||'anonymous','file':_0x56640f[0x2],'line':parseInt(_0x56640f[0x3],0xa),'column':parseInt(_0x56640f[0x4],0xa)};}return null;}['calculateMinViaSize'](_0x1769f,_0x52f92f,_0x1592c8=![]){const _0x502013=_0x52f92f??this['pcb']['copper_thickness'];function _0x42c046(_0x1d7cba,_0x1460f1){return a18_0x13c7(_0x1460f1-0x14c,_0x1d7cba);}const _0x52cbaf=0.048,_0x2c207d=0.44,_0x8c9eee=0.725,_0xaae600=1.378,_0x258cd6=_0x502013/0x23,_0x1ead86=Math['pow'](_0x1769f/(_0x52cbaf*Math['pow'](0xa,_0x2c207d)),0x1/_0x8c9eee),_0x1f6fe2=0x2*Math['sqrt'](_0x1ead86/Math['PI']),_0x187b0a=_0x1f6fe2*0.0254,_0x182710=0.1,_0x50af98=_0x187b0a+0x2*_0x182710;return _0x1592c8&&(console['log']('Via\x20calculation\x20for\x20'+_0x1769f+'A:'),console[_0x42c046(0x173,0x16c)]('\x20\x20-\x20Drill:\x20'+_0x187b0a['toFixed'](0x3)+'mm'),console['log'](_0x42c046(0x17a,0x16d)+_0x182710+'mm'),console[_0x42c046(0x15c,0x16c)]('\x20\x20-\x20Total\x20size:\x20'+_0x50af98['toFixed'](0x3)+'mm')),{'size':_0x50af98,'drill':_0x187b0a};}[a18_0x3fff52(0x271,0x26c)](_0x3668e9={}){if(!this['lastOperationSuccessful']){const _0x154b78=this[_0x3135c0(-0x2d8,-0x2d9)](),_0xddb90b=_0x154b78?'\x20(called\x20from\x20'+_0x154b78['file']+':'+_0x154b78[_0x3135c0(-0x309,-0x2f4)]+')':'';throw new Error('Previous\x20track\x20operation\x20failed'+_0xddb90b);}if(!this['currentPosition']){const _0xc24aba=this['getCallSite'](),_0xcd6f9c=_0xc24aba?_0x3135c0(-0x2d1,-0x2d8)+_0xc24aba['file']+':'+_0xc24aba['line']+')':'';throw new Error(_0x3135c0(-0x2c9,-0x2d7)+_0xcd6f9c);}if(_0x3668e9['powerInfo']){const _0x5c96c8=this[_0x3135c0(-0x2df,-0x2d6)](_0x3668e9['powerInfo']['current'],_0x3668e9['powerInfo'][_0x3135c0(-0x2c6,-0x2d5)]??this['pcb']['copper_thickness'],this['_debug']),_0x5c84a8=Math['round'](_0x5c96c8['size']*0x3e8)/0x3e8,_0x2b630f=Math['round'](_0x5c96c8['drill']*0x3e8)/0x3e8;(!_0x3668e9['size']||_0x3668e9['size']<_0x5c84a8)&&(_0x3668e9['size']=_0x5c84a8),(!_0x3668e9[_0x3135c0(-0x2dc,-0x2d4)]||_0x3668e9[_0x3135c0(-0x2d9,-0x2d4)]<_0x2b630f)&&(_0x3668e9['drill']=_0x2b630f);}const _0x405bc6=this[_0x3135c0(-0x2d6,-0x2d3)]['via']({'at':this['currentPosition'],'size':_0x3668e9['size'],'drill':_0x3668e9['drill']});_0x405bc6[_0x3135c0(-0x2de,-0x2d3)]['x']=this['currentPosition']['x'];function _0x3135c0(_0x302461,_0x4d8aaf){return a18_0x13c7(_0x4d8aaf- -0x2fc,_0x302461);}_0x405bc6['pcb']['y']=this['currentPosition']['y'];if(_0x405bc6['viaData']){if(_0x3668e9['layers']&&_0x3668e9['layers'][_0x3135c0(-0x2e0,-0x2e2)]>0x0)_0x405bc6[_0x3135c0(-0x2d2,-0x2d2)][_0x3135c0(-0x2e7,-0x2d1)]=_0x3668e9['layers'];else{let _0x5c652b='B.Cu';if(this['currentLayer']==='B.Cu')_0x5c652b=_0x3135c0(-0x2cd,-0x2d0);else this['currentLayer']!=='F.Cu'&&(_0x5c652b='F.Cu');_0x405bc6[_0x3135c0(-0x2bb,-0x2d2)][_0x3135c0(-0x2cc,-0x2d1)]=[this['currentLayer'],_0x5c652b],_0x405bc6['viaData']['layers'][0x0]===_0x405bc6['viaData']['layers'][0x1]&&(_0x405bc6['viaData']['layers']=['F.Cu','B.Cu']);}_0x3668e9[_0x3135c0(-0x2ed,-0x2f9)]&&(_0x405bc6[_0x3135c0(-0x2da,-0x2d2)]['net']=_0x3668e9['net']);this['pcb']['place'](_0x405bc6),this['elements']['push']({'type':'via','uuid':_0x405bc6['uuid'],'details':{..._0x405bc6['viaData'],'powerInfo':_0x3668e9['powerInfo']}});const _0x47c935=_0x405bc6['viaData']['layers'];_0x47c935['length']>0x0&&(_0x47c935[_0x3135c0(-0x2cb,-0x2cf)](this['currentLayer'])&&_0x47c935['length']>0x1?this['currentLayer']=_0x47c935[_0x3135c0(-0x2e1,-0x2ce)](_0x4ffe00=>_0x4ffe00!==this[_0x3135c0(-0x2be,-0x2cd)])||_0x47c935[0x0]:this['currentLayer']=_0x47c935[0x0]);}else{const _0x263322=this['getCallSite'](),_0x6542fe=_0x263322?'\x20(called\x20from\x20'+_0x263322['file']+':'+_0x263322['line']+')':'';console[_0x3135c0(-0x2dc,-0x2cc)](a18_0x2c5607['yellow']('[TrackBuilder]\x20WARN:\x20\x27via()\x27\x20creation\x20on\x20PCB\x20failed\x20or\x20returned\x20unexpected\x20structure.\x20Via\x20not\x20added\x20to\x20track\x20elements.'+_0x6542fe)),this['lastOperationSuccessful']=![];}return this;}['getElements'](){if(!this['lastOperationSuccessful']){const _0x5b4dc=this['getCallSite'](),_0xb76b31=_0x5b4dc?'\x20(called\x20from\x20'+_0x5b4dc['file']+':'+_0x5b4dc['line']+')':'';console['warn'](a18_0x2c5607['yellow']('[TrackBuilder]\x20WARN:\x20getElements()\x20called\x20on\x20a\x20builder\x20chain\x20that\x20had\x20a\x20failing\x20operation.\x20Results\x20might\x20be\x20incomplete.'+_0xb76b31));}return this['elements'];}}