EDA365电子工程师网

标题: 【分享源代碼】比較兩個Board file符號差異工具/比较两份PCB文件的零件差异 [打印本页]

作者: XYX365    时间: 2016-2-17 09:52
标题: 【分享源代碼】比較兩個Board file符號差異工具/比较两份PCB文件的零件差异
本帖最后由 XYX365 于 2016-2-17 15:17 编辑

【分享源代碼】比較兩個Board file符號差異工具/比较两份PCB文件的零件差异

;
;FileName:        
;Load:                load("fCS.il")
;Command:        cs
;
;功能:比較兩個PCB的Symbols差異
;使用方法:
;        1.開起一個新的brd
;        2.執行cs
;        3.會提示讀取一個舊的brd
;        4.選擇檔案後,再選擇開啟之後就開始比較,直到輸出結果
;
;; 程式特色:
;        1.源代碼分享,讓所有人都可以依照自己的方式加入其他功能,
;                例如加入輸出檔案為excel檔
;                或是其他功能,自己想像.

[attach]108983[/attach]


[attach]108974[/attach]

[hide=d180]
  1. ;
  2. ;FileName:        
  3. ;Load:                load("fCS.il")
  4. ;Command:        cs
  5. ;
  6. ;功能:比較兩個PCB的Symbols差異
  7. ;使用方法:
  8. ;        1.開起一個新的brd
  9. ;        2.執行cs
  10. ;        3.會提示讀取一個舊的brd
  11. ;        4.選擇檔案後,再選擇開啟之後就開始比較,直到輸出結果
  12. ;
  13. ;; 程式特色:
  14. ;        1.源代碼分享,讓所有人都可以依照自己的方式加入其他功能,
  15. ;                例如加入輸出檔案為excel檔
  16. ;                或是其他功能,自己想像.
  17. axlCmdRegister("cs" 'fnCompareSymbol ?cmdType "general")

  18. procedure(fnCompareSymbol()
  19.         prog((tBrdPathNew tBrdOld tBrdPathOld pPort tCmd tNewFile tOldFile lNewList lOldList)
  20.                
  21.                 ;取新舊brd檔案名稱
  22.                 axlMsgPut("M-Please select a brd file:")
  23.                 tBrdPathOld = axlDMFileBrowse("ALLEGRO_BRD" nil ?title "Compare Symbol" ?optFilters "Board file(*.brd)|*.brd|") ;瀏覽舊的brd
  24.                 unless(tBrdPathOld
  25.                         return(nil)
  26.                 )
  27.                 tBrdNew = axlCurrentDesign() ;目前所開啟的brd
  28.                 tBrdPathNew = strcat(simplifyFilename(tBrdNew) ".brd")
  29.                 ;要導出比較的資料
  30.                 fnCSExtractaData(tBrdPathNew tBrdPathOld)
  31.                
  32.                 ;讀取新brd所導出的資料Comp
  33.                 tNewFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathNew)) "_comp.txt")
  34.                 lNewCompList = fnCSReadFile(tNewFile)
  35.                 deleteFile(tNewFile)
  36.                                 
  37.                 ;讀取舊brd所導出的資料Comp
  38.                 tOldFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathOld)) "_comp.txt")
  39.                 lOldCompList = fnCSReadFile(tOldFile)
  40.                 deleteFile(tOldFile)
  41.                
  42.                 ;讀取新brd所導出的資料Sym
  43.                 tNewFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathNew)) "_sym.txt")
  44.                 lNewSymList = fnCSReadFile(tNewFile)
  45.                 deleteFile(tNewFile)
  46.                                 
  47.                 ;讀取舊brd所導出的資料Sym
  48.                 tOldFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathOld)) "_sym.txt")
  49.                 lOldSymList = fnCSReadFile(tOldFile)
  50.                 deleteFile(tOldFile)
  51.                
  52.                 ;比較新舊brd差異並輸出到檔案
  53.                 fnCSCompareData(tBrdPathNew tBrdPathOld lNewCompList lOldCompList lNewSymList lOldSymList)
  54.         )
  55. )
  56. procedure(fnCSReadFile(tFile)
  57.         let((pPort tLine lLines)
  58.                 if(tFile && isFile(tFile) then
  59.                         pPort = infile(tFile)
  60.                         rexCompile(".$")
  61.                         for(x 1 2 ;讀取前面兩行,這兩行不會處理
  62.                                 gets(tLine pPort)
  63.                         )
  64.                         while(gets(tLine pPort)
  65.                                 unless(blankstrp(tLine)
  66.                                         lLines = cons(rexReplace(tLine "" 0) lLines)
  67.                                 )
  68.                         )
  69.                         close(pPort)
  70.                         sort(lLines nil) ;排序所有資料
  71.                 else
  72.                         axlUIConfirm("E- Misssing file.")
  73.                 )
  74.         )
  75. )
  76. procedure(fnCSCompareData(tBrdPathNew tBrdPathOld lNewCompList lOldCompList lNewSymList lOldSymList)
  77.         let((oNewComp oOldComp oNewSym oOldSym lLines tRefDes tPartNum tValue tTol tDeviceType tXY tIsMirrored
  78.                 tRotation tMode tSymName)
  79.                 ;將Comp的Data存放到Table
  80.                 for(x 0 1
  81.                         if(zerop(x) then
  82.                                 oNewComp = makeTable("NEWCOMPDATA" nil)
  83.                         else
  84.                                 oOldComp = makeTable("OLDCOMPDATA" nil)
  85.                         )
  86.                         rexCompile("!!")
  87.                         foreach(tLine nth(x list(lNewCompList lOldCompList))
  88.                                 tLine = rexReplace(tLine "! !" 0)
  89.                                 lLines = parseString(tLine "!")
  90.                                 
  91.                                 tRefDes = cadr(lLines)
  92.                                 tPartNum = caddr(lLines)
  93.                                 tValue = nth(3 lLines)
  94.                                 tTol = nth(4 lLines)
  95.                                 tDeviceType = nth(6 lLines)
  96.                                                                
  97.                                 if(zerop(x) then
  98.                                         oNewComp[tRefDes] = list(tPartNum tValue tTol tDeviceType)
  99.                                 else
  100.                                         oOldComp[tRefDes] = list(tPartNum tValue tTol tDeviceType)
  101.                                 )
  102.                         )
  103.                 )
  104.                
  105.                 ;將Sym的Data存放到Table
  106.                 for(x 0 1
  107.                         if(zerop(x) then
  108.                                 oNewSym = makeTable("NEWSYMDATA" nil)
  109.                         else
  110.                                 oOldSym = makeTable("OLDSYMDATA" nil)
  111.                         )
  112.                         rexCompile("!!")
  113.                         foreach(tLine nth(x list(lNewSymList lOldSymList))
  114.                                 tLine = rexReplace(tLine "! !" 0)
  115.                                 lLines = parseString(tLine "!")
  116.                                 
  117.                                 tRefDes = cadr(lLines)
  118.                                 tXY = strcat("(" caddr(lLines) "," nth(3 lLines) ")")
  119.                                 tIsMirrored = nth(4 lLines)
  120.                                 if(tIsMirrored == "YES" then
  121.                                         tIsMirrored = "B"
  122.                                 else
  123.                                         tIsMirrored = "T"
  124.                                 )
  125.                                 tRotation = sprintf(nil "%.2f" readstring(nth(5 lLines)))
  126.                                 tMode = nth(6 lLines)
  127.                                 tSymName = nth(7 lLines)
  128.                                 
  129.                                 if(zerop(x) then
  130.                                         tPartNum = car(oNewComp[tRefDes])
  131.                                         unless(tPartNum
  132.                                                 tPartNum = ""
  133.                                         )
  134.                                         oNewSym[tRefDes] = list(tXY tIsMirrored tRotation tMode tSymName tPartNum)
  135.                                 else
  136.                                         tPartNum = car(oOldComp[tRefDes])
  137.                                         unless(tPartNum
  138.                                                 tPartNum = ""
  139.                                         )
  140.                                         oOldSym[tRefDes] = list(tXY tIsMirrored tRotation tMode tSymName tPartNum)
  141.                                 )
  142.                         )
  143.                 )
  144.                 fnCSOutputData(tBrdPathNew tBrdPathOld oNewComp oOldComp oNewSym oOldSym)
  145.         )
  146. )
  147. procedure(fnCSOutputData(tBrdPathNew tBrdPathOld oNewComp oOldComp oNewSym oOldSym)
  148.         let((lAdded lDeleted lChanged tFile pPort xItem tOne)
  149.                 ;判斷是否有新增資料
  150.                 foreach(tRefdes oNewSym
  151.                         unless(oOldSym[tRefdes]
  152.                                 lAdded = cons(tRefdes lAdded)
  153.                         )
  154.                 )
  155.                 lAdded = sort(lAdded nil)
  156.                
  157.                 ;判斷是否有減少資料
  158.                 foreach(tRefdes oOldSym
  159.                         unless(oNewSym[tRefdes]
  160.                                 lDeleted = cons(tRefdes lDeleted)
  161.                         )
  162.                 )
  163.                 lDeleted = sort(lDeleted nil)
  164.                
  165.                 ;判斷是否有改變資料
  166.                 foreach(tRefdes oNewSym
  167.                         when(oOldSym[tRefdes]
  168.                                 unless(oNewSym[tRefdes] == oOldSym[tRefdes]
  169.                                         lChanged = cons(tRefdes lChanged)
  170.                                 )
  171.                         )
  172.                 )
  173.                 lChanged = sort(lChanged nil)
  174.                
  175.                 ;輸出資料到檔案
  176.                 drain()
  177.                 tFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathNew)) "_OldNew.rpt")
  178.                 pPort = outfile(tFile)
  179.                 ;檔案顯示的標題
  180.                 fprintf(pPort "Compare Symbol report\n")
  181.                 fprintf(pPort "Date: %s\n" getCurrentTime())
  182.                 fprintf(pPort "%s.brd [Old]\n" cadr(axlDMFileParts(tBrdPathOld)))
  183.                 fprintf(pPort "%s.brd [New]\n\n" cadr(axlDMFileParts(tBrdPathNew)))
  184.                                                                
  185.                 fprintf(pPort "%s\n" "===============================================================================================================================")
  186.                 fprintf(pPort "%4s %-5s %-8s %20s %-20s %-4s %6s %-25s %-17s %-40s\n"  "#" "Brd" "Type" "Refdes" strcat("XY(" car(axlDBGetDesignUnits()) ")") "Side" "Rot" "Symtype" "Part number" "Device type")
  187.                 fprintf(pPort "%s\n" "===============================================================================================================================")
  188.                 xItem = 1
  189.                 ;輸出新增的資料到檔案
  190.                 foreach(tOne lAdded
  191.                         fprintf(pPort "%4d %-5s %-8s %20s %-20s %-4s %6s %-25s %-17s %-40s\n" xItem "[New]" "Added:" tOne car(oNewSym[tOne]) cadr(oNewSym[tOne]) caddr(oNewSym[tOne]) nth(4 oNewSym[tOne]) nth(5 oNewSym[tOne]) _ssfnEnsureNonNilValue(nth(3 oNewComp[tOne])))
  192.                         xItem++
  193.                 )
  194.                 fprintf(pPort "\n")
  195.                 ;輸出減少的資料到檔案
  196.                 xItem = 1
  197.                 foreach(tOne lDeleted
  198.                         fprintf(pPort "%4d %-5s %-8s %20s %-20s %-4s %6s %-25s %-17s %-40s\n" xItem "[Old]" "Deleted:" tOne car(oOldSym[tOne]) cadr(oOldSym[tOne]) caddr(oOldSym[tOne]) nth(4 oOldSym[tOne]) nth(5 oOldSym[tOne]) _ssfnEnsureNonNilValue(nth(3 oOldComp[tOne])))
  199.                         xItem++
  200.                 )
  201.                 fprintf(pPort "\n")
  202.                 ;輸出變更的資料到檔案
  203.                 xItem = 1
  204.                 foreach(tOne lChanged
  205.                         fprintf(pPort "%4d %-5s %-8s %20s %-20s %-4s %6s %-25s %-17s %-40s\n" xItem "[New]" "Changed:" tOne car(oNewSym[tOne]) cadr(oNewSym[tOne]) caddr(oNewSym[tOne]) nth(4 oNewSym[tOne]) nth(5 oNewSym[tOne]) _ssfnEnsureNonNilValue(nth(3 oNewComp[tOne])))
  206.                         fprintf(pPort "%4d %-5s %-8s %20s %-20s %-4s %6s %-25s %-17s %-40s\n" xItem "[Old]" "Changed:" tOne car(oOldSym[tOne]) cadr(oOldSym[tOne]) caddr(oOldSym[tOne]) nth(4 oOldSym[tOne]) nth(5 oOldSym[tOne]) _ssfnEnsureNonNilValue(nth(3 oOldComp[tOne])))
  207.                         fprintf(pPort "\n")
  208.                         xItem++
  209.                 )
  210.                 ;輸出總數量的訊息
  211.                 fprintf(pPort "\n\nTotal: %5d\n\n" length(lAdded)+length(lDeleted)+length(lChanged))
  212.                 fprintf(pPort "Summary:\n")
  213.                 fprintf(pPort "  %d Added symbols\n" length(lAdded))
  214.                 fprintf(pPort "  %d Deleted symbols\n" length(lDeleted))
  215.                 fprintf(pPort "  %d Changed symbols\n\n" length(lChanged))
  216.                 close(pPort)
  217.                
  218.                 axlUIViewFileCreate(tFile "Report Window" t (120:60)) ;觀看輸出結果
  219.         )
  220. )
  221. procedure(_ssfnEnsureNonNilValue(val)
  222.         unless(val
  223.                 val = ""
  224.         )
  225.         val
  226. )
  227. procedure(fnCSExtractaData(tBrdPathNew tBrdPathOld)
  228.         let((tFile pPort tBrdName tCmd)
  229.                 ;要導出比較的資料
  230.                 tFile = strcat(getWorkingDir() "/symbol.view")
  231.                 pPort = outfile(tFile)
  232.                 fprintf(pPort "SYMBOL\n\n")
  233.                 fprintf(pPort "REFDES\n")
  234.                 fprintf(pPort "SYM_X\n")
  235.                 fprintf(pPort "SYM_Y\n")
  236.                 fprintf(pPort "SYM_MIRROR\n")
  237.                 fprintf(pPort "SYM_ROTATE\n")
  238.                 fprintf(pPort "SYM_TYPE\n")
  239.                 fprintf(pPort "SYM_NAME\n")
  240.                 fprintf(pPort "END\n")
  241.                 fprintf(pPort "COMPONENT\n")
  242.                 fprintf(pPort "REFDES\n")
  243.                 fprintf(pPort "COMP_PART_NUMBER\n")
  244.                 fprintf(pPort "COMP_VALUE\n")
  245.                 fprintf(pPort "COMP_TOL\n")
  246.                 fprintf(pPort "COMP_PACKAGE\n")
  247.                 fprintf(pPort "COMP_DEVICE_TYPE\n")
  248.                 fprintf(pPort "COMP_CLASS\n")
  249.                 fprintf(pPort "COMP_DEVICE_LABEL\n")
  250.                 fprintf(pPort "END\n")
  251.                 close(pPort)
  252.                
  253.                 ;導出新舊brd的資料,使用axlRunBatchDBProgram()就不會開啟cmd視窗
  254.                 foreach(tBrdPath list(tBrdPathNew tBrdPathOld)
  255.                         tBrdName = cadr(axlDMFileParts(tBrdPath))
  256.                         sprintf(tCmd "extracta %L %s %s_sym.txt %s_comp.txt" tBrdPath tFile tBrdName tBrdName)
  257.                         axlRunBatchDBProgram("extracta" tCmd ?silent t ?noUnload t ?reloadDB nil)
  258.                         deleteFile(strcat(getWorkingDir() "/extract.log"))
  259.                 )
  260.                 deleteFile(tFile)
  261.         )
  262. )
复制代码

[/hide]

作者: JIMDENG    时间: 2016-2-17 10:45
本帖最后由 JIMDENG 于 2016-2-17 10:58 编辑

测试了一下,两个文件中元件坐标变动了,能直观的显示出来!很实用!新年的好礼物!谢谢楼主!

作者: penny190    时间: 2016-2-17 15:51
謝謝大大 ~~ 又有新分享喔
作者: guanhaiji301    时间: 2016-2-17 15:54
真的这么好吗?谢谢
作者: nanosoc    时间: 2016-2-17 16:31
好东西,谢谢楼主分享!!!
作者: huzf    时间: 2016-2-17 17:06
看看

作者: wolf343105    时间: 2016-2-18 08:47
ding xiexie.
作者: lindaling59420    时间: 2016-2-18 14:32
好东西


作者: 武紫旭    时间: 2016-2-19 14:39
不错,赞一个!

作者: ben71431    时间: 2016-2-19 14:53
感謝分享~
作者: 卫冬冬    时间: 2016-2-21 08:38
看看 学习学习学习学习


作者: jackoosam    时间: 2016-2-21 20:18
這功能很不錯用
小弟常常在比對檔案阿
這是太謝謝了
作者: mistletoe    时间: 2016-2-22 14:23
感谢分享,楼主威武

作者: zqy610710    时间: 2016-2-23 20:20

好东西,谢谢楼主分享!!!

作者: 小四月    时间: 2016-3-4 16:43
厉害 支持哦  学习一下

作者: angelly    时间: 2016-3-14 10:10
谢谢分享
作者: 步六孤    时间: 2016-3-15 09:32
牛!

作者: Dina    时间: 2016-3-15 11:19
想看看的,不知道能不能了,试下
作者: davidlong98    时间: 2016-3-16 16:59
看起来好高端的样子

作者: TobyTao_Zhang    时间: 2016-3-18 12:56
厉害 支持一下 ,谢谢楼主分享
作者: snow6333    时间: 2016-4-12 14:10
這個skill比較出來的資料比較完整,又有原始碼可以研究
感謝感謝
作者: vvdbvv    时间: 2016-7-13 17:07
好东西,谢谢楼主分享!!!
作者: jackoosam    时间: 2016-7-17 12:56
很實用的SKILL 比對前後版本PCB很方便
真是感謝
作者: gaylin53    时间: 2016-7-20 11:36
謝謝大大 ~~ 又有新分享喔
作者: gaylin53    时间: 2016-7-20 16:33
謝謝大大 ~~
作者: hy20060614    时间: 2016-7-21 11:06
谢谢分享
作者: Eric0921    时间: 2016-7-21 11:49
感謝分享~
作者: szhot    时间: 2016-7-22 17:28
布线和VIA孔能区别出来吗?
作者: qiqi0713    时间: 2016-11-18 15:29
厉害 支持哦  学习一下
作者: qiqi0713    时间: 2016-11-18 15:34
好想用,但是這要怎麼用?
作者: tim207    时间: 2016-11-23 23:51
下下来支持一下
作者: 1005196332    时间: 2016-11-24 10:23
学习学习学习学习

作者: startlin    时间: 2017-6-17 15:52
謝謝分享,努力學習中!
作者: 砰砰小心脏    时间: 2017-7-23 09:11
支持楼主
作者: zhanghua315    时间: 2017-7-24 14:59
多谢分享
作者: happy666    时间: 2017-7-26 15:04
謝謝分享~
作者: wancai9550    时间: 2017-7-27 09:26
谢谢楼主分享!!!
作者: vivianwu0317    时间: 2017-7-27 09:57
謝謝大大 ~~ 又有新分享喔




欢迎光临 EDA365电子工程师网 (http://bbs.elecnest.cn/) Powered by Discuz! X3.2