明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1154|回复: 3

DCL通用函数 求解 求优化

[复制链接]
发表于 2016-5-5 09:40 | 显示全部楼层 |阅读模式
本帖最后由 lea丶丶 于 2016-5-5 10:03 编辑

在前人基础上修改了DCL通用函数,但是为什么radio——button 获得属性值有问题。求优化
  1. (vl-load-com)
  2. ;;;=================================================================*
  3. (defun lea-dcl-init (STR_DIANAME      LST       /
  4.                           LIST->DCL  TEMPFILENAME       F1
  5.                           STR_JG     I    N       DCLID
  6.                           LST_RESULT
  7.                         )
  8.   ;;==================================================================*
  9.   ;;功能:根据控件信息表,生成DCL语言的文本                           *
  10.   ;;      注意,调用参数均为字符串形式                                *
  11.   ;;返回:与控件对应的dcl文本
  12.   (defun LIST->DCL (LST  / X)
  13.     (cond
  14.       ;;写button
  15.       ((wcmatch (car LST) "☆*")
  16.         (strcat
  17.           ":button{"
  18.           (strcat "\nlabel=""
  19.             (nth 0 LST)
  20.             "";"
  21.             "\nis_enabled = false;"
  22.           )
  23.           "\n}\n"
  24.         )
  25.       )
  26.   
  27.       ;;写edit_box
  28.       ((= (nth 2 LST) "int")
  29.         (strcat
  30.           ":edit_box{"
  31.           "\nallow_accept = true ;"
  32.           (strcat "\nedit_width =20"
  33.             ";"
  34.           )
  35.           "\nfixed_width = true ;"
  36.           (strcat "\nkey ="" (CAR N) "";")
  37.           (strcat "\nlabel=""
  38.             (nth 1 LST)
  39.             "";"
  40.           )
  41.           (strcat "\nvalue=""
  42.             (nth 3 LST)
  43.             "";"
  44.           )
  45.           "\n}\n"
  46.         )
  47.       )
  48.       ;;写popup_list
  49.       ((= (nth 2 LST) "poplist")
  50.         (strcat
  51.           ":popup_list{"
  52.           (strcat "\nwidth =20"
  53.             ";"
  54.           )
  55.           (strcat "\nlabel=""
  56.             (nth 1 LST)
  57.             "";"
  58.           )
  59.           (strcat "\nkey ="" (CAR N) "";")
  60.           (cond
  61.             ((= (type (nth 3 LST)) 'STR)
  62.               (strcat "\nlist=""
  63.                 (nth 3 LST)
  64.                 "";"
  65.               )
  66.             )
  67.             ((= (type (nth 3 LST)) 'list)
  68.               (strcat
  69.                 "\nlist=""
  70.                 (apply
  71.                   'strcat
  72.                   (mapcar
  73.                     '(lambda (X)
  74.                        (strcat "\\n"
  75.                          (vl-princ-to-string X)
  76.                        )
  77.                      )
  78.                     (nth 3 LST)
  79.                   )
  80.                 )
  81.                 "";"
  82.               )
  83.             )
  84.             ((= (type (nth 3 LST)) 'SYM)
  85.               (strcat
  86.                 "\nlist=""
  87.                 (apply
  88.                   'strcat
  89.                   (mapcar
  90.                     '(lambda (X)
  91.                        (strcat "\\n"
  92.                          (vl-princ-to-string X)
  93.                        )
  94.                      )
  95.                     (eval (nth 3 LST))
  96.                   )
  97.                 )
  98.                 "";"
  99.               )
  100.             )
  101.           ) ;_结束 cond
  102.           "\n}\n"
  103.         )
  104.       )
  105.       ;;
  106.       ((= (nth 2 LST) "list")
  107.         (strcat
  108.           ":list_box{"
  109.           (strcat "\nwidth ="(nth 4 lst)
  110.             ";"
  111.           )
  112.           (strcat "\nheight =" (nth 5 lst)
  113.             ";"
  114.           )
  115.           (strcat "\nlabel=""
  116.             (nth 1 LST)
  117.             "";"
  118.           )
  119.           (strcat "\nkey ="" (CAR N) "";")
  120.           (cond
  121.             ((= (type (nth 3 LST)) 'STR)
  122.               (strcat "\nlist=""
  123.                 (nth 3 LST)
  124.                 "";"
  125.               )
  126.             )
  127.             ((= (type (nth 3 LST)) 'list)
  128.               (strcat
  129.                 "\nlist=""
  130.                 (apply
  131.                   'strcat
  132.                   (mapcar
  133.                     '(lambda (X)
  134.                        (strcat "\\n"
  135.                          (vl-princ-to-string X)
  136.                        )
  137.                      )
  138.                     (nth 3 LST)
  139.                   )
  140.                 )
  141.                 "";"
  142.               )
  143.             )
  144.             ((= (type (nth 3 LST)) 'SYM)
  145.               (strcat
  146.                 "\nlist=""
  147.                 (apply
  148.                   'strcat
  149.                   (mapcar
  150.                     '(lambda (X)
  151.                        (strcat "\\n"
  152.                          (vl-princ-to-string X)
  153.                        )
  154.                      )
  155.                     (eval (nth 3 LST))
  156.                   )
  157.                 )
  158.                 "";"
  159.               )
  160.             )
  161.           ) ;_结束 cond
  162.           "\n}\n"
  163.         )
  164.       )
  165.       ;;
  166.       ((= (car LST) "text")
  167.         (strcat
  168.           ":text{"
  169.           (strcat "\nlabel=""
  170.             (nth 1 LST)
  171.             "";"
  172.           )
  173.           "\n}\n"
  174.         )
  175.       )
  176.        ;;
  177.       ((= (nth 1 LST) "radio_button")
  178.       (strcat "\nkey ="" (CAR N) "";")
  179.         (strcat
  180.           ":radio_button{"
  181.           (strcat "\nlabel=""
  182.             (nth 2 LST)
  183.             "";"
  184.           )
  185.           "\n}\n"
  186.         )
  187.       )
  188.       ;;
  189.       ((= (car LST) "spacer_1")
  190.         (strcat "\n"
  191.           (nth 0 LST)
  192.           ";\n"
  193.         )
  194.       )
  195.       ;;
  196.       ((= (car LST) "boxed_column")
  197.         (strcat
  198.           ":boxed_column{"
  199.           (strcat "\nlabel=""
  200.             (nth 1 LST)
  201.             "";"
  202.           )
  203.           "\n"
  204.         )
  205.       )
  206.       ;;
  207.       ((= (car LST) "boxed_radio_row")
  208.         (strcat
  209.           ":boxed_radio_row{"
  210.           (strcat "\nlabel=""
  211.             (nth 1 LST)
  212.             "";"
  213.           )
  214.           "\n"
  215.         )
  216.       )
  217.       ((= (car LST) "}")
  218.         (strcat
  219.           "\n}\n"
  220.         )
  221.       )
  222.       ;;;      ((/= (LIST->DCL (cons "editbox" LST) KEY_I) "")
  223.       ;;;       (LIST->DCL (cons "editbox" LST) KEY_I)
  224.       ;;;      )
  225.       (t "")
  226.     ) ;_结束 cond
  227.   ) ;_结束defun
  228.   ;;==================================================================*
  229.   ;;功能:定义按下确定按钮后的操作
  230.   
  231. (defun getinput  (lst / i n tmp)
  232.   (setq i 0)
  233.   (repeat (length lst)
  234.     (setq n (nth i lst)
  235.     i (1+ i)
  236.     )
  237.     (cond
  238.       ((= (nth 2 n) "int")
  239.      (set (read (car n)) (atof (get_tile (car n))))
  240.     )
  241.       ;;
  242.      ((= (nth 1 n) "radio_button")
  243.      (set (read (car n)) (get_attr (car n) "label"));此处获得属性值哪里出问题了
  244.     )
  245.       ;;
  246.     ((= (nth 2 n) "poplist")
  247.      (setq tmp (nth 3 n))
  248.      (cond ((= (type (nth 3 n)) 'str)
  249.       (setq tmp "*inputbox函数有待完善*")
  250.      )
  251.      ((= (type (nth 3 n)) 'list)
  252.       (set (read (car n))
  253.             (nth (atoi (get_tile (car n))) tmp)
  254.       )
  255.      )
  256.         ((= (type (nth 3 n)) 'sym)
  257.       (set (read (car n))
  258.             (nth (atoi (get_tile (car n))) (eval tmp))
  259.       )
  260.      )
  261.       
  262.      )
  263.     )
  264.   ;;
  265.       ((= (nth 2 n) "list")
  266.      (setq tmp (nth 3 n))
  267.      (cond ((= (type (nth 3 n)) 'str)
  268.       (setq tmp "*inputbox函数有待完善*")
  269.      )
  270.      ((= (type (nth 3 n)) 'list)
  271.       (set (read (car n))
  272.            (atof (nth (atoi (get_tile (car n))) tmp))
  273.       )
  274.      )
  275.         ((= (type (nth 3 n)) 'sym)
  276.       (set (read (car n))
  277.             (nth (atoi (get_tile (car n))) (eval tmp))
  278.       )
  279.      )
  280.       
  281.      )
  282.     )
  283.       ;
  284.     )
  285.   )
  286. )
  287.   ;_结束defun
  288.   ;;==================================================================*
  289.   (setq TEMPFILENAME (vl-filename-mktemp "dcltmp.dcl"))
  290.   (setq F1 (open TEMPFILENAME "w"))
  291.   
  292.   ;;组织头部
  293.   (setq  STR_JG (strcat
  294.                  "InputBox:dialog {"
  295.                  (strcat "\nlabel ="" STR_DIANAME "";")
  296.                )
  297.   )
  298.   ;;组织正文
  299.   (setq I 0)
  300.   (repeat (length LST)
  301.     (setq N (nth I LST))
  302.     (setq STR_JG (strcat STR_JG
  303.                    (LIST->DCL N )
  304.                  )
  305.     )
  306.     (setq I (1+ I))
  307.   )
  308.   
  309.   ;;组织按钮
  310.   (setq  STR_JG
  311.     (strcat STR_JG
  312.       "\nspacer_0;"
  313.       "\nok_cancel;\n}\n"
  314.     )
  315.   )
  316.   ;;写入文件
  317.   (princ STR_JG F1)
  318.   ;;关闭文件
  319.   (close F1)
  320.   (setq DCLID (load_dialog TEMPFILENAME))
  321.   (if (not (new_dialog "InputBox" DCLID ""))
  322.     (progn (alert "对话框加载失败!") (exit))
  323.   )
  324.   (action_tile
  325.     "accept"
  326.     "(GetInput  Lst ) (done_dialog 1)"
  327.   )
  328. (start_dialog)
  329.   (unload_dialog DCLID)
  330.   (vl-file-delete TEMPFILENAME)
  331.   ;;返回

  332. )
  333. ;(lea-dcl-init  "图库"
  334. ;                '(  ("boxed_column" "文件")
  335. ;                    ("blockname"  "名称" "list" allfile1 "40" "40");40宽度  40高度  
  336. ;                    ("}")
  337. ;                     ("boxed_radio_row" "分类")
  338. ;                    ("txt" "radio_button" "电气")
  339. ;                    ("txt" "radio_button" "土建")  
  340. ;                     ("}")  )
  341. ;  )
 楼主| 发表于 2016-5-5 11:34 | 显示全部楼层
竟然没人呢
发表于 2016-5-6 00:39 | 显示全部楼层
1. (strcat "\nkey =\"" (CAR N) "\";") 这里有几处有问题,应该是  (strcat "\nkey =\"" (CAR LST) "\";")

2. ((= (nth 1 LST) "radio_button")
      (strcat "\nkey =\"" (CAR N) "\";")
        (strcat
          ":radio_button{"
          (strcat "\nlabel=\""
......
key 同1点问题,位置也放错了,应该是
((= (nth 1 LST) "radio_button")
        (strcat
          ":radio_button{"
          (strcat "\nkey =\"" (CAR N) "\";")
          (strcat "\nlabel=\""

3. (set (read (car n)) (get_attr (car n) "label"));此处获得属性值哪里出问题了
改为 (set (read (car n)) (atof (get_tile (car n))))

4.(setq tmp "*inputbox函数有待完善*")
改为 (set (read (car n)) tmp)

评分

参与人数 1明经币 +1 收起 理由
USER2128 + 1 乐于助人

查看全部评分

 楼主| 发表于 2016-5-6 15:21 | 显示全部楼层
xiaolong1487 发表于 2016-5-6 00:39
1. (strcat "\nkey =\"" (CAR N) "\";") 这里有几处有问题,应该是  (strcat "\nkey =\"" (CAR LST) "\";") ...

谢谢,这错误真是不该犯的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-3-29 02:43 , Processed in 0.202581 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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