-- ProcessProfFront.lua by Egaltech s.r.l. 2019/04/01 -- Gestione calcolo profilo caudato per Travi -- Tabella per definizione modulo local ProcessProfFront = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Cut = require( 'ProcessCut') EgtOutLog( ' ProcessProfFront started', 1) -- Dati local BD = require( 'BeamData') local Millings = require( 'MillingData') --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessProfFront.Identify( Proc) return (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 100) end --------------------------------------------------------------------- local function FindMilling( sType) for i = 1, #Millings do local Milling = Millings[i] if Milling.Type == sType then return i, Milling.Name end end return 0 end --------------------------------------------------------------------- local function GetSawCutData( AuxId, vtN) -- comincio con la normale a 45deg local vtNP = Vector3d( vtN) for i = 1, 3 do if vtNP[i] > GEO.EPS_SMALL then vtNP[i] = 1 elseif vtNP[i] < -GEO.EPS_SMALL then vtNP[i] = -1 end end vtNP:normalize() -- assegno un punto di passaggio local ptStart = EgtSP( AuxId, GDB_ID.ROOT) + vtNP * 5.0 -- determino asse di rotazione local vtRot = - Y_AX() if vtN:getX() < 0 then vtRot = - vtRot end if vtN:getZ() < -0.1 then vtRot = - vtRot elseif vtN:getY() < -0.1 then vtRot:rotate( X_AX(), 90) elseif vtN:getY() > 0.1 then vtRot:rotate( X_AX(), -90) end -- miglioro l'inclinazione (ripartendo da faccia perpendicolare asse trave) vtNP[2] = 0 vtNP[3] = 0 local dRot = 45 for i = 1, 4 do local vtNP2 = Vector3d( vtNP) vtNP2:rotate( vtRot, dRot) local frRef = Frame3d( ptStart, vtNP2) local b3Box = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frRef) if b3Box:getMax():getZ() < -3 then vtNP = Vector3d( vtNP2) end dRot = dRot / 2 end -- restituisco i dati del piano return ptStart, vtNP end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessProfFront.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) -- ingombro del grezzo local b3Raw = EgtGetRawPartBBox( nRawId) -- recupero e verifico l'entità curva local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or ( EgtGetType( AuxId) & GDB_FY.GEO_CURVE) == 0 then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dDepth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local nLastFacet = EgtSurfTmFacetCount( Proc.Id) - 1 -- ultima faccia local nRefFacet = nLastFacet - 1 -- penultima faccia -- determino la normale media local CvxHullId = EgtSurfTmConvexHullInBBox( EgtGetParent( Proc.Id), Proc.Id, b3Raw, GDB_ID.ROOT) local vtN = EgtSurfTmFacetNormVersor( CvxHullId, 0, GDB_ID.ROOT) EgtErase( CvxHullId) -- verifico se in testa o coda local bHead = ( vtN:getX() > 0) --EgtOutLog( 'vtN=' .. tostring( vtN)) -- verifico se profilo orientato verso l'alto (1), il basso (-1) o di fianco (0) local nSide = 0 if vtN:getZ() > 0.1 then nSide = 1 elseif vtN:getZ() < -0.1 then nSide = -1 end -- 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 -- aggiungo taglio di lama di sgrossatura e lo lavoro local ptStart, vtNP = GetSawCutData( AuxId, vtN) local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptStart, vtNP, b3Solid, GDB_RT.GLOB) if AddId then EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) -- applico la lavorazione local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg} local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, 0) if not bOk then return bOk, sErr end end -- recupero la lavorazione local nMill, sMilling = FindMilling( 'Prof') if not sMilling then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library' EgtOutLog( sErr) return false, sErr end -- inserisco la lavorazione local sName = 'Prof_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchId = EgtAddMachining( sName, sMilling) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- se lavorazione da sopra if nSide == 1 then -- se lavorazione a destra di fronte o sinistra da dietro, inverto if ( bHead and vtExtr:getY() < -0.1) or ( not bHead and vtExtr:getY() > 0.1) then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) EgtSetMachiningParam( MCH_MP.INVERT, true) end -- altrimenti lavorazione dal davanti o dal dietro else -- se fresa verso il basso, la porto verso l'alto if vtExtr:getZ() < 0 then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) EgtSetMachiningParam( MCH_MP.INVERT, true) end -- se lavorazione a destra da dietro o sinistra di fronte, inverto if ( bHead and vtExtr:getY() > 0.1) or ( not bHead and vtExtr:getY() < -0.1) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, true) end end -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr end -- se non da sotto, inserisco lavorazione finitura angolo if nSide ~= -1 then sName = 'ProfV_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchVId = EgtAddMachining( sName, sMilling) if not nMchVId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr end -- calcolo massima elevazione local _, _, _, _, _, _, dWidth = EgtSurfTmFacetOppositeSide( Proc.Id, 0, EgtIf( bHead, X_AX(), - X_AX()), GDB_ID.ROOT) -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, 0}}) -- aggiusto i parametri EgtSetMachiningParam( MCH_MP.INVERT, false) EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') EgtSetMachiningParam( MCH_MP.STEP, 0) EgtSetMachiningParam( MCH_MP.OFFSR, 0) EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dWidth, 1)) -- imposto tipo uso faccia local nFaceUse = MCH_MILL_FU.PARAL_DOWN if nSide ~= 1 then nFaceUse = EgtIf( vtN:getY() > 0.1, MCH_MILL_FU.PARAL_FRONT, MCH_MILL_FU.PARAL_BACK) end EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) -- imposto posizione braccio porta testa local nSCC = MCH_SCC.ADIR_YM if vtN:getY() > 100 * GEO.EPS_ZERO then nSCC = MCH_SCC.ADIR_YP end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchVId, false) return false, sErr end end -- aggiorno ingombro testa o coda per presa if nSide == 0 then if bHead then BL.UpdateHCING( nRawId, b3Raw:getMax():getX() - dCurrOvmH - Proc.Box:getMin():getX()) else BL.UpdateTCING( nRawId, Proc.Box:getMax():getX() - b3Raw:getMin():getX()) end end return true end --------------------------------------------------------------------- return ProcessProfFront