CONST WANDLAENGE = 5900.0
CONST WANDBREITE = 2400.0
CONST WANDHOEHE = 120.0




'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright by Weinmann Holzbausystemtechnik GmbH (c) 2003
'
' Filename:		globvars.WMK
'
' Description:	Macros
'
' Author:		tb32rr
'
' Date:			20030815
'
' Version:		V0.01
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' variables and their initializing

function f_IntersectLine(ByRef X, ByRef Y, ByVal A1X, ByVal A1Y, ByVal E1X, ByVal E1Y, ByVal A2X, ByVal A2Y, ByVal E2X, ByVal E2Y)
	DIM nReturnValue
 nReturnValue=0
	DIM deS
 deS=0.0
	DIM deT
 deT=0.0
	DIM deDivS
 deDivS = 0.0
	DIM deDivT
 DeDivT = 0.0

 'MsgBox "A1X: #" & A1X & "A1Y: #" & A1Y & " @1"
 'MsgBox "E1X: #" & E1X & "E1Y: #" & E1Y & " @1"
 'MsgBox "A2X: #" & A2X & "A2Y: #" & A2Y & " @1"
 'MsgBox "E2X: #" & E2X & "E2Y: #" & E2Y & " @1"

	deDivT=(A1X*E2Y)+(E2X*E1Y)+(E1X*A2Y)+(A2X*A1Y)-(E2X*A1Y)-(A1X*A2Y)-(A2X*E1Y)-(E1X*E2Y)
	If(0.0<>deDivT) Then
	 deT=((A1X*E1Y)+(E1X*A2Y)+(A2X*A1Y)-(E1X*A1Y)-(A2X*E1Y)-(A1X*A2Y))/deDivT
	Else
	 nReturnValue=0
 End If

	deDivS=(A2X*E1Y)+(E1X*E2Y)+(E2X*A1Y)+(A1X*A2Y)-(E1X*A2Y)-(A2X*A1Y)-(A1X*E2Y)-(E2X*E1Y)
	If(0.0<>deDivS) Then
	 deS =((A2X*E2Y)+(E2X*A1Y)+(A1X*A2Y)-(E2X*A2Y)-(A1X*E2Y)-(A2X*A1Y))/deDivS
	Else
	 nReturnValue=0
 End If

 X = (A1X+deS*(E1X-A1X))
 Y = (A1Y+deS*(E1Y-A1Y))


	'Wenn deS und deT im Intervall [0,1] liegen, dann schneiden sich die Strecken.
	If((deDivS<>0.0) and (deDivT<>0.0) and (deT>=0.0) and (deT<=1.0) and (deS>=0.0) and (deS<=1.0)) Then
	 nReturnValue=1
			'MsgBox "deDivS: #" & deDivS & " @1"
			'MsgBox "deDivT: #" & deDivT & " @1"
			'MsgBox "deT: #" & deT & " @1"
			'MsgBox "deS: #" & deS & " @1"
		 'MsgBox "X: #" & X & " @1"
			'MsgBox "Y: #" & Y & " @1"
 End If

 If (nReturnValue=1) Then
	 If ((A1X = X) and (A1Y = Y)) Then
	 	 nReturnValue=0
	 End If
	If ((E1X = X) and (E1Y = Y)) Then
		 nReturnValue=0
	End If
	If ((A2X = X) and (A2Y = Y)) Then
		 nReturnValue=2
	End If
	If ((E2X = X) and (E2Y = Y)) Then
		 nReturnValue=2
	End If
 End If

 f_IntersectLine = nReturnValue
end function

function f_GetLine(ByRef AX, ByRef AY, ByRef EX, ByRef EY, ByVal TTYPE, ByVal IE, ByVal PosX, ByVal PosY, ByVal Lx, ByVal By)
  DIM HelpBy
  DIM HelpLx

  If (TTYPE=5) Then
   HelpBy = By
   HelpLx = Lx
  Else
   HelpBy = Lx
   HelpLx = By
  End If

  If (IE=1) Then
   AX = PosX
   AY = PosY
   EX = PosX+HelpBy
   EY = PosY
  Else If (IE=2) Then
   AX = PosX+HelpBy
   AY = PosY
   EX = PosX+HelpBy
   EY = PosY+HelpLx
  Else If (IE=3) Then
   AX = PosX+HelpBY
   AY = PosY+HelpLx
   EX = PosX
   EY = PosY+HelpLx
  Else If (IE=4) Then
   AX = PosX
   AY = PosY+HelpLx
   EX = PosX
   EY = PosY
  End If
  End If
  End If
  End If
	f_GetLine = 1
end function


function f_Bearbeite(ByVal TTYPE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal NPosX, ByVal NPosY, ByVal NPosZ)
 DIM Lx
 DIM By
 DIM Hz
 DIM PosX
 DIM PosY
 DIM PosZ
 DIM Index

 DIM I
 DIM J

 DIM SX
 DIM SY
 DIM OK

 DIM A1X
 DIM A1Y
 DIM E1X
 DIM E1Y
 DIM A2X
 DIM A2Y
 DIM E2X
 DIM E2Y
 A1X = 0.0
 A1Y = 0.0
 E1X = 0.0
 E1Y = 0.0
 A2X = 0.0
 A2Y = 0.0
 E2X = 0.0
 E2Y = 0.0

 CONST MaxPunkte = 36
 DIM S_PUNKTE(36, 7) 'MaxPunkte
 DIM S_Line(18) 'MaxPunkte/2
 DIM ISP(3)

'Querstiele Suchen

 FINDFIRSTTYPE(TTYPE)

 J = GETCOUNTTYPE(TTYPE)
 For I = 1 To J - 1

  Lx = GETPARAM(1)
  By = GETPARAM(2)
  Hz = GETPARAM(3)
  PosX = GETPARAM(4)
  PosY = GETPARAM(5)
  Index = GETPARAM(6)
  'MsgBox "Lx: #" & Lx & "By: #" & By & "PosX: #" & PosX & "PosY: #" & PosY & " @1"

  DIM IEcken
  DIM IEcken2
  ISP(0) = 0
  ISP(1) = 0
  ISP(2) = 0

  For IEcken = 1 To 4
   OK = f_GetLine(A1X,A1Y,E1X,E1Y,TTYPE,IEcken,PosX,PosY,Lx,By)
  'MsgBox "A1X: #" & A1X & "A1Y: #" & A1Y & "E1X: #" & E1X & "E1Y: #" & E1Y & " @1"
    For IEcken2 = 1 To 4
     OK = f_GetLine(A2X,A2Y,E2X,E2Y,5,IEcken2,NPosX,NPosY,NLx,NBy)
    'MsgBox "A2X: #" & A2X & "A2Y: #" & A2Y & "E2X: #" & E2X & "E2Y: #" & E2Y & " @1"
     OK = f_IntersectLine(SX,SY,A1X,A1Y,E1X,E1Y,A2X,A2Y,E2X,E2Y)
     If ((OK > 0) AND (ISP(0) < MaxPunkte))  Then
      S_PUNKTE(ISP(0),0) = SX
      S_PUNKTE(ISP(0),1) = SY
      S_PUNKTE(ISP(0),3) = IEcken
      S_PUNKTE(ISP(0),4) = IEcken2
	     S_PUNKTE(ISP(0),5) = OK
      ISP(0) = ISP(0) + 1
      ISP(OK) = ISP(OK) + 1
     End If
    Next
  Next

  ISP(0) = ISP(0) - 1
  ISP(1) = ISP(1) - 1
  ISP(2) = ISP(2) - 1

  DIM ISL
  ISL = 0
  DIM Richtung
  Richtung = 0.0

  If (ISP(1) = 3) or (ISP(1) = 1) Then
   'MsgBox " 00: #" & S_PUNKTE(0,0) & " 01: #" & S_PUNKTE(0,1) & " 10: #" & S_PUNKTE(1,0) & " 11: #" & S_PUNKTE(1,1) & " @1"

   If (ISP(1) = 1) Then
    For IEcken = 0 To ISP(0)
	    If (S_PUNKTE(IEcken,5)=1) Then
      If (S_PUNKTE(0,4)=S_PUNKTE(1,4)) Then
       S_Line(0) = 0
       S_Line(1) = 1
       Richtung = 1
       'MsgBox "Gleich: #"
      Else
       S_Line(0) = 0
       S_Line(1) = 1
       'MsgBox "Ungleich: #"
      End If
      ISL = 1
	    End If
    Next
   Else
    For IEcken = 0 To ISP(0)
     'MsgBox "IE: #" & IEcken
     S_PUNKTE(IEcken,6) = 0
     For IEcken2 = (IEcken+1) To ISP(0)
      If ((S_PUNKTE(IEcken,4)=S_PUNKTE(IEcken2,4)) AND (S_PUNKTE(IEcken,5)=S_PUNKTE(IEcken2,5)) AND (S_PUNKTE(IEcken,5)=1)) Then
       S_PUNKTE(IEcken,6) = IEcken2
       S_Line(ISL) = IEcken
       ISL = ISL + 1
       'MsgBox " 0: #" & S_PUNKTE(IEcken,0) & " 1: #" & S_PUNKTE(IEcken,1) & " 0: #" & S_PUNKTE(IEcken2,0) & " 1: #" & S_PUNKTE(IEcken2,1) & " @1"
      End If
     Next
    Next
   ISL = ISL - 1
   End IF

   DIM Help1
   If (ISL = 1) Then

   	DIM YDiff
	   YDiff = 0.0
	   DIM XDiff
	   XDiff = 0.0

	   YDiff = (S_PUNKTE(S_Line(0),1) - S_PUNKTE(S_Line(1),1))
	   XDiff = (S_PUNKTE(S_Line(0),0) - S_PUNKTE(S_Line(1),0))

	   If (Richtung = 0) Then
		   If (YDiff <> 0.0) Then
			   Richtung = ATN(XDiff/YDiff)
		   Else
			   Richtung = 1
		   End If
	   Else
		   If (XDiff <> 0.0) Then
			   Richtung = ATN(YDiff/XDiff)
		   Else
			   Richtung = 1
		   End If
	   End If

    'MsgBox " R: #" & Richtung

	   DIM PUNKTSP
    DIM PUNKTSP2

    If (Richtung = 0) Then
     If (S_PUNKTE(S_Line(0),1) >= S_PUNKTE(S_Line(1),1)) Then
	     PUNKTSP = S_PUNKTE(S_Line(0),1)
	     PUNKTSP2 = S_PUNKTE(S_Line(1),1)
   	 Else
	     PUNKTSP = S_PUNKTE(S_Line(1),1)
	     PUNKTSP2 = S_PUNKTE(S_Line(0),1)
	    End If

     Help1 = (PUNKTSP - GETPARAM(5))
     If (TTYPE = 2) THEN
      OG GETPARAM(1), GETPARAM(2)-Help1, GETPARAM(3), GETPARAM(4), PUNKTSP, GETPARAM(6), "Obergurt", 0
     Else If (TTYPE = 3) THEN
      UG GETPARAM(1), GETPARAM(2)-Help1, GETPARAM(3), GETPARAM(4), PUNKTSP, GETPARAM(6), "Untergurt", 0
     Else If (TTYPE = 4) THEN
      LS GETPARAM(1), GETPARAM(2)-Help1, GETPARAM(3), GETPARAM(4), PUNKTSP, GETPARAM(6), "Laengsstiel", 0
     Else If (TTYPE = 5) THEN
      QS GETPARAM(1)-Help1, GETPARAM(2), GETPARAM(3), GETPARAM(4), PUNKTSP, GETPARAM(6), "Querstiel", 0
     Else If (TTYPE = 7) THEN
      BT4 GETPARAM(1)-Help1, GETPARAM(2), GETPARAM(3), GETPARAM(4), PUNKTSP, GETPARAM(6), "BT4", 0
     Else If (TTYPE = 8) THEN
      BT6 GETPARAM(1)-Help1, GETPARAM(2), GETPARAM(3), GETPARAM(4), PUNKTSP, GETPARAM(6), "BT6", 0
     End If
     End If
     End If
     End If
     End If
     End If
     Help1 = GETPARAM(1)-(PUNKTSP2 - GETPARAM(5))
     OK = SETPARAM(1,GETPARAM(1)-Help1)
    Else
     If (S_PUNKTE(S_Line(0),0) >= S_PUNKTE(S_Line(1),0)) Then
	     PUNKTSP = S_PUNKTE(S_Line(0),0)
	     PUNKTSP2 = S_PUNKTE(S_Line(1),0)
	    Else
	     PUNKTSP = S_PUNKTE(S_Line(1),0)
	     PUNKTSP2 = S_PUNKTE(S_Line(0),0)
	    End If

     Help1 = (PUNKTSP - GETPARAM(4))
     If (TTYPE = 2) THEN
      OG GETPARAM(1)-Help1, GETPARAM(2), GETPARAM(3), PUNKTSP, GETPARAM(5), GETPARAM(6), "Obergurt", 0
     Else If (TTYPE = 3) THEN
      UG GETPARAM(1)-Help1, GETPARAM(2), GETPARAM(3), PUNKTSP, GETPARAM(5), GETPARAM(6), "Untergurt", 0
     Else If (TTYPE = 4) THEN
      LS GETPARAM(1)-Help1, GETPARAM(2), GETPARAM(3), PUNKTSP, GETPARAM(5), GETPARAM(6), "Laengsstiel", 0
     Else If (TTYPE = 5) THEN
      QS GETPARAM(1), GETPARAM(2)-Help1, GETPARAM(3), PUNKTSP, GETPARAM(5), GETPARAM(6), "Querstiel", 0
     Else If (TTYPE = 7) THEN
      BT4 GETPARAM(1), GETPARAM(2)-Help1, GETPARAM(3), PUNKTSP, GETPARAM(5), GETPARAM(6), "BT4", 0
     Else If (TTYPE = 8) THEN
      BT6 GETPARAM(1), GETPARAM(2)-Help1, GETPARAM(3), PUNKTSP, GETPARAM(5), GETPARAM(6), "BT6", 0
     End If
     End If
     End If
     End If
     End If
     End If
     Help1 = GETPARAM(2)-(PUNKTSP2 - GETPARAM(4))
     OK = SETPARAM(1,GETPARAM(2)-Help1)
    End If
   End If
  End If

 	FINDNEXTTYPE(TTYPE)
 Next
 f_Bearbeite = 1
end function


function f_Ausschneiden(ByVal TTYPE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal NPosX, ByVal NPosY, ByVal NPosZ)

 DIM OK
 OK = f_Bearbeite(2,NLx,NBy,NHz,NPosX,NPosY,NPosZ)
 OK = f_Bearbeite(3,NLx,NBy,NHz,NPosX,NPosY,NPosZ)
 OK = f_Bearbeite(4,NLx,NBy,NHz,NPosX,NPosY,NPosZ)
 OK = f_Bearbeite(5,NLx,NBy,NHz,NPosX,NPosY,NPosZ)
 f_Ausschneiden = OK
end function

function f_BT_and_Ausschneiden(ByVal TTYPE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal NPosX, ByVal NPosY, ByVal NPosZ)

 DIM OK
 If (TTYPE = 2) Then
  'Achtung Tauschen
  OK = f_Ausschneiden (TTYPE,NBy,NLx,NHz,NPosX,NPosY,NPosZ)
  OG NLx,NBy,NHz,NPosX,NPosY,1,"Obergurt", 0
 Else If (TTYPE = 3) Then
  'Achtung Tauschen
  OK = f_Ausschneiden (TTYPE,NBy,NLx,NHz,NPosX,NPosY,NPosZ)
  UG NLx,NBy,NHz,NPosX,NPosY,1,"Untergurt", 0
 Else If (TTYPE = 4) Then
  'Achtung Tauschen
  OK = f_Ausschneiden (TTYPE,NBy,NLx,NHz,NPosX,NPosY,NPosZ)
  LS NLx,NBy,NHz,NPosX,NPosY,1,"Laengsstiel", 0
 Else If (TTYPE = 5) Then
  OK = f_Ausschneiden (TTYPE,NLx,NBy,NHz,NPosX,NPosY,NPosZ)
  QS NLx,NBy,NHz,NPosX,NPosY,1,"Querstiel", 0
 End If
 End If
 End If
 End If

 f_BT_and_Ausschneiden = OK
end function

function f_GetLineBT4(ByRef AX, ByRef AY, ByRef EX, ByRef EY, ByVal TTYPE, ByVal IE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal XLU, ByVal YLU, ByVal XRU, ByVal YRU, ByVal XRO, ByVal YRO, ByVal XLO, ByVal YLO)

  DIM HelpBy
  DIM HelpLx

  If (IE=1) Then
   AX = XLU
   AY = YLU
   EX = XRU
   EY = YRU
  Else If (IE=2) Then
   AX = XRU
   AY = YRU
   EX = XRO
   EY = YRO
  Else If (IE=3) Then
   AX = XRO
   AY = YRO
   EX = XLO
   EY = YLO
  Else If (IE=4) Then
   AX = XLO
   AY = YLO
   EX = XLU
   EY = YLU
  End If
  End If
  End If
  End If
	f_GetLineBT4 = 1
end function

function f_BearbeiteBT4(ByVal TTYPE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal NXLU, ByVal NYLU, ByVal NXRU, ByVal NYRU, ByVal NXRO, ByVal NYRO, ByVal NXLO, ByVal NYLO)

 DIM Lx
 DIM By
 DIM Hz
 DIM PosX
 DIM PosY
 DIM PosZ
 DIM Index

 DIM I
 DIM J

 DIM SX
 DIM SY
 DIM OK

 DIM A1X
 DIM A1Y
 DIM E1X
 DIM E1Y
 DIM A2X
 DIM A2Y
 DIM E2X
 DIM E2Y
 A1X = 0.0
 A1Y = 0.0
 E1X = 0.0
 E1Y = 0.0
 A2X = 0.0
 A2Y = 0.0
 E2X = 0.0
 E2Y = 0.0

 DIM ALx
 DIM ABy
 DIM AHz
 DIM XLU
 DIM YLU
 DIM XRU
 DIM YRU
 DIM XRO
 DIM YRO
 DIM XLO
 DIM YLO

 ALx = 0.0
 ABy = 0.0
 AHz = 0.0
 XLU = 0.0
 YLU = 0.0
 XRU = 0.0
 YRU = 0.0
 XRO = 0.0
 YRO = 0.0
 XLO = 0.0
 YLO = 0.0


 CONST MaxPunkte = 36
 DIM S_PUNKTE(36, 7) 'MaxPunkte
 DIM S_Line(18) 'MaxPunkte/2
 DIM ISP(3)

'Querstiele Suchen

 FINDFIRSTTYPE(TTYPE)

 J = GETCOUNTTYPE(TTYPE)
 For I = 1 To J - 1

  Lx = GETPARAM(1)
  By = GETPARAM(2)
  Hz = GETPARAM(3)
  PosX = GETPARAM(4)
  PosY = GETPARAM(5)
  Index = GETPARAM(6)
  'MsgBox "Lx: #" & Lx & "By: #" & By & "PosX: #" & PosX & "PosY: #" & PosY & " @1"

  DIM IEcken
  DIM IEcken2
  ISP(0) = 0
  ISP(1) = 0
  ISP(2) = 0

  For IEcken = 1 To 4
   OK = f_GetLine(A1X,A1Y,E1X,E1Y,TTYPE,IEcken,PosX,PosY,Lx,By)
   'MsgBox "A1X: #" & A1X & "A1Y: #" & A1Y & "E1X: #" & E1X & "E1Y: #" & E1Y & " @1"
    For IEcken2 = 1 To 4
	   OK = f_GetLineBT4(A2X,A2Y,E2X,E2Y,5,IEcken2,NLx,NBy,NHz,NXLU,NYLU,NXRU,NYRU,NXRO,NYRO,NXLO,NYLO)
    'MsgBox "A2X: #" & A2X & "A2Y: #" & A2Y & "E2X: #" & E2X & "E2Y: #" & E2Y & " @1"
     OK = f_IntersectLine(SX,SY,A1X,A1Y,E1X,E1Y,A2X,A2Y,E2X,E2Y)
     If ((OK > 0) AND (ISP(0) < MaxPunkte))  Then
      S_PUNKTE(ISP(0),0) = SX
      S_PUNKTE(ISP(0),1) = SY
      S_PUNKTE(ISP(0),3) = IEcken
      S_PUNKTE(ISP(0),4) = IEcken2
	     S_PUNKTE(ISP(0),5) = OK
      ISP(0) = ISP(0) + 1
      ISP(OK) = ISP(OK) + 1
     End If
    Next
  Next

  ISP(0) = ISP(0) - 1
  ISP(1) = ISP(1) - 1
  ISP(2) = ISP(2) - 1

  DIM ISL
  ISL = 0
  DIM Richtung
  Richtung = 0.0

  If (ISP(1) = 3) or (ISP(1) = 1) Then
   'MsgBox " 00: #" & S_PUNKTE(0,0) & " 01: #" & S_PUNKTE(0,1) & " 10: #" & S_PUNKTE(1,0) & " 11: #" & S_PUNKTE(1,1) & " @1"

   If (ISP(1) = 1) Then
    For IEcken = 0 To ISP(0)
	    If (S_PUNKTE(IEcken,5)=1) Then
      If (S_PUNKTE(0,4)=S_PUNKTE(1,4)) Then
       S_Line(0) = 0
       S_Line(1) = 1
       Richtung = 1
       'MsgBox "Gleich: #"
      Else
       S_Line(0) = 0
       S_Line(1) = 1
       'MsgBox "Ungleich: #"
      End If
      ISL = 1
	    End If
    Next
   Else
    For IEcken = 0 To ISP(0)
     'MsgBox "IE: #" & IEcken
     S_PUNKTE(IEcken,6) = 0
     For IEcken2 = (IEcken+1) To ISP(0)
      If ((S_PUNKTE(IEcken,4)=S_PUNKTE(IEcken2,4)) AND (S_PUNKTE(IEcken,5)=S_PUNKTE(IEcken2,5)) AND (S_PUNKTE(IEcken,5)=1)) Then
       S_PUNKTE(IEcken,6) = IEcken2
       S_Line(ISL) = IEcken
       'MsgBox " ISL:" & ISL
       'MsgBox " E1:" & IEcken & " E2:" & IEcken2
       'MsgBox " S_P 0:" & S_PUNKTE(IEcken,0) & " 1:" & S_PUNKTE(IEcken,1) & " 0:" & S_PUNKTE(IEcken2,0) & " 1:" & S_PUNKTE(IEcken2,1)
       'MsgBox " S_PL 0:" & S_PUNKTE(S_Line(ISL),0) & " 1:" & S_PUNKTE(S_Line(ISL),1) & " 0:" & S_PUNKTE(S_PUNKTE(S_Line(ISL),6),0) & " 1:" & S_PUNKTE(S_PUNKTE(S_Line(ISL),6),1)
       ISL = ISL + 1
      End If
     Next
    Next
   ISL = ISL - 1
   End IF

   DIM Help1
   If (ISL = 1) Then
 	  DIM YDiff
 	  YDiff = 0.0
 	  DIM XDiff
 	  XDiff = 0.0

 	  YDiff = (S_PUNKTE(S_Line(0),1) - S_PUNKTE(S_Line(1),1))
 	  XDiff = (S_PUNKTE(S_Line(0),0) - S_PUNKTE(S_Line(1),0))

 	  If (Richtung = 0) Then
 		  If (YDiff <> 0.0) Then
 		  	Richtung = ATN(XDiff/YDiff)
 		  Else
 		  	Richtung = 1
 		  End If
 	  Else
 	  	If (XDiff <> 0.0) Then
 		  	Richtung = ATN(YDiff/XDiff)
 		  Else
 		  	Richtung = 1
 		  End If
 	  End If

    'MsgBox " R: #" & Richtung

    DIM ISL0
    DIM ISL1
    ISL0 = 0
    ISL1 = 1

    If (Richtung = 0) Then
     If (S_PUNKTE(S_Line(0),1) >= S_PUNKTE(S_Line(1),1)) Then
      ISL0 = 1
      ISL1 = 0
	    Else
      ISL0 = 0
      ISL1 = 1
     End If

     ALx = GETPARAM(1)
     ABy = GETPARAM(2)
     AHz = GETPARAM(3)
     If ((TTYPE = 2) OR (TTYPE = 3) OR (TTYPE = 4)) Then
      XRU = S_PUNKTE(S_Line(ISL1),0)
      YRU = S_PUNKTE(S_Line(ISL1),1)
      XLU = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),0)
      YLU = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),1)
      XRO = GETPARAM(4) + GETPARAM(1)
      YRO = GETPARAM(5)
      XLO = GETPARAM(4) + GETPARAM(1)
      YLO = GETPARAM(5) + GETPARAM(2)
      ALx = YLU - YLO
      BT4 ALx,ABy,AHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
     Else
      XRU = S_PUNKTE(S_Line(ISL1),0)
      YRU = S_PUNKTE(S_Line(ISL1),1)
      XLU = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),0)
      YLU = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),1)
      XRO = GETPARAM(4) + GETPARAM(2)
      YRO = GETPARAM(5) + GETPARAM(1)
      XLO = GETPARAM(4)
      YLO = GETPARAM(5) + GETPARAM(1)
      ALx = YLU - YLO
      BT4 ALx,ABy,AHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
     End If

     If ((TTYPE = 2) OR (TTYPE = 3) OR (TTYPE = 4)) Then
      XLU = GETPARAM(4)
      YLU = GETPARAM(5)
      XRU = GETPARAM(4)
      YRU = GETPARAM(5) + GETPARAM(2)
      XRO = S_PUNKTE(S_Line(ISL0),0)
      YRO = S_PUNKTE(S_Line(ISL0),1)
      XLO = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),0)
      YLO = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),1)
      ALx = YLU - YLO
     Else
      XLU = GETPARAM(4)
      YLU = GETPARAM(5)
      XRU = GETPARAM(4) + GETPARAM(2)
      YRU = GETPARAM(5)
      XRO = S_PUNKTE(S_Line(ISL0),0)
      YRO = S_PUNKTE(S_Line(ISL0),1)
      XLO = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),0)
      YLO = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),1)
      ALx = YLU - YLO
     End If
     DELETEACTUAL()
     BT4 ALx,ABy,AHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
    Else
     If (S_PUNKTE(S_Line(0),0) >= S_PUNKTE(S_Line(1),0)) Then
      ISL0 = 0
      ISL1 = 1
	    Else
      ISL0 = 1
      ISL1 = 0
	    End If

     ALx = GETPARAM(1)
     ABy = GETPARAM(2)
     AHz = GETPARAM(3)
     If ((TTYPE = 2) OR (TTYPE = 3) OR (TTYPE = 4)) Then
      XRU = S_PUNKTE(S_Line(ISL0),0)
      YRU = S_PUNKTE(S_Line(ISL0),1)
      XLU = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),0)
      YLU = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),1)
      XRO = GETPARAM(4) + GETPARAM(1)
      YRO = GETPARAM(5)
      XLO = GETPARAM(4) + GETPARAM(1)
      YLO = GETPARAM(5) + GETPARAM(2)
      ALx = YLU - YLO
      BT4 ALx,ABy,AHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
     Else
      XRU = S_PUNKTE(S_Line(ISL1),0)
      YRU = S_PUNKTE(S_Line(ISL1),1)
      XLU = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),0)
      YLU = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),1)
      XRO = GETPARAM(4) + GETPARAM(1)
      YRO = GETPARAM(5) + GETPARAM(2)
      XLO = GETPARAM(4)
      YLO = GETPARAM(5) + GETPARAM(2)
      ALx = YLU - YLO
      BT4 ALx,ABy,AHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
     End If

     If ((TTYPE = 2) OR (TTYPE = 3) OR (TTYPE = 4)) Then
      XLU = GETPARAM(4)
      YLU = GETPARAM(5) + GETPARAM(2)
      XRU = GETPARAM(4)
      YRU = GETPARAM(5)
      XRO = S_PUNKTE(S_Line(ISL1),0)
      YRO = S_PUNKTE(S_Line(ISL1),1)
      XLO = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),0)
      YLO = S_PUNKTE(S_PUNKTE(S_Line(ISL1),6),1)
      ALx = YLU - YLO
     Else
      XLU = GETPARAM(4)
      YLU = GETPARAM(5)
      XRU = GETPARAM(4) + GETPARAM(2)
      YRU = GETPARAM(5)
      XRO = S_PUNKTE(S_Line(ISL0),0)
      YRO = S_PUNKTE(S_Line(ISL0),1)
      XLO = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),0)
      YLO = S_PUNKTE(S_PUNKTE(S_Line(ISL0),6),1)
      ALx = YLU - YLO
     End If
     DELETEACTUAL()
     BT4 ALx,ABy,AHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
    End If
   End If
  End If

 	FINDNEXTTYPE(TTYPE)
 Next
 f_BearbeiteBT4 = 1
end function

function f_AusschneidenBT4(TTYPE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal NXLU, ByVal NYLU, ByVal NXRU, ByVal NYRU, ByVal NXRO, ByVal NYRO, ByVal NXLO, ByVal NYLO)


 DIM OK
 OK = f_BearbeiteBT4(2,NLx,NBy,NHz,NXLU,NYLU,NXRU,NYRU,NXRO,NYRO,NXLO,NYLO)
 OK = f_BearbeiteBT4(3,NLx,NBy,NHz,NXLU,NYLU,NXRU,NYRU,NXRO,NYRO,NXLO,NYLO)
 OK = f_BearbeiteBT4(4,NLx,NBy,NHz,NXLU,NYLU,NXRU,NYRU,NXRO,NYRO,NXLO,NYLO)
 OK = f_BearbeiteBT4(5,NLx,NBy,NHz,NXLU,NYLU,NXRU,NYRU,NXRO,NYRO,NXLO,NYLO)
 f_AusschneidenBT4 = OK
end function

function f_BT4_and_Ausschneiden(ByVal TTYPE, ByVal NLx, ByVal NBy, ByVal NHz, ByVal XLU, ByVal YLU, ByVal XRU, ByVal YRU, ByVal XRO, ByVal YRO, ByVal XLO, ByVal YLO)

 DIM OK
 If (TTYPE = 7) Then
  'Achtung Tauschen
  OK = f_AusschneidenBT4(TTYPE,NLx,NBy,NHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO)
  BT4 NLx,NBy,NHz,XLU,YLU,XRU,YRU,XRO,YRO,XLO,YLO,1,"BT4", 0
 End If

 f_BT4_and_Ausschneiden = OK
end function
