-- 2020/11/13 -- Gestione attrezzaggio per Essetre-FAST -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Tavola di passaggio valori local STU = {} STU.TUUID = "" STU.TCPOS = "" STU.HEAD = "" STU.GROUP = "" STU.POS = "" STU.EXIT = 0 STU.INDEX = 0 STU.HEAD1 = "" STU.HEAD2 = "" STU.ISVALID = false STU.ERR = 0 _G.STU = STU local INVALIDPOS = "" local POS = "Pos" -- Geom Set local GS = {} -- Configurazione posizioni local PositionTable={{Pos = "Pos1", TcPos = "T31", Head = "H1", Group = "G1"}, {Pos = "Pos2", TcPos = "T32", Head = "H1", Group = "G1"}, {Pos = "Pos3", TcPos = "T33", Head = "H1", Group = "G1"}, {Pos = "Pos4", TcPos = "T34", Head = "H1", Group = "G1"}, {Pos = "Pos5", TcPos = "T35", Head = "H1", Group = "G1"}, {Pos = "Pos6", TcPos = "T36", Head = "H1", Group = "G1"}, {Pos = "Pos7", TcPos = "T37", Head = "H1", Group = "G1"}, {Pos = "Pos8", TcPos = "T38", Head = "H1", Group = "G1"}, {Pos = "Pos9", TcPos = "T39", Head = "H1", Group = "G1"}, {Pos = "Pos10", TcPos = "T40", Head = "H3", Group = "G1"}, {Pos = "Pos11", TcPos = "T42", Head = "H2", Group = "G2"}} local UsePositionHead = true local function IsInGeomSet( ToolHead, PosHead) for GsIndex = 1, #GS do local bToolHead = false local bPosHead = false for HIndex = 1, #GS[GsIndex] do if GS[GsIndex][HIndex] == ToolHead then bToolHead = true elseif GS[GsIndex][HIndex] == PosHead then bPosHead = true end if bToolHead and bPosHead then return true end end if bToolHead and bPosHead then return true end end return false end function STU.IsCompatibleHeads() STU.ISVALID = false if IsInGeomSet(STU.HEAD1, STU.HEAD2) then STU.ISVALID = true else STU.ISVALID = false end end function STU.GetValidHeadExitForPos() -- se TUUID non valido restituisco errore local ToolName = EgtTdbGetToolFromUUID( STU.TUUID) if ToolName == nill then STU.ERR = 1 return end EgtTdbSetCurrTool( ToolName) local CurrToolHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) STU.EXIT = EgtTdbGetCurrToolParam( MCH_TP.EXIT) -- recupero testa predefinita per la posizione corrente local CurrPosHead for i = 1, #PositionTable do if PositionTable[i].TcPos == STU.TCPOS then CurrPosHead = PositionTable[i].Head break end end -- verifico se la testa è quella della posizione predefinita if CurrPosHead == CurrToolHead then STU.HEAD = CurrToolHead STU.ERR = 0 return -- verifico se la testa è compatibile con quella della posizione predefinita elseif IsInGeomSet( CurrToolHead, CurrPosHead) then if UsePositionHead then STU.HEAD = CurrPosHead STU.ERR = 0 return else STU.HEAD = CurrToolHead STU.ERR = 0 return end -- la testa non è compatibile con quella della posizione predefinita else STU.HEAD = INVALIDPOS STU.ERR = 0 return end end function STU.IsValidTcPosFromHead() STU.ISVALID = false for i = 1, #PositionTable do if PositionTable[i].TcPos == STU.TCPOS then if PositionTable[i].Head == STU.HEAD then STU.ISVALID = true STU.ERR = 0 return elseif IsInGeomSet(PositionTable[i].Head, STU.HEAD) then STU.ISVALID = true STU.ERR = 0 return end STU.ISVALID = false STU.ERR = 0 return end end end function STU.GetTcPosHeadGroupFromPos() for i = 1, #PositionTable do if PositionTable[i].Pos == (POS .. tostring(STU.INDEX)) then STU.TCPOS = PositionTable[i].TcPos STU.HEAD = PositionTable[i].Head STU.GROUP = PositionTable[i].Group STU.ERR = 0 return end end STU.TCPOS = INVALIDPOS STU.HEAD = INVALIDPOS STU.GROUP = INVALIDPOS STU.ERR = 1 end function STU.GetPosFromTcPos() for i = 1, #PositionTable do if PositionTable[i].TcPos == STU.TCPOS then STU.POS = PositionTable[i].Pos STU.ERR = 0 return end end STU.POS = INVALIDPOS STU.ERR = 1 end function STU.GetGroupFromTcPos() for i = 1, #PositionTable do if PositionTable[i].TcPos == STU.TCPOS then STU.GROUP = PositionTable[i].Group STU.ERR = 0 return end end STU.GROUP = INVALIDPOS STU.ERR = 1 end function STU.GetHeadFromPos() for i = 1, #PositionTable do if PositionTable[i].Pos == (POS .. tostring(STU.INDEX)) then STU.HEAD = PositionTable[i].Head STU.ERR = 0 return end end STU.HEAD = INVALIDPOS STU.ERR = 1 end function STU.GetTcPosFromPos() for i = 1, #PositionTable do if PositionTable[i].Pos == (POS .. tostring(STU.INDEX)) then STU.TCPOS = PositionTable[i].TcPos STU.ERR = 0 return end end STU.TCPOS = INVALIDPOS STU.ERR = 1 end