From 511201107e4bbd5f16e62ce8e70d6c9e63b153df Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 2 Apr 2020 15:01:14 +0000 Subject: [PATCH] DataBeam : - correzioni e migliorie varie. --- LuaLibs/BeamExec.lua | 7 +- LuaLibs/BeamLib.lua | 17 +++- LuaLibs/ProcessLapJoint.lua | 192 ++++++++++++++++++++++++++++++++---- 3 files changed, 191 insertions(+), 25 deletions(-) diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index eec3b5c..1a7d145 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -1,4 +1,4 @@ --- BeamExec.lua by Egaltech s.r.l. 2020/03/18 +-- BeamExec.lua by Egaltech s.r.l. 2020/04/02 -- Libreria esecuzione lavorazioni per Travi -- 2019/07/11 Aggiunta gestione stato rotazione di feature per TS3. -- 2019/09/04 Corretto controllo feature di testa e coda con sovramateriale di testa elevato. @@ -6,6 +6,7 @@ -- 2020/01/21 Aggiunta gestione ScarfJoint -- 2020/02/10 Aggiunta gestione FrenchRidgeLap -- 2020/02/11 Aggiunta gestione BlockHausFront +-- 2020/04/02 Fori di testa dal basso non danno errore e fanno ribaltare la trave. -- Tabella per definizione modulo local BeamExec = {} @@ -495,6 +496,7 @@ local function ClassifyFeatures( vProc, b3Raw, Stats) local Proc = vProc[i] local bOk = true local bDown = false + local bDownOnHeadOk = false -- se intestatura if Hcut.Identify( Proc) then nHeading = i @@ -525,6 +527,7 @@ local function ClassifyFeatures( vProc, b3Raw, Stats) -- se foratura elseif Drill.Identify( Proc) then bOk, bDown = Drill.Classify( Proc, b3Raw) + bDownOnHeadOk = true -- se tenone elseif Tenon.Identify( Proc) then bOk, bDown = Tenon.Classify( Proc, b3Raw) @@ -574,7 +577,7 @@ local function ClassifyFeatures( vProc, b3Raw, Stats) -- assegno risultato if bOk then -- non ammessa feature di testa da lavorare ribaltata - if Proc.Head and bDown then + if Proc.Head and bDown and not bDownOnHeadOk then Proc.Flg = 0 Proc.Down = true bAllOk = false diff --git a/LuaLibs/BeamLib.lua b/LuaLibs/BeamLib.lua index 1eb9a96..1ff0bb9 100644 --- a/LuaLibs/BeamLib.lua +++ b/LuaLibs/BeamLib.lua @@ -1,4 +1,4 @@ --- BeamLib.lua by Egaltech s.r.l. 2020/03/19 +-- BeamLib.lua by Egaltech s.r.l. 2020/03/20 -- Libreria globale per Travi -- Tabella per definizione modulo @@ -388,6 +388,7 @@ function BeamLib.GetFaceWithMostAdj( nSurfId, nPartId, bCompare3Fc) -- se 4 facce tutte con adiacenza 2, allora è un tunnel if nFacCnt == 4 then if vAdj[1] == 2 and vAdj[2] == 2 and vAdj[3] == 2 and vAdj[4] == 2 then + -- se tutte le facce sono ortogonali tra loro esco con un flag che ne indica questa propietà if vOrtho[1] == true and vOrtho[2] == true and vOrtho[3] == true and vOrtho[4] == true then return -1, GEO.INFINITO, true else @@ -395,8 +396,20 @@ function BeamLib.GetFaceWithMostAdj( nSurfId, nPartId, bCompare3Fc) end end end + -- se 3 facce con una che ha 2 adiacenze e le altre hanno 1 adiacenza, allora è una semi-fessura if bCompare3Fc and nFacCnt == 3 then - if vAdj[1] == 2 and vAdj[2] == 1 and vAdj[3] == 1 then + local nCount2Adc = 0 + local nCount1Adc = 0 + -- ottengo il numero di facce con due adiacenze e il numero di facce con una adiacenza + for i = 1, #vAdj do + if vAdj[i] == 2 then + nCount2Adc = nCount2Adc + 1 + elseif vAdj[i] == 1 then + nCount1Adc = nCount1Adc + 1 + end + end + -- se il numero di adiacenze corrisponde + if nCount2Adc == 1 and nCount1Adc == 2 then if vOrtho[1] == true and vOrtho[2] == true and vOrtho[3] == true then return -1, GEO.INFINITO, true else diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index 0060390..8c1a175 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -1733,11 +1733,10 @@ local function MakePocket( Proc, nPartId, ptPs, tvtN, nFaceRef, sMchFind, nUseRo local dCollSic = 2 * BD.COLL_SIC -- calcolo il diametro utensile local dDiamTool - if nUseRoughTool == 1 and tDimAndRef then - dDiamTool = max( 80, min( tDimAndRef[2][1], tDimAndRef[2][2])) - elseif tDimAndRef then - -- se non uso truciolatore prendo il valore dalle dimensioni minime delle facce - dDiamTool = min( tDimAndRef[2][1], tDimAndRef[2][2]) + local dFaceDiamTool + if tDimAndRef then + -- prendo il valore dalle dimensioni minime delle facce + dFaceDiamTool = min( tDimAndRef[2][1], tDimAndRef[2][2]) end -- se ho lavorazione precedente ricalcolo grossolanamente l'elevazione if dPrevFaceElev and dPrevFaceElev > 0 and dAng then @@ -1749,7 +1748,7 @@ local function MakePocket( Proc, nPartId, ptPs, tvtN, nFaceRef, sMchFind, nUseRo if sMasterPocket then sPocketing = sMasterPocket else - sPocketing = ML.FindPocketing( sMchFind, dDiamTool, dElev + dCollSic) + sPocketing = ML.FindPocketing( sMchFind, dFaceDiamTool, dElev + dCollSic) end if not sPocketing then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' pocketing not found in library' @@ -1766,6 +1765,10 @@ local function MakePocket( Proc, nPartId, ptPs, tvtN, nFaceRef, sMchFind, nUseRo dDiamTool = EgtTdbGetCurrToolParam( MCH_TP.DIAM) end end + -- se nome svuotatura non è stato ricalcolato, confronto il diametro utensile utilizzato con il minimo faccia e se non sono compatibili esco + if sMasterPocket and dFaceDiamTool and dDiamTool >= dFaceDiamTool then + return false, '', sTuuidPk, dDiamTool, dElev + end -- inserisco la lavorazione di svuotatura local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. 'F' .. tostring( nFaceRef) local nMchFId = EgtAddMachining( sName, sPocketing) @@ -1830,11 +1833,66 @@ local function MachineByMill( Proc, nPhase, nRawId, nPartId, b3Solid, tvtN, nBas end -- se angolo tra le facce maggiore di 90, inserisco la contornatura o svuotatura del lato più corto if ( 180 + dAng) > 90.1 then - -- se la normale della faccia corta si discosta dalla trave di più di 45° utilizzo la svutatura altrimenti la contornatura - if abs( tvtN[2]:getX()) < cos(dAngLimit) then -- se si discosta di più di 30° applico svuotatura + -- calcolo l'angolo dalla verticale dall'angolo tra le due facce, perchè la feature potrebbe essere ruotata sulla Z locale della + -- faccia principale e quindi la componente X del versore della faccia potrebbe dare un valore non coerente + local dDiffFromSqAng = 180 + dAng - 90 + -- se la normale della faccia corta si discosta dalla trave di più dell'angolo selezionato utilizzo la svutatura altrimenti la contornatura +-- if abs( tvtN[2]:getX()) < cos(dAngLimit) then -- se si discosta di più del valore impostato applico svuotatura + -- se l'angolo dalla verticale si discosta di più dell'angolo limite impostato, utilizzo la svuotatura + if cos( dDiffFromSqAng) < cos(dAngLimit) then -- se si discosta di più del valore impostato applico svuotatura -- applico la svuotatura - return MakePocket( Proc, nPartId, ptPs, tvtN, nSideFace, sMchFind, nUseRoughTool, sPocketing, dPrevFaceElev, tDimAndRef, dAng) - -- altrimenti contornatura + local bOk, sWarn, sTuuidPk, dDiamTool, dElev = MakePocket( Proc, nPartId, ptPs, tvtN, nSideFace, sMchFind, nUseRoughTool, sPocketing, dPrevFaceElev, tDimAndRef, dAng) + if not bOk then + -- se ho id utensile e diametro è perchè non ha fatto svuotatura perchè la faccia è più stretta del diametro utensile + -- e provo ad inserire singola passata di testa + if sTuuidPk and dDiamTool then + -- recupero la lavorazione + local sMilling = ML.FindMilling( 'Long2Cut', dElev, sTuuidPk) + if not sMilling then + local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' milling not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- inserisco la lavorazione + local sName = 'Prof_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchId = EgtAddMachining( sName, sMilling) + if not nMchId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nSideFace}}) + -- imposto uso faccia + local nFaceUse = BL.GetNearestOrthoOpposite(tvtN[1]) + -- aggiusto i parametri + EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) + EgtSetMachiningParam( MCH_MP.DEPTH_STR, 'TH') + EgtSetMachiningParam( MCH_MP.OFFSR, 0) + EgtSetMachiningParam( MCH_MP.INVERT, false) + EgtSetMachiningParam( MCH_MP.WORKSIDE, 1) + -- imposto posizione braccio porta testa + if tvtN[2]:getY() < GEO.EPS_SMALL then + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) + else + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) + end + -- imposto elevazione e dichiaro non si generano sfridi per VMill + local sNotes = 'MaxElev=' .. EgtNumToString( dElev, 1) .. ';' + sNotes = sNotes .. 'VMRS=0;' + EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + end + else + return false, sWarn + end + else + return bOk, sWarn + end + -- altrimenti contornatura di fianco else local bOpenStart = false local bOpenEnd = false @@ -2255,6 +2313,73 @@ local function ExtractExternalPaths( nPathInt, nNumIdAux, vtOrtho, b3Solid, nAdd return nil, 0, nil end +--------------------------------------------------------------------- +local function CheckPocketTool( sMchFind, dDiam, dElev) + + local sPocketing = ML.FindPocketing( sMchFind, dDiam, dElev) + if sPocketing then + -- recupero i dati dell'utensile + local dTDiam = 50 + if EgtMdbSetCurrMachining( sPocketing) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + dTDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dTDiam + return true, dTDiam + end + end + return false +end + +--------------------------------------------------------------------- +local function CheckDiamToolByFaces( Proc, nFacInd, dH, dV, bIsU, bIsL, dElev) + local bUSAngle + local dDiam = min( dH, dV) + local dMaxLenFace = max( dH, dV) + -- verifico che diametro utensile prende con la openpocket con la massima dimensione faccia + local bUseMaxTool, dMaxDiam = CheckPocketTool( 'OpenPocket', dMaxLenFace, dElev) + -- se non trovato utensile esco + if not bUseMaxTool then + return false + end + -- Recupero le facce adiacenti alla principale + local vAdj = EgtSurfTmFacetAdjacencies( Proc.Id, nFacInd)[1] + -- se non ho facce adiacenti esco subito + if not vAdj or #vAdj == 0 then + return false + end + -- Cerco le facce adiacenti alla principale con angolo >= 90 + local nFacAdj + local tDistAdj = {} + for i = 1, #vAdj do + if vAdj[i] >= 0 then + local bAdj, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, nFacInd, vAdj[i], GDB_ID.ROOT) + -- se adiacenza e angolo >= 90 + if bAdj and dAng < 0 and 180 + dAng > 90 - 20 * GEO.EPS_SMALL then + table.insert( tDistAdj, dist( ptP1, ptP2)) + elseif bAdj and dAng < 0 and 180 + dAng < 90 - 20 * GEO.EPS_SMALL then + -- se trovato angolo sottosquadra esco subito + return false + end + end + end + -- se le facce di adiacenza non corrispondono con quelle della forma esco + if ( bIsU and #tDistAdj ~= 2) or ( bIsL and #tDistAdj ~= 1) then + return false + end + local bUseMaxDist = true + for i = 1, #tDistAdj do + -- se trovo una lunghezza di adiacenza sul lato lungo e diametro minimo inferiore di quello massimo trovato + -- setto di non utilizzare il diametro massimo + if tDistAdj[i] > dMaxLenFace - 20 * GEO.EPS_SMALL and dDiam < dMaxDiam + 10 * GEO.EPS_SMALL then + bUseMaxDist = false + end + end + if bUseMaxDist then + return dMaxDiam, 'OpenPocket', 1 + end + + return false +end + --------------------------------------------------------------------- local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, sMchFindMaster, b3FacesUsed, b3Solid, bOrthoFacesMaster) @@ -2858,8 +2983,11 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSingle_part) if not bOk then return false, sErr end end -- recupero la lavorazione + local dCollSic = 2 * BD.COLL_SIC + if abs( vtN:getX()) > 0.996 or abs( vtN:getY()) > 0.996 or abs( vtN:getZ()) > 0.996 then dCollSic = 0 end local nUseRoughTool = 0 local sMchFind = 'Pocket' + local dDiam -- se processo 20 vedo se ho truciolatore abilitato if Proc.Prc == 20 then -- se forzato uso truciolatore altrimenti prosegue con fresa più piccola @@ -2867,22 +2995,44 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSingle_part) sMchFind = 'OpenPocket' nUseRoughTool = 1 end + dDiam = min( dH, dV) else - -- Se feature lavorata in singolo passo uso fresa (richiesta di Alessandro) - if bSingle_part and not bIsL and not bIsU then + -- Da disposizini di Alessandro, se feature lavorata in singolo passo uso fresa + if bSingle_part then -- disabilito il truciolatore sMchFind = 'Pocket' nUseRoughTool = 0 - -- altrimenti va lavorata in passo multiplo + -- verifico dalla forma se posso prendere utensile più grande + if ( Proc.Fct == 3 and bIsU) or ( Proc.Fct == 2 and bIsL) then + --verifico dimensioni facce adiacenti + dDiam, sMchFind, nUseRoughTool = CheckDiamToolByFaces( Proc, nFacInd, dH, dV, bIsU, bIsL, ( dFacElev + dCollSic)) + if not dDiam then + dDiam = min( dH, dV) + sMchFind = 'Pocket' + nUseRoughTool = 0 + end + else + dDiam = min( dH, dV) + end + -- altrimenti le lavorata in passo multiplo else -- abilito il truciolatore sMchFind = 'OpenPocket' nUseRoughTool = 1 + -- verifico dalla forma se posso prendere utensile più grande + if ( Proc.Fct == 3 and bIsU) or ( Proc.Fct == 2 and bIsL) or ( Proc.Fct == 1 and not bIsU and not bIsL) then + --verifico dimensioni facce adiacenti + dDiam, sMchFind, nUseRoughTool = CheckDiamToolByFaces( Proc, nFacInd, dH, dV, bIsU, bIsL, ( dFacElev + dCollSic)) + if not dDiam then + dDiam = min( dH, dV) + sMchFind = 'Pocket' + nUseRoughTool = 0 + end + else + dDiam = min( dH, dV) + end end end - local dDiam = min( dH, dV) - local dCollSic = 2 * BD.COLL_SIC - if abs( vtN:getX()) > 0.996 or abs( vtN:getY()) > 0.996 or abs( vtN:getZ()) > 0.996 then dCollSic = 0 end --EgtOutLog( 'Mortise Find Diam =' .. EgtNumToString( dDiam)) local sPocketing = ML.FindPocketing( sMchFind, dDiam, dFacElev + dCollSic) -- se non trova una svuotatura adatta @@ -2893,7 +3043,7 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSingle_part) if nChamfer < 2 then return MakeByMill( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dFacElev) end - -- altrimenti provo con la sega a catena o lama + -- altrimenti, in base alla forma, provo con svuotature di fianco o con la sega a catena o lama else local bTryWithBlades = true local nOk, bOk, sStat, sErr, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces @@ -2932,10 +3082,11 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSingle_part) -- se richiesti antischeggia con lama su U trasversale e smusso non esclusivo -- rimane da gestire: se da eseguire con fresa o se richiesto lama ma impossibile utilizzarla, si utilizza fresa local bMadeASbyBld = false - if nChamfer < 2 and EgtGetInfo( Proc.Id, sAntisplintMode, 'i') == 1 and bIsU and + if nChamfer < 2 and EgtGetInfo( Proc.Id, sAntisplintMode, 'i') == 1 and ( bIsU or bIsL) and ( Proc.Box:getDimY() > b3Raw:getDimY() - 1 or Proc.Box:getDimZ() > b3Raw:getDimZ() - 1) then + local nNumFac = EgtIf( bIsU, 2, 1) -- va eseguito sulle facce diverse dalla principale - for nFacet = 0, 2 do + for nFacet = 0, nNumFac do if nFacet ~= nFacInd then bMadeASbyBld, sWarn = MakeAntiSplintBySaw( Proc, nFacet, vtN, b3Raw) if not bMadeASbyBld then return false, sWarn end @@ -2951,7 +3102,6 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSingle_part) local bOk bOk, sWarn, sTuuidPk, dDiamTool = MakePocket( Proc, nPartId, ptC, tvtNx, nFacInd, sMchFind, nUseRoughTool, sPocketing, dFacElev) if not bOk then return false, sWarn end - -- se ho più di 3 facce e non di forma ad u oppure ho 3 facce e di forma ad u -- e non sono stati inseriti antischeggia di lama -- controllo se c'è una faccia non ortogonale alla principale e la lavoro con una contornatura o svuotatura @@ -3046,8 +3196,8 @@ local function MakeLongMoreFaces( Proc, nPhase, nRawId, nPartId) local nFct = EgtSurfTmFacetCount( vAddId[i]) local AddProc = { Id = vAddId[i], Grp = Proc.Grp, Prc = Proc.Prc, Box = b3Box, Fct = nFct, Flg = Proc.Flg} local bOk, sMyWarn = MakeMoreFaces( AddProc, nPhase, nRawId, nPartId, false) - if not bOk then return bOk, sWarn end if not sWarn then sWarn = sMyWarn end + if not bOk then return bOk, sWarn end end return true, sWarn end