diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index ba27f28..a1247f0 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -18,6 +18,7 @@ local BCS = require( 'BasicCustomerStrategies') local FeatureLib = require( 'FeatureLib') local FaceData = require( 'FaceData') local MachiningLib = require( 'MachiningLib') +local Logs = require( 'Logs') EgtOutLog( ' BeamExec started', 1) @@ -381,7 +382,7 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS) local dPartLen = PARTS[i].b3Box:getDimX() local dPartWidth = PARTS[i].b3Box:getDimY() local dPartHeight = PARTS[i].b3Box:getDimZ() - local dNextLen = dLen - dDeltaS - dPartLen - dDeltaE + local dNextLen = dLen - EgtIf( i == 1, dDeltaS, 0) - dPartLen - dDeltaE if (( abs( dPartWidth - dRawW) < 100 * GEO.EPS_SMALL and abs( dPartHeight - dRawH) < 100 * GEO.EPS_SMALL) or ( abs( dPartHeight - dRawW) < 100 * GEO.EPS_SMALL and abs( dPartWidth - dRawH) < 100 * GEO.EPS_SMALL)) and dNextLen + dDeltaE >= 0 then @@ -836,6 +837,7 @@ local function GetBestStrategy( vProcSingleRot) end if nIndexBestStrategy ~= 0 then Proc.ChosenStrategy = Proc.AvailableStrategies[nIndexBestStrategy] + Proc.nIndexBestStrategy = nIndexBestStrategy end end end @@ -1156,99 +1158,10 @@ local function GetProcBestMachRotationFromList( ListToCompare) Data.dCompositeRating = ListToCompare[nIndexChosenProcInRot][1].ChosenStrategy.Result.dCompositeRating Data.bComplete = ListToCompare[nIndexChosenProcInRot][1].ChosenStrategy.Result.sStatus == 'Completed' Data.bNotComplete = ListToCompare[nIndexChosenProcInRot][1].ChosenStrategy.Result.sStatus == 'Not-Completed' - Data.bNotExecute = ListToCompare[nIndexChosenProcInRot][1].ChosenStrategy.Result.sStatus == 'Not-Applicable' + Data.bNotApplicable = ListToCompare[nIndexChosenProcInRot][1].ChosenStrategy.Result.sStatus == 'Not-Applicable' return Proc, Data end -------------------------------------------------------------------------------------------------------------- -local function WriteMatrixLog( ProcessingsOnPart, PartInfo) - EgtOutLog( ' === === === === === === === === === === ROTATION MATRIX === === === === === === === === === === === === ===') - EgtOutLog( ' Feature ID | BTL POSITION | 90 ROTATION | 180 ROTATION | 270 ROTATION |') - EgtOutLog( '----------------------------------------------------------------------------------------------------------') - - local nProcessingsNumber - local nFirstAvailableRotation - -- ricerco prima rotazione effettivamente calcolata. In genere è sempre la prima - for i = 1, 4 do - if PartInfo.CombinationList.Rotations[i] == 1 then - nProcessingsNumber = #ProcessingsOnPart.Rotation[i] - nFirstAvailableRotation = i - break - end - end - - for ProcLog = 1, nProcessingsNumber do - local sLogLine = ' ' .. tostring( ProcessingsOnPart.Rotation[nFirstAvailableRotation][ProcLog].id) - while string.len( sLogLine) <= 20 do - sLogLine = sLogLine .. ' ' - end - sLogLine = sLogLine .. '|' - for nRotLog = 1, 4 do - if PartInfo.CombinationList.Rotations[nRotLog] == 1 then - if ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy then - local sLogLineProc = tostring( ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy.Result.dCompositeRating) .. - ' (' .. tostring( ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy.sStrategyId) .. ') |' - while string.len( sLogLineProc) <= 20 do - sLogLineProc = ' ' .. sLogLineProc - end - sLogLine = sLogLine .. sLogLineProc - else - sLogLine = sLogLine .. ' 0 (STR----) |' - end - else - sLogLine = sLogLine .. ' NOT NEEDED |' - end - end - EgtOutLog( sLogLine) - end - EgtOutLog( '----------------------------------------------------------------------------------------------------------') -end -------------------------------------------------------------------------------------------------------------- -local function WriteCombinationLog( CombinationsList, BestCombination) - EgtOutLog( ' === === === === === === === === === === COMBINATIONS === === === === === === ') - EgtOutLog( ' COMBI (UNL) | RATING | COMPLETE | NO COMPL | NO EXEC | ROTATE |') - EgtOutLog( '---------------------------------------------------------------------------') - - for CombiLog = 1, #CombinationsList do - local sLogLine = ' ' .. CombinationsList[CombiLog].sBitIndexCombination .. ' (' .. CombinationsList[CombiLog].nUnloadPos .. ') |' - -- rating - local sOtherField = tostring( CombinationsList[CombiLog].dTotalRating) .. ' |' - while string.len( sOtherField) <= 11 do - sOtherField = ' ' .. sOtherField - end - sLogLine = sLogLine .. sOtherField - -- completed - sOtherField = tostring( CombinationsList[CombiLog].nComplete) .. ' |' - while string.len( sOtherField) <= 11 do - sOtherField = ' ' .. sOtherField - end - sLogLine = sLogLine .. sOtherField - -- not completed - sOtherField = tostring( CombinationsList[CombiLog].nNotComplete) .. ' |' - while string.len( sOtherField) <= 11 do - sOtherField = ' ' .. sOtherField - end - sLogLine = sLogLine .. sOtherField - -- not executed - sOtherField = tostring( CombinationsList[CombiLog].nNotExecute) .. ' |' - while string.len( sOtherField) <= 11 do - sOtherField = ' ' .. sOtherField - end - sLogLine = sLogLine .. sOtherField - -- rotations - sOtherField = tostring( CombinationsList[CombiLog].nRotations) .. ' |' - while string.len( sOtherField) <= 11 do - sOtherField = ' ' .. sOtherField - end - sLogLine = sLogLine .. sOtherField - - EgtOutLog( sLogLine) - end - EgtOutLog( '---------------------------------------------------------------------------') - EgtOutLog( ' BEST ROTATION : ' .. BestCombination.sBitIndexCombination .. ' (' .. BestCombination.nUnloadPos .. ')') - EgtOutLog( '---------------------------') -end - ------------------------------------------------------------------------------------------------------------- -- funzione che calcola le combinazioni di rotazione per lavorare la trave e sceglie la migliore local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart, PartInfo) @@ -1257,7 +1170,7 @@ local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart, PartInfo) -- scrittura nel log della matrice delle rotazioni if EgtGetDebugLevel() >= 3 then - WriteMatrixLog( ProcessingsOnPart, PartInfo) + Logs.WriteMatrixLog( ProcessingsOnPart, PartInfo) end -- per ogni posizione di scarico @@ -1316,7 +1229,7 @@ local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart, PartInfo) SingleCombination.dTotalRating = SingleCombination.dTotalRating + Data.dCompositeRating SingleCombination.nComplete = SingleCombination.nComplete + EgtIf( Data.bComplete, 1, 0) SingleCombination.nNotComplete = SingleCombination.nNotComplete + EgtIf( Data.bNotComplete, 1, 0) - SingleCombination.nNotExecute = SingleCombination.nNotExecute + EgtIf( Data.bNotExecute, 1, 0) + SingleCombination.nNotExecute = SingleCombination.nNotExecute + EgtIf( Data.bNotApplicable, 1, 0) SingleCombination.nIndexRotation = nUnloadPos else SingleCombination.nNotExecute = SingleCombination.nNotExecute + 1 @@ -1338,7 +1251,7 @@ local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart, PartInfo) -- scrittura nel log delle combinazioni possibili if EgtGetDebugLevel() >= 3 then - WriteCombinationLog( CombinationsList, BestCombination) + Logs.WriteCombinationLog( CombinationsList, BestCombination) end local vFinalProc, nInitialPosition, bSomeFeatureDown, bSomeFeatureSide = GetProcessingListFromCombination( BestCombination) @@ -1384,6 +1297,12 @@ function BeamExec.ProcessMachinings( PROCESSINGS, PARTS) for dRotIndex = 1, 4 do PROCESSINGS[nPart].Rotation[dRotIndex] = GetBestStrategy( PROCESSINGS[nPart].Rotation[dRotIndex]) end + + -- scrittura nel log del risultato della scelta della strategia migliore tra quelle disponibili + if EgtGetDebugLevel() >= 3 then + Logs.WriteFeaturesLog( PROCESSINGS[nPart], PARTS[nPart]) + end + -- si calcola la combinazione di lavorazione migliore local vProc, nInitialPosition, bSomeFeatureDown, bSomeFeatureSide = GetBestResultFromCombinationsMatrix( PROCESSINGS[nPart], PARTS[nPart]) -- salvo sul PART la posizione di partenza che è stata scelta diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index 6257a5e..e5a2700 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -7,6 +7,7 @@ local FaceData = {} -- carico librerie local BeamLib = require( 'BeamLib') +local Logs = require( 'Logs') --------------------------------------------------------------------- @@ -487,35 +488,15 @@ function FaceData.GetMainFaces( Proc, Part) MainFaces.BottomFaces = GetBottomFaces( Proc) MainFaces.LongFaces = GetLongFaces( Proc, MainFaces) MainFaces.SideFaces = GetSideFaces( Proc, MainFaces) - -- TODO funzione apposita per informazioni log? + + -- scrivo informazioni delle facce nel log if EgtGetDebugLevel() >= 3 then - if MainFaces.BottomFaces then - for i = 1, #MainFaces.BottomFaces do - EgtOutLog( 'Bottom Face : ' .. MainFaces.BottomFaces[i].id) - end - -- colore differente per la faccia di fondo principale - EgtSurfTmSetFaceColor( Proc.id, MainFaces.BottomFaces[1].id, 1) - end - if MainFaces.LongFaces then - for i = 1, #MainFaces.LongFaces do - EgtOutLog( 'Long Face : ' .. MainFaces.LongFaces[i].id) - end - end - if MainFaces.SideFaces then - for i = 1, #MainFaces.SideFaces do - EgtOutLog( 'Side Face : ' .. MainFaces.SideFaces[i].id) - end - end - if MainFaces.TunnelAddedFaces then - EgtOutLog( 'Middle Face (Trimesh): ' .. MainFaces.TunnelAddedFaces.MiddleFaceTm.id) - end + Logs.WriteMainFacesLog( Proc, MainFaces) end else EgtOutLog( '---MainFaces NOT NEEDED---') end - - EgtOutLog( '---MainFaces END---') return MainFaces end diff --git a/LuaLibs/Logs.lua b/LuaLibs/Logs.lua new file mode 100644 index 0000000..b1a8711 --- /dev/null +++ b/LuaLibs/Logs.lua @@ -0,0 +1,213 @@ +-- Logs.lua by Egalware s.r.l. 2024/11/20 +-- Libreria per logs vari + +-- Tabella per definizione modulo +local Logs = {} + +------------------------------------------------------------------------------------------------------------- +function Logs.WriteFeaturesLog( ProcessingsOnPart, PartInfo) + EgtOutLog( ' === === === === === === === === === === FEATURES STRATEGIES === === === === === === === === === === === ===') + EgtOutLog( ' Feature ID | BTL POSITION | 90 ROTATION | 180 ROTATION | 270 ROTATION |') + EgtOutLog( '----------------------------------------------------------------------------------------------------------') + + local nProcessingsNumber + local nFirstAvailableRotation + -- ricerco prima rotazione effettivamente calcolata. In genere è sempre la prima + for i = 1, 4 do + if PartInfo.CombinationList.Rotations[i] == 1 then + nProcessingsNumber = #ProcessingsOnPart.Rotation[i] + nFirstAvailableRotation = i + break + end + end + + -- per ogni feature + for ProcLog = 1, nProcessingsNumber do + -- ricavo il massimo numero di strategie per feature + local nMaxStrategiesPerFeature = 0 + for nRotLog = 1, 4 do + if PartInfo.CombinationList.Rotations[nRotLog] == 1 and ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies then + nMaxStrategiesPerFeature = max( nMaxStrategiesPerFeature, #ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies) + end + end + + -- ciclo su tutte le strategie + for nCountStrategies = 1, nMaxStrategiesPerFeature do + local sLogLine = '' + -- al primo ciclo scrivo ID feature + if nCountStrategies == 1 then + sLogLine = ' ' .. tostring( ProcessingsOnPart.Rotation[nFirstAvailableRotation][ProcLog].id) + while string.len( sLogLine) <= 20 do + sLogLine = sLogLine .. ' ' + end + sLogLine = sLogLine .. '|' + else + sLogLine = ' |' + end + + for nRotLog = 1, 4 do + -- se rotazione abilitata + if PartInfo.CombinationList.Rotations[nRotLog] == 1 then + -- se ci sono strategie + if ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies and ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies] then + -- se la strategia è stat processata e ha un risultato + if ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].Result then + -- leggo lo stato della strategia per aggiungere un suffisso + local sStatusStrategy = ' ' + if not ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].Result.sStatus or + ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].Result.sStatus == 'Not-Applicable' then + sStatusStrategy = 'N' + elseif ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].Result.sStatus == 'Completed' then + sStatusStrategy = 'C' + elseif ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].Result.sStatus == 'Not-Completed' then + sStatusStrategy = 'P' + end + -- se c'è una chosen strategy, si aggiunge prefisso '*' per indicare nel log qual è la strategia che è stata scelta + local nIndexBestStrategy = ProcessingsOnPart.Rotation[nRotLog][ProcLog].nIndexBestStrategy or 0 + local sLogLineProc = EgtIf( nIndexBestStrategy == nCountStrategies, '*', '') .. + tostring( ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].Result.dCompositeRating) ..' (' .. + tostring( ProcessingsOnPart.Rotation[nRotLog][ProcLog].AvailableStrategies[nCountStrategies].sStrategyId) .. ')' .. + sStatusStrategy .. ' |' + while string.len( sLogLineProc) <= 20 do + sLogLineProc = ' ' .. sLogLineProc + end + sLogLine = sLogLine .. sLogLineProc + else + sLogLine = sLogLine .. ' 0 (STR----)- |' + end + else + sLogLine = sLogLine .. ' |' + end + -- rotazione non presa in considerazione + else + if nCountStrategies == 1 then + sLogLine = sLogLine .. ' ---------- |' + else + sLogLine = sLogLine .. ' |' + end + end + end + EgtOutLog( sLogLine) + end + + end + EgtOutLog( '----------------------------------------------------------------------------------------------------------') +end + +------------------------------------------------------------------------------------------------------------- +function Logs.WriteMatrixLog( ProcessingsOnPart, PartInfo) + EgtOutLog( ' === === === === === === === === === === ROTATION MATRIX === === === === === === === === === === === === ===') + EgtOutLog( ' Feature ID | BTL POSITION | 90 ROTATION | 180 ROTATION | 270 ROTATION |') + EgtOutLog( '----------------------------------------------------------------------------------------------------------') + + local nProcessingsNumber + local nFirstAvailableRotation + -- ricerco prima rotazione effettivamente calcolata. In genere è sempre la prima + for i = 1, 4 do + if PartInfo.CombinationList.Rotations[i] == 1 then + nProcessingsNumber = #ProcessingsOnPart.Rotation[i] + nFirstAvailableRotation = i + break + end + end + + for ProcLog = 1, nProcessingsNumber do + local sLogLine = ' ' .. tostring( ProcessingsOnPart.Rotation[nFirstAvailableRotation][ProcLog].id) + while string.len( sLogLine) <= 20 do + sLogLine = sLogLine .. ' ' + end + sLogLine = sLogLine .. '|' + for nRotLog = 1, 4 do + if PartInfo.CombinationList.Rotations[nRotLog] == 1 then + if ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy then + local sStatusStrategy = EgtIf( ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy.Result.sStatus == 'Completed', 'C', 'P') + local sLogLineProc = tostring( ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy.Result.dCompositeRating) .. + ' (' .. tostring( ProcessingsOnPart.Rotation[nRotLog][ProcLog].ChosenStrategy.sStrategyId) .. ')' .. sStatusStrategy .. ' |' + while string.len( sLogLineProc) <= 20 do + sLogLineProc = ' ' .. sLogLineProc + end + sLogLine = sLogLine .. sLogLineProc + else + sLogLine = sLogLine .. ' 0 (STR----)- |' + end + else + sLogLine = sLogLine .. ' ---------- |' + end + end + EgtOutLog( sLogLine) + end + EgtOutLog( '----------------------------------------------------------------------------------------------------------') +end + +------------------------------------------------------------------------------------------------------------- +function Logs.WriteCombinationLog( CombinationsList, BestCombination) + EgtOutLog( ' === === === === === === === === === === COMBINATIONS === === === === === === ') + EgtOutLog( ' COMBI (UNL) | RATING | COMPLETE | NO COMPL | NO EXEC | ROTATE |') + EgtOutLog( '---------------------------------------------------------------------------') + + for CombiLog = 1, #CombinationsList do + local sLogLine = ' ' .. CombinationsList[CombiLog].sBitIndexCombination .. ' (' .. CombinationsList[CombiLog].nUnloadPos .. ') |' + -- rating + local sOtherField = tostring( CombinationsList[CombiLog].dTotalRating) .. ' |' + while string.len( sOtherField) <= 11 do + sOtherField = ' ' .. sOtherField + end + sLogLine = sLogLine .. sOtherField + -- completed + sOtherField = tostring( CombinationsList[CombiLog].nComplete) .. ' |' + while string.len( sOtherField) <= 11 do + sOtherField = ' ' .. sOtherField + end + sLogLine = sLogLine .. sOtherField + -- not completed + sOtherField = tostring( CombinationsList[CombiLog].nNotComplete) .. ' |' + while string.len( sOtherField) <= 11 do + sOtherField = ' ' .. sOtherField + end + sLogLine = sLogLine .. sOtherField + -- not executed + sOtherField = tostring( CombinationsList[CombiLog].nNotExecute) .. ' |' + while string.len( sOtherField) <= 11 do + sOtherField = ' ' .. sOtherField + end + sLogLine = sLogLine .. sOtherField + -- rotations + sOtherField = tostring( CombinationsList[CombiLog].nRotations) .. ' |' + while string.len( sOtherField) <= 11 do + sOtherField = ' ' .. sOtherField + end + sLogLine = sLogLine .. sOtherField + + EgtOutLog( sLogLine) + end + EgtOutLog( '---------------------------------------------------------------------------') + EgtOutLog( ' BEST ROTATION : ' .. BestCombination.sBitIndexCombination .. ' (' .. BestCombination.nUnloadPos .. ')') + EgtOutLog( '---------------------------') +end + +------------------------------------------------------------------------------------------------------------- +function Logs.WriteMainFacesLog( Proc, MainFaces) + if MainFaces.BottomFaces then + for i = 1, #MainFaces.BottomFaces do + EgtOutLog( 'Bottom Face : ' .. MainFaces.BottomFaces[i].id) + end + -- colore differente per la faccia di fondo principale + EgtSurfTmSetFaceColor( Proc.id, MainFaces.BottomFaces[1].id, 1) + end + if MainFaces.LongFaces then + for i = 1, #MainFaces.LongFaces do + EgtOutLog( 'Long Face : ' .. MainFaces.LongFaces[i].id) + end + end + if MainFaces.SideFaces then + for i = 1, #MainFaces.SideFaces do + EgtOutLog( 'Side Face : ' .. MainFaces.SideFaces[i].id) + end + end + if MainFaces.TunnelAddedFaces then + EgtOutLog( 'Middle Face (Trimesh): ' .. MainFaces.TunnelAddedFaces.MiddleFaceTm.id) + end +end +--------------------------------------------------------------------- + +return Logs diff --git a/Process.lua b/Process.lua index 3b1808e..8a9ad60 100644 --- a/Process.lua +++ b/Process.lua @@ -42,6 +42,7 @@ _G.package.loaded.BasicCustomerStrategies = nil _G.package.loaded.FeatureLib = nil _G.package.loaded.FaceData = nil _G.package.loaded.MachiningLib = nil +_G.package.loaded.Logs = nil -- strategie di base sempre presenti _G.package.loaded['SPLITCUT\\SPLITCUT'] = nil _G.package.loaded['SPLITCUT\\SPLITCUTConfig'] = nil diff --git a/Strategies/Core/FACEBYBLADE.lua b/Strategies/Core/FACEBYBLADE.lua index b2fba40..ec5ebc3 100644 --- a/Strategies/Core/FACEBYBLADE.lua +++ b/Strategies/Core/FACEBYBLADE.lua @@ -14,7 +14,6 @@ local FACEBYBLADE = {} ------------------------------------------------------------------------------------------------------------- local function CalculateLeadInOut( EdgeToMachine) - local LeadIn = {} local LeadOut = {} LeadIn.dStartAddLength = 0 @@ -63,7 +62,7 @@ local function GetSCC( vtMachiningDirection) end ------------------------------------------------------------------------------------------------------------- --- TODO funziona da fare completamente +-- TODO da sistemare function FACEBYBLADE.Make( Proc, Part, FaceToMachine, EdgeToMachine, OptionalParameters) local Cutting = {}