autolisp&visuallisp

circuit No. regconition

2018-05-27  本文已影响0人  CWYAC

当获得的字符串离纯线号有一点差距时,通过TLST_REFINE来过滤而得到纯线号。
思路 1. 去除在纯线号尾部打多个空格后写其他与纯线号无关的内容
        2. 在上面基础上去除在纯线号尾部打括号的内容
        3. 对一些省略circuit mark的线号进行circuit mark的添加,利用固化cirmk及输入cirmk
        4. 对一些合写线号的字符串进行处理 这种情况如:P12A,13A~13F
            先将字串据comma seperate,
            找到common part,如上例中的P
            再将得到的列表并入原列表

(defun TLST_REFINE(lo_str_list cirMk /
                                    asclastlst seq tlst_tmp)
;full name: text list refine
;arg: pure string list . circuit mark
;return: pure string list ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun rem_sufprefix(strx / ax)
  ;full name: remove the suffix not necessary
  ;input: str. output: str.
    (setq ax (cdr (member 32 (reverse (vl-string->list strx)))))
    (if (member 32 ax);32->space
      (setq strx (vl-list->string (reverse ax)))
    )
    (if (setq ax (cdr (member 40 (reverse (vl-string->list strx)))));40->(....
      (setq strx (vl-list->string (reverse ax)))
    )
    (setq strx (vl-list->string (vl-remove 32 (vl-string->list strx))))
  )
  (defun merge_CM_if_not(cirMk lo_str_list / i_slt feature_CM)
  ;full name: merge circuit mark(with cable No)if it has not
  ;input: circuit mark . line no string list
    (setq feature_CM "#L#*,#L@*,#E#*,#E@*");for circuit mark feature in lighting diagram
    (setq feature_CM (strcat feature_CM "," cirMk "#*" "," cirMk "@*")); append the feature for other diagram
    (foreach strx lo_str_list
      (if (and (not (wcmatch strx feature_CM)) (wcmatch strx "#*"))
      ;if the string not fit for above pattern, remain the string satisify "#*" pattern
        (setq lo_str_list (subst (strcat cirMk strx) strx lo_str_list))
      )
    )
    (setq lo_str_list lo_str_list)
  )
  (defun disperselo_in_lst (lo_str_list /
                                          add_lst strlt_tmp orgstr 
                                          punc str2 alen
                                          root add_lst_i)
    (setq add_lst (list "start!"))
    (while add_lst
      (setq add_lst nil) 
      (foreach lostri lo_str_list
        (if (vl-string-search "," lostri)
          (progn (setq strlt_tmp nil);save the merge cable no string to strlt_tmp(temperary string list)
            (setq orgstr lostri) ; orginal string
            (while (setq punc (vl-string-search "," lostri));return seq.no. of "," start from 0
              (setq strlt_tmp (cons (substr lostri 1 punc) strlt_tmp)) ;substr start from 1
              (setq lostri (substr lostri (+ punc 2)))
            )
            (setq strlt_tmp (reverse (cons lostri strlt_tmp)))
            (setq strlt_tmp (mapcar 'rem_sufprefix strlt_tmp))
            (setq str2 (cadr strlt_tmp)) ; "str2" prepare for extract the common part (include cirmk) and append this to every str in list
            (if (and (not (wcmatch str2 "*~*")) (not (wcmatch str2 "* *")));
              (setq alen (strlen str2))
              (setq alen (min (vl-string-search "~" str2) (vl-string-search " " str2)))
            )
            (setq root (substr (car strlt_tmp) 1 (- (strlen (car strlt_tmp)) alen)));get the common part
            (setq lo_str_list (subst (car strlt_tmp) orgstr lo_str_list));replace the merged cable no string in list with the first new string
            (setq add_lst_i (mapcar '(lambda (str)(strcat root str)) (cdr strlt_tmp)));append the afterward string with the common part
            (setq add_lst (append add_lst add_lst_i))
          ) 
        )
      )
      (if (/= add_lst nil)
        (setq lo_str_list (append lo_str_list add_lst)) 
      )
    )
    (setq lo_str_list lo_str_list)
  )
  (setq lo_str_list (mapcar 'rem_sufprefix lo_str_list))
  (setq lo_str_list (merge_CM_if_not cirMk lo_str_list))
  (setq lo_str_list (disperselo_in_lst lo_str_list)) 
)

上一篇下一篇

猜你喜欢

热点阅读