; 由离散点生成三角网[mini_triangle].lsp


(or mai_cehui_gcd_blk
	(mai_load_files (mai_panel_search "谜你测绘功能设置文件.lsp"))
)

; (defun c:mini_triangle ( / old_cmd t0 sss pts)
	; (mai_start nil)
	; (mai_last_com "mini_triangle")
	; (setq t0 (car (mai_entsel nil "选择一个实体并获得块或点的图层名:" "选择的不是实体." '((0 . "insert,point")) nil)))
	; (or t0 (exit))
	; (setq pts
			; (mai_select_first
				; (list (cons 0 "insert,point") (assoc 8 (entget t0)))
				; "选择要由离散点生成三角网triangle地形的块或点:<回车退出>"
				; "没有找到任何块或点."
			; )
	; )
	; (princ "\n数据处理中......")
	; (setq t0 (getvar "TDUSRTIMER"))
	; (setq
		; pts (mapcar '(lambda(x)(setq x (entget x))(trans (mai_dxf 10 x) (mai_dxf 210 x) 1 T)) (mai_ssget_2_list pts))
		; sss (mai_points_triangle pts)
	; )
	; (princ (strcat "\n用时" (rtos (* (- (getvar "TDUSRTIMER") t0) 86400) 2 4) "秒"))
	; (apply 'mai_create_layer mai_triangle_layer)
	; (mapcar '(lambda (x) (mai_a_triangle (mapcar '(lambda (y)(nth y pts)) x) nil T)) sss)
	; (princ (strcat "\n用时" (rtos (* (- (getvar "TDUSRTIMER") t0) 86400) 2 4) "秒"))
	; (mai_end)
; )

; (defun c:mini_old_triangle ( / old_cmd t0 ss pts)
	; (mai_start nil)
	; (mai_last_com "mini_old_triangle")
	; (setq t0 (car (mai_entsel nil "选择一个实体并获得块或点的图层名:" "选择的不是实体." '((0 . "insert,point")) nil)))
	; (or t0 (exit))
	; (setq pts
			; (mai_select_first
				; (list (cons 0 "insert,point") (assoc 8 (entget t0)))
				; "选择要由离散点生成三角网triangle地形的块或点:<回车退出>"
				; "没有找到任何块或点."
			; )
	; )
	; (princ "\n数据处理中......")
	; (setq
		; pts (mapcar '(lambda(x)(setq x (entget x))(trans (mai_dxf 10 x) (mai_dxf 210 x) 1 T)) (mai_ssget_2_list pts))
		; ss (mai_points_triangle pts)
	; )
	; (apply 'mai_create_layer mai_triangle_layer)
	; (mapcar '(lambda (x) (mai_a_triangle (mapcar '(lambda (y)(nth y pts)) x) nil T)) ss)
	; (mai_end)
; )

(defun c:mini_triangle ( / old_cmd cfgname mai_sym_list stop mm nn ss pts old_pwidth chk
							gcd_blk_lay gcd_blk gcd_tin gcd_tin_style gcd_dgx gcd_dgx_hight gcd_dgx_style

						)
	(mini_start nil)
	(mai_last_com "mini_triangle")
	(setq
		cfgname (mai_fix_dir1 (strcat mai_mini_path "Plus_lib\\迷你收录插件\\测绘\\mini_triangle.cfg"))
		mai_sym_list
			(list
				(list 'gcd_blk_lay		mai_cehui_gcd_blk)
				(list 'gcd_blk			mai_cehui_gc_blkname)
				(list 'gcd_tin			mai_cehui_tin)				;三角网所在图层及颜色
				(list 'gcd_tin_style	"3DFACE")					;三角网所在图层及颜色
				(list 'gcd_dgx 			mai_cehui_dgx)         ;等高线所在图层及颜色
				(list 'gcd_dgx_hight 	1)        			 ;等高线所在图层及颜色
					(list 'gcd_dgx_style 	"1")
			)
	)
	(mai_read_config cfgname mai_sym_list 'mai_triangle_op)
	(setq
		mm (mai_dcl_model1
				(list (list "-15" ))
				0
				"【点生三角网，等高线，凸包】"
				(list 1 1 45 0.01 -15 nil nil)
				(list
					(list "" 1 40)
					(list "高程图层:" "get_layer" gcd_blk_lay)
					(list "高程点块:" "get_block" gcd_blk)
					(list "三角网层:" "get_layer" gcd_tin)
					(list "三角网实体类型:" (list "radio" "3DFACE" "3DPOLWLINE") gcd_tin_style)
					(list "等高线层:" "get_layer" gcd_dgx)
					(list "等高线高差:" (list "get_dist" 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5) gcd_dgx_hight)
					(list "曲线拟合等高线" "toggle" gcd_dgx_style)
					(list "" "text" T)
					(list "由高程块或点生成三角网---------->>" "get_done" T)
					(list "由高程块或点生成三角网和等高线-->>" "get_done" T)
					(list "由高程块或点生成凸包------------>>" "get_done" T)
					(list "" "text" T)
					(list "按Ｚ坐标设置高程块属性---------->>" "get_done" T)
					(list "按块属性设置高程块Ｚ坐标-------->>" "get_done" T)
					(list "高程块Ｚ坐标改为０-------------->>" "get_done" T)
				)
				nil
				nil
			)
		nn (cadddr mm)
		mm (cadr mm)
		old_pwidth (getvar "plinewid")
	)
	(or mm (exit))
	(mapcar '(lambda(x y) (set (car x) y)) mai_sym_list mm)
	(mai_write_config cfgname mai_sym_list 'mai_triangle_op)
	(setvar "plinewid" 0)
	(if (member nn (list 9 9 10 12))
		(setq
			ss (mai_select_first
					(list
						(cons -4 "<OR")
							(cons -4 "<AND") (cons 0 "insert") (cons 2 gcd_blk) (cons -4 "AND>")
							(cons -4 "<AND") (cons 0 "point") (cons 8 (car gcd_blk_lay)) (cons -4 "AND>")
						(cons -4 "OR>")
					)
					"选择高程块或点:<回车退出>"
					"没有找到任何块或点."
				)
			ss (mai_ssget_2_list ss)
		)
	)
	(cond
		(	(< 8 nn 11)
			(princ "\n三角网数据处理中......")
			(setq
				old_chk_time (getvar "millisecs")
				pts (mapcar '(lambda(x)(setq x (entget x))(trans (mai_dxf 10 x) (mai_dxf 210 x) 1 T)) ss)
				ss (mai_points_triangle pts)
				chk (entlast)
			)
		(progn (setq
					old_chk_time (/ (- (getvar "millisecs") old_chk_time) 1000)
					mm (rtos (fix (/ old_chk_time 60)) 2 0)
					old_chk_time (rtos (rem old_chk_time 60) 2 0)
				)
				(princ (strcat "\n 耗时 " (if (= mm "0") "" (strcat mm " 分钟 ")) old_chk_time " 秒."))
		)
			(apply 'mai_create_layer gcd_tin)
			(mapcar '(lambda (x) (mai_a_triangle (mapcar '(lambda(y)(nth y pts)) x) nil (eq "3DFACE" gcd_tin_style))) ss)
			(if (= nn 9)
				(progn
					(princ "\n等高线数据处理中......")
					(apply 'mai_create_layer gcd_dgx)
					(setq
						pts (mapcar
								'(lambda (x)(setq x (entget x)) (mai_remove_same (list (mai_dxf 10 x)(mai_dxf 11 x)(mai_dxf 12 x)(mai_dxf 13 x))))
								(mai_ssget_2_list (mai_newset chk))
							)
						chk (entlast)
					)
					(mai_faces_elev pts gcd_dgx_hight)
					(and
						(= gcd_dgx_style "1")
						(setq ss (mai_ssget_2_list (mai_newset chk)))
						(foreach pts ss (command "_.pedit" pts "F" ""))
					)
				)
			)
		)

		(	(= 11 nn)
			(princ "\n凸包数据处理中......")
			(setq
				ss (mapcar '(lambda (x)(trans (mai_dxf 10 x) 0 1)) ss)
				ss (mai_points_hull ss T)
			)
			(mai_entmake "polyline" (cons (last ss) ss))
		)

		(	(= 13 nn)
			(mapcar
				'(lambda(x / att txt elst )
					(setq
						att (entget x)
						txt (rtos (caddr (trans (mai_dxf 10 att) (mai_dxf 210 att) 0 T)) 2 2)
						att (vl-string-search "." txt)
						txt (if att
								(substr (strcat txt "00") 1 (+ 3 att))
								(strcat txt ".00")
							)
						att (caar (mai_get_blk_atts x nil))
					)
					(if att
						(progn
							(setq
								elst (entget att)
								elst (subst (cons 2 txt) (assoc 2 elst) elst)
							)
							(entmod elst)
							(entupd att)
						)
					)
				)
				(vl-remove-if '(lambda(x)(= (mai_dxf 0 x) "POINT")) ss)
			)
		)

		(	(= 14 nn)
			(mapcar
				'(lambda(x / att txt elst nor pt1 pt2 )
					(setq
						elst (entget x)
						att (caddar (mai_get_blk_atts x nil))
					)
					(if att
						(progn
							(setq
								nor (mai_dxf 210 elst)
								pt1 (trans (mai_dxf 10 elst) nor 0 T)
								pt2 (list (car pt1) (cadr pt1) (atof att))
								pt2 (trans pt2 0 nor T)
								elst (subst (cons 10 pt2) (assoc 10 elst) elst)
							)
							(entmod elst)
						)
					)
				)
				(vl-remove-if '(lambda(x)(= (mai_dxf 0 x) "POINT")) ss)
			)
		)
		(	(= 14 nn)
			(mapcar
				'(lambda(x / att elst nor pt1 pt2 )
					(setq
						elst (entget x)
						nor (mai_dxf 210 elst)
						pt1 (trans (mai_dxf 10 elst) nor 0 T)
						pt2 (list (car pt1) (cadr pt1) 0)
						pt2 (trans pt2 0 nor T)
						elst (subst (cons 10 pt2) (assoc 10 elst) elst)
					)
					(entmod elst)
				)
				(vl-remove-if '(lambda(x)(= (mai_dxf 0 x) "POINT")) ss)
			)
		)
	)
	(mai_end)
)
