From aeeaac33265eec13a130b785511de73688c4b150 Mon Sep 17 00:00:00 2001 From: "andrea.villa" Date: Thu, 3 Oct 2024 11:54:17 +0200 Subject: [PATCH] - Nuova gestione AddOperation - Prima versione ordinamento lavorazioni - In WinLib funzioni base per ordinamento --- CAMAuto/LuaLibs/MachiningLib.lua | 325 ++++++++++++++++--------------- CAMAuto/LuaLibs/WinExec.lua | 133 +++++++++---- CAMAuto/LuaLibs/WinLib.lua | 25 +++ CAMAuto/ProcessWin.lua | 7 +- CAMAuto/Strategies/Drilling.lua | 27 ++- CAMAuto/Strategies/Profiling.lua | 16 +- 6 files changed, 320 insertions(+), 213 deletions(-) diff --git a/CAMAuto/LuaLibs/MachiningLib.lua b/CAMAuto/LuaLibs/MachiningLib.lua index 225c56a..86f555c 100644 --- a/CAMAuto/LuaLibs/MachiningLib.lua +++ b/CAMAuto/LuaLibs/MachiningLib.lua @@ -200,12 +200,12 @@ function MachiningLib.GetDrillAdditionalSafeDistanceToRaw( Proc, Part, Machining local dStartSafetyLength = EgtCAvToolPosBox( Proc.ptCentre, Proc.vtDir, Part.b3RawPart, Proc.vtDir) -- si riporta valore calcolato sulla punta utensile dStartSafetyLength = dStartSafetyLength - TOOLS[Machining.nToolIndex].dLength - return dStartSafetyLength + return dStartSafetyLength + 5 -- si aggiungono 5mm di sicurezza extra end ------------------------------------------------------------------------------------------------------------- -- salva in lista globale la lavorazione appena calcolata -function MachiningLib.AddNewMachining( ProcToAdd, MachiningToAdd, AuxInfoToAdd) +function MachiningLib.AddNewMachining( ProcToAdd, MachiningToAdd, AuxiliaryDataToAdd) -- Controllo parametri obbligatori if not MachiningToAdd.nType or not MachiningToAdd.nToolIndex or not MachiningToAdd.Geometry or not ProcToAdd.id then return false @@ -239,7 +239,7 @@ function MachiningLib.AddNewMachining( ProcToAdd, MachiningToAdd, AuxInfoToAdd) local Machining = {} Machining.Proc = ProcToAdd Machining.Machining = MachiningToAdd - Machining.AuxInfo = AuxInfoToAdd + Machining.AuxiliaryData = AuxiliaryDataToAdd table.insert( MACHININGS, Machining) return true end @@ -251,171 +251,182 @@ function MachiningLib.AddOperation( OperationToInsert) local sErr = '' local bAreAllMachiningApplyOk = true - -- creazione lavorazione - local nOperationId = EgtCreateMachining( OperationToInsert.Machining.sOperationName, OperationToInsert.Machining.nType, OperationToInsert.Machining.sToolName) + -- parametri generali lavorazione + local MachiningParameters = { + { sName = 'sDepth', nMchParam = MCH_MP.DEPTH_STR}, + { sName = 'bInvert', nMchParam = MCH_MP.INVERT}, + { sName = 'nWorkside', nMchParam = MCH_MP.WORKSIDE}, + { sName = 'nFaceuse', nMchParam = MCH_MP.FACEUSE}, + { sName = 'nSCC', nMchParam = MCH_MP.SCC}, + { sName = 'bToolInvert', nMchParam = MCH_MP.TOOLINVERT}, + { sName = 'sBlockedAxis', nMchParam = MCH_MP.BLOCKEDAXIS}, + { sName = 'sInitialAngles', nMchParam = MCH_MP.INITANGS}, + { sName = 'nHeadSide', nMchParam = MCH_MP.HEADSIDE}, + { sName = 'nSubType', nMchParam = MCH_MP.SUBTYPE}, + { sName = 'dOverlap', nMchParam = MCH_MP.OVERL}, + { sName = 'nStepType', nMchParam = MCH_MP.STEPTYPE}, + { sName = 'dStartSafetyLength', nMchParam = MCH_MP.STARTPOS}, + { sName = 'dReturnPos', nMchParam = MCH_MP.RETURNPOS}, + { sName = 'dRadialOffset', nMchParam = MCH_MP.OFFSR}, + { sName = 'dLongitudinalOffset', nMchParam = MCH_MP.OFFSL}, + { sName = 'dStartSlowLen', nMchParam = MCH_MP.STARTSLOWLEN}, + { sName = 'dEndSlowLen', nMchParam = MCH_MP.ENDSLOWLEN}, + { sName = 'dThrouAddLen', nMchParam = MCH_MP.THROUADDLEN}, + { sName = 'sSystemNotes', nMchParam = MCH_MP.SYSNOTES}, + { sName = 'sUserNotes', nMchParam = MCH_MP.USERNOTES} + } - if nOperationId then - -- impostazione geometria - local bOk = true - bOk = EgtSetMachiningGeometry( OperationToInsert.Machining.Geometry) + -- parametri relativi allo step + MachiningParameters.Steps = { + { sName = 'nStepType', nMchParam = MCH_MP.STEPTYPE}, + { sName = 'dStep', nMchParam = MCH_MP.STEP}, + { sName = 'dSideStep', nMchParam = MCH_MP.SIDESTEP} + } - -- impostazione parametri lavorazione - if OperationToInsert.Machining.sDepth then - EgtSetMachiningParam( MCH_MP.DEPTH_STR, OperationToInsert.Machining.sDepth) - end - if OperationToInsert.Machining.bInvert then - EgtSetMachiningParam( MCH_MP.INVERT, OperationToInsert.Machining.bInvert) - end - if OperationToInsert.Machining.nWorkSide then - EgtSetMachiningParam( MCH_MP.WORKSIDE, OperationToInsert.Machining.nWorkSide) - end - if OperationToInsert.Machining.nFaceuse then - EgtSetMachiningParam( MCH_MP.FACEUSE, OperationToInsert.Machining.nFaceuse) - end - if OperationToInsert.Machining.nSCC then - EgtSetMachiningParam( MCH_MP.SCC, OperationToInsert.Machining.nSCC) - end - if OperationToInsert.Machining.bToolInvert then - EgtSetMachiningParam( MCH_MP.TOOLINVERT, OperationToInsert.Machining.bToolInvert) - end - if OperationToInsert.Machining.sBlockedAxis then - EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, OperationToInsert.Machining.sBlockedAxis) - end - if OperationToInsert.Machining.sInitialAngles then - EgtSetMachiningParam( MCH_MP.INITANGS, OperationToInsert.Machining.sInitialAngles) - end - if OperationToInsert.Machining.nHeadSide then - EgtSetMachiningParam( MCH_MP.HEADSIDE, OperationToInsert.Machining.nHeadSide) - end - if OperationToInsert.Machining.nSubType then - EgtSetMachiningParam( MCH_MP.SUBTYPE, OperationToInsert.Machining.nSubType) - end - if OperationToInsert.Machining.dOverlap then - EgtSetMachiningParam( MCH_MP.OVERL, OperationToInsert.Machining.dOverlap) - end - if OperationToInsert.Machining.dStartSafetyLength then - EgtSetMachiningParam( MCH_MP.STARTPOS, OperationToInsert.Machining.dStartSafetyLength) - end + -- parametri relativi all'approccio + MachiningParameters.LeadIn = { + { sName = 'nType', nMchParam = MCH_MP.LEADINTYPE}, + { sName = 'dStartAddLength', nMchParam = MCH_MP.STARTADDLEN}, + { sName = 'dTangentDistance', nMchParam = MCH_MP.LITANG}, + { sName = 'dPerpDistance', nMchParam = MCH_MP.LIPERP}, + { sName = 'dElevation', nMchParam = MCH_MP.LIELEV}, + { sName = 'dCompLength', nMchParam = MCH_MP.LICOMPLEN} + } - -- step - if OperationToInsert.Machining.Steps then - if OperationToInsert.Machining.Steps.dStepType then - EgtSetMachiningParam( MCH_MP.STEPTYPE, OperationToInsert.Machining.Steps.dStepType) - end - if OperationToInsert.Machining.Steps.dStep then - EgtSetMachiningParam( MCH_MP.STEP, OperationToInsert.Machining.Steps.dStep) - end - if OperationToInsert.Machining.Steps.dSideStep then - EgtSetMachiningParam( MCH_MP.SIDESTEP, OperationToInsert.Machining.Steps.dSideStep) - end - end + -- parametri relativi alla retrazione + MachiningParameters.LeadOut = { + { sName = 'nType', nMchParam = MCH_MP.LEADOUTTYPE}, + { sName = 'dEndAddLength', nMchParam = MCH_MP.ENDADDLEN}, + { sName = 'dTangentDistance', nMchParam = MCH_MP.LOTANG}, + { sName = 'dPerpDistance', nMchParam = MCH_MP.LOPERP}, + { sName = 'dElevation', nMchParam = MCH_MP.LOELEV}, + { sName = 'dCompLength', nMchParam = MCH_MP.LOCOMPLEN} + } - if OperationToInsert.Machining.dStartPos then - EgtSetMachiningParam( MCH_MP.STARTPOS, OperationToInsert.Machining.dStartPos) - end - if OperationToInsert.Machining.dReturnPos then - EgtSetMachiningParam( MCH_MP.RETURNPOS, OperationToInsert.Machining.dReturnPos) - end + -- parametri da scrivere nelle note utente + local UserNotes = { + { sName = 'dMaxElev', sMchParam = 'MaxElev'} + } - if OperationToInsert.Machining.dRadialOffset then - EgtSetMachiningParam( MCH_MP.OFFSR, OperationToInsert.Machining.dRadialOffset) - end - if OperationToInsert.Machining.dLongitudinalOffset then - EgtSetMachiningParam( MCH_MP.OFFSL, OperationToInsert.Machining.dLongitudinalOffset) - end + -- parametri da scrivere nelle note di sistema + local SystemNotes = { + } - -- paraemtri attacco - if OperationToInsert.Machining.LeadIn then - if OperationToInsert.Machining.LeadIn.nType then - EgtSetMachiningParam( MCH_MP.LEADINTYPE, OperationToInsert.Machining.LeadIn.nType) - end - if OperationToInsert.Machining.LeadIn.dStartAddLength then - EgtSetMachiningParam( MCH_MP.STARTADDLEN, OperationToInsert.Machining.LeadIn.dStartAddLength) - end - if OperationToInsert.Machining.LeadIn.dTangentDistance then - EgtSetMachiningParam( MCH_MP.LITANG, OperationToInsert.Machining.LeadIn.dTangentDistance) - end - if OperationToInsert.Machining.LeadIn.dPerpDistance then - EgtSetMachiningParam( MCH_MP.LIPERP, OperationToInsert.Machining.LeadIn.dPerpDistance) - end - if OperationToInsert.Machining.LeadIn.dElevation then - EgtSetMachiningParam( MCH_MP.LIELEV, OperationToInsert.Machining.LeadIn.dElevation) - end - if OperationToInsert.Machining.LeadIn.dCompLength then - EgtSetMachiningParam( MCH_MP.LICOMPLEN, OperationToInsert.Machining.LeadIn.dCompLength) - end - end - -- parametri uscita - if OperationToInsert.Machining.LeadOut then - if OperationToInsert.Machining.LeadOut.nType then - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, OperationToInsert.Machining.LeadOut.nType) - end - if OperationToInsert.Machining.LeadOut.dEndAddLength then - EgtSetMachiningParam( MCH_MP.ENDADDLEN, OperationToInsert.Machining.LeadOut.dEndAddLength) - end - if OperationToInsert.Machining.LeadOut.dTangentDistance then - EgtSetMachiningParam( MCH_MP.LOTANG, OperationToInsert.Machining.LeadOut.dTangentDistance) - end - if OperationToInsert.Machining.LeadOut.dPerpDistance then - EgtSetMachiningParam( MCH_MP.LOPERP, OperationToInsert.Machining.LeadOut.dPerpDistance) - end - if OperationToInsert.Machining.LeadOut.dElevation then - EgtSetMachiningParam( MCH_MP.LOELEV, OperationToInsert.Machining.LeadOut.dElevation) - end - if OperationToInsert.Machining.LeadOut.dCompLength then - EgtSetMachiningParam( MCH_MP.LOCOMPLEN, OperationToInsert.Machining.LeadOut.dCompLength) - end - end + local nClonesToAdd = 1 + if OperationToInsert.AuxiliaryData.Clones then + nClonesToAdd = #OperationToInsert.AuxiliaryData.Clones + end + for j = 1, nClonesToAdd do + -- creazione lavorazione + local nOperationId = EgtCreateMachining( OperationToInsert.Machining.sOperationName, OperationToInsert.Machining.nType, OperationToInsert.Machining.sToolName) - if OperationToInsert.Machining.dStartSlowLen then - EgtSetMachiningParam( MCH_MP.STARTSLOWLEN, OperationToInsert.Machining.dStartSlowLen) - end - if OperationToInsert.Machining.dEndSlowLen then - EgtSetMachiningParam( MCH_MP.ENDSLOWLEN, OperationToInsert.Machining.dEndSlowLen) - end - if OperationToInsert.Machining.dThrouAddLen then - EgtSetMachiningParam( MCH_MP.THROUADDLEN, OperationToInsert.Machining.dThrouAddLen) - end + if nOperationId then + -- impostazione geometria + EgtSetMachiningGeometry( OperationToInsert.Machining.Geometry) - -- parametri da settare nelle note di sistema - -- TODO da decidere quali sono le note da salvare qui. Probabilmente tutte quelle relative all'ordine delle lavorazioni - local sSystemNotes = EgtGetMachiningParam( MCH_MP.SYSNOTES) - --if OperationToInsert.Machining.nMachiningOrder then - -- sSystemNotes = EgtSetValInNotes( sSystemNotes, 'MachiningOrder', OperationToInsert.Machining.nMachiningOrder) - --end - EgtSetMachiningParam( MCH_MP.SYSNOTES, sSystemNotes) - - -- parametri da settare nelle note utente - local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) - if OperationToInsert.Machining.dMaxElev then - sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', OperationToInsert.Machining.dMaxElev) - end - EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) - - local b3MachEncumbrance = nil - local bIsApplyOk = MachiningLib.ApplyMachining( true, false) - if not bIsApplyOk then - bAreAllMachiningApplyOk = false - nErr, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nOperationId, false) - else - local nClId = EgtGetFirstNameInGroup( nOperationId, 'CL') - local ptMin = EgtGetInfo( nClId, 'MMIN', 'p') - local ptMax = EgtGetInfo( nClId, 'MMAX', 'p') - -- box percorso lavorazione - if ptMin and ptMax then - local dToolRadius = TOOLS[OperationToInsert.Machining.nToolIndex].dTotDiameter / 2 - if dToolRadius then - ptMin = ptMin - Vector3d( dToolRadius, 0, 0) - ptMax = ptMax + Vector3d( dToolRadius, 0, 0) + -- impostazione parametri lavorazione + -- TODO scrivere sempre Steps, LeadIn, LeadOut nelle tabelle in modo da non dover controllare ogni volta che ci siano + for k = 1, #MachiningParameters do + local sValue + if OperationToInsert.AuxiliaryData.Clones and OperationToInsert.AuxiliaryData.Clones[j][MachiningParameters[k].sName] then + sValue = OperationToInsert.AuxiliaryData.Clones[j][MachiningParameters[k].sName] + elseif OperationToInsert.Machining[MachiningParameters[k].sName] then + sValue = OperationToInsert.Machining[MachiningParameters[k].sName] + end + if sValue then + EgtSetMachiningParam( MachiningParameters[k].nMchParam, sValue) + end + end + for k = 1, #MachiningParameters.Steps do + local sValue + if OperationToInsert.AuxiliaryData.Clones and OperationToInsert.AuxiliaryData.Clones[j].Steps and OperationToInsert.AuxiliaryData.Clones[j].Steps[MachiningParameters.Steps[k].sName] then + sValue = OperationToInsert.AuxiliaryData.Clones[j].Steps[MachiningParameters.Steps[k].sName] + elseif OperationToInsert.Machining.Steps and OperationToInsert.Machining.Steps[MachiningParameters.Steps[k].sName] then + sValue = OperationToInsert.Machining.Steps[MachiningParameters.Steps[k].sName] + end + if sValue then + EgtSetMachiningParam( MachiningParameters.Steps[k].nMchParam, sValue) + end + end + for k = 1, #MachiningParameters.LeadIn do + local sValue + if OperationToInsert.AuxiliaryData.Clones and OperationToInsert.AuxiliaryData.Clones[j].LeadIn and OperationToInsert.AuxiliaryData.Clones[j].LeadIn[MachiningParameters.LeadIn[k].sName] then + sValue = OperationToInsert.AuxiliaryData.Clones[j].LeadIn[MachiningParameters.LeadIn[k].sName] + elseif OperationToInsert.Machining.LeadIn and OperationToInsert.Machining.LeadIn[MachiningParameters.LeadIn[k].sName] then + sValue = OperationToInsert.Machining.LeadIn[MachiningParameters.LeadIn[k].sName] + end + if sValue then + EgtSetMachiningParam( MachiningParameters.LeadIn[k].nMchParam, sValue) + end + end + for k = 1, #MachiningParameters.LeadOut do + local sValue + if OperationToInsert.AuxiliaryData.Clones and OperationToInsert.AuxiliaryData.Clones[j].LeadOut and OperationToInsert.AuxiliaryData.Clones[j].LeadOut[MachiningParameters.LeadOut[k].sName] then + sValue = OperationToInsert.AuxiliaryData.Clones[j].LeadOut[MachiningParameters.LeadOut[k].sName] + elseif OperationToInsert.Machining.LeadOut and OperationToInsert.Machining.LeadOut[MachiningParameters.LeadOut[k].sName] then + sValue = OperationToInsert.Machining.LeadOut[MachiningParameters.LeadOut[k].sName] + end + if sValue then + EgtSetMachiningParam( MachiningParameters.LeadOut[k].nMchParam, sValue) + end + end + for k = 1, #UserNotes do + local sValue + if OperationToInsert.AuxiliaryData.Clones and OperationToInsert.AuxiliaryData.Clones[j][UserNotes[k].sName] then + sValue = OperationToInsert.AuxiliaryData.Clones[j][UserNotes[k].sName] + elseif OperationToInsert.Machining[UserNotes[k].sName] then + sValue = OperationToInsert.Machining[UserNotes[k].sName] + end + if sValue then + local sUserNotes = '' + sUserNotes = EgtSetValInNotes( sUserNotes, UserNotes[k].sMchParam, sValue) + EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) + end + end + -- parametri da settare nelle note di sistema + -- TODO da decidere quali sono le note da salvare qui. Probabilmente tutte quelle relative all'ordine delle lavorazioni + --if OperationToInsert.Machining.nMachiningOrder then + -- sSystemNotes = EgtSetValInNotes( sSystemNotes, 'MachiningOrder', OperationToInsert.Machining.nMachiningOrder) + --end + for k = 1, #SystemNotes do + local sValue + if OperationToInsert.AuxiliaryData.Clones and OperationToInsert.AuxiliaryData.Clones[j][SystemNotes[k].sName] then + sValue = OperationToInsert.AuxiliaryData.Clones[j][SystemNotes[k].sName] + elseif OperationToInsert.Machining[SystemNotes[k].sName] then + sValue = OperationToInsert.Machining[SystemNotes[k].sName] + end + if sValue then + local sSystemNotes = '' + sSystemNotes = EgtSetValInNotes( sSystemNotes, SystemNotes[k].sMchParam, sValue) + EgtSetMachiningParam( MCH_MP.SYSNOTES, sSystemNotes) end end - b3MachEncumbrance = BBox3d( ptMin, ptMax) - end - return bIsApplyOk, sErr, b3MachEncumbrance - else - return false, 'UNEXPECTED ERROR: Error on creating machining' + local b3MachEncumbrance = nil + local bIsApplyOk = MachiningLib.ApplyMachining( true, false) + if not bIsApplyOk then + bAreAllMachiningApplyOk = false + nErr, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nOperationId, false) + else + local nClId = EgtGetFirstNameInGroup( nOperationId, 'CL') + local ptMin = EgtGetInfo( nClId, 'MMIN', 'p') + local ptMax = EgtGetInfo( nClId, 'MMAX', 'p') + -- box percorso lavorazione + if ptMin and ptMax then + local dToolRadius = TOOLS[OperationToInsert.Machining.nToolIndex].dTotDiameter / 2 + if dToolRadius then + ptMin = ptMin - Vector3d( dToolRadius, 0, 0) + ptMax = ptMax + Vector3d( dToolRadius, 0, 0) + end + end + b3MachEncumbrance = BBox3d( ptMin, ptMax) + end + + return bIsApplyOk, sErr, b3MachEncumbrance + else + return false, 'UNEXPECTED ERROR: Error on creating machining' + end end end diff --git a/CAMAuto/LuaLibs/WinExec.lua b/CAMAuto/LuaLibs/WinExec.lua index 8247e0c..2dcea97 100644 --- a/CAMAuto/LuaLibs/WinExec.lua +++ b/CAMAuto/LuaLibs/WinExec.lua @@ -271,65 +271,117 @@ local function GetFeatureInfoAndDependency( vProc, Part) local ProcB = vProc[j] -- TODO dipendenze da controllare : -- * gruppo di forature con aggregato 2/3 uscite - -- * Se 'Left' e 'Out' hanno stesso profilo, vanno concatenati (anche 'Right' se consentito dalle dimensioni) + -- * Se 'Left' e 'Out' hanno stesso profilo, vanno concatenati (anche 'Right' se consentito dalla macchina) end end end return vProc end +------------------------------------------------------------------------------------------------------------- +-- ottimizza le lavorazioni, considerando di ridurre i cambi utensile +local function SortByChangeToolOpt( MACHININGS) + local vProcToSortToolOpt = {} + vProcToSortToolOpt = MACHININGS + + for i = 1, #vProcToSortToolOpt do + for j = i + 1, #vProcToSortToolOpt do + -- se sono su stessa fase + if vProcToSortToolOpt[i].AuxiliaryData.nPhase == vProcToSortToolOpt[j].AuxiliaryData.nPhase then + -- se stesso utensile + if vProcToSortToolOpt[i].Machining.nToolIndex == vProcToSortToolOpt[j].Machining.nToolIndex then + if i + 1 == j then + -- il confronto riparte dall'ultimo spostato + i = j + else + -- sposto lavorazione confrontata dopo la principale + WinLib.ChangeElementPositionInTable( vProcToSortToolOpt, j, i+1) + -- il confronto riparte dall'ultimo spostato + i = j + end + end + end + end + end + + return vProcToSortToolOpt +end + ------------------------------------------------------------------------------------------------------------- -- Ordina le feature in base a fase di lavorazione -- L'ordine è indicativamente: -- 1) Tagli di testa -- 2) Fori -- 3) Scassi serratura/maniglia --- 4) Profili testa +-- 4) Profili testa / Minizinken -- 5) Profili longitudinali --- 6) Incontri/scontri +-- 6) Incontri/scontri (encounter/clash) -- 7) Listello ferma-vetro -- TODO Ordinamento da fare local function OrderMachining( MACHININGS) + local vProcToSort = MACHININGS + -- funzione di confronto. TRUE = B1 prima di B2. FALSE = B2 prima di B1 + local function CompareFeatures( B1, B2) + -- se secondo disabilitato, va lasciato dopo + if B1.Proc.nFlg ~= 0 and B2.Proc.nFlg == 0 then + return true + elseif B1.AuxiliaryData.nPhase < B2.AuxiliaryData.nPhase then + return true + elseif B1.AuxiliaryData.nPhase > B2.AuxiliaryData.nPhase then + return false + elseif B1.Machining.Geometry == B2.Machining.Geometry then + return B1.AuxiliaryData.nIndexMachining < B2.AuxiliaryData.nIndexMachining + elseif B1.AuxiliaryData.bIsProfiling and B2.AuxiliaryData.bIsDrilling and B2.AuxiliaryData.bExecAfterProfile then + return true + elseif B1.AuxiliaryData.bIsDrilling and B1.AuxiliaryData.bExecAfterProfile and B2.AuxiliaryData.bIsProfiling then + return false + elseif B1.AuxiliaryData.bIsDrilling and B2.AuxiliaryData.bIsProfiling then + return true + elseif B2.AuxiliaryData.bIsDrilling and B1.AuxiliaryData.bIsProfiling then + return false + elseif B1.AuxiliaryData.bIsProfiling and B2.AuxiliaryData.bIsProfiling then + if B1.Proc.b3Box:getCenter():getX() - B2.Proc.b3Box:getCenter():getX() < 10 * GEO.EPS_SMALL then + return EgtIf( B1.AuxiliaryData.nPhase == 1, true, false) -- se arrivati a questo controllo, la fase di lavorazione di entrambe è la stessa, quindi mi basta controllarne una + else + return EgtIf( B1.AuxiliaryData.nPhase == 1, false, true) -- se arrivati a questo controllo, la fase di lavorazione di entrambe è la stessa, quindi mi basta controllarne una + end + elseif B1.AuxiliaryData.bIsDrilling and B2.AuxiliaryData.bIsDrilling then + if B1.Proc.b3Box:getMin():getX() < B2.Proc.b3Box:getMin():getX() then + return true + else + return false + end + else + return false + end + end - -- local vProcToSort = vProc - -- -- funzione di confronto. TRUE = B1 prima di B2. FALSE = B2 prima di B1 - -- local function CompareFeatures( B1, B2) - -- -- se secondo disabilitato, va lasciato dopo - -- if B1.nFlg ~= 0 and B2.nFlg == 0 then - -- return true - -- elseif B1.nPhase and B2.nPhase and B1.nPhase < B2.nPhase then - -- return true - -- elseif B1.nPhase and B2.nPhase and B2.nPhase < B1.nPhase then - -- return true - -- -- altrimenti si inverte - -- else - -- return false - -- end - -- end + -- test della funzione di ordinamento + if EgtGetDebugLevel() >= 3 then + EgtOutLog( ' CompareFeatures Test ') + local bCompTest = true + for i = 1, #vProcToSort do + for j = i + 1, #vProcToSort do + local bComp1 = CompareFeatures( vProcToSort[i], vProcToSort[j]) + local bComp2 = CompareFeatures( vProcToSort[j], vProcToSort[i]) + if bComp1 == bComp2 then + bCompTest = false + EgtOutLog( string.format( ' ProcId : %d vs %d --> ERROR', vProcToSort[i].Proc.id, vProcToSort[j].Proc.id)) + end + end + end + if bCompTest then + EgtOutLog( ' ALL OK') + end + end - -- -- test della funzione di ordinamento - -- if EgtGetDebugLevel() >= 3 then - -- EgtOutLog( ' CompareFeatures Test ') - -- local bCompTest = true - -- for i = 1, #vProcToSort do - -- for j = i + 1, #vProcToSort do - -- local bComp1 = CompareFeatures( vProcToSort[i], vProcToSort[j]) - -- local bComp2 = CompareFeatures( vProcToSort[j], vProcToSort[i]) - -- if bComp1 == bComp2 then - -- bCompTest = false - -- EgtOutLog( string.format( ' ProcId : %d vs %d --> ERROR', vProcToSort[i].id, vProcToSort[j].id)) - -- end - -- end - -- end - -- if bCompTest then - -- EgtOutLog( ' ALL OK') - -- end - -- end + -- eseguo un primo ordinamento + table.sort( vProcToSort, CompareFeatures) - -- -- eseguo ordinamento - -- table.sort( vProcToSort, CompareFeatures) + -- ordino per ottimizzare cambio utensile + MACHININGS = SortByChangeToolOpt( MACHININGS) return true end @@ -425,9 +477,8 @@ function WinExec.ProcessFeatures( PARTS) -- ordina le lavorazioni OrderMachining( MACHININGS) - for i = 1, #MACHININGS do - if MACHININGS[i].AuxInfo.nPhase == 1 then + if MACHININGS[i].AuxiliaryData.nPhase == 1 then -- aggiunge effettivamente la lavorazione e restituisce gli ingombri local bIsApplyOk, sErr, b3MachEncumbrance = MachiningLib.AddOperation( MACHININGS[i]) -- TODO ingombro lavorazione mi restituisce dati sbagliati. C'è un riferimento? -- se feature di testa, sposto testa in base a ingombro lavorazione @@ -453,7 +504,7 @@ function WinExec.ProcessFeatures( PARTS) EgtSetCurrPhase( 2) UpdateRawPosition( PARTS) for i = 1, #MACHININGS do - if MACHININGS[i].AuxInfo.nPhase == 2 then + if MACHININGS[i].AuxiliaryData.nPhase == 2 then -- aggiunge effettivamente la lavorazione local bIsApplyOk, sErr, b3MachEncumbrance = MachiningLib.AddOperation( MACHININGS[i]) -- TODO ingombro lavorazione mi restituisce dati sbagliati. C'è un riferimento? -- se feature di testa, sposto testa in base a ingombro lavorazione diff --git a/CAMAuto/LuaLibs/WinLib.lua b/CAMAuto/LuaLibs/WinLib.lua index b6a64d5..f9a131d 100644 --- a/CAMAuto/LuaLibs/WinLib.lua +++ b/CAMAuto/LuaLibs/WinLib.lua @@ -70,6 +70,31 @@ function WinLib.GetAffectedFaces( Proc, Part) return vtFacesAffected end +------------------------------------------------------------------------------------------------------------- +function WinLib.SwapElements( Table, Pos1, Pos2) + Table[Pos1], Table[Pos2] = Table[Pos2], Table[Pos1] + return Table +end + +------------------------------------------------------------------------------------------------------------- +function WinLib.ChangeElementPositionInTable( Table, nCurrentPosition, nTargetPosition) + -- se indici uguali esco subito + if nTargetPosition == nCurrentPosition then + return Table + end + + local Item = Table[nCurrentPosition] + + if nTargetPosition > nCurrentPosition then + nTargetPosition = nTargetPosition - 1 + end + table.remove( Table, nCurrentPosition) + table.insert( Table, nTargetPosition, Item) + + return Table +end + + ------------------------------------------------------------------------------------------------------------- function WinLib.GetAddGroup( PartId) -- recupero il nome del gruppo di lavoro corrente diff --git a/CAMAuto/ProcessWin.lua b/CAMAuto/ProcessWin.lua index 69ee3c1..dfe566a 100644 --- a/CAMAuto/ProcessWin.lua +++ b/CAMAuto/ProcessWin.lua @@ -7,7 +7,7 @@ -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() -EgtEnableDebug( true) +EgtEnableDebug( false) -- TODO da cancellare quando verrà passato automaticamente da programma local WIN = {} @@ -283,7 +283,10 @@ local function MyProcessPieces() -- Impostazione dell'attrezzaggio di default -- TODO se lascio il campo vuoto non mi carica il default!!!!!!! - local bOk = EgtImportSetup( 'Standard') + local bOk = EgtImportSetup() + if not bOk then + EgtImportSetup( 'Default') + end return true end diff --git a/CAMAuto/Strategies/Drilling.lua b/CAMAuto/Strategies/Drilling.lua index 26ea23e..371c8bb 100644 --- a/CAMAuto/Strategies/Drilling.lua +++ b/CAMAuto/Strategies/Drilling.lua @@ -14,12 +14,22 @@ local MachiningLib = require( 'MachiningLib') EgtOutLog( ' Drilling started', 1) EgtMdbSave() +------------------------------------------------------------------------------------------------------------- +-- funzione che decide se eseguire le forature dopo le profilature. Solo forature di testa inclinate. Altrimenti sempre prima. +local function IsDrillToMachineAfterProfile( Proc) + local bExecAfterProfile = false + if ( Proc.AffectedFaces.Left or Proc.AffectedFaces.Right) and abs( Proc.vtDir:getX()) > 0.15 then + bExecAfterProfile = true + end + return bExecAfterProfile +end + ------------------------------------------------------------------------------------------------------------- function Drilling.Make( Proc, Part) local ToolInfo = {} local Machining = {} - local AuxInfo = {} + local AuxiliaryData = {} Machining.LeadIn = {} Machining.LeadOut = {} Machining.Steps = {} @@ -37,9 +47,12 @@ function Drilling.Make( Proc, Part) Machining.sDepth = 'th' Machining.Steps.dStep = TOOLS[ToolInfo.nToolIndex].dStep Machining.Geometry = Proc.id - AuxInfo.nPhase = MachiningLib.GetPhaseMach( Proc) - Machining.dStartSafetyLength = MachiningLib.GetDrillAdditionalSafeDistanceToRaw( Proc, Part, Machining) + 5 -- aggiungo 5mm di sicurezza - MachiningLib.AddNewMachining( Proc, Machining, AuxInfo) + AuxiliaryData.bExecAfterProfile = IsDrillToMachineAfterProfile( Proc) + AuxiliaryData.bIsDrilling = true + AuxiliaryData.nIndexMachining = 1 + AuxiliaryData.nPhase = MachiningLib.GetPhaseMach( Proc) + Machining.dStartSafetyLength = MachiningLib.GetDrillAdditionalSafeDistanceToRaw( Proc, Part, Machining) + MachiningLib.AddNewMachining( Proc, Machining, AuxiliaryData) else -- provo a cercare una fresa che faccia una svuotatura ToolSearchParameters.dMaxToolDiameter = Proc.dDiameter @@ -56,8 +69,10 @@ function Drilling.Make( Proc, Part) Machining.LeadIn.dElevation = TOOLS[ToolInfo.nToolIndex].dDiameter/2 Machining.sDepth = 0 Machining.Geometry = Proc.id - AuxInfo.nPhase = MachiningLib.GetPhaseMach( Proc) - MachiningLib.AddNewMachining( Proc, Machining, AuxInfo) + AuxiliaryData.bIsPocketingDrill = true + AuxiliaryData.nIndexMachining = 1 + AuxiliaryData.nPhase = MachiningLib.GetPhaseMach( Proc) + MachiningLib.AddNewMachining( Proc, Machining, AuxiliaryData) else return false end diff --git a/CAMAuto/Strategies/Profiling.lua b/CAMAuto/Strategies/Profiling.lua index 2851732..ab6dc2e 100644 --- a/CAMAuto/Strategies/Profiling.lua +++ b/CAMAuto/Strategies/Profiling.lua @@ -22,7 +22,7 @@ function Profiling.Make( Proc, Part) if Proc.nToolsToUse then for i = 1, Proc.nToolsToUse do local Machining = {} - local AuxInfo = {} + local AuxiliaryData = {} Machining.LeadIn = {} Machining.LeadOut = {} Machining.Steps = {} @@ -33,20 +33,22 @@ function Profiling.Make( Proc, Part) -- se trovato utensile if ToolInfo.nToolIndex then Machining.nType = MCH_MY.MILLING - Machining.nWorkSide = MCH_MILL_WS.RIGHT + Machining.nWorkside = MCH_MILL_WS.RIGHT Machining.nToolIndex = ToolInfo.nToolIndex Machining.sDepth = 0 Machining.dRadialOffset = Proc.Tools[i].dRadialOffset Machining.dLongitudinalOffset = Proc.Tools[i].dLongitudinalOffset Machining.LeadIn.nType = MCH_MILL_LI.TANGENT - Machining.LeadIn.dTangentDistance = (TOOLS[ToolInfo.nToolIndex].dTotDiameter / 2) + 10 - Machining.LeadIn.dPerpDistance = (TOOLS[ToolInfo.nToolIndex].dTotDiameter / 2) + 10 + Machining.LeadIn.dTangentDistance = (TOOLS[ToolInfo.nToolIndex].dTotDiameter / 2) + 30 + Machining.LeadIn.dPerpDistance = (TOOLS[ToolInfo.nToolIndex].dTotDiameter / 2) + 30 Machining.LeadOut.nType = MCH_MILL_LO.TANGENT - Machining.LeadOut.dTangentDistance = (TOOLS[ToolInfo.nToolIndex].dTotDiameter / 2) + 10 + Machining.LeadOut.dTangentDistance = (TOOLS[ToolInfo.nToolIndex].dTotDiameter / 2) + 30 Machining.LeadOut.dPerpDistance = 0 Machining.Geometry = Proc.id - AuxInfo.nPhase = MachiningLib.GetPhaseMach( Proc) - MachiningLib.AddNewMachining( Proc, Machining, AuxInfo) + AuxiliaryData.bIsProfiling = true + AuxiliaryData.nIndexMachining = i + AuxiliaryData.nPhase = MachiningLib.GetPhaseMach( Proc) + MachiningLib.AddNewMachining( Proc, Machining, AuxiliaryData) else return false, 'Tool not found' end