EDA365电子论坛网

标题: 【Skill分享/提取】导入BMP图片LOGO的Skill 【源码】 [打印本页]

作者: Newroomantics    时间: 2022-1-19 17:56
标题: 【Skill分享/提取】导入BMP图片LOGO的Skill 【源码】
本帖最后由 Newroomantics 于 2022-1-26 10:50 编辑

提取自GTAllegroOpen开源项目https://github.com/whh5118/GTOpen


下载:
gtopen_Logo.zip (3.01 KB, 下载次数: 73)







作者: 刘强633    时间: 2022-1-19 18:04
有这个软件就方便了,loge有时把人都能弄得郁闷
作者: mofise007    时间: 2022-1-19 21:09
111111111111
作者: zc333    时间: 2022-1-20 11:08
导入logo工具
作者: kuka_555    时间: 2022-1-26 20:55
好东西
作者: koncc    时间: 2022-1-27 08:31
感謝分享
作者: Newroomantics    时间: 2022-1-27 11:43
gtopen_Logo.il:
  1. ;--------导入LOGO--------
  2. ;
  3. ;---------------

  4. axlCmdRegister("gtopen_Logo" 'gtopen_Logo ?cmdType "interactive")
  5. procedure( gtopen_Logo()
  6. let((form)
  7.        
  8.         axlShell("noappmode")
  9.         form = gtopen_Logo_Createform()
  10.         gtopen_Logo_Int_Var(form)
  11.         gtopen_Logo_Update_form(form)
  12. )
  13. )




  14. procedure( gtopen_Logo_Createform()
  15. let((file form)
  16.         file = "gtopen_Logo.form"
  17.         when('gtopen_Logoform && boundp('gtopen_Logoform)
  18.                 when(axlIsFormType(eval('gtopen_Logoform))
  19.                         axlFormClose(eval('gtopen_Logoform))
  20.                 )
  21.         )
  22.        
  23.         form = axlFormCreate('gtopen_Logoform file nil 'gtopen_Logo_CB t)
  24.        
  25.         form
  26. )
  27. )


  28. procedure( gtopen_Logo_Int_Var(form)
  29. let((_getFontList)
  30.         form->pop = ncons(nil)
  31.         form->pop->layerclass = list("BOARD GEOMETRY" "PACKAGE GEOMETRY" "MANUFACTURING" "ETCH" "DRAWING FORMAT")

  32.        
  33.         form->var = ncons(nil)
  34.         form->var->layerclass = "PACKAGE GEOMETRY"
  35.         form->var->layersubclass = "SILKSCREEN_TOP"
  36.         form->var->pic_size = 1
  37.         form->var->neg = nil
  38. )
  39. )


  40. procedure( gtopen_Logo_CB(form)
  41. prog((tt bmp_show Blockw Blockh width height pixel_size box pick)
  42.         case(form->curField
  43.                 ("layerclass"
  44.                         form->var->layerclass = form->curValue
  45.                         form->var->layersubclass = car(axlSubclasses(form->var->layerclass))
  46.                 )
  47.                 ("layersubclass" | "neg" | "pic_size"
  48.                         evalstring(sprintf(nil "form->var->%s = form->curValue" form->curField))
  49.                 )
  50.                 ("vis"
  51.                         if(form->curValue then
  52.                                 axlVisibleLayer(strcat(form->var->layerclass "/" form->var->layersubclass) t)
  53.                         else
  54.                                 axlVisibleLayer(strcat(form->var->layerclass "/" form->var->layersubclass) nil)
  55.                         )
  56.                         axlVisibleUpdate(t)
  57.                 )
  58.                 ("load"
  59.                         tt = axlDMFileBrowse("\321\241\324\361\315\274\306\254" nil ?optFilters "BMP Files(*.bmp)|*.bmp")
  60.                         when(tt
  61.                                 if(isFile(tt) && member(upperCase(lastelem(axlDMFileParts(tt))) list("BMP")) then
  62.                                         form->var->bmpinput = tt
  63.                                 else
  64.                                         printf(">>\262\273\326\247\263\326\315\274\306\254\270\361\312\275\n")
  65.                                 )
  66.                         )
  67.                 )
  68.                 ("place"
  69.                         when(form->bmpdate
  70.                                 tt = axlGetParam(sprintf(nil "paramTextBlock:%d" form->var->pic_size))
  71.                                 Blockw = tt->width
  72.                                 Blockh = tt->height
  73.                                 width = (form->bmpdate[21] << 24) + (form->bmpdate[20] << 16) + (form->bmpdate[19] << 8) + form->bmpdate[18]
  74.                                 height = (form->bmpdate[25] << 24) + (form->bmpdate[24] << 16) + (form->bmpdate[23] << 8) + form->bmpdate[22]
  75.                                 pixel_size = max(Blockw/width Blockh/height)
  76.                                 box = list(list(0 0) list(width*pixel_size height*pixel_size))
  77.                                 axlClearDynamics()
  78.                                 axlAddSimpleMoveDynamics(0:0 axlPathStart(box) "box" ?ref_point 0:0)
  79.                                 pick = axlEnterPoint()
  80.                                 axlClearDynamics()
  81.                                 when(pick
  82.                                         axlDBCloak(gtopen_Logo_addshape(form pick) 'shape)
  83.                                 )
  84.                         )
  85.                 )
  86.                 ("textset"
  87.                         axlShell("define text")
  88.                 )
  89.                 (t
  90.                         return(t)
  91.                 )
  92.         )
  93.         gtopen_Logo_Update_form(form)
  94. )
  95. )

  96. procedure( gtopen_Logo_Update_form(form)
  97. let((tt port bmpdate)

  98.         form->pop->layersubclass = nil
  99.         foreach(n0 axlSubclasses(form->var->layerclass)
  100.                 when(axlIsLayer(buildString(list(form->var->layerclass n0) "/"))
  101.                         form->pop->layersubclass = cons(list(n0 n0 axlLayerGet(buildString(list(form->var->layerclass n0) "/"))->color) form->pop->layersubclass)
  102.                 )
  103.         )
  104.         tt = axlLayerGet(strcat(form->var->layerclass "/" form->var->layersubclass))
  105.         if(tt->visible then
  106.                 form->var->vis = tt->color
  107.                 axlFormSetField(form "vis" t)
  108.         else
  109.                 form->var->vis = 0
  110.                 axlFormSetField(form "vis" nil)
  111.         )
  112.        
  113.         foreach(n0 form->pop->?
  114.                 tt = member(n0 form->pop)
  115.                 axlFormBuildPopup(form symbolToString(car(tt)) cadr(tt))
  116.         )
  117.         foreach(n0 form->var->?
  118.                 tt = member(n0 form->var)
  119.                 axlFormSetField(form symbolToString(car(tt)) cadr(tt))
  120.         )
  121.         when(form->curField == "load" && form->var->bmpinput
  122.                 form->bmpsize = fileLength(form->var->bmpinput)
  123.                 axlFormSetField(form "bmp_show" form->var->bmpinput)
  124.                 port = infile(form->var->bmpinput)
  125.                 declare(bmpdate[form->bmpsize])
  126.                 for(i 0 form->bmpsize-1
  127.                         bmpdate[i] = charToInt(getc(port))
  128.                 )
  129.                 close(port)
  130.                 form->bmpdate = bmpdate
  131.         )
  132.         if(form->var->bmpinput then
  133.                 axlFormSetFieldEditable(form "place" t)
  134.         else
  135.                 axlFormSetFieldEditable(form "place" nil)
  136.         )
  137.         axlFormAutoResize(form)
  138.         axlFormDisplay(form)
  139. )
  140. )

  141. procedure( gtopen_Logo_addshape(form pickxy)
  142. prog((tt Blockw Blockh number num row max_column column max_w bit x y offset width height Grid imagesize path polys symbolid)
  143.         tt = axlGetParam(sprintf(nil "paramTextBlock:%d" form->var->pic_size))
  144.         Blockw = tt->width
  145.         Blockh = tt->height
  146.        
  147.         offset = (form->bmpdate[13] << 24) + (form->bmpdate[12] << 16) + (form->bmpdate[11] << 8) + form->bmpdate[10]
  148.         width = (form->bmpdate[21] << 24) + (form->bmpdate[20] << 16) + (form->bmpdate[19] << 8) + form->bmpdate[18]
  149.         height = (form->bmpdate[25] << 24) + (form->bmpdate[24] << 16) + (form->bmpdate[23] << 8) + form->bmpdate[22]
  150.         imagesize = form->bmpsize - offset
  151.        
  152.         max_column = (imagesize / height) << 3
  153.         max_w = (imagesize / width) << 3
  154.         number = offset + imagesize - 1
  155.         Grid = 1/min(width/Blockw height/Blockh)
  156.         column = 0
  157.         polys = '()
  158.         if(!axlSelectByName("SYMTYPE" "GTLogo") then
  159.     axlDBCreateSymDefSkeleton(list("GTLogo" "mechanical") list(list(0 0) list(width height)))
  160.         else
  161.           axlClearSelSet()
  162.         )
  163.         symbolid = car(axlDBCreateSymbolSkeleton(list("GTLogo" "mechanical") pickxy nil 0.0 nil))
  164.         axlMeterCreate("\275\370\263\314\326\320" "" t)
  165.         for(i offset number
  166.                 tt = fix((50*i) / (imagesize-1))
  167.                 when(tt == 12 || tt == 25 || tt == 37 || tt == 50
  168.                         axlMeterUpdate(tt sprintf(nil "\315\352\263\311\266\310 :%d / %d" (i-offset) (imagesize-1)))
  169.                 )
  170.                
  171.                 y = Grid * fix((i - offset) / (max_column >> 3)) + cadr(pickxy)
  172.                 for(j 0 7
  173.             bit = bitfield1(form->bmpdate[i] (7 - j))
  174.             when(form->var->neg
  175.                     bit = abs(bit-1)
  176.             )
  177.             x = Grid * column + car(pickxy)
  178.                         when(zerop(bit) && (column < width)
  179.                                 path = axlPathStart(list(x:y))
  180.                                 axlPathLine(path 0.0 x:(y+1.1*Grid))
  181.                                 axlPathLine(path 0.0 (x+1.1*Grid):(y+1.1*Grid))
  182.                                 axlPathLine(path 0.0 (x+1.1*Grid):y)
  183.                                 axlPathLine(path 0.0 x:y)
  184.                                 polys = append(axlPolyFromDB(path) polys)
  185.                         )
  186.             column++
  187.                 )
  188.                 when(column == max_column
  189.             column = 0
  190.                 )
  191.         )
  192.         polys = axlPolyOperation(car(polys) cdr(polys) 'OR)
  193.         num = 1
  194.         foreach(n0 polys
  195.                 tt = fix((50*num) / length(polys)) + 50
  196.                 when(tt == 62 || tt == 75 || tt == 87 || tt == 100
  197.                         axlMeterUpdate(tt sprintf(nil "\315\352\263\311\266\310 :%d / %d" num length(polys)))
  198.                 )
  199.                 tt = axlDBCreateShape(n0 t strcat(form->var->layerclass "/" form->var->layersubclass) nil symbolid)
  200.                 axlCustomColorObject(car(tt) 0)
  201.                 num++
  202.         )
  203.         axlMeterDestroy()
  204.         axlVisibleUpdate(t)
  205.        
  206. )
  207. )


  208. /*
  209. axlCmdRegister("gtopen_Logo" 'gtopen_Cline2Shape ?cmdType "interactive")
  210. procedure( gtopen_Cline2Shape()
  211. let((form)
  212.        
  213. ;        axlShell("noappmode")
  214.         form = gtopen_Cline2Shape_Createform()
  215.         gtopen_Cline2Shape_Int_Var(form)
  216.         gtopen_Cline2Shape_Update_form(form)
  217. )
  218. )

  219. procedure( gtopen_Cline2Shape_Createform()
  220. let((file form)
  221.         file = "gtopen_Cline2Shape.form"
  222.         when('gtopen_Logoform && boundp('gtopen_Cline2Shapeform)
  223.                 when(axlIsFormType(eval('gtopen_Cline2Shapeform))
  224.                         axlFormClose(eval('gtopen_Cline2Shapeform))
  225.                 )
  226.         )
  227.        
  228.         form = axlFormCreate('gtopen_Cline2Shapeform file nil 'gtopen_Cline2Shape_CB t)
  229.        
  230. )
  231. )

  232. procedure( gtopen_Cline2Shape_CB(form)
  233. let(()
  234.         println(form->curField)
  235.         case(form->curField
  236.                 (
  237.                
  238.                 )
  239.         )

  240. )
  241. )

  242. */
复制代码
gtopen_Logo.form:
  1. FILE_TYPE=FORM_DEFN VERSION=2
  2. FORM AUTOGREYTEXT
  3. FIXED
  4. PORT 69 10
  5. HEADER "BMP Logo导入"
  6. POPUP <fontlist_pop>""""
  7. POPUP <layerclass_pop>""""
  8. POPUP <layersubclass_pop>""""
  9. POPUP <brushmode>""""
  10. TILE

  11. GROUP "预览"
  12. GLOC 1 1
  13. GSIZE 40 22
  14. ENDGROUP
  15. FIELD bmp_show
  16. THUMBNAIL
  17. FLOC 3 5
  18. FSIZE 37 16
  19. ENDFIELD

  20. GROUP "参数"
  21. GLOC 43 1
  22. GSIZE 26 22
  23. ENDGROUP

  24. FIELD layerclass
  25. FLOC 47 4
  26. ENUMSET 18 1
  27. POP layerclass_pop
  28. OPTIONS prettyprint
  29. ENDFIELD

  30. FIELD vis
  31. FLOC 44 7
  32. COLOR 2 1
  33. ENDFIELD

  34. FIELD layersubclass
  35. FLOC 47 7
  36. ENUMSET 18 1
  37. OPTIONS ownerdrawn prettyprint
  38. POP layersubclass_pop
  39. ENDFIELD

  40. TEXT "大小"
  41. TLOC 44 10
  42. ENDTEXT

  43. FIELD pic_size
  44. FLOC 50 10
  45. INTSLIDEBAR 4 2
  46. MIN 1
  47. MAX 50
  48. ENDFIELD

  49. FIELD textset
  50. FLOC 60 10
  51. MENUBUTTON "设置" 3 3
  52. ENDFIELD

  53. TEXT "类型"
  54. TLOC 44 13
  55. ENDTEXT


  56. FIELD neg
  57. FLOC 50 13
  58. CHECKLIST "负片"
  59. ENDFIELD



  60. TEXT
  61. FLOC 1 25
  62. INFO bmpinput 100
  63. FSIZE 45 2
  64. ENDTEXT

  65. FIELD load
  66. FLOC 45 24
  67. MENUBUTTON "1.导入" 9 4
  68. ENDFIELD

  69. FIELD place
  70. FLOC 58 24
  71. MENUBUTTON "2.摆放" 9 4
  72. ENDFIELD

  73. ENDTILE
  74. ENDFORM
复制代码




作者: db-_-    时间: 2022-1-27 12:47
已拜读,很不错,17.2亲测可用。
作者: barry_chen    时间: 2022-2-3 16:03
进来先下载一下
作者: a429772682    时间: 2022-2-4 15:03
学习。试一下
作者: digitzing    时间: 2022-2-8 14:14
是好东西!加油
作者: digitzing    时间: 2022-2-8 15:26
速度太慢了
作者: 86232648    时间: 2022-2-17 23:12
niu1
作者: 2386    时间: 2022-3-1 15:52
是好东西!加油
作者: 小池养大鱼    时间: 2022-3-8 16:59
我下载的全是乱码,图片导入之后也不显示
作者: Newroomantics    时间: 2022-3-9 11:01
小池养大鱼 发表于 2022-3-8 16:59
我下载的全是乱码,图片导入之后也不显示

16.6版本测试没问题,你的是17.x版本吗,我知道的是17.x以后的不支持中文显示会乱码另外可以不用下载附件了,下载扣贡献,我有把代码贴上来,复制就行了

作者: hunterwang    时间: 2022-3-17 22:15
可以学习一下!
作者: 136259909QY    时间: 2022-3-19 09:15
学习。试一下
作者: hifirockz    时间: 2022-3-30 20:15
thanks fro the info

作者: ygc870327    时间: 2022-5-17 20:25
牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛!

作者: myhome43    时间: 2022-7-5 17:44
想問一下 .form這檔案需要放在哪~ 謝謝分享
作者: Newroomantics    时间: 2022-7-6 10:47
myhome43 发表于 2022-7-5 17:44
想問一下 .form這檔案需要放在哪~ 謝謝分享

帖子里有写


作者: myhome43    时间: 2022-7-7 00:28
Newroomantics 发表于 2022-7-6 10:47
帖子里有写
  • gtopen_Logo.form文件存放至目录 cadence\SPB_16.6\share\local\pcb\forms中

  • 阿...謝謝板主提醒,眼盲了

    作者: myhome43    时间: 2022-8-5 11:46
    顯示E- *Error* putprop: first arg must be either symbol, list, defstruct or user type - nil
    作者: badkai1988    时间: 2022-8-5 14:35
    哇塞~~~ 這東西超方便 謝謝分享!!!!
    作者: lorby    时间: 2023-7-15 23:39
    666666 感谢分享
    作者: Dc2024061241a    时间: 2024-7-29 14:21

    感谢分享 666666
    作者: 无痕03356    时间: 2024-7-29 15:53
    学习一下学习一下
    作者: lrlshina    时间: 2024-10-9 10:18
    再次下载试一下。感觉威望都快用光了
    作者: lrlshina    时间: 2024-10-9 10:54
    好用,在16.6上可以用就够了。

    作者: dinodino66    时间: 2025-1-15 11:46
    感謝分享~好用
    作者: fuxiangyupi23    时间: 2025-3-20 08:31
    谢谢分享
    作者: fuxiangyupi23    时间: 2025-3-22 11:48
    试试,谢谢
    作者: fuxiangyupi23    时间: 2025-3-22 13:53
    感谢分享
    作者: antoni2011    时间: 2025-3-22 14:05
    感谢分享了,支持学习了.
    作者: fuxiangyupi23    时间: 2025-3-22 14:06
    大佬,我的弹出first arg must be either symbol, list, defstruct or user type - nil这是哪里出问题了吗?谢谢
    作者: 万里羊    时间: 2025-3-24 21:41
    正真的好心人,爱了
    作者: t123456    时间: 2025-3-27 18:30
    谢谢分享




    欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/) Powered by Discuz! X3.2