From d00127370425ed28988b3c912e9078566fd04aa5 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Tue, 31 Mar 2026 16:11:54 +0200 Subject: [PATCH 1/2] - in FlipRot e ProcessAlternatives si scrivono le variabili globali nella tabella Beam per l'interfaccia --- FlipRot.lua | 5 +++++ LuaLibs/BeamExec.lua | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/FlipRot.lua b/FlipRot.lua index f8e670a..988f70c 100644 --- a/FlipRot.lua +++ b/FlipRot.lua @@ -146,6 +146,11 @@ local function MyProcessFeatures() BeamExec.GetProcessings( PARTS, true) BeamExec.GetCombinationMatrix( PARTS, true) BeamExec.ProcessMachinings( PARTS) + + -- scrittura variabili globali per interfaccia + BEAM.PREROTATE90 = PARTS[1].nInitialPosition - 1 + BEAM.PREINVERT = EgtIf( PARTS[1].bPartInCombiIsInverted, 1, 0) + local nErrCnt = 0 local nWarnCnt = 0 local sOutput = '' diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index e5e54fa..79a4f54 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -1927,6 +1927,11 @@ end ------------------------------------------------------------------------------------------------------------- function BeamExec.ProcessAlternatives( PARTS) + + -- inizializzazione variabili globali per interfaccia + BEAM.ALTERNATIVESNEST2D = '' + BEAM.ALTERNATIVES = '' + -- ciclo sui pezzi local BestCombination = {} local nPart = 1 @@ -1935,7 +1940,7 @@ function BeamExec.ProcessAlternatives( PARTS) local bTryToReProcess = false -- se non serve trovare altre soluzioni, si esce subito - if not ( PARTS[nPart].GeneralParameters.GEN_bTestAlternative and not PARTS[nPart].bSquareSection) or not PARTS[nPart].GeneralParameters.GEN_bGetAlternativesNesting2D then + if not ( PARTS[nPart].GeneralParameters.GEN_bTestAlternative and not PARTS[nPart].bSquareSection) and not PARTS[nPart].GeneralParameters.GEN_bGetAlternativesNesting2D then return end @@ -1982,33 +1987,33 @@ function BeamExec.ProcessAlternatives( PARTS) if PARTS[nPart].GeneralParameters.GEN_bGetAlternativesNesting2D then -- POSIZIONE 0 (e invertito) local sCombinationToCheck = BeamLib.StringReplaceChar( '0000', PARTS[nPart].nInitialPosition, "1") - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}, bIsNesting2D = true}) if PARTS[nPart].GeneralParameters.GEN_bAllowPieceInversion then - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}, bIsNesting2D = true}) end -- POSIZIONE 180 (e invertito) if PARTS[nPart].GeneralParameters.GEN_sPiecesLoadingPosition == 'STD_PRE_ROTATION' then local nOtherPosition = EgtIf( PARTS[nPart].nInitialPosition + 2 > 4, PARTS[nPart].nInitialPosition + 2 - 4, PARTS[nPart].nInitialPosition + 2) sCombinationToCheck = BeamLib.StringReplaceChar( '0000', nOtherPosition, "1") - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}, bIsNesting2D = true}) if PARTS[nPart].GeneralParameters.GEN_bAllowPieceInversion then - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}, bIsNesting2D = true}) end end -- POSIZIONE 90/270 (e invertito) if PARTS[nPart].GeneralParameters.GEN_sPiecesLoadingPosition == 'FULL_PRE_ROTATION' then local nOtherPosition = EgtIf( PARTS[nPart].nInitialPosition + 1 > 4, PARTS[nPart].nInitialPosition + 1 - 4, PARTS[nPart].nInitialPosition + 1) sCombinationToCheck = BeamLib.StringReplaceChar( '0000', nOtherPosition, "1") - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}, bIsNesting2D = true}) if PARTS[nPart].GeneralParameters.GEN_bAllowPieceInversion then - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}, bIsNesting2D = true}) end nOtherPosition = EgtIf( PARTS[nPart].nInitialPosition + 3 > 4, PARTS[nPart].nInitialPosition + 3 - 4, PARTS[nPart].nInitialPosition + 3) sCombinationToCheck = BeamLib.StringReplaceChar( '0000', nOtherPosition, "1") - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck}, bIsNesting2D = true}) if PARTS[nPart].GeneralParameters.GEN_bAllowPieceInversion then - table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}}) + table.insert( TotalCombiToTest, {{ sBitIndexCombination = sCombinationToCheck, bPartInCombiIsInverted = true}, bIsNesting2D = true}) end end end @@ -2253,11 +2258,24 @@ function BeamExec.ProcessAlternatives( PARTS) -- Aggiornamento finale di tutto EgtSetCurrPhase( 1) local bApplOk, _, _ = EgtApplyAllMachinings() - -- se non ci sono errori, soluzione alternativa valida + -- se non ci sono errori, soluzione alternativa valida: scrittura variabili globali per interfaccia if bApplOk then - -- TODO scrivere info su pezzo! + local Alternatives = {} + local sBitIndexCombinationWithInvert = BestCombination.sBitIndexCombination .. EgtIf( BestCombination.bPartInCombiIsInverted, '_INV', '') + if TotalCombiToTest[z].bIsNesting2D then + if BEAM.ALTERNATIVESNEST2D and BEAM.ALTERNATIVESNEST2D ~= "" then + table.insert( Alternatives, BEAM.ALTERNATIVESNEST2D) + end + table.insert( Alternatives, sBitIndexCombinationWithInvert) + BEAM.ALTERNATIVESNEST2D = table.concat( Alternatives, ', ') + else + if BEAM.ALTERNATIVES and BEAM.ALTERNATIVES ~= "" then + table.insert( Alternatives, BEAM.ALTERNATIVES) + end + table.insert( Alternatives, sBitIndexCombinationWithInvert) + BEAM.ALTERNATIVES = table.concat( Alternatives, ', ') + end end - -- se ultima combinazione, si esce e non si riporta in posizione inizale. Verrà infatti cancellata if z == #TotalCombiToTest then break end From 6fd356f757967a3c2929f4c76ca8e002ba683ea0 Mon Sep 17 00:00:00 2001 From: "andrea.villa" Date: Wed, 1 Apr 2026 11:06:15 +0200 Subject: [PATCH 2/2] - Aggiunta tolleranza nella scelta della migliore combinazione di lavorazione. Se voto uguale non era chiaro quale avrebbe scelto prima - Quando si processano alternative, si resetta flag bPartInCombiIsInverted --- LuaLibs/BeamExec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 79a4f54..06d1895 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -1297,7 +1297,7 @@ local function GetBestCombination( ListToCompare, Part) -- scelgo soluzione senza rotazioni if ListToCompare[ListIndex].nRotations == 0 then -- scelgo soluzione con voto più alto - if ListToCompare[nIndexBestCombination].dTotalRating < ListToCompare[ListIndex].dTotalRating then + if ListToCompare[nIndexBestCombination].dTotalRating + 10 * GEO.EPS_SMALL < ListToCompare[ListIndex].dTotalRating then nIndexBestCombination = ListIndex end end @@ -1328,7 +1328,7 @@ local function GetBestCombination( ListToCompare, Part) nIndexBestCombination = ListIndex elseif ListToCompare[ListIndex].nComplete == ListToCompare[nIndexBestCombination].nComplete then -- scelgo soluzione con voto più alto - if ListToCompare[nIndexBestCombination].dTotalRating < ListToCompare[ListIndex].dTotalRating then + if ListToCompare[nIndexBestCombination].dTotalRating + 10 * GEO.EPS_SMALL < ListToCompare[ListIndex].dTotalRating then nIndexBestCombination = ListIndex end end @@ -1343,10 +1343,10 @@ local function GetBestCombination( ListToCompare, Part) local dOtherTotalRating = ListToCompare[ListIndex].dTotalRating -- scelgo soluzione con voto più alto - if dBestTotalRating < dOtherTotalRating then + if dBestTotalRating + 10 * GEO.EPS_SMALL < dOtherTotalRating then nIndexBestCombination = ListIndex -- se stesso voto - elseif dBestTotalRating == dOtherTotalRating then + elseif abs( dBestTotalRating - dOtherTotalRating) < 10 * GEO.EPS_SMALL then -- scelgo soluzione con meno rotazioni if ListToCompare[nIndexBestCombination].nRotations > ListToCompare[ListIndex].nRotations then nIndexBestCombination = ListIndex @@ -2040,6 +2040,7 @@ function BeamExec.ProcessAlternatives( PARTS) BestCombination = GetBestCombination( CombinationListFromMatrix, PARTS[nPart]) -- se la soluzione alternativa migliore è completa, allora la verifico, altrimenti si tiene la migliore in assoluto if BestCombination.nNotComplete == 0 and BestCombination.nNotExecute == 0 then + PARTS[nPart].bPartInCombiIsInverted = BestCombination.bPartInCombiIsInverted -- compilazione della vProc finale contenente le feature da lavorare nella giusta rotazione local vProc, MatrixResult = GetProcessingListFromCombination( BestCombination)