From 65fec1e05ddb253df08774643e93ed3ad900759e Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 18 Apr 2024 18:34:09 +0200 Subject: [PATCH] - implementata parzialmente GetMainFaces e funzioni accessorie - migliorie stilistiche e refactoring parziale --- LuaLibs/BeamExec.lua | 27 +++-- LuaLibs/BeamLib.lua | 67 ++++++++++-- LuaLibs/FaceData.lua | 230 ++++++++++++++++++++++++++++++++++++++++ LuaLibs/FeatureData.lua | 125 ++++++---------------- 4 files changed, 341 insertions(+), 108 deletions(-) create mode 100644 LuaLibs/FaceData.lua diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index b97ff7f..c5274dd 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -12,10 +12,11 @@ require( 'EgtBase') local BD = require( 'BeamData') -- carico librerie -local BL = require( 'BeamLib') +local BeamLib = require( 'BeamLib') local ID = require( 'Identity') local BCS = require( 'BasicCustomerStrategies') -local FD = require( 'FeatureData') +local FeatureData = require( 'FeatureData') +local FaceData = require( 'FaceData') EgtOutLog( ' BeamExec started', 1) @@ -72,6 +73,7 @@ local function IsToolOk( Tool) end end end + return false end @@ -290,12 +292,12 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b Cnt = Cnt + 1 EgtSetInfo( nRaw, 'ORD', Cnt) -- creo o pulisco gruppo geometrie aggiuntive - if not BL.CreateOrEmptyAddGroup( Pz) then + if not BeamLib.CreateOrEmptyAddGroup( Pz) then local sOut = 'Error creating Additional Group in Part ' .. tostring( Pz) return false, sOut end -- aggiungo faccia per taglio iniziale al pezzo - BL.AddPartStartFace( Pz, b3Solid) + BeamLib.AddPartStartFace( Pz, b3Solid) -- se sovramateriale di testa, lo notifico if DeltaS > 0.09 then EgtSetInfo( nRaw, 'HOVM', DeltaS) @@ -307,7 +309,7 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b EgtSetInfo( nRaw, 'TOVM', DeltaE) end -- aggiungo faccia per taglio finale al pezzo - BL.AddPartEndFace( Pz, b3Solid) + BeamLib.AddPartEndFace( Pz, b3Solid) -- inserisco il pezzo nel grezzo EgtDeselectPartObjs( Pz) local ptPos = b3Part:getMin() - b3Solid:getMin() + Vector3d( Delta, ( dRawW - PartWidth) / 2, ( dRawH - PartHeight) / 2) @@ -466,7 +468,7 @@ local function CollectFeatures( PartId, b3Raw) -- recupero le feature local vProc = {} local LayerId = {} - LayerId[1] = BL.GetAddGroup( PartId) + LayerId[1] = BeamLib.GetAddGroup( PartId) LayerId[2] = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, 'Processings') for nInd = 1, 2 do local ProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL) @@ -495,6 +497,7 @@ local function CollectFeatures( PartId, b3Raw) Proc.CutId = nCutId Proc.TaskId = nTaskId -- se ci sono feature collegate ne scrivo il riferimento nella Proc + -- TODO AdjId e MainId servono a qualcosa??? if nAddAdjId then Proc.AdjId = Proc.Id + nAddAdjId elseif nAddMainId then @@ -507,14 +510,16 @@ local function CollectFeatures( PartId, b3Raw) -- se foro calcolo altri dati if ID.IsDrilling( Proc) then -- assegno diametro e facce di ingresso e uscita (dati tabelle sempre per riferimento) - Proc.Diam, Proc.Len, Proc.Fcs, Proc.Fce = FD.GetDataDrill( Proc) + Proc.Diam, Proc.Len, Proc.Fcs, Proc.Fce = FeatureData.GetDrillingData( Proc) end - -- si recupera la topologia della feature - Proc.Topology = FD.GetTopology( Proc, b3Raw) + -- informazioni facce e topologia + Proc.AdjacencyMatrix = FaceData.GetAdjacencyMatrix( Proc) + Proc.Faces = FaceData.GetFacesInfo( Proc, b3Raw) + Proc.Topology = FeatureData.GetTopology( Proc, b3Raw) -- se topologia feature riconosciuta, oppure da non calcolare perchè il riconoscimento topologico è basato sulla feature stessa if Proc.Topology.Name ~= 'NOT_IMPLEMENTED' then -- TODO Funzione 'GetMainFaces' da scrivere - Proc.MainFaces = FD.GetMainFaces( Proc) + Proc.MainFaces = FaceData.GetMainFaces( Proc) -- se la processing ha una strategia forzata, riporto tutto nella proc local vForcedStrategy = GetFeatureForcedStrategy( Proc) if vForcedStrategy then @@ -591,7 +596,7 @@ function BeamExec.ProcessFeatures() if nOrd == 1 then EgtSetCurrPhase( 1) else - BL.AddPhaseWithRawParts( nRawId, BD.OriXR, BD.PosXR, 0) + BeamLib.AddPhaseWithRawParts( nRawId, BD.OriXR, BD.PosXR, 0) end local nPhase = EgtGetCurrPhase() local nDispId = EgtGetPhaseDisposition( nPhase) diff --git a/LuaLibs/BeamLib.lua b/LuaLibs/BeamLib.lua index e2f5142..d8ee03d 100644 --- a/LuaLibs/BeamLib.lua +++ b/LuaLibs/BeamLib.lua @@ -14,6 +14,8 @@ EgtOutLog( ' BeamLib started', 1) -- Dati local BD = require( 'BeamData') +--TODO refactoring di queste funzioni + ------------------------------------------------------------------------------------------------------------- function BeamLib.AddPartStartFace( PartId, b3Solid) -- recupero gruppo per geometria aggiuntiva @@ -23,6 +25,7 @@ function BeamLib.AddPartStartFace( PartId, b3Solid) EgtOutLog( sErr) return false, sErr end + -- aggiungo nuovo taglio iniziale local nStmId = EgtSurfTmPlaneInBBox( AddGrpId, b3Solid:getMax(), X_AX(), b3Solid, GDB_RT.GLOB) if not nStmId then @@ -47,6 +50,7 @@ function BeamLib.AddPartStartFace( PartId, b3Solid) end nProcId = EgtGetNext( nProcId) end + return true end @@ -59,6 +63,7 @@ function BeamLib.AddPartEndFace( PartId, b3Solid) EgtOutLog( sErr) return false, sErr end + -- aggiungo nuovo taglio finale local nStmId = EgtSurfTmPlaneInBBox( AddGrpId, b3Solid:getMin(), -X_AX(), b3Solid, GDB_RT.GLOB) if not nStmId then @@ -83,6 +88,7 @@ function BeamLib.AddPartEndFace( PartId, b3Solid) end nProcId = EgtGetNext( nProcId) end + return true end @@ -105,7 +111,10 @@ end function BeamLib.CreateOrEmptyAddGroup( PartId) -- recupero i dati del gruppo aggiuntivo local AddGrpId, sMchGrp = BeamLib.GetAddGroup( PartId) - if not sMchGrp then return false end + if not sMchGrp then + return false + end + -- se esiste, aggiorno riferimento al gruppo di lavoro e lo svuoto if AddGrpId then EgtSetInfo( AddGrpId, GDB_SI.MGRPONLY, EgtGetCurrMachGroup()) @@ -113,11 +122,14 @@ function BeamLib.CreateOrEmptyAddGroup( PartId) end -- altrimenti lo creo AddGrpId = EgtGroup( PartId or GDB_ID.NULL) - if not AddGrpId then return false end + if not AddGrpId then + return false + end -- assegno nome, flag di layer per gruppo di lavoro e colore EgtSetName( AddGrpId, sMchGrp) EgtSetInfo( AddGrpId, GDB_SI.MGRPONLY, EgtGetCurrMachGroup()) EgtSetColor( AddGrpId, Color3d( 80, 160, 160, 50)) + return true end @@ -125,9 +137,13 @@ end function BeamLib.GetAddGroup( PartId) -- recupero il nome del gruppo di lavoro corrente local sMchGrp = EgtGetMachGroupName( EgtGetCurrMachGroup() or GDB_ID.NULL) - if not sMchGrp then return nil, nil end + if not sMchGrp then + return nil, nil + end + -- cerco il gruppo aggiuntivo omonimo nel pezzo e se esiste lo restituisco local AddGrpId = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, sMchGrp) + -- restituisco Id e Nome return AddGrpId, sMchGrp end @@ -164,15 +180,18 @@ end --------------------------------------------------------------------- -- Funzione per determinare se la faccia ha lati molto corti (trascurabili) ed è quindi approssimabile ad una 3 facce -function BeamLib.Is3EdgesApprox( Proc, nFacet, nAddGrpId) +function BeamLib.Is3EdgesApprox( Proc, idFace, nAddGrpId) nAddGrpId = nAddGrpId or BeamLib.GetAddGroup( Proc.PartId) if not nAddGrpId then - local nEdges = #(EgtSurfTmFacetAdjacencies( Proc.Id, nFacet)[1]) + local nEdges = #(EgtSurfTmFacetAdjacencies( Proc.Id, idFace)[1]) return ( nEdges == 3) end local bResult = false - local nContourId, nContourCnt = EgtExtractSurfTmFacetLoops( Proc.Id, nFacet, nAddGrpId) - if not nContourId then return false end + + local nContourId, nContourCnt = EgtExtractSurfTmFacetLoops( Proc.Id, idFace, nAddGrpId) + if not nContourId then + return false + end EgtMergeCurvesInCurveCompo( nContourId) -- recupero il numero effettivo di lati local _, nEntityCount = EgtCurveDomain( nContourId) @@ -189,8 +208,42 @@ function BeamLib.Is3EdgesApprox( Proc, nFacet, nAddGrpId) if nEdges == 3 then bResult = true end -- cancello tutti i contorni appena creati EgtErase( EgtTableFill( nContourId, nContourCnt)) + return bResult end +--------------------------------------------------------------------- +--- ritorna il riferimento di tipo OCS della faccia *idFace* della trimesh *nSurfId* e le dimensioni orizzontale e verticale, eventualmente limitate dal grezzo *b3Raw* +function BeamLib.GetFaceHvRefDim( nSurfId, idFace, b3Raw) + -- recupero centro e normale della faccia + local ptC, vtN = EgtSurfTmFacetCenter( nSurfId, idFace, GDB_ID.ROOT) + if not ptC or not vtN then + return + end + -- riferimento tipo OCS della faccia (X orizz, Y max pendenza, Z normale) + local frHV = Frame3d( ptC, vtN) + if frHV:getVersY():getZ() < 0 then + frHV:rotate( ptC, vtN, 180) + end + -- determino l'ingombro in questo riferimento + local b3HV = EgtSurfTmGetFacetBBoxRef( nSurfId, idFace, GDB_BB.STANDARD, frHV) + local dDimH = b3HV:getDimX() + local dDimV = b3HV:getDimY() + -- se definito grezzo (o solido), applico eventuali limiti + if b3Raw then + local dCoeffY = abs( frHV:getVersX():getY()) + if dCoeffY > GEO.EPS_SMALL then + dDimH = min( dDimH, b3Raw:getDimY() / dCoeffY) + end + local dCoeffZ = abs( frHV:getVersY():getZ()) + if dCoeffZ > GEO.EPS_SMALL then + dDimV = min( dDimV, b3Raw:getDimZ() / dCoeffZ) + end + end + + -- restituisco i valori calcolati + return frHV, dDimH, dDimV +end + ------------------------------------------------------------------------------------------------------------- return BeamLib diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua new file mode 100644 index 0000000..e42f737 --- /dev/null +++ b/LuaLibs/FaceData.lua @@ -0,0 +1,230 @@ +-- FaceData.lua by Egalware s.r.l. 2024/04/18 +-- Libreria lettura o calcolo dati e proprietà delle facce di una trimesh +-- 2024/04/02 PRIMA VERSIONE CALCOLO LAVORAZIONI CON STRATEGIE + +-- Tabella per definizione modulo +local FaceData = {} + +-- Carico i dati globali +local BD = require( 'BeamData') + +-- carico librerie +local BeamLib = require( 'BeamLib') + + +--------------------------------------------------------------------- +-- restituisce la matrice delle adiacenze di Proc dove i e j sono le facce e a(ij) è l'angolo tra di esse; 0 se nessuna adiacenza +function FaceData.GetAdjacencyMatrix( Proc) + local vAdj = {} + + -- essendo la matrice simmetrica a diagonale nulla, ne calcolo solo la metà superiore + for i = 1, Proc.Fct do + vAdj[i] = {} + for j = i + 1, Proc.Fct do + _, _, _, vAdj[i][j] = EgtSurfTmFacetsContact( Proc.Id, i - 1, j - 1, GDB_ID.ROOT) + if not vAdj[i][j] then + vAdj[i][j] = 0 + end + end + end + + -- riempio di conseguenza il resto della matrice + for i = 1, Proc.Fct do + vAdj[i][i] = 0 + for j = i + 1, Proc.Fct do + vAdj[j][i] = vAdj[i][j] + end + + end + return vAdj +end + +--------------------------------------------------------------------- +-- restituisce un vettore con gli indici (0 based) delle facce triangolari (o quasi) di Proc +function FaceData.GetTriangularFaces( Proc) + local vTriangularFaces = {} + + for i = 1, Proc.Fct do + if BeamLib.Is3EdgesApprox( Proc, i - 1) then + table.insert( vTriangularFaces, i - 1) + end + + end + return vTriangularFaces +end + +------------------------------------------------------------------------------------------------------------- +local function GetAdjacentFaces( Proc, idFace) + local AdjacentFaces = {} + + local vAdj + if Proc.AdjacencyMatrix then + vAdj = Proc.AdjacencyMatrix + else + vAdj = FaceData.GetAdjacencyMatrix( Proc) + end + + for i = 1, Proc.Fct do + if vAdj[idFace + 1][i] and vAdj[idFace + 1][i] ~= 0 and ( idFace + 1 ~= i) then + local _, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, idFace, i - 1, GDB_ID.ROOT) + local dLength = dist( ptP1, ptP2) + AdjacentFaces[i].Id = i - 1 + AdjacentFaces[i].LengthOnMainFace = dLength + end + end + + return AdjacentFaces +end + +--------------------------------------------------------------------- +-- restituisce una tabella che correla numero di adiacenze e id delle facce con quello stesso numero di adiacenze +function FaceData.GetFacesByAdjacencyNumber( Proc) + local FacesByAdjacencyNumber = {} + + for i = 1, Proc.Fct do + table.insert( FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies], i - 1) + end + + return FacesByAdjacencyNumber +end + +------------------------------------------------------------------------------------------------------------- +local function GetBottomFace( Proc) + local BottomFace = {} + + -- la faccia di fondo ha sempre Fct - 1 adiacenze. Se si trovano più facce di fondo si sceglie quella con minor elevazione + local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) + local vBottomFace = vFacesByAdjNumber[ Proc.Fct - 1] + local nBottomFace + if #vBottomFace > 1 then + local dMinElevation = GEO.INFINITO + for i = 1, #vBottomFace do + for j = 1, Proc.Fct do + if vBottomFace[i] == Proc.Face[j].Id then + if Proc.Face[j].Elevation < dMinElevation then + dMinElevation = Proc.Face[j].Elevation + nBottomFace = Proc.Face[j].Id + end + end + end + end + else + nBottomFace = vBottomFace[1] + end + + BottomFace.Id = nBottomFace + BottomFace.FrameHV = Proc.Face[nBottomFace + 1].FrameHV + BottomFace.Width = Proc.Face[nBottomFace + 1].Width + BottomFace.Height = Proc.Face[nBottomFace + 1].Height + BottomFace.Elevation = Proc.Face[nBottomFace + 1].Elevation + BottomFace.VtN = Proc.Face[nBottomFace + 1].VtN + + return BottomFace +end + +------------------------------------------------------------------------------------------------------------- +local function GetLongFaces( Proc) + local LongFaces = {} + + if Proc.Fct > 5 then + error( 'GetLongFaces : More than 5 faces not supported') + end + + local idBottomFace = GDB_ID.NULL + if Proc.MainFaces.BottomFace.Id then + idBottomFace = Proc.MainFaces.BottomFace.Id + else + local BottomFace = GetBottomFace( Proc) + idBottomFace = BottomFace.Id + end + + -- facce adiacenti a quella di fondo, ordinate + local FacesAdjacentToBottom = GetAdjacentFaces( Proc, idBottomFace) + table.sort( FacesAdjacentToBottom, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) + + -- la prima faccia lunga è sempre la prima della lista + LongFaces[1].Id = FacesAdjacentToBottom[1].Id + -- si cerca l'eventuale seconda faccia lunga, ossia quella non adiacente alla prima + if Proc.Fct > 3 then + for i = 1, Proc.Fct do + if ( i - 1) ~= idBottomFace and ( i - 1) ~= LongFaces[1].Id then + local bIsAdjacent = false + for j = 1, #Proc.Face[i].Adjacences do + if Proc.Face[i].Adjacences[j].Id == LongFaces[i].Id then + bIsAdjacent = true + end + end + if not bIsAdjacent then + LongFaces[2].Id = i - 1 + break + end + end + end + end + + for i = 1, #LongFaces do + for j = 1, Proc.Fct do + if LongFaces[i].Id == Proc.Face[j].Id then + LongFaces[i].Frame = Proc.Face[j].FrameHV + LongFaces[i].Width = Proc.Face[j].Width + LongFaces[i].Height = Proc.Face[j].Height + LongFaces[i].Elevation = Proc.Face[j].Elevation + LongFaces[i].VtN = Proc.Face[j].VtN + end + end + end + + return LongFaces +end + +------------------------------------------------------------------------------------------------------------- +function FaceData.GetFacesInfo( Proc, b3Raw) + Faces = {} + local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) + + for i = 1, Proc.Fct do + Faces[i].Id = i - 1 + Faces[i].VtN = EgtSurfTmFacetNormVersor( Proc.Id, i - 1, GDB_ID.ROOT ) + if Proc.Fct < 6 then + local frHV, dFaceWidth, dFaceHeight = BeamLib.GetFaceHvRefDim( Proc.Id, i - 1, b3Raw) + -- frame OCS faccia + Faces[i].FrameHV = frHV + -- larghezza OCS faccia + Faces[i].Width = dFaceWidth + -- altezza OCS faccia + Faces[i].Height = dFaceHeight + -- elevazione calcolata rispetto al box della parte + Faces[i].Elevation = EgtSurfTmFacetElevationInBBox( Proc.Id, i - 1, b3Solid, true, GDB_ID.ROOT) + -- adiacenze della faccia + Faces[i].Adjacencies = GetAdjacentFaces( Proc, i - 1) + end + end + + return Faces +end + +------------------------------------------------------------------------------------------------------------- +-- recupero facce principali della feature, in base alla topologia +function FaceData.GetMainFaces( Proc) + local MainFaces = {} + + -- faccia di fondo + if Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket' then + MainFaces.BottomFace = GetBottomFace( Proc) + end + + -- facce lunghe + if Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket' or Proc.FeatureTopology.Family == 'Tunnel' then + MainFaces.LongFaces = GetLongFaces( Proc) + end + + -- facce laterali + + + + return MainFaces +end + + +------------------------------------------------------------------------------------------------------------- +return FaceData \ No newline at end of file diff --git a/LuaLibs/FeatureData.lua b/LuaLibs/FeatureData.lua index 4fb67f6..0a254fd 100644 --- a/LuaLibs/FeatureData.lua +++ b/LuaLibs/FeatureData.lua @@ -9,15 +9,14 @@ local FeatureData = {} local BD = require( 'BeamData') -- carico librerie -local BL = require( 'BeamLib') +local BeamLib = require( 'BeamLib') +local FaceData = require( 'FaceData') local ID = require( 'Identity') ------------------------------------------------------------------------------------------------------------- -- recupero topologia della feature -------------------------------------------------------------------------------------------------------------- local function NeedTopologyFeature( Proc) - -- richiedono calcolo topologia le feature tipo: if ID.IsCut( Proc) then return true elseif ID.IsDoubleCut( Proc) then @@ -44,41 +43,25 @@ local function NeedTopologyFeature( Proc) return true elseif ID.IsPocket( Proc) then return true - elseif ID.IsMortise( Proc) and Proc.Fct < 6 then -- calcolo topologia SOLO se non raggiata -- TODO oppure riconoscerla come feature speciale + -- calcolo topologia SOLO se non raggiata + -- TODO oppure riconoscerla come feature speciale; valutare se controllare il numero di facce è un metodo efficace + elseif ID.IsMortise( Proc) and Proc.Fct < 6 then return true - elseif ID.IsFrontMortise( Proc) and Proc.Fct < 6 then -- calcolo topologia SOLO se non raggiata -- TODO oppure riconoscerla come feature speciale + -- calcolo topologia SOLO se non raggiata + -- TODO oppure riconoscerla come feature speciale; valutare se controllare il numero di facce è un metodo efficace + elseif ID.IsFrontMortise( Proc) and Proc.Fct < 6 then return true end - -- tutte le altre non richiedono calcolo topologia - return false -end ---------------------------------------------------------------------- --- restituisce la matrice delle adiacenze di Proc dove i e j sono le facce e a(ij) è l'angolo tra di esse; 0 se nessuna adiacenza -local function GetAdjacencyMatrix( Proc) - local vAdj = {} - -- essendo la matrice simmetrica a diagonale nulla, ne calcolo solo la metà superiore - for i = 1, Proc.Fct do - vAdj[i] = {} - for j = i + 1, Proc.Fct do - _, _, _, vAdj[i][j] = EgtSurfTmFacetsContact( Proc.Id, i - 1, j - 1, GDB_ID.ROOT) - if not vAdj[i][j] then vAdj[i][j] = 0 end - end - end - -- riempio di conseguenza il resto della matrice - for i = 1, Proc.Fct do - vAdj[i][i] = 0 - for j = i + 1, Proc.Fct do - vAdj[j][i] = vAdj[i][j] - end - end - return vAdj + -- se feature non tra quelle sopra, riconoscimento topologico non necessario + return false end --------------------------------------------------------------------- -- restituisce true se Proc ha tutti gli angoli concavi (bAllConcave) e, nei casi in cui ha senso, se questi sono esattamente 90 deg (bAllRight) local function AreAllAnglesConcaveOrRight( vAdj) local bAllConcave, bAllRight = true, true + local nFct = #( vAdj or {}) for i = 1, nFct do for j = 1, nFct do @@ -92,6 +75,7 @@ local function AreAllAnglesConcaveOrRight( vAdj) end end end + -- se 1 faccia oppure 2 facce con angolo convesso non ha senso ritornare valori per bAllRight if nFct < 2 or ( nFct == 2 and vAdj[1][2] > 0) then return bAllConcave @@ -100,17 +84,6 @@ local function AreAllAnglesConcaveOrRight( vAdj) end end ---------------------------------------------------------------------- --- retituisce un vettore con gli indici (0 based) delle facce triangolari (o quasi) di Proc -local function GetTriangularFaces( Proc) - local vTriangularFaces = {} - for i = 1, Proc.Fct do - if BL.Is3EdgesApprox( Proc, i - 1) then - table.insert( vTriangularFaces, i - 1) - end - end - return vTriangularFaces -end --------------------------------------------------------------------- -- restituisce true se almeno una delle dimensioni della feature è maggiore o uguale ad una delle dimensioni principali del pezzo (tolleranza 1 mm) @@ -118,32 +91,14 @@ local function IsAnyDimensionLongAsPart( Proc) local bResult = false local nBoxSolidId = EgtGetFirstNameInGroup( Proc.PartId or GDB_ID.NULL, 'Box') local b3Solid = EgtGetBBoxGlob( nBoxSolidId, GDB_BB.STANDARD) + if Proc.Box:getDimX() > b3Solid:getDimX() - 1000 * GEO.EPS_SMALL or Proc.Box:getDimY() > b3Solid:getDimY() - 1000 * GEO.EPS_SMALL or Proc.Box:getDimZ() > b3Solid:getDimZ() - 1000 * GEO.EPS_SMALL then bResult = true end - return bResult -end ---------------------------------------------------------------------- --- restituisce gli id delle facce di Proc che hanno il numero di adiacenze nAdj -local function GetFacesWithGivenAdjacencyNumber( Proc, vAdj) - if not vAdj then vAdj = GetAdjacencyMatrix( Proc) end - local nFct = #( vAdj or {}) - local vFacesWithAdj = {} - for i = 1, nFct do - local nAdjCount = 0 - for j = 1, nFct do - if vAdj[i][j] and vAdj[i][j] ~= 0 and i ~= j then - nAdjCount = nAdjCount + 1 - end - end - if nAdjCount > 0 then - table.insert( vFacesWithAdj[nAdjCount], i - 1) - end - end - return vFacesWithAdj + return bResult end ------------------------------------------------------------------------------------------------------------- @@ -165,23 +120,22 @@ end local function GetTopologyName( sFamily, nNumberOfFaces, bIsThrough) return sFamily .. '-' .. nNumberOfFaces .. '-' .. EgtIf( bIsThrough, 'Through', 'Blind') end + --------------------------------------------------------------------- -- recupera topologia feature local function ClassifyTopology( Proc, b3Raw) local FeatureTopology = {} - -- calcoli - if not Proc.AffectedFaces then Proc.AffectedFaces = BL.GetProcessAffectedFaces( Proc) end + if not Proc.AffectedFaces then Proc.AffectedFaces = BeamLib.GetProcessAffectedFaces( Proc) end - local vAdj = GetAdjacencyMatrix( Proc) + local vAdj = FaceData.GetAdjacencyMatrix( Proc) local bAllAnglesConcave, bAllRightAngles = AreAllAnglesConcaveOrRight( vAdj) - local vTriangularFaces = GetTriangularFaces( Proc) + local vTriangularFaces = FaceData.GetTriangularFaces( Proc) local bIsAnyDimensionLongAsPart = IsAnyDimensionLongAsPart( Proc) - local vFacesWithAdjNumber = GetFacesWithGivenAdjacencyNumber( Proc, vAdj) + local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) local bIsFeatureCuttingEntireSection = IsFeatureCuttingEntireSection( Proc.Box, b3Raw) local bIsFeatureCuttingEntireLength = IsFeatureCuttingEntireLength( Proc.Box, b3Raw) - -- assegnazione tipologia local sFamily local bIsThrough if Proc.Fct == 1 and ( bIsFeatureCuttingEntireSection or bIsFeatureCuttingEntireLength) then @@ -196,52 +150,52 @@ local function ClassifyTopology( Proc, b3Raw) sFamily = 'Rabbet' bIsThrough = true elseif Proc.Fct == 2 and bAllAnglesConcave then - sFamily = 'V-Groove' + sFamily = 'VGroove' bIsThrough = true elseif Proc.Fct == 2 and not bAllAnglesConcave and bIsAnyDimensionLongAsPart then sFamily = 'DoubleBevel' bIsThrough = true - elseif Proc.Fct == 3 and bAllAnglesConcave and #vFacesWithAdjNumber[2] == 1 and #vTriangularFaces == 2 then + elseif Proc.Fct == 3 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 1 and #vTriangularFaces == 2 then sFamily = 'Bevel' bIsThrough = false - elseif Proc.Fct == 3 and bAllAnglesConcave and #vFacesWithAdjNumber[2] == 1 and bIsAnyDimensionLongAsPart then + elseif Proc.Fct == 3 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 1 and bIsAnyDimensionLongAsPart then sFamily = 'Groove' bIsThrough = true - elseif Proc.Fct == 3 and bAllAnglesConcave and #vFacesWithAdjNumber[2] == 3 then + elseif Proc.Fct == 3 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 3 then sFamily = 'Groove' bIsThrough = false - elseif Proc.Fct == 4 and #vFacesWithAdjNumber[2] == 4 and #vTriangularFaces == 2 then + elseif Proc.Fct == 4 and #vFacesByAdjNumber[2] == 4 and #vTriangularFaces == 2 then sFamily = 'DoubleBevel' bIsThrough = false - elseif Proc.Fct == 4 and bAllAnglesConcave and #vFacesWithAdjNumber[3] == 2 then + elseif Proc.Fct == 4 and bAllAnglesConcave and #vFacesByAdjNumber[3] == 2 then sFamily = 'Groove' bIsThrough = false - elseif Proc.Fct == 4 and bAllAnglesConcave and #vFacesWithAdjNumber[2] == 4 and bIsAnyDimensionLongAsPart then + elseif Proc.Fct == 4 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 4 and bIsAnyDimensionLongAsPart then sFamily = 'Tunnel' bIsThrough = true - elseif Proc.Fct >= 4 and #vFacesWithAdjNumber[1] == 2 and bIsAnyDimensionLongAsPart then + elseif Proc.Fct >= 4 and #vFacesByAdjNumber[1] == 2 and bIsAnyDimensionLongAsPart then sFamily = 'Strip' bIsThrough = true - elseif Proc.Fct == 5 and bAllAnglesConcave and #vFacesWithAdjNumber[4] == 1 then + elseif Proc.Fct == 5 and bAllAnglesConcave and #vFacesByAdjNumber[4] == 1 then sFamily = 'Pocket' bIsThrough = false - elseif Proc.Fct == 6 and #vFacesWithAdjNumber[2] == 4 and #vFacesWithAdjNumber[3] == 2 and #vTriangularFaces == 4 then + elseif Proc.Fct == 6 and #vFacesByAdjNumber[2] == 4 and #vFacesByAdjNumber[3] == 2 and #vTriangularFaces == 4 then sFamily = 'DoubleBevel' bIsThrough = false end - -- assegnazioni if sFamily then FeatureTopology.Family = sFamily FeatureTopology.IsThrough = bIsThrough FeatureTopology.AllRightAngles = bAllRightAngles FeatureTopology.Name = GetTopologyName( sFamily, bIsThrough, bAllRightAngles) - FeatureTopology.vAdj = vAdj + FeatureTopology.AdjacencyMatrix = vAdj -- feature che necessita di essere catalogata, ma non si capisce come else FeatureTopology.Family = 'NOT_IMPLEMENTED' FeatureTopology.Name = FeatureTopology.Family end + return FeatureTopology end @@ -252,7 +206,6 @@ function FeatureData.GetTopology( Proc, b3Raw) -- calcolo topologia solo se necessario, altrimenti si sfruttano le informazioni della feature BTL if NeedTopologyFeature( Proc) then FeatureTopology = ClassifyTopology( Proc, b3Raw) - -- se non richiesto, setto 'FEATURE' else FeatureTopology.Family = 'FEATURE' FeatureTopology.Name = FeatureTopology.Family @@ -261,19 +214,11 @@ function FeatureData.GetTopology( Proc, b3Raw) return FeatureTopology end -------------------------------------------------------------------------------------------------------------- --- recupero facce principali della feature, in base alla topologia -------------------------------------------------------------------------------------------------------------- -function FeatureData.GetMainFaces( Proc, b3Raw) - local MainFaces = {} - - return MainFaces -end ------------------------------------------------------------------------------------------------------------- -- Recupero dati foro e adattamento se speciale -------------------------------------------------------------------------------------------------------------- -function FeatureData.GetDataDrill( Proc) +function FeatureData.GetDrillingData( Proc) local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') + -- verifico se foro da adattare if EgtExistsInfo( Proc.Id, 'DiamUser') then if AuxId then AuxId = AuxId + Proc.Id end @@ -281,12 +226,12 @@ function FeatureData.GetDataDrill( Proc) EgtModifyArcRadius( AuxId, BD.USER_HOLE_DIAM / 2) end end - -- recupero diametro e lunghezza + local dDiam = EgtGetInfo( Proc.Id, 'P12', 'd') or 0 local dLen = abs( EgtCurveThickness( Proc.Id + AuxId)) or 0 - -- recupero faccia di entrata e uscita local nFcs = EgtGetInfo( Proc.Id, 'FCS', 'i') or 0 local nFce = EgtGetInfo( Proc.Id, 'FCE', 'i') or 0 + return dDiam, dLen, nFcs, nFce end