;------------------------------------------------------------------------;
; EINGAENGE_B                                                            ;
;------------------------------------------------------------------------;
; 02.02.2007                                                             ;
;------------------------------------------------------------------------;
(defun Dbox (/ Dat)
  (setq Dat (load_dialog (strcat lw "/acadsst/steuerg/EINGAENGE_B.DCL")))
  (if (not (new_dialog "EINGAENGE_B" Dat)) (exit))
  (set_tile "DWG_NAME" m_DWG_NAME); Blockname

  (set_tile "INPUT"          m_INPUT)   
  (set_tile "IDENT"          m_IDENT)   
  (set_tile "COMPONENT"      m_COMPONENT)   
  (set_tile "BEZEICHNUNG"    m_BEZEICHNUNG)   
  (set_tile "FAKT"           m_FAKT)
  (set_tile "ZUSATZ"         m_ZUSATZ)
  (set_tile "PREFIX"         m_PREFIX)  ; B,S oder E

  (mode_tile "anzeige" 0)
  (SetDia)
  (ACTION_TILE "DWG_NAME" "(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)
  
  (cond 
    ((= m_DWG_NAME "1")        ; Induktiv 8 mm
      (slide_image 0 0 breite hoehe "steuerg(20002002)")
    )
    ((= m_DWG_NAME "2")        ; Induktiv 12 mm
      (slide_image 0 0 breite hoehe "steuerg(20002003)")
    )
    ((= m_DWG_NAME "3")        ; Induktiv 16 mm
      (slide_image 0 0 breite hoehe "steuerg(20002006)")
    )
    ((= m_DWG_NAME "4")        ;Sensor Kapazitiv AP60
      (slide_image 0 0 breite hoehe "steuerg(26904025)")
    )
    ((= m_DWG_NAME "5")       ;Sensor Kapazitiv AP110
      (slide_image 0 0 breite hoehe "steuerg(26904024)")
    )
    ((= m_DWG_NAME "6")       ;Sensor Kapazitiv
      (slide_image 0 0 breite hoehe "steuerg(21000011)")
    )
  )  ; end cond
  (end_image)
)

(defun zeig_dia()
  (setq WINKEL1 0)
  (setq m_DWG_NAME (get_tile "DWG_NAME"))
  (setq m_PREFIX   (get_tile "PREFIX"))
  (setq m_FAKT     (get_tile "FAKT"))
  (setq m_ZUSATZ   (get_tile "ZUSATZ"))
  (SetDia)
)

(defun setpara()
  (setq m_PREFIX       (get_tile "PREFIX"))
  (setq m_INPUT        (get_tile "INPUT"))  
  (setq m_IDENT        (get_tile "IDENT"))  
  (setq m_COMPONENT    (get_tile "COMPONENT"))  
  (setq m_BEZEICHNUNG  (get_tile "BEZEICHNUNG"))  
  (setq m_DWG_NAME     (get_tile "DWG_NAME"))
  (setq m_FAKT         (get_tile "FAKT"))
  (setq m_ZUSATZ       (get_tile "ZUSATZ"))
  (setq FAKTO          (atof m_FAKT))
  (InputStringAnalyse)
)

(defun InputStringAnalyse()
  (setq DisplayString "")
  (setq InputLaenge (strlen m_INPUT))
;  (alert (itoa InputLaenge))
  (if (or (> InputLaenge 4) (= InputLaenge 0))
    (progn
      (alert "Mehr als 4 Stellen nicht bzw. LEERE Eingabe nicht erlaubt")
      (exit)
    )
  )
  (cond 
    ((= InputLaenge 1)
      (setq DisplayString (strcat "000" m_INPUT))
    )
    ((= InputLaenge 2)
      (setq DisplayString (strcat "00" m_INPUT))    
    )
    ((= InputLaenge 3)
      (setq DisplayString (strcat "0" m_INPUT))    
    )
    ((= InputLaenge 4)
      (setq DisplayString m_INPUT)    
    )
  )  ; end cond
	(cond 
		((= m_COMPONENT "0")
			(setq VERWENDUNG "SEP1_2Y+1B")
		)
		((= m_COMPONENT "1")
			(setq VERWENDUNG "SEP1_1Y+1B")
		)
		((= m_COMPONENT "2")
			(setq VERWENDUNG "SEP2_2Y+1B")
		)
		((= m_COMPONENT "3")
			(setq VERWENDUNG "SEP2_1Y+1B")
		)
		((= m_COMPONENT "4")
			(setq VERWENDUNG "SCAN_1A")
		)
		((= m_COMPONENT "5")
			(setq VERWENDUNG "SW_2Y")
		)
		((= m_COMPONENT "6")
			(setq VERWENDUNG "SW_2Y+1B")
		)
		((= m_COMPONENT "7")
			(setq VERWENDUNG "SW_2Y+3B")
		)
		((= m_COMPONENT "8")
			(setq VERWENDUNG "MOT_1M+1B")
		)
		((= m_COMPONENT "9")
			(setq VERWENDUNG "MOT_1M")
		)
		((= m_COMPONENT "10")
			(setq VERWENDUNG "INPUT-1B")
		)
		((= m_COMPONENT "11")
			(setq VERWENDUNG "OUTPUT-1Y")
		)
		((= m_COMPONENT "12")
			(setq VERWENDUNG "NO-ID")
		)
	)  ; end cond
)

(defun datain ()  
  (setq dummy nil)
)

(defun geometrie()
  (cond
    ((= m_DWG_NAME "0")
      (setq BL_NAME "") ;Blinde Eintragung
			(setq BEZEICHNUNG "")
			(setq BEZ1 "")
			(setq BEZ2 "")
			(setq BEZEICHNUNG_BG "")
    )
    ((= m_DWG_NAME "1")
      (setq BL_NAME "720002002") ;Sensor Induktiv 8mm Schaltabstand
			(setq BEZEICHNUNG "SENSOR INDUKTIV 8MM SCHALTABSTAND")
			(setq BEZ1 "IND")
			(setq BEZ2 "8mm")
			(setq BEZEICHNUNG_BG "")
    )
    ((= m_DWG_NAME "2")
      (setq BL_NAME "720002003") ;BG-> Sensor Induktiv 12mm Schaltabstand 720002003=1St.+ 826906133=1St.
			(setq BEZEICHNUNG "SENSOR INDUKTIV 12MM SCHALTABSTAND") ;BG->720002003=1St.+ 826906133=1St.
			(setq BEZEICHNUNG_BG "SENSOR INDUKTIV 12 MM MIT HALTER KPL.") ;BG->720002003=1St.+ 826906133=1St.
			(setq BEZ1 "IND")
			(setq BEZ2 "12mm")
    )
    ((= m_DWG_NAME "3")
      (setq BL_NAME "720002006") ;Sensor Induktiv 16mm Schaltabstand
			(setq BEZEICHNUNG "SENSOR INDUKTIV 16MM SCHALTABSTAND")
			(setq BEZEICHNUNG_BG "")          
			(setq BEZ1 "IND")
			(setq BEZ2 "16mm")
    )
    ((= m_DWG_NAME "4")        ;Sensor Kapazitiv AP60
      (setq BL_NAME "826904025")
			(setq BEZEICHNUNG "SENSOR KAPAZITIV AP60")
			(setq BEZEICHNUNG_BG "")          
			(setq BEZ1 "KAP")
			(setq BEZ2 "AP60")
    )
    ((= m_DWG_NAME "5")       ;Sensor Kapazitiv AP110
      (setq BL_NAME "826904025")
			(setq BEZEICHNUNG "SENSOR KAPAZITIV AP110")
			(setq BEZEICHNUNG_BG "")          
			(setq BEZ1 "KAP")
			(setq BEZ2 "AP110")
    )
    ((= m_DWG_NAME "6")       ;Sensor Kapazitiv
      (setq BL_NAME "721000011")
			(setq BEZEICHNUNG "SENSOR KAPAZITIV")
			(setq BEZEICHNUNG_BG "")          
			(setq BEZ1 "KAP")
			(setq BEZ2 "")
    )
  )  ; end cond

	(cond 
		((= m_PREFIX "PREFIX_1")
			(setq _PREFIX "B")
		)
		((= m_PREFIX "PREFIX_2")
			(setq _PREFIX "E")
		)
		((= m_PREFIX "PREFIX_3")
			(setq _PREFIX "S")
		)
	)
	    
	(setq AUSWAHL-SATZ-ROTATE nil)	; wird am Ende ROTATE
	(setq AUSWAHL-SATZ nil)					; Blockbildung

  (setq P0  (getpoint "\nPick insert point: "))
  (setvar "osmode" 0)  
  (bl-name P0) ;--> Block-Name definieren -> Rckgabe: element-name    
  
	(setq P10  (list (+ (car p0) (* FAKTO 1170)) (+ (cadr p0) (* FAKTO 0))   (caddr p0)))
	(setq P11  (list (+ (car p0) (* FAKTO 1170)) (+ (cadr p0) (* FAKTO 330)) (caddr p0)))
	(setq P12  (list (+ (car p0) (* FAKTO 0))    (+ (cadr p0) (* FAKTO 330)) (caddr p0)))
	(setq P13  (list (+ (car p0) (* FAKTO 340))  (+ (cadr p0) (* FAKTO 0))   (caddr p0)))
	(setq P14  (list (+ (car p0) (* FAKTO 340))  (+ (cadr p0) (* FAKTO 330)) (caddr p0)))
	(setq P15  (list (+ (car p0) (* FAKTO 1370)) (+ (cadr p0) (* FAKTO 0))   (caddr p0)))
	(setq P16  (list (+ (car p0) (* FAKTO 1370)) (+ (cadr p0) (* FAKTO 330)) (caddr p0)))
    
	;<<<Text>>>
	(setq P1  (list (+ (car p0) (* FAKTO 380)) (+ (cadr p0) (* FAKTO 90))  (caddr p0)))
	(setq P2  (list (+ (car p0) (* FAKTO 550)) (+ (cadr p0) (* FAKTO 90))  (caddr p0)))
	(setq P3  (list (+ (car p0) (* FAKTO 20))  (+ (cadr p0) (* FAKTO 220)) (caddr p0)))
	(setq P4  (list (+ (car p0) (* FAKTO 20))  (+ (cadr p0) (* FAKTO 120)) (caddr p0)))
	(setq P5  (list (+ (car p0) (* FAKTO 20))  (+ (cadr p0) (* FAKTO 10))  (caddr p0)))
	(setq P6  (list (+ (car p0) (* FAKTO 20))  (+ (cadr p0) (* FAKTO 20))  (caddr p0)))
	(setq P7  (list (+ (car p0) (* FAKTO 1200)) (+ (cadr p0) (* FAKTO 100))   (caddr p0)))
	
	(command "_layer" "_m" "EINGANG" "_c" "6" "" "")

	;<<< IO Einfgen
	(command "_insert" (strcat lw "/acadsst/steuerg/io") P6 FAKTO "" "") 
	(ATTRIBUTE-AENDERN_IO (strcat _PREFIX DisplayString) m_IDENT VERWENDUNG m_BEZEICHNUNG) 
  (setq AUSWAHL-SATZ-ROTATE (ssget "_L"))	

	;>>> Byteweise arbeiten. Wenn die letzte Zahl "7" dann auf "10" aufrunden
	(setq LAENGE_m_INPUT (strlen m_INPUT))
	(if (= (substr m_INPUT LAENGE_m_INPUT 1) "7")
    (setq m_INPUT (itoa (+ 3 (atoi m_INPUT))))
    (setq m_INPUT (itoa (+ 1 (atoi m_INPUT))))
	)

  ;<<< Korpus zeichnen ---------------------------------------
  (command "_layer" "_m" "EINGANG-HW" "_c" "7" "" "")
	(command "_pline" P0 P10 P11 P12 P0 "")
  (setq AUSWAHL-SATZ (ssget "_L"))	
	(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
	(command "_pline" P13 P14 "")
	(ssadd (entlast) AUSWAHL-SATZ)
	(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
	;<<< Beschreibung als Text hinzufgen
	(command "_text" P3 (rtos (* FAKTO 70)) "0" BEZ1)
	(ssadd (entlast) AUSWAHL-SATZ)
	(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
	(command "_text" P4 (rtos (* FAKTO 70)) "0" BEZ2)
	(ssadd (entlast) AUSWAHL-SATZ)
	(ssadd (entlast) AUSWAHL-SATZ-ROTATE)	


	;<<<< Zusatztext >>>>>>>
  (if (> (strlen m_ZUSATZ) 0 )
		(progn
			(command "_text" P7 (rtos (* FAKTO 150)) "0" m_ZUSATZ)
			(ssadd (entlast) AUSWAHL-SATZ)
			(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
			(command "_pline" P10 P15 "")
			(ssadd (entlast) AUSWAHL-SATZ)
			(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
			(command "_pline" P15 P16 "")
			(ssadd (entlast) AUSWAHL-SATZ)
			(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
			(command "_pline" P16 P11 "")
			(ssadd (entlast) AUSWAHL-SATZ)
			(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			
		)
	)	
			
	(mach-block P0 "0" AUSWAHL-SATZ)	
	(attribute-aendern "0" "0" "9" "0" (strcat _PREFIX DisplayString) block-kennung BL_NAME BEZEICHNUNG "1" "")     
	(ssadd (entlast) AUSWAHL-SATZ-ROTATE)			

  (setq AUSWAHL-SATZ (ssget "_L")) ; Auswahlsatz reinitialieren 	
	:<<<-------------------------------------------------------------------

  ;<<<< BAUGRUPPEN >>>
  (if (= m_DWG_NAME "1") 
    (progn
      (EINZELTEIL P0 "826906133" "SENSORHALTER SPULENPRFUNG AP110" "1") ;BG-> Sensor Induktiv 12mm Schaltabstand 720002003=1St.+ 826906133=1St.
      (command "_layer" "_m" "A-GRUPPE" "_c" "7" "" "")  

      (mach-block P0 "0" AUSWAHL-SATZ)
      (attribute-aendern "0" "2" "9" "0" (strcat _PREFIX DisplayString) block-kennung "333333333" BEZEICHNUNG_BG "1" "")
      (ssadd (entlast) AUSWAHL-SATZ-ROTATE)
    )  
  )
	(command "_rotate" AUSWAHL-SATZ-ROTATE "" P0 pause)
)

(defun EINZELTEIL (P1 E_ARTINR E_BEZEICHNUNG E_MENGE)
  (setq WINKEL1 (+ WINKEL1 10))
  (command "_insert" (strcat lw "/acadsst/steuerg/d_einzel") P0 "" "" (rtos WINKEL1)) 
  (attribute-aendern "0" "0" "29" "" "" block-kennung E_ARTINR E_BEZEICHNUNG E_MENGE "")     
  (ssadd (entlast) AUSWAHL-SATZ)
)

;------------------------------------------------------------------------------
(defun c:EINGAENGE_B ( / DWG_NAME BL_NAME P0) 
  (setvar "limcheck" 0)
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setq ALTFANG (getvar "osmode"))  
  (setq EINZEL 0) ; fuer EINZEL=0 Baugruppen / EINZEL=1 fuer APB
  (prompt "**** EINGNGE B *******")
  (prompt "")
  (if (null m_DWG_NAME)  (setq m_DWG_NAME "0"))      ; Auswahl
  (if (null m_INPUT)     (setq m_INPUT "1"))         ; Input Bit   
  (if (null m_IDENT)     (setq m_IDENT "1000"))      ; ID   
  (if (null m_COMPONENT) (setq m_COMPONENT "1"))     ; Verwendung   
  (if (null m_BEZEICHNUNG) (setq m_BEZEICHNUNG "xxxxxxxxxxxxxxx")) ; BEZEICHNUNG   
  (if (null m_FAKT)      (setq m_FAKT "1"))          ; Skalierungsfaktor   
  (if (null m_ZUSATZ)    (setq m_ZUSATZ ""))         ; Zusatztext   
  (if (null m_PREFIX)    (setq m_PREFIX "PREFIX_1")) ; Prefix (B,E oder S)
  (Dbox)
  (prompt "")
  (datain)
  (geometrie)
	(setvar "osmode" ALTFANG)  
)
