-- ProcessDoubleCut.lua by Egaltech s.r.l. 2022/07/11 -- Gestione calcolo doppi tagli di lama per Travi -- Tabella per definizione modulo local ProcessDoubleCut = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Fbs = require( 'FacesBySaw') local DC = require( 'DiceCut') local Cut = require( 'ProcessCut') EgtOutLog( ' ProcessDoubleCut started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessDoubleCut.Identify( Proc) return ( ( Proc.Grp == 1 or Proc.Grp == 2) and Proc.Prc == 11) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessDoubleCut.Classify( Proc, b3Raw) --se una faccia, uso la classificazione dei tagli singoli if Proc.Fct == 1 then return Cut.Classify( Proc, b3Raw) end -- se PF con testa da sotto o TURN, ammessa qualunque orientazione if ( BD.C_SIMM and BD.DOWN_HEAD) or BD.TURN then return true end -- determino se convesso o concavo local bAdj, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) local bConvex = ( not bAdj or ( dAng > 0)) -- se convesso if bConvex then -- recupero i dati di ogni singola faccia for i = 1, 2 do local nFac = i - 1 local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFac, GDB_ID.ROOT) if ( vtN:getZ() <= - 0.5 and abs( vtN:getY()) > 0.1) or ( vtN:getZ() <= - 0.174 and abs( vtN:getY()) > 0.866) then -- calcolo la massima estensione orizzontale lineare della faccia local _, DimH, DimV = BL.GetFaceHvRefDim( Proc.Id, nFac, b3Raw) -- confronto questa estensione con la massima dimensione del DiceCut (impossibile lavorare se maggiore) if DimH > BD.MAX_DIM_DICE and DimV > BD.MAX_DIM_DICE then return true, true end end local dNzLimDwnUp = BL.GetNzLimDownUp( b3Raw, vtN) local bDownCut = ( vtN:getZ() <= dNzLimDwnUp) if bDownCut then -- calcolo l'ingombro orizzontale della faccia local _, DimH, DimV = BL.GetFaceHvRefDim( Proc.Id, nFac) -- confronto questo ingombro con il doppio della massima dimensione del DiceCut (impossibile lavorare sotto da sopra se più di 2 tagli) if DimH > 2 * BD.MAX_DIM_DICE then return true, true end end end return true, false -- altrimenti concavo, verifico le normali delle facce per tagli da sotto else local ptC = {} local vtN = {} ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) local vtX = vtN[1] ^ vtN[2] ; vtX:normalize() local vtY = { vtX ^ vtN[1], - vtX ^ vtN[2]} for i = 1, 2 do local dNzLimDwnUp = BL.GetNzLimDownUp( b3Raw, vtN[i], vtY[i]) local bDownCut = ( vtN[i]:getZ() <= dNzLimDwnUp) if bDownCut then -- dimensione della faccia perpendicolarmente alla linea di intersezione tra le facce local frRef = Frame3d( ptC[i], ptC[i] + 100 * vtX, ptC[i] + 100 * vtY[i]) local b3Ref = EgtSurfTmGetFacetBBoxRef( Proc.Id, i-1, GDB_BB.STANDARD, frRef) -- dimensione dell'altra faccia perpendicolarmente alla linea di intersezione tra le facce local frRef2 = Frame3d( ptC[3-i], ptC[3-i] + 100 * vtX, ptC[3-i] + 100 * vtY[3-1]) local b3Ref2 = EgtSurfTmGetFacetBBoxRef( Proc.Id, 2-i, GDB_BB.STANDARD, frRef2) -- se faccia grande if b3Ref:getDimY() > BD.MAX_DIM_DICE then -- se altra faccia piccola if b3Ref2:getDimY() < BD.MAX_DIM_DICE then return true, true else return false end end end end return true, false end end --------------------------------------------------------------------- -- lavorazione smussi local function MakeChamfer( Proc, nPhase, nRawId, nPartId, dOvmHead) -- verifico che lo smusso sia richiesto local dDepth = EgtGetInfo( Proc.Id, 'Q06', 'd') or 0 if dDepth < 0.1 then return true end -- ingombro del grezzo local b3Raw = EgtGetRawPartBBox( nRawId) -- recupero e verifico l'entità curva associata local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if AuxId then AuxId = AuxId + Proc.Id end if not AuxId then return true end if ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error : missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dWidth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) -- eseguo lo smusso solo se direzione orizzontale o anche testa da sotto (non propago la segnalazione a TS3) local bVert = ( abs( vtExtr:getZ()) > 0.1) if bVert and not BD.DOWN_HEAD then local sWarn = 'Warning : skipped not horizontal chamfer' EgtOutLog( sWarn) return true end -- eseguo lo smusso solo se feature larga come la trave if ( not bVert and dWidth < b3Raw:getDimY() - 1) or ( bVert and dWidth < b3Raw:getDimZ() - 1) then local sWarn = 'Warning : skipped chamfer (feature smaller than beam)' EgtOutLog( sWarn) return true, sWarn end local dExtra = 2 -- recupero la lavorazione local sMilling = ML.FindMilling( 'Mark') if not sMilling then local sErr = 'Error : milling (Mark) not found in library' EgtOutLog( sErr) return false, sErr end local sMillingDw = ML.FindMilling( 'Mark_H2', nil, nil, nil, nil, false, true) if bVert and not sMillingDw then local sErr = 'Error : milling (Mark_H2) not found in library' EgtOutLog( sErr) return false, sErr end -- Inserisco la lavorazione del lato standard local sName1 = 'SJN_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMch1Id = EgtAddMachining( sName1, EgtIf( not bVert or vtExtr:getZ() > 0.1, sMilling, sMillingDw)) if not nMch1Id then local sErr = 'Error adding machining ' .. sName1 .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- assegno affondamento e offset radiale EgtSetMachiningParam( MCH_MP.DEPTH, dDepth + dExtra) EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) -- assegno lato di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end -- Inserisco la lavorazione del lato opposto local sName2 = 'SJN_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMch2Id = EgtAddMachining( sName2, EgtIf( not bVert or vtExtr:getZ() < -0.1, sMilling, sMillingDw)) if not nMch2Id then local sErr = 'Error adding machining ' .. sName2 .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- inverto direzione utensile EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) -- assegno affondamento e offset radiale EgtSetMachiningParam( MCH_MP.DEPTH, dDepth + dExtra) EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) -- assegno lato di lavoro EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end return true end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessDoubleCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- se singola faccia, passo a quella lavorazione if Proc.Fct == 1 then return Cut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, nil, nil, bForced, b3Raw, sNotes, dOvmTail, true) end -- ingombro del grezzo local b3Raw = EgtGetRawPartBBox( nRawId) -- ingombro del pezzo local Ls = EgtGetFirstNameInGroup( nPartId, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then local sErr = 'Error : part box not found' EgtOutLog( sErr) return false, sErr end -- dati delle facce local ptC = {} local vtN = {} ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) -- normale media per capire se taglio di testa o di coda local vtNm = ( vtN[1] + vtN[2]) ; vtNm:normalize() local bHead = ( vtNm:getX() > 0) -- angolo diedro per stabilire se taglio convesso local bAdj, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) local bConvex = true local bOnY = true local ptPs = ( ptC[1] + ptC[2]) / 2 if bAdj then local vtDir = ptP1 - ptP2 ; vtDir:normalize() bOnY = abs( vtDir:getZ()) > 0.5 and ( abs( vtDir:getZ()) + abs( vtDir:getX()) > abs( vtDir:getY())) ptPs = ( ptP1 + ptP2) / 2 bConvex = ( dAng > 0) end -- determino quale faccia è più grande local _, dB1, dH1 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0) local _, dB2, dH2 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 1) local nBigInd = EgtIf( dB1 * dH1 >= dB2 * dH2, 1, 2) local nSmaInd = 3 - nBigInd -- inserimento smussi local bOkc, sErrC = MakeChamfer( Proc, nPhase, nRawId, nPartId, dOvmHead) if not bOkc then return bOkc, sErrC end -- recupero gruppo per geometria addizionale local nAddGrpId = BL.GetAddGroup( nPartId) if not nAddGrpId then local sErr = 'Error : missing AddGroup' EgtOutLog( sErr) return false, sErr end -- se convesso, lo tratto come due tagli singoli if bConvex then -- lavoro per prima la faccia più diretta in alto local vOrd = { 1, 2} if vtN[2]:getZ() > vtN[1]:getZ() then vOrd = { 2, 1} end -- creo piano di taglio coincidente con la prima faccia e lo lavoro local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vOrd[1]], vtN[vOrd[1]], b3Solid, GDB_RT.GLOB) if AddId then EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) EgtSetInfo( AddId, 'TASKID', Proc.TaskId) local b3Add = EgtGetBBoxGlob( AddId, GDB_BB.STANDARD) -- applico lavorazione local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = b3Add, Fct = 1, Flg = Proc.Flg, Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId} local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dOvmHead, nil, nil, bForced, b3Raw, sNotes, dOvmTail, true) if not bOk then return bOk, sErr end end -- creo piano di taglio coincidente con la seconda faccia e lo lavoro AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vOrd[2]], vtN[vOrd[2]], b3Solid, GDB_RT.GLOB) if AddId then EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) EgtSetInfo( AddId, 'TASKID', Proc.TaskId) local b3Add = EgtGetBBoxGlob( AddId, GDB_BB.STANDARD) -- applico lavorazione local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = b3Add, Fct = 1, Flg = Proc.Flg, Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId} local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dOvmHead, nil, nil, bForced, b3Raw, sNotes, dOvmTail, true) if not bOk then return bOk, sErr end end -- altrimenti concavo else -- eseguo local sCutType = EgtIf( bHead, 'HeadSide', 'TailSide') local bDownHead = ( BD.DOWN_HEAD and vtNm:getZ() < BD.NZ_MINB) local bOk, sErr = Fbs.MakeTwo( Proc, nPhase, nRawId, nPartId, dOvmHead, sCutType, false, bDownHead) if not bOk then return bOk, sErr end -- segnalazione ingombro di testa o coda if Proc.Head then -- intersezioni con linee a metà altezza appena dentro dal davanti e dal dietro local ptRef = b3Raw:getCenter() - 0.5 * b3Raw:getDimX() * X_AX() local ptL1 = ptRef - ( 0.5 * b3Raw:getDimY() - 0.1) * Y_AX() local ptL2 = ptRef + ( 0.5 * b3Raw:getDimY() - 0.1) * Y_AX() local bInt1, IntTy1, IntPar1 = EgtLineSurfTmInters( ptL1, X_AX(), Proc.Id, GDB_ID.ROOT) local bInt2, IntTy2, IntPar2 = EgtLineSurfTmInters( ptL2, X_AX(), Proc.Id, GDB_ID.ROOT) local dMinPar = b3Raw:getDimX() if IntPar1 and #IntPar1 > 0 then dMinPar = min( dMinPar, IntPar1[1]) end if IntPar2 and #IntPar2 > 0 then dMinPar = min( dMinPar, IntPar2[1]) end local dOffs = b3Raw:getDimX() - dMinPar BL.UpdateHCING( nRawId, dOffs) elseif Proc.Tail then -- accetto approssimazione più grezza local dOffs = Proc.Box:getMax():getX() - b3Solid:getMin():getX() if vtNm:getZ() > 0.5 then dOffs = 0.4 * dOffs elseif abs( vtNm:getZ()) > 0.35 then dOffs = 0.75 * dOffs end BL.UpdateTCING( nRawId, dOffs) end end return true end --------------------------------------------------------------------- return ProcessDoubleCut