-- WinLib.lua by Egalware s.r.l. 2024/06/14 -- Libreria globale per Serramenti -- Tabella per definizione modulo local WinLib = {} -- Include require( 'EgtBase') local WinData = require( 'WinData') EgtOutLog( ' WinLib started', 1) ------------------------------------------------------------------------------------------------------------- -- restituisce le facce della parte interessate dalla feature Proc function WinLib.GetAffectedFaces( Proc, Part) local vtFacesAffected = { bTop = false, bBottom = false, bFront = false, bBack = false, bLeft = false, bRight = false} if Proc.b3Box and not Proc.b3Box:isEmpty() then -- caso speciale foro if Proc.sType == 'Hole' and Proc.sReferenceSide then if Proc.sReferenceSide == Part.SideNames.sLeft then vtFacesAffected.bLeft = true elseif Proc.sReferenceSide == Part.SideNames.sRight then vtFacesAffected.bRight = true elseif Proc.sReferenceSide == Part.SideNames.sFront then vtFacesAffected.bFront = true elseif Proc.sReferenceSide == Part.SideNames.sBack then vtFacesAffected.bBack = true end -- caso speciale profili per pezzo con cambio-profilo elseif Proc.sType == 'Profiling' and Proc.sProfileInfo == 'Mixed' then if Proc.sReferenceSide == Part.SideNames.sLeft then vtFacesAffected.bLeft = true elseif Proc.sReferenceSide == Part.SideNames.sRight then vtFacesAffected.bRight = true elseif Proc.sReferenceSide == Part.SideNames.sFront then vtFacesAffected.bFront = true elseif Proc.sReferenceSide == Part.SideNames.sBack then vtFacesAffected.bBack = true end -- caso speciale profili elseif Proc.sType == 'Profiling' then if not Part.SideNames then Part.SideNames = {} end -- quando si settano i lati interessati, mi salvo anche il nome. -- se c'è una rotazione di 180°, potrebbe essere che il lato LEFT del pezzo corrisponda al lato RIGHT della lavorazione. Stesso per IN/OUT if Proc.b3Box:getMax():getX() < Part.b3Part:getCenter():getX() then vtFacesAffected.bLeft = true Part.SideNames.sLeft = Proc.sEntityName elseif Proc.b3Box:getMin():getX() > Part.b3Part:getCenter():getX() then vtFacesAffected.bRight = true Part.SideNames.sRight = Proc.sEntityName elseif Proc.b3Box:getMax():getY() < Part.b3Part:getCenter():getY() then vtFacesAffected.bFront = true Part.SideNames.sFront = Proc.sEntityName elseif Proc.b3Box:getMin():getY() > Part.b3Part:getCenter():getY() then vtFacesAffected.bBack = true Part.SideNames.sBack = Proc.sEntityName end -- caso standard else if Proc.b3Box:getMax():getZ() > Part.b3Part:getMax():getZ() - 500 * GEO.EPS_SMALL then vtFacesAffected.bTop = true end if Proc.b3Box:getMin():getZ() < Part.b3Part:getMin():getZ() + 500 * GEO.EPS_SMALL then vtFacesAffected.bBottom = true end if Proc.b3Box:getMin():getY() < Part.b3Part:getMin():getY() + 500 * GEO.EPS_SMALL then vtFacesAffected.bFront = true end if Proc.b3Box:getMax():getY() > Part.b3Part:getMax():getY() - 500 * GEO.EPS_SMALL then vtFacesAffected.bBack = true end if Proc.b3Box:getMin():getX() < Part.b3Part:getMin():getX() + 500 * GEO.EPS_SMALL then vtFacesAffected.bLeft = true end if Proc.b3Box:getMax():getX() > Part.b3Part:getMax():getX() - 500 * GEO.EPS_SMALL then vtFacesAffected.bRight = true end end end return vtFacesAffected end ------------------------------------------------------------------------------------------------------------- function WinLib.SwapElements( Table, Pos1, Pos2) Table[Pos1], Table[Pos2] = Table[Pos2], Table[Pos1] return Table end ------------------------------------------------------------------------------------------------------------- function WinLib.ChangeElementPositionInTable( Table, nCurrentPosition, nTargetPosition) -- se indici uguali esco subito if nTargetPosition == nCurrentPosition then return Table end local Item = Table[nCurrentPosition] if nTargetPosition > nCurrentPosition then nTargetPosition = nTargetPosition - 1 end table.remove( Table, nCurrentPosition) table.insert( Table, nTargetPosition, Item) return Table end ------------------------------------------------------------------------------------------------------------- function WinLib.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 -- 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 ------------------------------------------------------------------------------------------------------------- function WinLib.GetPathMinRadius( IdCurve) local dSmallRadius = 9999 local InitIdEntity, LastIdEntity = EgtCurveDomain(IdCurve) for i = InitIdEntity, LastIdEntity do local dRadius = EgtCurveCompoRadius( IdCurve, i) -- se è un arco ed è più piccolo del minimo, lo salvo if dRadius and dRadius > 0 and dRadius < dSmallRadius then dSmallRadius = dRadius end end return dSmallRadius end ------------------------------------------------------------------------------------------------------------- --- copia una tabella lua in modo ricorsivo, ossia mantiene indipendenti anche tutte le sottotabelle --- ATTENZIONE: in caso di modifiche vanno gestiti anche i tipi custom; sarebbe meglio metterla nel LuaLibs function WinLib.TableCopyDeep( OriginalTable) -- controllo se oggetto passato è valido, altrimenti errore. Non deve mai succedere if not OriginalTable then error( "TableCopyDeep : can't copy nil object") end local CopiedTable = {} for key, value in pairs( OriginalTable) do if type( value) == "table" then if isBBox3d( value) then CopiedTable[ key] = BBox3d( value) elseif isColor3d( value) then CopiedTable[ key] = Color3d( value) elseif isFrame3d( value) then CopiedTable[ key] = Frame3d( value) elseif isPoint3d( value) then CopiedTable[ key] = Point3d( value) elseif isQuaternion( value) then CopiedTable[ key] = Quaternion( value) elseif isVector3d( value) then CopiedTable[ key] = Vector3d( value) else CopiedTable[ key] = BeamLib.TableCopyDeep( value) end else CopiedTable[ key] = value end end return CopiedTable end ------------------------------------------------------------------------------------------------------------- return WinLib