From 7383e914cc8cc537b110edd30c57e2cd2592eb21 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Wed, 18 Nov 2020 08:10:36 +0000 Subject: [PATCH] DataWall : - aggiunte fresature su fessure di fianco - l'elevazione delle facce viene calcolata rispetto al grezzo complessivo. --- LuaLibs/WProcessLapJoint.lua | 172 +++++++++++++++++++++++++++++++---- LuaLibs/WallLib.lua | 47 +++++++++- 2 files changed, 194 insertions(+), 25 deletions(-) diff --git a/LuaLibs/WProcessLapJoint.lua b/LuaLibs/WProcessLapJoint.lua index d2696c9..f592bfe 100644 --- a/LuaLibs/WProcessLapJoint.lua +++ b/LuaLibs/WProcessLapJoint.lua @@ -33,16 +33,15 @@ function WPL.Classify( Proc, b3Raw) -- se 1 faccia if Proc.Fct == 1 then -- dati della faccia - local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) -- verifico se è lavorabile da sopra return vtN:getZ() >= WD.NZ_MINA -- se 2 facce elseif Proc.Fct == 2 then -- dati delle facce - local ptC = {} local vtN = {} - ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) - ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) + vtN[1] = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) + vtN[2] = EgtSurfTmFacetNormVersor( Proc.Id, 1, GDB_ID.ROOT) -- verifico se è lavorabile da sopra return vtN[1]:getZ() >= WD.NZ_MINA or vtN[2]:getZ() >= WD.NZ_MINA -- se più di 2 facce @@ -50,27 +49,35 @@ function WPL.Classify( Proc, b3Raw) local nFacInd, dElev, nFacInd2, dElev2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) -- se trovata faccia di fondo if nFacInd >= 0 then + -- determino componente Z della normale più diretta verso il basso + local dMinNz = 1 + for i = 1, Proc.Fct do + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, i - 1, GDB_ID.ROOT) + if vtN:getZ() < dMinNz then + dMinNz = vtN:getZ() + end + end -- dati della faccia - local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT) + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) - -- verifico se la faccia è lavorabile da sopra o di fianco se con sega a catena - if ( vtN:getZ() >= WD.NZ_MINA or ( dV < 19 and Proc.Fct > 4 and vtN:getZ() > - 0.01)) then + -- verifico se la faccia è lavorabile da sopra o di fianco + if ( vtN:getZ() >= WD.NZ_MINA or ( dMinNz < -0.866 and Proc.Fct >= 3 and vtN:getZ() > - 0.01)) then Proc.Stype = 1 return true -- altrimenti verifico la eventuale seconda faccia elseif nFacInd2 then -- dati della faccia - local ptC2, vtN2 = EgtSurfTmFacetCenter( Proc.Id, nFacInd2, GDB_ID.ROOT) + local vtN2 = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd2, GDB_ID.ROOT) local _, dH2, dV2 = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd2, GDB_ID.ROOT) -- restituisco se faccia lavorabile Proc.Stype = 2 - return ( vtN2:getZ() >= WD.NZ_MINA or ( dV2 < 19 and Proc.Fct > 4 and vtN2:getZ() > - 0.01)) + return ( vtN2:getZ() >= WD.NZ_MINA or ( dMinNz < -0.866 and Proc.Fct >= 3 and vtN2:getZ() > - 0.01)) -- se tre facce elseif Proc.Fct == 3 then -- verifico se U da sopra -- dati della faccia local nFac2 = EgtIf( nFacInd == 0, 1, 0) - local ptC2, vtN2 = EgtSurfTmFacetCenter( Proc.Id, nFac2, GDB_ID.ROOT) + local vtN2 = EgtSurfTmFacetNormVersor( Proc.Id, nFac2, GDB_ID.ROOT) Proc.Stype = 3 return ( abs( ( vtN ^ vtN2) * Z_AX()) >= WD.NZ_MINA) -- altrimenti non lavorabile @@ -80,11 +87,10 @@ function WPL.Classify( Proc, b3Raw) -- se altrimenti tunnel elseif nFacInd == -1 then -- dati delle prime tre facce - local ptC = {} local vtN = {} - ptC[1], vtN[1] = EgtSurfTmFacetCenter( Proc.Id, 0, GDB_ID.ROOT) - ptC[2], vtN[2] = EgtSurfTmFacetCenter( Proc.Id, 1, GDB_ID.ROOT) - ptC[3], vtN[3] = EgtSurfTmFacetCenter( Proc.Id, 2, GDB_ID.ROOT) + vtN[1] = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) + vtN[2] = EgtSurfTmFacetNormVersor( Proc.Id, 1, GDB_ID.ROOT) + vtN[3] = EgtSurfTmFacetNormVersor( Proc.Id, 2, GDB_ID.ROOT) -- verifico se è lavorabile da sopra local vtAxN = vtN[1] ^ vtN[2] if vtAxN:isSmall() then vtAxN = vtN[1] ^ vtN[3] end @@ -212,11 +218,123 @@ local function MakeByChainSaw( Proc, nFacet, nRawId, b3Raw, dElev, dH, dV) return true end +--------------------------------------------------------------------- +local function MakeByMill( Proc, nFacet, nOthFac, nRawId, b3Raw) + -- dati della faccia e dell'altra + local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacet, GDB_ID.ROOT) + local dElev = WL.GetFaceElevation( Proc.Id, nFacet, nRawId) + local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacet, GDB_ID.ROOT) + local dDiam = min( dH, dV) + local _, vtRef = EgtSurfTmFacetCenter( Proc.Id, nOthFac, GDB_ID.ROOT) + -- recupero la lavorazione + local sMilling = WM.FindMilling( 'Side') + if not sMilling then return false end + -- recupero i dati dell'utensile + local dMillDiam = 20 + local dMaxDepth = 0 + local dThDiam = 100 + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam + dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth + dThDiam = EgtTdbGetCurrToolThDiam() or dThDiam + end + end + if dMillDiam < dDiam or dMaxDepth < dElev then return false end + -- inserisco la lavorazione di contornatura + local sName = 'Mill_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchFId = EgtAddMachining( sName, sMilling) + if not nMchFId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nFacet}}) + -- imposto posizione braccio porta testa + local nSCC = MCH_SCC.ADIR_ZP + if AreSameVectorApprox( vtN, Z_AX()) then + nSCC = EgtIf( Proc.Box:getDimX() >= Proc.Box:getDimY(), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_XP) + end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + -- imposto modo di lavorare la faccia + local nFaceUse = WL.GetNearestOrthoOpposite( vtRef, vtN) + EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtRemoveOperation( nMchFId) + return false, sErr + end + return true +end + +--------------------------------------------------------------------- +local function MakeSideGrooveByMill( Proc, nFacet, nRawId, b3Raw) + -- dati della faccia e dell'altra + local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacet, GDB_ID.ROOT) + local dElev = WL.GetFaceElevation( Proc.Id, nFacet, nRawId) + local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacet, GDB_ID.ROOT) + local dThick = min( dH, dV) + -- recupero la lavorazione + local sMilling = WM.FindMilling( 'SideGroove') + if not sMilling then + local sErr = 'Error : SideGroove not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- recupero i dati dell'utensile + local dMillDiam = 20 + local dMaxMat = 0 + if EgtMdbSetCurrMachining( sMilling) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam + dMaxMat = EgtTdbGetCurrToolParam( MCH_TP.MAXMAT) or dMaxMat + end + end + if dElev > dMillDiam / 2 - 30 then + local sErr = 'Error : Side Elevation too big' + EgtOutLog( sErr) + return false, sErr + end + -- inserisco la lavorazione di contornatura + local sName = 'Mill_' .. ( EgtGetName( Proc.Id) or tostring( Proc.Id)) + local nMchFId = EgtAddMachining( sName, sMilling) + if not nMchFId then + local sErr = 'Error adding machining ' .. sName .. '-' .. sMilling + EgtOutLog( sErr) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nFacet}}) + -- imposto posizione braccio porta testa + local nSCC = MCH_SCC.ADIR_ZP + if AreSameVectorApprox( vtN, Z_AX()) then + nSCC = EgtIf( Proc.Box:getDimX() >= Proc.Box:getDimY(), MCH_SCC.ADIR_YP, MCH_SCC.ADIR_XP) + end + EgtSetMachiningParam( MCH_MP.SCC, nSCC) + -- imposto modo di lavorare la faccia + local nFaceUse = WL.GetNearestParalOpposite( Z_AX(), vtN) + EgtSetMachiningParam( MCH_MP.FACEUSE, nFaceUse) + -- imposto elevazione + local dMaxElev = 2 * ( dThick - dMaxMat) + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( dMaxElev, 1) .. ';') + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtRemoveOperation( nMchFId) + return false, sErr + end + return true +end + --------------------------------------------------------------------- local function MakeByPocketing( Proc, nFacet, nRawId, b3Raw) -- dati della faccia local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacet, GDB_ID.ROOT) - local dElev = WL.GetFaceElevation( Proc.Id, nFacet, Proc.PartId) + local dElev = WL.GetFaceElevation( Proc.Id, nFacet, nRawId) local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacet, GDB_ID.ROOT) local dDiam = min( dH, dV) if Proc.Fct < 5 then dDiam = dDiam * 2 end @@ -346,12 +464,20 @@ local function MakeTwoFaces( Proc, nRawId, b3Raw) end -- recupero la lavorazione di taglio con lama e i suoi parametri local sCutting, dSawDiam, dSawThick, dSawMaxDepth = WM.FindCutting( 'Standard') - -- se non inclinate o capacità di taglio non sufficiente, provo con svuotatura + -- se non inclinate o capacità di taglio non sufficiente, provo con contornatura o svuotatura if not sCutting or vtN[1]:getZ() > 0.95 or vtN[2]:getZ() > 0.95 or dSawMaxDepth < dDimY[1] + WD.CUT_SIC or dSawMaxDepth < dDimY[2] + WD.CUT_SIC then - -- cerco la faccia con il maggior numero di adiacenze + -- cerco la faccia con il maggior numero di adiacenze (e minor elevazione) local nFacInd, _, nFacInd2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) local nFacet = EgtIf( vtN:getZ() >= WD.NZ_MINA, nFacInd, nFacInd2) + -- se vicino al bordo del grezzo e non troppo larga, provo con fresatura di fianco + local ptMid = ( ptP1 + ptP2) / 2 + if abs( ptMid:getX() - b3Raw:getMin():getX()) < 300 or abs( ptMid:getX() - b3Raw:getMax():getX()) < 300 or + abs( ptMid:getY() - b3Raw:getMin():getY()) < 300 or abs( ptMid:getY() - b3Raw:getMax():getY()) < 300 then + if MakeByMill( Proc, nFacet, 1 - nFacet, nRawId, b3Raw) then + return true + end + end -- eseguo la svuotatura return MakeByPocketing( Proc, nFacet, nRawId, b3Raw) end @@ -405,9 +531,15 @@ local function MakeMoreFaces( Proc, nRawId, b3Raw) end local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nFacInd, GDB_ID.ROOT) - -- se necessaria sega a catena - if dV < 19 and Proc.Fct > 4 and vtN:getZ() > - 0.01 then - return MakeByChainSaw( Proc, nFacInd, nRawId, b3Raw, dElev, dH, dV) + -- se di fianco + if Proc.Fct >= 3 and vtN:getZ() < WD.NZ_MINA then + -- fresatura + if dV > 30 then + return MakeSideGrooveByMill( Proc, nFacInd, nRawId, b3Raw) + -- altrimenti sega a catena + else + return MakeByChainSaw( Proc, nFacInd, nRawId, b3Raw, dElev, dH, dV) + end end local nFacet = EgtIf( vtN:getZ() >= WD.NZ_MINA, nFacInd, nFacInd2) -- eseguo la svuotatura diff --git a/LuaLibs/WallLib.lua b/LuaLibs/WallLib.lua index f9daab5..6cd1c5d 100644 --- a/LuaLibs/WallLib.lua +++ b/LuaLibs/WallLib.lua @@ -1,4 +1,4 @@ --- WallLib.lua by Egaltech s.r.l. 2020/07/15 +-- WallLib.lua by Egaltech s.r.l. 2020/11/18 -- Libreria globale per Pareti -- Tabella per definizione modulo @@ -40,9 +40,9 @@ function WallLib.CreateOrEmptyAddGroup( PartId) end ------------------------------------------------------------------------------------------------------------- -function WallLib.GetPointDirDepth( nPartId, ptP, vtDir) +function WallLib.GetPointDirDepth( nRawId, ptP, vtDir) -- recupero il solido del grezzo - local nSolId = EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, 'Box') + local nSolId = EgtGetFirstNameInGroup( nRawId, 'RawSolid') if not nSolId then return end -- interseco con la retta local bOk, vType, vPar = EgtLineSurfTmInters( ptP, vtDir, nSolId, GDB_RT.GLOB) @@ -70,14 +70,14 @@ function WallLib.GetPointDirDepth( nPartId, ptP, vtDir) end --------------------------------------------------------------------- -function WallLib.GetFaceElevation( nSurfId, nFac, nPartId) +function WallLib.GetFaceElevation( nSurfId, nFac, nRawId) local ptC, vtN = EgtSurfTmFacetCenter( nSurfId, nFac, GDB_ID.ROOT) if not ptC or not vtN then return 0 end local frOCS = Frame3d( ptC, vtN) ; local b3Box = EgtGetBBoxRef( nSurfId, GDB_BB.STANDARD, frOCS) local dElev = b3Box:getDimZ() if nPartId then - local _, dCenElev = WallLib.GetPointDirDepth( nPartId, ptC, vtN) + local _, dCenElev = WallLib.GetPointDirDepth( nRawId, ptC, vtN) if dCenElev and dCenElev > dElev then dElev = dCenElev end @@ -253,5 +253,42 @@ function WallLib.GetNearestParalOpposite( vtRef) return nil end +--------------------------------------------------------------------- +function WallLib.GetNearestOrthoOpposite( vtRef, vtNorm) + -- se definita anche la normale alla faccia, elimino la parte di vtRef parallela a questa + local vtMyRef = Vector3d( vtRef) + if vtNorm then + vtMyRef = vtMyRef - ( vtMyRef * vtNorm) * vtNorm + vtMyRef:normalize() + end + -- devo confrontare la componente orizzontale con quella verticale + local dHorSq = vtMyRef:getX() * vtMyRef:getX() + vtMyRef:getY() * vtMyRef:getY() + local dVertSq = vtMyRef:getZ() * vtMyRef:getZ() + -- se prevalente la componente orizzontale + if dHorSq >= dVertSq then + if abs( vtMyRef:getX()) >= abs( vtMyRef:getY()) then + if vtMyRef:getX() > 0 then + return MCH_MILL_FU.ORTHO_LEFT + else + return MCH_MILL_FU.ORTHO_RIGHT + end + else + if vtMyRef:getY() > 0 then + return MCH_MILL_FU.ORTHO_FRONT + else + return MCH_MILL_FU.ORTHO_BACK + end + end + -- altrimenti prevale la verticale + else + if vtMyRef:getZ() > 0 then + return MCH_MILL_FU.ORTHO_DOWN + else + return MCH_MILL_FU.ORTHO_TOP + end + end + return nil +end + ------------------------------------------------------------------------------------------------------------- return WallLib