- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
用OPENDCL制作一个对话框,返回需要的层表给后续LISP调用。
演示:
很简单的一个对话框,使用了最基本的ListBox,CheckBox,Image Button,程序能很方便快捷的根据你的需要返回需要的层表。
1、程序开始,常规的调用Oninitialize ,由于我们程序中有关闭对话框拾取图层的需要,所以对话框恢复显示后,要初始化一些数据。
[pcode=lisp,true]
(defun c:LayerListForm_OnInitialize ( / a all b n pos)
(dcl_Control_SetValue SelAllCheck 0) ;; 全选的checkbox 清空
(setq all ($xdob_layer_GetAllLayer)) ;;lisp函数,获得所有的层表
(setq all (vl-sort all '(lambda (a b) ;; 图层排序
(< (ascii a) (ascii b))
)
)
)
(dcl_ListBox_Clear LayerList) ;;清空列表框
(dcl_ListBox_AddList LayerList all) ;;图层字符串表添加到listbox显示
(if $xdob_layer_hadlayerlist
(progn
(foreach n $xdob_layer_hadlayerlist ;;保存我们选择项的表
(setq pos (- (length (dcl_control_getlist LayerList))(length (member n (dcl_control_getlist LayerList)))))
(if (>= pos 0)
(dcl_ListBox_SelectItem LayerList pos t) ;;根据选择的项目,亮显
)
)
)
)
(if (= (length (dcl_control_getlist LayerList))(length (dcl_ListBox_GetSelectedItems LayerList))) ;;当LISTBOX的所有项目数量和量显的选择项目相同时候,全选框勾选。
(dcl_Control_SetValue SelAllCheck 1)
)
)
[/pcode]
2、当listbox里面选项变化的时候,因为我们设计LISTBOX时候是可以多选的,如果全选上了,那么就要变换 全选 checkbox的状态,代码如下:
[pcode=lisp,true]
(defun c:LayerList_OnSelChanged (ItemIndexOrCount Value /)
(if (= ItemIndexOrCount (length (dcl_Control_GetList LayerList)))
(dcl_Control_SetValue SelAllCheck 1)
(dcl_Control_SetValue SelAllCheck 0)
)
(dcl_Control_SetValue UnSelCheck 0)
)
[/pcode]
3、当我们勾选全选checkbox的时候要相应的事件,如果全选勾上,则listbox框里面的所有图层亮显选择。同时设置 反选 checkbox。
[pcode=lisp,true]
(defun c:SelAllCheck_OnClicked (Value /)
(if (= 1 value)
(dcl_ListBox_SelItemRange LayerList 0 (1- (length (dcl_Control_GetList LayerList))) T)
(dcl_ListBox_SelItemRange LayerList 0 (1- (length (dcl_Control_GetList LayerList))) nil)
)
(dcl_Control_SetValue UnSelCheck 0)
)
[/pcode]
4、下面是 反选 checkbox 相应的事件处理函数
[pcode=lisp,true]
(defun c:UnSelCheck_OnClicked (Value / n selindexlist)
(setq selIndexList (dcl_ListBox_GetSelectedNths LayerList))
(dcl_ListBox_SelItemRange LayerList 0 (1- (length (dcl_Control_GetList LayerList))) T)
(foreach n selIndexList
(dcl_ListBox_SelectItem LayerList n nil)
)
(setq selIndexList (dcl_ListBox_GetSelectedNths LayerList))
(cond
((= 0 (length selIndexList))
(dcl_Control_SetValue SelAllCheck 0)
)
((= (length (dcl_Control_GetList LayerList)) (length selIndexList))
(dcl_Control_SetValue SelAllCheck 0)
)
)
)
[/pcode]
5、拾取按钮选择的时候的响应事件处理函数。因为要到图中选择实体确定图层,所以要关闭模式对话框。
[pcode=lisp,true]
(defun c:PickSel_OnClicked (/)
(setq $xdob_layer_hadlayerlist (dcl_ListBox_GetSelectedItems LayerList)) ;;保存当前我们已经选好的图层
(dcl_Control_SetValue UnSelCheck 0)
(dcl_form_close LayerListForm 5) ;; 关闭对话框,带参数5,下面介绍。
)
[/pcode]
6、按下OK按钮和退出按钮时候的事件处理函数
[pcode=lisp,true]
(defun c:CQuit_OnClicked (/)
(dcl_Form_Close LayerListForm 4) ;;关闭对话框,带参数4
)
(defun c:ok_OnClicked (/)
(if (> (dcl_ListBox_GetSelCount LayerList) 0)
(progn
(dcl_Form_Close LayerListForm 3) ;;关闭对话框,带参数3
(setq lyrl (dcl_ListBox_GetSelectedItems LayerList))
)
(dcl_MessageBox "请选择图层。" "晓东温馨提示" 2 3)
)
)
[/pcode]
7、主程序,因为我们要关闭对话框拾取实体确定图层,确定后,还要返回对话框,所以用了一个循环结构不断的循环,直到关闭对话框参数是3或者4的时候才结束循环,退出程序。
下面代码是典型的处理临时关闭对话框,操作后再返回对话框的结构循环。
[pcode=lisp,true]
(setq lxd (dcl_Project_Load (*ODCL:Samples:FindFile "XDOB_DCL.odcl") t ))
(setq doContinue T)
(while doContinue
;; However, to avoid an endless loop, the condition for repeating the loop, must negate at first
;; The condition will be "activated" again after dcl_form_show for some cases.
(setq doContinue nil)
;; if the dialog get closed, the function returns a value
;; This is 1 for OK (reserved value), 2 for ESC or Cancel (reserved value)
;; or the value, which was given to dcl_form_close
(setq intResult (dcl_form_show LayerListForm))
;; This is a modal form, so (dcl_Form_Show) does not return until
;; the modal form is closed. In the meantime, the event handlers
;; manage the form.
;; Now the return value can be interpreted
(cond
;; close-button
;; Here something can be done with the selected points ans objects
((= intResult 1) (setq doContinue nil))
;; ESC key
((= intResult 2) (setq doContinue nil))
;; point selection
((= intResult 3) (setq doContinue nil) ;;结束循环
)
((= intResult 4) (setq doContinue nil) ;; 结束循环
)
((= intResult 5)
(setq $xdob_layer_hadlayerlist (xdrx_string_tok (point_selection) ",")) ;;拾取按钮时候进入这里处理,处理完因为条件不满足继续返回对话框
)
); cond
); while
[/pcode]
程序的主要代码就上面那些了,通过这个程序可以学会如何处理临时关闭对话框,再打开的技巧和一些LISTBOX基本操作的技巧。
|
评分
-
参与人数 1 | 威望 +1 |
D豆 +5 |
贡献 +1 |
收起
理由
|
牢固
| + 1 |
+ 5 |
+ 1 |
很给力!经验;技术要点;资料分享奖! |
查看全部评分
|