diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index c4cc5cd..8346a9a 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -494,6 +494,7 @@ local function CollectFeatures( PartId, b3Raw) Proc.MainId = Proc.Id + nAddMainId end Proc.Box = EgtGetBBoxGlob( ProcId, GDB_BB.STANDARD) + EgtOutLog( '------Feature ' .. Proc.FeatureId .. '------') -- se esiste la geometria if Proc.Box and not Proc.Box:isEmpty() then -- TODO fare una funzione per recuperare i dati delle feature che non passano dal calcolo della topologia? @@ -504,7 +505,7 @@ local function CollectFeatures( PartId, b3Raw) end -- informazioni facce e topologia Proc.AdjacencyMatrix = FaceData.GetAdjacencyMatrix( Proc) - Proc.Faces = FaceData.GetFacesInfo( Proc, b3Raw) + Proc.Faces = FaceData.GetFacesInfo( Proc) 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 diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index b6662e1..53d1d0c 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -51,9 +51,55 @@ function FaceData.GetTriangularFaces( Proc) end ------------------------------------------------------------------------------------------------------------- -local function GetAdjacentFaces( Proc, idFace) - local AdjacentFaces = {} +local function GetNotAdjacentFaces( Proc, idFace) + local NotAdjacentFaces = {} + for i = 1, Proc.Fct do + if Proc.Faces[i].Id ~= idFace then + local bIsAdjacent = false + for j = 1, #Proc.Faces[idFace + 1].Adjacencies do + if Proc.Faces[i].Id == Proc.Faces[idFace + 1].Adjacencies[j] then + bIsAdjacent = true + end + end + if not bIsAdjacent then + table.insert( NotAdjacentFaces, Proc.Faces[i]) + end + end + end + + return NotAdjacentFaces +end + +--------------------------------------------------------------------- +local function GetFacesContactLength( Proc, idFace1, idFace2) + local _, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, idFace1, idFace2, GDB_ID.ROOT) + local dLength = dist( ptP1, ptP2) + + return dLength +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, 10 do + FacesByAdjacencyNumber[i] = {} + end + for i = 1, Proc.Fct do + table.insert( FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies], Proc.Faces[i]) + end + + return FacesByAdjacencyNumber +end + +------------------------------------------------------------------------------------------------------------- +function FaceData.GetFacesInfo( Proc) + EgtOutLog( '---Faces START---') + local Faces = {} + + local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) local vAdj if Proc.AdjacencyMatrix then vAdj = Proc.AdjacencyMatrix @@ -61,134 +107,12 @@ local function GetAdjacentFaces( Proc, idFace) 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] = {} - 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 - if not FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies] then - FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies] = {} - end - 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.Faces[j].Id then - if Proc.Faces[j].Elevation < dMinElevation then - dMinElevation = Proc.Faces[j].Elevation - nBottomFace = Proc.Faces[j].Id - end - end - end - end - else - nBottomFace = vBottomFace[1] - end - - BottomFace.Id = nBottomFace - BottomFace.FrameHV = Proc.Faces[nBottomFace + 1].FrameHV - BottomFace.Width = Proc.Faces[nBottomFace + 1].Width - BottomFace.Height = Proc.Faces[nBottomFace + 1].Height - BottomFace.Elevation = Proc.Faces[nBottomFace + 1].Elevation - BottomFace.VtN = Proc.Faces[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 and 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.Faces[i].Adjacences do - if Proc.Faces[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.Faces[j].Id then - LongFaces[i].Frame = Proc.Faces[j].FrameHV - LongFaces[i].Width = Proc.Faces[j].Width - LongFaces[i].Height = Proc.Faces[j].Height - LongFaces[i].Elevation = Proc.Faces[j].Elevation - LongFaces[i].VtN = Proc.Faces[j].VtN - end - end - end - - return LongFaces -end - -------------------------------------------------------------------------------------------------------------- -function FaceData.GetFacesInfo( Proc, b3Raw) - local Faces = {} - local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) - for i = 1, Proc.Fct do Faces[i] = {} Faces[i].Id = i - 1 - Faces[i].VtN = EgtSurfTmFacetNormVersor( Proc.Id, i - 1, GDB_ID.ROOT ) + Faces[i].PtCenter, Faces[i].VtN = EgtSurfTmFacetCenter( Proc.Id, i - 1, GDB_ID.ROOT) if Proc.Fct < 6 then - local frHV, dFaceWidth, dFaceHeight = BeamLib.GetFaceHvRefDim( Proc.Id, i - 1, b3Raw) + local frHV, dFaceWidth, dFaceHeight = BeamLib.GetFaceHvRefDim( Proc.Id, i - 1) -- frame OCS faccia Faces[i].FrameHV = frHV -- larghezza OCS faccia @@ -197,33 +121,228 @@ function FaceData.GetFacesInfo( Proc, b3Raw) Faces[i].Height = dFaceHeight -- elevazione calcolata rispetto al box della parte Faces[i].Elevation = EgtSurfTmFacetElevationInBBox( Proc.Id, i - 1, b3Solid, true, GDB_ID.ROOT) + + -- TODO valutare se fare un output unico alla fine o gestire log in altro modo + EgtOutLog( 'Facet ' .. Faces[i].Id .. ' of ' .. Proc.Fct - 1) + EgtOutLog( ' VtN: ' .. tostring( Faces[i].VtN)) + -- adiacenze della faccia - Faces[i].Adjacencies = GetAdjacentFaces( Proc, i - 1) + -- TODO chiamarle in modo che si capisca che sono solo gli id e non l'intero oggetto faccia + Faces[i].Adjacencies = {} + for j = 1, Proc.Fct do + if vAdj[i][j] and vAdj[i][j] ~= 0 and ( i ~= j) then + table.insert( Faces[i].Adjacencies, j - 1) + if EgtGetDebugLevel() >= 3 then + EgtOutLog( ' Adjacent to facet: ' .. j - 1) + end + end + end end end + EgtOutLog( '---Faces END---') return Faces end +------------------------------------------------------------------------------------------------------------- +-- TODO valutare refactoring per mettere i calcoli del tunnel in una funzione +-- TODO valutare se restituire anche altre informazioni oltre alle facce (es: box); magari metterle in funzione a parte chiamata allo stesso livello della GetMainFAces +local function GetTunnelFaces( Proc) + local TunnelAddedFaces = {} + + -- TODO scrivere il box della parte nella Proc o fare funzione per recuperarlo + local b3Part = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) + + if not ( Proc.Topology.IsThrough and Proc.Topology.AllRightAngles and Proc.Fct < 5) then + error( 'GetTunnelFaces : Topology not implemented') + end + + -- direzione del tunnel + local vtTunnelDirection = Proc.Faces[1].VtN ^ Proc.Faces[ Proc.Faces[1].Adjacencies[1] + 1].VtN + + -- centro del tunnel + local frTunnel = Frame3d( Proc.Faces[1].PtCenter, vtTunnelDirection) + local b3Tunnel = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frTunnel) + local ptTunnelCenter = b3Tunnel:getCenter() + ptTunnelCenter:toGlob( frTunnel) + + -- recupero gruppo per geometria addizionale + local nAddGrpId = BeamLib.GetAddGroup( Proc.PartId) + if not nAddGrpId then + -- TODO gestire meglio questo errore. Non conviene creare e verificare all'inizio se il gruppo esiste? + EgtOutLog( 'Error : missing AddGroup') + return TunnelAddedFaces + end + + -- faccia centrale, si crea larga come la parte e poi si trimma + TunnelAddedFaces.MiddleFaceTm = {} + TunnelAddedFaces.MiddleFaceTm.Id = EgtSurfTmPlaneInBBox( nAddGrpId, ptTunnelCenter, vtTunnelDirection, b3Part, GDB_ID.ROOT) + -- TODO se non si riesce a costruire la faccia bisogna dare errore o semplicemente non ritornarla?? + for i = 1, Proc.Fct do + EgtCutSurfTmPlane( TunnelAddedFaces.MiddleFaceTm.Id, Proc.Faces[i].PtCenter, -Proc.Faces[i].VtN, false, GDB_ID.ROOT) + end + + return TunnelAddedFaces +end + +------------------------------------------------------------------------------------------------------------- +local function GetBottomFace( Proc) + local BottomFace = {} + + if Proc.Topology.Family == 'Tunnel' then + return BottomFace + elseif not ( Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket') then + error( 'GetBottomFace : Topology not implemented') + end + + -- la faccia di fondo ha sempre Fct - 1 adiacenze. Se si trovano più facce di fondo si sceglie quella con minor elevazione + local FacesByAdjacencyNumber = FaceData.GetFacesByAdjacencyNumber( Proc) + local BottomFaces = FacesByAdjacencyNumber[ Proc.Fct - 1] + if #BottomFaces > 1 then + local dMinElevation = GEO.INFINITO + for i = 1, #BottomFaces do + if Proc.Faces[BottomFaces[i].Id + 1].Elevation < dMinElevation then + dMinElevation = Proc.Faces[BottomFaces[i].Id + 1].Elevation + BottomFace = Proc.Faces[BottomFaces[i].Id + 1] + end + end + else + BottomFace = BottomFaces[1] + end + + return BottomFace +end + +------------------------------------------------------------------------------------------------------------- +local function GetLongFaces( Proc, MainFaces) + local LongFaces = {} + + if Proc.Fct > 5 then + error( 'GetLongFaces : Topology not implemented') + end + + local idBottomFace = GDB_ID.NULL + if MainFaces.BottomFace then + idBottomFace = MainFaces.BottomFace.Id + else + local BottomFace = GetBottomFace( Proc) + idBottomFace = BottomFace.Id or idBottomFace + end + + local idTunnelMiddleFace = GDB_ID.NULL + if Proc.Topology.Family == 'Tunnel' then + if MainFaces.TunnelAddedFaces then + idTunnelMiddleFace = MainFaces.TunnelAddedFaces.MiddleFaceTm.Id + else + local TunnelAddedFaces = GetTunnelFaces( Proc) + idTunnelMiddleFace = TunnelAddedFaces.MiddleFaceTm.Id or idTunnelMiddleFace + end + end + + local FacesToAnalyze = {} + for i = 1, Proc.Fct do + if Proc.Faces[i].Id ~= idBottomFace then + table.insert( FacesToAnalyze, Proc.Faces[i]) + if Proc.Topology.Family == 'Tunnel' then + -- TODO questo non funziona nei tunnel, da modificare + FacesToAnalyze[#FacesToAnalyze].LengthOnMainFace = GetFacesContactLength( Proc, idTunnelMiddleFace, Proc.Faces[i].Id) + else + FacesToAnalyze[#FacesToAnalyze].LengthOnMainFace = GetFacesContactLength( Proc, idBottomFace, Proc.Faces[i].Id) + end + end + end + table.sort( FacesToAnalyze, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) + + -- la prima faccia lunga è sempre la prima della lista + LongFaces[1] = FacesToAnalyze[1] + -- si cerca l'eventuale seconda faccia lunga, ossia quella non adiacente alla prima + if Proc.Fct > 3 then + local NotAdjacentFaces = GetNotAdjacentFaces(Proc, LongFaces[1].Id) + if #NotAdjacentFaces > 0 then + LongFaces[2] = NotAdjacentFaces[1] + end + end + + return LongFaces +end + +------------------------------------------------------------------------------------------------------------- +local function GetSideFaces( Proc, MainFaces) + local SideFaces = {} + + if Proc.Fct > 5 then + error( 'GetSideFaces : Topology not implemented') + end + + local idBottomFace = GDB_ID.NULL + if MainFaces.BottomFace then + idBottomFace = MainFaces.BottomFace.Id + else + local BottomFace = GetBottomFace( Proc) + idBottomFace = BottomFace.Id or idBottomFace + end + local LongFaces = {} + if MainFaces.LongFaces then + LongFaces = MainFaces.LongFaces + else + LongFaces = GetLongFaces( Proc, MainFaces) + end + + for i = 1, Proc.Fct do + if i ~= idBottomFace + 1 then + local bIsSideFace = true + for j = 1, #LongFaces do + if Proc.Faces[i].Id == LongFaces[j].Id then + bIsSideFace = false + break + end + end + if bIsSideFace then + table.insert( SideFaces, Proc.Faces[i]) + end + end + end + + return SideFaces +end + ------------------------------------------------------------------------------------------------------------- -- recupero facce principali della feature, in base alla topologia function FaceData.GetMainFaces( Proc) + EgtOutLog( '---MainFaces START---') local MainFaces = {} - -- faccia di fondo - if Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket' then - MainFaces.BottomFace = GetBottomFace( Proc) + if Proc.Topology.IsThrough and Proc.Topology.AllRightAngles and Proc.Fct < 5 then + MainFaces.TunnelAddedFaces = GetTunnelFaces( Proc) end - -- facce lunghe if Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket' or Proc.Topology.Family == 'Tunnel' then - MainFaces.LongFaces = GetLongFaces( Proc) + MainFaces.BottomFace = GetBottomFace( Proc) + MainFaces.LongFaces = GetLongFaces( Proc, MainFaces) + MainFaces.SideFaces = GetSideFaces( Proc, MainFaces) end - -- facce laterali - - + -- TODO funzione apposita per informazioni log? + if EgtGetDebugLevel() >= 3 then + if MainFaces.BottomFace then + EgtOutLog( 'Bottom Face : ' .. MainFaces.BottomFace.Id) + end + if MainFaces.LongFaces then + for i = 1, #MainFaces.LongFaces do + EgtOutLog( 'Long Face : ' .. MainFaces.LongFaces[i].Id) + end + end + if MainFaces.SideFaces then + for i = 1, #MainFaces.SideFaces do + EgtOutLog( 'Side Face : ' .. MainFaces.SideFaces[i].Id) + end + end + if MainFaces.TunnelAddedFaces then + EgtOutLog( 'Middle Face (Trimesh): ' .. MainFaces.TunnelAddedFaces.MiddleFaceTm.Id) + end + end + EgtOutLog( '---MainFaces END---') return MainFaces end