From f2a039373ac04545582cba1ec2934fca78aafa0f Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 7 Sep 2020 18:08:05 +0000 Subject: [PATCH] DataBeam : - migliorato calcolo elevazione di feature con 1 sola faccia - lavorazione faccia superiore di tenone con svuotature successive se pezzo corto - miglioramenti a LapJoint. --- LuaLibs/BeamLib.lua | 15 +- LuaLibs/ProcessDtTenon.lua | 83 ++++- LuaLibs/ProcessLapJoint.lua | 696 +++++++++++++++++++----------------- 3 files changed, 453 insertions(+), 341 deletions(-) diff --git a/LuaLibs/BeamLib.lua b/LuaLibs/BeamLib.lua index 79cf079..348a82d 100644 --- a/LuaLibs/BeamLib.lua +++ b/LuaLibs/BeamLib.lua @@ -1,4 +1,4 @@ --- BeamLib.lua by Egaltech s.r.l. 2020/08/18 +-- BeamLib.lua by Egaltech s.r.l. 2020/09/07 -- Libreria globale per Travi -- 2020/07/28 Corretto calcolo attacchi e uscite di lame per non uscire dalla faccia sotto. -- 2020/08/18 Aggiunto a GetNearestParalOpposite e GetNearestOrthoOpposite parametro opzionale vtNorm. @@ -390,9 +390,16 @@ function BeamLib.GetFaceElevation( nSurfId, nFac, nPartId) local b3Box = EgtGetBBoxRef( nSurfId, GDB_BB.STANDARD, frOCS) local dElev = b3Box:getDimZ() if nPartId then - local _, dCenElev = BeamLib.GetPointDirDepth( nPartId, ptC, vtN) - if dCenElev and dCenElev > dElev then - dElev = dCenElev + if EgtSurfTmFacetCount( nSurfId) > 1 then + local _, dCenElev = BeamLib.GetPointDirDepth( nPartId, ptC, vtN) + if dCenElev and dCenElev > dElev then + dElev = dCenElev + end + else + local b3Solid = EgtGetBBoxRef( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD, frOCS) + if b3Solid and b3Solid:getMax():getZ() > dElev then + dElev = b3Solid:getMax():getZ() + end end end return dElev diff --git a/LuaLibs/ProcessDtTenon.lua b/LuaLibs/ProcessDtTenon.lua index b877290..63a7fef 100644 --- a/LuaLibs/ProcessDtTenon.lua +++ b/LuaLibs/ProcessDtTenon.lua @@ -71,6 +71,38 @@ function ProcessDtTenon.Classify( Proc, b3Raw) return true, bDown end +--------------------------------------------------------------------- +local function ApplyPocket( Proc, sPocketing, nStep, dSurfStep, nIdSurf, vtExtr) + + -- inserisco la lavorazione di svuotatura + local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. nStep + local nMchFId = EgtAddMachining( sName, sPocketing) + if not nMchFId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ nIdSurf, -1}}) + -- imposto uso faccia + EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT) + if dSurfStep > 0 then + -- imposto elevazione + local sNotes = 'MaxElev=' .. EgtNumToString( dSurfStep, 2) .. ';' + EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) + end + -- imposto posizione braccio porta testa + local nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + end + + return true +end + --------------------------------------------------------------------- -- Applicazione della lavorazione function ProcessDtTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) @@ -130,25 +162,42 @@ function ProcessDtTenon.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) -- 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') - -- inserisco la lavorazione di svuotatura - local sName = 'Pock_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) - local nMchFId = EgtAddMachining( sName, sPocketing) - if not nMchFId then - local sErr = 'Error adding machining ' .. sName .. '-' .. sPocketing - EgtOutLog( sErr) + local dMaxDepth = 100 + local dStep = 30 + local nSurfStep + -- acquisisco i dati necessari dall'utensile + if EgtMdbSetCurrMachining( sPocketing) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + dStep = EgtMdbGetCurrMachiningParam( MCH_MP.STEP) or dStep + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth + end + end + -- acquisisco elevazione + local dElev = BL.GetFaceElevation( AddId, 0, nPartId) + nSurfStep = ceil( dElev / dMaxDepth) + dSurfStep = dElev / nSurfStep + local bOk = true + local sErr + -- copio superfice al passo superfice e ci applico la lavorazione + for i = nSurfStep, 2, -1 do + local nAddIdTmp = EgtSurfTmPlaneInBBox( nAddGrpId, ptC+((dSurfStep*(i-1))*vtN), vtN, b3Solid, GDB_RT.GLOB) + if nAddIdTmp then + EgtSetName( nAddIdTmp, 'AddCut_' .. tostring( Proc.Id)) + EgtSetInfo( nAddIdTmp, 'TASKID', Proc.TaskId) + -- aggiungo lavorazione + bOk, sErr = ApplyPocket( Proc, sPocketing, i, (dSurfStep + 0), nAddIdTmp, vtExtr) + if not bOk then + break + end + end + end + if not bOk then return false, sErr end - -- aggiungo geometria - EgtSetMachiningGeometry( {{ AddId, -1}}) - -- imposto uso faccia - EgtSetMachiningParam( MCH_MP.FACEUSE, MCH_MILL_FU.ORTHO_CONT) - -- imposto posizione braccio porta testa - local nSCC = EgtIf( vtExtr:getX() < GEO.EPS_SMALL, MCH_SCC.ADIR_XM, MCH_SCC.ADIR_XP) - EgtSetMachiningParam( MCH_MP.SCC, nSCC) - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchFId, false) + -- faccio ultima superfice + bOk, sErr = ApplyPocket( Proc, sPocketing, 1, EgtIf( nSurfStep > 1, ( dSurfStep + 0), 0), AddId, vtExtr) + if not bOk then return false, sErr end -- altrimenti applico taglio di lama diff --git a/LuaLibs/ProcessLapJoint.lua b/LuaLibs/ProcessLapJoint.lua index 2ef6294..b1df962 100644 --- a/LuaLibs/ProcessLapJoint.lua +++ b/LuaLibs/ProcessLapJoint.lua @@ -34,6 +34,9 @@ local sMakeOnlyContourOrFullPocket = '' -- i local sMakeBySideRoughTool = '' -- i local sAntisplintMode = '' -- i +-- variabile smussi +local bMadeChamfer + -- Settaggi interni local bTrySidePocketAtFirst = true @@ -1536,8 +1539,360 @@ local function MakeDrillOnCorner( Proc, nPhase, nRawId, nPartId, b3Raw, nFacInd, end --------------------------------------------------------------------- -local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dElev, bForceUseBlade, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces, nBottomFace) +local function ExtractExternalPaths( nPathInt, nNumIdAux, vtOrtho, b3Solid, nAddGrpId) + local nAuxId1, nAuxId2 + if nNumIdAux == 1 then + -- fondo tra loro le curve compatibili + EgtMergeCurvesInCurveCompo( nPathInt) + -- esplodo il percorso in modo da avere entià separate per poterle controllare + local nStartId, nNumIds = EgtExplodeCurveCompo( nPathInt) + if nStartId then + local sDeleteByDir + -- Se normale lungo la Z elimino le entità che hanno differenza in Z + if abs(vtOrtho:getZ()) > 0.7 then + sDeleteByDir = 'Z' + -- altrimenti se normale lungo la Y elimino le entità che hanno variazione in Y +-- elseif abs(vtOrtho:getZ()) < 0.001 and abs(vtOrtho:getY()) > 0.7 then + elseif abs(vtOrtho:getY()) > 0.7 then + sDeleteByDir = 'Y' + -- caso che non dovrebbe mai capitare ma gestito per completezza + -- altrimenti se normale lungo la X elimino le entità che hanno variazione in X +-- elseif abs(vtOrtho:getZ()) < 0.001 and abs(vtOrtho:getX()) > 0.7 then + elseif abs(vtOrtho:getX()) > 0.7 then + sDeleteByDir = 'X' + end + if sDeleteByDir then + for i = 1, nNumIds do + local ptP1 = EgtSP( ( nStartId + i - 1), GDB_RT.GLOB) + local ptP2 = EgtEP( ( nStartId + i - 1), GDB_RT.GLOB) + if sDeleteByDir == 'Z' then + -- se hanno variazione in Z cancello l'entità + if abs( ptP1:getZ() - ptP2:getZ()) > 10 * GEO.EPS_SMALL then + EgtErase( nStartId + i - 1) + end + elseif sDeleteByDir == 'Y' then + -- se hanno variazione in Y cancello l'entità + if abs( ptP1:getY() - ptP2:getY()) > 10 * GEO.EPS_SMALL then + EgtErase( nStartId + i - 1) + end + elseif sDeleteByDir == 'X' then + -- se hanno variazione in X cancello l'entità + if abs( ptP1:getX() - ptP2:getX()) > 10 * GEO.EPS_SMALL then + EgtErase( nStartId + i - 1) + end + end + end + -- ricreo i vari percorsi + local dLocalVal + local tPaths = {} + local nNumPaths + local dMaxVal + local dMinVal + for i = 1, nNumIds do + local ptP1 = EgtSP( ( nStartId + i - 1), GDB_RT.GLOB) + if ptP1 then + if sDeleteByDir == 'Z' then + local bInsTab + for j = 1, #tPaths do + local dLocalVal = tPaths[j][2] + if abs( ptP1:getZ() - dLocalVal) < 10 * GEO.EPS_SMALL then + local tLocIds = tPaths[j][1] + table.insert( tLocIds, ( nStartId + i - 1)) + tPaths[j][1] = tLocIds + bInsTab = true + end + end + -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella + if not bInsTab then + table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getZ()}) + dMaxVal = b3Solid:getMax():getZ() + dMinVal = b3Solid:getMin():getZ() + end + elseif sDeleteByDir == 'Y' then + local bInsTab + for j = 1, #tPaths do + local dLocalVal = tPaths[j][2] + if abs( ptP1:getY() - dLocalVal) < 10 * GEO.EPS_SMALL then + local tLocIds = tPaths[j][1] + table.insert( tLocIds, ( nStartId + i - 1)) + tPaths[j][1] = tLocIds + bInsTab = true + end + end + -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella + if not bInsTab then + table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getY()}) + dMaxVal = b3Solid:getMax():getY() + dMinVal = b3Solid:getMin():getY() + end + elseif sDeleteByDir == 'X' then + local bInsTab + for j = 1, #tPaths do + local dLocalVal = tPaths[j][2] + if abs( ptP1:getX() - dLocalVal) < 10 * GEO.EPS_SMALL then + local tLocIds = tPaths[j][1] + table.insert( tLocIds, ( nStartId + i - 1)) + tPaths[j][1] = tLocIds + bInsTab = true + end + end + -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella + if not bInsTab then + table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getX()}) + dMaxVal = b3Solid:getMax():getX() + dMinVal = b3Solid:getMin():getX() + end + end + end + end + + if tPaths then + local tChamPath = {} + -- elimino quelle che non corrispondono agli estremi + for i = 1, #tPaths do + -- se non corrisponde ai limiti elimino l'elemento + if abs( tPaths[i][2] - dMaxVal) > 10 * GEO.EPS_SMALL and abs( tPaths[i][2] - dMinVal) > 10 * GEO.EPS_SMALL then + tPaths[i] = nil + end + end + + for i = 1, #tPaths do + if tPaths[i] then + local tNoMatch = {} + local tPathLoc = tPaths[i][1] + local pIniLoc = EgtSP( tPathLoc[1], GDB_RT.GLOB) + local pEndLoc = EgtEP( tPathLoc[1], GDB_RT.GLOB) + -- ciclo sui percorsi per trovare i punti non coincidenti (se percorso non chiuso) + for j = 2, #tPathLoc do + -- prendo i punti del percorso successivo + local pAddIni = EgtSP( tPathLoc[j], GDB_RT.GLOB) + local pAddEnd = EgtEP( tPathLoc[j], GDB_RT.GLOB) + -- se consecutivi + if AreSamePointApprox( pEndLoc, pAddIni) then + pEndLoc = pAddEnd + elseif AreSamePointApprox( pIniLoc, pAddEnd) then + pIniLoc = pAddIni + else + table.insert( tNoMatch, tPathLoc[j]) + end + end + -- controllo eventuali percorsi scartati + for j = 1, #tNoMatch do + -- prendo i punti del percorso successivo + local pAddIni = EgtSP( tNoMatch[j], GDB_RT.GLOB) + local pAddEnd = EgtEP( tNoMatch[j], GDB_RT.GLOB) + -- se consecutivi + if AreSamePointApprox( pEndLoc, pAddIni) then + pEndLoc = pAddEnd + elseif AreSamePointApprox( pIniLoc, pAddEnd) then + pIniLoc = pAddIni + end + end + -- creo concatenamento partendo dal punto iniziale + local nIdLoc = EgtCurveCompoByReorder( nAddGrpId, tPathLoc, pIniLoc, true) + if nIdLoc then + table.insert( tChamPath, nIdLoc) + end + end + end + for i = 1, #tChamPath do + local ptP1 = EgtSP( tChamPath[i], GDB_RT.GLOB) + -- modifico estrusione percorso + if sDeleteByDir == 'Z' then + if abs(ptP1:getZ() - dMaxVal) < 10 * GEO.EPS_SMALL then + EgtModifyCurveExtrusion( tChamPath[i], Z_AX(), GDB_RT.GLOB) + else + EgtModifyCurveExtrusion( tChamPath[i], -Z_AX(), GDB_RT.GLOB) + end + elseif sDeleteByDir == 'Y' then + if abs(ptP1:getY() - dMaxVal) < 10 * GEO.EPS_SMALL then + EgtModifyCurveExtrusion( tChamPath[i], Y_AX(), GDB_RT.GLOB) + else + EgtModifyCurveExtrusion( tChamPath[i], -Y_AX(), GDB_RT.GLOB) + end + elseif sDeleteByDir == 'X' then + if abs(ptP1:getX() - dMaxVal) < 10 * GEO.EPS_SMALL then + EgtModifyCurveExtrusion( tChamPath[i], X_AX(), GDB_RT.GLOB) + else + EgtModifyCurveExtrusion( tChamPath[i], -X_AX(), GDB_RT.GLOB) + end + end + end + if #tChamPath == 1 then + return tChamPath[1], 1, nil + elseif #tChamPath == 2 then + return tChamPath[1], 2, tChamPath[2] + else + for i = 1, nNumIds do + EgtErase( nStartId + i - 1) + end + for i = 1, #tChamPath do + EgtErase( tChamPath[i]) + end + end + else + for i = 1, nNumIds do + EgtErase( nStartId + i - 1) + end + end + -- altrimenti cancello tutte le emtità e restituisco nil + else + for i = 1, nNumIds do + EgtErase( nStartId + i - 1) + end + end + end + end + + return nil, 0, nil +end + +--------------------------------------------------------------------- +local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) + + -- Se variabile globale indica che lo smusso è gi stato fatto, esco + if bMadeChamfer then + return 0 + end + bMadeChamfer = true + -- recupero la lavorazione + local sMilling = ML.FindMilling( 'Mark') + if not sMilling then + local sErr = 'Error : chamfer not found in library' + EgtOutLog( sErr) + return -1, sErr + end + -- ottengo le curve di contorno libero + local nAuxId1, nAuxId2, nNumIdAux + if b3FacesUsed then +-- nAuxId1, _ = EgtExtractSurfTmLoops( nSurfInt, nAddGrpId) +-- EgtModifyCurveExtrusion( nAuxId1, vtOrtho, GDB_RT.GLOB) +-- SetOpenSide( nAuxId1, vtOrtho, b3Solid, nAddGrpId, true) +-- nNumIdAux = 2 + + -- estraggo i percorsi + nAuxId1, nNumIdAux = EgtExtractSurfTmLoops( Proc.Id, nAddGrpId) + -- se percorso creato estraggo solo i percorsi delle facce interessate, non di testa + if nAuxId1 then + nAuxId1, nNumIdAux, nAuxId2 = ExtractExternalPaths( nAuxId1, nNumIdAux, vtOrtho, b3Solid, nAddGrpId) + end + else + nAuxId1, nNumIdAux = EgtExtractSurfTmLoops( Proc.Id, nAddGrpId) + if not nNumIdAux then nNumIdAux = 0 end + end + + local dExtra = 2 + for i = 1, nNumIdAux do + local AuxId + local vtExtr + if b3FacesUsed then + if i == 1 then + AuxId = nAuxId1 + else + -- faccio la copia del percorso +-- AuxId = EgtCopyGlob( nAuxId1, nAddGrpId) + AuxId = nAuxId2 + end + if AuxId then + vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) + end + else + AuxId = nAuxId1 + i - 1 + vtExtr, _, _ = EgtCurveArea( AuxId) + end + if vtExtr then + if not b3FacesUsed then + local fFrCurve = EgtGetGlobFrame( AuxId) + vtExtr:toGlob( fFrCurve) + end +-- if b3FacesUsed and i == nNumIdAux then +-- vtExtr = -vtExtr +-- end + -- Se normale entro certi limiti +-- if vtExtr:getZ() > -0.707 and ( abs(vtOrtho:getX()) > 0.99 or abs(vtOrtho:getY()) > 0.99 or abs(vtOrtho:getZ()) > 0.99) then + if vtExtr:getZ() > -0.707 and ( abs(vtExtr:getX()) > 0.99 or abs(vtExtr:getY()) > 0.99 or abs(vtExtr:getZ()) > 0.99) then + -- inserisco la lavorazione + local sNameCh = 'Cham_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) + local nMchId = EgtAddMachining( sNameCh, sMilling) + if not nMchId then + local sErr = 'Error adding machining ' .. sNameCh .. '-' .. sMilling + EgtOutLog( sErr) + return -1, sErr + end + -- modifico estrusione percorso + EgtModifyCurveExtrusion( AuxId, vtExtr, GDB_RT.GLOB) + -- aggiungo geometria + EgtSetMachiningGeometry( {{ AuxId, -1}}) + -- imposto posizione braccio porta testa + if vtExtr:getY() < GEO.EPS_SMALL then + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) + else + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) + end + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + -- assegno affondamento e offset radiale +-- EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra - EgtIf( b3FacesUsed, (dDepth / 2), 0)) + EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) + EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) + -- se opero su 3 facce e sono al secondo e ultimo percorso inverto la lavorazione +-- if b3FacesUsed and i == nNumIdAux then +-- EgtSetMachiningParam( MCH_MP.INVERT, true) +-- end + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchId, false) + return -1, sErr + end + -- se non perpendicolare emetto un warning + -- else + -- sWarn = 'Warning : chamfer skipped because not perpendicular to face or from bottom' + -- EgtOutLog( sWarn) + end + --emetto un warning + -- else + -- sWarn = 'Warning : chamfer skipped because not perpendicular to face' + -- EgtOutLog( sWarn) + end + end + + return 0 +end + +--------------------------------------------------------------------- +local function MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, + rfFac, dH, dV, dElev, bForceUseBlade, + dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, + bOrthoFacesMaster, nBottomFace, nChamfer, nAddGrpId, b3Solid, + dDepthCham, b3FacesUsed) + local bOrthoFaces local sWarn + if b3FacesUsed then + -- recupero la faccia con il maggior numero di adiacenze e l'elevazione relativa + local nFacInd1, dFacElev1, nFacInd2, dFacElev2 = BL.GetFaceWithMostAdj( Proc.Id, nPartId, b3FacesUsed) + if not nFacInd1 or nFacInd1 < 0 then + if nFacInd1 == -1 then + bOrthoFaces = nFacInd2 + else + local sErr = 'Error : MakeByPockets could not find reference face' + EgtOutLog( sErr) + return false, sErr + end + end + else + bOrthoFaces = bOrthoFacesMaster + end + + if bOrthoFaces then + -- ottengo le dimensioni del tunnel + _, _, _, vtOrtho, _, nSurfInt = GetTunnelDimension( Proc, nPartId) + -- verifico la direzione + -- se devo inserire il chamfer + if nChamfer > 0 then + local nOk, sErr = MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) + if nOk < 0 then return false, sErr end + end + end -- Recupero le facce adiacenti alla principale local vAdj = EgtSurfTmFacetAdjacencies( Proc.Id, nFacInd)[1] if not vAdj or #vAdj == 0 then @@ -2239,215 +2594,6 @@ local function SetOpenSide( nPathInt, vtOrtho, b3Solid, nAddGrpId, bStartPoint) end end ---------------------------------------------------------------------- -local function ExtractExternalPaths( nPathInt, nNumIdAux, vtOrtho, b3Solid, nAddGrpId) - local nAuxId1, nAuxId2 - if nNumIdAux == 1 then - -- fondo tra loro le curve compatibili - EgtMergeCurvesInCurveCompo( nPathInt) - -- esplodo il percorso in modo da avere entià separate per poterle controllare - local nStartId, nNumIds = EgtExplodeCurveCompo( nPathInt) - if nStartId then - local sDeleteByDir - -- Se normale lungo la Z elimino le entità che hanno differenza in Z - if abs(vtOrtho:getZ()) > 0.7 then - sDeleteByDir = 'Z' - -- altrimenti se normale lungo la Y elimino le entità che hanno variazione in Y --- elseif abs(vtOrtho:getZ()) < 0.001 and abs(vtOrtho:getY()) > 0.7 then - elseif abs(vtOrtho:getY()) > 0.7 then - sDeleteByDir = 'Y' - -- caso che non dovrebbe mai capitare ma gestito per completezza - -- altrimenti se normale lungo la X elimino le entità che hanno variazione in X --- elseif abs(vtOrtho:getZ()) < 0.001 and abs(vtOrtho:getX()) > 0.7 then - elseif abs(vtOrtho:getX()) > 0.7 then - sDeleteByDir = 'X' - end - if sDeleteByDir then - for i = 1, nNumIds do - local ptP1 = EgtSP( ( nStartId + i - 1), GDB_RT.GLOB) - local ptP2 = EgtEP( ( nStartId + i - 1), GDB_RT.GLOB) - if sDeleteByDir == 'Z' then - -- se hanno variazione in Z cancello l'entità - if abs( ptP1:getZ() - ptP2:getZ()) > 10 * GEO.EPS_SMALL then - EgtErase( nStartId + i - 1) - end - elseif sDeleteByDir == 'Y' then - -- se hanno variazione in Y cancello l'entità - if abs( ptP1:getY() - ptP2:getY()) > 10 * GEO.EPS_SMALL then - EgtErase( nStartId + i - 1) - end - elseif sDeleteByDir == 'X' then - -- se hanno variazione in X cancello l'entità - if abs( ptP1:getX() - ptP2:getX()) > 10 * GEO.EPS_SMALL then - EgtErase( nStartId + i - 1) - end - end - end - -- ricreo i vari percorsi - local dLocalVal - local tPaths = {} - local nNumPaths - local dMaxVal - local dMinVal - for i = 1, nNumIds do - local ptP1 = EgtSP( ( nStartId + i - 1), GDB_RT.GLOB) - if ptP1 then - if sDeleteByDir == 'Z' then - local bInsTab - for j = 1, #tPaths do - local dLocalVal = tPaths[j][2] - if abs( ptP1:getZ() - dLocalVal) < 10 * GEO.EPS_SMALL then - local tLocIds = tPaths[j][1] - table.insert( tLocIds, ( nStartId + i - 1)) - tPaths[j][1] = tLocIds - bInsTab = true - end - end - -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella - if not bInsTab then - table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getZ()}) - dMaxVal = b3Solid:getMax():getZ() - dMinVal = b3Solid:getMin():getZ() - end - elseif sDeleteByDir == 'Y' then - local bInsTab - for j = 1, #tPaths do - local dLocalVal = tPaths[j][2] - if abs( ptP1:getY() - dLocalVal) < 10 * GEO.EPS_SMALL then - local tLocIds = tPaths[j][1] - table.insert( tLocIds, ( nStartId + i - 1)) - tPaths[j][1] = tLocIds - bInsTab = true - end - end - -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella - if not bInsTab then - table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getY()}) - dMaxVal = b3Solid:getMax():getY() - dMinVal = b3Solid:getMin():getY() - end - elseif sDeleteByDir == 'X' then - local bInsTab - for j = 1, #tPaths do - local dLocalVal = tPaths[j][2] - if abs( ptP1:getX() - dLocalVal) < 10 * GEO.EPS_SMALL then - local tLocIds = tPaths[j][1] - table.insert( tLocIds, ( nStartId + i - 1)) - tPaths[j][1] = tLocIds - bInsTab = true - end - end - -- se non ho trovato da inserirlo aggiungo nuovo elemento in tabella - if not bInsTab then - table.insert( tPaths, {{( nStartId + i - 1)}, ptP1:getX()}) - dMaxVal = b3Solid:getMax():getX() - dMinVal = b3Solid:getMin():getX() - end - end - end - end - - if tPaths then - local tChamPath = {} - -- elimino quelle che non corrispondono agli estremi - for i = 1, #tPaths do - -- se non corrisponde ai limiti elimino l'elemento - if abs( tPaths[i][2] - dMaxVal) > 10 * GEO.EPS_SMALL and abs( tPaths[i][2] - dMinVal) > 10 * GEO.EPS_SMALL then - tPaths[i] = nil - end - end - - for i = 1, #tPaths do - if tPaths[i] then - local tNoMatch = {} - local tPathLoc = tPaths[i][1] - local pIniLoc = EgtSP( tPathLoc[1], GDB_RT.GLOB) - local pEndLoc = EgtEP( tPathLoc[1], GDB_RT.GLOB) - -- ciclo sui percorsi per trovare i punti non coincidenti (se percorso non chiuso) - for j = 2, #tPathLoc do - -- prendo i punti del percorso successivo - local pAddIni = EgtSP( tPathLoc[j], GDB_RT.GLOB) - local pAddEnd = EgtEP( tPathLoc[j], GDB_RT.GLOB) - -- se consecutivi - if AreSamePointApprox( pEndLoc, pAddIni) then - pEndLoc = pAddEnd - elseif AreSamePointApprox( pIniLoc, pAddEnd) then - pIniLoc = pAddIni - else - table.insert( tNoMatch, tPathLoc[j]) - end - end - -- controllo eventuali percorsi scartati - for j = 1, #tNoMatch do - -- prendo i punti del percorso successivo - local pAddIni = EgtSP( tNoMatch[j], GDB_RT.GLOB) - local pAddEnd = EgtEP( tNoMatch[j], GDB_RT.GLOB) - -- se consecutivi - if AreSamePointApprox( pEndLoc, pAddIni) then - pEndLoc = pAddEnd - elseif AreSamePointApprox( pIniLoc, pAddEnd) then - pIniLoc = pAddIni - end - end - -- creo concatenamento partendo dal punto iniziale - local nIdLoc = EgtCurveCompoByReorder( nAddGrpId, tPathLoc, pIniLoc, true) - if nIdLoc then - table.insert( tChamPath, nIdLoc) - end - end - end - for i = 1, #tChamPath do - local ptP1 = EgtSP( tChamPath[i], GDB_RT.GLOB) - -- modifico estrusione percorso - if sDeleteByDir == 'Z' then - if abs(ptP1:getZ() - dMaxVal) < 10 * GEO.EPS_SMALL then - EgtModifyCurveExtrusion( tChamPath[i], Z_AX(), GDB_RT.GLOB) - else - EgtModifyCurveExtrusion( tChamPath[i], -Z_AX(), GDB_RT.GLOB) - end - elseif sDeleteByDir == 'Y' then - if abs(ptP1:getY() - dMaxVal) < 10 * GEO.EPS_SMALL then - EgtModifyCurveExtrusion( tChamPath[i], Y_AX(), GDB_RT.GLOB) - else - EgtModifyCurveExtrusion( tChamPath[i], -Y_AX(), GDB_RT.GLOB) - end - elseif sDeleteByDir == 'X' then - if abs(ptP1:getX() - dMaxVal) < 10 * GEO.EPS_SMALL then - EgtModifyCurveExtrusion( tChamPath[i], X_AX(), GDB_RT.GLOB) - else - EgtModifyCurveExtrusion( tChamPath[i], -X_AX(), GDB_RT.GLOB) - end - end - end - if #tChamPath == 1 then - return tChamPath[1], 1, nil - elseif #tChamPath == 2 then - return tChamPath[1], 2, tChamPath[2] - else - for i = 1, nNumIds do - EgtErase( nStartId + i - 1) - end - for i = 1, #tChamPath do - EgtErase( tChamPath[i]) - end - end - else - for i = 1, nNumIds do - EgtErase( nStartId + i - 1) - end - end - -- altrimenti cancello tutte le emtità e restituisco nil - else - for i = 1, nNumIds do - EgtErase( nStartId + i - 1) - end - end - end - end - - return nil, 0, nil -end - --------------------------------------------------------------------- local function CheckPocketTool( sMchFind, dDiam, dElev) @@ -2532,113 +2678,6 @@ local function CheckDiamToolByFaces( Proc, nFacInd, dH, dV, bIsU, bIsL, dElev, n end end ---------------------------------------------------------------------- -local function MakeChamfer( Proc, b3FacesUsed, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) - - -- recupero la lavorazione - local sMilling = ML.FindMilling( 'Mark') - if not sMilling then - local sErr = 'Error : chamfer not found in library' - EgtOutLog( sErr) - return -1, sErr - end - -- ottengo le curve di contorno libero - local nAuxId1, nAuxId2, nNumIdAux - if b3FacesUsed then --- nAuxId1, _ = EgtExtractSurfTmLoops( nSurfInt, nAddGrpId) --- EgtModifyCurveExtrusion( nAuxId1, vtOrtho, GDB_RT.GLOB) --- SetOpenSide( nAuxId1, vtOrtho, b3Solid, nAddGrpId, true) --- nNumIdAux = 2 - - -- estraggo i percorsi - nAuxId1, nNumIdAux = EgtExtractSurfTmLoops( Proc.Id, nAddGrpId) - -- se percorso creato estraggo solo i percorsi delle facce interessate, non di testa - if nAuxId1 then - nAuxId1, nNumIdAux, nAuxId2 = ExtractExternalPaths( nAuxId1, nNumIdAux, vtOrtho, b3Solid, nAddGrpId) - end - else - nAuxId1, nNumIdAux = EgtExtractSurfTmLoops( Proc.Id, nAddGrpId) - if not nNumIdAux then nNumIdAux = 0 end - end - - local dExtra = 2 - for i = 1, nNumIdAux do - local AuxId - local vtExtr - if b3FacesUsed then - if i == 1 then - AuxId = nAuxId1 - else - -- faccio la copia del percorso --- AuxId = EgtCopyGlob( nAuxId1, nAddGrpId) - AuxId = nAuxId2 - end - if AuxId then - vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) - end - else - AuxId = nAuxId1 + i - 1 - vtExtr, _, _ = EgtCurveArea( AuxId) - end - if vtExtr then - if not b3FacesUsed then - local fFrCurve = EgtGetGlobFrame( AuxId) - vtExtr:toGlob( fFrCurve) - end --- if b3FacesUsed and i == nNumIdAux then --- vtExtr = -vtExtr --- end - -- Se normale entro certi limiti --- if vtExtr:getZ() > -0.707 and ( abs(vtOrtho:getX()) > 0.99 or abs(vtOrtho:getY()) > 0.99 or abs(vtOrtho:getZ()) > 0.99) then - if vtExtr:getZ() > -0.707 and ( abs(vtExtr:getX()) > 0.99 or abs(vtExtr:getY()) > 0.99 or abs(vtExtr:getZ()) > 0.99) then - -- inserisco la lavorazione - local sNameCh = 'Cham_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) .. '_' .. tostring( i) - local nMchId = EgtAddMachining( sNameCh, sMilling) - if not nMchId then - local sErr = 'Error adding machining ' .. sNameCh .. '-' .. sMilling - EgtOutLog( sErr) - return -1, sErr - end - -- modifico estrusione percorso - EgtModifyCurveExtrusion( AuxId, vtExtr, GDB_RT.GLOB) - -- aggiungo geometria - EgtSetMachiningGeometry( {{ AuxId, -1}}) - -- imposto posizione braccio porta testa - if vtExtr:getY() < GEO.EPS_SMALL then - EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YM) - else - EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_YP) - end - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - -- assegno affondamento e offset radiale --- EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra - EgtIf( b3FacesUsed, (dDepth / 2), 0)) - EgtSetMachiningParam( MCH_MP.DEPTH, dDepthCham + dExtra) - EgtSetMachiningParam( MCH_MP.OFFSR, dExtra) - -- se opero su 3 facce e sono al secondo e ultimo percorso inverto la lavorazione --- if b3FacesUsed and i == nNumIdAux then --- EgtSetMachiningParam( MCH_MP.INVERT, true) --- end - -- eseguo - if not EgtApplyMachining( true, false) then - local _, sErr = EgtGetLastMachMgrError() - EgtSetOperationMode( nMchId, false) - return -1, sErr - end - -- se non perpendicolare emetto un warning - -- else - -- sWarn = 'Warning : chamfer skipped because not perpendicular to face or from bottom' - -- EgtOutLog( sWarn) - end - --emetto un warning - -- else - -- sWarn = 'Warning : chamfer skipped because not perpendicular to face' - -- EgtOutLog( sWarn) - end - end - - return 0 -end - --------------------------------------------------------------------- local function MakeByPockets( Proc, nPhase, nRawId, nPartId, nChamfer, dDepthCham, nAddGrpId, sMchFindMaster, b3FacesUsed, b3Solid, bOrthoFacesMaster) @@ -3273,7 +3312,11 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSinglePart) if Proc.Prc == 16 and bForceUseBlade then -- Se la svuotatura precedente non è stata fatta e smusso non è esclusivo, provo con le lame if bTryWithBlades and nChamfer < 2 then - bOk, sWarn, sStat = MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dFacElev, bForceUseBlade, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces, nBottomFace) + bOk, sWarn, sStat = MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, + rfFac, dH, dV, dFacElev, bForceUseBlade, + dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, + bOrthoFaces, nBottomFace, nChamfer, nAddGrpId, b3Solid, + dDepthCham, true) if not bOk then -- in base al flag interno e al numero di facce e se ha forma ad U: provo prima la svuotatura sul fianco e -- se non è possibile allora provo in seguito con lama o segacatena @@ -3310,6 +3353,13 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSinglePart) return bOk, sWarn end else + -- se devo inserire il chamfer + if ( ( Proc.Fct == 3 and bIsU) or (Proc.Fct == 2 and bIsL)) and nChamfer > 0 then + -- ottengo le dimensioni dello pseudotunnel + local _, _, _, vtOrtho, _, nSurfInt = GetTunnelDimension( Proc, nPartId) + local nOk, sErr = MakeChamfer( Proc, true, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) + if nOk < 0 then return false, sErr end + end bOk = true return bOk, sWarn end @@ -3334,7 +3384,11 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSinglePart) end -- Se la svuotatura precedente non è stata fatta e smusso non è esclusivo, provo con le lame if bTryWithBlades and nChamfer < 2 then - bOk, sWarn, sStat = MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, rfFac, dH, dV, dFacElev, bForceUseBlade, dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, bOrthoFaces, nBottomFace) + bOk, sWarn, sStat = MakeByChainOrSaw( Proc, nPhase, nRawId, nPartId, nFacInd, + rfFac, dH, dV, dFacElev, bForceUseBlade, + dDimMin, dDimMax, dDepth, vtOrtho, nLundIdFace, + bOrthoFaces, nBottomFace, nChamfer, nAddGrpId, b3Solid, + dDepthCham) if not bOk and sStat == 'MNF' then sPocketing = ML.FindPocketing( sMchFind, dDiam) if not sPocketing then @@ -3357,7 +3411,7 @@ local function MakeMoreFaces( Proc, nPhase, nRawId, nPartId, bSinglePart) -- ottengo le dimensioni dello pseudotunnel local _, _, _, vtOrtho, _, nSurfInt = GetTunnelDimension( Proc, nPartId) local nOk, sErr = MakeChamfer( Proc, true, nAddGrpId, vtOrtho, b3Solid, nSurfInt, dDepthCham) - if nOk < 0 then return -1, sErr end + if nOk < 0 then return false, sErr end end end -- se richiesti antischeggia con lama su U trasversale e smusso non esclusivo @@ -3573,6 +3627,8 @@ end -- Applicazione della lavorazione --------------------------------------------------------------------- function ProcessLapJoint.Make( Proc, nPhase, nRawId, nPartId, dOvmHead) + -- setto a nil la variabile smussi + bMadeChamfer = nil -- limiti di fresatura semplice local MAX_MILL_LIN = 80 -- recupero l'ingombro del grezzo di appartenenza