-- FeatureData.lua by Egalware s.r.l. 2024/04/02 -- Libreria lettura o calcolo dati e proprietà della feature -- 2024/04/02 PRIMA VERSIONE CALCOLO LAVORAZIONI CON STRATEGIE -- Tabella per definizione modulo local FeatureData = {} -- Carico i dati globali local BeamData = require( 'BeamData') -- carico librerie local BeamLib = require( 'BeamLib') local FaceData = require( 'FaceData') local ID = require( 'Identity') ------------------------------------------------------------------------------------------------------------- -- recupero topologia della feature function FeatureData.NeedTopologyFeature( Proc) -- features tipo taglio if ID.IsCut( Proc) then return true elseif ID.IsDoubleCut( Proc) then return true elseif ID.IsSawCut( Proc) then return true -- features tipo taglio longitudinale elseif ID.IsLongitudinalCut( Proc) then return true elseif ID.IsDoubleLongitudinalCut( Proc) then return true elseif ID.IsChamfer( Proc) then return true -- features tipo LapJoint elseif ID.IsSlot( Proc) then return true elseif ID.IsFrontSlot( Proc) then return true elseif ID.IsRidgeLap( Proc) then return true elseif ID.IsLapJoint( Proc) then return true elseif ID.IsNotchRabbet( Proc) then return true elseif ID.IsNotch( Proc) then return true elseif ID.IsPocket( Proc) then return true -- 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.nFct < 6 then return true -- 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.nFct < 6 then return true end -- 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) -- se la feature ha una sola faccia, esco subito if #vAdj <= 1 then return end local bAllConcave, bAllRight = true, true local nFct = #( vAdj or {}) for i = 1, nFct do for j = 1, nFct do -- se trovo un angolo convesso restituisco falso e esco subito if vAdj[i][j] and vAdj[i][j] > 0 then bAllConcave = false bAllRight = false break elseif vAdj[i][j] and vAdj[i][j] ~= 0 and vAdj[i][j] + 90 > 500 * GEO.EPS_ANG_SMALL then bAllRight = false 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 else return bAllConcave, bAllRight end end --------------------------------------------------------------------- -- restituisce true se almeno una delle dimensioni della feature è maggiore o uguale ad una delle dimensioni principali del pezzo (tolleranza 1 mm) local function IsAnyDimensionLongAsPart( Proc) local bResult = false local nBoxSolidId = EgtGetFirstNameInGroup( Proc.idPart or GDB_ID.NULL, 'Box') local b3Solid = EgtGetBBoxGlob( nBoxSolidId, GDB_BB.STANDARD) if Proc.b3Box:getDimX() > b3Solid:getDimX() - 1000 * GEO.EPS_SMALL or Proc.b3Box:getDimY() > b3Solid:getDimY() - 1000 * GEO.EPS_SMALL or Proc.b3Box:getDimZ() > b3Solid:getDimZ() - 1000 * GEO.EPS_SMALL then bResult = true end return bResult end ------------------------------------------------------------------------------------------------------------- -- restituisce vero se la feature con box b3Proc taglia l'intera sezione della barra, rappresentata dalle sue dimensioni W e H local function IsFeatureCuttingEntireSection( b3Proc, Part) return ( b3Proc:getDimY() > ( Part.b3RawBox:getDimY() - 500 * GEO.EPS_SMALL) and b3Proc:getDimZ() > ( Part.b3RawBox:getDimZ() - 500 * GEO.EPS_SMALL)) end ------------------------------------------------------------------------------------------------------------- -- restituisce vero se la feature con box b3Proc taglia l'intera lunghezza della barra, rappresentata dalle sue dimensioni W e L oppure H e L local function IsFeatureCuttingEntireLength( b3Proc, Part) return ( ( b3Proc:getDimY() > ( Part.b3RawBox:getDimY() - 500 * GEO.EPS_SMALL) and b3Proc:getDimX() > ( Part.b3RawBox:getDimX() - 500 * GEO.EPS_SMALL)) or ( b3Proc:getDimZ() > ( Part.b3RawBox:getDimZ() - 500 * GEO.EPS_SMALL) and b3Proc:getDimX() > ( Part.b3RawBox:getDimX() - 500 * GEO.EPS_SMALL))) end --------------------------------------------------------------------- -- restituisce una stringa con il nome esteso della topologia della feature -- *famiglia - numero di facce - passante* local function GetTopologyName( sFamily, nNumberOfFaces, bIsThrough) return sFamily .. '-' .. tostring( nNumberOfFaces) .. '-' .. EgtIf( bIsThrough, 'Through', 'Blind') end --------------------------------------------------------------------- -- recupera topologia feature function FeatureData.ClassifyTopology( Proc, Part) local FeatureTopology = {} if not Proc.AffectedFaces then Proc.AffectedFaces = BeamLib.GetAffectedFaces( Proc) end local bIsFeatureCuttingEntireSection = IsFeatureCuttingEntireSection( Proc.b3Box, Part) local bIsFeatureCuttingEntireLength = IsFeatureCuttingEntireLength( Proc.b3Box, Part) local bIsAnyDimensionLongAsPart = IsAnyDimensionLongAsPart( Proc) local vAdj = Proc.AdjacencyMatrix local bAllAnglesConcave, bAllRightAngles = AreAllAnglesConcaveOrRight( vAdj) local vTriangularFaces = FaceData.GetTriangularFaces( Proc) local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) local sFamily local bIsThrough if Proc.nFct == 1 and ( bIsFeatureCuttingEntireSection or bIsFeatureCuttingEntireLength) then sFamily = 'Cut' bIsThrough = true elseif Proc.nFct == 1 then sFamily = 'Bevel' bIsThrough = true elseif Proc.nFct == 2 and bAllAnglesConcave and #vTriangularFaces == 1 then sFamily = 'Bevel' bIsThrough = false elseif Proc.nFct == 2 and bAllAnglesConcave and ( Proc.AffectedFaces.Left or Proc.AffectedFaces.Right) and ( Proc.AffectedFaces.Front or Proc.AffectedFaces.Back) then sFamily = 'Rabbet' bIsThrough = true elseif Proc.nFct == 2 and bAllAnglesConcave then sFamily = 'VGroove' bIsThrough = true elseif Proc.nFct == 2 and not bAllAnglesConcave and bIsAnyDimensionLongAsPart then sFamily = 'DoubleBevel' bIsThrough = true elseif Proc.nFct == 3 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 1 and #vTriangularFaces == 2 then sFamily = 'Bevel' bIsThrough = false elseif Proc.nFct == 3 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 1 and bIsAnyDimensionLongAsPart then sFamily = 'Groove' bIsThrough = true elseif Proc.nFct == 3 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 3 then sFamily = 'Groove' bIsThrough = false elseif Proc.nFct == 4 and #vFacesByAdjNumber[2] == 4 and #vTriangularFaces == 2 then sFamily = 'DoubleBevel' bIsThrough = false elseif Proc.nFct == 4 and bAllAnglesConcave and #vFacesByAdjNumber[3] == 2 then sFamily = 'Groove' bIsThrough = false elseif Proc.nFct == 4 and bAllAnglesConcave and #vFacesByAdjNumber[2] == 4 and bIsAnyDimensionLongAsPart then sFamily = 'Tunnel' bIsThrough = true elseif Proc.nFct >= 4 and #vFacesByAdjNumber[1] == 2 and bIsAnyDimensionLongAsPart then sFamily = 'Strip' bIsThrough = true elseif Proc.nFct == 5 and bAllAnglesConcave and #vFacesByAdjNumber[4] == 1 then sFamily = 'Pocket' bIsThrough = false elseif Proc.nFct == 6 and #vFacesByAdjNumber[2] == 4 and #vFacesByAdjNumber[3] == 2 and #vTriangularFaces == 4 then sFamily = 'DoubleBevel' bIsThrough = false end if sFamily then FeatureTopology.sFamily = sFamily FeatureTopology.bIsThrough = bIsThrough FeatureTopology.bAllRightAngles = bAllRightAngles FeatureTopology.sName = GetTopologyName( sFamily, Proc.nFct, bIsThrough) FeatureTopology.AdjacencyMatrix = vAdj -- feature che necessita di essere catalogata, ma non si capisce come else FeatureTopology.sFamily = 'NOT_IMPLEMENTED' FeatureTopology.sName = FeatureTopology.sFamily end return FeatureTopology end ------------------------------------------------------------------------------------------------------------- -- Recupero dati foro e adattamento se speciale 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 if AuxId and EgtGetType( AuxId) == GDB_TY.CRV_ARC and BeamData.USER_HOLE_DIAM and BeamData.USER_HOLE_DIAM > 1 then EgtModifyArcRadius( AuxId, BeamData.USER_HOLE_DIAM / 2) end end local dDiam = EgtGetInfo( Proc.id, 'P12', 'd') or 0 local dLen = abs( EgtCurveThickness( Proc.id + AuxId)) or 0 local nFcs = EgtGetInfo( Proc.id, 'FCS', 'i') or 0 local nFce = EgtGetInfo( Proc.id, 'FCE', 'i') or 0 return dDiam, dLen, nFcs, nFce end ------------------------------------------------------------------------------------------------------------- -- funzione che restituisce indice di completamento in base alla percentuale di volume lavorato function FeatureData.GetFeatureCompletionIndex( dCompletionPercentage) -- indice di completamento local dCompletionIndex = 0 -- nullo if dCompletionPercentage < 5 then dCompletionIndex = 0 -- Low elseif dCompletionPercentage < 50 then dCompletionIndex = 1 -- Medium elseif dCompletionPercentage < 80 then dCompletionIndex = 2 -- High / Complete else dCompletionIndex = 5 end return dCompletionIndex end ------------------------------------------------------------------------------------------------------------- -- funzione che restituisce rating feature in base al numero di lavorazioni, tipo di utensili e indice di completamento -- TODO feature da sistemare function FeatureData.GetFeatureRating( sTypeTools, dCompletionIndex) local dRating = 5 local TypeTools = EgtSplitString( sTypeTools) -- se non è stato fatto nulla, esco subito if dCompletionIndex == 0 then return 0 end -- indice in base a utensile for i=1, #TypeTools do if TypeTools[i] == 'Blade' then dRating = min( dRating, 5) elseif TypeTools[i] == 'Mill' then dRating = min( dRating, 4) elseif TypeTools[i] == 'ChainSaw' then dRating = min( dRating, 3) else dRating = min( dRating, 1) end end dRating = dRating + dCompletionIndex return dRating end ------------------------------------------------------------------------------------------------------------- return FeatureData