diff --git a/LuaLibs/Squaring.lua b/LuaLibs/Squaring.lua index 142f11c..3115537 100644 --- a/LuaLibs/Squaring.lua +++ b/LuaLibs/Squaring.lua @@ -18,7 +18,7 @@ local function IsToolOk( Tool, dMachiningDepth) local bToolExists = false local dToolMaxDepth = 0 - bToolExists = Tool ~= {} + bToolExists = ( next( Tool) ~= nil) if bToolExists then if Tool.nType == MCH_TY.MILL_NOTIP then dToolMaxDepth = Tool.dThickness @@ -49,10 +49,11 @@ function Squaring.GetTools() Tool.sName = EgtTdbGetFirstTool( MCH_TF.SAWBLADE + MCH_TF.MILL + MCH_TF.MORTISE) while Tool.sName ~= '' do EgtTdbSetCurrTool( Tool.sName) - local bToolLoadedOnSetup = EgtFindToolInCurrSetup( 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 @@ -63,20 +64,21 @@ function Squaring.GetTools() 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 bToolLoadedOnSetup and Tool.nType and bIsSquaringTool then + 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 = not Tool.bIsCcw + Tool.bIsPathCw = Tool.bIsCcw -- frese standard elseif Tool.nType == MCH_TY.MILL_STD then SquaringTools.Mill[Tool.sHead] = Tool - Tool.bIsPathCw = Tool.bIsCcw + Tool.bIsPathCw = not Tool.bIsCcw -- truciolatori elseif Tool.nType == MCH_TY.MILL_NOTIP then SquaringTools.Diskmill[Tool.sHead] = Tool - Tool.bIsPathCw = not Tool.bIsCcw + Tool.bIsPathCw = Tool.bIsCcw end end @@ -135,10 +137,10 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) dExtendZ = WD.SQUARING_EXTEND_Z end - local Front = { Side = 'Front'} - local Right = { Side = 'Right'} - local Back = { Side = 'Back'} - local Left = { Side = 'Left'} + 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 ) @@ -147,10 +149,12 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) 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) - 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) + 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') @@ -162,16 +166,19 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) 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 @@ -187,6 +194,7 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) 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 @@ -302,67 +310,129 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) end ------------------------------------------------------------------------------------------------------------- -function Squaring.AddMachinings( MachiningGeometries) +function Squaring.AddMachinings( SquaringGeometries, RawPart, nFirstOperationId) local nNotOkCount = 0 local sMsgTotal = '' - - for i = 1, #MachiningGeometries do - local nOperationId = EgtCreateMachining( 'SQUARING', MCH_AT.LINEAR, MACHININGS[i].Machining.sToolName) + 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 - - - -- for i = 1, #SquaringGeometries do - -- local nSquaringOperationId = EgtAddMachining('SQUARING', Machining.sSquaring) - -- EgtSetMachiningGeometry( SquaringGeometries[i].nId) - -- -- in base al verso di percorrenza modifico i parametri significativi di lavorazione - -- if Machining.bIsPathCw then - -- if Machining.sType == 'Sawing'then - -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_SAW_WS.LEFT) - -- EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.LEFT) - -- elseif Machining.sType == 'Milling' then - -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - -- elseif Machining.sType == 'Diskmilling' then - -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) - -- end - -- EgtSetMachiningParam( MCH_MP.INVERT, true) - -- else - -- if Machining.sType == 'Sawing' then - -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_SAW_WS.RIGHT) - -- EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.RIGHT) - -- elseif Machining.sType == 'Milling' then - -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) - -- elseif Machining.sType == 'Diskmilling' then - -- EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - -- end - -- EgtSetMachiningParam( MCH_MP.INVERT, false) - -- end - -- local bOk = EgtApplyMachining( true, false) - -- EgtRelocateGlob( nSquaringOperationId, nFirstOperationId, GDB_IN.BEFORE) - -- if not bOk then - -- local _, sMsg = EgtGetLastMachMgrError() - -- nNotOkCount = nNotOkCount + 1 - -- sMsgTotal = sMsgTotal ..'\n' .. ( sMsg or '') - -- end - -- 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 ------------------------------------------------------------------------------------------------------------- diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index a62335b..81c9750 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -1080,6 +1080,7 @@ end ------------------------------------------------------------------------------------------------------------- local function AddSquaring( sSquaringTool, RawPart) + local nFirstOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( 1)) local dMachiningDepth = RawPart.b3:getDimZ() local bOk local sMsg = '' @@ -1094,9 +1095,9 @@ local function AddSquaring( sSquaringTool, RawPart) return false, sMsg end - MachiningGeometries = Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) + SquaringGeometries = Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart) - bOk, sMsg, OperationsId = Squaring.AddMachinings( MachiningGeometries) + bOk, sMsg, OperationsId = Squaring.AddMachinings( SquaringGeometries, RawPart, nFirstOperationId) if not bOk then for i = 1, #OperationsId do EgtRemoveOperation( i) @@ -1105,7 +1106,7 @@ local function AddSquaring( sSquaringTool, RawPart) return false, sMsg end - Squaring.AddScrapRemoval() + Squaring.AddScrapRemoval( nFirstOperationId) if WD.SQUARING_TYPE == 2 then Squaring.RemoveExternalMachinings( Geometry) @@ -1272,7 +1273,10 @@ function WallExec.ProcessFeatures() bOk, sMsg = AddSquaring( 'DoubleDiskmill', RawPart) end if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 2) then - bOk, sMsg = AddSquaring( 'DoubleDiskmillAndBlade', RawPart) + -- attualmente non gestito, va modificata la configurazione macchina e non si sa se sia gestito in macchina (PLC) + bOk = false + sMsg = 'Squaring not possible : double blade + diskmill not supported' + --bOk, sMsg = AddSquaring( 'DoubleDiskmillAndBlade', RawPart) end if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 3) then bOk, sMsg = AddSquaring( 'DoubleBlade', RawPart) @@ -1298,43 +1302,6 @@ function WallExec.ProcessFeatures() else table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=0, TaskId=0}) end - - - - - - - local nFirstOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( nPhase)) - local dDepth = b3Raw:getDimZ() - - -- ricerca lavorazione - local Machining = Squaring.GetMachining( dDepth) - if Machining.sSquaring then - -- creazione percorsi - local RawPart = { nId = nRawId, b3 = b3Raw} - local SquaringGeometries = Squaring.CreateGeometry( RawPart, Machining) - - -- applicazione lavorazioni - local bIsApplyOk, sMsg = Squaring.AddMachinings( Machining, SquaringGeometries, nFirstOperationId) - if not bIsApplyOk then - nTotErr = nTotErr + 1 - table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=0, TaskId=0}) - elseif sMsg and #sMsg > 0 then - table.insert( Stats, {Err=-1, Msg=sMsg, Rot=0, CutId=0, TaskId=0}) - else - table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=0, TaskId=0}) - end - - -- 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) - else - local sErr = 'Error : Squaring not found in library' - EgtOutLog( sErr) - table.insert( Stats, {Err=1, Msg=sErr, Rot=0, CutId=0, TaskId=0}) - end end -- Aggiornamento finale di tutto