diff --git a/LuaLibs/Squaring.lua b/LuaLibs/Squaring.lua index cd0d3e9..7d0225d 100644 --- a/LuaLibs/Squaring.lua +++ b/LuaLibs/Squaring.lua @@ -14,26 +14,34 @@ local WD = require( 'WallData') local WM = require( 'WMachiningLib') ------------------------------------------------------------------------------------------------------------- -local function IsToolOk( Tool, dMachiningDepth) +local function IsToolOk( Tool, dRawPartHeight) local bIsToolOk = false local bToolExists = false - local dToolMaxDepth = 0 + 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 - dToolMaxDepth = Tool.dThickness + bToolCanReachDepth = ( Tool.dThickness > dMaxOvermaterial - 10 * GEO.EPS_SMALL) + and ( Tool.dSideDepth > dRawPartHeight - 10 * GEO.EPS_SMALL) else - dToolMaxDepth = Tool.dMaxDepth + bToolCanReachDepth = Tool.dMaxDepth > dRawPartHeight - 10 * GEO.EPS_SMALL end end - bIsToolOk = bToolExists and ( dToolMaxDepth > dMachiningDepth - 10 * GEO.EPS_SMALL) + 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 = {} @@ -67,12 +75,15 @@ function Squaring.GetTools() Tool.dMinFeed = EgtTdbGetCurrToolParam( MCH_TP.MINFEED) Tool.dStep = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'STEP', 'd') or ( Tool.dMaxMaterial / 3) Tool.dSideStep = EgtTdbGetCurrToolValInNotes( MCH_TP.USERNOTES, 'SIDESTEP', 'd') or ( Tool.dDiameter / 6) + 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 @@ -92,27 +103,27 @@ function Squaring.GetTools() end ------------------------------------------------------------------------------------------------------------- -function Squaring.AreToolsOk( sSquaringTool, SquaringTools, dMachiningDepth) +function Squaring.AreToolsOk( sSquaringTool, SquaringTools, dRawPartHeight) 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)) + 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, dMachiningDepth) - and ( IsToolOk( SquaringTools.Diskmill.H1, WD.SQUARING_MAX_OVERMATERIAL) or IsToolOk( SquaringTools.Diskmill.H7, WD.SQUARING_MAX_OVERMATERIAL))) + 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, dMachiningDepth) - and ( IsToolOk( SquaringTools.Blade.H1, dMachiningDepth) or IsToolOk( SquaringTools.Blade.H7, dMachiningDepth))) + 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, WD.SQUARING_MAX_OVERMATERIAL) or IsToolOk( SquaringTools.Diskmill.H7, WD.SQUARING_MAX_OVERMATERIAL) + bAreToolsOk = IsToolOk( SquaringTools.Diskmill.H1, dRawPartHeight) or IsToolOk( SquaringTools.Diskmill.H7, dRawPartHeight) elseif sSquaringTool == 'Blade' then - bAreToolsOk = IsToolOk( SquaringTools.Blade.H2, dMachiningDepth) + bAreToolsOk = IsToolOk( SquaringTools.Blade.H2, dRawPartHeight) elseif sSquaringTool == 'DoubleMill' then - bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dMachiningDepth) and IsToolOk( SquaringTools.Mill.H7, dMachiningDepth) + bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dRawPartHeight) and IsToolOk( SquaringTools.Mill.H7, dRawPartHeight) elseif sSquaringTool == 'Mill' then - bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dMachiningDepth) or IsToolOk( SquaringTools.Mill.H7, dMachiningDepth) + bAreToolsOk = IsToolOk( SquaringTools.Mill.H1, dRawPartHeight) or IsToolOk( SquaringTools.Mill.H7, dRawPartHeight) else error( 'Squaring Tool not recognized') end @@ -121,15 +132,14 @@ function Squaring.AreToolsOk( sSquaringTool, SquaringTools, dMachiningDepth) end ------------------------------------------------------------------------------------------------------------- -function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart, vPart) - -- TODO gestire squadratura sulle dimensioni massime dei pezzi (shrinktoparts) invece che sul master panel - local SquaringGeometries = {} +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" then + 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 @@ -141,8 +151,9 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart, vPart) 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( RawPart.b3:getCenter()) + b3Squaring = BBox3d( vPart[1].Box:getCenter()) for i = 1, #vPart do b3Squaring:Add( vPart[i].Box) end @@ -153,6 +164,10 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart, vPart) 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) @@ -215,110 +230,110 @@ function Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart, vPart) -- lato lungo lavorato in doppio if not Back.Tool then for i = 1, 3 do - SquaringGeometries[i] = {} + SquaringParameters[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 + SquaringParameters[1] = Front + SquaringParameters[2] = Left + SquaringParameters[3] = Right elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then - SquaringGeometries[1] = Right - SquaringGeometries[2] = Front - SquaringGeometries[3] = Left + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then - SquaringGeometries[1] = Right - SquaringGeometries[2] = Front - SquaringGeometries[3] = Left + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left elseif bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then - SquaringGeometries[1] = Left - SquaringGeometries[2] = Front - SquaringGeometries[3] = Right + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right else - SquaringGeometries[1] = Right - SquaringGeometries[2] = Front - SquaringGeometries[3] = Left + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left end else if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then - SquaringGeometries[1] = Left - SquaringGeometries[2] = Front - SquaringGeometries[3] = Right + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then - SquaringGeometries[1] = Front - SquaringGeometries[2] = Right - SquaringGeometries[3] = Left + SquaringParameters[1] = Front + SquaringParameters[2] = Right + SquaringParameters[3] = Left elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then - SquaringGeometries[1] = Front - SquaringGeometries[2] = Right - SquaringGeometries[3] = Left + SquaringParameters[1] = Front + SquaringParameters[2] = Right + SquaringParameters[3] = Left elseif bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then - SquaringGeometries[1] = Left - SquaringGeometries[2] = Front - SquaringGeometries[3] = Right + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right else - SquaringGeometries[1] = Left - SquaringGeometries[2] = Front - SquaringGeometries[3] = Right + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right end end -- doppio non attivo else for i = 1, 4 do - SquaringGeometries[i] = {} + SquaringParameters[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 + SquaringParameters[1] = Front + SquaringParameters[2] = Left + SquaringParameters[3] = Back + SquaringParameters[4] = Right elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then - SquaringGeometries[1] = Back - SquaringGeometries[2] = Right - SquaringGeometries[3] = Front - SquaringGeometries[4] = Left + SquaringParameters[1] = Back + SquaringParameters[2] = Right + SquaringParameters[3] = Front + SquaringParameters[4] = Left elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then - SquaringGeometries[1] = Right - SquaringGeometries[2] = Front - SquaringGeometries[3] = Left - SquaringGeometries[4] = Back + SquaringParameters[1] = Right + SquaringParameters[2] = Front + SquaringParameters[3] = Left + SquaringParameters[4] = Back else - SquaringGeometries[1] = Left - SquaringGeometries[2] = Back - SquaringGeometries[3] = Right - SquaringGeometries[4] = Front + SquaringParameters[1] = Left + SquaringParameters[2] = Back + SquaringParameters[3] = Right + SquaringParameters[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 + SquaringParameters[1] = Back + SquaringParameters[2] = Left + SquaringParameters[3] = Front + SquaringParameters[4] = Right elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then - SquaringGeometries[1] = Right - SquaringGeometries[2] = Back - SquaringGeometries[3] = Left - SquaringGeometries[4] = Front + SquaringParameters[1] = Right + SquaringParameters[2] = Back + SquaringParameters[3] = Left + SquaringParameters[4] = Front elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then - SquaringGeometries[1] = Front - SquaringGeometries[2] = Right - SquaringGeometries[3] = Back - SquaringGeometries[4] = Left + SquaringParameters[1] = Front + SquaringParameters[2] = Right + SquaringParameters[3] = Back + SquaringParameters[4] = Left else - SquaringGeometries[1] = Left - SquaringGeometries[2] = Front - SquaringGeometries[3] = Right - SquaringGeometries[4] = Back + SquaringParameters[1] = Left + SquaringParameters[2] = Front + SquaringParameters[3] = Right + SquaringParameters[4] = Back end end end - return SquaringGeometries, b3Squaring + return SquaringParameters, b3Squaring end ------------------------------------------------------------------------------------------------------------- -function Squaring.AddMachinings( SquaringGeometries, b3Squaring, nFirstOperationId) +function Squaring.AddMachinings( SquaringParameters, b3Squaring, nFirstOperationId) local nNotOkCount = 0 local sMsgTotal = '' local dSquaringHeight = b3Squaring:getDimZ() @@ -329,9 +344,9 @@ function Squaring.AddMachinings( SquaringGeometries, b3Squaring, nFirstOperation end local bUseZigZagStep = ( type( WD.SQUARING_USE_ZIGZAG) == "boolean") and ( WD.SQUARING_USE_ZIGZAG == true) - for i = 1, #SquaringGeometries do - local dToolRadius = SquaringGeometries[i].Tool.dDiameter / 2 - local vtExtr = EgtCurveExtrusion( SquaringGeometries[i].nId, GDB_RT.GLOB) + 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 @@ -339,25 +354,25 @@ function Squaring.AddMachinings( SquaringGeometries, b3Squaring, nFirstOperation -- calcolo step laterale local MachiningSteps = { nCount = 1, dStep = 0} if not bIsVerticalMilling then - MachiningSteps = WM.GetMachiningSteps( dSquaringHeight, SquaringGeometries[i].Tool.dSideStep) + MachiningSteps = WM.GetMachiningSteps( dSquaringHeight, SquaringParameters[i].Tool.dSideStep) end for j = 1, MachiningSteps.nCount do - local nOperationId = EgtCreateMachining( 'SQUARING_' .. SquaringGeometries[i].sSide, MCH_OY.MILLING, SquaringGeometries[i].Tool.sName) + local nOperationId = EgtCreateMachining( 'SQUARING_' .. SquaringParameters[i].sSide, MCH_OY.MILLING, SquaringParameters[i].Tool.sName) -- geometria - EgtSetMachiningGeometry( SquaringGeometries[i].nId) + EgtSetMachiningGeometry( SquaringParameters[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 + 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 SquaringGeometries[i].Tool.nType == MCH_TY.MILL_STD then + 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) @@ -379,7 +394,11 @@ function Squaring.AddMachinings( SquaringGeometries, b3Squaring, nFirstOperation EgtSetMachiningParam( MCH_MP.STEPTYPE, MCH_MILL_ST.ONEWAY) end -- step - EgtSetMachiningParam( MCH_MP.STEP, SquaringGeometries[i].Tool.dStep) + 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 @@ -433,13 +452,16 @@ function Squaring.AddMachinings( SquaringGeometries, b3Squaring, nFirstOperation -- note utente local sUserNotes = '' sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) - if SquaringGeometries[i].ToolDouble then + 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', SquaringGeometries[i].ToolDouble.sName) + sUserNotes = EgtSetValInNotes( sUserNotes, 'TOOLDOUBLE', SquaringParameters[i].ToolDouble.sName) + end + if not bIsVerticalMilling then + sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', 0) end EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) 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 2e2e458..ec2c812 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -178,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 = {} @@ -227,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) @@ -352,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) @@ -395,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 @@ -1079,25 +1087,38 @@ local function SetMirroredOperations() end ------------------------------------------------------------------------------------------------------------- -local function AddSquaring( sSquaringTool, RawPart, vPart) - local nFirstOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( 1)) - local dMachiningDepth = RawPart.b3:getDimZ() +local function CalculateSquaring( sSquaringTool, RawPart, vPart) + local dRawPartHeight = RawPart.b3:getDimZ() local bOk local sMsg = '' local SquaringTools = {} - local Geometry = {} - local OperationsId = {} + local SquaringParameters = {} + local b3Squaring SquaringTools = Squaring.GetTools() - bOk = Squaring.AreToolsOk( sSquaringTool, SquaringTools, dMachiningDepth) + bOk = Squaring.AreToolsOk( sSquaringTool, SquaringTools, dRawPartHeight) if not bOk then sMsg = 'Squaring failed: cannot find matching tools' - return false, sMsg + return false, {}, nil, sMsg end - local SquaringGeometries, b3Squaring = Squaring.CreateGeometry( sSquaringTool, SquaringTools, RawPart, vPart) + 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 - bOk, sMsg, OperationsId = Squaring.AddMachinings( SquaringGeometries, b3Squaring, nFirstOperationId) + 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) @@ -1108,10 +1129,6 @@ local function AddSquaring( sSquaringTool, RawPart, vPart) Squaring.AddScrapRemoval( nFirstOperationId) - if WD.SQUARING_TYPE == 2 then - Squaring.RemoveExternalMachinings( Geometry) - end - return true, sMsg end @@ -1132,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 @@ -1163,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}) @@ -1263,39 +1326,9 @@ function WallExec.ProcessFeatures() end -- ordinamento standard SortMachinings( nPhase, PrevMch) - -- squadratura, se richiesta - 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, sMsg = AddSquaring( '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' - --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, vPart) - end - if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 4) then - bOk, sMsg = AddSquaring( 'Diskmill', RawPart, vPart) - end - if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 5) then - bOk, sMsg = AddSquaring( 'Blade', RawPart, vPart) - end - if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 6) then - bOk, sMsg = AddSquaring( 'DoubleMill', RawPart, vPart) - end - if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 7) then - bOk, sMsg = AddSquaring( 'Mill', RawPart, vPart) - end + if SquaringParameters and next( SquaringParameters) ~= nil then + local bOk, sMsg = AddSquaring( SquaringParameters, b3Squaring) if not bOk then nTotErr = nTotErr + 1 @@ -1306,7 +1339,6 @@ function WallExec.ProcessFeatures() table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=0, TaskId=0}) end end - -- Aggiornamento finale di tutto if nGetPriorityFromBtl > 0 then InsertScrapRemoval( nPhase)