'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright by Weinmann Holzbausystemtechnik GmbH (c) 2005
'
' Filename:                Makro_7.WMK
'
' Description:        Bau Vila Makrodefinition, Makro 7
'
' Author:                Mikan
'
' Date:                        20050510
'
' Version:                V0.01
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

const MACROTITLE = "Macro"

SUB MAIN

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM sIni
DIM BALKEN_WIDTH
DIM BALKEN_HEIGHT
DIM RADIUS ' curve radius
DIM MILL_DEPTH

DIM MILL_WIDTH
DIM MILL_WIDTH_X
DIM MILL_WIDTH_ADDTOX1
DIM MILL_WIDTH_Y
DIM MILL_WIDTH_ADDTOY1
DIM MILL_OVERHANG
DIM MILL_HEIGHT
' input values
DIM INDEX_TOP
DIM EBENE_TOP
DIM INDEX_FRONT
DIM EBENE_FRONT
DIM INDEX_CURVE
DIM EBENE_CURVE
DIM X1
DIM X2
DIM XT
DIM Y1
DIM Y2
DIM YT
DIM ANGLE
DIM ANGLE_TYPE

'INITIALISIERUNG DER KONSTANTEN
MILL_WIDTH = 50 ' minimal width of the groove
                ' (also extent of the start position for curve milling)
MILL_WIDTH_ADDTOX1 = 30 ' in case X1 > MILL_WIDTH, specify MILL_WIDTH_X
                        ' as X1 + this constant
MILL_WIDTH_ADDTOY1 = 30 ' in case Y1 > MILL_WIDTH, specify MILL_WIDTH_Y
                        ' as Y1 + this constant
MILL_OVERHANG = 0 ' extend position in height-axis movement
MILL_HEIGHT = 0 ' z-coordinate of the PP element

INDEX_FRONT = 211 ' default values
EBENE_FRONT = 5
INDEX_TOP = 111
EBENE_TOP = 1
INDEX_CURVE = 211
EBENE_CURVE = 2
X1 = 40
X2 = 40
XT = 180
Y1 = 20
Y2 = 20
YT = 140
ANGLE = 0.0
ANGLE_TYPE = "Acw" ' clockwise < 180

'Holen Parameterbezeichnungen abhaengig von der Landessprache
sIni = "BV_l" + GETACTUALLANGUAGE() + ".ini"

' ==========================================================================

	IF NOT FINDFIRSTSELECTED THEN
		DIM BEAMCOUNTER

		BEAMCOUNTER = GETCOUNTTYPE(CalcType("LS"))
		BEAMCOUNTER = BEAMCOUNTER + GETCOUNTTYPE(CalcType("QS"))
		BEAMCOUNTER = BEAMCOUNTER + GETCOUNTTYPE(CalcType("BT4"))
		BEAMCOUNTER = BEAMCOUNTER + GETCOUNTTYPE(CalcType("BT6"))

		IF BEAMCOUNTER = 1 THEN
			IF GETCOUNTTYPE(CalcType("LS")) = 1 THEN
				FINDFIRSTTYPE(CalcType("LS"))
			END IF
			IF GETCOUNTTYPE(CalcType("QS")) = 1 THEN
				FINDFIRSTTYPE(CalcType("QS"))
			END IF
			IF GETCOUNTTYPE(CalcType("BT4")) = 1 THEN
				FINDFIRSTTYPE(CalcType("BT4"))
			END IF
			IF GETCOUNTTYPE(CalcType("BT6")) = 1 THEN
				FINDFIRSTTYPE(CalcType("BT6"))
			END IF
		ELSE
		  MsgBox GETPRIVATEPROFILESTRING("Fehler", "F1", " ", sIni),vbOkOnly+vbCritical+vbSystemModal,MACROTITLE
		  exit sub
		END IF
	END IF

	IF NOT (ISBEAM OR (ISBEAMPROCESSING AND SELECTPARENTBEAM())) THEN
	  MsgBox GETPRIVATEPROFILESTRING("Fehler", "F2", " ", sIni),vbOkOnly+vbCritical+vbSystemModal,MACROTITLE
	  exit sub
	END IF

' ==========================================================================

BALKEN_WIDTH = GETPARAM(2)
BALKEN_HEIGHT = GETPARAM(3)

IF NOT GetDimension("X1:", sIni, X1, X1) THEN EXIT SUB
IF MILL_WIDTH < X1 THEN
   MILL_WIDTH_X = X1 + MILL_WIDTH_ADDTOX1
ELSE
    MILL_WIDTH_X = MILL_WIDTH
END IF
IF NOT GetDimension("XT:", sIni, XT, XT) THEN EXIT SUB
IF NOT GetDimension("X2:", sIni, X2, X1) THEN EXIT SUB

IF NOT GetDimension("Y1:", sIni, Y1, Y1) THEN EXIT SUB
IF MILL_WIDTH < Y1 THEN
   MILL_WIDTH_Y = Y1 + MILL_WIDTH_ADDTOY1
ELSE
    MILL_WIDTH_Y = MILL_WIDTH
END IF
IF NOT GetDimension("YT:", sIni, YT, YT) THEN EXIT SUB
IF YT > BALKEN_WIDTH THEN
   MsgBox GETPRIVATEPROFILESTRING("Fehler", "F7", " ", sIni),vbOkOnly+vbCritical+vbSystemModal,MACROTITLE
    EXIT SUB
END IF
IF NOT GetDimension("Y2:", sIni, Y2, Y1) THEN EXIT SUB

RADIUS = XT - X1 - X2

' ==========================================================================
' front groove
MILL_DEPTH = -(MILL_HEIGHT + X2)
PAF EBENE_FRONT
PP BALKEN_HEIGHT+MILL_OVERHANG, BALKEN_WIDTH-YT, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP -MILL_OVERHANG, BALKEN_WIDTH-YT, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP -MILL_OVERHANG, BALKEN_WIDTH-YT+MILL_WIDTH_Y, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP BALKEN_HEIGHT+MILL_OVERHANG, BALKEN_WIDTH-YT+MILL_WIDTH_Y, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP BALKEN_HEIGHT+MILL_OVERHANG, BALKEN_WIDTH-YT, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
' top groove
MILL_DEPTH = -(MILL_HEIGHT + Y2)
PAF EBENE_TOP
PP XT, BALKEN_HEIGHT+MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP XT-MILL_WIDTH_X, BALKEN_HEIGHT+MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP XT-MILL_WIDTH_X, -MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP XT, -MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP XT, BALKEN_HEIGHT+MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
' curve milling
PAF EBENE_CURVE
MILL_DEPTH = -(MILL_HEIGHT+BALKEN_HEIGHT)
PP XT-X1, BALKEN_WIDTH+MILL_WIDTH, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
PP XT-X1, BALKEN_WIDTH-Y2, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
KB X2, BALKEN_WIDTH-Y2-RADIUS, RADIUS, ANGLE_TYPE, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
PP -MILL_WIDTH, BALKEN_WIDTH-Y1-RADIUS, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
END SUB

' ==========================================================================

PRIVATE FUNCTION GetDimension(DimName, IniFile, DimVal, MaxVal)
DO
  DimVal = InputBoxFLoc(DimName, MACROTITLE, DimVal)

  IF bInputBoxCancel = 1 THEN
     GetDimension = False
     EXIT FUNCTION
  END IF

  IF (0 <= DimVal) and (DimVal <= MaxVal) THEN
    GetDimension = true
    EXIT FUNCTION
  ELSE
  MsgBox GETPRIVATEPROFILESTRING("Fehler", "F5", " ", IniFile),vbOkOnly+vbCritical+ vbSystemModal,MACROTITLE
  END IF
LOOP
END FUNCTION

' ==========================================================================

MAIN