From da7ebc6b97f0009a66be87cd82a89693817c22e3 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 29 Aug 2024 18:17:08 +0200 Subject: [PATCH] - refactoring di ProcessHeadCut --- LuaLibs/ProcessHeadCut.lua | 275 ++++++++++++++++++++----------------- 1 file changed, 146 insertions(+), 129 deletions(-) diff --git a/LuaLibs/ProcessHeadCut.lua b/LuaLibs/ProcessHeadCut.lua index 31f4069..1936b69 100644 --- a/LuaLibs/ProcessHeadCut.lua +++ b/LuaLibs/ProcessHeadCut.lua @@ -156,7 +156,7 @@ end --------------------------------------------------------------------- -- tagli verticali aggiuntivi -local function AddVerticalPreCuts( Proc, sCutting, dCutXOffset, b3Raw ) +local function AddVerticalPreCuts( Proc, sCutting, dCutXOffset, b3Raw) local _, dimH = BL.GetFaceHvRefDim( Proc.Id, 0, b3Raw) local nVerticalCuts = ceil( dimH / ( BD.MAX_LEN_DICE)) - 1 local dVerticalSliceHeight = dimH / ( nVerticalCuts + 1) @@ -180,6 +180,135 @@ local function AddVerticalPreCuts( Proc, sCutting, dCutXOffset, b3Raw ) return bOk, sErr end +--------------------------------------------------------------------- +-- tagli standard +local function MakeStandardCuts( Proc, b3Raw, nCuts, dOffsetBetweenCuts, HeadCutType, Cutting1Data, Cutting2Data, bNeedVerticalAddedCuts, bNeedHorizontalAddedCuts) + if not HeadCutType.bDoubleHorizCut then + -- flag di lavorazione faccia + local nOrthoOpposite = EgtIf( HeadCutType.bHorizCut, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_FRONT) + -- calcolo extra taglio ed accorciamento + local dCutExtra = 0 + local dAccStart = 0 + local dAccEnd = 0 + + if b3Raw:getDimZ() < BD.MIN_DIM_HBEAM + 10 * GEO.EPS_SMALL or b3Raw:getDimY() < 2 * BD.MAX_DIM_HTCUT_HBEAM + 10 * GEO.EPS_SMALL then + dCutExtra = EgtIf( HeadCutType.bDoubleCut, - 0.5 * b3Raw:getDimY() + BD.CUT_EXTRA_MIN, BD.CUT_EXTRA) + else + dCutExtra = - ( b3Raw:getDimY() - Cutting1Data.dMaxDepth) + local dSawRad = Cutting1Data.dSawDiam / 2 + -- distanza in Y tra il centro della lama e l'intersezione tra la lama stessa e la massima Z della trave, + extra + -- se taglio doppio l'intersezione sarà in mezzeria, se taglio singolo sarà all'estremo opposto della trave + local dKL = dSawRad - Cutting1Data.dMaxDepth + EgtIf( HeadCutType.bDoubleCut, b3Raw:getDimY() / 2 + BD.CUT_EXTRA_MIN, b3Raw:getDimY() + BD.CUT_EXTRA) + -- lunghezza minima del percorso di lavorazione, in caso accorciamento porti a lunghezza negativa + local dMinSawingLength = 5 + if BD.C_SIMM then + dAccEnd = sqrt( max( dSawRad * dSawRad - dKL * dKL, 0)) + -- non posso comunque accorciare più della dimensione della geometria, quindi in caso allungo entrata + if dAccEnd > b3Raw:getDimZ() - 100 * GEO.EPS_SMALL then + dAccStart = b3Raw:getDimZ() - dAccEnd - dMinSawingLength + end + else + dAccStart = sqrt( max( dSawRad * dSawRad - dKL * dKL, 0)) + -- non posso comunque accorciare più della dimensione della geometria, quindi in caso allungo uscita + if dAccStart > b3Raw:getDimZ() - 100 * GEO.EPS_SMALL then + dAccEnd = b3Raw:getDimZ() - dAccStart - dMinSawingLength + end + end + end + + -- per travi alte faccio dei tagli orizzontali aggiuntivi + if bNeedHorizontalAddedCuts then + local nHorizontalCuts = ceil( Proc.Face[1].HeightTrimmed / BD.MAX_DIM_DICE) - 1 + local dHorizontalSliceHeight = Proc.Face[1].HeightTrimmed / ( nHorizontalCuts + 1) + for i = nCuts, 1, -1 do + local dCutXOffset = ( i - 1) * dOffsetBetweenCuts + -- tagli orizzontali + for j = nHorizontalCuts, 1, -1 do + local nFaceUse = MCH_MILL_FU.PARAL_DOWN + local dHorizontalCutOffset = dHorizontalSliceHeight * -j + local bForceTangentLeadInOut = BD.PRESS_ROLLER + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting1Data.sCutting, Cutting1Data.dSawDiam, nFaceUse, nil, -0.1 -dCutXOffset, BD.CUT_SIC, dHorizontalCutOffset, 0, 0, '', b3Raw, nil, nil, nil, bForceTangentLeadInOut) + if not bOk then return bOk, sErr end + end + -- se necessario taglio verticale doppio, eseguo l'opposto + if HeadCutType.bDoubleCut then + -- gli accorciamenti vanno invertiti per il taglio opposto + local dAccStartDoubleCut, dAccEndDoubleCut = dAccEnd, dAccStart + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting1Data.sCutting, Cutting1Data.dSawDiam, MCH_MILL_FU.ORTHO_BACK, nil, dCutExtra, BD.CUT_SIC, dCutXOffset, dAccStartDoubleCut, dAccEndDoubleCut, '', b3Raw, true) + if not bOk then return false, sErr end + end + -- taglio verticale + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting1Data.sCutting, Cutting1Data.dSawDiam, nOrthoOpposite, nil, dCutExtra, BD.CUT_SIC, dCutXOffset, dAccStart, dAccEnd, '', b3Raw) + if not bOk then return bOk, sErr end + end + return true, sWarn + end + + -- se necessari tagli in doppio, eseguo gli opposti + if HeadCutType.bDoubleCut then + -- gli accorciamenti vanno invertiti per il taglio opposto + local dAccStartDoubleCut, dAccEndDoubleCut = dAccEnd, dAccStart + for i = nCuts, 1, -1 do + local dCutOffset = ( i - 1) * dOffsetBetweenCuts + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting1Data.sCutting, Cutting1Data.dSawDiam, MCH_MILL_FU.ORTHO_BACK, nil, dCutExtra, BD.CUT_SIC, dCutOffset, dAccStartDoubleCut, dAccEndDoubleCut, '', b3Raw, true) + if not bOk then return false, sErr end + end + end + -- eseguo i tagli necessari + for i = nCuts, 1, -1 do + local dCutOffset = ( i - 1) * dOffsetBetweenCuts + -- se trave larga effettuo tagli verticali aggiuntivi + if bNeedVerticalAddedCuts then + local bOk, sErr = AddVerticalPreCuts( Proc, Cutting1Data.sCutting, dCutOffset, b3Raw) + if not bOk then return bOk, sErr end + end + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting1Data.sCutting, Cutting1Data.dSawDiam, nOrthoOpposite, nil, dCutExtra, BD.CUT_SIC, dCutOffset, dAccStart, dAccEnd, '', b3Raw) + if not bOk then return false, sErr end + end + -- altrimenti necessari tagli da sopra e sotto con testa opportuna + else + -- verifico esistenza della lavorazione con lama da sotto + if not Cutting2Data.sCutting then + local sErr = 'Error : cutting H2 not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- verifico che le due lame riescano a lavorare la sezione + local dDimZ = b3Raw:getDimZ() + local dExtra = Cutting1Data.dMaxVertDepth + Cutting2Data.dMaxDepth - dDimZ + if ( dExtra - 2 * BD.CUT_EXTRA_MIN + 10 * GEO.EPS_SMALL < 0) and not HeadCutType.bBigSectionCut then + local sErr = 'Error : section too big for head cut' + EgtOutLog( sErr) + return false, sErr + end + -- calcolo extra taglio ed accorciamento + local dCutExtra = -Cutting2Data.dMaxDepth + dExtra / 2 + BD.CUT_EXTRA_MIN + local dCutExtra2 = -Cutting1Data.dMaxVertDepth + dExtra / 2 + BD.CUT_EXTRA_MIN + local dAccStart = 0 + local dVzLimDwnUp + if BD.TURN then dVzLimDwnUp = -2 end + -- eseguo i tagli da sotto necessari + for i = nCuts, 1, -1 do + local dCutOffset = ( i - 1) * dOffsetBetweenCuts + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting2Data.sCutting, Cutting2Data.dSawDiam, MCH_MILL_FU.ORTHO_TOP, dVzLimDwnUp, dCutExtra2, BD.CUT_SIC, dCutOffset, dAccStart, 0, '', b3Raw, nil, true) + if not bOk then return false, sErr end + end + -- eseguo i tagli da sopra necessari + for i = nCuts, 1, -1 do + local dCutOffset = ( i - 1) * dOffsetBetweenCuts + -- se trave larga effettuo tagli verticali aggiuntivi + if bNeedVerticalAddedCuts then + local bOk, sErr = AddVerticalPreCuts( Proc, Cutting1Data.sCutting, dCutOffset, b3Raw) + if not bOk then return bOk, sErr end + end + local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, Cutting1Data.sCutting, Cutting1Data.dSawDiam, MCH_MILL_FU.ORTHO_DOWN, dVzLimDwnUp, dCutExtra, BD.CUT_SIC, dCutOffset, dAccStart, 0, '', b3Raw) + if not bOk then return false, sErr end + end + end + + return true +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessHeadCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, bNeedHCut) @@ -243,7 +372,6 @@ function ProcessHeadCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, bNeedHCut -- determino se lo spessore del materiale da rimuovere è eccessivo e quindi vanno fatti più tagli con offset local nCuts = max( ceil( dOvmHead / (( BD.MAX_LEN_SCRAP_START or BD.MAX_LEN_SCRAP) + 0.5)), 1) local dOffsL = dOvmHead / nCuts - local _, dimH, dimV = BL.GetFaceHvRefDim( Proc.Id, 0, b3Raw) local dMinOvmHeadForAddeddCuts = 10.123 -- se taglio per sezioni alte e larghe if bBigSectionCut then @@ -264,7 +392,7 @@ function ProcessHeadCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, bNeedHCut if dMaxElev > dSawThickCheck then local bOk, sErr -- se trave larga effettuo tagli verticali aggiuntivi - if ( dimH > BD.MAX_LEN_DICE) and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) then + if ( Proc.Face[1].WidthTrimmed > BD.MAX_LEN_DICE) and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) then -- ad ogni offset di taglio dovrò fare prima i tagli verticali e poi i cubetti for i = nCuts, 1, -1 do local nAddGrpId = BL.GetAddGroup( Proc.PartId) @@ -289,11 +417,11 @@ function ProcessHeadCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, bNeedHCut bOk, sErr = AddVerticalPreCuts( AddProc, sCutting, 0, b3Raw) if not bOk then return bOk, sErr end -- tagli a cubetti con eventuale superficie limitante - bOk, sErr = Cut.Make( AddProc, nPhase, nRawId, nPartId, dOvmHead, nil, false, true, nil, nil, dCurrOvmT, nil, nLimitingSurf) + bOk, sErr = Cut.Make( AddProc, nPhase, nRawId, nPartId, dOvmHead, nil, false, true, nil, nil, nil, nil, nLimitingSurf) end -- tagli aggiuntivi non necessari else - bOk, sErr = Cut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, nil, false, true, nil, nil, dCurrOvmT) + bOk, sErr = Cut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, nil, false, true) end return bOk, sErr end @@ -316,131 +444,20 @@ function ProcessHeadCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, bNeedHCut end end end - -- se tagli standard - if not bDoubleHorizCut then - -- flag di lavorazione faccia - local nOrthoOpposite = EgtIf( bHorizCut, MCH_MILL_FU.ORTHO_DOWN, MCH_MILL_FU.ORTHO_FRONT) - -- calcolo extra taglio ed accorciamento - local dCutExtra = 0 - local dAccStart = 0 - local dAccEnd = 0 - if b3Raw:getDimZ() < BD.MIN_DIM_HBEAM + 10 * GEO.EPS_SMALL or b3Raw:getDimY() < 2 * BD.MAX_DIM_HTCUT_HBEAM + 10 * GEO.EPS_SMALL then - dCutExtra = EgtIf( bDoubleCut, - 0.5 * b3Raw:getDimY() + BD.CUT_EXTRA_MIN, BD.CUT_EXTRA) - else - dCutExtra = - ( b3Raw:getDimY() - dMaxDepth) - local dSawRad = dSawDiam / 2 - -- distanza in Y tra il centro della lama e l'intersezione tra la lama stessa e la massima Z della trave, + extra - -- se taglio doppio l'intersezione sarà in mezzeria, se taglio singolo sarà all'estremo opposto della trave - local dKL = dSawRad - dMaxDepth + EgtIf( bDoubleCut, b3Raw:getDimY() / 2 + BD.CUT_EXTRA_MIN, b3Raw:getDimY() + BD.CUT_EXTRA) - -- lunghezza minima del percorso di lavorazione, in caso accorciamento porti a lunghezza negativa - local dMinSawingLength = 5 - if BD.C_SIMM then - dAccEnd = sqrt( max( dSawRad * dSawRad - dKL * dKL, 0)) - -- non posso comunque accorciare più della dimensione della geometria, quindi in caso allungo entrata - if dAccEnd > b3Raw:getDimZ() - 100 * GEO.EPS_SMALL then - dAccStart = b3Raw:getDimZ() - dAccEnd - dMinSawingLength - end - else - dAccStart = sqrt( max( dSawRad * dSawRad - dKL * dKL, 0)) - -- non posso comunque accorciare più della dimensione della geometria, quindi in caso allungo uscita - if dAccStart > b3Raw:getDimZ() - 100 * GEO.EPS_SMALL then - dAccEnd = b3Raw:getDimZ() - dAccStart - dMinSawingLength - end - end - end - - -- per travi alte faccio dei tagli orizzontali aggiuntivi - local bAreHorizontalCutsNeeded = ( dimV > BD.MAX_LEN_DICE) and not bBigSectionCut and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) - if bAreHorizontalCutsNeeded then - local nHorizontalCuts = ceil( dimV / BD.MAX_DIM_DICE) - 1 - local dHorizontalSliceHeight = dimV / ( nHorizontalCuts + 1) - for i = nCuts, 1, -1 do - local dCutXOffset = ( i - 1) * dOffsL - -- tagli orizzontali - for j = nHorizontalCuts, 1, -1 do - local nFaceUse = MCH_MILL_FU.PARAL_DOWN - local dHorizontalCutOffset = dHorizontalSliceHeight * -j - local bForceTangentLeadInOut = BD.PRESS_ROLLER - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting, dSawDiam, nFaceUse, nil, -0.1 -dCutXOffset, BD.CUT_SIC, dHorizontalCutOffset, 0, 0, '', b3Raw, nil, nil, nil, bForceTangentLeadInOut) - if not bOk then return bOk, sErr end - end - -- se necessario taglio verticale doppio, eseguo l'opposto - if bDoubleCut then - -- gli accorciamenti vanno invertiti per il taglio opposto - local dAccStartDoubleCut, dAccEndDoubleCut = dAccEnd, dAccStart - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting, dSawDiam, MCH_MILL_FU.ORTHO_BACK, nil, dCutExtra, BD.CUT_SIC, dCutXOffset, dAccStartDoubleCut, dAccEndDoubleCut, '', b3Raw, true) - if not bOk then return false, sErr end - end - -- taglio verticale - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting, dSawDiam, nOrthoOpposite, nil, dCutExtra, BD.CUT_SIC, dCutXOffset, dAccStart, dAccEnd, '', b3Raw) - if not bOk then return bOk, sErr end - end - return true, sWarn - end - - -- se necessari tagli in doppio, eseguo gli opposti - if bDoubleCut then - -- gli accorciamenti vanno invertiti per il taglio opposto - local dAccStartDoubleCut, dAccEndDoubleCut = dAccEnd, dAccStart - for i = nCuts, 1, -1 do - local dCutOffset = ( i - 1) * dOffsL - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting, dSawDiam, MCH_MILL_FU.ORTHO_BACK, nil, dCutExtra, BD.CUT_SIC, dCutOffset, dAccStartDoubleCut, dAccEndDoubleCut, '', b3Raw, true) - if not bOk then return false, sErr end - end - end - -- eseguo i tagli necessari - for i = nCuts, 1, -1 do - local dCutOffset = ( i - 1) * dOffsL - -- se trave larga effettuo tagli verticali aggiuntivi - if ( dimH > BD.MAX_LEN_DICE) and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) then - local bOk, sErr = AddVerticalPreCuts( Proc, sCutting, dCutOffset, b3Raw) - if not bOk then return bOk, sErr end - end - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting, dSawDiam, nOrthoOpposite, nil, dCutExtra, BD.CUT_SIC, dCutOffset, dAccStart, dAccEnd, '', b3Raw) - if not bOk then return false, sErr end - end - -- altrimenti necessari tagli da sopra e sotto con testa opportuna - else - -- verifico esistenza della lavorazione con lama da sotto - if not sCutting2 then - local sErr = 'Error : cutting H2 not found in library' - EgtOutLog( sErr) - return false, sErr - end - -- verifico che le due lame riescano a lavorare la sezione - local dDimZ = b3Raw:getDimZ() - local dExtra = dMaxVertDepth + dMaxDepth2 - dDimZ - if ( dExtra - 2 * BD.CUT_EXTRA_MIN + 10 * GEO.EPS_SMALL < 0) and not bBigSectionCut then - local sErr = 'Error : section too big for head cut' - EgtOutLog( sErr) - return false, sErr - end - -- calcolo extra taglio ed accorciamento - local dCutExtra = -dMaxDepth2 + dExtra / 2 + BD.CUT_EXTRA_MIN - local dCutExtra2 = -dMaxVertDepth + dExtra / 2 + BD.CUT_EXTRA_MIN - local dAccStart = 0 - local dVzLimDwnUp - if BD.TURN then dVzLimDwnUp = -2 end - -- eseguo i tagli da sotto necessari - for i = nCuts, 1, -1 do - local dCutOffset = ( i - 1) * dOffsL - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting2, dSawDiam2, MCH_MILL_FU.ORTHO_TOP, dVzLimDwnUp, dCutExtra2, BD.CUT_SIC, dCutOffset, dAccStart, 0, '', b3Raw, nil, true) - if not bOk then return false, sErr end - end - -- eseguo i tagli da sopra necessari - for i = nCuts, 1, -1 do - local dCutOffset = ( i - 1) * dOffsL - -- se trave larga effettuo tagli verticali aggiuntivi - if ( dimH > BD.MAX_LEN_DICE) and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) then - local bOk, sErr = AddVerticalPreCuts( Proc, sCutting, dCutOffset, b3Raw) - if not bOk then return bOk, sErr end - end - local bOk, sErr = Fbs.MakeOne( Proc.Id, 0, sCutting, dSawDiam, MCH_MILL_FU.ORTHO_DOWN, dVzLimDwnUp, dCutExtra, BD.CUT_SIC, dCutOffset, dAccStart, 0, '', b3Raw) - if not bOk then return false, sErr end - end + + local HeadCutType = { bBigSectionCut = bBigSectionCut, bHorizCut = bHorizCut, bDoubleHorizCut = bDoubleHorizCut, bDoubleCut = bDoubleCut} + local Cutting1Data = { sCutting = sCutting, dSawDiam = dSawDiam, dMaxDepth = dMaxDepth, dSawThick = dSawThick } + local Cutting2Data = { sCutting = sCutting2, dSawDiam = dSawDiam2, dMaxDepth = dMaxDepth2, dSawThick = dSawThick2 } + local bNeedVerticalAddedCuts = false + if ( Proc.Face[1].WidthTrimmed > BD.MAX_LEN_DICE) and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) then + bNeedVerticalAddedCuts = true end - return true -end + local bNeedHorizontalAddedCuts = ( Proc.Face[1].HeightTrimmed > BD.MAX_LEN_DICE) and not bBigSectionCut and ( dOvmHead > dMinOvmHeadForAddeddCuts - 10 * GEO.EPS_SMALL) + + local bOk, sErr = MakeStandardCuts( Proc, b3Raw, nCuts, dOffsL, HeadCutType, Cutting1Data, Cutting2Data, bNeedVerticalAddedCuts, bNeedHorizontalAddedCuts) + + return bOk, sErr +end --------------------------------------------------------------------- return ProcessHeadCut