-- ProcessProfConvex.lua by Egaltech s.r.l. 2023/07/31 -- Gestione calcolo profilo convesso per Travi -- 2021/05/03 Aggiunta gestione smusso da sopra e sotto per macchina con testa da sotto. -- 2021/06/28 Per macchine con testa sotto, smussi di lato con questa testa se non c'è lav.ne da sopra. -- 2022/02/02 Aggiunta funzione OnlyChamfer. -- 2022/05/24 Aggiunta fresatura da sotto su macchine con testa da sotto. -- 2022/05/28 Aggiunto calcolo svuotatura da modulo di libreria. -- 2023/05/25 Sistemazione SCC per TURN. -- 2023/07/31 Correzione e semplificazione di ModifySideInvertLead per invert. -- 2023/11/30 Calcolo elevazione velocizzato e centralizzato tramite la funzione GetFaceElevation. -- Tabella per definizione modulo local ProcessProfConvex = {} -- Include require( 'EgtBase') local BL = require( 'BeamLib') local Fbp = require( 'FaceByPocket') local Cut = require( 'ProcessCut') EgtOutLog( ' ProcessProfConvex started', 1) -- Dati local BD = require( 'BeamData') local ML = require( 'MachiningLib') -- variabili assegnazione parametri Q local sEnableExtraMillUpperFace = 'Q05' -- i local sEnableExtraBladeUpperFace = '' -- i local sDepthChamferMill = 'Q02' -- d local sOverMaterialForFinish = 'Q04' -- d local sPreemptiveChamfer = 'Q01' -- i local sMachFacesUnderneath = 'Q99' -- i --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessProfConvex.Identify( Proc) return (( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 102) end --------------------------------------------------------------------- -- Classificazione della feature function ProcessProfConvex.Classify( Proc, b3Raw) -- recupero la curva associata local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') AuxId = EgtIf( AuxId, AuxId + Proc.Id, GDB_ID.NULL) local vtN = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) if not vtN then return false end -- se profilo orizzontale if abs( vtN:getZ()) < 0.5 then return true, false, false -- altrimenti è profilo verticale che interessa tutta la sezione else -- recupero la massima capacità di lavoro dell'utensile da utilizzare local sMilling, dMaxDepth = ML.FindMilling( 'Prof') if not sMilling then dMaxDepth = 0 end if Proc.Box:getDimZ() > dMaxDepth and BD.ROT90 then return true, false, true else return true, false, false end end end --------------------------------------------------------------------- -- Verifico se richiesto il solo smusso function ProcessProfConvex.OnlyChamfer( Proc) return (( EgtGetInfo( Proc.Id, sDepthChamferMill, 'd') or 0) > 0.1 and EgtGetInfo( Proc.Id, sPreemptiveChamfer, 'i') == 1) 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 = EgtMP( AuxId, GDB_ID.ROOT) local frOCS = Frame3d( ptStart, vtNP) ; local b3Box = EgtGetBBoxRef( AuxId, GDB_BB.STANDARD, frOCS) ptStart = ptStart + vtNP * ( b3Box:getMax():getZ() + 10.0) -- restituisco i dati del piano return ptStart, vtNP end --------------------------------------------------------------------- local function ModifySideInvertLead( Proc, bHead, dToolDiam, dLenIni, dLenLst, bFirstTrim, bLastTrim, dOffsetPar) -- confronto il punto iniziale e finale della lavorazione con il box della feature -- e se è vicino alla parte esterna della trave inverto la lavorazione local ptSP = EgtGetMachiningStartPoint() local ptEp = EgtGetMachiningEndPoint() local nMachMode = EgtGetMachiningParam( MCH_MP.STEPTYPE) if nMachMode == 1 and ptSP and ptEp then -- recupero flag inversione direzione di lavorazione local bInvertMode = EgtGetMachiningParam( MCH_MP.INVERT) -- verifico se da aggiustare if abs( EgtIf( bHead, Proc.Box:getMax():getX(), Proc.Box:getMin():getX()) - ptSP:getX()) < abs( EgtIf( bHead, Proc.Box:getMax():getX(), Proc.Box:getMin():getX()) - ptEp:getX()) then -- ottengo il lato lavoro e lo inverto local nSideWork = EgtGetMachiningParam( MCH_MP.WORKSIDE) if nSideWork > 0 then EgtSetMachiningParam( MCH_MP.WORKSIDE, EgtIf( nSideWork == MCH_MILL_WS.LEFT, MCH_MILL_WS.RIGHT, MCH_MILL_WS.LEFT)) end -- imposto il contrario dell'inversione trovata bInvertMode = not bInvertMode EgtSetMachiningParam( MCH_MP.INVERT, bInvertMode) end -- se lavorazione invertita rispetto a geometria, scambio dati di inizio e fine if bInvertMode then dLenIni, dLenLst = dLenLst, dLenIni bFirstTrim, bLastTrim = bLastTrim, bFirstTrim end -- modifico attacco e uscita if dLenIni and dLenLst then -- se entità agli estremi sono inferiori del raggio utensile ed è abilitata la ripresa della faccia, -- allungo attacco e/o uscita local dStartAddLen = 0 if bFirstTrim and dLenIni < dToolDiam / 2 + ( 20 * GEO.EPS_SMALL) then dStartAddLen = dToolDiam / 2 - dLenIni + dOffsetPar + 1 end local dEndAddLen = 0 if bLastTrim and dLenLst < dToolDiam / 2 + ( 20 * GEO.EPS_SMALL) then dEndAddLen = dToolDiam / 2 - dLenLst + dOffsetPar + 1 end EgtSetMachiningParam( MCH_MP.STARTADDLEN, dStartAddLen) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dEndAddLen) end -- riapplico la lavorazione ML.ApplyMachining( true, false) end end --------------------------------------------------------------------- local function VerifyCham( Proc, AuxId, nRawId, bMakeVertCham, sDephtCham, sOnlyCham) local nChamfer = 0 -- ingombro del grezzo local b3Raw = EgtGetRawPartBBox( nRawId) -- verifico che lo smusso sia richiesto local dDepth = EgtGetInfo( Proc.Id, sDephtCham, 'd') or 0 if dDepth > 0.1 then nChamfer = 1 end -- verifico se posso fare solo lo smusso if EgtGetInfo( Proc.Id, sOnlyCham, 'i') == 1 then if nChamfer == 1 then nChamfer = nChamfer + 1 -- altrimenti se non ho l'affondamento esco else local sErr = 'Error : no chamfer depth' EgtOutLog( sErr) return -1, dDepth, sErr end 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 e il flag di lavorazione verticale è disabilitato if abs( vtExtr:getZ()) > 0.1 then if not bMakeVertCham then if nChamfer == 2 then -- se devo fare solo smusso, genero errore local sErr = 'Error : not horizontale chamfer' EgtOutLog( sErr) return -1, dDepth, sErr else local sWarn = 'Warning : skipped not horizontale chamfer' EgtOutLog( sWarn) return 0, dDepth end end end -- recupero la lavorazione local sMilling, sMilling2 if nChamfer > 0 then sMilling = ML.FindMilling( 'Mark') if not sMilling then if BD.DOWN_HEAD and abs( vtExtr:getZ()) < 0.1 then sMilling = ML.FindMilling( 'Mark_H2', nil, nil, nil, nil, false, true) end if not sMilling then local sErr = 'Error : chamfer not found in library' EgtOutLog( sErr) return -1, 0, sErr end end if BD.DOWN_HEAD and abs( vtExtr:getZ()) > 0.9 then sMilling2 = ML.FindMilling( 'Mark_H2', nil, nil, nil, nil, false, true) if not sMilling2 then local sErr = 'Error : chamfer2 not found in library' EgtOutLog( sErr) return -1, 0, sErr end end end return nChamfer, dDepth, sMilling, sMilling2 end --------------------------------------------------------------------- function GetSccForTurn( vtN, sType) local nSCC if abs( vtN:getZ()) > abs( vtN:getY()) then if sType == 'V' then nSCC = EgtIf( vtN:getZ() > 0, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_ZM) else nSCC = EgtIf( vtN:getZ() > 0, MCH_SCC.ADIR_ZP, MCH_SCC.ADIR_ZM) end else if sType == 'V' then nSCC = EgtIf( vtN:getY() > 0, MCH_SCC.ADIR_ZM, MCH_SCC.ADIR_ZP) else nSCC = EgtIf( vtN:getY() > 0, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) end end return nSCC end --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessProfConvex.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) local sWarn -- 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 -- 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 : missing profile geometry' EgtOutLog( sErr) return false, sErr end -- recupero i dati della curva e del profilo local dProfDepth = abs( EgtCurveThickness( AuxId)) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local nFirstFacet = 0 -- faccia iniziale local nLastFacet = EgtSurfTmFacetCount( Proc.Id) - 1 -- faccia finale local nMidFacet = ( nLastFacet + 1) // 2 -- faccia a metà circa local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nMidFacet, GDB_ID.ROOT) -- acquisisco informazioni sulle facce estreme local _, _, dLenIni = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFirstFacet, GDB_ID.ROOT) local _, _, dLenLst = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nLastFacet, GDB_ID.ROOT) -- verifico se in testa o coda local bHead = ( vtN:getX() > 0) EgtOutLog( 'vtN=' .. tostring( vtN), 3) -- 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 -- verifico se necessari ripassi agli estremi negli angoli local _, _, _, dFirstAng = EgtSurfTmFacetsContact( Proc.Id, nFirstFacet, nFirstFacet + 1, GDB_ID.ROOT) local bFirstTrim = ( dFirstAng and dFirstAng < -30) local _, _, _, dLastAng = EgtSurfTmFacetsContact( Proc.Id, nLastFacet, nLastFacet - 1, GDB_ID.ROOT) local bLastTrim = ( dLastAng and dLastAng < -30) -- 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 -- verifico se sono presenti i parametri Q per la profondità smusso e -- per eseguire in esclusiva solo lo smusso local bMakeVertCham = BD.DOWN_HEAD local nChamfer, dDepthCham, sChamfer, sChamfer2 = VerifyCham( Proc, AuxId, nRawId, bMakeVertCham, sDepthChamferMill, sPreemptiveChamfer) -- se non posso lavorare la feature perché condizionata dall'esecuzione del solo chamfer -- genero errore e non faccio nulla if nChamfer < 0 then return false, sChamfer end -- se smusso non è esclusivo, aggiungo sgrossatura if nChamfer < 2 then -- aggiungo piano di sgrossatura e lo lavoro local ptStart, vtNP = GetSawCutData( AuxId, vtN) local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptStart, vtNP, b3Solid, GDB_RT.GLOB) if AddId and BL.GetFaceElevation( AddId, 0, b3Solid) > 20.0 then EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- se macchina PF o ONE e profilo sopra davanti e pezzo alto applico svuotatura if BD.C_SIMM and not BD.DOWN_HEAD and vtNP:getZ() > 0 and vtNP:getX() > 0 and b3Raw:getDimZ() > 550 then -- recupero la lavorazione local sPockType = 'OpenPocket' local sPocketing = ML.FindPocketing( sPockType, nil, nil, nil, true, false) if not sPocketing then local sErr = 'Error : pocketing '..sPockType..' not found in library' EgtOutLog( sErr) return false, sErr end -- eseguo le svuotature necessarie local bOk, sErr = Fbp.Make( Proc, AddId, 0, sPocketing, nPartId, b3Solid) if not bOk then return false, sErr end -- altrimenti applico taglio di lama else local CutProc = { Id = AddId, Grp = Proc.Grp, Prc = Proc.Prc, Box = Proc.Box, Fct = Proc.Fct, Flg = Proc.Flg, Head = Proc.Head, Tail = Proc.Tail, CutId = Proc.CutId, TaskId = Proc.TaskId, PartId = Proc.PartId} CutProc.AffectedFaces = BL.GetProcessAffectedFaces( CutProc) local bOk, sErr = Cut.Make( CutProc, nPhase, nRawId, nPartId, dCurrOvmH) if not bOk then return false, sErr end end end end -- se devo inserire il chamfer if nChamfer > 0 then local bDoubleCham = false local dExtra = 2 -- Recupero i dati dell'utensile local dToolDiam = 0 if EgtMdbSetCurrMachining( sChamfer) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) end end -- inserisco la lavorazione local sNameCh = 'Cham_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchId = EgtAddMachining( sNameCh, sChamfer) if not nMchId then local sErr = 'Error adding machining ' .. sNameCh .. '-' .. sChamfer EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- se lavorazione da sopra o da sotto if nSide ~= 0 then bDoubleCham = true -- 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 bDoubleCham = BD.DOWN_HEAD -- 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 vtN:getY() > 0.1) or ( not bHead and vtN:getY() < -0.1) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, true) end end -- assegno affondamento e offset radiale EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) -- cambio il tipo di attacco in tangente EgtSetMachiningParam( MCH_MP.LEADINTYPE, 2) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr else -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno -- della feature inverto il punto di inizio della lavorazione ModifySideInvertLead( Proc, bHead, dToolDiam + ( 2 * dExtra), dLenIni, dLenLst, bFirstTrim, bLastTrim, dExtra) end -- se lavorazione da due parti, aggiungo la seconda if bDoubleCham then -- inserisco la lavorazione local sName = 'ChamB_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local sMachining2 = EgtIf( BD.DOWN_HEAD and sChamfer2, sChamfer2, sChamfer) local nMchId = EgtAddMachining( sName, sMachining2) if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMachining2 EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) -- se lavorazione da sopra o da sotto if nSide ~= 0 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 else -- se lavorazione a destra di fronte o sinistra da dietro, inverto if ( bHead and vtN:getY() > 0.1) or ( not bHead and vtN:getY() < -0.1) then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) EgtSetMachiningParam( MCH_MP.INVERT, true) end end -- assegno affondamento e offset radiale EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) -- cambio il tipo di attacco in tangente EgtSetMachiningParam( MCH_MP.LEADINTYPE, 2) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr else -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno -- della feature inverto il punto di inizio della lavorazione ModifySideInvertLead( Proc, bHead, dToolDiam + ( 2 * dExtra), dLenIni, dLenLst, bFirstTrim, bLastTrim, dExtra) end end end -- se il chamfer non è esclusivo continuo con le altre lavorazioni if nChamfer < 2 then -- recupero la lavorazione local sMilling = ML.FindMilling( 'Prof') if not sMilling then local sErr = 'Error : milling not found in library' EgtOutLog( sErr) return false, sErr end -- Recupero i dati dell'utensile local dToolDiam = 0 local dToolMaxDepth = 0 local dToolMaxMat = 0 if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() or dToolMaxDepth dToolMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dToolMaxMat end end -- verifico se necessario lavorare in doppio local bDouble = ( dProfDepth + BD.CUT_EXTRA - 100 * GEO.EPS_SMALL > dToolMaxDepth) local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) -- se lavorazione da due parti, aggiungo la seconda local sMillingDown if bDouble then if nSide == 0 then if BD.DOWN_HEAD then -- recupero la lavorazione sMillingDown = ML.FindMilling( 'Prof_H2', nil, nil, nil, nil, false, true) if not sMillingDown then sWarn = 'Warning : milling from bottom not found in library' EgtOutLog( sWarn) bDouble = false end elseif not BD.TURN then sWarn = 'Warning in profiling : depth (' .. EgtNumToString( dProfDepth, 1) .. ') bigger than max tool depth (' .. EgtNumToString( dToolMaxDepth, 1) .. ')' EgtOutLog( sWarn) bDouble = false end end end -- se orizzontale o trovata lavorazione per doppio verticale if bDouble then -- inserisco la lavorazione local sName = 'ProfB_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchId = EgtAddMachining( sName, EgtIf( BD.DOWN_HEAD and nSide == 0, sMillingDown, 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 e da sotto if ( nSide == 0) then if vtExtr:getZ() > 0.1 then EgtSetMachiningParam( MCH_MP.TOOLINVERT, true) EgtSetMachiningParam( MCH_MP.INVERT, true) end -- altrimenti lavorazione davanti e dietro else -- 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 end -- imposto l'affondamento EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- posizione braccio porta testa local nSCC = EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) if BD.TURN then nSCC = GetSccForTurn( vtN) end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- variabili per gestione direzione percorso e per gestione lavorazione di finitura opzionale local bFinish local dOriOffset = 0 local dOffsetPar = EgtGetInfo( Proc.Id, sOverMaterialForFinish, 'i') or 0 -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale if dOffsetPar > 0 then EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) bFinish = true end -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale precedente if dOffsetPar > 0 then EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) end -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr else -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno -- della feature inverto il punto di inizio della lavorazione e modifico i parametri dell'attacco -- e uscita ModifySideInvertLead( Proc, bHead, dToolDiam, dLenIni, dLenLst, bFirstTrim, bLastTrim, dOffsetPar) end -- se abilitata, aggiungo lavorazione di finitura if bFinish then -- inserisco la lavorazione local sNewName = 'ProfB_Fin_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMch2Id = EgtCopyMachining( sNewName, EgtGetName( nMchId)) if not nMch2Id then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr else -- riporto il sovramateriale originale e tolgo i passi inutili EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) EgtSetMachiningParam( MCH_MP.STEP, dToolMaxMat) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMch2Id, false) return false, sErr end end end end -- inserisco la prima 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 o da sotto if nSide ~= 0 then if not bDouble and nSide == -1 then -- se lavorazione a sinistra di fronte o destra 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 else -- 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 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 vtN:getY() > 0.1) or ( not bHead and vtN:getY() < -0.1) then EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) EgtSetMachiningParam( MCH_MP.INVERT, true) end end -- se in doppio, imposto l'affondamento if bDouble then EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) end -- posizione braccio porta testa local nSCC = EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) if BD.TURN then nSCC = GetSccForTurn( vtN) end EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- variabili per gestione direzione percorso e per gestione lavorazione di finitura opzionale local bFinish local dOriOffset = 0 local dOffsetPar = EgtGetInfo( Proc.Id, sOverMaterialForFinish, 'i') or 0 -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale if dOffsetPar > 0 then EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) bFinish = true end -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchId, false) return false, sErr else -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno -- della feature inverto il punto di inizio della lavorazione e modifico i parametri dell'attacco -- e uscita ModifySideInvertLead( Proc, bHead, dToolDiam, dLenIni, dLenLst, bFirstTrim, bLastTrim, dOffsetPar) end -- se abilitata, aggiungo lavorazione di finitura if bFinish then -- inserisco la lavorazione local sNewName = 'Prof_Fin_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMch2Id = EgtCopyMachining( sNewName, EgtGetName( nMchId)) if not nMch2Id then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr else -- riporto il sovramateriale originale e tolgo i passi inutili EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) EgtSetMachiningParam( MCH_MP.STEP, dToolMaxMat) -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMch2Id, false) return false, sErr end end end -- se parametro Q disabilitato, e consentito anche in alcuni casi lavorarlo con la feature da sotto -- inserisco eventuale finitura faccia finale (ortogonale alla trave o, se da sotto, parallela) if EgtGetInfo( Proc.Id, sEnableExtraMillUpperFace, 'i') ~= 1 and bLastTrim and ( nSide ~= -1 or ( nSide == -1 and ( EgtGetInfo( Proc.Id, sMachFacesUnderneath, 'i') == 1 or BD.DOWN_HEAD or BD.TURN))) 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 -- aggiungo geometria EgtSetMachiningGeometry( {{ Proc.Id, nLastFacet}}) -- aggiusto i parametri if vtN:getZ() > 0.1 then EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_DOWN) elseif vtN:getY() > 0.1 then EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_FRONT) elseif vtN:getY() < -0.1 then EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_BACK) else EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTUP_TOP) EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) or '' sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', EgtNumToString( (dToolMaxDepth/2), 1)) EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) end EgtSetMachiningParam( MCH_MP.INVERT, false) EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') EgtSetMachiningParam( MCH_MP.STEP, 0) EgtSetMachiningParam( MCH_MP.OFFSR, 0) if BD.TURN then local nSCC = GetSccForTurn( vtN, 'V') EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- modifico attacco e uscita per forzare risalita EgtSetMachiningParam( MCH_MP.STARTADDLEN, dToolDiam / 2) EgtSetMachiningParam( MCH_MP.LEADINTYPE, MCH_MILL_LI.TANGENT) EgtSetMachiningParam( MCH_MP.LITANG, 20) EgtSetMachiningParam( MCH_MP.LIPERP, 20) EgtSetMachiningParam( MCH_MP.LIELEV, 20) EgtSetMachiningParam( MCH_MP.ENDADDLEN, dToolDiam / 2) EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, MCH_MILL_LO.AS_LI) end -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchVId, false) return false, sErr end end -- se parametro Q disabilitato, e consentito anche in alcuni casi lavorarlo con la feature da sotto -- inserisco eventuale finitura faccia finale (ortogonale alla trave o, se da sotto, parallela) if EgtGetInfo( Proc.Id, sEnableExtraMillUpperFace, 'i') ~= 1 and bFirstTrim and ( nSide ~= -1 or ( nSide == -1 and ( EgtGetInfo( Proc.Id, sMachFacesUnderneath, 'i') == 1 or BD.DOWN_HEAD or BD.TURN))) then sName = 'ProfV2_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchV2Id = EgtAddMachining( sName, sMilling) if not nMchV2Id 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, nFirstFacet}}) -- aggiusto i parametri if bHead then EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_LEFT) else EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_RIGHT) end EgtSetMachiningParam( MCH_MP.INVERT, false) EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') EgtSetMachiningParam( MCH_MP.STEP, 0) EgtSetMachiningParam( MCH_MP.OFFSR, 0) local sUserNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) or '' sUserNotes = EgtSetValInNotes( sUserNotes, 'MaxElev', EgtNumToString( dWidth, 1)) EgtSetMachiningParam( MCH_MP.USERNOTES, sUserNotes) if BD.TURN then local nSCC = GetSccForTurn( vtN) EgtSetMachiningParam( MCH_MP.SCC, nSCC) end -- eseguo if not ML.ApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() EgtSetOperationMode( nMchV2Id, false) return false, sErr end end end -- aggiorno ingombro testa o coda per presa if nSide ~= 1 then -- se feature di fianco o da sotto if bHead then BL.UpdateHCING( nRawId, b3Raw:getMax():getX() - dCurrOvmH - Proc.Box:getMin():getX()) else BL.UpdateTCING( nRawId, Proc.Box:getMax():getX() - b3Solid:getMin():getX()) end -- altrimenti feature da sopra else if bHead then BL.UpdateHCING( nRawId, b3Raw:getMax():getX() - dCurrOvmH - Proc.Box:getMax():getX()) else BL.UpdateTCING( nRawId, Proc.Box:getMin():getX() - b3Solid:getMin():getX()) end end return true, sWarn end --------------------------------------------------------------------- return ProcessProfConvex