-- ProcessMortise.lua by Egaltech s.r.l. 2020/11/08 -- Gestione calcolo mortase per Travi -- Tabella per definizione modulo local ProcessMortise = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Cut = require( 'ProcessCut') EgtOutLog( ' ProcessMortise started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessMortise.Identify( Proc) return ( (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 50) or (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 51) or (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 53)) end --------------------------------------------------------------------- -- Riconoscimento della sola feature frontale function ProcessMortise.FrontIdentify( Proc) return (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 51) end --------------------------------------------------------------------- -- Classificazione della feature: decide se la feature è in una posizione che per lavorala -- deve essere ribaltata o no function ProcessMortise.Classify( Proc) -- recupero e verifico il percorso supplementare local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if AuxId then AuxId = AuxId + Proc.Id end -- recupero versore estrusione della curva supplementare e non più della superficie -- perché quest'ultima potrebbe non avere il fondo e dare quindi un risultato non corretto local vtExtr = EgtCurveExtrusion( AuxId or GDB_ID.NULL, GDB_ID.ROOT) -- recupero i dati della faccia di fondo local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) -- verifico sia una superficie if not vtExtr then return false end if not vtN then return false end local bDown -- Confronto le direzioni Z dei 2 versori : se diverse la faccia 0 non è il fondo => mortasa passante if abs( vtExtr:getZ() - vtN:getZ()) > GEO.EPS_SMALL then bDown = false -- altrimenti è chiusa else -- verifico se la mortasa è lavorabile solo da sotto bDown = ( vtN:getZ() < - 0.1) end return true, bDown end --------------------------------------------------------------------- -- Piano di taglio della feature function ProcessMortise.GetCutPlane( Proc) if ProcessMortise.FrontIdentify( Proc) then return EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) else return nil, nil end end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessMortise.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) -- ingombro del pezzo local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then local sErr = 'Error : part box not found' EgtOutLog( sErr) return false, sErr end -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') local bForceOneSide local bRevertSide if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error : missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero versore estrusione della curva supplementare local vtExtr = EgtCurveExtrusion( AuxId, GDB_ID.ROOT) -- Se curva di contorno aperta if not EgtCurveIsClosed( AuxId) then local NewId, nCount = EgtExtractSurfTmFacetLoops( Proc.Id, 0, EgtGetParent( Proc.Id)) if NewId then -- elimino eventuali loop interni (non dovrebbero comunque esserci) for i = 1, nCount - 1 do EgtErase( NewId + i) end -- sostituisco il loop esterno alla curva originale EgtModifyCurveExtrusion( NewId, vtExtr, GDB_ID.ROOT) EgtRelocate( NewId, AuxId, GDB_IN.AFTER) EgtErase( AuxId) EgtChangeId( NewId, AuxId) -- sistemo i lati aperti local vFacAdj = EgtSurfTmFacetAdjacencies( Proc.Id, 0)[1] if vFacAdj then local sOpen = '' for i = 1, #vFacAdj do if vFacAdj[i] < 0 then sOpen = sOpen .. EgtIf( #sOpen > 0, ',', '') .. tostring( i - 1) end end if #sOpen > 0 then EgtSetInfo( AuxId, 'OPEN', sOpen) end end end end -- verifico se frontale local bFront = ( Proc.Prc == 51) -- recupero i dati della faccia di fondo local frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( Proc.Id, 0, GDB_ID.ROOT) local ptC = ORIG() local vtN = V_NULL() if frMor then ptC = frMor:getOrigin() vtN = frMor:getVersZ() end -- Confronto le direzioni dei 2 versori : se diverse la faccia 0 non è il fondo => mortasa passante local bOpenBtm = not AreSameVectorApprox( vtExtr, vtN) if bOpenBtm then -- creo superficie chiusa local nFlat = EgtSurfTmByFlatContour( EgtGetParent( AuxId), AuxId, 0.05) if nFlat then frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( nFlat, 0, GDB_ID.ROOT) ptC = frMor:getOrigin() vtN = frMor:getVersZ() -- verifico se copiare la geometria lungo l'asse Z local b3Aux = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frMor) local bxMax = b3Aux:getMax() local b3Mor = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frMor) local bxMin = b3Mor:getMin() local dMove = bxMin:getZ()-bxMax:getZ() -- se il percorso ausiliario è esterno al grezzo, lo riavvicino if abs( dMove) > GEO.EPS_SMALL then AuxId = EgtCopyGlob( AuxId, BL.GetAddGroup(nPartId)) EgtMove( AuxId, Vector3d(0,0,-dMove)) EgtMove( nFlat, Vector3d(0,0,-dMove)) frMor, dL, dW = EgtSurfTmFacetMinAreaRectangle( nFlat, 0, GDB_ID.ROOT) ptC = frMor:getOrigin() vtN = frMor:getVersZ() end -- cancello le prove del misfatto (superficie piana) EgtErase( nFlat) end end -- scrivo info nel log EgtOutLog( 'ptC=' .. tostring( ptC) ..' vtN=' .. tostring( vtN), 3) -- Se mortasa chiusa if not bOpenBtm then -- verifico che la mortasa non sia orientata verso il basso (limite -5 deg) if vtN:getZ() < -0.1 and not BD.DOWN_HEAD then local sErr = 'Error : Mortise from bottom impossible' EgtOutLog( sErr) return false, sErr end -- altrimenti passante else -- determino se la mortasa da lavorare sul lato opposto sia di angolo inferiore a quello consentito if abs( vtN:getZ()) > 0.1 then bForceOneSide = true end -- determino se è meglio lavorare la mortasa nel lato opposto if vtN:getZ() < -GEO.EPS_SMALL then bRevertSide = true end end -- se mortasa di fronte, eseguo il taglio della faccia if bFront then -- verifico esista la faccia di taglio local ptCutC, vtCutN = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) if ptCutC and vtCutN and AreSameVectorApprox( vtExtr, vtCutN) then -- recupero gruppo per geometria addizionale local nAddGrpId = BL.GetAddGroup( nPartId) if not nAddGrpId then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing AddGroup' EgtOutLog( sErr) return false, sErr end local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptCutC, vtCutN, b3Solid, GDB_RT.GLOB) local b3Cut = EgtGetBBoxGlob( AddId or GDB_ID.NULL, GDB_BB.STANDARD) local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = b3Cut, Fct = 1, Flg = Proc.Flg, Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId} local bFromBottom = ( b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getZ() > 0.25) local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dCurrOvmH, bFromBottom) if not bOk then return bOk, sErr end end end -- determino altezza della mortasa local b3Mor = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frMor) local dMorH = b3Mor:getDimZ() -- elevazione del punto centro if not bFront then local _, dCenElev = BL.GetPointDirDepth( nPartId, ptC, vtN) dMorH = max( dMorH, dCenElev or 0) end -- determino larghezza della mortasa if dL < dW then dL, dW = dW, dL end -- recupero la lavorazione local sMchExt = EgtIf( BD.DOWN_HEAD and vtN:getZ() < 0.1, '_H2', '') local sPocketing if Proc.Prc ~= 53 then sPocketing = ML.FindPocketing( 'Mortise'..sMchExt, dW) end if not sPocketing then sPocketing = ML.FindPocketing( 'Pocket'..sMchExt, dW) end if not sPocketing then local sErr = 'Error : Mortise or Pocket not found in library' EgtOutLog( sErr) return false, sErr end -- recupero i dati dell'utensile local dMillDiam = 20 local dMaxDepth = 0 local bCW = true if EgtMdbSetCurrMachining( sPocketing) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam dMaxDepth = ( EgtTdbGetCurrToolMaxDepth() or dMaxDepth) local dSpeed = EgtMdbGetCurrMachiningParam( MCH_MP.SPEED) or 0 bCW = ( dSpeed >= 0) end end -- inserisco la lavorazione di svuotatura local sName = 'Mort_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchFId = EgtAddMachining( sName, sPocketing) if not nMchFId then local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing EgtOutLog( sErr) return false, sErr end -- verifico se invertire versore estrusione geometria if bRevertSide then EgtModifyCurveExtrusion( AuxId, -vtExtr, GDB_ID.ROOT) end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- sistemo la direzione di lavoro EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false)) -- imposto posizione braccio porta testa if vtN:getY() < GEO.EPS_SMALL then if bRevertSide then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) else EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) end else if bRevertSide then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) else EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) end end local sWarn local nDepthMin -- se la mortasa è passante e non è forzata a un solo lato, riduco l'affondamento a metà profondità if bOpenBtm and not bForceOneSide then dMorH = dMorH * 0.5 end -- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente if dMorH > dMaxDepth + 10 * GEO.EPS_SMALL then sWarn = 'Warning in mortise : elevation (' .. EgtNumToString( dMorH,1) .. ') bigger than max tool depth (' .. EgtNumToString( dMaxDepth,1) .. ')' -- se non ho invertito la direzione di estrusione if not bRevertSide then nDepthMin = dMaxDepth - EgtIf( bOpenBtm and not bForceOneSide, dMorH * 2, dMorH) else nDepthMin = dMaxDepth end EgtSetMachiningParam( MCH_MP.DEPTH, nDepthMin) dMorH = dMaxDepth EgtOutLog( sWarn .. ' (process ' .. tostring( Proc.Id) .. ')') else if bOpenBtm and not bForceOneSide then -- se mortasa passante setto metà profondità nDepthMin = -dMorH EgtSetMachiningParam( MCH_MP.DEPTH, nDepthMin) end end -- imposto elevazione EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dMorH, 1) .. ';') -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end -- Se non c'è il fondo e la lavorazione non ha lavorato tutta la superficie per limite altezza utensile -- inserisco una ulteriore lavorazione contraria if bOpenBtm and not bForceOneSide and nDepthMin and abs(nDepthMin) > 0 then -- inserisco la lavorazione di svuotatura opposta sName = 'Mort_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_Oppo' nMchFId = EgtAddMachining( sName, sPocketing) if not nMchFId then local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing EgtOutLog( sErr) return false, sErr end -- faccio la copia e la metto nel layer dedicato alle geometrie aggiunte local AuxId_oppo = EgtCopyGlob( AuxId, BL.GetAddGroup(nPartId)) -- inverto la direzione estrusione di questa EgtModifyCurveExtrusion( AuxId_oppo, - vtExtr, GDB_ID.ROOT) -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId_oppo, -1}}) -- sistemo la direzione di lavoro EgtSetMachiningParam( MCH_MP.INVERT, EgtIf( bCW, true, false)) -- imposto posizione braccio porta testa if vtN:getY() < GEO.EPS_SMALL then EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) else EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) end -- se altezza mortasa differente da altezza massima lavorabile if abs( dMorH - dMaxDepth) > GEO.EPS_SMALL then nDepthMin = -dMorH else -- se sono uguali setto nDepthMin = -( dMorH - BD.CUT_EXTRA) end -- setto profondità EgtSetMachiningParam( MCH_MP.DEPTH, -nDepthMin+BD.CUT_EXTRA) -- imposto elevazione EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( (-nDepthMin+BD.CUT_EXTRA), 1) .. ';') -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchFId, false) return false, sErr end end return true, sWarn end --------------------------------------------------------------------- return ProcessMortise