明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 265|回复: 3

[经验] 列表数据引导用户点击

  [复制链接]
发表于 2024-4-25 13:07 | 显示全部楼层 |阅读模式
本帖最后由 dcl1214 于 2024-4-25 15:18 编辑

  1. (defun delsame (lst / s-car new)
  2.                                         ;删除表中重复项,删除重复
  3.   (setq lst (vl-remove nil lst))
  4.   (while (setq s-car (car lst))
  5.     (if        (vl-position s-car new)
  6.       ()
  7.       (set 'new (cons s-car new))
  8.     )
  9.     (setq lst (cdr lst))
  10.   )
  11.   (setq new (reverse new))
  12.   new
  13. )
  14. (defun list>Split (lst len / g i gs)
  15.                                         ;分段,点表拆分,拆分表,按照指定长度拆分表,按长度拆分表,表拆分,表分段,列表分割,列表分组,分段拆分表(另一个函数叫做sn:splitlst)(本函数是2018年0806日写的),点表分割,按个数分割
  16.                                         ;切分表lst成若干段长度为len的子表,子表的个数
  17.   (if (and len
  18.            (= (type len) 'int)
  19.            (> len 0)
  20.            lst
  21.            (= (type lst) 'list)
  22.       )
  23.     (if        (= len 1)
  24.       (setq gs (mapcar 'list lst))
  25.       (progn
  26.         (while lst
  27.           (setq g nil)
  28.           (setq i 1)
  29.           (while (and lst (<= i len))
  30.             (setq cars (car lst))
  31.             (setq g (cons cars g))
  32.             (setq lst (cdr lst))
  33.             (setq i (1+ i))
  34.           )
  35.           (setq g (reverse g))
  36.           (setq gs (cons g gs))
  37.         )
  38.         (setq gs (reverse gs))
  39.       )
  40.     )
  41.   )
  42.   gs
  43. )
  44. (defun wire:list-fill-with-title (dot-pare-list         keys
  45.                                   /                 gen-row-string
  46.                                   content         colum-widths
  47.                                   row-string
  48.                                  )
  49. ;;;将点表对变成有标题的listbox填充,列表填充,填充列表,\t方式填充列表,填充listbox
  50. ;;;                :: dot-pare-list 数据源点表对
  51. ;;;                :: keys 表头,如果没有表头则所有点表对的表头
  52. ;;;                :: 返回排成行了的结果,第一行为表头
  53.   (defun gen-row-string        (str-list width-list /)
  54.                                         ;将字串按各列宽度串在一起
  55.     (apply 'strcat
  56.            (mapcar '(lambda (a b)
  57.                       (if (not a)
  58.                         (setq a "")
  59.                       )
  60.                       (if (not (= (type a) 'str))
  61.                         (setq a (vl-princ-to-string a))
  62.                       )
  63.                       (setq a (strcat "|" a))
  64.                       (while (< (strlen a) b)
  65.                         (setq a (strcat a " "))
  66.                       )
  67.                       a
  68.                     )
  69.                    str-list
  70.                    width-list
  71.            )
  72.     )
  73.   )
  74.   (if (and dot-pare-list
  75.            keys
  76.            (= (type dot-pare-list) 'list)
  77.            (= (type (car dot-pare-list)) 'list)
  78.            (= (type (caar dot-pare-list)) 'list)
  79.            (= (type (caaar dot-pare-list)) 'str)
  80.            (= (type keys) 'list)
  81.            (= (type (car keys)) 'str)
  82.       )
  83.     (progn
  84.       (if (not keys)
  85.         (setq keys
  86.                (DELSAME
  87.                  (apply        'append
  88.                         (mapcar '(lambda (a) (mapcar 'car a)) dot-pare-list)
  89.                  )
  90.                )
  91.         )
  92.       )
  93.       (setq
  94.         content        (mapcar
  95.                   '(lambda (a)
  96.                      (if (member 'nil a)
  97.                        (print "wire:list-fill-with-title 遇到nil值")
  98.                      )
  99.                      (mapcar '(lambda (b)
  100.                                 (if (cdr (assoc b a))
  101.                                   (cdr (assoc b a))
  102.                                   ""
  103.                                 )
  104.                               )
  105.                              keys
  106.                      )
  107.                    )
  108.                   dot-pare-list
  109.                 )
  110.       )
  111. ;;;计算列宽
  112.       (setq colum-widths
  113.              (mapcar
  114.                '(lambda        (a)
  115.                   (apply
  116.                     'max
  117.                     (mapcar
  118.                       (function
  119.                         (lambda        (b)
  120.                           (if (and b (= (type b) 'list) (= (length b) 1))
  121.                             (setq b (car b))
  122.                             (setq b (vl-princ-to-string b))
  123.                           )
  124.                           (strlen b)
  125.                         )
  126.                       )
  127.                       a
  128.                     )
  129.                   )
  130.                 )
  131.                (apply 'mapcar (cons 'list (cons keys content)))
  132.              )
  133.       )
  134.       (setq colum-widths
  135.              (mapcar '1+
  136.                      (mapcar '(lambda (a)
  137.                                 (if (< a 3)
  138.                                   3
  139.                                   a
  140.                                 )
  141.                               )
  142.                              colum-widths
  143.                      )
  144.              )
  145.       )
  146.       (setq row-string
  147.              (mapcar (function (lambda (a / str)
  148.                                  (setq str (gen-row-string a colum-widths))
  149.                                  (setq str (vl-string-left-trim "|" str))
  150.                                )
  151.                      )
  152.                      (cons keys content)
  153.              )
  154.       )
  155.     )
  156.   )
  157.   row-string
  158. )

  159. (defun AddList (key lst)
  160.                                         ;对话框控件填充
  161.   (IF (AND key lst)
  162.     (PROGN
  163.       (if (= (type lst) 'str)
  164.         (setq lst (list lst))
  165.       )
  166.       (start_list key)
  167.       (foreach x lst (AND X (= (type x) 'str) (add_list x)))
  168.       (end_list)
  169.     )
  170.     (PROGN
  171.       (start_list key)
  172.       (end_list)
  173.     )
  174.   )
  175.   lst
  176. )

  177. (defun $xuan-ze$ (label     data      f-c       lst      /         $d$
  178.       $xuan-ze-xq$      _xz_dcl  agxh-db  d         dclid
  179.       jz     old_time si       sql      startNum tbn-agk
  180.       zds
  181.      )
  182.           ;label 顶部提示语
  183.           ;data 点表格式的数据,不是矩阵数据
  184.           ;f-c 第一列的列名
  185.           ;lst 预留参数
  186.      ;|
  187. ;示例
  188. ($xuan-ze$ "请选择mo_xing_ming_cheng"
  189.      '((("id" . "3")
  190.         ("an_gui_hao" . "HL-061-1")
  191.         ("zhuan_yong_ke_hu" . "")
  192.         ("guo_bie" . "0")
  193.         ("guo_bie_biao_zhi" . "BSMI")
  194.         ("zhen_jiao_shu" . "3")
  195.         ("zhi_wan" . "直")
  196.         ("e_ding_dian_liu" . "9A")
  197.         ("e_ding_dian_ya" . "125V")
  198.         ("zheng_shu_bian_hao" . "CI362060510465")
  199.         ("ren_zheng_fan_wei_yan_se" . "")
  200.         ("mo_xing_ming_cheng" . "台规三插")
  201.         ("bei_zhu" . "")
  202.        )
  203.        (("id" . "7")
  204.         ("an_gui_hao" . "HL-061-2")
  205.         ("zhuan_yong_ke_hu" . "")
  206.         ("guo_bie" . "33")
  207.         ("guo_bie_biao_zhi" . "BSMI")
  208.         ("zhen_jiao_shu" . "3")
  209.         ("zhi_wan" . "3")
  210.         ("e_ding_dian_liu" . "10A")
  211.         ("e_ding_dian_ya" . "125V")
  212.         ("zheng_shu_bian_hao" . "CI362060510465")
  213.         ("ren_zheng_fan_wei_yan_se" . "")
  214.         ("mo_xing_ming_cheng" . "台规三插")
  215.         ("bei_zhu" . "")
  216.        )
  217.        (("id" . "8")
  218.         ("an_gui_hao" . "HL-028")
  219.         ("zhuan_yong_ke_hu" . "")
  220.         ("guo_bie" . "巴西")
  221.         ("guo_bie_biao_zhi" . "UC")
  222.         ("zhen_jiao_shu" . "2")
  223.         ("zhi_wan" . "直")
  224.         ("e_ding_dian_liu" . "2.5A")
  225.         ("e_ding_dian_ya" . "250V")
  226.         ("zheng_shu_bian_hao" . "TüV 23.1140")
  227.         ("ren_zheng_fan_wei_yan_se" . "")
  228.         ("mo_xing_ming_cheng" . "8字尾")
  229.         ("bei_zhu" . "")
  230.        )
  231.        (("id" . "9")
  232.         ("an_gui_hao" . "HL-028")
  233.         ("zhuan_yong_ke_hu" . "")
  234.         ("guo_bie" . "巴西")
  235.         ("guo_bie_biao_zhi" . "UC")
  236.         ("zhen_jiao_shu" . "2")
  237.         ("zhi_wan" . "直")
  238.         ("e_ding_dian_liu" . "7A")
  239.         ("e_ding_dian_ya" . "125V")
  240.         ("zheng_shu_bian_hao" . "TüV 23.1140")
  241.         ("ren_zheng_fan_wei_yan_se" . "")
  242.         ("mo_xing_ming_cheng" . "8字尾")
  243.         ("bei_zhu" . "")
  244.        )
  245.        (("id" . "10")
  246.         ("an_gui_hao" . "HL-061-3")
  247.         ("zhuan_yong_ke_hu" . "")
  248.         ("guo_bie" . "台湾")
  249.         ("guo_bie_biao_zhi" . "BSMI")
  250.         ("zhen_jiao_shu" . "3")
  251.         ("zhi_wan" . "直")
  252.         ("e_ding_dian_liu" . "11A")
  253.         ("e_ding_dian_ya" . "125V")
  254.         ("zheng_shu_bian_hao" . "CI362060510465")
  255.         ("ren_zheng_fan_wei_yan_se" . "")
  256.         ("mo_xing_ming_cheng" . "台规三插")
  257.         ("bei_zhu" . "")
  258.        )
  259.       )
  260.      "mo_xing_ming_cheng"
  261.      nil
  262. )
  263.   |;
  264.   (defun _xz_dcl (lst / f p lst dcl-n file)
  265.     (setq dcl-n "_xz_dcl")
  266.     (SETQ F (VL-FILENAME-DIRECTORY (VL-FILENAME-MKTEMP)))
  267.     (SETQ P (STRCAT F "\\" DCL-N))
  268.     (if  (findfile p)
  269.       (VL-FILE-DELETE P)
  270.     )
  271.     (or  (and (setq w (cdr (assoc "width" lst)))
  272.        (= (type w) 'str)
  273.        (= (type (read w)) 'int)
  274.   )
  275.   (setq w "100")
  276.     )
  277.     (setq lst (list
  278.     "head:list_box {"
  279.     "    is_enabled = false ;"
  280.     "    fixed_height = true ;"
  281.     "    height = 2 ;"
  282.     "    vertical_margin = none ;"
  283.     "    horizontal_margin = none ;"
  284.     "}"
  285.     ""
  286.     "xz:dialog {"
  287.     "            key = \"xz\" ;"
  288.     "    :paragraph {"
  289.     "        :head {"
  290.     "            key = \"h\" ;"
  291.     "        }"
  292.     "        :list_box {"
  293.     "            height = 18 ;"
  294.     "            key = \"d\" ;"
  295.     (strcat "            width = " w " ;")
  296.     "            vertical_margin = none ;"
  297.     "            horizontal_margin = none ;"
  298.     "        }"
  299.     "    }"
  300.     "    :button {"
  301.     "        height = 3 ;"
  302.     "        is_cancel = true ;"
  303.     "        key = \"tc\" ;"
  304.     "        label = \"< < < 返回上一级\" ;"
  305.     "    }"
  306.     "}"
  307.         )
  308.     )
  309.     (setq p nil)
  310.     (setq p (STRCAT f "\\xz.dcl"))
  311.     (if  (setq file (open p "w"))
  312.       (progn
  313.   (foreach line lst
  314.     (write-line line file)
  315.   )
  316.   (close file)
  317.       )
  318.     )
  319.     (if  (findfile p)
  320.       p
  321.       nil
  322.     )
  323.   )
  324.   (defun $xuan-ze-xq$
  325.           (data  /   _xiangqing_dcl     dcl_id
  326.            dqy  i   keys    s     sjs
  327.            startnum  str   str-l
  328.           )
  329.     (defun _xiangqing_dcl (texts / tmp_folder tmp_file tmp_lst)
  330.       (defun $rows$ (texts)
  331.   (mapcar
  332.     (function
  333.       (lambda (a / s)
  334.         (setq
  335.     s
  336.      (mapcar
  337.        (function
  338.          (lambda (b)
  339.            (list
  340.        "        :text {"
  341.        "            fixed_width = true ;"
  342.        (strcat "            label = \""
  343.          (car b)
  344.          "\" ;"
  345.        )
  346.        "            width = 30 ;"
  347.        "            vertical_margin = none ;"
  348.        "            horizontal_margin = none ;"
  349.        "        }"
  350.        "        :text {"
  351.        (strcat "            label = \""
  352.          (cdr b)
  353.          "\" ;"
  354.        )
  355.        "            width = 60 ;"
  356.        "            vertical_margin = none ;"
  357.        "            horizontal_margin = none ;"
  358.        "        }"
  359.            )
  360.          )
  361.        )
  362.        a
  363.      )
  364.         )
  365.         (setq s (apply 'append s))
  366.         (setq s
  367.          (cons "    :concatenation {       fixed_width = true ;"
  368.          s
  369.          )
  370.         )
  371.         (setq
  372.     s
  373.      (append
  374.        s
  375.        (list
  376.          "                        vertical_margin = none ;                        horizontal_margin = none ;    }"
  377.        )
  378.      )
  379.         )
  380.       )
  381.     )
  382.     texts
  383.   )
  384.       )
  385.       (setq tmp_folder (strcat (vl-filename-directory (vl-filename-mktemp))
  386.              "\\"
  387.            )
  388.       tmp_file   (strcat
  389.        tmp_folder
  390.        "xiangqing.dcl"
  391.            )
  392.       )
  393.       (if
  394.   (findfile tmp_file)
  395.    (vl-file-delete tmp_file)
  396.       )
  397.       (setq texts (vl-remove-if-not
  398.         (function (lambda (a) (= (type (cdr a)) 'str)))
  399.         texts
  400.       )
  401.       )
  402.       (if (> (length texts) 70)
  403.   (setq texts (list>Split texts 2))
  404.   (setq texts (mapcar 'list texts))
  405.       )
  406.       (setq tmp_lst
  407.        (append
  408.          (list (LIST "xq:dialog {"))
  409.          (list (list "            label = \"详情预览\" ;"))
  410.          ($rows$ texts)
  411.          (list (LIST "    ok_only;"))
  412.          (list
  413.      (list
  414.        "                        vertical_margin = none ;"
  415.      )
  416.          )
  417.          (list (LIST "}"))
  418.        )
  419.       )
  420.       (setq tmp_lst (apply 'append tmp_lst))
  421.       (if (setq file (open tmp_file "w"))
  422.   (progn
  423.     (cond  ((= (type tmp_lst) 'STR)
  424.      (write-line tmp_lst file)
  425.     )
  426.     ((= (type tmp_lst) 'LIST)
  427.      (foreach line tmp_lst
  428.        (write-line line file)
  429.      )
  430.     )
  431.     )
  432.     (close file)
  433.   )
  434.   (setq tmp_file nil)
  435.       )
  436.           ;(_sensor:lst->dat tmp_file tmp_lst T NIL)
  437.       tmp_file
  438.     )
  439.     (setq s DATA)
  440.     (setq dcl_id (load_dialog (_xiangqing_dcl s)))
  441.     (new_dialog "xq" dcl_id)
  442.     (start_dialog)
  443.     (unload_dialog dcl_id)
  444.   )
  445.   (defun $d$ (data old_time / new_time pass_time pick si)
  446.     (setq new_time (read (substr (rtos (getvar "date") 2 15) 9 6)))
  447.     (setq pass_time (- new_time old_time))
  448.     (setq pick (get_tile "d"))
  449.     (setq pick (atoi pick))
  450.     (setq si (nth pick data))
  451.     (if  (<= pass_time 4)
  452.       ($xuan-ze-xq$ si)
  453.     )
  454.     (list pick new_time)
  455.   )
  456.   (IF (NOT old_time)
  457.     (SETq
  458.       old_time (- (read (substr (rtos (getvar "date") 2 15) 9 6)) 4)
  459.     )
  460.   )
  461.   (setq zds (delsame (mapcar 'car (apply 'append data))))
  462.   (if f-c
  463.     (setq zds (cons f-c (vl-remove f-c zds)))
  464.   )          ;第一列强制
  465.   (setq d nil)
  466.   (setq jz (wire:list-fill-with-title data zds))
  467.   (setq dclid (load_dialog (_xz_dcl lst)))
  468.   (new_dialog "xz" dclid "" (list -1 -1))
  469.   (and label (set_tile "xz" label))
  470.   (addlist "d" (cdr jz))
  471.   (addlist "h" (list (car jz)))
  472.   (action_tile "tc" "(setq pick(get_tile \"d\"))")
  473.   (action_tile
  474.     "d"
  475.     "(mapcar 'set(list 'd 'old_time)($d$ data old_time))"
  476.   )
  477.   (setq startNum (start_dialog))
  478.   (COND ((= STARTNUM 0) (princ)))
  479.   (unload_dialog dclid)
  480.   (if (and pick data)
  481.     (setq si (nth (atoi pick) data))
  482.   )
  483.   si          ;返回给上一级
  484. )


评分

参与人数 1明经币 +1 收起 理由
ssyfeng + 1 很给力!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2024-4-25 13:13 | 显示全部楼层
来学习了                              
发表于 2024-4-25 14:20 | 显示全部楼层
缺少函数:delsame,wire:list-fill-with-title,addlist,list>Split
 楼主| 发表于 2024-4-25 14:58 | 显示全部楼层
ssyfeng 发表于 2024-4-25 14:20
缺少函数:delsame,wire:list-fill-with-title,addlist,list>Split

缺少的函数已经补充了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-4 18:46 , Processed in 0.257498 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表