diff --git a/LuaLibs/Squaring.lua b/LuaLibs/Squaring.lua new file mode 100644 index 0000000..8caa5bb --- /dev/null +++ b/LuaLibs/Squaring.lua @@ -0,0 +1,491 @@ +-- 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 WM = require( 'WMachiningLib') + +------------------------------------------------------------------------------------------------------------- +local function IsToolOk( Tool, dRawPartHeight) + local bIsToolOk = false + local bToolExists = false + local bToolCanReachDepth = false + local dMaxOvermaterial = 0 + if type( WD.SQUARING_MAX_OVERMATERIAL) == "number" then + dMaxOvermaterial = WD.SQUARING_MAX_OVERMATERIAL + end + + bToolExists = ( next( Tool) ~= nil) + if bToolExists then + if Tool.nType == MCH_TY.MILL_NOTIP then + bToolCanReachDepth = ( Tool.dThickness > dMaxOvermaterial - 10 * GEO.EPS_SMALL) + and ( Tool.dSideDepth > dRawPartHeight - 10 * GEO.EPS_SMALL) + else + bToolCanReachDepth = Tool.dMaxDepth > dRawPartHeight - 10 * GEO.EPS_SMALL + end + end + bIsToolOk = bToolExists and bToolCanReachDepth + + return bIsToolOk +end + +------------------------------------------------------------------------------------------------------------- +function Squaring.GetTools() + -- TODO vedere se questo valore è coerente sulle diverse macchine + local dHeadEncumberance = 130 + + 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.dMaxMaterial = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) + Tool.dThickness = EgtIf( ( Tool.nType == MCH_TY.SAW_FLAT or Tool.nType == MCH_TY.SAW_STD), EgtTdbGetCurrToolParam( MCH_TP.THICK), Tool.dMaxMaterial) + 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.dStep = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'STEP', 'd') or EgtIf( ( Tool.nType == MCH_TY.SAW_FLAT or Tool.nType == MCH_TY.SAW_STD), ( Tool.dDiameter / 3), ( Tool.dMaxMaterial / 3)) + Tool.dSideStep = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'SIDESTEP', 'd') or ( Tool.dDiameter / 3) + Tool.dSideDepth = Tool.dDiameter / 2 - dHeadEncumberance + + 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 + Tool.dSideStep = Tool.dStep + Tool.dStep = Tool.dThickness + -- 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, dRawPartHeight) + local bAreToolsOk = false + + if sSquaringTool == 'DoubleDiskmill' then + bAreToolsOk = ( IsToolOk( SquaringTools.Blade.H2, dRawPartHeight) + and IsToolOk( SquaringTools.Diskmill.H1, dRawPartHeight) + and IsToolOk( SquaringTools.Diskmill.H7, dRawPartHeight)) + elseif sSquaringTool == 'DoubleDiskmillAndBlade' then + bAreToolsOk = ( IsToolOk( SquaringTools.Blade.H2, dRawPartHeight) + and ( IsToolOk( SquaringTools.Diskmill.H1, dRawPartHeight) or IsToolOk( SquaringTools.Diskmill.H7, dRawPartHeight))) + elseif sSquaringTool == 'DoubleBlade' then + bAreToolsOk = ( IsToolOk( SquaringTools.Blade.H2, dRawPartHeight) + and ( IsToolOk( SquaringTools.Blade.H1, dRawPartHeight) or IsToolOk( SquaringTools.Blade.H7, dRawPartHeight))) + elseif sSquaringTool == 'Diskmill' then + bAreToolsOk = IsToolOk( SquaringTools.Diskmill.H1, dRawPartHeight) or IsToolOk( SquaringTools.Diskmill.H7, dRawPartHeight) + elseif sSquaringTool == 'Blade' then + bAreToolsOk = IsToolOk( SquaringTools.Blade.H2, dRawPartHeight) + elseif sSquaringTool == 'DoubleMill' then + bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dRawPartHeight) and IsToolOk( SquaringTools.Mill.H7, dRawPartHeight) + elseif sSquaringTool == 'Mill' then + bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dRawPartHeight) or IsToolOk( SquaringTools.Mill.H7, dRawPartHeight) + else + error( 'Squaring Tool not recognized') + end + + return bAreToolsOk +end + +------------------------------------------------------------------------------------------------------------- +function Squaring.CalculateParameters( sSquaringTool, SquaringTools, RawPart, vPart) + local SquaringParameters = {} + 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" and ( WD.SQUARING_TYPE < 2) 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 b3Squaring = BBox3d( RawPart.b3) + -- se squadratura sui pezzi invece che sul master panel, si costruisce il box minimo che contiene tutti i pezzi + if bShrinkToParts then + b3Squaring = BBox3d( vPart[1].Box:getCenter()) + for i = 1, #vPart do + b3Squaring:Add( vPart[i].Box) + end + end + local dDimX = b3Squaring:getDimX() + local dDimY = b3Squaring:getDimY() + local pt1 = b3Squaring: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) + b3Squaring:Add( pt1) + b3Squaring:Add( pt2) + b3Squaring:Add( pt3) + b3Squaring:Add( pt4) + 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 + SquaringParameters[i] = {} + end + if Front.Tool.bIsPathCw then + if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then + SquaringParameters[1] = Front + SquaringParameters[2] = Left + SquaringParameters[3] = Right + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left + elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right + else + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left + end + else + if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then + SquaringParameters[1] = Front + SquaringParameters[2] = Right + SquaringParameters[3] = Left + elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then + SquaringParameters[1] = Front + SquaringParameters[2] = Right + SquaringParameters[3] = Left + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right + else + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right + end + end + -- doppio non attivo + else + for i = 1, 4 do + SquaringParameters[i] = {} + end + if Front.Tool.bIsPathCw then + if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then + SquaringParameters[1] = Front + SquaringParameters[2] = Left + SquaringParameters[3] = Back + SquaringParameters[4] = Right + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then + SquaringParameters[1] = Back + SquaringParameters[2] = Right + SquaringParameters[3] = Front + SquaringParameters[4] = Left + elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left + SquaringParameters[4] = Back + else + SquaringParameters[1] = Left + SquaringParameters[2] = Back + SquaringParameters[3] = Right + SquaringParameters[4] = Front + end + else + if bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then + SquaringParameters[1] = Back + SquaringParameters[2] = Left + SquaringParameters[3] = Front + SquaringParameters[4] = Right + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then + SquaringParameters[1] = Right + SquaringParameters[2] = Back + SquaringParameters[3] = Left + SquaringParameters[4] = Front + elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then + SquaringParameters[1] = Front + SquaringParameters[2] = Right + SquaringParameters[3] = Back + SquaringParameters[4] = Left + else + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right + SquaringParameters[4] = Back + end + end + end + + return SquaringParameters, b3Squaring +end + +------------------------------------------------------------------------------------------------------------- +function Squaring.AddMachinings( SquaringParameters, b3Squaring, nFirstOperationId) + local nNotOkCount = 0 + local sMsgTotal = '' + local dSquaringHeight = b3Squaring:getDimZ() + local dExtendPath = 0 + local dMaxOvermaterial = 0 + if type( WD.SQUARING_MAX_OVERMATERIAL) == "number" then + dMaxOvermaterial = WD.SQUARING_MAX_OVERMATERIAL + end + local bUseZigZagStep = ( type( WD.SQUARING_USE_ZIGZAG) == "boolean") and ( WD.SQUARING_USE_ZIGZAG == true) + + for i = 1, #SquaringParameters do + local dToolRadius = SquaringParameters[i].Tool.dDiameter / 2 + local vtExtr = EgtCurveExtrusion( SquaringParameters[i].nId, GDB_RT.GLOB) + local bIsVerticalMilling = false + if AreSameVectorApprox( vtExtr, Z_AX()) then + bIsVerticalMilling = true + end + -- calcolo step laterale + local MachiningSteps = { nCount = 1, dStep = 0} + if not bIsVerticalMilling then + MachiningSteps = WM.GetMachiningSteps( dSquaringHeight, SquaringParameters[i].Tool.dSideStep) + end + + for j = 1, MachiningSteps.nCount do + local nOperationId = EgtCreateMachining( 'SQUARING_' .. SquaringParameters[i].sSide, MCH_OY.MILLING, SquaringParameters[i].Tool.sName) + -- geometria + EgtSetMachiningGeometry( SquaringParameters[i].nId) + -- profondità di lavoro + EgtSetMachiningParam( MCH_MP.DEPTH_STR, 0) + -- workside e inversione + if SquaringParameters[i].Tool.bIsPathCw then + if SquaringParameters[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 SquaringParameters[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 bIsVerticalMilling then + EgtSetMachiningParam( MCH_MP.STARTPOS, WD.CUT_SIC + dSquaringHeight) + else + EgtSetMachiningParam( MCH_MP.STARTPOS, WD.CUT_SIC) + end + -- overlap + EgtSetMachiningParam( MCH_MP.OVERL, 0) + -- tipo di step + if bIsVerticalMilling and bUseZigZagStep then + EgtSetMachiningParam( MCH_MP.STEPTYPE, MCH_MILL_ST.ZIGZAG) + else + EgtSetMachiningParam( MCH_MP.STEPTYPE, MCH_MILL_ST.ONEWAY) + end + -- step + if bIsVerticalMilling then + EgtSetMachiningParam( MCH_MP.STEP, SquaringParameters[i].Tool.dStep) + else + EgtSetMachiningParam( MCH_MP.STEP, 0) + end + -- offset radiale + local dRadialOffset = 0 + if not bIsVerticalMilling then + dRadialOffset = ( MachiningSteps.nCount - j) * MachiningSteps.dStep + end + EgtSetMachiningParam( MCH_MP.OFFSR, dRadialOffset) + -- 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 bIsVerticalMilling 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 - dSquaringHeight) * ( dToolRadius - dSquaringHeight)))) + end + -- approccio + EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_MILL_LI.LINEAR) + EgtSetMachiningParam( MCH_MP.STARTADDLEN, dExtendPath) + EgtSetMachiningParam( MCH_MP.LITANG, 0) + if bIsVerticalMilling 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 + dSquaringHeight) + 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 bIsVerticalMilling 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 + dSquaringHeight) + end + EgtSetMachiningParam( MCH_MP.LOELEV, 0) + EgtSetMachiningParam( MCH_MP.LOCOMPLEN, 0) + -- note utente + local sUserNotes = '' + sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) + if SquaringParameters[i].ToolDouble then + local dYMirrorAx + local b3Tab = EgtGetTableArea() + dYMirrorAx = b3Squaring:getCenter():getY() - b3Tab:getMin():getY() + sUserNotes = EgtSetValInNotes( sUserNotes, 'DOUBLE', 2) + sUserNotes = EgtSetValInNotes( sUserNotes, 'MirrorAx', dYMirrorAx) + sUserNotes = EgtSetValInNotes( sUserNotes, 'TOOLDOUBLE', SquaringParameters[i].ToolDouble.sName) + end + if not bIsVerticalMilling then + sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', 0) + 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 + 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 \ No newline at end of file diff --git a/LuaLibs/WMachiningLib.lua b/LuaLibs/WMachiningLib.lua index d4cbf8d..d5ed5c5 100644 --- a/LuaLibs/WMachiningLib.lua +++ b/LuaLibs/WMachiningLib.lua @@ -266,5 +266,17 @@ function WMachiningLib.IsMachiningOkForDouble( sMachining) return bDoubleOk end +------------------------------------------------------------------------------------------------------------- +function WMachiningLib.GetMachiningSteps( dMachiningDepth, dStep) + local MachiningSteps = {} + MachiningSteps.dStep = 0 + MachiningSteps.nCount = ceil( ( dMachiningDepth - 10 * GEO.EPS_SMALL) / dStep) + if MachiningSteps.nCount > 1 then + MachiningSteps.dStep = ( dMachiningDepth - dStep) / ( MachiningSteps.nCount - 1) + end + + return MachiningSteps +end + ------------------------------------------------------------------------------------------------------------- return WMachiningLib diff --git a/LuaLibs/WProcessFreeContour.lua b/LuaLibs/WProcessFreeContour.lua index b03a6de..bebaf61 100644 --- a/LuaLibs/WProcessFreeContour.lua +++ b/LuaLibs/WProcessFreeContour.lua @@ -175,6 +175,22 @@ local function IsPointOnRawLongEdges( ptCen, b3Raw) return ( abs( ptCen:getY() - b3Raw:getMin():getY()) < 0.1 or abs( ptCen:getY() - b3Raw:getMax():getY()) < 0.1) end +--------------------------------------------------------------------- +local function IsFaceOutsideSquaring( Proc, Face, b3Squaring) + -- faccia esterna al box di squadratura + if b3Squaring then + local b3SquaringReduced = BBox3d( b3Squaring) + b3SquaringReduced:expand( -0.1) + local b3Face = EgtSurfTmGetFacetBBoxGlob( Proc.Id, Face.Fac, GDB_BB.STANDARD) + if not OverlapsXY( b3SquaringReduced, b3Face) then + EgtOutLog( 'Proc ' .. Proc.Id .. ': skipped face ' .. Face.Fac .. ' outside squaring' ) + return true + end + else + return false + end +end + --------------------------------------------------------------------- local function GetOtherRegions( nPartId) local vOthers = {} @@ -1705,13 +1721,13 @@ local function AddSawings( sSawing, vFace, Proc, nRawId, b3Raw) end --------------------------------------------------------------------- -local function AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick) +local function AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick, b3Squaring) -- verifico se ciclo chiuso local bClosed = ( abs( vFace[1].PrevAng) > 0.1) -- ciclo di inserimento dei tagli sulle facce del contorno in esame for i = 1, #vFace do - -- verifico se faccia da saltare, perchè macchina travi e faccia su bordo longitudinale esterno già finito - local bToSkip = ( WD.BEAM_MACHINE and IsPointOnRawLongEdges( vFace[i].Cen, b3Raw)) + -- verifico se faccia da saltare, perchè macchina travi e faccia su bordo longitudinale esterno già finito oppure se faccia fuori dal box di squadratura + local bToSkip = ( WD.BEAM_MACHINE and IsPointOnRawLongEdges( vFace[i].Cen, b3Raw)) or IsFaceOutsideSquaring( Proc, vFace[i], b3Squaring) -- se non è faccia da saltare, inserisco il taglio di lama if not bToSkip and vFace[i].Type ~= 4 then -- indice del successivo @@ -1841,7 +1857,7 @@ local function AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick) end --------------------------------------------------------------------- -local function MakeByCut( Proc, nRawId, b3Raw) +local function MakeByCut( Proc, nRawId, b3Raw, b3Squaring) local sWarn = '' -- ingombro del pezzo local Ls = EgtGetFirstNameInGroup( Proc.PartId, 'Box') @@ -1887,9 +1903,9 @@ local function MakeByCut( Proc, nRawId, b3Raw) -- gruppo ausiliario local nAddGrpId = WL.GetAddGroup( Proc.PartId) -- recupero i dati di tutte le facce - local vFace, dMaxWidth, nNewProc = GetFacesData( Proc, bOpposite, true, dSawDiam, dSawMaxDepth, dSawThick, nAddGrpId, b3Raw, nil) + local vFace, dMaxWidth, nNewProc = GetFacesData( Proc, bOpposite, true, dSawDiam, dSawMaxDepth, dSawThick, nAddGrpId, b3Raw) -- inserimento dei tagli di lama - local bCtOk, sCtErr = AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick) + local bCtOk, sCtErr = AddCuts( sCutting, vFace, Proc, nRawId, b3Raw, dSawThick, b3Squaring) if not bCtOk then return bCtOk, sCtErr end -- se richiesta solo lama, esco local nCntType = EgtGetInfo( Proc.Id, 'CNT_TYPE', 'i') or 0 @@ -2426,7 +2442,7 @@ local function MakeByPocket( Proc, nRawId, b3Raw) EgtErase( nAddedBottomSurface) end if not nFacet then - return MakeByMill( Proc, nRawId, b3Raw) + return MakeByMill( Proc, nRawId, b3Raw, b3Squaring) end -- se ho creato la faccia di fondo utilizzo quella local nSurfId = nProcTmWithAddedBottomSurfaceId or Proc.Id @@ -2573,7 +2589,7 @@ end --------------------------------------------------------------------- -- Applicazione della lavorazione -function WPF.Make( Proc, nRawId, b3Raw, vNLO) +function WPF.Make( Proc, nRawId, b3Raw, vNLO, b3Squaring) -- recupero la tipologia (contorno o tasca) local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- se svuotatura @@ -2596,7 +2612,7 @@ function WPF.Make( Proc, nRawId, b3Raw, vNLO) return MakeByNail( Proc, nRawId, b3Raw, vNLO) -- altrimenti, taglio con lama e pulizia angoli con fresa else - return MakeByCut( Proc, nRawId, b3Raw) + return MakeByCut( Proc, nRawId, b3Raw, b3Squaring) end end end diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index b8fdb51..ec2c812 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -45,6 +45,7 @@ _G.package.loaded.WProcessVariant = nil local WM = require( 'WMachiningLib') local WL = require( 'WallLib') local Topology = require( 'WFeatureTopology') +local Squaring = require( 'Squaring') local Cut = require( 'WProcessCut') local DoubleCut = require( 'WProcessDoubleCut') local SawCut = require( 'WProcessSawCut') @@ -57,7 +58,6 @@ local Text = require( 'WProcessText') local FreeContour = require( 'WProcessFreeContour') local Variant = require( 'WProcessVariant') - ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle pareti nel pannello *** ------------------------------------------------------------------------------------------------------------- @@ -132,6 +132,7 @@ function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall, bMachGroupOk, bNewPr nRaw = EgtAddRawPart( Point3d( 0, 0, 0), dRawL, dRawW, dRawH, WD.RAWCOL) end EgtMoveToCornerRawPart( nRaw, OrigOnTab, nCorner) + EgtSetInfo( nRaw, 'ORIGCORNER', sOrigCorner) EgtSetInfo( nRaw, 'ORD', 1) -- Inserimento dei pezzi nel grezzo for i = 1, #vWall do @@ -177,7 +178,7 @@ end ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle lavorazioni nelle pareti *** ------------------------------------------------------------------------------------------------------------- -function WallExec.CollectFeatures( PartId, b3Raw) +function WallExec.CollectFeatures( PartId, b3Raw, b3Squaring) -- recupero le feature local vProc = {} local LayerId = {} @@ -226,6 +227,14 @@ function WallExec.CollectFeatures( PartId, b3Raw) end if Proc.Box and not Proc.Box:isEmpty() then table.insert( vProc, Proc) + -- se squadratura sui pezzi, si annullano le lavorazioni esterne al box di squadratura + if b3Squaring then + local b3SquaringReduced = BBox3d( b3Squaring) + b3SquaringReduced:expand( -0.1) + if not OverlapsXY( Proc.Box, b3SquaringReduced) then + Proc.Flag = 0 + end + end -- se foro if Drill.Identify( Proc) then -- assegno diametro e facce di ingresso e uscita (dati tabelle sempre per riferimento) @@ -351,7 +360,7 @@ local function PrintFeatures( vProc) end ------------------------------------------------------------------------------------------------------------- -local function AddFeatureMachining( Proc, nRawId, b3Raw, vNLO) +local function AddFeatureMachining( Proc, nRawId, b3Raw, vNLO, b3Squaring) local bOk = true local sErr = '' EgtOutLog( ' * Process ' .. tostring( Proc.Id) .. ' *', 1) @@ -394,7 +403,7 @@ local function AddFeatureMachining( Proc, nRawId, b3Raw, vNLO) -- se contorno libero, outline o apertura ( 0/3/4-250/251/252-X) elseif FreeContour.Identify( Proc) then -- esecuzione contorno libero - bOk, sErr = FreeContour.Make( Proc, nRawId, b3Raw, vNLO) + bOk, sErr = FreeContour.Make( Proc, nRawId, b3Raw, vNLO, b3Squaring) -- se feature custom (Variant) elseif Variant.Identify( Proc) then -- esecuzione @@ -1077,6 +1086,52 @@ local function SetMirroredOperations() end end +------------------------------------------------------------------------------------------------------------- +local function CalculateSquaring( sSquaringTool, RawPart, vPart) + local dRawPartHeight = RawPart.b3:getDimZ() + local bOk + local sMsg = '' + local SquaringTools = {} + local SquaringParameters = {} + local b3Squaring + + SquaringTools = Squaring.GetTools() + bOk = Squaring.AreToolsOk( sSquaringTool, SquaringTools, dRawPartHeight) + if not bOk then + sMsg = 'Squaring failed: cannot find matching tools' + return false, {}, nil, sMsg + end + + SquaringParameters, b3Squaring = Squaring.CalculateParameters( sSquaringTool, SquaringTools, RawPart, vPart) + if not SquaringParameters or next( SquaringParameters) == nil then + sMsg = 'Squaring failed: cannot calculate parameters' + return false, {}, nil, sMsg + end + + return true, SquaringParameters, b3Squaring, sMsg +end + +------------------------------------------------------------------------------------------------------------- +local function AddSquaring( SquaringParameters, b3Squaring) + local nFirstOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( 1)) + local bOk + local sMsg = '' + local OperationsId = {} + + bOk, sMsg, OperationsId = Squaring.AddMachinings( SquaringParameters, b3Squaring, nFirstOperationId) + if not bOk then + for i = 1, #OperationsId do + EgtRemoveOperation( i) + end + sMsg = 'Squaring failed: cannot apply machinings' + return false, sMsg + end + + Squaring.AddScrapRemoval( nFirstOperationId) + + return true, sMsg +end + ------------------------------------------------------------------------------------------------------------- function WallExec.ProcessFeatures() -- errori e stato @@ -1094,11 +1149,57 @@ function WallExec.ProcessFeatures() table.insert( vPart, {Id=nPartId, Box=b3Solid}) nPartId = EgtGetNextPartInRawPart( nPartId) end + + -- calcolo i parametri della squadratura, se richiesta + local SquaringParameters = {} + local b3Squaring + if WD.SQUARING_TYPE and WD.SQUARING_TYPE > 0 then + local RawPart = { nId = nRawId, b3 = b3Raw} + local bOk, sMsg + if type( WD.SQUARING_TOOL) ~= "number" then + WD.SQUARING_TOOL = 0 + end + + if WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 1 then + bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'DoubleDiskmill', RawPart, vPart) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 2) then + -- 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' + --SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'DoubleDiskmillAndBlade', RawPart) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 3) then + bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'DoubleBlade', RawPart, vPart) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 4) then + bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'Diskmill', RawPart, vPart) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 5) then + bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'Blade', RawPart, vPart) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 6) then + bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'DoubleMill', RawPart, vPart) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 7) then + bOk, SquaringParameters, b3Squaring, sMsg = CalculateSquaring( 'Mill', RawPart, vPart) + end + + if not bOk 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 + end + -- raccolgo l'elenco delle feature da lavorare, ciclando sui pezzi local vProc = {} for i = 1, #vPart do -- recupero le feature di lavorazione della parete - local vPartProc = WallExec.CollectFeatures( vPart[i].Id, b3Raw) + local vPartProc = WallExec.CollectFeatures( vPart[i].Id, b3Raw, b3Squaring) vProc = EgtJoinTables( vProc, vPartProc) end -- classifico topologicamente le feature @@ -1125,7 +1226,7 @@ function WallExec.ProcessFeatures() -- creo la lavorazione local Proc = vProc[i] if Proc.Flg ~= 0 then - local bOk, sMsg = AddFeatureMachining( Proc, nRawId, b3Raw, vNLO) + 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}) @@ -1225,7 +1326,19 @@ function WallExec.ProcessFeatures() end -- ordinamento standard SortMachinings( nPhase, PrevMch) + -- squadratura, se richiesta + if SquaringParameters and next( SquaringParameters) ~= nil then + local bOk, sMsg = AddSquaring( SquaringParameters, b3Squaring) + if not bOk 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 + end -- Aggiornamento finale di tutto if nGetPriorityFromBtl > 0 then InsertScrapRemoval( nPhase)