;-----------------------------------------------------------------------;
; Bügelplätze zeichnen  - TYP 1 -                                       ;
; 3 Arten von Bügelplätzen:                                             ;
; --------------------------------------------------------------------- ;
; a) für REINIGUNG - Abnahme von RECHTS geschlossener Bügelhaken LINKS  ;
;                    ( für ca. 30% der Anwendungsfälle )                ;
; b) für REINIGUNG - Abnahme von RECHTS geschlossener Bügelhaken RECHTS ;
;                    ( für ca. 70% der Anwendungsfälle )                ;
; c) für FERTIGUNG und PRODUKTION - Abnahme von LINKS                   ;
; --------------------------------------------------------------------- ;
; 21.06.93 / 12.06.1998                                                 ;
;-----------------------------------------------------------------------;
(defun Dbox (/ Dat)
  (setq Dat (load_dialog (strcat lw "/acadsst/module/b_typ1.dcl")))
  (if (not (new_dialog "b_typ1" Dat)) (exit))
  (set_tile "L1"      m_L1)
  (set_tile "L2"      m_L2)
  (set_tile "K0"      m_K0)
  (set_tile "ART"     m_ART)
  (SetDia)
  (ACTION_TILE "ART"  "(zeig_dia)")
  (action_tile "accept" "(SetPara) (done_dialog)")
  (action_tile "cancel" "(exit) (done_dialog)")
  (start_dialog)
  (unload_dialog Dat)
)

(defun SetDia()
  (setq breite (dimx_tile "anzeige"))
  (setq hoehe  (dimy_tile "anzeige"))
  (start_image "anzeige")
  (FILL_IMAGE 0 0 breite hoehe -18)
  (if (= m_ART "ART_1")  ; Nr 1
    (slide_image 0 0 breite hoehe "arbplz(btyp01_1)")
  )
  (if (= m_ART "ART_2")  ; Nr 2
    (slide_image 0 0 breite hoehe "arbplz(btyp01_2)")
  )
  (if (= m_ART "ART_3")  ; Nr 3
    (slide_image 0 0 breite hoehe "arbplz(btyp01_3)")
  )
  (end_image)
)

(defun zeig_dia()
  (setq m_ART (get_tile "ART"))
  (SetDia)
)

(defun SetPara ()
  (setq m_L1       (get_tile "L1")     ; Breite
	  m_L2       (get_tile "L2")     ; Tiefe
	  m_K0       (get_tile "K0")     ; Anzahl Plätze
	  m_ART      (get_tile "ART")    ; Art
  )
)

(defun datain()
  (setq L1     (atof m_L1))               ; Breite
  (setq L2     (atof m_L2))               ; Tiefe
  (setq K0     (atof m_K0))               ; Anzahl Plätze
  (setq ART    (atoi (substr m_ART 5 1))) ; Art

  ;---------------------------------------------------------------------;
  ; >>>>>> EINGABETEIL <<<<<<                                           ;
  ;---------------------------------------------------------------------;
  (setq P0 (getpoint "\nUntere linke Ecke definieren: "))
  (initget (+ 2 4))
  ;---------------------------------------------------------------------;
  ; >>>>>> Prüfung ob die Grenzwerte eingehalten sind <<<<<<            ;
  ;---------------------------------------------------------------------;
  (while (or (< L1 4600) (> L1 8000))
     (initget (+ 1 2 4))
     (setq l1 (getreal "\nBreite eingeben [4600-8000]: "))
  )
  (while (or (< L2 2200) (> L2 6000))
     (initget (+ 1 2 4))
     (setq l2 (getreal "\nTiefe eingeben [2200-6000]: "))
  )
)

(defun punkte()
  ;---------------------------------------------------------------------;
  ; >>>>>> Konstruktionspunkte definieren <<<<<<                        ;
  ;---------------------------------------------------------------------;
  (setq P1 (list (car P0)                       (+ (cadr P0) 800)))
  (setq P2 (list (+ (car P0) 800)               (cadr P1)))
  (setq P3 (list (+ (car P1) (/ (- L1 1850) 2)) (cadr P1)))
  (setq P4 (list (+ (car P3) 425)               (cadr P1)))
  (setq P5 (list (+ (car P3) 825)               (- (cadr P1) 400)))
  (setq P6 (list (+ (car P3) 1025)              (- (cadr P1) 600)))
  (setq P7 (list (+ (car P3) 1425)              (- (cadr P1) 1000)))
  (setq P8 (list (+ (car P3) 1850)              (cadr P7)))
  (setq P9 (list (+ (car P0) (- L1 800))        (cadr P7)))
  (setq P10 (list (+ (car P0) L1)               (cadr P7)))
  (setq P11 (list (car P10)                     (+ (cadr P7) 800)))
  (setq P12 (list (car P10)                     (+ (cadr P7) L2)))
  (setq P13 (list (car P0)                      (+ (cadr P0) L2)))
  (setq P14 (list (- (car P0) 400)              (- (cadr P0) 400)))
  (setq P15 (list (+ (car P12) 400)             (+ (cadr P12) 400)))
  (cond
     ((= ART 1)
     (setq P16 (list (- (car P4) 1400)          (- (cadr P4) 1090)))
     (setq P17 (list (- (car P4) 700)           (- (cadr P16) 560)))
     (setq P18 (list (+ (car P4) 200)           (- (cadr P4) 1350)))
     (setq P19 (list (+ (car p18) 750)          (+ (cadr P18) 350)))
     (setq P20 (list (car P1)                   (+ (cadr P1) (/ (- L2 800) 2)))) 
     (setq P21 (list (car P10) (+ (+ (cadr P10) 800) (/ (- L2 800) 2))))
     (setq P22 (list (- (car P4) 650)           (cadr P4)))
     )
     ((= ART 2)
     (setq P16 (list (+ (car P7) 1400)          (+ (cadr P7) 1090)))
     (setq P17 (list (+ (car P7) 700)           (+ (cadr P16) 560)))
     (setq P18 (list (- (car P7) 200)           (+ (cadr P7) 1350)))
     (setq P19 (list (- (car p18) 750)          (- (cadr P18) 350)))
     (setq P20 (list (car P1)                   (+ (cadr P1) (/ (- L2 800) 2)))) 
     (setq P21 (list (car P10) (+ (+ (cadr P10) 800) (/ (- L2 800) 2))))
     (setq P22 (list (- (car P4) 400)           (cadr P4)))
     (setq P23 (list (+ (car P8) 250)           (cadr P8)))
     )
     ((= ART 3)
     (setq P16 (list (- (car P7) 300)           (- (cadr P4) 1750)))
     (setq P17 (list (- (car P7) 1200)          (+ (cadr P16) 850)))
     (setq P18 (list (+ (car P4) 200)           (- (cadr P4) 1350)))
     (setq P19 (list (+ (car p18) 750)          (+ (cadr P18) 350)))
     (setq P20 (list (car P1)                   (+ (cadr P1) (/ (- L2 800) 2)))) 
     (setq P21 (list (car P10) (+ (+ (cadr P10) 800) (/ (- L2 800) 2))))
     (setq P22 (list (- (car P4) 400)           (cadr P4)))
     (setq P23 (list (+ (car P8) 250)           (cadr P8)))
     )
   )
)

(defun geometrie()
  ;---------------------------------------------------------------------;
  ; >>>>>> Blöcke einfügen <<<<<<                                       ;
  ;---------------------------------------------------------------------;
  (command "_layer" "_m" "L-2" "_c" "2" "" "")
  (command "_insert" (strcat lw "/acadsst/layout/w90650R8") P1 "" "" "90")
  (setq auswahl-satz (ssget "_L"))
  (command "_insert" (strcat lw "/acadsst/layout/s45650R4") P4 "" "" "0")
  (ssadd (entlast) auswahl-satz)
  (command "_insert" (strcat lw "/acadsst/layout/s45650R4") P7 "" "" "180")
  (ssadd (entlast) auswahl-satz)
  (command "_insert" (strcat lw "/acadsst/layout/w90650R8") P10 "" "" "-90")
  (ssadd (entlast) auswahl-satz)
  (command "_line" P2 P3 "")
  (ssadd (entlast) auswahl-satz)
  (command "_line" P5 P6 "")
  (ssadd (entlast) auswahl-satz)
  (command "_line" P8 P9 "")
  (ssadd (entlast) auswahl-satz)
  (command "_line" P11 P12 "")
  (ssadd (entlast) auswahl-satz)
  (command "_line" P1 P13 "")
  (ssadd (entlast) auswahl-satz)
  ;---------------------------------------------------------------------;
  ; >>>>>> Pfeile + Maschinen setzen <<<<<<                             ;
  ;---------------------------------------------------------------------;
  (command "_layer" "_m" "Z-1" "_c" "1" "" "")
  (cond
     ((= ART 1)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegel") P20 "" "" "") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegel") P21 "" "" "")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegel") P2 "" "" "-90") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegel") P5 "" "" "-135")     
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegel") P9 "" "" "-90")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/vario14") P16 "" "" "-90")     
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/maus") P17 "" "" "")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pfeil") P18 "" "" "45") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pfeil") P19 "" "" "-135")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") P8 "" "" "")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pf0_v") P22 "" "" "")
     (ssadd (entlast) auswahl-satz)
     )
     ((= ART 2)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P20 "" "" "") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P21 "" "" "")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P2 "" "" "-90") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P5 "" "" "-135")     
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P9 "" "" "-90")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/vario14") P16 "" "" "90")     
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/maus") P17 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pfeil") P18 "" "" "-135") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pfeil") P19 "" "" "45")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pf0_v") P23 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") P22 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     )
     ((= ART 3)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P20 "" "" "180")     
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P21 "" "" "180")     
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P2 "" "" "90") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P5 "" "" "45")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/buegelr") P9 "" "" "90")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/dobli-fw") P16 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/maus") P17 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pfeil") P18 "" "" "45") 
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pfeil") P19 "" "" "-135")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pf0_v") P23 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     (command "_insert" (strcat lw "/acadsst/zier2d/pf0_l") P22 "" "" "180")
     (ssadd (entlast) auswahl-satz)
     )
  )    
  (If (> K0 1)
    ;(command "_array" "_c" P14 P15 "" "_r" m_K0 "1" m_L2)
    (command "_array" auswahl-satz "" "_r" m_K0 "1" m_L2)
  )
)

  ;---------------------------------------------------------------------;
  ; >>>>>> Programm <<<<<<                                              ;
  ;---------------------------------------------------------------------;
(defun c:b_typ1 ( / L1 L2 K0 ART P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 P16 P17 P18 P19 P20 P21 P22 P23) 
  (setvar "limcheck" 0)
  (prompt "*** Bügelplatz TYP 1 ***")
  (if (null m_L1)    (setq m_L1       "4600"   ))     ; Breite
  (if (null m_L2)    (setq m_L2       "2400"   ))     ; Tiefe
  (if (null m_K0)    (setq m_K0       "1"      ))     ; Anzahl der Plätze
  (if (null m_ART)   (setq m_ART      "ART_1"  ))     ; Art
  (setq auswahl-satz nil)
  (Dbox)
  (prompt "")
  (datain)
  (punkte)
  (geometrie)
)
  ;---------------------------------------------------------------------;
  ; >>>>>> Ende <<<<<<                                                  ;
  ;---------------------------------------------------------------------; 