From ea9f74c0ad72ad29e3f8fcd6616c9d27f1dc4beb Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Tue, 30 Jun 2020 17:37:29 +0000 Subject: [PATCH] DataWall : - aggiunta gestione tasche (solo svuotatura). --- LuaLibs/WProcessDrill.lua | 16 +-- LuaLibs/WProcessFreeContour.lua | 12 +-- LuaLibs/WProcessLapJoint.lua | 123 +++++++++++++++++++++++ LuaLibs/WallExec.lua | 14 ++- LuaLibs/WallLib.lua | 167 ++++++++++++++++++++++++++++++++ 5 files changed, 316 insertions(+), 16 deletions(-) create mode 100644 LuaLibs/WProcessLapJoint.lua diff --git a/LuaLibs/WProcessDrill.lua b/LuaLibs/WProcessDrill.lua index bbe2f4f..4b165e0 100644 --- a/LuaLibs/WProcessDrill.lua +++ b/LuaLibs/WProcessDrill.lua @@ -1,13 +1,13 @@ --- ProcessDrill.lua by Egaltech s.r.l. 2020/06/24 +-- WProcessDrill.lua by Egaltech s.r.l. 2020/06/24 -- Gestione calcolo forature per Pareti -- Tabella per definizione modulo -local ProcessDrill = {} +local WPD = {} -- Include require( 'EgtBase') -EgtOutLog( ' ProcessDrill started', 1) +EgtOutLog( ' WProcessDrill started', 1) -- Dati local WD = require( 'WallData') @@ -15,13 +15,13 @@ local WM = require( 'WMachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature -function ProcessDrill.Identify( Proc) +function WPD.Identify( Proc) return ( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 40) end --------------------------------------------------------------------- -- Recupero dati foro e adattamento se speciale -function ProcessDrill.GetData( Proc) +function WPD.GetData( Proc) -- verifico se foro da adattare if EgtExistsInfo( Proc.Id, 'DiamUser') then local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') @@ -41,7 +41,7 @@ end --------------------------------------------------------------------- -- Classificazione della feature -function ProcessDrill.Classify( Proc, b3Raw) +function WPD.Classify( Proc, b3Raw) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end @@ -69,7 +69,7 @@ end --------------------------------------------------------------------- -- Applicazione della lavorazione -function ProcessDrill.Make( Proc, nRawId, b3Raw) +function WPD.Make( Proc, nRawId, b3Raw) -- recupero e verifico l'entità foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end @@ -186,4 +186,4 @@ function ProcessDrill.Make( Proc, nRawId, b3Raw) end --------------------------------------------------------------------- -return ProcessDrill +return WPD diff --git a/LuaLibs/WProcessFreeContour.lua b/LuaLibs/WProcessFreeContour.lua index 1beb10f..0675508 100644 --- a/LuaLibs/WProcessFreeContour.lua +++ b/LuaLibs/WProcessFreeContour.lua @@ -2,13 +2,13 @@ -- Gestione calcolo profilo libero per Pareti -- Tabella per definizione modulo -local ProcessFreeContour = {} +local WPF = {} -- Include require( 'EgtBase') local WL = require( 'WallLib') -EgtOutLog( ' ProcessFreeContour started', 1) +EgtOutLog( ' WProcessFreeContour started', 1) -- Dati local WD = require( 'WallData') @@ -18,14 +18,14 @@ local MIN_LEN_CUT = 1 --------------------------------------------------------------------- -- Riconoscimento della feature -function ProcessFreeContour.Identify( Proc) +function WPF.Identify( Proc) return ( ( Proc.Grp == 0 or Proc.Grp == 3 or Proc.Grp == 4) and ( Proc.Prc == 250 or Proc.Prc == 251 or Proc.Prc == 252)) end --------------------------------------------------------------------- -- Classificazione della feature -function ProcessFreeContour.Classify( Proc, b3Raw) +function WPF.Classify( Proc, b3Raw) -- verifico se di tipo pocket local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- recupero la curva associata @@ -521,7 +521,7 @@ end --------------------------------------------------------------------- -- Applicazione della lavorazione -function ProcessFreeContour.Make( Proc, nRawId, b3Raw) +function WPF.Make( Proc, nRawId, b3Raw) -- recupero la tipologia local bPocket = ( EgtGetInfo( Proc.Id, 'PCKT', 'i') == 1) -- se svuotatura @@ -537,4 +537,4 @@ function ProcessFreeContour.Make( Proc, nRawId, b3Raw) end --------------------------------------------------------------------- -return ProcessFreeContour +return WPF diff --git a/LuaLibs/WProcessLapJoint.lua b/LuaLibs/WProcessLapJoint.lua new file mode 100644 index 0000000..f641f21 --- /dev/null +++ b/LuaLibs/WProcessLapJoint.lua @@ -0,0 +1,123 @@ +-- WProcessLapJoint.lua by Egaltech s.r.l. 2020/06/30 +-- Gestione calcolo mezzo-legno per Pareti + +-- Tabella per definizione modulo +local WPL = {} + +-- Include +require( 'EgtBase') +local WL = require( 'WallLib') + +EgtOutLog( ' WProcessLapJoint started', 1) + +-- Dati +local WD = require( 'WallData') +local WM = require( 'WMachiningLib') + +--------------------------------------------------------------------- +-- Riconoscimento della feature +function WPL.Identify( Proc) + return ( ( Proc.Grp == 3 or Proc.Grp == 4) and Proc.Prc == 30) +end + +--------------------------------------------------------------------- +-- Classificazione della feature +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) + -- 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) + -- verifico se è lavorabile da sopra + return vtN[1]:getZ() >= WD.NZ_MINA or vtN[2]:getZ() >= WD.NZ_MINA + -- se più di 2 facce + else + local nFacInd, dElev, nFacInd2, dElev2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) + -- dati della faccia + local ptC, vtN = EgtSurfTmFacetCenter( Proc.Id, nFacInd, GDB_ID.ROOT) + -- verifico se è lavorabile da sopra + return vtN:getZ() >= WD.NZ_MINA + end +end + +--------------------------------------------------------------------- +local function MakePocketing( Proc, nFacet, nRawId, b3Raw) + -- recupero i dati della curva e del profilo + local dElev = WL.GetFaceElevation( Proc.Id, nFacet, nPartId) + -- recupero la lavorazione + local sPocketing = WM.FindPocketing( 'Pocket', nil, dDepth) + if not sPocketing then + local sErr = 'Error : pocketing not found in library' + EgtOutLog( sErr) + return false, sErr + end + -- recupero i dati dell'utensile + local dMillDiam = 20 + local dMaxDepth = 0 + if EgtMdbSetCurrMachining( sPocketing) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + dMillDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dMillDiam + dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth + end + end + -- 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) + return false, sErr + end + -- aggiungo geometria + EgtSetMachiningGeometry( {{ Proc.Id, nFacet}}) + -- imposto posizione braccio porta testa + EgtSetMachiningParam( MCH_MP.SCC, MCH_SCC.ADIR_XP) + -- se elevazione superiore a massimo affondamento della fresa, riduco opportunamente + local dDepth = 0 + if dElev > dMaxDepth + 10 * GEO.EPS_SMALL then + dDepth = dMaxDepth - dElev + local sWarn = 'Warning : elevation bigger than max tool depth' + EgtOutLog( sWarn) + end + EgtSetMachiningParam( MCH_MP.DEPTH, dDepth) + -- imposto elevazione + EgtSetMachiningParam( MCH_MP.USERNOTES, 'MaxElev=' .. EgtNumToString( min( dElev, dMaxDepth), 1) .. ';') + -- eseguo + if not EgtApplyMachining( true, false) then + local _, sErr = EgtGetLastMachMgrError() + EgtSetOperationMode( nMchFId, false) + return false, sErr + end + return true +end + +--------------------------------------------------------------------- +-- Applicazione della lavorazione +function WPL.Make( Proc, nRawId, b3Raw) + -- svuotatura della faccia principale + local nFacet + if Proc.Fct == 1 then + nFacet = 0 + elseif Proc.Fct >= 2 then + local nFacInd, _, nFacInd2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) + local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) + if vtN:getZ() >= WD.NZ_MINA then + nFacet = nFacInd + else + nFacet = nFacInd2 + end + end + return MakePocketing( Proc, nFacet, nRawId, b3Raw) +end + +--------------------------------------------------------------------- +return WPL diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index 9151b4d..2225962 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -16,6 +16,8 @@ _G.package.loaded.WMachiningLib = nil local WM = require( 'WMachiningLib') _G.package.loaded.WallLib = nil local WL = require( 'WallLib') +_G.package.loaded.WProcessLapJoint = nil +local LapJoint = require( 'WProcessLapJoint') _G.package.loaded.WProcessDrill = nil local Drill = require( 'WProcessDrill') _G.package.loaded.WProcessFreeContour = nil @@ -122,8 +124,12 @@ end local function ClassifyFeatures( vProc, b3Raw) for i = 1, #vProc do local Proc = vProc[i] + -- se tasca + if LapJoint.Identify( Proc) then + local bOk = LapJoint.Classify( Proc, b3Raw) + if not bOk then Proc.Flg = 0 end -- se foratura - if Drill.Identify( Proc) then + elseif Drill.Identify( Proc) then local bOk = Drill.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se contorno libero, outile o aperture @@ -150,8 +156,12 @@ end local function AddFeatureMachining( Proc, nRawId, b3Raw) local bOk = true local sErr = '' + -- se tasca (3/4-030-X) + if LapJoint.Identify( Proc) then + -- esecuzione tasca + bOk, sErr = LapJoint.Make( Proc, nRawId, b3Raw) -- se foratura ( 3/4-040-X) - if Drill.Identify( Proc) then + elseif Drill.Identify( Proc) then -- esecuzione foratura bOk, sErr = Drill.Make( Proc, nRawId, b3Raw) -- se contorno libero, outline o apertura ( 0/3/4-250/251/252-X) diff --git a/LuaLibs/WallLib.lua b/LuaLibs/WallLib.lua index 7d8cc35..1c7cc60 100644 --- a/LuaLibs/WallLib.lua +++ b/LuaLibs/WallLib.lua @@ -39,6 +39,173 @@ function WallLib.CreateOrEmptyAddGroup( PartId) return true end +------------------------------------------------------------------------------------------------------------- +function WallLib.GetPointDirDepth( nPartId, ptP, vtDir) + -- recupero il solido del grezzo + local nSolId = EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( nPartId, 'Box') or GDB_ID.NULL, 'Box') + if not nSolId then return end + -- interseco con la retta + local bOk, vType, vPar = EgtLineSurfTmInters( ptP, vtDir, nSolId, GDB_RT.GLOB) + if not bOk then return end + if not vPar or #vPar == 0 then return -2 end + local dLenIn, dLenOut + for i = 1, #vPar do + if vPar[i] < 0 then + if vType[i] == GDB_SLT.IN or vType[i] == GDB_SLT.TG_INI then + dLenIn = -1 + end + if vType[i] == GDB_SLT.OUT or vType[i] == GDB_SLT.TG_FIN then + dLenIn = -2 + end + else + if vType[i] == GDB_SLT.IN or vType[i] == GDB_SLT.TG_INI then + dLenIn = vPar[i] + end + if vType[i] == GDB_SLT.OUT or vType[i] == GDB_SLT.TG_FIN or vType[i] == GDB_SLT.TOUCH then + dLenOut = vPar[i] + end + end + end + return dLenIn, dLenOut +end + +--------------------------------------------------------------------- +function WallLib.GetFaceElevation( nSurfId, nFac, nPartId) + 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) + if dCenElev and dCenElev > dElev then + dElev = dCenElev + end + end + return dElev +end + +--------------------------------------------------------------------- +function WallLib.GetFaceWithMostAdj( nSurfId, nPartId, bCompare3Fc, dCosSideAng) + -- recupero il numero di facce + local nFacCnt = EgtSurfTmFacetCount( nSurfId) + if not dCosSideAng then + dCosSideAng = -0.09 + end + -- recupero le normali delle facce + local vvtN = {} + for i = 1, nFacCnt do + local _, vtN = EgtSurfTmFacetCenter( nSurfId, i - 1, GDB_ID.ROOT) + vvtN[i] = vtN ; + end + -- adiacenze e sottosquadra delle facce + local vAdj = {} + local vUcut = {} + local vOrtho = {} + for i = 1, nFacCnt do + -- recupero le adiacenze del loop esterno + local vFacAdj = EgtSurfTmFacetAdjacencies( nSurfId, i - 1)[1] + -- le conto + local nCount = 0 + for j = 1, #vFacAdj do + if vFacAdj[j] >= 0 then + nCount = nCount + 1 + end + end + vAdj[i] = nCount + -- ne determino eventuale sottosquadra ( dal valore passato o - 3deg) e ortogonalità + local bUcut = false + local bOrtho = true + for j = 1, #vFacAdj do + if vFacAdj[j] >= 0 then + local vtN = vvtN[i] + local vtN2 = vvtN[vFacAdj[j]+1] + local dResV = vtN * vtN2 + if dResV < dCosSideAng - GEO.EPS_SMALL then + bUcut = true + end + if abs( dResV) > 2 * GEO.EPS_SMALL then + bOrtho = false + end + end + end + vUcut[i] = bUcut + vOrtho[i] = bOrtho + end + -- 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 + return -1, GEO.INFINITO + 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 + 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 + return -1, GEO.INFINITO + end + end + end + -- recupero le facce non in sottosquadra e con il maggior numero di adiacenze + local nFacInd = {} + local nMaxAdj = -1 + local nSupAdj = -1 + for i = 1, nFacCnt do + if not vUcut[i] then + if vAdj[i] > nMaxAdj then + nFacInd = {} + nFacInd[1] = i - 1 + nMaxAdj = vAdj[i] + elseif vAdj[i] == nMaxAdj and nMaxAdj > 0 then + table.insert( nFacInd, i - 1) + end + end + if vAdj[i] > nSupAdj then + nSupAdj = vAdj[i] + end + end + -- verifico non ci sia una faccia in sottosquadra con adiacenza superiore + if nSupAdj > nMaxAdj then + return -2, GEO.INFINITO + end + -- premio la faccia con minore elevazione + local nFacOpt, nFacOpt2 + local dMinElev, dMinElev2 = GEO.INFINITO, GEO.INFINITO + for i = 1, #nFacInd do + local dElev = WallLib.GetFaceElevation( nSurfId, nFacInd[i], nPartId) + if dElev < dMinElev then + if dMinElev < dMinElev2 then + nFacOpt2 = nFacOpt + dMinElev2 = dMinElev + end + nFacOpt = nFacInd[i] + dMinElev = dElev + elseif dElev < dMinElev2 then + nFacOpt2 = nFacInd[i] + dMinElev2 = dElev + end + end + return nFacOpt, dMinElev, nFacOpt2, dMinElev2 +end + --------------------------------------------------------------------- function WallLib.GetFaceHvRefDim( nSurfId, nFacet) -- recupero centro e normale della faccia