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]
;
;FileName:
;Load: load("fCS.il")
;Command: cs
;
;功能:比較兩個PCB的Symbols差異
;使用方法:
; 1.開起一個新的brd
; 2.執行cs
; 3.會提示讀取一個舊的brd
; 4.選擇檔案後,再選擇開啟之後就開始比較,直到輸出結果
;
;; 程式特色:
; 1.源代碼分享,讓所有人都可以依照自己的方式加入其他功能,
; 例如加入輸出檔案為excel檔
; 或是其他功能,自己想像.
axlCmdRegister("cs" 'fnCompareSymbol ?cmdType "general")
procedure(fnCompareSymbol()
prog((tBrdPathNew tBrdOld tBrdPathOld pPort tCmd tNewFile tOldFile lNewList lOldList)
;取新舊brd檔案名稱
axlMsgPut("M-Please select a brd file:")
tBrdPathOld = axlDMFileBrowse("ALLEGRO_BRD" nil ?title "Compare Symbol" ?optFilters "Board file(*.brd)|*.brd|") ;瀏覽舊的brd
unless(tBrdPathOld
return(nil)
)
tBrdNew = axlCurrentDesign() ;目前所開啟的brd
tBrdPathNew = strcat(simplifyFilename(tBrdNew) ".brd")
;要導出比較的資料
fnCSExtractaData(tBrdPathNew tBrdPathOld)
;讀取新brd所導出的資料Comp
tNewFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathNew)) "_comp.txt")
lNewCompList = fnCSReadFile(tNewFile)
deleteFile(tNewFile)
;讀取舊brd所導出的資料Comp
tOldFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathOld)) "_comp.txt")
lOldCompList = fnCSReadFile(tOldFile)
deleteFile(tOldFile)
;讀取新brd所導出的資料Sym
tNewFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathNew)) "_sym.txt")
lNewSymList = fnCSReadFile(tNewFile)
deleteFile(tNewFile)
;讀取舊brd所導出的資料Sym
tOldFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathOld)) "_sym.txt")
lOldSymList = fnCSReadFile(tOldFile)
deleteFile(tOldFile)
;比較新舊brd差異並輸出到檔案
fnCSCompareData(tBrdPathNew tBrdPathOld lNewCompList lOldCompList lNewSymList lOldSymList)
)
)
procedure(fnCSReadFile(tFile)
let((pPort tLine lLines)
if(tFile && isFile(tFile) then
pPort = infile(tFile)
rexCompile(".$")
for(x 1 2 ;讀取前面兩行,這兩行不會處理
gets(tLine pPort)
)
while(gets(tLine pPort)
unless(blankstrp(tLine)
lLines = cons(rexReplace(tLine "" 0) lLines)
)
)
close(pPort)
sort(lLines nil) ;排序所有資料
else
axlUIConfirm("E- Misssing file.")
)
)
)
procedure(fnCSCompareData(tBrdPathNew tBrdPathOld lNewCompList lOldCompList lNewSymList lOldSymList)
let((oNewComp oOldComp oNewSym oOldSym lLines tRefDes tPartNum tValue tTol tDeviceType tXY tIsMirrored
tRotation tMode tSymName)
;將Comp的Data存放到Table
for(x 0 1
if(zerop(x) then
oNewComp = makeTable("NEWCOMPDATA" nil)
else
oOldComp = makeTable("OLDCOMPDATA" nil)
)
rexCompile("!!")
foreach(tLine nth(x list(lNewCompList lOldCompList))
tLine = rexReplace(tLine "! !" 0)
lLines = parseString(tLine "!")
tRefDes = cadr(lLines)
tPartNum = caddr(lLines)
tValue = nth(3 lLines)
tTol = nth(4 lLines)
tDeviceType = nth(6 lLines)
if(zerop(x) then
oNewComp[tRefDes] = list(tPartNum tValue tTol tDeviceType)
else
oOldComp[tRefDes] = list(tPartNum tValue tTol tDeviceType)
)
)
)
;將Sym的Data存放到Table
for(x 0 1
if(zerop(x) then
oNewSym = makeTable("NEWSYMDATA" nil)
else
oOldSym = makeTable("OLDSYMDATA" nil)
)
rexCompile("!!")
foreach(tLine nth(x list(lNewSymList lOldSymList))
tLine = rexReplace(tLine "! !" 0)
lLines = parseString(tLine "!")
tRefDes = cadr(lLines)
tXY = strcat("(" caddr(lLines) "," nth(3 lLines) ")")
tIsMirrored = nth(4 lLines)
if(tIsMirrored == "YES" then
tIsMirrored = "B"
else
tIsMirrored = "T"
)
tRotation = sprintf(nil "%.2f" readstring(nth(5 lLines)))
tMode = nth(6 lLines)
tSymName = nth(7 lLines)
if(zerop(x) then
tPartNum = car(oNewComp[tRefDes])
unless(tPartNum
tPartNum = ""
)
oNewSym[tRefDes] = list(tXY tIsMirrored tRotation tMode tSymName tPartNum)
else
tPartNum = car(oOldComp[tRefDes])
unless(tPartNum
tPartNum = ""
)
oOldSym[tRefDes] = list(tXY tIsMirrored tRotation tMode tSymName tPartNum)
)
)
)
fnCSOutputData(tBrdPathNew tBrdPathOld oNewComp oOldComp oNewSym oOldSym)
)
)
procedure(fnCSOutputData(tBrdPathNew tBrdPathOld oNewComp oOldComp oNewSym oOldSym)
let((lAdded lDeleted lChanged tFile pPort xItem tOne)
;判斷是否有新增資料
foreach(tRefdes oNewSym
unless(oOldSym[tRefdes]
lAdded = cons(tRefdes lAdded)
)
)
lAdded = sort(lAdded nil)
;判斷是否有減少資料
foreach(tRefdes oOldSym
unless(oNewSym[tRefdes]
lDeleted = cons(tRefdes lDeleted)
)
)
lDeleted = sort(lDeleted nil)
;判斷是否有改變資料
foreach(tRefdes oNewSym
when(oOldSym[tRefdes]
unless(oNewSym[tRefdes] == oOldSym[tRefdes]
lChanged = cons(tRefdes lChanged)
)
)
)
lChanged = sort(lChanged nil)
;輸出資料到檔案
drain()
tFile = strcat(getWorkingDir() "/" cadr(axlDMFileParts(tBrdPathNew)) "_OldNew.rpt")
pPort = outfile(tFile)
;檔案顯示的標題
fprintf(pPort "Compare Symbol report\n")
fprintf(pPort "Date: %s\n" getCurrentTime())
fprintf(pPort "%s.brd [Old]\n" cadr(axlDMFileParts(tBrdPathOld)))
fprintf(pPort "%s.brd [New]\n\n" cadr(axlDMFileParts(tBrdPathNew)))
fprintf(pPort "%s\n" "===============================================================================================================================")
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")
fprintf(pPort "%s\n" "===============================================================================================================================")
xItem = 1
;輸出新增的資料到檔案
foreach(tOne lAdded
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])))
xItem++
)
fprintf(pPort "\n")
;輸出減少的資料到檔案
xItem = 1
foreach(tOne lDeleted
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])))
xItem++
)
fprintf(pPort "\n")
;輸出變更的資料到檔案
xItem = 1
foreach(tOne lChanged
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])))
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])))
fprintf(pPort "\n")
xItem++
)
;輸出總數量的訊息
fprintf(pPort "\n\nTotal: %5d\n\n" length(lAdded)+length(lDeleted)+length(lChanged))
fprintf(pPort "Summary:\n")
fprintf(pPort " %d Added symbols\n" length(lAdded))
fprintf(pPort " %d Deleted symbols\n" length(lDeleted))
fprintf(pPort " %d Changed symbols\n\n" length(lChanged))
close(pPort)
axlUIViewFileCreate(tFile "Report Window" t (120:60)) ;觀看輸出結果
)
)
procedure(_ssfnEnsureNonNilValue(val)
unless(val
val = ""
)
val
)
procedure(fnCSExtractaData(tBrdPathNew tBrdPathOld)
let((tFile pPort tBrdName tCmd)
;要導出比較的資料
tFile = strcat(getWorkingDir() "/symbol.view")
pPort = outfile(tFile)
fprintf(pPort "SYMBOL\n\n")
fprintf(pPort "REFDES\n")
fprintf(pPort "SYM_X\n")
fprintf(pPort "SYM_Y\n")
fprintf(pPort "SYM_MIRROR\n")
fprintf(pPort "SYM_ROTATE\n")
fprintf(pPort "SYM_TYPE\n")
fprintf(pPort "SYM_NAME\n")
fprintf(pPort "END\n")
fprintf(pPort "COMPONENT\n")
fprintf(pPort "REFDES\n")
fprintf(pPort "COMP_PART_NUMBER\n")
fprintf(pPort "COMP_VALUE\n")
fprintf(pPort "COMP_TOL\n")
fprintf(pPort "COMP_PACKAGE\n")
fprintf(pPort "COMP_DEVICE_TYPE\n")
fprintf(pPort "COMP_CLASS\n")
fprintf(pPort "COMP_DEVICE_LABEL\n")
fprintf(pPort "END\n")
close(pPort)
;導出新舊brd的資料,使用axlRunBatchDBProgram()就不會開啟cmd視窗
foreach(tBrdPath list(tBrdPathNew tBrdPathOld)
tBrdName = cadr(axlDMFileParts(tBrdPath))
sprintf(tCmd "extracta %L %s %s_sym.txt %s_comp.txt" tBrdPath tFile tBrdName tBrdName)
axlRunBatchDBProgram("extracta" tCmd ?silent t ?noUnload t ?reloadDB nil)
deleteFile(strcat(getWorkingDir() "/extract.log"))
)
deleteFile(tFile)
)
)
复制代码
[/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