diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 42e56ca..a09a9eb 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -925,11 +925,21 @@ end ------------------------------------------------------------------------------------------------------------- -- funzione che controlla validità delle combinazioni proposte -local function IsCombinationAvailable( sCombination, nUnloadPos) +local function IsCombinationAvailable( sCombination, nUnloadPos, bSquareSection) + -- se non utilizzo BEAMWALL, forzo comportamento BASIC + if not BEAM.BeamWall or not BEAM.Rotation then + BEAM.Rotation = {} + BEAM.Rotation.Basic = true + end + + -- TODO scelta combinazione forzato DA RIMUOVERE!! Serve modifica al BEAM. BEAM.BeamWall = true BEAM.Rotation = {} BEAM.Rotation.bBasic = true + BEAM.Rotation.bNoRotation = false + BEAM.Rotation.bAdvanced = false + -- BASIC : posizione di scarico come posizionamento iniziale if not BEAM.BeamWall or BEAM.Rotation.bBasic then @@ -954,48 +964,27 @@ local function IsCombinationAvailable( sCombination, nUnloadPos) else return false end - -- STANDARD : come BASIC ma ammesse anche le prerotazioni (posizione di scarico può essere diversa da posizione iniziale) - -- TODO : In caso di sezione quadrata, la tipologia STANDARD può diventare FULL COMBI. - elseif BEAM.Rotation.bStandard then - local ExtraRotation = EgtIf( nUnloadPos + 3 > 4, nUnloadPos + 3 - 4, nUnloadPos + 3) + -- ADVANCED : come BASIC ma ammesse anche le prerotazioni (posizione di scarico può essere diversa da posizione iniziale) + elseif BEAM.Rotation.bAdvanced then local Rotation90 = EgtIf( nUnloadPos + 1 > 4, nUnloadPos + 1 - 4, nUnloadPos + 1) local Rotation180 = EgtIf( nUnloadPos + 2 > 4, nUnloadPos + 2 - 4, nUnloadPos + 2) - if nUnloadPos == 2 or nUnloadPos == 4 then - return false - elseif string.sub( sCombination, nUnloadPos, nUnloadPos) == '1' and string.sub( sCombination, ExtraRotation, ExtraRotation) == '0' then - if not BeamData.ROT90 and string.sub( sCombination, Rotation90, Rotation90) == '1' then - return false - elseif not BeamData.ROT180 and string.sub( sCombination, Rotation180, Rotation180) == '1' then - return false - else - return true - end - else - return false - end - -- FULL COMBI : ammesso anche rotazione finale diversa da quella di partenza - elseif BEAM.Rotation.bFullCombi then local ExtraRotation = EgtIf( nUnloadPos + 3 > 4, nUnloadPos + 3 - 4, nUnloadPos + 3) - local Rotation90 = EgtIf( nUnloadPos + 1 > 4, nUnloadPos + 1 - 4, nUnloadPos + 1) - local Rotation180 = EgtIf( nUnloadPos + 2 > 4, nUnloadPos + 2 - 4, nUnloadPos + 2) - if string.sub( sCombination, nUnloadPos, nUnloadPos) ~= '1' or string.sub( sCombination, ExtraRotation, ExtraRotation) == '1' then + + if not bSquareSection and ( nUnloadPos == 2 or nUnloadPos == 4) then return false else - if not BeamData.ROT90 and string.sub( sCombination, Rotation90, Rotation90) == '1' then - return false - elseif not BeamData.ROT180 and string.sub( sCombination, Rotation180, Rotation180) == '1' then + if string.sub( sCombination, nUnloadPos, nUnloadPos) ~= '1' or string.sub( sCombination, ExtraRotation, ExtraRotation) == '1' then return false else - return true + if not BeamData.ROT90 and string.sub( sCombination, Rotation90, Rotation90) == '1' then + return false + elseif not BeamData.ROT180 and string.sub( sCombination, Rotation180, Rotation180) == '1' then + return false + else + return true + end end end - else - -- forzo comportamento BASIC - if not BEAM.Rotation then - BEAM.Rotation = {} - end - BEAM.Rotation.Basic = true - return IsCombinationAvailable( sCombination, nUnloadPos) end end @@ -1024,6 +1013,9 @@ local function GetBestCombination( ListToCompare) -- scelgo soluzione con meno rotazioni if ListToCompare[nIndexBestCombination].nRotations > ListToCompare[ListIndex].nRotations then nIndexBestCombination = ListIndex + -- se anche le rotazioni sono le stesse, prendo la soluzione con più lavorazioni alla fine + elseif #ListToCompare[nIndexBestCombination].Rot0 < #ListToCompare[ListIndex].Rot0 then + nIndexBestCombination = ListIndex end -- se voto diverso else @@ -1184,10 +1176,11 @@ end ------------------------------------------------------------------------------------------------------------- -- funzione che calcola le combinazioni di rotazione per lavorare la trave e sceglie la migliore -local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart) +local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart, PartInfo) -- TODO funzione da sviluppare completamente local BestCombination = {} local CombinationsList = {} + local bSquareSection = abs( PartInfo.dWidth - PartInfo.dHeight) < 100 * GEO.EPS_SMALL -- scrittura nel log della matrice delle rotazioni if EgtGetDebugLevel() >= 3 then @@ -1196,11 +1189,12 @@ local function GetBestResultFromCombinationsMatrix( ProcessingsOnPart) -- per ogni posizione di scarico for nUnloadPos = 1, 4 do - -- verifico tutte le combinazioni che ripettano lo scarico come desiderato + -- verifico tutte le combinazioni che possono essere considerate for i = 1, BeamLib.BinaryToDecimal( 1111) do local nBitIndexCombination = BeamLib.DecimalToBinary( i) local sBitIndexCombination = BeamLib.CalculateStringBinaryFormat( nBitIndexCombination, 4) - if IsCombinationAvailable( sBitIndexCombination, nUnloadPos) then + -- TODO si potrebbero calcolare le combinazioni all'inizio, e ottimizzare facendo la collect solo nelle rotazioni che possono essere considerate + if IsCombinationAvailable( sBitIndexCombination, nUnloadPos, bSquareSection) then local bRot90, bRot180 local SingleCombination = {} SingleCombination.nRotations = 0 @@ -1320,7 +1314,7 @@ function BeamExec.ProcessMachinings( PROCESSINGS, PARTS) PROCESSINGS[nPart].Rotation[dRotIndex] = GetBestStrategy( PROCESSINGS[nPart].Rotation[dRotIndex]) end -- si calcola la combinazione di lavorazione migliore - local vProc, nInitialPosition, bSomeFeatureDown, bSomeFeatureSide = GetBestResultFromCombinationsMatrix( PROCESSINGS[nPart]) + local vProc, nInitialPosition, bSomeFeatureDown, bSomeFeatureSide = GetBestResultFromCombinationsMatrix( PROCESSINGS[nPart], PARTS[nPart]) -- debug if EgtGetDebugLevel() >= 1 then @@ -1338,8 +1332,6 @@ function BeamExec.ProcessMachinings( PROCESSINGS, PARTS) -- ordino le lavorazioni -- MACHININGS = OrderMachining( MACHININGS, PARTS[nPart]) - -- TODO se la posizione di partenza cambia, devo ruotare il pezzo! - -- aggiungo la fase, se non è la prima if nOrd == 1 then EgtSetCurrPhase( 1) @@ -1416,6 +1408,42 @@ function BeamExec.ProcessMachinings( PROCESSINGS, PARTS) end end + -- ruoto il pezzo in caso la soluzione scelta sia con prerotazione + if nInitialPosition == 1 then + ; -- il pezzo è già in posizione + elseif nInitialPosition == 2 then + local dDeltaYZ = EgtGetRawPartBBox( PARTS[nPart].idRaw):getDimY() - EgtGetRawPartBBox( PARTS[nPart].idRaw):getDimZ() + local vtMove = Vector3d( 0, dDeltaYZ / 2 * EgtIf( BeamData.RIGHT_LOAD, -1, 1), dDeltaYZ / 2) + local bPreMove = dDeltaYZ < 0 + -- ruoto le travi della fase corrente + local nRId = PARTS[nPart].idRaw + while nRId do + if bPreMove then EgtMoveRawPart( nRId, vtMove) end + EgtRotateRawPart( nRId, X_AX(), EgtIf( BeamData.RIGHT_LOAD, -90, 90)) + if not bPreMove then EgtMoveRawPart( nRId, vtMove) end + nRId = EgtGetNextRawPart( nRId) + end + elseif nInitialPosition == 3 then + -- ribalto le travi della fase corrente + local nRId = PARTS[nPart].idRaw + while nRId do + EgtRotateRawPart( nRId, X_AX(), 180) + nRId = EgtGetNextRawPart( nRId) + end + elseif nInitialPosition == 4 then + local dDeltaYZ = EgtGetRawPartBBox( PARTS[nPart].idRaw):getDimY() - EgtGetRawPartBBox( PARTS[nPart].idRaw):getDimZ() + local vtMove = Vector3d( 0, dDeltaYZ / 2 * EgtIf( BeamData.RIGHT_LOAD, -1, 1), dDeltaYZ / 2) + local bPreMove = dDeltaYZ < 0 + -- ruoto le travi della fase corrente + local nRId = PARTS[nPart].idRaw + while nRId do + if bPreMove then EgtMoveRawPart( nRId, vtMove) end + EgtRotateRawPart( nRId, X_AX(), EgtIf( BeamData.RIGHT_LOAD, 90, -90)) + if not bPreMove then EgtMoveRawPart( nRId, vtMove) end + nRId = EgtGetNextRawPart( nRId) + end + end + -- aggiunta lavorazioni in ultima fase MachiningLib.AddOperations( MACHININGS, PARTS[nPart], 'STD')