Files
DataWall/LuaLibs/Squaring.lua
T
luca.mazzoleni d2b3c32b61 - in Squaring aggiunt creazione lavorazione al momento e settaggio parametri
- in Squaring gestito allungamento e attacco verticale per contemplare overmaterial e altezza pezzo
2024-10-29 09:09:19 +01:00

439 lines
19 KiB
Lua

-- Squaring.lua by Egaltech s.r.l. 2024/10/15
-- Libreria squadratura pareti
-- Tabella per definizione modulo
local Squaring = {}
-- Include
require( 'EgtBase')
EgtOutLog( ' Squaring started', 1)
-- Dati
local WD = require( 'WallData')
-------------------------------------------------------------------------------------------------------------
local function IsToolOk( Tool, dMachiningDepth)
local bIsToolOk = false
local bToolExists = false
local dToolMaxDepth = 0
bToolExists = ( next( Tool) ~= nil)
if bToolExists then
if Tool.nType == MCH_TY.MILL_NOTIP then
dToolMaxDepth = Tool.dThickness
else
dToolMaxDepth = Tool.dMaxDepth
end
end
bIsToolOk = bToolExists and ( dToolMaxDepth > dMachiningDepth - 10 * GEO.EPS_SMALL)
return bIsToolOk
end
-------------------------------------------------------------------------------------------------------------
function Squaring.GetTools()
local Tool = {}
local SquaringTools = {}
SquaringTools.Blade = {}
SquaringTools.Diskmill = {}
SquaringTools.Mill = {}
SquaringTools.Blade.H1 = {}
SquaringTools.Blade.H2 = {}
SquaringTools.Blade.H7 = {}
SquaringTools.Diskmill.H1 = {}
SquaringTools.Diskmill.H7 = {}
SquaringTools.Mill.H1 = {}
SquaringTools.Mill.H7 = {}
Tool.sName = EgtTdbGetFirstTool( MCH_TF.SAWBLADE + MCH_TF.MILL + MCH_TF.MORTISE)
while Tool.sName ~= '' do
EgtTdbSetCurrTool( Tool.sName)
local bIsToolLoadedOnSetup = EgtFindToolInCurrSetup( Tool.sName)
local bIsSquaringTool = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'SQUARING', 'b') or false
Tool.nType = EgtTdbGetCurrToolParam( MCH_TP.TYPE)
Tool.dDiameter = EgtTdbGetCurrToolParam( MCH_TP.DIAM)
Tool.dThickness = EgtTdbGetCurrToolParam( MCH_TP.THICK)
Tool.dMaxMaterial = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT)
Tool.dMaxDepth = EgtTdbGetCurrToolMaxDepth() or Tool.dMaxMaterial
Tool.sHead = EgtTdbGetCurrToolParam( MCH_TP.HEAD)
Tool.bIsCcw = EgtTdbGetCurrToolParam( MCH_TP.SPEED) < 0
Tool.dFeed = EgtTdbGetCurrToolParam( MCH_TP.FEED)
Tool.dStartFeed = EgtTdbGetCurrToolParam( MCH_TP.STARTFEED)
Tool.dEndFeed = EgtTdbGetCurrToolParam( MCH_TP.ENDFEED)
Tool.dTipFeed = EgtTdbGetCurrToolParam( MCH_TP.TIPFEED)
Tool.dMinFeed = EgtTdbGetCurrToolParam( MCH_TP.MINFEED)
Tool.dSideStep = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'SIDESTEP', 'd') or ( Tool.dDiameter / 2)
if bIsToolLoadedOnSetup and Tool.nType and bIsSquaringTool then
-- lame
if Tool.nType == MCH_TY.SAW_FLAT or Tool.nType == MCH_TY.SAW_STD then
SquaringTools.Blade[Tool.sHead] = Tool
Tool.bIsPathCw = Tool.bIsCcw
-- frese standard
elseif Tool.nType == MCH_TY.MILL_STD then
SquaringTools.Mill[Tool.sHead] = Tool
Tool.bIsPathCw = not Tool.bIsCcw
-- truciolatori
elseif Tool.nType == MCH_TY.MILL_NOTIP then
SquaringTools.Diskmill[Tool.sHead] = Tool
Tool.bIsPathCw = Tool.bIsCcw
end
end
Tool = {}
Tool.sName = EgtTdbGetNextTool( MCH_TF.SAWBLADE + MCH_TF.MILL + MCH_TF.MORTISE)
end
return SquaringTools
end
-------------------------------------------------------------------------------------------------------------
function Squaring.AreToolsOk( sSquaringTool, SquaringTools, dMachiningDepth)
local bAreToolsOk = false
if sSquaringTool == 'DoubleDiskmill' then
bAreToolsOk = ( IsToolOk( SquaringTools.Blade.H2, dMachiningDepth)
and IsToolOk( SquaringTools.Diskmill.H1, WD.SQUARING_MAX_OVERMATERIAL)
and IsToolOk( SquaringTools.Diskmill.H7, WD.SQUARING_MAX_OVERMATERIAL))
elseif sSquaringTool == 'DoubleDiskmillAndBlade' then
bAreToolsOk = ( IsToolOk( SquaringTools.Blade.H2, dMachiningDepth)
and ( IsToolOk( SquaringTools.Diskmill.H1, WD.SQUARING_MAX_OVERMATERIAL) or IsToolOk( SquaringTools.Diskmill.H7, WD.SQUARING_MAX_OVERMATERIAL)))
elseif sSquaringTool == 'DoubleBlade' then
bAreToolsOk = ( IsToolOk( SquaringTools.Blade.H2, dMachiningDepth)
and ( IsToolOk( SquaringTools.Blade.H1, dMachiningDepth) or IsToolOk( SquaringTools.Blade.H7, dMachiningDepth)))
elseif sSquaringTool == 'Diskmill' then
bAreToolsOk = IsToolOk( SquaringTools.Diskmill.H1, WD.SQUARING_MAX_OVERMATERIAL) or IsToolOk( SquaringTools.Diskmill.H7, WD.SQUARING_MAX_OVERMATERIAL)
elseif sSquaringTool == 'Blade' then
bAreToolsOk = IsToolOk( SquaringTools.Blade.H2, dMachiningDepth)
elseif sSquaringTool == 'DoubleMill' then
bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dMachiningDepth) and IsToolOk( SquaringTools.Mill.H7, dMachiningDepth)
elseif sSquaringTool == 'Mill' then
bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dMachiningDepth) or IsToolOk( SquaringTools.Mill.H7, dMachiningDepth)
else
error( 'Squaring Tool not recognized')
end
return bAreToolsOk
end
-------------------------------------------------------------------------------------------------------------
function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart)
-- TODO gestire squadratura sulle dimensioni massime dei pezzi (shrinktoparts) invece che sul master panel
local SquaringGeometries = {}
local dDimX = RawPart.b3:getDimX()
local dDimY = RawPart.b3:getDimY()
local sOrigCorner = EgtGetInfo( RawPart.nId, 'ORIGCORNER')
local bShrinkToParts = ( WD.SQUARING_TYPE == 2)
local bSquaringStartsOnReference = type( WD.SQUARING_STARTS_ON_REFERENCE) == "boolean" and ( WD.SQUARING_STARTS_ON_REFERENCE == true)
local dOffsetXY = 0
local dExtendZ = 0
if type( WD.SQUARING_OFFSET_XY) == "number" then
dOffsetXY = WD.SQUARING_OFFSET_XY
end
if type( WD.SQUARING_EXTEND_Z) == "number" then
dExtendZ = WD.SQUARING_EXTEND_Z
end
local Front = { sSide = 'Front'}
local Right = { sSide = 'Right'}
local Back = { sSide = 'Back'}
local Left = { sSide = 'Left'}
local pt1 = RawPart.b3:getMin() + Point3d( -dOffsetXY, -dOffsetXY, -dExtendZ)
local pt2 = pt1 + Point3d( dDimX + 2 * dOffsetXY, 0, 0)
local pt3 = pt2 + Point3d( 0, dDimY + 2 * dOffsetXY,0 )
local pt4 = pt3 + Point3d( -dDimX - 2 * dOffsetXY, 0, 0)
Front.nId = EgtLine( RawPart.nId, pt1, pt2, GDB_RT.GLOB)
Right.nId = EgtLine( RawPart.nId, pt2, pt3, GDB_RT.GLOB)
Back.nId = EgtLine( RawPart.nId, pt3, pt4, GDB_RT.GLOB)
Left.nId = EgtLine( RawPart.nId, pt4, pt1, GDB_RT.GLOB)
if not ( sSquaringTool == 'DoubleMill') and not ( sSquaringTool == 'Mill') then
EgtModifyCurveExtrusion( Front.nId, -Y_AX(), GDB_RT.GLOB)
EgtModifyCurveExtrusion( Right.nId, X_AX(), GDB_RT.GLOB)
EgtModifyCurveExtrusion( Back.nId, Y_AX(), GDB_RT.GLOB)
EgtModifyCurveExtrusion( Left.nId, -X_AX(), GDB_RT.GLOB)
end
EgtSetName( Front.nId, 'SquaringGeometry')
EgtSetName( Right.nId, 'SquaringGeometry')
EgtSetName( Back.nId, 'SquaringGeometry')
EgtSetName( Left.nId, 'SquaringGeometry')
-- in base al caso si assegna l'utensile al lato
if sSquaringTool == 'DoubleDiskmill' then
Left.Tool = SquaringTools.Diskmill.H1
Right.Tool = SquaringTools.Blade.H2
Front.Tool = SquaringTools.Diskmill.H1
Front.ToolDouble = SquaringTools.Diskmill.H7
Front.sSide = 'Front+Back'
elseif sSquaringTool == 'DoubleDiskmillAndBlade' then
Left.Tool = SquaringTools.Diskmill.H1 or SquaringTools.Diskmill.H7
Right.Tool = SquaringTools.Blade.H2
Front.Tool = SquaringTools.Blade.H2
Front.ToolDouble = SquaringTools.Diskmill.H1 or SquaringTools.Diskmill.H7
Front.sSide = 'Front+Back'
elseif sSquaringTool == 'DoubleBlade' then
Left.Tool = SquaringTools.Blade.H2
Right.Tool = SquaringTools.Blade.H2
Front.Tool = SquaringTools.Blade.H2
Front.ToolDouble = SquaringTools.Blade.H1 or SquaringTools.Blade.H7
Front.sSide = 'Front+Back'
elseif sSquaringTool == 'Diskmill' then
Left.Tool = SquaringTools.Diskmill.H1 or SquaringTools.Diskmill.H7
Back.Tool = SquaringTools.Diskmill.H1 or SquaringTools.Diskmill.H7
Right.Tool = SquaringTools.Blade.H2
Front.Tool = SquaringTools.Diskmill.H1 or SquaringTools.Diskmill.H7
elseif sSquaringTool == 'Blade' then
Left.Tool = SquaringTools.Blade.H2
Back.Tool = SquaringTools.Blade.H2
Right.Tool = SquaringTools.Blade.H2
Front.Tool = SquaringTools.Blade.H2
elseif sSquaringTool == 'DoubleMill' then
Left.Tool = SquaringTools.Mill.H1
Right.Tool = SquaringTools.Mill.H1
Front.Tool = SquaringTools.Mill.H1
Front.ToolDouble = SquaringTools.Mill.H7
Front.sSide = 'Front+Back'
elseif sSquaringTool == 'Mill' then
Left.Tool = SquaringTools.Mill.H1 or SquaringTools.Mill.H7
Back.Tool = SquaringTools.Mill.H1 or SquaringTools.Mill.H7
Right.Tool = SquaringTools.Mill.H1 or SquaringTools.Mill.H7
Front.Tool = SquaringTools.Mill.H1 or SquaringTools.Mill.H7
end
-- l'ordinamento delle linee dipende dal verso di percorrenza e, se attivato, dal riferimento utilizzato
-- con doppio l'ordine cambia
-- lato lungo lavorato in doppio
if not Back.Tool then
for i = 1, 3 do
SquaringGeometries[i] = {}
end
if Front.Tool.bIsPathCw then
if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then
SquaringGeometries[1] = Front
SquaringGeometries[2] = Left
SquaringGeometries[3] = Right
elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then
SquaringGeometries[1] = Right
SquaringGeometries[2] = Front
SquaringGeometries[3] = Left
elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then
SquaringGeometries[1] = Right
SquaringGeometries[2] = Front
SquaringGeometries[3] = Left
elseif bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then
SquaringGeometries[1] = Left
SquaringGeometries[2] = Front
SquaringGeometries[3] = Right
else
SquaringGeometries[1] = Right
SquaringGeometries[2] = Front
SquaringGeometries[3] = Left
end
else
if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then
SquaringGeometries[1] = Left
SquaringGeometries[2] = Front
SquaringGeometries[3] = Right
elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then
SquaringGeometries[1] = Front
SquaringGeometries[2] = Right
SquaringGeometries[3] = Left
elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then
SquaringGeometries[1] = Front
SquaringGeometries[2] = Right
SquaringGeometries[3] = Left
elseif bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then
SquaringGeometries[1] = Left
SquaringGeometries[2] = Front
SquaringGeometries[3] = Right
else
SquaringGeometries[1] = Left
SquaringGeometries[2] = Front
SquaringGeometries[3] = Right
end
end
-- doppio non attivo
else
for i = 1, 4 do
SquaringGeometries[i] = {}
end
if Front.Tool.bIsPathCw then
if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then
SquaringGeometries[1] = Front
SquaringGeometries[2] = Left
SquaringGeometries[3] = Back
SquaringGeometries[4] = Right
elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then
SquaringGeometries[1] = Back
SquaringGeometries[2] = Right
SquaringGeometries[3] = Front
SquaringGeometries[4] = Left
elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then
SquaringGeometries[1] = Right
SquaringGeometries[2] = Front
SquaringGeometries[3] = Left
SquaringGeometries[4] = Back
else
SquaringGeometries[1] = Left
SquaringGeometries[2] = Back
SquaringGeometries[3] = Right
SquaringGeometries[4] = Front
end
else
if bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then
SquaringGeometries[1] = Back
SquaringGeometries[2] = Left
SquaringGeometries[3] = Front
SquaringGeometries[4] = Right
elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then
SquaringGeometries[1] = Right
SquaringGeometries[2] = Back
SquaringGeometries[3] = Left
SquaringGeometries[4] = Front
elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then
SquaringGeometries[1] = Front
SquaringGeometries[2] = Right
SquaringGeometries[3] = Back
SquaringGeometries[4] = Left
else
SquaringGeometries[1] = Left
SquaringGeometries[2] = Front
SquaringGeometries[3] = Right
SquaringGeometries[4] = Back
end
end
end
return SquaringGeometries
end
-------------------------------------------------------------------------------------------------------------
function Squaring.AddMachinings( SquaringGeometries, RawPart, nFirstOperationId)
local nNotOkCount = 0
local sMsgTotal = ''
local dRawPartWidth = RawPart.b3:getDimY()
local dRawPartHeight = RawPart.b3:getDimZ()
local dExtendPath = 0
local dMaxOvermaterial = 0
if type( WD.SQUARING_MAX_OVERMATERIAL) == "number" then
dMaxOvermaterial = WD.SQUARING_MAX_OVERMATERIAL
end
for i = 1, #SquaringGeometries do
local dToolRadius = SquaringGeometries[i].Tool.dDiameter / 2
local vtExtr = EgtCurveExtrusion( SquaringGeometries[i].nId, GDB_RT.GLOB)
local nOperationId = EgtCreateMachining( 'SQUARING_' .. SquaringGeometries[i].sSide, MCH_OY.MILLING, SquaringGeometries[i].Tool.sName)
-- geometria
EgtSetMachiningGeometry( SquaringGeometries[i].nId)
-- profondità di lavoro
EgtSetMachiningParam( MCH_MP.DEPTH_STR, 0)
-- workside e inversione
if SquaringGeometries[i].Tool.bIsPathCw then
if SquaringGeometries[i].Tool.nType == MCH_TY.MILL_STD then
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
else
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT)
end
EgtSetMachiningParam( MCH_MP.INVERT, true)
else
if SquaringGeometries[i].Tool.nType == MCH_TY.MILL_STD then
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT)
else
EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT)
end
EgtSetMachiningParam( MCH_MP.INVERT, false)
end
-- distanza di sicurezza
if AreSameVectorApprox( vtExtr, Z_AX()) then
EgtSetMachiningParam( MCH_MP.STARTPOS, WD.CUT_SIC + RawPart.b3:getDimZ())
else
EgtSetMachiningParam( MCH_MP.STARTPOS, WD.CUT_SIC)
end
-- overlap
EgtSetMachiningParam( MCH_MP.OVERL, 0)
-- tipo di step
EgtSetMachiningParam( MCH_MP.STEPTYPE, MCH_MILL_ST.ONEWAY)
-- step
EgtSetMachiningParam( MCH_MP.STEP, SquaringGeometries[i].Tool.dMaxMaterial)
-- offset radiale
EgtSetMachiningParam( MCH_MP.OFFSR, 0)
-- offset longitudinale
EgtSetMachiningParam( MCH_MP.OFFSL, 0)
-- inversione utensile
EgtSetMachiningParam( MCH_MP.TOOLINVERT, false)
-- faceuse
EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.NONE)
-- angoli suggeriti
EgtSetMachiningParam( MCH_MP.INITANGS, '')
-- asse bloccato
EgtSetMachiningParam( MCH_MP.BLOCKEDAXIS, '')
-- SCC
EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.NONE)
-- calcolo estensione percorso
if AreSameVectorApprox( vtExtr, Z_AX()) then
-- per utensili che lavorano di fianco, si deve partire fuori dall'altezza del grezzo
dExtendPath = dMaxOvermaterial + dToolRadius + WD.COLL_SIC
else
-- si calcola l'impronta utensile per uscire quanto basta a garantire il maxOvermaterial, con una distanza di sicurezza
dExtendPath = dMaxOvermaterial + WD.COLL_SIC + dToolRadius - ( dToolRadius - sqrt( dToolRadius * dToolRadius - ( ( dToolRadius - dRawPartHeight) * ( dToolRadius - dRawPartHeight))))
end
-- approccio
EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_MILL_LI.LINEAR)
EgtSetMachiningParam( MCH_MP.STARTADDLEN, dExtendPath)
EgtSetMachiningParam( MCH_MP.LITANG, 0)
if AreSameVectorApprox( vtExtr, Z_AX()) then
EgtSetMachiningParam( MCH_MP.LIPERP, 0)
else
-- per utensili che lavorano di fianco, si deve partire fuori dall'altezza del grezzo
EgtSetMachiningParam( MCH_MP.LIPERP, WD.CUT_SIC + RawPart.b3:getDimZ())
end
EgtSetMachiningParam( MCH_MP.LIELEV, 0)
EgtSetMachiningParam( MCH_MP.LICOMPLEN, 0)
-- retrazione
EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, MCH_MILL_LO.LINEAR)
EgtSetMachiningParam( MCH_MP.ENDADDLEN, dExtendPath)
EgtSetMachiningParam( MCH_MP.LOTANG, 0)
if AreSameVectorApprox( vtExtr, Z_AX()) then
EgtSetMachiningParam( MCH_MP.LOPERP, 0)
else
-- per utensili che lavorano di fianco, si deve partire fuori dall'altezza del grezzo
EgtSetMachiningParam( MCH_MP.LOPERP, WD.CUT_SIC + RawPart.b3:getDimZ())
end
EgtSetMachiningParam( MCH_MP.LOELEV, 0)
EgtSetMachiningParam( MCH_MP.LOCOMPLEN, 0)
-- note utente
local sUserNotes = ''
sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES)
if SquaringGeometries[i].ToolDouble then
sUserNotes = EgtSetValInNotes( sUserNotes, 'DOUBLE', 2)
sUserNotes = EgtSetValInNotes( sUserNotes, 'MirrorAx', dRawPartWidth / 2)
sUserNotes = EgtSetValInNotes( sUserNotes, 'TOOLDOUBLE', SquaringGeometries[i].ToolDouble.sName)
end
EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes)
local bOk = EgtApplyMachining( true, false)
EgtRelocateGlob( nOperationId, nFirstOperationId, GDB_IN.BEFORE)
if not bOk then
local _, sMsg = EgtGetLastMachMgrError()
nNotOkCount = nNotOkCount + 1
sMsgTotal = sMsgTotal ..'\n' .. ( sMsg or '')
end
end
return ( nNotOkCount < 1), sMsgTotal
end
-------------------------------------------------------------------------------------------------------------
function Squaring.AddScrapRemoval( nFirstOperationId)
-- pulizia sfridi alla prima lavorazione dopo la squadratura
EgtSetCurrMachining( nFirstOperationId)
local sMachiningNotes = EgtGetMachiningParam( MCH_MP.USERNOTES)
sMachiningNotes = sMachiningNotes .. 'ScrapRemove=1;'
EgtSetMachiningParam( MCH_MP.USERNOTES, sMachiningNotes)
end
-------------------------------------------------------------------------------------------------------------
return Squaring