diff --git a/LuaLibs/WMachiningLib.lua b/LuaLibs/WMachiningLib.lua index d5ed5c5..43cd040 100644 --- a/LuaLibs/WMachiningLib.lua +++ b/LuaLibs/WMachiningLib.lua @@ -148,18 +148,27 @@ function WMachiningLib.FindSawing( sType) end --------------------------------------------------------------------- -function WMachiningLib.FindDrilling( dDiam, dDepth, sHead, bOnlyPockets) +function WMachiningLib.FindDrilling( dDiam, dDepth, sHead, bOnlyPockets, bUseMultiDrill, DrillingsToAvoid) if bOnlyPockets == nil or not bOnlyPockets then -- ricerca sulle forature, dal diametro maggiore al minore for i = #Drillings, 1, -1 do local Drilling = Drillings[i] - if Drilling.On and Drilling.Type == 'Drill' and SetCurrMachiningAndTool( Drilling.Name) then + if Drilling.On and EgtIf( bUseMultiDrill, Drilling.Type == 'MultiDrill', Drilling.Type == 'Drill') and SetCurrMachiningAndTool( Drilling.Name) then + local bIsToAvoid = false + if DrillingsToAvoid then + for j = 1, #DrillingsToAvoid do + if Drilling.Name == DrillingsToAvoid[j] then + bIsToAvoid = true + end + end + end local nMchType = EgtMdbGetCurrMachiningParam( MCH_MP.TYPE) local dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) local dTMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) local sMyHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) if nMchType == MCH_MY.DRILLING and - dTDiam < dDiam + 10 * GEO.EPS_SMALL and dTDiam > dDiam - WD.DRILL_TOL - 10 * GEO.EPS_SMALL and + ( not bIsToAvoid) and + ( not dDiam or ( dTDiam < dDiam + 10 * GEO.EPS_SMALL and dTDiam > dDiam - WD.DRILL_TOL - 10 * GEO.EPS_SMALL)) and ( not dDepth or dTMaxMat > dDepth - GEO.EPS_SMALL) and (( not sHead and sMyHead ~= 'H5' and sMyHead ~= 'H6') or sHead == sMyHead) then return Drilling.Name, Drilling.Type, dTMaxMat @@ -167,16 +176,29 @@ function WMachiningLib.FindDrilling( dDiam, dDepth, sHead, bOnlyPockets) end end end + -- se MultiDrill non si prova il DrillPocket + if bUseMultiDrill then + return + end -- ricerca sulle svuotature, dal diametro maggiore al minore for i = #Drillings, 1, -1 do local Drilling = Drillings[i] if Drilling.On and Drilling.Type == 'Pocket' and SetCurrMachiningAndTool( Drilling.Name) then + local bIsToAvoid = false + if DrillingsToAvoid then + for j = 1, #DrillingsToAvoid do + if Drilling.Name == DrillingsToAvoid[j] then + bIsToAvoid = true + end + end + end local nMchType = EgtMdbGetCurrMachiningParam( MCH_MP.TYPE) local dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) local dTMaxDepth = EgtIf( WD.MILL_MAX_DEPTH_AS_MAT, EgtTdbGetCurrToolParam( MCH_TP.MAXMAT), EgtTdbGetCurrToolMaxDepth()) local sMyHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD) if nMchType == MCH_MY.POCKETING and - dTDiam < dDiam - 10 * GEO.EPS_SMALL and + ( not bIsToAvoid) and + ( not dDiam or ( dTDiam < dDiam - 10 * GEO.EPS_SMALL)) and ( not dDepth or dTMaxDepth > dDepth - GEO.EPS_SMALL) and ( ( not sHead and sMyHead ~= 'H5' and sMyHead ~= 'H6') or sHead == sMyHead) then return Drilling.Name, Drilling.Type, dTMaxDepth diff --git a/LuaLibs/WProcessDrill.lua b/LuaLibs/WProcessDrill.lua index a4de0c1..6eafa77 100644 --- a/LuaLibs/WProcessDrill.lua +++ b/LuaLibs/WProcessDrill.lua @@ -27,6 +27,9 @@ local WM = require( 'WMachiningLib') -- Parametri Q local sContourOnly = 'Q01' -- 0=no, 1=si +-- Per forature MultiDrill, lista lavorazioni già provate +local TriedDrillings = {} + --------------------------------------------------------------------- -- Riconoscimento della feature @@ -56,7 +59,7 @@ end --------------------------------------------------------------------- -- Classificazione della feature -function WPD.Classify( Proc, b3Raw) +function WPD.Classify( Proc, b3Raw, bUseMultiDrill) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 @@ -75,6 +78,10 @@ function WPD.Classify( Proc, b3Raw) -- è lavorabile se non troppo inclinato return ( abs( vtExtr:getZ()) >= WD.DRILL_VZ_MIN) end + -- multiforatore (cabinet) + if bUseMultiDrill then + return true + end -- se con direzione asse Y e macchina con foratore orizzontale del giusto diametro if WD.HOR_DRILL_DIAM and abs( dDiam - WD.HOR_DRILL_DIAM) < WD.DRILL_TOL and AreSameOrOppositeVectorApprox( vtExtr, Y_AX()) then return true @@ -255,7 +262,7 @@ end --------------------------------------------------------------------- -- Applicazione della lavorazione -function WPD.Make( Proc, nRawId, b3Raw) +function WPD.Make( Proc, nRawId, b3Raw, bUseMultiDrill, DrillingsToAvoid) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end @@ -272,7 +279,7 @@ function WPD.Make( Proc, nRawId, b3Raw) local bOpen = ( Proc.Fcs ~= 0 and Proc.Fce ~= 0) -- verifico che il foro non sia fattibile solo da sotto local bToInvert = ( vtExtr:getZ() < -0.1) - if bToInvert and ( not bOpen or Proc.Flg ~= 1) then + if bToInvert and ( not bOpen or Proc.Flg > 1) then local sErr = 'Error : drilling from bottom impossible' EgtOutLog( sErr) return false, sErr @@ -299,27 +306,35 @@ function WPD.Make( Proc, nRawId, b3Raw) end end end - local bUseDLenToFindDrilling = true - local sDrilling, nType = WM.FindDrilling( dDiam, dLen, sHead) - if not sDrilling then - bUseDLenToFindDrilling = false - sDrilling, nType = WM.FindDrilling( dDiam, nil, sHead) - end - -- se Proc è settata per essere specchiata cerco la lavorazione adatta e verifico possa essere effettivamente specchiata - if Proc.Double and Proc.Double == 2 then - local sDrillingBackup = sDrilling - sDrilling = WM.FindDrilling( dDiam, EgtIf( bUseDLenToFindDrilling, dLen, nil), 'H1') - if not IsMachiningOkForDouble( sDrilling) then - Proc.Double = 0 - sDrilling = sDrillingBackup - end - end - if sHead and not sDrilling then - sDrilling, nType = WM.FindDrilling( dDiam, dLen) + local sDrilling, nType + if bUseMultiDrill then + sDrilling, nType = WM.FindDrilling( nil, nil, nil, nil, true, TriedDrillings) if not sDrilling then - sDrilling, nType = WM.FindDrilling( dDiam) + return false + end + else + local bUseDLenToFindDrilling = true + sDrilling, nType = WM.FindDrilling( dDiam, dLen, sHead) + if not sDrilling then + bUseDLenToFindDrilling = false + sDrilling, nType = WM.FindDrilling( dDiam, nil, sHead) + end + -- se Proc è settata per essere specchiata cerco la lavorazione adatta e verifico possa essere effettivamente specchiata + if Proc.Double and Proc.Double == 2 then + local sDrillingBackup = sDrilling + sDrilling = WM.FindDrilling( dDiam, EgtIf( bUseDLenToFindDrilling, dLen, nil), 'H1') + if not IsMachiningOkForDouble( sDrilling) then + Proc.Double = 0 + sDrilling = sDrillingBackup + end + end + if sHead and not sDrilling then + sDrilling, nType = WM.FindDrilling( dDiam, dLen) + if not sDrilling then + sDrilling, nType = WM.FindDrilling( dDiam) + end + if sDrilling then sHead = '' end end - if sDrilling then sHead = '' end end local bAngledContourDrill = false local nAngledContourDrillId = GDB_ID.NULL @@ -446,11 +461,29 @@ function WPD.Make( Proc, nRawId, b3Raw) -- aggiungo geometria if bAngledContourDrill then EgtSetMachiningGeometry( nAngledContourDrillId) + elseif bUseMultiDrill then + if Proc.SkippedGeometries and #Proc.SkippedGeometries > 0 then + EgtSetMachiningGeometry( Proc.SkippedGeometries) + else + local HolesGeometries = {} + -- aggiungo foro principale + table.insert( HolesGeometries, { AuxId, -1}) + -- aggiungo eventuali altre geometrie connesse + if Proc.OtherGeometries and #Proc.OtherGeometries > 0 then + for i = 1, #Proc.OtherGeometries do + -- recupero geometria da lavorare + local OtherAuxId = Proc.OtherGeometries[i].Id + EgtGetInfo( Proc.OtherGeometries[i].Id, 'AUXID', 'i') + local Geometry = { OtherAuxId, -1} + table.insert( HolesGeometries, Geometry) + end + end + EgtSetMachiningGeometry( HolesGeometries) + end else EgtSetMachiningGeometry( {{ AuxId, -1}}) end -- eventuale inversione - if nType == 'Drill' then + if nType == 'Drill' or nType == 'MultiDrill' then EgtSetMachiningParam( MCH_MP.INVERT, bToInvert) else EgtSetMachiningParam( MCH_MP.TOOLINVERT, bToInvert) @@ -488,7 +521,9 @@ function WPD.Make( Proc, nRawId, b3Raw) end -- imposto posizione braccio porta testa local nSCC = MCH_SCC.ADIR_ZP - if AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then + if bUseMultiDrill then + nSCC = MCH_SCC.ADIR_NEAR + elseif AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then nSCC = MCH_SCC.ADIR_YP end EgtSetMachiningParam( MCH_MP.SCC, nSCC) @@ -502,8 +537,13 @@ function WPD.Make( Proc, nRawId, b3Raw) EgtOutLog( sMyWarn .. ' (process ' .. tostring( Proc.Id) .. ')') end end - EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) - -- leggo eventuali note esistenti della lavorazione + if bUseMultiDrill then + local sDepth = 'TH' + EgtSetMachiningParam( MCH_MP.DEPTH_STR, sDepth) + else + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + end + -- leggo eventuali note esistenti della lavorazione local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) -- se foratura o svuotatura, dichiarazione nessuna generazione sfridi per Vmill if nType == 'Drill' or nType == 'Pocket' then @@ -536,19 +576,95 @@ function WPD.Make( Proc, nRawId, b3Raw) EgtSetMachiningParam( MCH_MP.TABMAX, 3) end -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchId, false) - return false, sErr - else - local _, sWarn = EgtGetMachMgrWarning( 0) - if EgtIsMachiningEmpty() then - EgtSetOperationMode( nMchId, false) - return false, sWarn - else - sMyWarn = (sMyWarn or sWarn) + local bOk = EgtApplyMachining( true, false) + + -- in caso di fori raggruppati vengono restituiti gli eventuali fori saltati + local SkippedGeometries = {} + SkippedGeometries = EgtGetMachiningSkippedGeometry() + local sMsgMaster + if bUseMultiDrill and SkippedGeometries and #SkippedGeometries > 0 then + if ( Proc.SkippedGeometries and ( #SkippedGeometries == #Proc.SkippedGeometries)) + or ( Proc.OtherGeometries and ( #SkippedGeometries == #Proc.OtherGeometries + 1)) + or ( not Proc.OtherGeometries and #SkippedGeometries == 1) then + EgtRemoveOperation( nMchId) + end + Proc.SkippedGeometries = SkippedGeometries + table.insert( TriedDrillings, sDrilling) + -- per provare tutte le MultiDrill disponibili si passano quelle già fatte come lavorazioni da ignorare + bOk = WPD.Make( Proc, nRawId, b3Raw, true, TriedDrillings) + -- non trovata lavorazione, si prova con le lavorazioni singole + if not bOk then + local bOkMaster = true + for i = #Proc.SkippedGeometries, 1, -1 do + local sErr + if Proc.OtherGeometries then + for j = 1, #Proc.OtherGeometries do + local AuxIdOtherGeometry = EgtGetInfo( Proc.OtherGeometries[j].Id, 'AUXID', 'i') or 0 + if AuxIdOtherGeometry then AuxIdOtherGeometry = AuxIdOtherGeometry + Proc.OtherGeometries[j].Id end + if Proc.SkippedGeometries[i][1] == AuxIdOtherGeometry then + bOk, sErr = WPD.Make( Proc.OtherGeometries[j], nRawId, b3Raw, false) + if bOk then + Proc.OtherGeometries[j].bOk = true + else + Proc.OtherGeometries[j].bOk = false + end + Proc.OtherGeometries[j].sMsg = sErr + break + end + end + -- se nelle altre geometrie non è stato trovato, potrebbe essere la principale + local AuxIdProc = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 + if AuxIdProc then AuxIdProc = AuxIdProc + Proc.Id end + if Proc.SkippedGeometries[i][1] == AuxIdProc then + bOk, sErr = WPD.Make( Proc, nRawId, b3Raw, false) + if not bOk then + bOkMaster = false + end + sMsgMaster = sErr + end + -- se non ci sono altre geometrie quella da fare è sicuramente la Proc principale + else + bOk, sErr = WPD.Make( Proc, nRawId, b3Raw, false) + if not bOk then + bOkMaster = false + end + sMsgMaster = sErr + end + if bOk then + table.remove( Proc.SkippedGeometries, i) + end + end + bOk = bOkMaster end end + -- se presenti geometrie aggiuntive, aggiunta informazioni per output statistiche + if Proc.OtherGeometries and #Proc.OtherGeometries > 0 then + for i = 1, #Proc.OtherGeometries do + if Proc.OtherGeometries[i].bOk == nil then + Proc.OtherGeometries[i].bOk = true + Proc.OtherGeometries[i].sMsg = '' + end + end + end + + if not bUseMultiDrill then + if not bOk then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + else + local _, sWarn = EgtGetMachMgrWarning( 0) + if EgtIsMachiningEmpty() then + EgtSetOperationMode( nMchId, false) + return false, sWarn + else + sMyWarn = (sMyWarn or sWarn) + end + end + else + return bOk, sMsgMaster + end + -- se preforo inclinato impostato, inclinazione oltre limite impostato e foro non orizzontale if WD.PREDRILL_DIAM and WD.PREDRILL_DIAM > 0 and vtExtr:getZ() < ( WD.PREDRILL_MINANGLE or 0.707) and vtExtr:getZ() > 0.1 then -- gruppo ausiliario per preforo diff --git a/LuaLibs/WProcessLapJoint.lua b/LuaLibs/WProcessLapJoint.lua index f6e9e49..f61294f 100644 --- a/LuaLibs/WProcessLapJoint.lua +++ b/LuaLibs/WProcessLapJoint.lua @@ -2860,7 +2860,7 @@ local function MakeMoreFaces( Proc, nRawId, b3Raw) local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) local dMaxSlotThicknessForBlade = 19 - local bIsSmallSlot = ( Proc.Fct == 3 and ( min( dH, dV) < dMaxSlotThicknessForBlade - 10 * GEO.EPS_SMALL) and vtN:getZ() > -0.01) + local bIsSmallSlot = ( Proc.Fct == 3 and ( min( dH, dV) < dMaxSlotThicknessForBlade - 10 * GEO.EPS_SMALL) and ( vtN:getZ() > -0.01) and ( vtN:getZ() < 0.5)) -- se di fianco if not bPckt and Proc.Fct >= 3 and ( ( vtN:getZ() < WD.NZ_MINA) or bIsSmallSlot) then -- recupero elevazione faccia in feature diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index 1a5e0ec..055d634 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -303,7 +303,8 @@ local function ClassifyFeatures( vProc, b3Raw) if not bOk then Proc.Flg = 0 end -- se foratura elseif Drill.Identify( Proc) then - local bOk = Drill.Classify( Proc, b3Raw) + local bUseMultiDrill = WD.USE_MULTI_DRILL or false + local bOk = Drill.Classify( Proc, b3Raw, bUseMultiDrill) if not bOk then Proc.Flg = 0 end -- se mortasatura elseif Mortise.Identify( Proc) then @@ -383,7 +384,8 @@ local function AddFeatureMachining( Proc, nRawId, b3Raw, vNLO, b3Squaring) -- se foratura ( 3/4-040-X) elseif Drill.Identify( Proc) then -- esecuzione foratura - bOk, sErr = Drill.Make( Proc, nRawId, b3Raw) + local bUseMultiDrill = WD.USE_MULTI_DRILL or false + bOk, sErr = Drill.Make( Proc, nRawId, b3Raw, bUseMultiDrill) -- se mortasatura (3/4-050-X) o similari elseif Mortise.Identify( Proc) then -- esecuzione mortasatura @@ -1086,6 +1088,30 @@ local function SetMirroredOperations() end end +------------------------------------------------------------------------------------------------------------- +function GetFeatureInfoAndDependency( vProc) + -- ciclo tutte le feature + for i = 1, #vProc do + local Proc = vProc[i] + -- controllo la feature con tutte le altre per recuperare le dipendenze + for j = 1, #vProc do + local ProcB = vProc[j] + -- se non è la stessa feature + if Proc.Id ~= ProcB.Id then + -- raggruppamento fori per eventuale Multidrill + if WD.USE_MULTI_DRILL and Drill.Identify( Proc) and Proc.Flg ~= 0 and Drill.Identify( ProcB) and ProcB.Flg ~= 0 then + if not Proc.OtherGeometries then + Proc.OtherGeometries = {} + end + table.insert( Proc.OtherGeometries, ProcB) + ProcB.Flg = 0 + ProcB.bGrouped = true + end + end + end + end +end + ------------------------------------------------------------------------------------------------------------- local function CalculateSquaring( sSquaringTool, RawPart, vPart) local dRawPartHeight = RawPart.b3:getDimZ() @@ -1135,6 +1161,19 @@ local function AddSquaring( SquaringParameters, b3Squaring) return true, sMsg end +------------------------------------------------------------------------------------------------------------- +local function AddFeatureStats( Stats, bOk, sMsg, nCutId, nTaskId) + if not bOk then + table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId = nCutId, TaskId = nTaskId}) + elseif sMsg and #sMsg > 0 then + table.insert( Stats, {Err=-1, Msg=sMsg, Rot=0, CutId = nCutId, TaskId = nTaskId}) + else + table.insert( Stats, {Err=0, Msg='', Rot=0, CutId = nCutId, TaskId = nTaskId}) + end + + return Stats +end + ------------------------------------------------------------------------------------------------------------- function WallExec.ProcessFeatures() -- errori e stato @@ -1188,6 +1227,7 @@ function WallExec.ProcessFeatures() bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'Mill', RawPart, vPart) end + -- TODO sostituire con funzione if not bOk then nTotErr = nTotErr + 1 table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=0, TaskId=0}) @@ -1205,6 +1245,8 @@ function WallExec.ProcessFeatures() local vPartProc = WallExec.CollectFeatures( vPart[i].Id, b3Raw, b3Squaring) vProc = EgtJoinTables( vProc, vPartProc) end + -- recupero informazioni ausiliarie feature e dipendenze tra feature stesse + GetFeatureInfoAndDependency( vProc) -- classifico topologicamente le feature ClassifyTopology( vProc, nRawId) -- classifico le feature @@ -1232,13 +1274,19 @@ function WallExec.ProcessFeatures() local bOk, sMsg = AddFeatureMachining( Proc, nRawId, b3Raw, vNLO, b3Squaring) if not bOk then nTotErr = nTotErr + 1 - table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) - elseif sMsg and #sMsg > 0 then - table.insert( Stats, {Err=-1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) - else - table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) end - elseif not Proc.Double and not Proc.LockOut then + -- output statistiche feature + Stats = AddFeatureStats( Stats, bOk, sMsg, Proc.CutId, Proc.TaskId) + -- output statistiche in caso di più feature lavorate nella stessa Proc + if Proc.OtherGeometries and #Proc.OtherGeometries > 0 then + for j = 1, #Proc.OtherGeometries do + Stats = AddFeatureStats( Stats, Proc.OtherGeometries[j].bOk, Proc.OtherGeometries[j].sMsg, Proc.OtherGeometries[j].CutId, Proc.OtherGeometries[j].TaskId) + if not Proc.OtherGeometries[j].bOk then + nTotErr = nTotErr + 1 + end + end + end + elseif not Proc.Double and not Proc.LockOut and not Proc.bGrouped then local sMsg = 'Feature not machinable by orientation' table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) end @@ -1333,6 +1381,7 @@ function WallExec.ProcessFeatures() if SquaringParameters and next( SquaringParameters) ~= nil then local bOk, sMsg = AddSquaring( SquaringParameters, b3Squaring) + -- TODO sostituire con funzione if not bOk then nTotErr = nTotErr + 1 table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=0, TaskId=0})