;;;wri yft 00.01.24
;;;道路交通标志
;;;道路交通标志图库--插入
;;;sty---标志类型
;;;1---警告标志
;;;2---禁令标志
;;;3---指示标志
;;;4---指路标志
;;;5---旅游区标志
;;;6---施工安全标志
;;;7---辅助标志
(defun ?dljtbz (sty	    /		insert_pt   tk_name
		blk_name    loop	blk_scale   blk_angle
		ent	    bz_text	blk_name1   blk_ang
		list_sjb    xx		?dljtbz_qblkname  flag  my_error
	       )
;;;由图块名得到其在图库中的名称
;;;	(defun ?dljtbz_qblkname	(blkent		 blkname	 /)
;;;
;;;	)
  (HY_Set0)
  (IF (NULL GalleryManage)
    (#PPAS "GalleryManage")
  )
  ;;;(DL_MakeLayer "PP-DL-JTBZ")
  ;;;;2002-11-25 18:31 由王志宇修改
  (if (null (tblsearch "LAYER" "PP-DL-JTBZ"))
    (command "layer" "M" "PP-DL-JTBZ" "")
    (command "layer" "s" "PP-DL-JTBZ" "")
  )
  (cond ((= sty 1) (setq tk_name "警告标志"))
        ((= sty 2) (setq tk_name "禁令标志"))
        ((= sty 3) (setq tk_name "指示标志"))
        ((= sty 4) (setq tk_name "指路标志"))
        ((= sty 5) (setq tk_name "旅游区标志"))
        ((= sty 6) (setq tk_name "施工安全标志"))
        ((= sty 7) (setq tk_name "辅助标志"))
        (t (setq tk_name nil))
  )
   (#ppls "WWPUBLIC")
  (setq loop t)
  (while loop

    (setq blk_name (DL_ShowGallery tk_name))

    (if	(= nil (type blk_name))
      (setq loop nil)
      (progn
	 
	(setq bIsAtt (DL_Check_Attribute blk_name))
	(while
	  (setq insert_pt (getpoint "\n回车返回 / 请点取标志的放置点:"))

	   (initget 6)
	   (setq blk_scale (getreal "\n请输入图块的比例<1.0>:"))
	   (if (null blk_scale)
	     (setq blk_scale 0.25)
	     (setq blk_scale (* 0.25 blk_scale))
	   )
	   (if (= nil bIsAtt)
	   (progn
	   	(princ "\n请输入角度<0>:")
	   (command ".insert"
		    blk_name
		    insert_pt
		    blk_scale
		    blk_scale
		    pause
	   )

	   (setq ent	   (entlast)
		 blk_name1 (strcase(cdr (assoc 2 (entget ent))))
		 blk_ang   (cdr (assoc 50 (entget ent)))
	   )	   
	   )
	   (progn	   	
		(command ".insert" 
		    blk_name
		    insert_pt
		    blk_scale
		    blk_scale
        )
		(while (= (logand (getvar "cmdactive") 1) 1) (command ""))		
	   )
	   )	;; end if= nil bisatt
      )
	  )
	 )
  )		;; end while loop
  (HY_Set1)
  (princ)
)

;;;插入信号灯
(defun ?dljtbz_xhd (/ insert_pt tk_name blk_scale  flag my_error)

  (HY_Set0)
  ;;;(DL_MakeLayer "PP-DL-JTBZ")
  ;;;;2002-11-25 18:31 由王志宇修改
  (if (null (tblsearch "LAYER" "PP-DL-JTBZ"))
    (command "layer" "M" "PP-DL-JTBZ" "")
    (command "layer" "S" "PP-DL-JTBZ" "")
  )
  (setq tk_name (strcat (HY_GetInstallDir) "sys\\ryb_lamp"));;;;2002-11-26 17:10由王志宇修改
  (while (setq insert_pt (getpoint "\n回车退出 / 请点取信号灯放置点:"))

    (initget 6)
    (setq blk_scale (getreal "\n请输入图块的比例<1.0>:"))
    (if	(null blk_scale)
      (setq blk_scale 2.5)
      (setq blk_scale (* 2.5 blk_scale))
    )
    (princ "\n请输入角度<0>:")
    (command ".insert"
	     tk_name
	     insert_pt
	     blk_scale
	     blk_scale
	     pause
    )

  )
  (HY_Set1)
  (princ)
)

;;;wri yft 00.01.24
;;;道路交通标志统计
(defun ?dljtbz_tj (/ jtbz_sty glb bzfw loop ss k  my_error  error)
  (HY_Set0)
  (setq	glb  '((0 . "INSERT") (8 . "PP-DL-JTBZ"))
	bzfw 0.01
	loop t
  )
  (if (null szdlseld)
    (#ppls "dljtbx")
  )
  (while loop

    (setq jtbz_sty (szdlseld glb bzfw "\n请选择要统计的某类标志:"))
    (if	(and jtbz_sty (listp jtbz_sty))
      (progn
	(setq jtbz_sty (car jtbz_sty)
	      jtbz_sty (strcase(cdr (assoc 2 (entget jtbz_sty))))
	)
	(princ "\n请选择要统计的范围:")
	(setq ss (ssget	(list (cons 0 "INSERT")
			      (cons 8 "PP-DL-JTBZ")
			      (cons 2 jtbz_sty)
			)
		 )
	)
	(if ss
	  (progn
	    (setq k (sslength ss))
	    (princ (strcat "\n 该范围共有" (itoa k) "个此类标志"))
	    (alert (strcat "该范围共有" (itoa k) "个此类标志"))
	  )
	  (princ "\n该范围内没有此标志!")
	)
      )
    )
    (if	(null jtbz_sty)
      (setq loop nil)
    )
  )
  (HY_Set1)
  (princ)
)


;;;斜线填充
;;;wri yft 99.01.25 all vari:  jtbx_hatch_color
(defun ?dljtss_bx_hatch	(/	     loop	 pt
			 pt1	     ent_p	 e
			 ent_ss	     undom	 ent1
			 e0	     flag	 ?dljtss_bx_hatch_sub1
			 hatch_wid   hatch_scale hatch_angle
			 hatch_color lay	 n	;;;w_osmode
			 len    my_error	error
			)
;;;把hatch炸开并加粗
;;;  (setq w_osmode (getvar "osmode"))
  (defun ?dljtss_bx_hatch_sub1 (ent wid color / s_ent s_ss s_len s_n  error)
    (setq s_ent (ent_last))
    (HY_KZSJXZ ent nil 62 color)
    (command "explode" ent)
    (setq s_ss	(get_last s_ent)
	  s_len	(sslength s_ss)
	  s_n	0
    )
    (while (< s_n s_len)
      (setq s_ent (ssname s_ss s_n))
      (command ".pedit" s_ent "y" "w" wid "")
      (HY_KZSJXZ (entlast) nil 8 lay)
      (setq s_n (1+ s_n))
    )
  )

  (HY_Set0)
  (setq	hatch_wid 0.45
	hatch_scale
	 0.4567
	undom (HY_ClearUNDO)
	flag t
	lay "PP-DL-HATCH"
  )
  (if (null jtbx_hatch_color)
    (setq hatch_color 7)
    (setq hatch_color jtbx_hatch_color)
  )
;(DL_MakeLayer lay)
  (while flag
    (initget "H X U S")
    (setq pt
	   (getpoint
	     "\n 回车退出 /回退U /设颜色S /选闭合线X /绘边界线H /<点取填充域>:"
	   )
    )
    (setq ent_p nil)
    (cond
      ((= pt nil)
       (setq flag nil
	     e nil
	     ent_ss nil
       )
      )
      ((= pt "S")
       (setq hatch_color      (acad_colordlg hatch_color)
	     jtbx_hatch_color hatch_color
       )
      )
      ((= pt "U")
       (setq e nil
	     ent_ss nil
       )
       (if (> (getvar "undomarks") undom)
	 (HY_UndoB)
	 (prompt "\n已全部回退！")
       )
      )
      ((= pt "H")
       (HY_UndoM)
       (setq loop   t
	     ent_ss nil
	     ent_ss (ssadd)
       )
       (while loop
	 (setq e (&gzdkbj))
	 (if (equal 'ENAME (type e))
	   (progn
	     (setq ent_ss (ssadd e ent_ss))
	     (princ "\n 请依次绘制填充区域:")
	   )
	   (setq loop nil)
	 )
       )
      )
      ((= pt "X")
       (HY_UndoM)
       (princ "\n 请选择闭合的复合线:")
       (setq ent_ss (ssget '((-4 . "<OR")
			     (-4 . "<AND")
			     (0 . "*POLYLINE")
			     (70 . 1)
			     (-4 . "AND>")
			     (-4 . "<AND")
			     (0 . "*POLYLINE")
			     (70 . 3)
			     (-4 . "AND>")
			     (-4 . "<AND")
			     (0 . "*POLYLINE")
			     (70 . 5)
			     (-4 . "AND>")
			     (-4 . "OR>")
			    )
		    )
       )
      )
      ((= (type pt) 'LIST)
       (if (SETQ ent1 (hy_bpoly pt))
	 (progn
	   (HY_UndoM)
	   (setq e (entlast))
	   (initget 1)
	   (setq hatch_angle (getangle pt "\n请点选填充的方向:"))
	   (command ".bhatch"
		    "p"
		    "ANSI31"
		    hatch_scale
		    (- (rtod hatch_angle) 45)
		    pt
		    ""
	   )
	   (if (equal e (entlast))
	     (setq ent_p nil)
	     (progn
	       (setq ent_p (entlast))
	       (?dljtss_bx_hatch_sub1 ent_p hatch_wid hatch_color)
	       (HY_KZSJXZ ent1 nil 43 0.2 8 lay)
	     )
	   )
	 )
       )
       (setq ent_ss nil
	     ent_p nil
	     loop t
       )
      )
    )

    (if	ent_p
      (setq ent_ss nil)
    )
    (if	(and ent_ss (> (sslength ent_ss) 0))
      (progn
	(setq e0 (entlast))
	(initget 1)
	(setq hatch_angle (getangle "\n请输入填充的方向:"))
	(command ".hatch"
		 "ANSI31"
		 hatch_scale
		 (- (rtod hatch_angle) 45)
		 ent_ss
		 ""
	)
	(if (equal e0 (entlast))
	  (prompt "\n填充没有成功.")
	  (progn
	    (?dljtss_bx_hatch_sub1 (entlast) hatch_wid hatch_color)
	    (setq n   0
		  len (sslength ent_ss)
	    )
	    (while (< n len)
	      (setq e (ssname ent_ss n))
	      (cond
		((or (= (cdr (assoc 0 (entget e))) "LINE")
		     (= (cdr (assoc 0 (entget e))) "ARC")
		 )
		 (HY_KZSJXZ e nil 8 lay)
		 (command ".pedit" e "j" "w" 0.2 "")

		)
		((= (cdr (assoc 0 (entget e))) "LWPOLYLINE")
		 (HY_KZSJXZ e nil 43 0.2 8 lay)
		)
	      )
	      (setq n (1+ n))
	    )
	  )
	)
      )
    )
  )
  (HY_Set1)
;;;  (setvar "osmode" w_osmode)
  (princ)
)

;;;插入标志杆
(defun ?dl_bz_insert_bzg (/	   insert_pt	     ent      ang1
			  ang2	   my_error  dcl_id   sld_list
			  xx	   bz_sty   what     check_def
			  l1	   l2	    h	     line_pt  pt ;;;; w_osmode
			  pt1	   pt2	    bz_scale   my_error  path
			 )
;;;;  (setq w_osmode (getvar "osmode"))
  (HY_Set0)
  (defun my_error (msg)
    (setvar "snapang" 0)
    (setvar "orthomode" 0)
    (HY_Set1)
  )


  (defun check_def (/ flag)
    (setq flag t)
    (setq l1 (?add_zero (get_tile "l1"))
	  l2 (?add_zero (get_tile "l2"))
	  h  (?add_zero (get_tile "h"))
    )
    (cond
      ((and (= bz_sty 1) (chknum -0.000001 l1))
       (set_tile "error" "L1必须为大于等于0的数!")
       (setq flag nil)
      )
      ((and (/= bz_sty 1) (chknum 0 l1))
       (set_tile "error" "L1必须为大于0的数!")
       (setq flag nil)
      )
      ((chknum 0 h)
       (set_tile "error" "H必须为大于0的数!")
       (setq flag nil)
      )
    )
    (if	(and (= bz_sty 3) (chknum 0 l2))
      (progn
	(set_tile "error" "L2必须为大于0的数!")
	(setq flag nil)
      )
    )
    flag
  )

  (pusherr my_error)
  (setq bz_scale 6)
  (setq insert_pt (getpoint "\n回车退出 /<请点取标志杆的放置点>:"))
  (if insert_pt
    (progn
      (d_mark insert_pt)
      (setq ang1 (#setangpt insert_pt "请点选标志杆臂的"))
      (if ang1
	(progn
	  (setvar "snapang" ang1)
	  (setvar "orthomode" 1)
	  (initget 1)
	  (setq ang2 (getangle insert_pt "\n请点取标志牌的朝向:"))
	  (setq path (strcat (HY_GetInstallDir) "Commres\\DCL\\@@bzxs.dcl"))
	  (setq dcl_id (load_dialog path))

	  (if (not (new_dialog "jt_bz_bzg" dcl_id))
	    (exit)
	  )

	  (setq	sld_list '(("jt_bzg1" "sty1")
			   ("jt_bzg2" "sty2")
			   ("jt_bzg3" "sty3")
			  )
	  )
	  (foreach xx sld_list
	    (playsld (car xx) (cadr xx))
	  )
	  (setq bz_sty 1)
	  (mode_tile "l2" 1)
	  (action_tile
	    "sty1"
	    "(setq bz_sty 1)(mode_tile \"l2\" 1)"
	  )
	  (action_tile
	    "sty2"
	    "(setq bz_sty 2)(mode_tile \"l2\" 1)"
	  )
	  (action_tile
	    "sty3"
	    "(setq bz_sty 3)(mode_tile \"l2\" 0)"
	  )
	  (action_tile "accept" "(if (check_def)(done_dialog 1))")
	  (action_tile "cancel" "(done_dialog 0)")
	  (setq what (start_dialog))
	  (if (= what 1)
	    (progn
	      (setq l1 (read l1)
		    l2 (read l2)
		    h  (read h)
	      )
	      (setvar "snapang" 0)
	      (setvar "orthomode" 0)
	      (initget 1)
	      (setq line_pt
		     (getpoint insert_pt "\n请确定标志杆的引出位置:")
	      )
	      (HY_SV)
	      (command ".pline"
		       insert_pt
		       line_pt
		       (polar line_pt 0 (* bz_scale 1.5))
		       ""
	      )

	      (command ".insert"
		       (strcat (HY_GetInstallDir) "Commres\\block\\bzg_blk")
		       insert_pt
		       1
		       1
		       (+ 90 (rtod ang2))
	      )
	      (setq ent (entlast))
	      (HY_KZSJXZ ent
		      "DLBZ_BZG"
		      8
		      "PP-DL-BZG"
					;	62
					;4
		      1010
		      (list l1 l2 h)
		      1070
		      bz_sty
		      1040
		      ang2
	      )
	      (HY_RV)
	    )
	  )

	  (unload_dialog dcl_id)
	)
      )
    )
  )

  (setvar "snapang" 0)
  (setvar "orthomode" 0)
  (HY_Set1)
  (clr_err)
;;;;  (setvar "osmode" w_osmode)
  (princ)
)

(defun ?add_zero (str /)
	(setq str (strtrim str))
	(if	(and (= 'STR (type str)) (/= str ""))
		(if	(= (ascii (substr str 1 1)) 46)
			(setq str (strcat "0" str))
		)
	)
	str
)
;;;修改标志杆
(defun ?dl_bz_modi_bzg (/	 insert_pt	   ent	    ang1
			ang2	 dcl_id	  sld_list xx	    bz_sty
			what	 check_def	   l1	    l2
			h	 line_pt  pt	   pt1	    pt2
			bz_scale loop	error	   path	    my_error
		       )

  (HY_Set0)
  (defun my_error(msg)
    (setvar "snapang" 0)
    (setvar "orthomode" 0)
    (HY_Set1)
    )
  (defun check_def (/ flag)
    (setq flag t)
    (setq l1 (?add_zero (get_tile "l1"))
	  l2 (?add_zero (get_tile "l2"))
	  h  (?add_zero (get_tile "h"))
    )
    (cond
      ((chknum 0 l1)
       (set_tile "error" "L1必须为大于0的数!")
       (setq flag nil)
      )
      ((chknum 0 h)
       (set_tile "error" "H必须为大于0的数!")
       (setq flag nil)
      )
    )
    (if	(and (= bz_sty 3) (chknum 0 l2))
      (progn
	(set_tile "error" "L2必须为大于0的数!")
	(setq flag nil)
      )
    )
    flag
  )
  (pusherr my_error)
  (setq loop t)
  (while loop

    (setq ent (HY_SelSingleEnt "\n回车退出 /<请点取要修改的标志杆>:"
		       "INSERT"
		       "PP-DL-BZG"
		       "DLBZ_BZG"
		       nil
	      )
    )
    (cond
      ((null ent) (setq loop nil))
      ((= ent "RETURN")
       (princ "\n没有选中标志杆!")
      )
      (t
       (setq ent (car ent))
       (setq xx (HY_QQ10xx ent "DLBZ_BZG" 1010))
       (if xx
	 (setq l1 (rtos (car xx) 2 1)
	       l2 (rtos (cadr xx) 2 1)
	       h  (rtos (caddr xx) 2 1)
	 )
	 (setq l1 ""
	       l2 ""
	       h  ""
	 )
       )
       (setq bz_sty (HY_QQ10xx ent "DLBZ_BZG" 1070))
       (setq path (strcat (HY_GetInstallDir) "Commres\\DCL\\@@bzxs.dcl"))
	     (setq dcl_id (load_dialog path))
      
       (if (not (new_dialog "jt_bz_bzg" dcl_id))
	    (exit)
	  )

       (set_tile "bzg" "请修改标志杆的尺寸")
       (setq sld_list '(("jt_bzg1" "sty1")
			("jt_bzg2" "sty2")
			("jt_bzg3" "sty3")
		       )
       )
       (foreach	xx sld_list
	 (playsld (car xx) (cadr xx))
       )
       (set_tile "l1" l1)
       (set_tile "l2" l2)
       (set_tile "h" h)

       (cond
	 ((= bz_sty 1)
	  (mode_tile "l2" 1)
	  (mode_tile "sty1" 0)
	  (mode_tile "sty2" 1)
	  (mode_tile "sty3" 1)
	 )
	 ((= bz_sty 2)
	  (mode_tile "l2" 1)
	  (mode_tile "sty1" 1)
	  (mode_tile "sty2" 0)
	  (mode_tile "sty3" 1)
	 )
	 ((= bz_sty 3)
	  (mode_tile "l2" 0)
	  (mode_tile "sty1" 1)
	  (mode_tile "sty2" 1)
	  (mode_tile "sty3" 0)
	 )
       )
       (action_tile "accept" "(if (check_def)(done_dialog 1))")
       (action_tile "cancel" "(done_dialog 0)")
       (setq what (start_dialog))
       (if (= what 1)
	 (progn
	   (setq l1 (read l1)
		 l2 (read l2)
		 h  (read h)
	   )
	   (HY_KZSJXZ ent
		   "dlbz_bzg"
		   1010
		   (list l1 l2 h)
	   )
	 )
       )
       (unload_dialog dcl_id)
      )
    )
  )

  (setvar "snapang" 0)
  (setvar "orthomode" 0)
  (HY_Set1)
  (clr_err)
  (princ)
)
