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

const MACROTITLE = "Macro"

SUB MAIN

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM sIni
DIM BALKEN_WIDTH
DIM BALKEN_HEIGHT
DIM BALKEN_LENGTH
DIM CURVE_WIDTH ' beam width to use for radiuses
DIM RADIUS_1 ' smaller radius (1/3)
DIM RADIUS_2 ' bigger radius (2/3)
DIM MILL_DEPTH

DIM MILL_WIDTH
DIM MILL_WIDTH_X
DIM MILL_WIDTH_ADDTOX1
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 X4
DIM Y1
DIM Y4
DIM ANGLE
DIM ANGLE_TYPE_1 ' for smaller radius (1/3)
DIM ANGLE_TYPE_2 ' for bigger radius (2/3)

'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_OVERHANG = 0 ' extend position in height-axis movement
MILL_HEIGHT = 0 ' z-coordinate of the PP element

INDEX_FRONT = 211 ' default values
EBENE_FRONT = 6
INDEX_TOP = 211
EBENE_TOP = 1
INDEX_CURVE = 111
EBENE_CURVE = 2
X1 = 15
X4 = 10
Y1 = 25
Y4 = 10
ANGLE = 0.0
ANGLE_TYPE_1 = "Acc" ' clockwise < 180
ANGLE_TYPE_2 = "Acw" ' counter-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_LENGTH = GETPARAM(1)
BALKEN_WIDTH = GETPARAM(2)
BALKEN_HEIGHT = GETPARAM(3)
IF NOT GetDimension("X1:", sIni, X1, BALKEN_WIDTH) THEN EXIT SUB
IF NOT GetDimension("X4:", sIni, X4, BALKEN_WIDTH) THEN EXIT SUB
IF NOT GetDimension("Y1:", sIni, Y1, BALKEN_WIDTH) THEN EXIT SUB
IF NOT GetDimension("Y4:", sIni, Y4, BALKEN_WIDTH-Y1) THEN EXIT SUB

CURVE_WIDTH = BALKEN_WIDTH - Y1 - Y4
RADIUS_1 = FIX( (CURVE_WIDTH / 3) + 0.5 ) ' round
RADIUS_2 = CURVE_WIDTH - RADIUS_1
IF MILL_WIDTH < X1 THEN
   MILL_WIDTH_X = X1 + MILL_WIDTH_ADDTOX1
ELSE
    MILL_WIDTH_X = MILL_WIDTH
END IF

' ==========================================================================
' front groove
MILL_DEPTH = -(MILL_HEIGHT + X4)
PAF EBENE_FRONT
PP BALKEN_HEIGHT+MILL_OVERHANG, Y1, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP -MILL_OVERHANG, Y1, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP -MILL_OVERHANG, Y1+MILL_WIDTH, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP BALKEN_HEIGHT+MILL_OVERHANG, Y1+MILL_WIDTH, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
PP BALKEN_HEIGHT+MILL_OVERHANG, Y1, MILL_DEPTH, INDEX_FRONT, ANGLE, MILL_HEIGHT
' top groove
MILL_DEPTH = -(MILL_HEIGHT + Y4)
PAF EBENE_TOP
PP BALKEN_LENGTH-X1-X4-CURVE_WIDTH, BALKEN_HEIGHT+MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP BALKEN_LENGTH-X1-X4-CURVE_WIDTH+MILL_WIDTH_X, BALKEN_HEIGHT+MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP BALKEN_LENGTH-X1-X4-CURVE_WIDTH+MILL_WIDTH_X, -MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP BALKEN_LENGTH-X1-X4-CURVE_WIDTH, -MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
PP BALKEN_LENGTH-X1-X4-CURVE_WIDTH, BALKEN_HEIGHT+MILL_OVERHANG, MILL_DEPTH, INDEX_TOP, ANGLE, MILL_HEIGHT
' curve milling
PAF EBENE_CURVE
MILL_DEPTH = -(MILL_HEIGHT+BALKEN_HEIGHT)
PP BALKEN_LENGTH-X4-CURVE_WIDTH, BALKEN_WIDTH+MILL_WIDTH, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
PP BALKEN_LENGTH-X4-CURVE_WIDTH, BALKEN_WIDTH-Y4, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
KB BALKEN_LENGTH-X4-RADIUS_2, Y1+RADIUS_2, RADIUS_1, ANGLE_TYPE_1, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
KB BALKEN_LENGTH-X4, Y1, RADIUS_2, ANGLE_TYPE_2, MILL_DEPTH, INDEX_CURVE, ANGLE, MILL_HEIGHT
PP BALKEN_LENGTH+MILL_WIDTH, Y1, 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