;;
;;平面裁图：固定长度裁图和裁图线裁图 by 董冠军$
;;
;;---------------------------[函数列表]----------------------**
;;执行函数:
;;	(pmctinps)
;;公用函数:
;;	($p_to_e        w_fprm  w_bprm  glb     512 )
;; 	(&pp_zxpx2      ent_zhx                     )
;; 	(&pp_tqzhpxb    ent_zhx                     )
;; 	(&cal_ptzh      pt      lst_zhx             )
;;  (zh_get_pde     zh      w_lnkb  w::prec     )
;; 	(zhx_get_inter  ent     w_lnkb              )   ;;(见文件sup\pppp.lsp)
;; 	(zhx_get_minmax lst_zhx                     )   ;;(见文件sup\pppp.lsp)
;;  (hztk_          mode    width   higth   pt  )
;;  (get_dwgdir)
;;  (pingmianchaitu lst_pmctcs_def)
;;
;;辅助函数:
;;	(pmct_get_lst_pt zh_beg zh_end w_lnkb width )
;;	(get_ll_ur lst_pt )
;;	(get_standard_tf lst_pt mode )
;;	(hide_vp_frame ss_vp )
;;-----------------------------------------------------------**
;;
;;
(defun pmctinps ( / glb w_fprm w_bprm w_sele )
;;---------------------------[函数说明]----------------------**
;;函数功能: 布局方式平面裁图: 固定长度/裁图线两种方式        **
;;参数说明:
;;返 回 值: 无                                               **
;;备    注:
;;-----------------------------------------------------------**
	(hy_set0 )
	(setvar "regenmode" 1 )
	
	;;(#ppls    "@hztk"   )
	;;(#ppls    "&pp_jbfy")
	(#ppls "pppp"  )
	(if (null &pp_zxpx2     ) (#ppls "&@pp_zxp") )
	(if (null zhx_get_minmax) (#ppls "pppp"    ) )
	(if (null zhx_get_inter ) (#ppls "pppp"    ) )
	
	;;(tocom )
	(if (/= (getvar "tilemode") 1) (command "_.MODEL") )
	
	(setq glb '((-4 . "<or") (8 . "AXIS") (8 . "SW*") (-4 . "or>")
              (-4 . "<or") (-3 ("DLZH_*")) (-3 ("GDZH_*")) (-4 . "or>")) )
	(setq w_fprm "\n 回车退出 / 点取要进行平面裁图的桩号线:" )
	(setq w_bprm "\n 请点取已定义桩号的道路中心线或管线:" )
	
	(setq w_sele ($p_to_e w_fprm w_bprm glb 512) )

	;;说明: w_sele -- (选中的桩号线 选取点), 否则，nil$
	(if (= w_sele nil)
		(prompt "\n 图面没有或没选择桩号线不能进行自动裁图。" )
		(pmctinps_proc (car w_sele) )
	)
	(hy_set1)
	(setvar "regenmode" 0)
	(princ)
) ;end of defun
;;
;;
(defun pmctinps_proc ( ent_zhx /			
			sca ps_nam  lay_ctx n_column hig_txt lst_pmctcs_def			
			ii tt tt2 size count pt ang lst	isvalid isfixed isend			
			lst_zhx w_lnkb lst_zh lst_pt lst_clip lst_wid lst_pmctcs			
			ent_vp ent_pline ss_vp  ss_ctx
			width_tk wid_tk wid_right wid_all
			higth_tk hig_tk hig_top   hig_all
			dist_overlap dist_extend_beg dist_extend_end
			ang_beg ang_end ang_rot n_frame n_subgraph
			pt_beg pt_end pt_xx pt_yy pt_ll pt_lr pt_ul pt_ur pt_ori pt_ins pt_tk
			width_road mode_tk zh zh_min zh_max zh_beg zh_end num_zh_per
		)
;;---------------------------[函数说明]----------------------**
;;函数功能: 布局方式平面裁图的处理过程                       **
;;参数说明:
;;返 回 值: 无                                               **
;;备    注:
;;-----------------------------------------------------------**

	;$$--常量定义--$$
	(setq ps_nam   "平面裁图"        ;布局名$
				lay_ctx  "hy-ctx"          ;裁图线图层$
				n_column 6                 ;各列放置的分图数目$
				sca      (/ (DL_GetDrawingScale) 1000.0)             ;出图比例$
				hig_txt  (* sca (DL_GetTextHeight) ) ;文本高度$
	) ;setq

	(setq lst_zhx (&pp_zxpx2 ent_zhx) )	
	(if (/= lst_zhx nil)
		(progn

			;;得到最小、最大桩号$
			(setq tt     (zhx_get_minmax lst_zhx) )

			(setq zh_min (car  tt) zh_max (cadr tt) )			

			;;从文件中读取重叠长度和延伸长度$
			(setq dist_overlap    5)
			(setq dist_extend_beg 20)
			(setq dist_extend_end dist_extend_beg               )
			;;调出对话框，得到有效的分图参数(/或)图框参数$
			(setq isvalid nil lst_pmctcs nil )
			(while (not isvalid)
				(setq isvalid t )
				(#ppas  "hyGX_PMCT")
				(setq lst_pmctcs_def (list "横式" "A2" "0" 594.0 420.0 50.0 zh_min 1 200.0
											"固定长度" dist_overlap dist_extend_beg dist_extend_end 1)	) ;新增参数，By DGJ 2004.01.12$
				(setq lst_pmctcs     (pingmianchaitu lst_pmctcs_def) )
				(#ppuas "hyGX_PMCT")
				(setq nTq (nth 13 lst_pmctcs))
				(if lst_pmctcs ;Otherwise, Button "Cancel" is pressed, exit!
					(progn
						(setq mode_tk         (nth 0  lst_pmctcs)
								  width_tk        (nth 3  lst_pmctcs)
								  higth_tk        (nth 4  lst_pmctcs)
					        width_road      (nth 5  lst_pmctcs)
								  zh_beg          (nth 6  lst_pmctcs)
					        n_subgraph      (nth 7  lst_pmctcs)
								  num_zh_per      (nth 8  lst_pmctcs)
					 				isfixed         (nth 9  lst_pmctcs) ;$以下为新增参数$
									dist_overlap    (nth 10 lst_pmctcs)
							   	dist_extend_beg (nth 11 lst_pmctcs)
							  	dist_extend_end (nth 12 lst_pmctcs)
					  ) ;setq

					 ;$$--1--$$
					 ;
					 (if (= isfixed "固定长度")
						 (setq isfixed t  )
						 (setq isfixed nil)
					 )
					 (if (= mode_tk "横式")
					   (setq mode_tk 0 )
					   (setq mode_tk 1 )
					 )

					 ;$$--2--$$
					 ;
					 (if (= n_subgraph nil) (setq n_subgraph 1) )

					 ;$$--3--$$
					 ;
					 (cond
						 ((<  zh_beg zh_min )	(setq zh_beg zh_min) )
						 ((>= zh_beg zh_max)
							(prompt "\n 警告：起始桩号无效，重新输入!" )
							(princ)
							(setq isvalid nil)
						 )
					 ) ;cond
					) ;progn
				) ;if lst_pmctcs
			) ;while (not isvalid)

			(if lst_pmctcs
				(progn
					(setq w_lnkb (&pp_tqzhpxb ent_zhx) )
					;$$--求取桩号列表--$$
					;
					(setq lst_zh nil)
					(if isfixed						
						(progn  ;$固定长度方式裁图$
							(setq isend nil zh zh_beg )
							(setq lst_zh (append lst_zh (list zh)) )
							(setq zh (- zh_beg dist_extend_beg) )
							(while (not isend)
								(setq zh  (+ zh num_zh_per))
								(if (>= zh zh_max)
									(setq zh zh_max isend t)
									(progn
										(setq zh  (- zh (* 2.0 dist_overlap)) )
										(setq lst_zh (append lst_zh (list zh)) )
									)
								)
							) ;while (not isend)
						) ;progn
						(progn  ;$裁图线方式裁图$
							(prompt "\n 空选或回车退出 / 选择裁图线:")
							(setq ss_ctx (ssget (list (cons 8 lay_ctx) '(0 . "line"))) )
							(if ss_ctx
								(progn
									(setq ii 0 )
									(repeat (sslength ss_ctx)
										;;求该剪裁线与道路中心线的交点, 若无, 忽略该剪裁线$
										(setq pt (zhx_get_inter (ssname ss_ctx ii) w_lnkb) )
										;;由交点反求桩号,加入桩号列表$
										(if pt (setq lst_zh (append lst_zh (list (&cal_ptzh pt lst_zhx)))) )
										(setq ii (+ ii 1) )
									)	;repeat (sslength ss_ctx)
									(setq lst_zh (vl-sort lst_zh '<) ) ;桩号从小到大排序$
									(setq ss_ctx nil) ;Release ss_ctx$
								) ;progn
							) ;if ss_ctx
						) ;progn
					) ;if isfixed

					;; (处理桩号列表，如相邻桩号之差小于 zh_diff , 则忽略之)
					(setq count 0 lst nil zh_diff 20.0 )
					(if  isfixed
						(progn
							(repeat (length lst_zh)
								(setq zh_beg (nth count       lst_zh) )
							  	(if (<= (- zh_beg zh_min) 0.001)
									(setq zh_end (+ zh_beg (- num_zh_per dist_extend_beg)) )
									(setq zh_end (+ zh_beg num_zh_per) )
								)
							  	(if (>= zh_end zh_max) (setq zh_end zh_max))
								(if (>= (- zh_end zh_beg) zh_diff) (setq lst (append lst (list (list zh_beg zh_end)))) )
								(setq count  (+ count 1) )
							)
						)
						(progn
							(repeat (- (length lst_zh) 1)
								(setq zh_beg (nth count       lst_zh) )
								(setq zh_end (nth (+ count 1) lst_zh) )
								(if (>= (- zh_end zh_beg) zh_diff) (setq lst (append lst (list (list zh_beg zh_end)))) )
								(setq count  (+ count 1) )
							)
						)
					)
					(setq lst_zh lst)
					
					;; 若所求桩号列表有效 ;;
					;;
					(if lst_zh
						(progn
							;; 若指定布局还不存在,创建之; 切换到该布局 ;;
							(if (= (member ps_nam (layoutlist)) nil) (command "_.LAYOUT" "N" ps_nam) )
							(command "_.LAYOUT" "S" ps_nam )
							
							(setq pt_ori (getpoint "\n 指定第一幅图的左下角点<0.0,0.0,0.0>:") )
							(if (= pt_ori nil) (setq pt_ori '(0.0 0.0 0.0)) )

							;; (开始裁图)
							(setq ss_vp     (ssadd) ;( 由各分图所在视口构成的选择集) 
										count     0  			;( 循环计数器 )
										lst_wid   nil
										wid_all   0.0 )
							(setq n_frame  (length lst_zh) )
							(zh_get_dimcfg)						
							(repeat n_frame
								(setq zh_beg (car  (nth count lst_zh)) )
								(setq zh_end (cadr (nth count lst_zh)) )

								(setq lst    (zh_get_pde zh_beg w_lnkb w::prec) )
								(setq	pt_beg (car   lst) )
								(setq lst    (zh_get_pde zh_end w_lnkb w::prec) )
								(setq	pt_end (car   lst) )
								(setq ang    (angle pt_beg pt_end) )

								(setq lst    (pmct_get_lst_pt zh_beg zh_end w_lnkb width_road) )
								
								;$$--1.坐标变换以使起点和终点成零角度--$$
								(setq lst_pt (mapcar
															 '(lambda (pt) (polar pt_beg (- (angle pt_beg pt) ang) (distance pt_beg pt)))
															 lst) )



								(setq pt_ll  (car (get_ll_ur lst_pt)) )
								(setq lst_pt (mapcar '(lambda (pt) (mapcar '- pt pt_ll)) lst_pt) )


								;$$--2.以多边形模式创建视口--$$
								;
								(if (/= (getvar "CVPORT") 1) (command "_.PSPACE") )
								(&view_ptb lst_pt) ;$把此区域置于当前视区内$
								(command "_.MVIEW" "P") (mapcar 'command lst_pt) (command "C")								
								(setq ent_vp (entlast) )
								
								
;;(princ "\n ent_vp = ")(princ ent_vp)(princ "\n(entget ent_vp) = ")(princ (entget ent_vp))
								;;$$--3.按起点终点零角度的原则旋转/缩放试图--$$
								(if (= (getvar "CVPORT") 1) (command "_.MSPACE") )
								;;(若切换模型空间失败，后续程序出错!)
;;(getpoint "\n22 = ")(princ (cdr (assoc 69 (entget ent_vp))))
								;;(setvar "CVPORT" (cdr (assoc 69 (entget ent_vp))) )
;;(getpoint "\n11")
								(command "_.UCS" "W")
								(setq pt_xx (polar pt_beg ang                1000.0) )
								(setq pt_yy (polar pt_beg (+ ang (/ pi 2.0)) 1000.0) )
								(command "_.UCS" "N" "3" pt_beg pt_xx pt_yy )
								;$From WCS to OCS$
								(setq lst 	 (mapcar '(lambda (pt) (trans pt 0 1)) lst) )
								(setq pt_ll  (car  (get_ll_ur lst)) )
								(setq pt_ur  (cadr (get_ll_ur lst)) )
								(command "_.PLAN" "" )						
								(command "_.ZOOM" "W" pt_ll pt_ur )
								(command "_.UCS"  "W" )

								;;$$--4.剪裁视口，以允许两端的延伸长度和相临图间的重叠长度--$$
								(if (/= (getvar "CVPORT") 1) (command "_.PSPACE") )
								(setq size    (length lst_pt) ) ;$偶数$
								(setq pt_ul   (car    lst_pt) )
								(setq pt_ll   (last   lst_pt) )
								(setq pt_ur   (nth (- (/ size 2) 1) lst_pt) )
								(setq pt_lr   (nth    (/ size 2)		lst_pt) )
								(setq ang_beg (angle  pt_ll pt_ul) )
								(setq ang_end (angle  pt_lr pt_ur) )
								(if  isfixed
									(progn
										(cond
											((= count 0)  ;$第一帧图$
											 ;(if (> (- zh_beg zh_min) 10.0) (setq dist_extend_beg dist_overlap) )
											 (setq pt_ul   (polar pt_ul (+ ang_beg (* 0.5 pi)) dist_extend_beg) )
											 (setq pt_ll   (polar pt_ll (+ ang_beg (* 0.5 pi)) dist_extend_beg) )
											 ;(setq pt_ur   (polar pt_ur (- ang_end (* 0.5 pi)) dist_overlap   ) )
											 ;(setq pt_lr   (polar pt_lr (- ang_end (* 0.5 pi)) dist_overlap   ) )
											)
											((= count (- n_frame 1)) ;$最后一帧$
											 ;(if (> (- zh_max zh_end) 10.0) (setq dist_extend_end dist_overlap) )
											 ;(setq pt_ul   (polar pt_ul (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											 ;(setq pt_ll   (polar pt_ll (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_ur   (polar pt_ur (- ang_end (* 0.5 pi)) dist_extend_end) )
											 (setq pt_lr   (polar pt_lr (- ang_end (* 0.5 pi)) dist_extend_end) )
											)
											;(t ;$其它$
											; (setq pt_ul   (polar pt_ul (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											; (setq pt_ll   (polar pt_ll (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											; (setq pt_ur   (polar pt_ur (- ang_end (* 0.5 pi)) dist_overlap   ) )
											; (setq pt_lr   (polar pt_lr (- ang_end (* 0.5 pi)) dist_overlap   ) )
											;)
										) ;cond
									)
									(progn
										(cond
											((= count 0)  ;$第一帧图$
											 (if (> (- zh_beg zh_min) 10.0) (setq dist_extend_beg dist_overlap) )
											 (setq pt_ul   (polar pt_ul (+ ang_beg (* 0.5 pi)) dist_extend_beg) )
											 (setq pt_ll   (polar pt_ll (+ ang_beg (* 0.5 pi)) dist_extend_beg) )
											 (setq pt_ur   (polar pt_ur (- ang_end (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_lr   (polar pt_lr (- ang_end (* 0.5 pi)) dist_overlap   ) )
											)
											((= count (- n_frame 1)) ;$最后一帧$
											 (if (> (- zh_max zh_end) 10.0) (setq dist_extend_end dist_overlap) )
											 (setq pt_ul   (polar pt_ul (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_ll   (polar pt_ll (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_ur   (polar pt_ur (- ang_end (* 0.5 pi)) dist_extend_end) )
											 (setq pt_lr   (polar pt_lr (- ang_end (* 0.5 pi)) dist_extend_end) )
											)
											(t ;$其它$
											 (setq pt_ul   (polar pt_ul (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_ll   (polar pt_ll (+ ang_beg (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_ur   (polar pt_ur (- ang_end (* 0.5 pi)) dist_overlap   ) )
											 (setq pt_lr   (polar pt_lr (- ang_end (* 0.5 pi)) dist_overlap   ) )
											)
										) ;cond
									)
								)

								(setq lst_clip nil)
								(setq lst_clip (append lst_clip (list pt_ul)) )
								(setq ii 0)
								(while (< ii (/ size 2))
									(setq lst_clip (append lst_clip (list (nth ii lst_pt))) )
									(setq ii (+ ii 1) )
								)
								(setq lst_clip (append lst_clip (list pt_ur pt_lr)) )
								(while (< ii size)
									(setq lst_clip (append lst_clip (list (nth ii lst_pt))) )
									(setq ii (+ ii 1))
								)
								(setq lst_clip  (append lst_clip (list pt_ll)) ) ;$剪裁多边形点表$

								(setq ent_pline (cdr (assoc 340 (entget ent_vp))) ) ;$原来的视口边界$
								(command "_.PLINE") (mapcar 'command lst_clip) (command "C")
								(command "_.VPCLIP" ent_vp (entlast) )
								(if (/= ent_pline nil) (entdel ent_pline) ) ;$删去原来的视口边界$

								;;$$--5.插入图框--$$
								;;(若为裁图线方式裁图，需要计算图框大小)
								(setq isvalid nil)
								(if (not isfixed)
									(progn
										(setq tt       (get_standard_tf lst_clip mode_tk) )
										(setq width_tk (nth 0 tt) )
										(setq higth_tk (nth 1 tt) )
										(setq isvalid  (nth 2 tt) ) ;$若为t，说明有合适的图幅$
									)
								) ; if (not isfixed)

								;;(定位图框左下角位置)
								(if (= (rem count n_column) 0)
									(progn										
										(setq hig_all    0.0 ) ;$高度归零$
										(setq wid_all    (+ wid_all (apply 'max lst_wid)) ) ;$(apply 'max nil) == 0$
										(if (/= count 0) (setq wid_all (+ wid_all (* sca 40.0))) )
										(setq	lst_wid    nil ) ;$Reinitialize lst_wid$
									) ;progn
								) ;if (= (rem count n_column) 0)
								

								(setq pt_tk     (list (+ (car pt_ori) wid_all) (+ (cadr pt_ori) hig_all)) )								
								
;;图框绘制函数(drawtk pt length width nMode nTq)
;;参数说明：
;;pt   ：图框左下角点，若为nil，提示动态选择图框左下角点
;;length：图幅长度
;;width：图幅宽度
;;nMode：放置方式：0（横式）、1（立式）
;;nTq：  图签样式：0（通用式）、1（下通栏式）、2（上通栏式）、3（上下式）
;;返回值：
;;(ptOuterLL ptInnerLL dInnerLeng dInnerWidth dRet1 dRet2 selset)
;;其中，dRet1 -- 图签长，dRet2 -- 图签宽
;;而对上下式：dRet1 -- 上面的块长，dRet2 -- 下面的块长
								
								;;(setq lst_tk    (hztk_ mode_tk width_tk higth_tk pt_tk) )
								(#ppas  "HY_TuKuang")
								(setq lst_tk (drawtk pt_tk width_tk higth_tk mode_tk nTq) )
								(#ppuas  "HY_TuKuang")
								(hy_set0 )
                (setq dInnerLeng (caddr lst_tk) dInnerWidth (nth 3 lst_tk) )
								(setq wid_tk (+ dInnerLeng (* sca 40.0)) hig_tk (+ dInnerWidth (* sca 20.0)))
								(setq pt_list (szgx_caltk_blur lst_tk nTq) )
								(setq pt_tk_bl (car pt_list) pt_tk_ur (cadr pt_list) )
								

								;;(setq lst_tk '(100.0 100.0 100.0 100.0 100.0 100.0 10.0 10.0) )
								;;(setq wid_right (nth 6 lst_tk) hig_top (nth 7 lst_tk) )
							  ;; (width_tk higth_tk均是指图纸上的尺寸.具体向图面上绘制的大小需要乘以sca,
							  ;; 而wid_rigth hig_top已经换算过)
								;;(setq wid_tk (* sca width_tk) hig_tk (* sca higth_tk) )
								;;(print (list width_tk higth_tk) )
								 
								;;(if (= mode_tk "ls")
								;;	(setq tt wid_tk wid_tk hig_tk hig_tk tt )
									;; (鉴于A4图纸都是立式放置，故选择横式放置时，作以下调整)
								;;	(if (equal higth_tk 210.0 10.0)
								;;		(setq tt wid_tk wid_tk hig_tk hig_tk tt ) )
								;;)

								;$$--6.插入指北针和分图编号,插入点按图框右上角定位--$$
								;
							  (setq tt (HY_GetNorthDirection)) ;(北方向角)

								;;(setq pt_ins  (list (- (+ (car pt_tk) wid_tk) wid_right) (- (+ (cadr pt_tk) hig_tk) hig_top)) )
								;;(setq pt_ins  (list (- (car pt_ins) (* sca 60.0)) (- (cadr pt_ins) (* sca 40.0))) )
								(setq pt_ins (list (- (car pt_tk_ur) (* sca 50.0)) (- (cadr pt_tk_ur) (* sca 25.0))) )

								(setq tt      (- (jdtohud tt) (/ pi 2.0)) )
								(setq ang_rot (angle pt_beg pt_end) )
				        (setq ang_rot (- tt ang_rot) )
								;;(command "-INSERT" (strcat (get_dwgdir) "hytyzbzk\\" north_nam) pt_ins sca sca (hudtojd ang_rot) )
								;;(szdl_ins_sysblk "b09030" pt_ins sca sca (hudtojd ang_rot))
								(command "_.insert" (Dl_GetZhiBeiZhenPath) pt_ins sca sca (hudtojd ang_rot))

								(setq pt_ins     (polar pt_ins 0.0 (* sca 30.0)) )
				        (szdl_ins_sysblk "hyszftth" pt_ins sca sca 0)
				      	(setq tt  (polar pt_ins (* pi 0.5) (* 0.5 sca)) )
				      	(setq tt2 (polar pt_ins (* pi 1.5) (* 0.5 sca)) )
				      	(command "_.TEXT" "j" "BC" tt  (* 1.5 hig_txt) 0 (itoa n_subgraph) )
				      	(command "_.TEXT" "j" "TC" tt2 (* 1.5 hig_txt) 0 (itoa n_frame  ) )

								;$$--7.移动视口到图框中心位置--$$
								;
								(setq tt  (cdr  (assoc 10  (entget ent_vp))) ) ;$基点：视口中心点(WCS)$
								;;(setq tt2 (list (+ (car pt_tk) (* wid_tk 0.5)) (+ (cadr pt_tk) (* hig_tk 0.5))) ) ;$目标点：图框中心点$
								(setq tt2 (polar pt_tk_bl (angle pt_tk_bl pt_tk_ur) (* (pmdist pt_tk_bl pt_tk_ur) 0.5)) )

								(setq ent_pline (cdr (assoc 340 (entget ent_vp))) ) ;$新视口边界$
								(command "_.MOVE" ent_pline "" tt tt2 )

								(if (and (not isfixed) (not isvalid)) ;??
									(progn
										(prompt  "\n 圆形标志处的分图没有合适的标准图幅，是否标出<Y/N>?<Y>: ")
										(@xsjcbz tt2 '(13 89 121 78 110) "该图没有合适的标准图幅")
									)
								) ;if (and (not isfixed) (not isvalid))

								;$$--Next Frame--$$
								;
								(ssadd ent_vp     ss_vp )
								
								(setq  lst_wid    (append lst_wid (list wid_tk)) )
								(setq  hig_all    (+ hig_all hig_tk (* sca 20.0)) )
								(setq  n_subgraph (+ n_subgraph 1 ) )						
								(setq  count 			(+ count 1) )
							) ;; repeat
							
							;;(后续处理)
							(if (/= (getvar "CVPORT") 1) (command "_.PSPACE") )
							(command "_.MVIEW"  "LOCK" "ON" ss_vp "" ) ;$锁定所有视口$
							(hide_vp_frame ss_vp )
							(setq ss_vp nil)
						  (command "_.ZOOM" "E" "_.UCS" "W" )
						)
						(if isfixed
							(prompt (strcat "\n 警告：指定的单幅分图的桩号数小于" (rtos zh_diff 2 1) "!"))
							(prompt "\n 警告：裁图线少于两条!" )
						)
					) ;if (> n_frame 0)
				) ;progn
			) ;if lst_pmctcs
		) ;progn
		(prompt "\n 桩号数据没有定义.")
	) ;if (/= lst_zhx nil)
	(princ)
)
;;
;;
(defun pmct_get_lst_pt( zh_beg zh_end w_lnkb width / zh lst lst1 lst2 pt pt1 pt2 ang zh_diff )
;;---------------------------[函数说明]----------------------**
;;函数功能: 由起始桩号, 得到距离道路两侧距离中心线一定长度处 **
;;          的各点组成表, 顺时针方向排布                     **
;;参数说明:
;;返 回 值: (pt1 ...)                                        **
;;备    注:
;;-----------------------------------------------------------**

	(setq zh_diff 30.0 ) ;;$桩号加密所用间距，以加快处理速度$
	
	(setq zh zh_beg lst1 nil lst2 nil )

	(while (< zh zh_end)
		(setq lst  (zh_get_pde zh w_lnkb w::prec) )
		(setq	pt   (car  lst) ang  (cadr lst) )
		(setq pt1  (polar pt (+ ang (* 0.5 pi)) width) )
		(setq pt2  (polar pt (- ang (* 0.5 pi)) width) )
		(setq lst1 (append lst1 (list pt1)) )
		(setq lst2 (append lst2 (list pt2)) )
		(setq zh   (+ zh zh_diff) )
	) ;while (< zh zh_end)

	(setq lst  (zh_get_pde zh_end w_lnkb w::prec) )

	(setq	pt   (car  lst) ang  (cadr lst) )
	(setq pt1  (polar pt (+ ang (* 0.5 pi)) width) )
	(setq pt2  (polar pt (- ang (* 0.5 pi)) width) )
	(setq lst1 (append lst1 (list pt1)) )
	(setq lst2 (append lst2 (list pt2)) )
	
	(append lst1 (reverse lst2) )
) ;end of defun
;;
;;
(defun get_ll_ur ( lst_pt / x_min x_max y_min y_max )
;;---------------------------[函数说明]----------------------**
;;函数功能: 得到给定点表组成的多边形外接矩形的左下角点和右点 **
;;参数说明:
;;返 回 值: (pt_ll pt_ur)                                    **
;;备    注:
;;-----------------------------------------------------------**
	(setq x_min (apply 'min (mapcar 'car  lst_pt)) )
	(setq x_max (apply 'max (mapcar 'car  lst_pt)) )
	(setq y_min (apply 'min (mapcar 'cadr lst_pt)) )
	(setq y_max (apply 'max (mapcar 'cadr lst_pt)) )
	(list (list x_min y_min) (list x_max y_max) )
) ;end of defun
;;
;;
(defun get_standard_tf ( lst_pt mode / width_space higth_space sca 
												 isvalid ii jj tt pt_ll pt_ur width_tk higth_tk width higth
												 lst_standard_tf lst_config lst_coeff coeff )
;;---------------------------[函数说明]----------------------**
;;函数功能: 得到内含点表 lst_pt 中各点的最小标准图幅         **
;;参数说明: mode--图框放置方式，值为 "hs" / "ls"
;;返 回 值: (width higth isvalid)                            **
;;          若有标准图幅满足指定条件, isvalid为 t; 否则, nil **
;;备    注:
;;-----------------------------------------------------------**

	(setq sca (/ (DL_GetDrawingScale) 1000.0) )
	(setq width_space 50.0 ) ;$图框宽度－视口外接矩形宽度$
	(setq higth_space 50.0 ) ;$图框高度－视口外接矩形高度$

	;;(标准图幅定义表)
	(setq lst_standard_tf
				'(("A4" (297  210) (0.0                                             ))
				  ("A3" (420  297) (0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5                 ))
				  ("A2" (594  420) (0.0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5))
				  ("A1" (841  594) (0.0 0.25 0.5 0.75 1.0 1.25 1.5                  ))
				  ("A0" (1189 841) (0.0 0.125 0.25 0.375 0.5 0.625 0.75 0.875       )) )
	) ;setq

	(setq pt_ll    (car  (get_ll_ur lst_pt)) )
	(setq pt_ur    (cadr (get_ll_ur lst_pt)) )
	(setq width_tk (+ (- (car  pt_ur) (car  pt_ll)) width_space) )
	(setq higth_tk (+ (- (cadr pt_ur) (cadr pt_ll)) higth_space) )
	(setq width_tk (/ width_tk sca) )
	(setq higth_tk (/ higth_tk sca) )

	;;(鉴于A4图纸，都是立式放置，故作以下调整)
;;	(if (/= mode "ls")
	(if (/= mode 1)
		(if (and (>= 210.0 higth_tk) (>= 297.0 width_tk)) ;(横式放置，且A4能满足条件)
			(setq tt width_tk width_tk higth_tk higth_tk tt) )		
		(setq tt width_tk width_tk higth_tk higth_tk tt)  ;(立式放置，交换宽和高的值)
	) ;if (/= mode "ls")
	
	(setq ii 0 isvalid nil )
	(while (and (not isvalid) (< ii (length lst_standard_tf)))
		(setq lst_config  (nth ii lst_standard_tf) )
		(setq width (car  (nth 1 lst_config))
					higth (cadr (nth 1 lst_config)) )
		(setq lst_coeff   (nth 2 lst_config ) )
		(if (>= higth higth_tk)
			(progn
				(setq jj 0)
				(while (and (not isvalid) (< jj (length lst_coeff)))
					(setq coeff (+ (nth jj lst_coeff) 1.0) )					
					(if (>= (* width coeff) width_tk)
						(setq isvalid t higth_tk higth width_tk (* width coeff)) )
					(setq jj (+ jj 1) )
				) ;while (and (not isvalid) (< jj (length lst_coefficient)))
			)
		) ;if (>= higth higth_tk)
		(setq ii (+ ii 1) )
	) ;while (< ii (length lst_standard_tf))

	;;(if isvalid 更新width_tk higth为标准图幅的宽和高)
	(list width_tk higth_tk isvalid )
) ;end of defun
;;
;;
(defun hide_vp_frame( ss_vp / lay_vp ii ent_data ent_pline  )
;;---------------------------[函数说明]----------------------**
;;函数功能: 为视口边界指定特定图层                           **
;;参数说明:
;;返 回 值: 无                                               **
;;备    注: 如果不想显示视口边界，可以关闭/冻结/不打印该图层 **
;;-----------------------------------------------------------**
	(setq lay_vp "vpvp") ;视口边界图层$
	(if (null (tblsearch "layer" lay_vp)) (command "-layer" "n" lay_vp "") )
	(setq ii 0 )
	(repeat (sslength ss_vp)
		(setq ent_pline (cdr (assoc 340 (entget (ssname ss_vp ii)))) )  ;视口边界$
		(setq ent_data  (entget ent_pline) )
		(setq ent_data  (subst (cons 8 lay_vp) (assoc 8 ent_data) ent_data) )
		(entmod ent_data )
		(setq ii (+ ii 1) )
	)
	;(command "-LAYER" "OFF" lay_vp "" ) (关闭视口边界所在图层)
	(tocom)
	(princ)
) ;end of defun
;;
;;
;;
;;计算图框的有效区域左下角和右上角
;;nTq：  图签样式：0（通用式）、1（下通栏式）、2（上通栏式）、3（上下式）
;;lst_tk---(ptOuterLL ptInnerLL dInnerLeng dInnerWidth dRet1 dRet2 selset)
;;其中，dRet1 -- 图签长，dRet2 -- 图签宽
;;而对上下式：dRet1 -- 上面的块长，dRet2 -- 下面的块长
(defun szgx_caltk_blur(lst_tk nTq / ptInnerLL ptInnerRR dInnerLeng dInnerWidth dRet1 dRet2   )
 (setq ptInnerLL (nth 1 lst_tk) dInnerLeng (nth 2 lst_tk) dInnerWidth (nth 3 lst_tk)
       dRet1     (nth 4 lst_tk) dRet2      (nth 5 lst_tk)
 )
 (setq ptInnerRR (list (+ (car ptInnerLL) dInnerLeng) (+ (cadr ptInnerLL) dInnerWidth) 0.0) )
 (cond
  ((or (= nTq 0) (= nTq 1))
   (setq ptInnerLL (polar ptInnerLL (* pi 0.5) dRet2) )
  )
  ((= nTq 2)
   (setq ptInnerRR (polar ptInnerRR (* pi 1.5) dRet2) )
  )
  ((= nTq 3)
   (setq ptInnerRR (polar ptInnerRR pi (max dRet1 dRet2)) )
  )
 )
 (list ptInnerLL ptInnerRR)
)    ;;end of defun
;;
;;;弧度换算为角度
(defun hudtojd(ang) (* (/ ang pi) 180.0))
;
;
;;;角度换算为弧度
(defun jdtohud(ang) (* (/ ang 180.0) pi))
;;
(princ)