diff --git a/LuaLibs/MachiningLib.lua b/LuaLibs/MachiningLib.lua index ed176f6..8ab21d7 100644 --- a/LuaLibs/MachiningLib.lua +++ b/LuaLibs/MachiningLib.lua @@ -74,40 +74,34 @@ local function SetCurrMachineHeadType() end --------------------------------------------------------------------- --- funzione che conferma e rende attivi testa e utensile ipotizzati +-- setta ultimi testa e utensile utilizzati se compatibili con ottimizzazione testa local function ConfirmNextMachining() - -- se non definita testa successiva, esco - if not nNextMachHead or nNextMachHead < 1 or nNextMachHead > 2 then return end - -- altrimenti, la confermo come attiva - nActiveHead = nNextMachHead - if nNextMachHead == 1 then - H1_TOOL = H1_NEXT_TOOL - elseif nNextMachHead == 2 then - H2_TOOL = H2_NEXT_TOOL + -- utensile corrente + local sToolUuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + local sToolName = EgtTdbGetToolFromUUID( sToolUuid or '') + EgtTdbSetCurrTool( sToolName or '') + -- testa dell'utensile corrente + local sHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) + local nHead = tonumber( sHead:sub( 2, #sHead)) + 0 + + if ( nHead < 10 and nHead >= 30) or vFixedHeads[nHead] then + -- testa che non richiede ottimizzazione + return + elseif nHead >= 20 then + nHead = 2 + elseif nHead >= 10 then + nHead = 1 + end + + -- se la testa richiede ottimizzazione, confermo testa attiva + nActiveHead = nHead + if nActiveHead == 1 then + H1_TOOL = sToolName + elseif nActiveHead == 2 then + H2_TOOL = sToolName end - -- reset prossima testa - nNextMachHead = 0 - H1_NEXT_TOOL = '' - H2_NEXT_TOOL = '' end ---------------------------------------------------------------------- --- funzione che traccia testa e utensile ipotizzati -local function SetNextMachining( sToolName, nHead, bFixed) - if nHead < 1 or nHead > 2 then return end - if bFixed then - nNextMachHead = 0 - H1_NEXT_TOOL = '' - H2_NEXT_TOOL = '' - end - nNextMachHead = nHead - if nHead == 1 then - H1_NEXT_TOOL = sToolName - elseif nHead == 2 then - H2_NEXT_TOOL = sToolName - end -end - --------------------------------------------------------------------- local function SetCurrMachiningAndTool( Machining) EgtMdbSetCurrMachining( Machining.Name) @@ -356,7 +350,7 @@ local function FindMachining( MachiningType, sType, Params, bTopHead, bDownHead, end if ( BEAM and BEAM.BW) or MachineHeadType == ONE_HEAD or MachineHeadType == TWO_EQUAL_HEADS or ( MachineHeadType == TWO_UP_DOWN_HEADS and not bDownHead) then _, sType = EgtEndsWith( sType, '_H2') - elseif not ( BEAM and BEAM.BW) and MachineHeadType == TWO_UP_DOWN_HEADS and bDownHead then + elseif not ( BEAM and BEAM.BW) and MachineHeadType == TWO_UP_DOWN_HEADS and not bTopHead and bDownHead then if not EgtEndsWith( sType, '_H2') then sType = sType .. '_H2' end @@ -383,18 +377,15 @@ local function FindMachining( MachiningType, sType, Params, bTopHead, bDownHead, local bOk, ToolParams = VerifyTool( Machining, MachiningType, Params, bH2) if bOk then if MachineHeadUse == ONE_HEAD then - SetNextMachining( sToolName, 1, bFixed) return ReturnParams(MachiningType, Machining.Name, Machining.Type, ToolParams) elseif MachineHeadUse == TWO_EQUAL_HEADS then -- se nessuna testa attiva, prendo la prima lavorazione disponibile if nActiveHead == 0 then - SetNextMachining( sToolName, EgtIf( bH2, 2, 1), bFixed) return ReturnParams( MachiningType, Machining.Name, Machining.Type, ToolParams) -- verifico se posso usare lo stesso utensile della testa attiva elseif ( nActiveHead == 1 and not bH2 and sToolName == H1_TOOL) or ( nActiveHead == 2 and bH2 and sToolName == H2_TOOL) then -- se l'utensile sulla testa attiva è molto più piccolo rispetto a quelli salvati non lo scelgo if ( not sH1Param or not sH1Param.TDiam or sH1Param.TDiam < dBiggerToolTolerance * ToolParams.TDiam) and ( not sH2Param or not sH2Param.TDiam or sH2Param.TDiam < 1.25 * ToolParams.TDiam) then - SetNextMachining( sToolName, nActiveHead, bFixed) return ReturnParams( MachiningType, Machining.Name, Machining.Type, ToolParams) end end @@ -414,10 +405,8 @@ local function FindMachining( MachiningType, sType, Params, bTopHead, bDownHead, end elseif MachineHeadUse == TWO_UP_DOWN_HEADS then if bTopHead and not bH2 then - SetNextMachining( sToolName, 1, bFixed) return ReturnParams( MachiningType, Machining.Name, Machining.Type, ToolParams) elseif bDownHead and bH2 then - SetNextMachining( sToolName, 2, bFixed) return ReturnParams( MachiningType, Machining.Name, Machining.Type, ToolParams) end end @@ -428,31 +417,25 @@ local function FindMachining( MachiningType, sType, Params, bTopHead, bDownHead, -- se uno dei due utensili è molto più grande dell'altro scelgo quello senza fare altre analisi if sH1Mach ~= "" and sH1Param.TDiam and sH2Mach ~= "" and sH2Param.TDiam then if sH1Param.TDiam > dBiggerToolTolerance * sH2Param.TDiam then - SetNextMachining( sH1Tool, 1, bFixed) return ReturnParams( MachiningType, sH1Mach, sType, sH1Param) elseif sH2Param.TDiam > dBiggerToolTolerance * sH1Param.TDiam then - SetNextMachining( sH2Tool, 2, bFixed) return ReturnParams( MachiningType, sH2Mach, sType, sH2Param) end end -- verifico se cambiare testa o cambiare utensile su quella corrente if nActiveHead == 1 then if sH2Mach ~= "" then - SetNextMachining( sH2Tool, 2, bFixed) return ReturnParams( MachiningType, sH2Mach, sType, sH2Param) --return sH2Mach, sH2Param.Type, sH2Param.TMaxMat, sH2Param.MaxToolLength, sH2Param.ToolDiam, sH2Param.DiamTh, sH2Param.FreeLen elseif sH1Mach ~= "" then - SetNextMachining( sH1Tool, 1, bFixed) return ReturnParams( MachiningType, sH1Mach, sType, sH1Param) --return sH1Mach, sH1Param.Type, sH1Param.TMaxMat, sH1Param.MaxToolLength, sH1Param.ToolDiam, sH1Param.DiamTh, sH1Param.FreeLen end elseif nActiveHead == 2 then if sH1Mach ~= "" then - SetNextMachining( sH1Tool, 1, bFixed) return ReturnParams( MachiningType, sH1Mach, sType, sH1Param) --return sH1Mach, sH1Param.Type, sH1Param.TMaxMat, sH1Param.MaxToolLength, sH1Param.ToolDiam, sH1Param.DiamTh, sH1Param.FreeLen elseif sH2Mach ~= "" then - SetNextMachining( sH2Tool, 2, bFixed) return ReturnParams( MachiningType, sH2Mach, sType, sH2Param) --return sH2Mach, sH2Param.Type, sH2Param.TMaxMat, sH2Param.MaxToolLength, sH2Param.ToolDiam, sH2Param.DiamTh, sH2Param.FreeLen end