(defun C:profile_edit_simplification_line (/
					   block-obj block-profile-obj buffer-zone coor-trace curent-profile curent-text-style current-picket dist-tressa
					   flag height-text horizontal-scale inters-list-line inters-point list-vertex picket-first pline-obj pline-vla-obj
					   profile-mode profile-parameters reference-level scale-coefficient start-point trace-2dpline vertical-scale
					   result-simple-list-points n p1 p2 p3 data-dialog angle- dec g fakt-points-long plan-point temp-result-simple-list-points
					   )
  (setq profile-mode (vlax-ldata-get "geo_tools_dictionary" "profile-mode"))
  (if(if (not profile-mode)(profile-seleckt-curent-mode)T)
    (if (=(vlax-ldata-get "geo_tools_dictionary" "profile-mode")1)
      (progn
	(setq curent-profile(vlax-ldata-get "geo_tools_dictionary" "curent-profile"))
	(if curent-profile
	  (if (vlax-erased-p (cdr curent-profile))
	    (alert "Ошибка! Текущий профиль был удален.\nВыбрать другой текущий профиль можно с помощью команды \"Выбрать текущий профиль\"")
	    (progn
	      (princ (strcat"\nТекущий профиль: "(car curent-profile)))
	      		  (setq block-profile-obj (cdr curent-profile))
	      
	      (vla-StartUndoMark active_document)
	      (setq block-obj (cdr(assoc "block"(vlax-ldata-get block-profile-obj"obj-list"))))
	      (setq vertical-scale (vlax-ldata-get block-profile-obj"vertical-scale"))
	      (setq horizontal-scale (vlax-ldata-get block-profile-obj"horizontal-scale"))
	      (setq scale-coefficient (/ 1.0 (/ 1000.0 horizontal-scale)))
	      (setq height-text (*(atof(nth 9 (vlax-ldata-get block-profile-obj"profile-parameters")))scale-coefficient))
	      (setq reference-level (vlax-ldata-get block-profile-obj"reference-level"))
	      (setq buffer-zone(*(atof(nth 3 (vlax-ldata-get block-profile-obj"profile-parameters")))scale-coefficient))
	      (setq start-point(mapcar'+ (vlax-safearray->list(vlax-variant-value(vla-get-InsertionPoint block-profile-obj)))(list buffer-zone 0)))
	      (setq trace-2Dpline (trace-create-2Dpline-by-block-profile block-profile-obj))
	      (setq coor-trace(vlax-ldata-get block-profile-obj"coor-trace"))
	      (setq profile-parameters(vlax-ldata-get block-profile-obj"profile-parameters"))
	      (setq curent-text-style (nth 1 profile-parameters))
	      (if(or(eq curent-text-style "***Текущий***")(not(member curent-text-style(get-text-style-list))))
		(setq curent-text-style(getvar "TEXTSTYLE")))
	      (setq picket-first(vlax-ldata-get block-profile-obj"picket-first"))
	      
	      (setq pline-obj(car(entsel"\nВыбери полилинию на профиле: ")))
	      (cond
		((eq pline-obj nil)
		 (alert "Ничего не выбрано!"))
		((not(eq (cdr(assoc 0 (entget pline-obj))) "LWPOLYLINE"))
		 (alert "Выбрана не 2D полилиния!"))
		((eq (cdr(assoc 0 (entget pline-obj))) "LWPOLYLINE")
		 (setq list-vertex(extract_coord_lwpolyline (entget pline-obj)))
		 (setq pline-vla-obj (vlax-ename->vla-object pline-obj))
		 
		 (setq dist-tressa (vla-get-Length pline-vla-obj))
		 
		 (setq data-dialog (dialog-profile_edit_simplification_line))
		 
		 (setq current-picket(+(*(fix(/ picket-first 100.00))100.00)100.00))
		 (setq flag (if (>(- current-picket picket-first)dist-tressa)T))
		 (setq result-simple-list-points (list (car list-vertex)))
		 (if (= (get-item-by-name-in-list data-dialog "add-picket") 1)
		   (while (not flag)
		     (setq inters-list-line (list (mapcar '+ start-point (list (- current-picket picket-first) -10000000.0))
						  (mapcar '+ start-point (list (- current-picket picket-first) 10000000.0))))
		     
		     (if(setq inters-point (car(inters-2point-by-list-points (nth 0 inters-list-line)(nth 1 inters-list-line)list-vertex)))
		       (progn
			 (if (= (get-item-by-name-in-list data-dialog "add-pk-in-parent-poly") 1)
			   (if (not (member inters-point list-vertex))
			     (setq list-vertex (add-point-in-list-points-by-E inters-point list-vertex)))
			   )
			 (setq result-simple-list-points (append result-simple-list-points (list inters-point)))
			 )
		       )
		     (setq current-picket(+ current-picket (get-item-by-name-in-list data-dialog "pk-long")))
		     (setq flag (if (>(- current-picket picket-first)dist-tressa)T))
		     )
		   )
		 (setq result-simple-list-points (append result-simple-list-points (list (car (reverse list-vertex)))))
		 
		 (setq n 1)
		 (repeat (-(length list-vertex)2)
		   (setq p1 (nth (1- n) list-vertex))
		   (setq p2 (nth n list-vertex))
		   (setq p3 (nth (1+ n) list-vertex))
		   (setq angle- (calculation_angle_be_3points p1 p2 p3))
		   (if (and (= (get-item-by-name-in-list data-dialog "add-v") 1)(and (> (nth 1 p2)(nth 1 p1))(> (nth 1 p2)(nth 1 p3))))
		     (setq result-simple-list-points (add-point-in-list-points-by-E p2 result-simple-list-points))
		     (if (and (= (get-item-by-name-in-list data-dialog "add-turning") 1)(> (abs(- pi angle-)) (*(/ pi 180.0)(get-item-by-name-in-list data-dialog "min-angle-turning"))))
		       (setq result-simple-list-points (add-point-in-list-points-by-E p2 result-simple-list-points)))
		     )
		   (if (and (= (get-item-by-name-in-list data-dialog "add-n") 1)(and (< (nth 1 p2)(nth 1 p1))(< (nth 1 p2)(nth 1 p3))))
		     (setq result-simple-list-points (add-point-in-list-points-by-E p2 result-simple-list-points))
		     (if (and (= (get-item-by-name-in-list data-dialog "add-turning") 1)(> (abs(- pi angle-)) (*(/ pi 180.0)(get-item-by-name-in-list data-dialog "min-angle-turning"))))
		       (setq result-simple-list-points (add-point-in-list-points-by-E p2 result-simple-list-points)))
		     )
		   (setq n (1+ n))
		   )
		 (if (= (get-item-by-name-in-list data-dialog "add-angle") 1)
		   (progn
		     (repeat (- (length coor-trace) 2)
		       (setq p1 (car coor-trace))
		       (setq p2 (cadr coor-trace))
		       (setq p3 (caddr coor-trace))
		       (setq coor-trace (cdr coor-trace))
		       (setq g (calculation_angle_be_3points p1 p2 p3))
		       (setq dec (abs(convert-rad-grad (- g pi))))
		       
		       (if (> dec (get-item-by-name-in-list data-dialog "min-angle"))
			 (progn
			   (setq plan-point (vlax-curve-getDistAtPoint trace-2Dpline (vlax-curve-getClosestPointTo trace-2Dpline (list (car p2)(cadr p2)0))))
			   (setq inters-list-line (list (mapcar '+ start-point (list plan-point -10000000.0))
							(mapcar '+ start-point (list plan-point 10000000.0))))
			   (if(setq inters-point (car(inters-2point-by-list-points (nth 0 inters-list-line)(nth 1 inters-list-line)list-vertex)))
			     (setq result-simple-list-points (add-point-in-list-points-by-E inters-point result-simple-list-points))
			     )
			   )
			 )
		       )
		     )
		   ); if add-angle
		 
		 (if (= (get-item-by-name-in-list data-dialog "add-points") 1)
		   (progn
		     (setq temp-result-simple-list-points result-simple-list-points)
		     (setq n 0)
		     (repeat (1-(length temp-result-simple-list-points))
		       (setq p1 (nth n temp-result-simple-list-points))
		       (setq p2 (nth (1+ n) temp-result-simple-list-points))
		       (if (> (-(nth 0 p2)(nth 0 p1))(get-item-by-name-in-list data-dialog "points-long"))
			 (if (< (/(-(nth 0 p2)(nth 0 p1))(get-item-by-name-in-list data-dialog "points-long"))2.0)
			   (progn
			     (setq inters-list-line
				    (list (list (+ (nth 0 p1) (/(-(nth 0 p2)(nth 0 p1))2)) -10000000.0)
					  (list (+ (nth 0 p1) (/(-(nth 0 p2)(nth 0 p1))2)) 10000000.0)))
			     
			     (if(setq inters-point (car(inters-2point-by-list-points (nth 0 inters-list-line)(nth 1 inters-list-line)list-vertex)))
			       (setq result-simple-list-points (add-point-in-list-points-by-E inters-point result-simple-list-points))
			       )
			     )
			   (progn
			     (setq flag nil)
			     (setq fakt-points-long(/(-(nth 0 p2)(nth 0 p1))(1+(fix(/(-(nth 0 p2)(nth 0 p1))(get-item-by-name-in-list data-dialog "points-long"))))))
			     (setq current-picket (+(nth 0 p1) fakt-points-long))
			     (while (not flag)
			       (setq inters-list-line (list (list current-picket -10000000.0)
							    (list current-picket 10000000.0)))
;;;			       (draw-lwpolyline-vla-by-list-property
;;;			       (list(cons "spece" (if (eq (getvar "CTAB")"Model")model_spece paper_spece))
;;;				    (cons "Coordinates" inters-list-line)
;;;				    (cons "Color" 3)
;;;				    ))
			       (if(setq inters-point (car(inters-2point-by-list-points (nth 0 inters-list-line)(nth 1 inters-list-line)list-vertex)))
				 (setq result-simple-list-points (add-point-in-list-points-by-E inters-point result-simple-list-points))
				 )
			       (setq current-picket(+ current-picket fakt-points-long))
			       (setq flag (if (> current-picket (nth 0 p2))T))
			       )
			     )
			   )
			 )
		       (setq n (1+ n))
		       )
		     )
		   ); if add-points
		 
		 
		 
;;;		 (draw-lwpolyline-vla-by-list-property
;;;		   (list(cons "spece" (if (eq (getvar "CTAB")"Model")model_spece paper_spece))
;;;			(cons "Coordinates" list-vertex)
;;;			(cons "Color" 1)
;;;			))

		 
		 (if (= (get-item-by-name-in-list data-dialog "add-pk-in-parent-poly") 1)
		   (progn
		     (vla-put-Coordinates pline-vla-obj (convert-list-points-to-lwpolyline-safearray list-vertex))
		     (vla-update pline-vla-obj)
		     )
		   )
		 (draw-lwpolyline-vla-by-list-property
		   (list(cons "spece" (if (eq (getvar "CTAB")"Model")model_spece paper_spece))
			(cons "Coordinates" result-simple-list-points)
			(cons "Color" 1)
			))
		 (if (= (get-item-by-name-in-list data-dialog "del-parent-poly") 1)
		   (vla-delete pline-vla-obj)
		   )
		 (vla-delete trace-2Dpline)
		 (vla-EndUndoMark active_document)
		 )
		)
	      
	      )
	    )
	  (alert "Ошибка! Текущий профиль не определен.\nВыбрать текущий профиль можно с помощью команды \"Выбрать текущий профиль\"")
	  )
	)
      (alert "Данная команда не работает в режиме \"старый профиль\"!")
      )
    )
  (princ)
  )

(defun add-point-in-list-points-by-E (point input-list / n result-list p1 p2)
  (setq n 0)
  (setq result-list (list (nth n input-list)))
  (repeat (1-(length input-list))
    (setq p1 (nth n input-list))
    (setq p2 (nth (1+ n) input-list))
    
    (if (and (< (nth 0 p1) (nth 0 point))(<  (nth 0 point)(nth 0 p2)))
      (progn
	(setq result-list (append result-list (list point)))
	(setq result-list (append result-list(list (nth (1+ n) input-list))))
	)
      (setq result-list (append result-list(list (nth (1+ n) input-list)))))
    
    (setq n (1+ n))
    )
  result-list
  )

(defun dialog-profile_edit_simplification_line( / list-dialog dcl_id)
  (setq list-dialog(get-list-dialog-profile_edit_simplification_line))
  (setq dcl_id (geo-tools-load-dialog "d_profile_profile_edit_simplification_line"))
  (new_dialog "d_profile_profile_edit_simplification_line" dcl_id)
  (mode-tile-in-profile_profile_edit_simplification_line list-dialog)
  (foreach x (cdr list-dialog)
    (set_tile (car x)
	      (cond
		((="min-angle"(car x))
		 (convert-dec-to-gms-str (cadr x) 2))
		((="min-angle-turning"(car x))
		 (convert-dec-to-gms-str (cadr x) 2))
		((or (= "pk-long" (car x))(= "points-long" (car x)))
		 (rtos(cadr x)2 2))
		(T
		 (itoa (cadr x)))
		)
	      )
    )
  (action_tile "add-picket"
    (vl-prin1-to-string
      '(progn
	(setq list-dialog(subst (list "add-picket" (atoi $value))(assoc "add-picket" list-dialog) list-dialog))
	(mode-tile-in-profile_profile_edit_simplification_line list-dialog)
	)))
  
(action_tile "pk-long"(vl-prin1-to-string'(setq list-dialog(subst (list "pk-long" (atof $value))(assoc "pk-long" list-dialog) list-dialog))))
(action_tile "add-pk-in-parent-poly"
  (vl-prin1-to-string'(setq list-dialog(subst (list "add-pk-in-parent-poly" (atoi $value))(assoc "add-pk-in-parent-poly" list-dialog) list-dialog))))
  
(action_tile "add-v"(vl-prin1-to-string'(setq list-dialog(subst (list "add-v" (atoi $value))(assoc "add-v" list-dialog) list-dialog))))
  
(action_tile "add-n"(vl-prin1-to-string'(setq list-dialog(subst (list "add-n" (atoi $value))(assoc "add-n" list-dialog) list-dialog))))

  (action_tile "add-angle"
    (vl-prin1-to-string
      '(progn
	(setq list-dialog(subst (list "add-angle" (atoi $value))(assoc "add-angle" list-dialog) list-dialog))
	(mode-tile-in-profile_profile_edit_simplification_line list-dialog)
	)))
  
  (action_tile "min-angle"(vl-prin1-to-string'(setq list-dialog(subst (list "min-angle" (convert-str-gms-to-dec $value))(assoc "min-angle" list-dialog) list-dialog))))
  

  (action_tile "add-turning"
    (vl-prin1-to-string
      '(progn
	(setq list-dialog(subst (list "add-turning" (atoi $value))(assoc "add-turning" list-dialog) list-dialog))
	(mode-tile-in-profile_profile_edit_simplification_line list-dialog)
	)))
  
  (action_tile "min-angle-turning"(vl-prin1-to-string'(setq list-dialog(subst (list "min-angle-turning" (convert-str-gms-to-dec $value))(assoc "min-angle-turning" list-dialog) list-dialog))))
  
  (action_tile "add-points"
    (vl-prin1-to-string
      '(progn
	(setq list-dialog(subst (list "add-points" (atoi $value))(assoc "add-points" list-dialog) list-dialog))
	(mode-tile-in-profile_profile_edit_simplification_line list-dialog)
	)))
  (action_tile "points-long"(vl-prin1-to-string'(setq list-dialog(subst (list "points-long" (atof $value))(assoc "points-long" list-dialog) list-dialog))))
(action_tile "del-parent-poly"(vl-prin1-to-string'(setq list-dialog(subst (list "del-parent-poly" (atoi $value))(assoc "del-parent-poly" list-dialog) list-dialog))))
  
  (if(eq(start_dialog)0)
    (setq list-dialog nil)
    (vlax-ldata-put "geo_tools_dictionary" "dialog-profile_edit_simplification_line" list-dialog)
    )
  (unload_dialog dcl_id)
  list-dialog
  )

(defun get-list-dialog-profile_edit_simplification_line ( / list-dialog)
  (setq list-dialog(vlax-ldata-get "geo_tools_dictionary" "dialog-profile_edit_simplification_line"))
  (if (<(get-item-by-name-in-list list-dialog "version") 1.0)
    (setq list-dialog (list
			(list "version" 1.0)
			
			(list "add-picket" 1)
			(list "pk-long" 100.0)
			(list "add-pk-in-parent-poly" 0)
			
			(list "add-v" 1)
			(list "add-n" 1)
			
			(list "add-angle" 1)
			(list "min-angle" 3.0)
			
			(list "add-turning" 1)
			(list "min-angle-turning" 15.0)
			
			(list "add-points" 1)
			(list "points-long" 20.0)
			
			(list "del-parent-poly" 0)
			)
	  )
    )
  list-dialog
  )

(defun mode-tile-in-profile_profile_edit_simplification_line (list-dialog / )
  
  (if (=(cadr (assoc "add-picket" list-dialog))0)
    (foreach x (list "pk-long" "add-pk-in-parent-poly" )(mode_tile x 1))
    (foreach x (list "pk-long" "add-pk-in-parent-poly" )(mode_tile x 0))
    )
  
  (if (=(cadr (assoc "add-angle" list-dialog))0)
    (foreach x (list "min-angle" )(mode_tile x 1))
    (foreach x (list "min-angle" )(mode_tile x 0))
    )
  
  (if (=(cadr (assoc "add-turning" list-dialog))0)
    (foreach x (list "min-angle-turning" )(mode_tile x 1))
    (foreach x (list "min-angle-turning" )(mode_tile x 0))
    )
  
  (if (=(cadr (assoc "add-points" list-dialog))0)
    (foreach x (list "points-long" )(mode_tile x 1))
    (foreach x (list "points-long" )(mode_tile x 0))
    )
  )