diff --git a/LuaLibs/BeamLib.lua b/LuaLibs/BeamLib.lua index c001919..37d72d6 100644 --- a/LuaLibs/BeamLib.lua +++ b/LuaLibs/BeamLib.lua @@ -1,4 +1,4 @@ --- BeamLib.lua by Egaltech s.r.l. 2020/01/23 +-- BeamLib.lua by Egaltech s.r.l. 2020/02/06 -- Libreria globale per Travi -- Tabella per definizione modulo @@ -755,5 +755,10 @@ function BeamLib.UpdateTCING( nRawId, dTCI) end end +------------------------------------------------------------------------------------------------------------- +function BeamLib.GetNzLimDownUp( b3Raw) + return EgtIf( b3Raw:getDimZ() < 200, -0.5, -0.258) +end + ------------------------------------------------------------------------------------------------------------- return BeamLib diff --git a/LuaLibs/DiceCut.lua b/LuaLibs/DiceCut.lua index 3e290b0..5d8ca2e 100644 --- a/LuaLibs/DiceCut.lua +++ b/LuaLibs/DiceCut.lua @@ -6,6 +6,7 @@ local DiceCut = {} -- Include require( 'EgtBase') +local BL = require( 'BeamLib') EgtOutLog( ' DiceCut started', 1) @@ -389,6 +390,9 @@ function DiceCut.GetDice( nParent, BBoxRawPart, ptCPlanes, vtNPlanes, bGetOrtoPl dElevO = DistanzaMassima( nParent, ptCBond, vtNBond, ptCPlanes, vtNPlanes, BBoxRawPart, TBoxPoint) end + -- inclinazione limite per taglio da sotto + local dNzLimDwnUp = BL.GetNzLimDownUp( BBoxRawPart) + -- se normali senza componenti in Y con faccia quasi verticale e trave non alta, uso per offset i limiti dei tagli di testa e coda if abs( vtNPlanes:getY()) < 0.1 and vtNPlanes:getZ() < 0.7071 and ( not vtNBond or abs( vtNBond:getY()) < 0.1) and BBoxRawPart:getDimZ() < BD.MIN_DIM_HBEAM then --OffsetP = BD.MAX_DIM_HTCUT @@ -457,10 +461,10 @@ function DiceCut.GetDice( nParent, BBoxRawPart, ptCPlanes, vtNPlanes, bGetOrtoPl end -- calcolo la direzione dei piani ortogonali local vtO = VectorFromUprightOrtho( vtNInner) - if vtNInner:getZ() > 0.05 or vtNInner:getZ() < -0.5 or abs( vtNInner:getY()) > 0.5 then + if vtNInner:getZ() > 0.05 or vtNInner:getZ() < dNzLimDwnUp or abs( vtNInner:getY()) > 0.5 then vtO:rotate( vtNInner, 90) -- se diretto troppo ortogonalmente all'asse trave e taglio non da sotto, lo ruoto ulteriormente - if abs( vtO:getY()) > abs( vtO:getX()) and vtNInner:getZ() > -0.5 then + if abs( vtO:getY()) > abs( vtO:getX()) and vtNInner:getZ() > dNzLimDwnUp then vtO:rotate( vtNInner, 90) else if ptCInner:getX() > BBoxRawPart:getCenter():getX() then diff --git a/LuaLibs/ProcessCut.lua b/LuaLibs/ProcessCut.lua index 414b3ff..9295303 100644 --- a/LuaLibs/ProcessCut.lua +++ b/LuaLibs/ProcessCut.lua @@ -47,7 +47,7 @@ function ProcessCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead, bFromBottom) EgtOutLog( sErr) return false, sErr end - local dNzLimDwnUp = EgtIf( b3Raw:getDimZ() < 300, -0.5, -0.258) + local dNzLimDwnUp = BL.GetNzLimDownUp( b3Raw) -- dati geometrici del taglio local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) local bDownCut = ( vtN:getZ() <= dNzLimDwnUp) diff --git a/LuaLibs/ProcessDoubleCut.lua b/LuaLibs/ProcessDoubleCut.lua index 8f24b11..26ed531 100644 --- a/LuaLibs/ProcessDoubleCut.lua +++ b/LuaLibs/ProcessDoubleCut.lua @@ -1,4 +1,4 @@ --- ProcessDoubleCut.lua by Egaltech s.r.l. 2019/09/25 +-- ProcessDoubleCut.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo doppi tagli di lama per Travi -- Tabella per definizione modulo @@ -113,20 +113,20 @@ function ProcessDoubleCut.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) vOrd = { 2, 1} end -- creo piano di taglio coincidente con la prima faccia e lo lavoro - local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[vOrd[1]], vtN[vOrd[1]], b3Solid, GDB_RT.GLOB) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vOrd[1]], vtN[vOrd[1]], b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- applico 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 -- creo piano di taglio coincidente con la seconda faccia e lo lavoro - AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[vOrd[2]], vtN[vOrd[2]], b3Solid, GDB_RT.GLOB) + AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vOrd[2]], vtN[vOrd[2]], b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- applico 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) diff --git a/LuaLibs/ProcessDtMortise.lua b/LuaLibs/ProcessDtMortise.lua index 1be8d29..e01088c 100644 --- a/LuaLibs/ProcessDtMortise.lua +++ b/LuaLibs/ProcessDtMortise.lua @@ -1,4 +1,4 @@ --- ProcessMortise.lua by Egaltech s.r.l. 2020/01/16 +-- ProcessMortise.lua by Egaltech s.r.l. 2020/02/06 -- Gestione calcolo mortase a coda di rondice per Travi -- Tabella per definizione modulo @@ -50,7 +50,7 @@ function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId) 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' + local sErr = 'Missing profile geometry : Error on DtMortise ' .. tostring( Proc.Id) EgtOutLog( sErr) return false, sErr end @@ -59,14 +59,14 @@ function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) -- verifico che la mortasa non sia orientata verso il basso (-5 deg) if vtExtr:getZ() < - 0.1 then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' DtMortise from bottom impossible' + local sErr = 'Machining from bottom impossible : Error on DtMortise ' .. tostring( Proc.Id) EgtOutLog( sErr) return false, sErr end -- recupero la lavorazione local sMilling = ML.FindMilling( 'DtMortise') if not sMilling then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library' + local sErr = 'Milling not found in library : Error on DtMortise ' .. tostring( Proc.Id) EgtOutLog( sErr) return false, sErr end @@ -79,6 +79,16 @@ function ProcessDtMortise.Make( Proc, nPhase, nRawId, nPartId) end end dToolDiam = max( dToolDiam, 10) + -- verifico se raggio troppo piccolo per l'utensile + local nSt, nEnd = EgtCurveDomain( AuxId) + for i = nSt, nEnd - 1 do + local dRad = EgtCurveCompoRadius( AuxId, i) + if dRad > 0 and dRad < dToolDiam / 2 then + local sErr = 'Radius too small : Error on DtMortise ' .. tostring( Proc.Id) + EgtOutLog( sErr) + return false, sErr + end + end -- verifico se necessarie più passate (distanza all'imbocco ortogonale all'asse) local vtDiff = EgtEP( AuxId, GDB_RT.GLOB) - EgtSP( AuxId, GDB_RT.GLOB) local vtAx = EgtEV( AuxId, GDB_RT.GLOB) - EgtSV( AuxId, GDB_RT.GLOB) diff --git a/LuaLibs/ProcessDtTenon.lua b/LuaLibs/ProcessDtTenon.lua index 80178fa..d04dc30 100644 --- a/LuaLibs/ProcessDtTenon.lua +++ b/LuaLibs/ProcessDtTenon.lua @@ -1,4 +1,4 @@ --- ProcessTenon.lua by Egaltech s.r.l. 2019/12/10 +-- ProcessTenon.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo tenone a coda di rondine per Travi -- Tabella per definizione modulo @@ -123,10 +123,10 @@ function ProcessDtTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) return false, sErr end -- creo piano di taglio sulla testa del tenone e lo lavoro - local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC, vtN, b3Solid, GDB_RT.GLOB) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC, vtN, b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- se pezzo piccolo, in coda e piano inclinato attorno a Z applico svuotatura if b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getX() < 0 and abs( vtExtr:getY()) > 0.173 then local sPocketing = ML.FindPocketing( 'OpenPocket') diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index 0910bfa..2b2f330 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -1,4 +1,4 @@ --- ProcessLapJoint.lua by Egaltech s.r.l. 2020/02/04 +-- ProcessLapJoint.lua by Egaltech s.r.l. 2020/02/05 -- Gestione calcolo mezzo-legno per Travi -- 2019/10/08 Agg. gestione OpenPocket. @@ -244,9 +244,10 @@ function ProcessLapJoint.Classify( Proc) if not nFacInd or nFacInd < 0 then return false end + local rfFac, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) -- se può essere fatto con utensile tipo lama - local bUseBHSideMill = VerifyIfByBHSideMill( Proc) - if bUseBHSideMill then + local bUseBHSideMill, _, _, dMaxMat = VerifyIfByBHSideMill( Proc) + if bUseBHSideMill and ( dMaxMat <= dV) then return true, false -- altrimenti controllo se deve essere ruotato con le altre lavorazioni else @@ -768,10 +769,9 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId) local rfFac, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) -- verifico se U local bIsU = ( Proc.Fct == 3 and not TestElleShape3( Proc)) - - -- se fattibile con fresa BH di fianco + -- se fattibile con fresa BH di fianco e spessore utensile inferiore alla larghezza faccia local bMakeBySideMill, bHead, sMilling, dMaxMat = VerifyIfByBHSideMill( Proc) - if bMakeBySideMill then + if bMakeBySideMill and ( dMaxMat <= dV) then -- inserisco la lavorazione di fresatura local sName = 'BHMill_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) local nMchFId = EgtAddMachining( sName, sMilling) @@ -1002,8 +1002,9 @@ function ProcessLapJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) else -- una faccia if Proc.Fct == 1 then + local bForcedBlade = ( Proc.Prc == 20 and EgtGetInfo( Proc.Id, 'Q03', 'i') ~= 1 ) -- se piccola, con fresa - if ( Proc.Box:getDimX() < MAX_MILL_LIN and ( Proc.Box:getDimZ() < MAX_MILL_LIN or Proc.Box:getDimY() < MAX_MILL_LIN)) then + if not bForcedBlade and ( Proc.Box:getDimX() < MAX_MILL_LIN and ( Proc.Box:getDimZ() < MAX_MILL_LIN or Proc.Box:getDimY() < MAX_MILL_LIN)) then return MakeOneFaceByMill( Proc, nPhase, nRawId, nPartId) -- altrimenti, con lama else @@ -1013,8 +1014,9 @@ function ProcessLapJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) elseif Proc.Fct == 2 then -- determino l'angolo tra le facce local bAdj, _, _, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) + local bForcedBlade = ( Proc.Prc == 20 and EgtGetInfo( Proc.Id, 'Q03', 'i') ~= 1 ) -- se ortogonali e piccole, con fresa - if bAdj and abs( dAng + 90) < 1 and + if not bForcedBlade and bAdj and abs( dAng + 90) < 1 and ( Proc.Box:getDimX() < MAX_MILL_LIN and ( Proc.Box:getDimZ() < MAX_MILL_LIN or Proc.Box:getDimY() < MAX_MILL_LIN)) then return MakeTwoFacesByMill( Proc, nPhase, nRawId, nPartId) -- altrimenti, con lama diff --git a/LuaLibs/ProcessProfCamb.lua b/LuaLibs/ProcessProfCamb.lua index 4602bd4..97c636b 100644 --- a/LuaLibs/ProcessProfCamb.lua +++ b/LuaLibs/ProcessProfCamb.lua @@ -1,4 +1,4 @@ --- ProcessProfCamb.lua by Egaltech s.r.l. 2020/02/04 +-- ProcessProfCamb.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo profilo caudato per Travi -- Tabella per definizione modulo @@ -15,6 +15,13 @@ EgtOutLog( ' ProcessProfCamb started', 1) local BD = require( 'BeamData') local ML = require( 'MachiningLib') +-- variabili assegnazione parametri Q +local sEnableExtraMillUpperFace = 'Q01' -- i +local sEnableExtraBladeUpperFace = 'Q02' -- i +local sDepthChamferMill = 'Q03' -- d +local sOverMaterialForFinish = 'Q04' -- d +local sPreemptiveChamfer = 'Q05' -- i + --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessProfCamb.Identify( Proc) @@ -62,6 +69,94 @@ local function GetSawCutData( AuxId, vtNF) return ptStart, vtNP end +--------------------------------------------------------------------- +local function ModifySideAndInvert( Proc, bHead, dToolDiam) + -- confronto il punto iniziale e finale della lavorazione con il box della feature + -- e se è vicino alla parte esterna della trave inverto la lavorazione + ptSP = EgtGetMachiningStartPoint() + ptEp = EgtGetMachiningEndPoint() + local nMachMode = EgtGetMachiningParam( MCH_MP.STEPTYPE) + if nMachMode == 1 and ptSP and ptEp then + 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 + -- ottengo l'inversione e setto il contrario + local bInvertMode = EgtGetMachiningParam( MCH_MP.INVERT) + EgtSetMachiningParam( MCH_MP.INVERT, not bInvertMode) + -- riapplico la lavorazione + EgtApplyMachining() + end + 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 then + nChamfer = 1 + end + -- verifico se posso fare solo lo smusso + if EgtGetInfo( Proc.Id, sOnlyCham, 'i') == 1 then + if dDepth > 0 then + nChamfer = nChamfer + 1 + -- altrimenti se non ho l'affondamento esco + else + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' 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) + local nCanVert = 0 + -- 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 on process ' .. tostring( Proc.Id) .. ' not horizontale chamfer' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped not horizontale chamfer' + EgtOutLog( sWarn) + return 0, dDepth + end + else + nCanVert = 1 + end + end + -- eseguo lo smusso solo se feature larga come la trave + if dWidth < EgtIf( nCanVert == 1, b3Raw:getDimZ(), b3Raw:getDimY()) - 1 then + if nChamfer == 2 then -- se devo fare solo smusso, genero errore + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' feature smaller than beam' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped chamfer (feature smaller than beam)' + EgtOutLog( sWarn) + return 0, dDepth + end + end + -- recupero la lavorazione + local sMilling = ML.FindMilling( 'Mark') + if not sMilling then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' chamfer not found in library' + EgtOutLog( sErr) + return -1, 0, sErr + end + + return nChamfer, dDepth, sMilling +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessProfCamb.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) @@ -91,7 +186,6 @@ function ProcessProfCamb.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) local nRefFacet = nLastFacet - 1 -- penultima faccia local vtNF = EgtSurfTmFacetNormVersor( Proc.Id, nLastFacet, GDB_ID.ROOT) local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nRefFacet, GDB_ID.ROOT) - local bUseBladeOnLastFace -- serve per un eventuale gestione dell'inversione fresate se non c'è la lama -- verifico se in testa o coda local bHead = ( vtNF:getX() > 0) EgtOutLog( 'vtN=' .. tostring( vtN), 3) @@ -109,149 +203,115 @@ function ProcessProfCamb.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtOutLog( sErr) return false, sErr end - -- aggiungo taglio di lama di sgrossatura e lo lavoro - local ptStart, vtNP = GetSawCutData( AuxId, vtNF) - 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 + -- verifico se sono presenti i parametri Q per la profondità smusso e + -- per eseguire in esclusiva solo lo smusso + local nChamfer, dDepthCham, sChamfer = VerifyCham( Proc, AuxId, nRawId, false, 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 non da sotto e aggiungo taglio di lama se definito dal parametro Q02 - if nSide ~= -1 and nLastFacet and EgtGetInfo( Proc.Id, 'Q02', 'i') == 1 then - -- recupero la lavorazione - local sCutting = ML.FindCutting( 'HeadSide') - if not sCutting then - local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' sawing not found in library' + --variabili utilizzate in varie parti + local dToolMaxDepth = 0 + local dMillDiam = 0 + local sMilling + -- se smusso non è esclusivo + if nChamfer < 2 then + -- aggiungo taglio di lama di sgrossatura e lo lavoro + local ptStart, vtNP = GetSawCutData( AuxId, vtNF) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptStart, vtNP, b3Solid, GDB_RT.GLOB) + if AddId then + EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) + -- 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 + -- leggo anticipatamente i parametri utensile fresa per dare un valore opportuno all'elevazione della lama + -- recupero la lavorazione di fresatura + sMilling = ML.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 - -- recupero i dati dell'utensile - local dToolDiam = 0 - local dMaxDepth = 0 - local dToolThick = 0 - if EgtMdbSetCurrMachining( sCutting) then + -- Recupero i dati dell'utensile + if EgtMdbSetCurrMachining( sMilling) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam - dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth - dToolThick = EgtTdbGetCurrToolParam(MCH_TP.THICK) or dToolThick + dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() + dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) end end - local vtOrthoO = Vector3d(vtN) - local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, nLastFacet, sCutting, dToolDiam, vtOrthoO, nil, -(dV*0.25), BD.CUT_SIC, 0, 0, nil, b3Raw) - if bOk then bUseBladeOnLastFace = true end - end - -- recupero la lavorazione - local sMilling = ML.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 - -- Recupero i dati dell'utensile - local dToolMaxDepth = 0 - local dToolDiam = 0 - if EgtMdbSetCurrMachining( sMilling) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() - dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) - end - end - -- verifico se necessario lavorare in doppio - local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) - local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) - -- 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 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 - -- 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 vtNF:getY() > 0.1) or - ( not bHead and vtNF: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 - local ptSP, ptEp - -- 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 - else - -- confronto il punto iniziale e finale della lavorazione con il box della feature - -- e se è vicino alla parte esterna della trave inverto la lavorazione - ptSP = EgtGetMachiningStartPoint() - ptEp = EgtGetMachiningEndPoint() - local nMachMode = EgtMdbGetCurrMachiningParam( MCH_MP.STEPTYPE) - if nMachMode == 1 and ptSP and ptEp then - 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 = EgtMdbGetCurrMachiningParam( 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)) + -- se non da sotto e abilitato dal parametro Q aggiungo taglio di lama + if nSide ~= -1 and nLastFacet and EgtGetInfo( Proc.Id, sEnableExtraBladeUpperFace, 'i') == 1 then + -- recupero la lavorazione + local sCutting = ML.FindCutting( 'HeadSide') + if not sCutting then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' sawing not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- recupero i dati dell'utensile + local dToolDiam = 0 + local dMaxDepth = 0 + local dToolThick = 0 + if EgtMdbSetCurrMachining( sCutting) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dToolDiam + dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth + dToolThick = EgtTdbGetCurrToolParam(MCH_TP.THICK) or dToolThick end - -- ottengo l'inversione e setto il contrario - local bInvertMode = EgtMdbGetCurrMachiningParam( MCH_MP.INVERT) - EgtSetMachiningParam( MCH_MP.INVERT, not bInvertMode) - -- riapplico la lavorazione - EgtApplyMachining() end + local vtOrthoO = Vector3d(vtN) + local bOk, sNameOrErr = BL.MakeOneFaceBySaw( Proc.Id, nLastFacet, sCutting, dToolDiam, vtOrthoO, nil, -((dMillDiam/2)+1), BD.CUT_SIC, 0, 0, nil, b3Raw) end end - -- se lavorazione da due parti, aggiungo la seconda - if bDouble then + -- se devo inserire il chamfer + if nChamfer > 0 then + local bDoubleCham = false + local dExtra = 2 -- inserisco la lavorazione - local sName = 'ProfB_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) - local nMchId = EgtAddMachining( sName, sMilling) + local sNameCh = 'Cham_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchId = EgtAddMachining( sNameCh, sChamfer) if not nMchId then - local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + local sErr = 'Error adding machining ' .. sNameCh .. '-' .. sChamfer EgtOutLog( sErr) return false, sErr end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) - -- sempre lavorazione da sopra o da sotto - -- 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) + -- 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 + -- 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 vtNF:getY() > 0.1) or + ( not bHead and vtNF:getY() < -0.1) then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + EgtSetMachiningParam( MCH_MP.INVERT, true) + end end - -- imposto l'affondamento - EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + -- assegno affondamento e offset radiale + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) -- eseguo @@ -260,70 +320,252 @@ function ProcessProfCamb.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtSetOperationMode( nMchId, false) return false, sErr else - -- confronto il punto iniziale e finale della lavorazione con il box della feature - -- e se è vicino alla parte esterna della trave inverto la lavorazione - ptSP = EgtGetMachiningStartPoint() - ptEp = EgtGetMachiningEndPoint() - local nMachMode = EgtMdbGetCurrMachiningParam( MCH_MP.STEPTYPE) - if nMachMode == 1 and ptSP and ptEp then - 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 = EgtMdbGetCurrMachiningParam( 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 - -- ottengo l'inversione e setto il contrario - local bInvertMode = EgtMdbGetCurrMachiningParam( MCH_MP.INVERT) - EgtSetMachiningParam( MCH_MP.INVERT, not bInvertMode) - -- riapplico la lavorazione - EgtApplyMachining() - end + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvert( Proc, bHead, dMillDiam) + 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 nMchId = EgtAddMachining( sName, sChamfer) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sChamfer + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- assegno affondamento e offset radiale + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvert( Proc, bHead, dMillDiam) end end 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 + -- se il chamfer non è esclusivo continuo con le altre lavorazioni + if nChamfer < 2 then + -- verifico se necessario lavorare in doppio + local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) + local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) + -- 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( {{ Proc.Id, nLastFacet}}) - -- aggiusto i parametri - EgtSetMachiningParam( MCH_MP.INVERT, true) - EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') - EgtSetMachiningParam( MCH_MP.STEP, 0) - EgtSetMachiningParam( MCH_MP.OFFSR, -0.5) - -- imposto tipo uso faccia - local nFaceUse = MCH_MILL_FU.ORTHO_DOWN - if nSide ~= 1 then - nFaceUse = EgtIf( vtN:getY() > 0.1, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_BACK) + 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 vtNF:getY() > 0.1) or + ( not bHead and vtNF:getY() < -0.1) then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + EgtSetMachiningParam( MCH_MP.INVERT, true) + end 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 + -- se in doppio, imposto l'affondamento + if bDouble then + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + end + -- posizione braccio porta testa + EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- variabili per gestione direzione percorso e per gestione lavorazione di finitura opzionale + local ptSP, ptEp + local bFinish + local dOriOffset + local dOffsetPar = EgtGetInfo( Proc.Id, sOverMaterialForFinish, 'i') or 0 + -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale + if dOffsetPar > 0 then + dOriOffset = EgtMdbGetCurrMachiningParam( MCH_MP.OFFSR) or 0 + EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) + bFinish = true end - EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchVId, false) + 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 + ModifySideAndInvert( Proc, bHead, dMillDiam) + 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 nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end + end + end + -- se lavorazione da due parti, aggiungo la seconda + if bDouble then + -- inserisco la lavorazione + local sName = 'ProfB_' .. ( 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}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- imposto l'affondamento + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + -- posizione braccio porta testa + EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- 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 EgtApplyMachining( 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 + ModifySideAndInvert( Proc, bHead, dMillDiam) + 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 nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end + end + end + end + -- se non da sotto e parametro Q abilitato, inserisco lavorazione finitura angolo + if nSide ~= -1 and EgtGetInfo( Proc.Id, sEnableExtraMillUpperFace, 'i') == 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 + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nLastFacet}}) + -- aggiusto i parametri + EgtSetMachiningParam( MCH_MP.INVERT, true) + EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') + EgtSetMachiningParam( MCH_MP.STEP, 0) + EgtSetMachiningParam( MCH_MP.OFFSR, -0.5) + -- imposto tipo uso faccia + local nFaceUse = MCH_MILL_FU.ORTHO_DOWN + if nSide ~= 1 then + nFaceUse = EgtIf( vtN:getY() > 0.1, MCH_MILL_FU.ORTHO_FRONT, MCH_MILL_FU.ORTHO_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 end -- aggiorno ingombro testa o coda per presa - if nSide == 0 then + 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 end diff --git a/LuaLibs/ProcessProfConcave.lua b/LuaLibs/ProcessProfConcave.lua index 4c9e662..7cd1f52 100644 --- a/LuaLibs/ProcessProfConcave.lua +++ b/LuaLibs/ProcessProfConcave.lua @@ -1,4 +1,4 @@ --- ProcessProfConcave.lua by Egaltech s.r.l. 2020/02/04 +-- ProcessProfConcave.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo profilo caudato per Travi -- Tabella per definizione modulo @@ -15,6 +15,14 @@ EgtOutLog( ' ProcessProfConcave started', 1) local BD = require( 'BeamData') local ML = require( 'MachiningLib') +-- variabili assegnazione parametri Q +local sEnableExtraMillUpperFace = 'Q03' -- i +local sEnableExtraBladeUpperFace = '' -- i +local sDepthChamferMill = 'Q01' -- d +local sOverMaterialForFinish = 'Q02' -- d +local sPreemptiveChamfer = 'Q04' -- i +local sMachFacesUnderneath = 'Q99' -- i + --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessProfConcave.Identify( Proc) @@ -43,43 +51,111 @@ local function GetSawCutData( AuxId, vtN) end --------------------------------------------------------------------- -local function ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) +local function ModifySideAndInvertAndLead( Proc, bHead, dToolDiam, bNotModifLeadPar) -- confronto il punto iniziale e finale della lavorazione con il box della feature -- e se è vicino alla parte esterna della trave inverto la lavorazione ptSP = EgtGetMachiningStartPoint() ptEp = EgtGetMachiningEndPoint() - local nMachMode = EgtMdbGetCurrMachiningParam( MCH_MP.STEPTYPE) + local nMachMode = EgtGetMachiningParam( MCH_MP.STEPTYPE) if nMachMode == 1 and ptSP and ptEp then 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 = EgtMdbGetCurrMachiningParam( MCH_MP.WORKSIDE) + 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 -- ottengo l'inversione e setto il contrario - local bInvertMode = EgtMdbGetCurrMachiningParam( MCH_MP.INVERT) + local bInvertMode = EgtGetMachiningParam( MCH_MP.INVERT) EgtSetMachiningParam( MCH_MP.INVERT, not bInvertMode) -- modifico attacco e uscita - EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) - EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + if not bNotModifLeadPar then + EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) + EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + end -- riapplico la lavorazione EgtApplyMachining() else -- modifico attacco e uscita - EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) - EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) - -- riapplico la lavorazione - EgtApplyMachining() + if not bNotModifLeadPar then + EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) + EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + -- riapplico la lavorazione + EgtApplyMachining() + end end 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 then + nChamfer = 1 + end + -- verifico se posso fare solo lo smusso + if EgtGetInfo( Proc.Id, sOnlyCham, 'i') == 1 then + if dDepth > 0 then + nChamfer = nChamfer + 1 + -- altrimenti se non ho l'affondamento esco + else + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' 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) + local nCanVert = 0 + -- 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 on process ' .. tostring( Proc.Id) .. ' not horizontale chamfer' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped not horizontale chamfer' + EgtOutLog( sWarn) + return 0, dDepth + end + else + nCanVert = 1 + end + end + -- eseguo lo smusso solo se feature larga come la trave + if dWidth < EgtIf( nCanVert == 1, b3Raw:getDimZ(), b3Raw:getDimY()) - 1 then + if nChamfer == 2 then -- se devo fare solo smusso, genero errore + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' feature smaller than beam' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped chamfer (feature smaller than beam)' + EgtOutLog( sWarn) + return 0, dDepth + end + end + -- recupero la lavorazione + local sMilling = ML.FindMilling( 'Mark') + if not sMilling then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' chamfer not found in library' + EgtOutLog( sErr) + return -1, 0, sErr + end + + return nChamfer, dDepth, sMilling +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessProfConcave.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) @@ -110,6 +186,7 @@ function ProcessProfConcave.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nMidFacet, 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 @@ -129,90 +206,146 @@ function ProcessProfConcave.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtOutLog( sErr) return false, sErr end - -- aggiungo taglio di lama di sgrossatura e lo lavoro - local ptStart, vtNP = GetSawCutData( AuxId, vtN) - 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 + -- verifico se sono presenti i parametri Q per la profondità smusso e + -- per eseguire in esclusiva solo lo smusso + local nChamfer, dDepthCham, sChamfer = VerifyCham( Proc, AuxId, nRawId, false, 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 - -- recupero la lavorazione - local sMilling = ML.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 - -- Recupero i dati dell'utensile - local dToolMaxDepth = 0 - local dToolDiam = 0 - if EgtMdbSetCurrMachining( sMilling) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() - dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + -- se smusso non è esclusivo + if nChamfer < 2 then + -- aggiungo taglio di lama di sgrossatura e lo lavoro + local ptStart, vtNP = GetSawCutData( AuxId, vtN) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptStart, vtNP, b3Solid, GDB_RT.GLOB) + if AddId then + EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) + -- 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 end - -- verifico se necessario lavorare in doppio - local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) - local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) - -- 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 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 - -- 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 - 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 - 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 - ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) - end - -- se lavorazione da due parti, aggiungo la seconda - if bDouble then + -- se devo inserire il chamfer + if nChamfer > 0 then + local bDoubleCham = false + local dExtra = 2 -- inserisco la lavorazione - local sName = 'ProfB_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + 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 + -- 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 vtNF:getY() > 0.1) or + ( not bHead and vtNF: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) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvertAndLead( Proc, bHead, dMillDiam, true) + 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 nMchId = EgtAddMachining( sName, sChamfer) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sChamfer + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- assegno affondamento e offset radiale + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvertAndLead( Proc, bHead, dMillDiam, true) + 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 on process ' .. tostring( Proc.Id) .. ' milling not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- Recupero i dati dell'utensile + local dToolMaxDepth = 0 + local dToolDiam = 0 + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() + dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + end + end + -- verifico se necessario lavorare in doppio + local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) + local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) + -- 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 @@ -221,17 +354,54 @@ function ProcessProfConcave.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) - -- sempre lavorazione da sopra o da sotto - -- 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) + -- 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 - -- imposto l'affondamento - EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- variabili per gestione direzione percorso e per gestione lavorazione di finitura opzionale + local ptSP, ptEp + local bFinish + local dOriOffset + local dOffsetPar = EgtGetInfo( Proc.Id, sOverMaterialForFinish, 'i') or 0 + -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale + if dOffsetPar > 0 then + dOriOffset = EgtMdbGetCurrMachiningParam( MCH_MP.OFFSR) or 0 + EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) + bFinish = true + end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() @@ -243,75 +413,165 @@ function ProcessProfConcave.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) -- e uscita ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) end - end - -- eventuale finitura faccia finale (ortogonale alla trave) - if nSide ~= -1 and bLastTrim 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 + -- se abilitata, aggiungo lavorazione di finitura + if bFinish then + -- inserisco la lavorazione + local sNewName = 'Prof_Fin_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end + end 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) - else - EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_BACK) + -- se lavorazione da due parti, aggiungo la seconda + if bDouble then + -- inserisco la lavorazione + local sName = 'ProfB_' .. ( 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}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- imposto l'affondamento + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + -- posizione braccio porta testa + EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- 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 EgtApplyMachining( 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 + ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) + 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 nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end + end + end end - EgtSetMachiningParam( MCH_MP.INVERT, false) - EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') - EgtSetMachiningParam( MCH_MP.STEP, 0) - EgtSetMachiningParam( MCH_MP.OFFSR, 0) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchVId, false) - return false, sErr + -- 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)) 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, 1) + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( (dToolMaxDepth/2), 1)) + end + EgtSetMachiningParam( MCH_MP.INVERT, false) + EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') + EgtSetMachiningParam( MCH_MP.STEP, 0) + EgtSetMachiningParam( MCH_MP.OFFSR, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchVId, false) + return false, sErr + end end - end - -- eventuale finitura faccia iniziale (parallela alla trave) - if nSide ~= -1 and bFirstTrim 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) - EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dWidth, 1)) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchV2Id, false) - return false, sErr + -- 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)) 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) + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dWidth, 1)) + -- eseguo + if not EgtApplyMachining( 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 + 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()) diff --git a/LuaLibs/ProcessProfConvex.lua b/LuaLibs/ProcessProfConvex.lua index 23324d0..b83dec4 100644 --- a/LuaLibs/ProcessProfConvex.lua +++ b/LuaLibs/ProcessProfConvex.lua @@ -1,4 +1,4 @@ --- ProcessProfConvex.lua by Egaltech s.r.l. 2020/01/04 +-- ProcessProfConvex.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo profilo caudato per Travi -- Tabella per definizione modulo @@ -15,6 +15,14 @@ EgtOutLog( ' ProcessProfConvex started', 1) 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) @@ -43,43 +51,111 @@ local function GetSawCutData( AuxId, vtN) end --------------------------------------------------------------------- -local function ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) +local function ModifySideAndInvertAndLead( Proc, bHead, dToolDiam, bNotModifLeadPar) -- confronto il punto iniziale e finale della lavorazione con il box della feature -- e se è vicino alla parte esterna della trave inverto la lavorazione ptSP = EgtGetMachiningStartPoint() ptEp = EgtGetMachiningEndPoint() - local nMachMode = EgtMdbGetCurrMachiningParam( MCH_MP.STEPTYPE) + local nMachMode = EgtGetMachiningParam( MCH_MP.STEPTYPE) if nMachMode == 1 and ptSP and ptEp then 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 = EgtMdbGetCurrMachiningParam( MCH_MP.WORKSIDE) + 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 -- ottengo l'inversione e setto il contrario - local bInvertMode = EgtMdbGetCurrMachiningParam( MCH_MP.INVERT) + local bInvertMode = EgtGetMachiningParam( MCH_MP.INVERT) EgtSetMachiningParam( MCH_MP.INVERT, not bInvertMode) -- modifico attacco e uscita - EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) - EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + if not bNotModifLeadPar then + EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) + EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + end -- riapplico la lavorazione EgtApplyMachining() else -- modifico attacco e uscita - EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) - EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) - -- riapplico la lavorazione - EgtApplyMachining() + if not bNotModifLeadPar then + EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) + EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + -- riapplico la lavorazione + EgtApplyMachining() + end end 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 then + nChamfer = 1 + end + -- verifico se posso fare solo lo smusso + if EgtGetInfo( Proc.Id, sOnlyCham, 'i') == 1 then + if dDepth > 0 then + nChamfer = nChamfer + 1 + -- altrimenti se non ho l'affondamento esco + else + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' 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) + local nCanVert = 0 + -- 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 on process ' .. tostring( Proc.Id) .. ' not horizontale chamfer' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped not horizontale chamfer' + EgtOutLog( sWarn) + return 0, dDepth + end + else + nCanVert = 1 + end + end + -- eseguo lo smusso solo se feature larga come la trave + if dWidth < EgtIf( nCanVert == 1, b3Raw:getDimZ(), b3Raw:getDimY()) - 1 then + if nChamfer == 2 then -- se devo fare solo smusso, genero errore + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' feature smaller than beam' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped chamfer (feature smaller than beam)' + EgtOutLog( sWarn) + return 0, dDepth + end + end + -- recupero la lavorazione + local sMilling = ML.FindMilling( 'Mark') + if not sMilling then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' chamfer not found in library' + EgtOutLog( sErr) + return -1, 0, sErr + end + + return nChamfer, dDepth, sMilling +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessProfConvex.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) @@ -110,6 +186,7 @@ function ProcessProfConvex.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nMidFacet, 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 @@ -129,90 +206,146 @@ function ProcessProfConvex.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtOutLog( sErr) return false, sErr end - -- aggiungo taglio di lama di sgrossatura e lo lavoro - local ptStart, vtNP = GetSawCutData( AuxId, vtN) - 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 + -- verifico se sono presenti i parametri Q per la profondità smusso e + -- per eseguire in esclusiva solo lo smusso + local nChamfer, dDepthCham, sChamfer = VerifyCham( Proc, AuxId, nRawId, false, 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 - -- recupero la lavorazione - local sMilling = ML.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 - -- Recupero i dati dell'utensile - local dToolMaxDepth = 0 - local dToolDiam = 0 - if EgtMdbSetCurrMachining( sMilling) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() - dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + -- se smusso non è esclusivo + if nChamfer < 2 then + -- aggiungo taglio di lama di sgrossatura e lo lavoro + local ptStart, vtNP = GetSawCutData( AuxId, vtN) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptStart, vtNP, b3Solid, GDB_RT.GLOB) + if AddId then + EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) + -- 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 end - -- verifico se necessario lavorare in doppio - local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) - local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) - -- 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 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 - -- 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 - 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 - 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 - ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) - end - -- se lavorazione da due parti, aggiungo la seconda - if bDouble then + -- se devo inserire il chamfer + if nChamfer > 0 then + local bDoubleCham = false + local dExtra = 2 -- inserisco la lavorazione - local sName = 'ProfB_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + 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 + -- 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 vtNF:getY() > 0.1) or + ( not bHead and vtNF: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) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvertAndLead( Proc, bHead, dMillDiam, true) + 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 nMchId = EgtAddMachining( sName, sChamfer) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sChamfer + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- assegno affondamento e offset radiale + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvertAndLead( Proc, bHead, dMillDiam, true) + 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 on process ' .. tostring( Proc.Id) .. ' milling not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- Recupero i dati dell'utensile + local dToolMaxDepth = 0 + local dToolDiam = 0 + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() + dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + end + end + -- verifico se necessario lavorare in doppio + local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) + local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) + -- 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 @@ -221,17 +354,54 @@ function ProcessProfConvex.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) - -- sempre lavorazione da sopra o da sotto - -- 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) + -- 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 - -- imposto l'affondamento - EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- variabili per gestione direzione percorso e per gestione lavorazione di finitura opzionale + local ptSP, ptEp + local bFinish + local dOriOffset + local dOffsetPar = EgtGetInfo( Proc.Id, sOverMaterialForFinish, 'i') or 0 + -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale + if dOffsetPar > 0 then + dOriOffset = EgtMdbGetCurrMachiningParam( MCH_MP.OFFSR) or 0 + EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) + bFinish = true + end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() @@ -243,66 +413,155 @@ function ProcessProfConvex.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) -- e uscita ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) end - end - -- eventuale finitura faccia finale (ortogonale alla trave) - if nSide ~= -1 and bLastTrim 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 + -- se abilitata, aggiungo lavorazione di finitura + if bFinish then + -- inserisco la lavorazione + local sNewName = 'Prof_Fin_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end + end 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) - else - EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_BACK) + -- se lavorazione da due parti, aggiungo la seconda + if bDouble then + -- inserisco la lavorazione + local sName = 'ProfB_' .. ( 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}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- imposto l'affondamento + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + -- posizione braccio porta testa + EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- 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 EgtApplyMachining( 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 + ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) + 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 nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end + end + end end - EgtSetMachiningParam( MCH_MP.INVERT, false) - EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') - EgtSetMachiningParam( MCH_MP.STEP, 0) - EgtSetMachiningParam( MCH_MP.OFFSR, 0) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchVId, false) - return false, sErr + -- 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)) 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, 1) + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( (dToolMaxDepth/2), 1)) + end + EgtSetMachiningParam( MCH_MP.INVERT, false) + EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') + EgtSetMachiningParam( MCH_MP.STEP, 0) + EgtSetMachiningParam( MCH_MP.OFFSR, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchVId, false) + return false, sErr + end end - end - -- eventuale finitura faccia iniziale (parallela alla trave) - if nSide ~= -1 and bFirstTrim 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) - EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dWidth, 1)) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchV2Id, false) - return false, sErr + -- 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)) 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) + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dWidth, 1)) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchV2Id, false) + return false, sErr + end end end -- aggiorno ingombro testa o coda per presa diff --git a/LuaLibs/ProcessProfFront.lua b/LuaLibs/ProcessProfFront.lua index 70b459d..0081da2 100644 --- a/LuaLibs/ProcessProfFront.lua +++ b/LuaLibs/ProcessProfFront.lua @@ -1,4 +1,4 @@ --- ProcessProfFront.lua by Egaltech s.r.l. 2019/04/10 +-- ProcessProfFront.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo profilo caudato per Travi -- Tabella per definizione modulo @@ -82,10 +82,10 @@ function ProcessProfFront.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) end -- aggiungo taglio di lama di sgrossatura e lo lavoro local ptStart, vtNP = GetSawCutData( AuxId, vtN) - local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptStart, vtNP, b3Solid, GDB_RT.GLOB) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptStart, vtNP, b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- 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) diff --git a/LuaLibs/ProcessProfHead.lua b/LuaLibs/ProcessProfHead.lua index b6d5e58..75beeda 100644 --- a/LuaLibs/ProcessProfHead.lua +++ b/LuaLibs/ProcessProfHead.lua @@ -1,4 +1,4 @@ --- ProcessProfHead.lua by Egaltech s.r.l. 2020/01/04 +-- ProcessProfHead.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo profilo caudato per Travi -- Tabella per definizione modulo @@ -15,6 +15,14 @@ EgtOutLog( ' ProcessProfHead started', 1) local BD = require( 'BeamData') local ML = require( 'MachiningLib') +-- variabili assegnazione parametri Q +local sEnableExtraMillUpperFace = 'Q03' -- i +local sEnableExtraBladeUpperFace = '' -- i +local sDepthChamferMill = 'Q01' -- d +local sOverMaterialForFinish = 'Q04' -- d +local sPreemptiveChamfer = 'Q02' -- i +local sMachFacesUnderneath = 'Q99' -- i + --------------------------------------------------------------------- -- Riconoscimento della feature function ProcessProfHead.Identify( Proc) @@ -35,43 +43,111 @@ local function GetSawCutData( AuxId, vtN) end --------------------------------------------------------------------- -local function ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) +local function ModifySideAndInvertAndLead( Proc, bHead, dToolDiam, bNotModifLeadPar) -- confronto il punto iniziale e finale della lavorazione con il box della feature -- e se è vicino alla parte esterna della trave inverto la lavorazione ptSP = EgtGetMachiningStartPoint() ptEp = EgtGetMachiningEndPoint() - local nMachMode = EgtMdbGetCurrMachiningParam( MCH_MP.STEPTYPE) + local nMachMode = EgtGetMachiningParam( MCH_MP.STEPTYPE) if nMachMode == 1 and ptSP and ptEp then 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 = EgtMdbGetCurrMachiningParam( MCH_MP.WORKSIDE) + 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 -- ottengo l'inversione e setto il contrario - local bInvertMode = EgtMdbGetCurrMachiningParam( MCH_MP.INVERT) + local bInvertMode = EgtGetMachiningParam( MCH_MP.INVERT) EgtSetMachiningParam( MCH_MP.INVERT, not bInvertMode) -- modifico attacco e uscita - EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) - EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + if not bNotModifLeadPar then + EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) + EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + end -- riapplico la lavorazione EgtApplyMachining() else -- modifico attacco e uscita - EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) - EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) - EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) - EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) - -- riapplico la lavorazione - EgtApplyMachining() + if not bNotModifLeadPar then + EgtSetMachiningParam( MCH_MP.LIPERP, -(dToolDiam/2)) + EgtSetMachiningParam( MCH_MP.LITANG, (dToolDiam/2)+0.5) + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, 0) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, (dToolDiam/3*2)) + -- riapplico la lavorazione + EgtApplyMachining() + end end 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 then + nChamfer = 1 + end + -- verifico se posso fare solo lo smusso + if EgtGetInfo( Proc.Id, sOnlyCham, 'i') == 1 then + if dDepth > 0 then + nChamfer = nChamfer + 1 + -- altrimenti se non ho l'affondamento esco + else + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' 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) + local nCanVert = 0 + -- 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 on process ' .. tostring( Proc.Id) .. ' not horizontale chamfer' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped not horizontale chamfer' + EgtOutLog( sWarn) + return 0, dDepth + end + else + nCanVert = 1 + end + end + -- eseguo lo smusso solo se feature larga come la trave + if dWidth < EgtIf( nCanVert == 1, b3Raw:getDimZ(), b3Raw:getDimY()) - 1 then + if nChamfer == 2 then -- se devo fare solo smusso, genero errore + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' feature smaller than beam' + EgtOutLog( sErr) + return -1, dDepth, sErr + else + local sWarn = 'Warning on process ' .. tostring( Proc.Id) .. ' skipped chamfer (feature smaller than beam)' + EgtOutLog( sWarn) + return 0, dDepth + end + end + -- recupero la lavorazione + local sMilling = ML.FindMilling( 'Mark') + if not sMilling then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' chamfer not found in library' + EgtOutLog( sErr) + return -1, 0, sErr + end + + return nChamfer, dDepth, sMilling +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessProfHead.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) @@ -104,6 +180,7 @@ function ProcessProfHead.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtErase( CvxHullId) -- 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 @@ -126,90 +203,146 @@ function ProcessProfHead.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) EgtOutLog( sErr) return false, sErr end - -- aggiungo taglio di lama di sgrossatura e lo lavoro - local ptStart, vtNP = GetSawCutData( AuxId, vtN) - 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 + -- verifico se sono presenti i parametri Q per la profondità smusso e + -- per eseguire in esclusiva solo lo smusso + local nChamfer, dDepthCham, sChamfer = VerifyCham( Proc, AuxId, nRawId, false, 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 - -- recupero la lavorazione - local sMilling = ML.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 - -- Recupero i dati dell'utensile - local dToolMaxDepth = 0 - local dToolDiam = 0 - if EgtMdbSetCurrMachining( sMilling) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() - dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + -- se smusso non è esclusivo + if nChamfer < 2 then + -- aggiungo taglio di lama di sgrossatura e lo lavoro + local ptStart, vtNP = GetSawCutData( AuxId, vtN) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptStart, vtNP, b3Solid, GDB_RT.GLOB) + if AddId then + EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) + -- 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 end - -- verifico se necessario lavorare in doppio - local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) - local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) - -- 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 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 - -- 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 - 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 - 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 - ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) - end - -- se lavorazione da due parti, aggiungo la seconda - if bDouble then + -- se devo inserire il chamfer + if nChamfer > 0 then + local bDoubleCham = false + local dExtra = 2 -- inserisco la lavorazione - local sName = 'ProfB_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + 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 + -- 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 vtNF:getY() > 0.1) or + ( not bHead and vtNF: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) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvertAndLead( Proc, bHead, dMillDiam, true) + 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 nMchId = EgtAddMachining( sName, sChamfer) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sChamfer + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- assegno affondamento e offset radiale + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- allungo inizio e fine attacco + EgtSetMachiningParam( MCH_MP.STARTADDLEN, 10) + EgtSetMachiningParam( MCH_MP.ENDADDLEN, 10) + -- 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 + else + -- applico controllo del punto entrata lavorazione e se non è distante dall'esterno + -- della feature inverto il punto di inizio della lavorazione + ModifySideAndInvertAndLead( Proc, bHead, dMillDiam, true) + 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 on process ' .. tostring( Proc.Id) .. ' milling not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- Recupero i dati dell'utensile + local dToolMaxDepth = 0 + local dToolDiam = 0 + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dToolMaxDepth = EgtTdbGetCurrToolMaxDepth() + dToolDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) + end + end + -- verifico se necessario lavorare in doppio + local bDouble = ( nSide ~= 0 and dProfDepth + BD.CUT_EXTRA > dToolMaxDepth) + local dDepth = min( dToolMaxDepth, dProfDepth / 2 + BD.MILL_OVERLAP) + -- 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 @@ -218,17 +351,54 @@ function ProcessProfHead.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) end -- aggiungo geometria EgtSetMachiningGeometry( {{ AuxId, -1}}) - -- sempre lavorazione da sopra o da sotto - -- 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) + -- 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 - -- imposto l'affondamento - EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) -- posizione braccio porta testa EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- variabili per gestione direzione percorso e per gestione lavorazione di finitura opzionale + local ptSP, ptEp + local bFinish + local dOriOffset + local dOffsetPar = EgtGetInfo( Proc.Id, sOverMaterialForFinish, 'i') or 0 + -- se parametro sovramateriale è maggiore di 0 lo aggiungo al sovramateriale + if dOffsetPar > 0 then + dOriOffset = EgtMdbGetCurrMachiningParam( MCH_MP.OFFSR) or 0 + EgtSetMachiningParam( MCH_MP.OFFSR, ( dOriOffset + dOffsetPar)) + bFinish = true + end -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() @@ -240,88 +410,170 @@ function ProcessProfHead.Make( Proc, nPhase, nRawId, nPartId, dCurrOvmH) -- e uscita ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) end - end - -- eventuali finiture - if nSide ~= -1 and #vAngs > 0 then - -- dimensioni feature - local dLen = Proc.Box:getDimX() - local dDep = EgtIf( nSide == 1, Proc.Box:getDimZ(), Proc.Box:getDimY()) - -- se più alta che lunga - if dDep > dLen then - for i = 1, #vAngs do - sName = 'ProfV'.. tostring( i)..'_'..( 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 _, _, _, _, _, _, dElev = EgtSurfTmFacetOppositeSide( Proc.Id, vAngs[i], EgtIf( bHead, X_AX(), -X_AX()), GDB_ID.ROOT) - -- aggiungo geometria - EgtSetMachiningGeometry( {{ Proc.Id, vAngs[i]}}) - -- 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') + -- se abilitata, aggiungo lavorazione di finitura + if bFinish then + -- inserisco la lavorazione + local sNewName = 'Prof_Fin_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + else + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) EgtSetMachiningParam( MCH_MP.STEP, 0) - EgtSetMachiningParam( MCH_MP.OFFSR, 0) - EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dElev, 1)) - -- imposto posizione braccio - local nSCC = MCH_SCC.ADIR_YM - if nSide == 0 then - nSCC = EgtIf( vtN:getY() > 0, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) - end - EgtSetMachiningParam( MCH_MP.SCC, nSCC) -- eseguo if not EgtApplyMachining( true, false) then local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchV2Id, false) + EgtSetOperationMode( nMchId, false) return false, sErr end end - -- altrimenti - else - for i = 1, #vAngs do - sName = 'ProfV'.. tostring( i)..'_'..( EgtGetName( Proc.Id) or tostring( Proc.Id)) - local nMchVId = EgtAddMachining( sName, sMilling) - if not nMchVId then + end + -- se lavorazione da due parti, aggiungo la seconda + if bDouble then + -- inserisco la lavorazione + local sName = 'ProfB_' .. ( 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}}) + -- sempre lavorazione da sopra o da sotto + -- 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 + -- imposto l'affondamento + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + -- posizione braccio porta testa + EgtSetMachiningParam( MCH_MP.SCC, EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM)) + -- 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 EgtApplyMachining( 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 + ModifySideAndInvertAndLead( Proc, bHead, dToolDiam) + 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 nMchId = EgtCopyMachining( sNewName, sName) + if not nMchId then local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling EgtOutLog( sErr) return false, sErr - end - -- calcolo massima elevazione - local _, _, _, _, _, _, dElev = EgtSurfTmFacetOppositeSide( Proc.Id, vAngs[i]+1, vtN, GDB_ID.ROOT) - -- aggiungo geometria - EgtSetMachiningGeometry( {{ Proc.Id, vAngs[i]+1}}) - -- 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) else - EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_BACK) + -- riporto il sovramateriale originale e tolgo i passi + EgtSetMachiningParam( MCH_MP.OFFSR, dOriOffset) + EgtSetMachiningParam( MCH_MP.STEP, 0) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return false, sErr + end end - 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( dElev, 1)) - -- imposto posizione braccio - local nSCC = MCH_SCC.ADIR_YM - if nSide == 0 then - nSCC = EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) + 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 #vAngs > 0 then + -- dimensioni feature + local dLen = Proc.Box:getDimX() + local dDep = EgtIf( nSide == 1, Proc.Box:getDimZ(), Proc.Box:getDimY()) + -- se più alta che lunga o da sotto con il parametro Q abilitato + if (dDep > dLen) or ( nSide == -1 and EgtGetInfo( Proc.Id, sMachFacesUnderneath, 'i') == 1) then + for i = 1, #vAngs do + sName = 'ProfV'.. tostring( i)..'_'..( 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 _, _, _, _, _, _, dElev = EgtSurfTmFacetOppositeSide( Proc.Id, vAngs[i], EgtIf( bHead, X_AX(), -X_AX()), GDB_ID.ROOT) + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, vAngs[i]}}) + -- 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) + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dElev, 1)) + -- imposto posizione braccio + local nSCC = MCH_SCC.ADIR_YM + if nSide == 0 then + nSCC = EgtIf( vtN:getY() > 0, MCH_SCC.ADIR_YP, MCH_SCC.ADIR_YM) + end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchV2Id, false) + return false, sErr + end end - EgtSetMachiningParam( MCH_MP.SCC, nSCC) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchVId, false) - return false, sErr + -- altrimenti + else + for i = 1, #vAngs do + sName = 'ProfV'.. tostring( i)..'_'..( 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 _, _, _, _, _, _, dElev = EgtSurfTmFacetOppositeSide( Proc.Id, vAngs[i]+1, vtN, GDB_ID.ROOT) + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, vAngs[i]+1}}) + -- 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) + else + EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.PARAL_BACK) + end + 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( dElev, 1)) + -- imposto posizione braccio + local nSCC = MCH_SCC.ADIR_YM + if nSide == 0 then + nSCC = EgtIf( bHead, MCH_SCC.ADIR_XP, MCH_SCC.ADIR_XM) + end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchVId, false) + return false, sErr + end end end end diff --git a/LuaLibs/ProcessStepJoint.lua b/LuaLibs/ProcessStepJoint.lua index cedbdd4..e39641d 100644 --- a/LuaLibs/ProcessStepJoint.lua +++ b/LuaLibs/ProcessStepJoint.lua @@ -1,4 +1,4 @@ --- ProcessStepJoint.lua by Egaltech s.r.l. 2019/10/21 +-- ProcessStepJoint.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo giunto a gradino per Travi -- Tabella per definizione modulo @@ -117,20 +117,20 @@ local function MakeTwoFaces( Proc, nPhase, nRawId, nPartId, dOvmHead) vOrd = { 2, 1} end -- creo piano di taglio coincidente con la prima faccia e lo lavoro - local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[vOrd[1]], vtN[vOrd[1]], b3Solid, GDB_RT.GLOB) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vOrd[1]], vtN[vOrd[1]], b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- applico 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 -- creo piano di taglio coincidente con la seconda faccia e lo lavoro - AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[vOrd[2]], vtN[vOrd[2]], b3Solid, GDB_RT.GLOB) + AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[vOrd[2]], vtN[vOrd[2]], b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- applico 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) @@ -285,10 +285,10 @@ local function MakeThreeFaces( Proc, nPhase, nRawId, nPartId, dOvmHead) return false, sErr end -- creo piano di taglio coincidente con la faccia 2 e lo lavoro - local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC[3], vtN[3], b3Solid, GDB_RT.GLOB) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC[3], vtN[3], b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- applico 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) diff --git a/LuaLibs/ProcessTenon.lua b/LuaLibs/ProcessTenon.lua index 1c710c3..162fdbd 100644 --- a/LuaLibs/ProcessTenon.lua +++ b/LuaLibs/ProcessTenon.lua @@ -1,4 +1,4 @@ --- ProcessTenon.lua by Egaltech s.r.l. 2019/12/10 +-- ProcessTenon.lua by Egaltech s.r.l. 2020/02/07 -- Gestione calcolo tenone per Travi -- Tabella per definizione modulo @@ -130,10 +130,10 @@ function ProcessTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) return false, sErr end -- creo piano di taglio sulla testa del tenone e lo lavoro - local AddId = EgtSurfTmPlaneInBBox( EgtGetParent( Proc.Id), ptC, vtN, b3Solid, GDB_RT.GLOB) + local AddId = EgtSurfTmPlaneInBBox( nAddGrpId, ptC, vtN, b3Solid, GDB_RT.GLOB) if AddId then - EgtRelocate( AddId, nAddGrpId) EgtSetName( AddId, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( AddId, 'TASKID', Proc.TaskId) -- se pezzo piccolo, in coda e piano inclinato attorno a Z applico svuotatura if b3Solid:getDimX() < BD.LEN_SHORT_PART and vtExtr:getX() < 0 and abs( vtExtr:getY()) > 0.173 then local sPocketing = ML.FindPocketing( 'OpenPocket')