From c5b22133296f228fff351c6e5cccb1399d818732 Mon Sep 17 00:00:00 2001 From: DarioS Date: Sat, 29 Jan 2022 18:38:16 +0100 Subject: [PATCH] DataWall : - aggiunta ottimizzazione pe rutensile su fresature - corretti errori con fori inclinati --- LuaLibs/WProcessDrill.lua | 67 ++++++--------- LuaLibs/WProcessLapJoint.lua | 2 +- LuaLibs/WallExec.lua | 155 ++++++++++++++++++++++++++--------- 3 files changed, 144 insertions(+), 80 deletions(-) diff --git a/LuaLibs/WProcessDrill.lua b/LuaLibs/WProcessDrill.lua index b9fecc7..474269a 100644 --- a/LuaLibs/WProcessDrill.lua +++ b/LuaLibs/WProcessDrill.lua @@ -1,10 +1,11 @@ --- WProcessDrill.lua by Egaltech s.r.l. 2022/01/20 +-- WProcessDrill.lua by Egaltech s.r.l. 2022/01/29 -- Gestione calcolo forature per Pareti -- 2021/08/29 DS Se foratura di fianco setto flag per farla dopo i tagli. -- 2021/12/04 DS Modifiche per forature speciali lungo Y. -- 2022/01/12 DS Se con fresatura richiedo che l'utensile possa lavorare di testa. -- 2022/01/19 DS Forature orizzontali lunghe con nome LhDrill_. -- 2022/01/20 DS Aggiunta gestione Q01 (flag forzatura solo contornatura). +-- 2022/01/29 DS Corretta gestione ingombro portautensili per fori inclinati da sopra. -- Tabella per definizione modulo local WPD = {} @@ -63,8 +64,8 @@ function WPD.Classify( Proc, b3Raw) local dLen = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local ptCen = EgtCP( AuxId, GDB_RT.GLOB) - -- verifico se troppo inclinato e quindi non lavorabile - if not ( Proc.Fcs == 5 or Proc.Fcs == 6 or Proc.Fce == 5 or Proc.Fce == 6) and abs( vtExtr:getX()) > WD.DRILL_VX_MAX then + -- se in faccia sopra e troppo inclinato, non è lavorabile + if ptCen:getZ() > b3Raw:getMax():getZ() - dDiam / 2 and abs( vtExtr:getZ()) < WD.DRILL_VZ_MIN then return false end local bOpen = ( Proc.Fce ~= 0) @@ -81,8 +82,6 @@ end -- Classificazione del flip della feature per nesting -- return nFlip0, nFlip1 function WPD.FlipClassify( Proc, b3Part) - local nFlip0 = 0 - local nFlip1 = 0 -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end @@ -94,37 +93,18 @@ function WPD.FlipClassify( Proc, b3Part) local dLen = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local ptCen = EgtCP( AuxId, GDB_RT.GLOB) - - -- identifico su quali facce si trova il foro - local ptPrcMin = Proc.Box:getMin() - local ptPrcMax = Proc.Box:getMax() - local ptPartMin = b3Part:getMin() - local ptPartMax = b3Part:getMax() - - if not ( abs( ptPrcMin:getX() - ptPartMin:getX()) < GEO.EPS_SMALL or abs( ptPrcMax:getX() - ptPartMax:getX()) < GEO.EPS_SMALL) then -- corrispondente delle facce 5/6 nel caso ruotato - if abs( vtExtr:getX()) > WD.DRILL_VX_MAX then return 0, 0 end - end - -- se foro cieco if Proc.Fcs == 0 or Proc.Fce == 0 then -- se normale positiva local dVtExtrZ = vtExtr:getZ() -- verifico se è lavorabile da sopra - nFlip0 = EgtIf( dVtExtrZ >= WD.DRILL_VZ_MIN, 100, 0) - -- verifico se e' lavorabile da fliped: cambio segno al versore - nFlip1 = EgtIf( -dVtExtrZ >= WD.DRILL_VZ_MIN, 100, 0) + local nFlip0 = EgtIf( dVtExtrZ >= WD.DRILL_VZ_MIN, 100, 0) + -- verifico se e' lavorabile da flipped: cambio segno al versore + local nFlip1 = EgtIf( -dVtExtrZ >= WD.DRILL_VZ_MIN, 100, 0) return nFlip0, nFlip1 --- -- altrimenti foro passante --- else --- -- verifico orientamento della normale rispetto ad angolo massimo --- if abs( vtExtr:getX()) <= WD.DRILL_VX_MAX then --- nFlip0 = 100 --- nFlip1 = 100 --- else --- nFlip0 = 0 --- nFlip1 = 0 --- end end + -- altrimenti + return 0, 0 end --------------------------------------------------------------------- @@ -164,13 +144,10 @@ function WPD.RotateClassify( Proc) return nRot0, nRot90, nRot180, nRot270 end end - --- local b3Drill = EgtGetBBoxGlob( Proc.Id, GDB_BB.STANDARD) --- -- se ci sono fori sul profilo (box attaccato al profilo e / calcolo intersezione tra foro e box, se box del profilo foro ha Z, e' sul profilo) - end -function WPD.IsHorizLongDrill( Proc) +--------------------------------------------------------------------- +local function IsHorizLongDrill( Proc) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end @@ -183,8 +160,9 @@ function WPD.IsHorizLongDrill( Proc) return dDiam <= WD.HOR_DRILL_DIAM + WD.DRILL_TOL and dDiam >= WD.HOR_DRILL_DIAM - WD.DRILL_TOL and vtExtr:getZ() > -0.1 and vtExtr:getZ() < 0.1 end +--------------------------------------------------------------------- function WPD.UseMinYForLongDrill( Proc) - if WPD.IsHorizLongDrill( Proc) then + if IsHorizLongDrill( Proc) then -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end @@ -244,6 +222,7 @@ function WPD.Make( Proc, nRawId, b3Raw) local dDiam = 2 * EgtArcRadius( AuxId) local dLen = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) + local ptCen = EgtCP( AuxId, GDB_RT.GLOB) 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) @@ -312,15 +291,18 @@ function WPD.Make( Proc, nRawId, b3Raw) end -- recupero i dati dell'utensile local dMaxDepth = 20 + local dFreeLen = 20 local dDiamTh = 35 if EgtMdbSetCurrMachining( sDrilling) then local bIsDrilling = ( EgtMdbGetCurrMachiningParam( MCH_MP.TYPE) == MCH_MY.DRILLING) local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then if bIsDrilling then + dFreeLen = EgtTdbGetCurrToolParam( MCH_TP.LEN) - EgtTdbGetCurrToolThLength() - EgtMdbGetGeneralParam( MCH_GP.MAXDEPTHSAFE) dMaxDepth = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxDepth else - dMaxDepth = EgtIf( WD.MILL_MAX_DEPTH_AS_MAT, EgtTdbGetCurrToolParam( MCH_TP.MAXMAT), EgtTdbGetCurrToolMaxDepth()) or dMaxDepth + dFreeLen = EgtTdbGetCurrToolMaxDepth() or dFreeLen + dMaxDepth = EgtIf( WD.MILL_MAX_DEPTH_AS_MAT, EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxDepth, dFreeLen) end dDiamTh = EgtTdbGetCurrToolThDiam() end @@ -339,12 +321,13 @@ function WPD.Make( Proc, nRawId, b3Raw) dMaxDepth = dMaxDepth - dDeltaY end end - -- se foro intermedio e inclinato, limito il massimo affondamento - if not ( ( Proc.Fcs == 5 or Proc.Fcs == 6) or ( bToInvert and ( Proc.Fce == 5 or Proc.Fce == 6))) then - local CosB = abs( vtExtr:getX()) - if CosB < WD.DRILL_VX_MAX then - local TgA = CosB / sqrt( 1 - CosB * CosB) - dMaxDepth = dMaxDepth - dDiamTh / 2 * TgA + -- se foro faccia sopra, limito il massimo affondamento secondo inclinazione + if ptCen:getZ() > b3Raw:getMax():getZ() - dDiam / 2 then + local SinA = abs( vtExtr:getZ()) + if SinA >= WD.DRILL_VZ_MIN then + local CosA = sqrt( 1 - SinA * SinA) + local dSlantFreeLen = dFreeLen - ( dDiamTh / 2 * CosA / SinA) + dMaxDepth = min( dMaxDepth, dSlantFreeLen) else dMaxDepth = 0 end diff --git a/LuaLibs/WProcessLapJoint.lua b/LuaLibs/WProcessLapJoint.lua index 8c9ccf6..f69a557 100644 --- a/LuaLibs/WProcessLapJoint.lua +++ b/LuaLibs/WProcessLapJoint.lua @@ -1630,7 +1630,7 @@ local function MakeSideGrooveByMill( Proc, nFacet, nRawId, b3Raw, sCustomMach, d end end -- inserisco la lavorazione di ribasso o gola - local sName = 'Mill_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local sName = EgtIf( bEnablePreMill ~= nil, 'SideMill_', 'Mill_') .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchFId = EgtAddMachining( sName, sMilling) if not nMchFId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index c0a4ea4..5725f39 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -351,31 +351,7 @@ local function MoveMachiningsAtEnd( nPhase, nType, sStartName, sProperty) end ------ Ordinamento dei tagli, delle fresature e delle forature ------- -local function SortMach( nPhase, PrevMch, nPartId, nType, sStartName, bExistName, sInfo, bExistInfo, bOneWay) - -- dichiarazione tabella - local TabCut = {} - -- Recupero gli identificativi delle lavorazioni e annullo eventuali allungamenti e Id di altre lavorazioni rappresentate - local nOperId = EgtGetNextOperation( PrevMch) - while nOperId do - -- Se appartiene alla fase corrente e taglio con lama non da sopra (sempre su 1 sola entità) - if EgtGetOperationPhase( nOperId) == nPhase and EgtGetOperationType( nOperId) == nType and - ( not nPartId or EgtGetInfo( nOperId, 'Part', 'i') == nPartId) and - ( not sStartName or ( bExistName and string.sub( EgtGetName( nOperId), 1, #sStartName) == sStartName) or - ( not bExistName and string.sub( EgtGetName( nOperId), 1, #sStartName) ~= sStartName)) and - ( not sInfo or ( bExistInfo and EgtGetInfo( nOperId, sInfo, 'i') == 1) or - ( not bExistInfo and EgtGetInfo( nOperId, sInfo, 'i') ~= 1)) then - -- non si deve cambiare lo stato di attivazione della lavorazione (se disabilitata errata) - EgtSetCurrMachining( nOperId) - if not EgtIsMachiningEmpty() then - -- punto iniziale e finale e direzione della lavorazione - local ptStart = EgtGetMachiningStartPoint() - local ptEnd = EgtGetMachiningEndPoint() - table.insert( TabCut, {Mch=nOperId, Ent=nEntId, Start=ptStart, End=ptEnd}) - end - end - -- Passo alla operazione successiva - nOperId = EgtGetNextOperation( nOperId) - end +local function SpSorting( TabCut, PrevMch, nType, bOneWay) -- ordino le lavorazioni (in gruppi di max 1000 entità se 32bit 10000 se 64bit) --EgtOutLog('Dati per ShortestPath :') @@ -392,7 +368,7 @@ local function SortMach( nPhase, PrevMch, nPartId, nType, sStartName, bExistName end EgtSpSetAngularParams( 1000, 40, 2000, 60) EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, 50000, 0, 0, 0, 0) - if WD.BEAM_MACHINE and nType == MCH_OY.SAWING then + if WD.BEAM_MACHINE and (nType & MCH_OY.SAWING) == MCH_OY.SAWING then EgtSpSetOpenBound( false, SHP_OB.NEAR_PNT, -50000, 0, 0, 0, 0) end EgtSpSetZzOwStep( 10) @@ -413,31 +389,136 @@ local function SortMach( nPhase, PrevMch, nPartId, nType, sStartName, bExistName return PrevMch end +local function ContainsStartName( nOperId, StartNames) + local bFound = false + for i = 1, #StartNames do + local sStartName = StartNames[i] + if string.sub( EgtGetName( nOperId), 1, #sStartName) == sStartName then + bFound = true + end + end + return bFound +end + +------ Ordinamento dei tagli, delle fresature e delle forature ------- +local function SortMach( nPhase, PrevMch, nPartId, nType, StartNames, bExistName, sInfo, bExistInfo, bOneWay, bByTool) + -- dichiarazione tabella + local TabCut = {} + -- Recupero gli identificativi delle lavorazioni e annullo eventuali allungamenti e Id di altre lavorazioni rappresentate + local nOperId = EgtGetNextOperation( PrevMch) + while nOperId do + local nOperType = EgtGetOperationType( nOperId) + -- Se appartiene alla fase corrente e taglio con lama non da sopra (sempre su 1 sola entità) + if EgtGetOperationPhase( nOperId) == nPhase and ( nType & nOperType) == nOperType and + ( not nPartId or EgtGetInfo( nOperId, 'Part', 'i') == nPartId) and + ( not StartNames or ( bExistName and ContainsStartName( nOperId, StartNames)) or + ( not bExistName and not ContainsStartName( nOperId, StartNames))) and + ( not sInfo or ( bExistInfo and EgtGetInfo( nOperId, sInfo, 'i') == 1) or + ( not bExistInfo and EgtGetInfo( nOperId, sInfo, 'i') ~= 1)) then + -- non si deve cambiare lo stato di attivazione della lavorazione (se disabilitata errata) + EgtSetCurrMachining( nOperId) + if not EgtIsMachiningEmpty() then + -- punto iniziale e finale e direzione della lavorazione + local ptStart = EgtGetMachiningStartPoint() + local ptEnd = EgtGetMachiningEndPoint() + local sTUUID = '' + local nToolType = 0 + local nToolDiam = 0 + if bByTool then + sTUUID = EgtGetMachiningParam( MCH_MP.TUUID) + local sToolName = EgtTdbGetToolFromUUID( sTUUID) + if EgtTdbSetCurrTool( sToolName) then + nToolType = EgtTdbGetCurrToolParam( MCH_TP.TYPE) + nToolDiam = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) + else + sTUUID = '' + end + end + table.insert( TabCut, {Mch=nOperId, Ent=nEntId, Start=ptStart, End=ptEnd, Tool=sTUUID, ToolType=nToolType, ToolDiam=nToolDiam}) + end + end + -- Passo alla operazione successiva + nOperId = EgtGetNextOperation( nOperId) + end + + if bByTool then + function ToolCompare(a,b) + local y = a.ToolType < b.ToolType and a.ToolDiam > b.ToolDiam and a.Tool < b.Tool + if a.ToolType < b.ToolType then + return true + elseif a.ToolType == b.ToolType then + if a.ToolDiam > b.ToolDiam then + return true + elseif a.ToolDiam == b.ToolDiam then + if a.Tool < b.Tool then + return true + else + return false + end + end + end + return false +-- return a.ToolType < b.ToolType and a.ToolDiam > b.ToolDiam and a.Tool < b.Tool + end + table.sort(TabCut, ToolCompare) +-- table.sort(TabCut, function(a,b) return a.ToolType < b.ToolType and a.ToolDiam > b.ToolDiam and a.Tool < b.Tool end) + local SupportTabCut = {} + local nPrevTUUID = 0 + for i = 1, #TabCut do + -- se tuuid uguale al precedente, lo aggiungo alla lista + if nPrevTUUID == TabCut[i].Tool then + table.insert( SupportTabCut, TabCut[i]) + -- se tuuid diverso, + else + -- faccio calcolare la lista + PrevMch = SpSorting( SupportTabCut, PrevMch, nType, bOneWay) + -- cancello la lista e aggiorno tuuid corrente + SupportTabCut = {} + nPrevTUUID = TabCut[i].Tool + table.insert( SupportTabCut, TabCut[i]) + end + end + -- calcolo ultima lista + if #SupportTabCut > 0 then + PrevMch = SpSorting( SupportTabCut, PrevMch, nType, bOneWay) + end + else + PrevMch = SpSorting( TabCut, PrevMch, nType, bOneWay) + end + + return PrevMch + +end + ------------------------------------------------------------------------------------------------------------- local function SortMachinings( nPhase, PrevMch, nPartId) -- Chiodature - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, 'Nail_', true) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Nail_'}, true) -- Tagli con sega a catena che sono rifiniture di spigoli - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MORTISING, 'Csaw_', false) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MORTISING, { 'Csaw_'}, false) -- Forature orizzontali con punte lunghe - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, 'LhDrill_', true, 'MOVE_AFTER', false, true) - -- Forature - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, nil, nil, 'MOVE_AFTER', false) - -- Svuotature - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.POCKETING, nil, nil, 'MOVE_AFTER', false) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, { 'LhDrill_'}, true, 'MOVE_AFTER', false, true) + -- Forature e Svuotature + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING + MCH_OY.POCKETING + MCH_OY.MILLING, { 'SideMill_', 'Clean_'}, false, 'MOVE_AFTER', false, false, true) +-- -- Forature *** +-- PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, nil, nil, 'MOVE_AFTER', false) +-- -- Svuotature *** +-- PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.POCKETING, nil, nil, 'MOVE_AFTER', false) +-- -- Fresature che sono rifiniture di spigoli +-- PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Clean_'}, false, 'MOVE_AFTER', false, false, true) -- Lavorazioni di superficie PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_MY.SURFFINISHING, nil, nil, 'MOVE_AFTER', false) -- Fresature per gole - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, 'Gorge_', true, 'MOVE_AFTER', false) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Gorge_'}, true, 'MOVE_AFTER', false) -- Fresature che sono rifiniture di spigoli - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, 'Clean_', false, 'MOVE_AFTER', false) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'SideMill_'}, true, 'MOVE_AFTER', false, false, true) -- Fresature che sono puliture di spigoli - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, 'Clean_', true, 'MOVE_AFTER', false) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Clean_'}, true, 'MOVE_AFTER', false) -- Tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.SAWING) -- Qui rimozione sfridi (se ci sono lavorazioni successive) -- Tagli con sega a catena che vanno fatti dopo i tagli con lama - PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MORTISING, 'Csaw_', true) + PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MORTISING, { 'Csaw_'}, true) -- Fresature (puliture di spigoli) che vanno fatte dopo i tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, nil, nil, 'MOVE_AFTER', true) -- Forature che vanno fatte dopo i tagli con lama