-- SelectHoles.lua by Egalware s.r.l. 2026/01/05 require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Carico le costanti di Trimming EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua') local GlobVar = require( 'TrimmingLib') -- Costante di Errore local ERROR_SELECTION = 'Error in Surf Selection : ' -- Recupero il Part e Layer di Trimming corrente local nCurrPartId = EgtGetCurrPart() local nCurrLayerId = EgtGetCurrLayer() if not GlobVar.IsTrimmingHoleLayer( nCurrLayerId) then EgtOutBox( ERROR_SELECTION .. 'Not a valid Hole Trimming Layer', 'Error', 'ERROR', 'OK') return end -- Recupero l'oggetto selezionato ( verifico che sia Superficie TriMesh o Superficie Bezier) local nSelObjId = EgtGetLastSelectedObj() if not nSelObjId then EgtOutBox( ERROR_SELECTION .. 'No Object Selected', 'Error', 'ERROR', 'OK') return end local nType = EgtGetType( nSelObjId) if nType ~= GDB_TY.SRF_BEZ and nType ~= GDB_TY.SRF_MESH then EgtOutBox( ERROR_SELECTION .. 'Invalid Surface Selected. The Surface must be a TriMesh or a Bezier', 'Error', 'ERROR', 'OK') return end -- Recupero le tolleranze impostate alla creazione del Layer di Trimming corrente local dLinTol = EgtGetInfo( nCurrLayerId, KEY_LIN_TOL, 'd') local dAngTol = EgtGetInfo( nCurrLayerId, KEY_ANG_TOL, 'd') local dAngFaceTol = EgtGetInfo( nCurrLayerId, KEY_SURF_ANG_TOL, 'd') local bOk = ( dLinTol ~= nil and dAngTol ~= nil and dAngFaceTol ~= nil) if not bOk then EgtOutBox( ERROR_SELECTION .. 'Not a valid Trimming Layer', 'Error', 'ERROR', 'OK') return end -- Chiedo l'operazione da svolgere su tale superficie e ricavo i parametri inseriti local dSize = STRIP_SIZE local dStoredSize = EgtGetInfo( nCurrLayerId, KEY_SURF_BORDER_SIZE, 'd') if dStoredSize ~= nil then dSize = dStoredSize end local dSizeTol = STRIP_SIZE_TOL local dStoredSizeTol = EgtGetInfo( nCurrLayerId, KEY_SURF_BORDER_SIZE_TOL, 'd') if dStoredSizeTol ~= nil then dSizeTol = dStoredSizeTol end local nLastSelType = EgtGetInfo( nCurrLayerId, KEY_SELECTION_LAST_SELECTION_TYPE, 'i') local sLabels = { 'Insert Surface', 'Face Search', 'Surf Search'} local sTypeDBSel if nLastSelType ~= nil then local sParts = {} for i, sLabel in ipairs( sLabels) do if i == nLastSelType then sParts[i] = '*' .. sLabel else sParts[i] = sLabel end end sTypeDBSel = 'CB:' .. table.concat( sParts, ',') else sTypeDBSel = 'CB:' .. table.concat( sLabels, ',') end local dLinTolForEdges = dLinTol local dAngTolForEdges = dAngTol local dThickForEdges = EDGE_THICK local dEdgeLinTol = EgtGetInfo( nCurrLayerId, KEY_LIN_TOL_EDGES, 'd') local dEdgeAngTol = EgtGetInfo( nCurrLayerId, KEY_ANG_TOL_EDGES, 'd') local dEdgeThick = EgtGetInfo( nCurrLayerId, KEY_THICK_EDGES, 'd') if dEdgeLinTol then dLinTolForEdges = dEdgeLinTol end if dEdgeAngTol then dAngTolForEdges = dEdgeAngTol end if dEdgeThick then dThickForEdges = dEdgeThick end local vsVal = EgtDialogBox( 'Seletion', { 'Type', sTypeDBSel}, { 'Strip Size', tostring( dSize)}, { 'Strip Size Tolerance', tostring( dSizeTol)}, { 'Approx Linear Tolerance', tostring( dLinTolForEdges)}, { 'Approx Angular Tolerance', tostring( dAngTolForEdges)}, { 'Thickness', tostring( dThickForEdges)}) if not vsVal or #vsVal ~= 6 then return end dSize = tonumber( vsVal[2]) dSizeTol = tonumber( vsVal[3]) EgtSetInfo( nCurrLayerId, KEY_SURF_BORDER_SIZE, dSize) EgtSetInfo( nCurrLayerId, KEY_SURF_BORDER_SIZE_TOL, dSizeTol) for i, sLabel in ipairs( sLabels) do if sLabel == vsVal[1] then EgtSetInfo( nCurrLayerId, KEY_SELECTION_LAST_SELECTION_TYPE, i) break end end dEdgeLinTol = tonumber( vsVal[4]) dEdgeAngTol = tonumber( vsVal[5]) dEdgeThick = tonumber( vsVal[6]) EgtSetInfo( nCurrLayerId, KEY_LIN_TOL_EDGES, dEdgeLinTol) EgtSetInfo( nCurrLayerId, KEY_ANG_TOL_EDGES, dEdgeAngTol) EgtSetInfo( nCurrLayerId, KEY_THICK_EDGES, dEdgeThick) -- Rendo invisibili gli altri Layer di Trimmatura e tutti i Layer Temporanei -- NB. Il focus va sul Layer corrente EgtSetStatus( nCurrLayerId, GDB_ST.ON) nId = EgtGetFirstInGroup( nCurrPartId) while nId do if nId ~= nCurrLayerId and ( GlobVar.IsTrimmingLayer( nId) or GlobVar.IsEditSyncCurvesLayer( nId)) then EgtSetStatus( nId, GDB_ST.OFF) end nId = EgtGetNext( nId) end -- Recupero gli Id delle Superfici rappresentanti il Foro o l'Asola corrente local vSurfIds = {} --------------------------------- Inserimento della Superficie --------------------------------- -- [Nessuna Tolleranza] if vsVal[1] == 'Insert Surface' then -- Recupero tutti gli Oggetti selezionati che sono Superfici TriMesh o di Bezier local vObjId = {} local nCurrObjId = EgtGetFirstSelectedObj() while nCurrObjId do local nObjType = EgtGetType( nCurrObjId) if nObjType == GDB_TY.SRF_MESH or nObjType == GDB_TY.SRF_BEZ then table.insert( vSurfIds, nCurrObjId) end nCurrObjId = EgtGetNextSelectedObj() end --------------------------------- Ricerca delle facce adiancenti -------------------------------- -- [Tolleranza angolare di superficie] elseif vsVal[1] == 'Face Search' then local bOk = false -- Se la superficie è una Bezier, allora è lei if nType == GDB_TY.SRF_BEZ then table.insert( vSurfIds, nSelObjId) -- Se invece è una Trimesh, recupero il primo triangolo selezionato else local nId, nTria, ptInt = EgtGetLastSelInfo() if not nId or not nTria then EgtOutBox( ERROR_SELECTION .. 'Face not found', 'Error', 'ERROR', 'OK') return end -- *** Debug ( nel caso di errori, so che punto è stato selezionato ) *** local sStr = 'Pt = ' .. tostring( ptInt) .. ' - nTria = ' .. tostring( nTria) EgtOutLog( sStr) -- Recupero la superficie mediante adiancenza dei triangoli local nInsertSurfId = EgtTrimmingGetSurfTmFaceAdj( nCurrLayerId, nId, nTria, ptInt, dAngFaceTol, dSize, dSizeTol) if not nInsertSurfId or nInsertSurfId == GDB_ID.NULL then EgtOutBox( ERROR_SELECTION .. 'Face Search failed', 'Error', 'ERROR', 'OK') return end table.insert( vSurfIds, nInsertSurfId) end --------------------------------- Ricerca delle superfici Adiacenti --------------------------------- -- [Tolleranza lineare, Tolleranza angolare e Tolleranza angolare applicata alla Superficie] elseif vsVal[1] == 'Surf Search' then -- Recupero il Gruppo della superficie corrente local nSurfGroup = EgtGetParent( nSelObjId) if not nSurfGroup or nSurfGroup == GDB_ID.NULL then EgtOutBox( ERROR_SELECTION .. 'Surface not in a valid Group', 'Error', 'ERROR', 'OK') return end -- Recupero tutti Gli Id delle Superfici Attive del Gruppo della Superficie Corrente local vAllSurfIds = {} local nOtherId = EgtGetFirstInGroup( nSurfGroup) while nOtherId do local nStatus = EgtGetStatus( nOtherId) if nStatus == GDB_ST.ON and nOtherId ~= nId then table.insert( vAllSurfIds, nOtherId) end nOtherId = EgtGetNext( nOtherId) end -- Recupero le superfici da Selezionare local bOk, vSelSurfId = EgtTrimmingGetAdjSurfs( nSelObjId, vAllSurfIds, dLinTol, dAngTol, dAngFaceTol) if not bOk then EgtOutBox( ERROR_SELECTION .. 'Surface Search failed', 'Error', 'ERROR', 'OK') return end table.insert( vSurfIds, nSelObjId) for i = 1, #vSelSurfId do table.insert( vSurfIds, vSelSurfId[i]) end end -- Se non ho ottenuto Id di Superfici, errore if #vSurfIds == 0 then EgtOutBox( ERROR_SELECTION .. 'Not a valid Surf Detected', 'Error', 'ERROR', 'OK') return end -- Recupero tutte Le Superfici Visibili nello Stesso Layer dell'Oggetto Selezionato local vAllOtherSurfIds = GlobVar.GetAllOtherVisibileSurfsInSameLayer( nSelObjId) if not vAllOtherSurfIds then EgtOutBox( ERROR_SELECTION .. 'Surface not in a valid Group', 'Error', 'ERROR', 'OK') return end -- Da queste superfici Recupero i Fori e le Asole local nFirstId, nCount bOk, nFirstId, nCount = EgtTrimmingGetHoleBorder( nCurrLayerId, vSurfIds, vAllOtherSurfIds, dLinTol, dAngTol, dEdgeLinTol, dEdgeAngTol, dEdgeThick) if bOk and ( nFirstId == GDB_ID.NULL or nCount == 0) then EgtOutBox( 'No Hole found under Tolerances', 'Edge Warning', 'WARNING', 'OK') else -- Assegno Colore e Nome alla curva ricavata bOk = bOk and nFirstId ~= nil and nFirstId ~= GDB_ID.NULL and nCount > 0 if bOk then for i = 0, nCount - 1 do EgtSetName( i + nFirstId, EDGE_HOLE_NAME) EgtSetColor( i + nFirstId, EDGES_COLOR) end end end -- Elimino tutte le entità in eccesso nel Layer corrente local nId = EgtGetFirstInGroup( nCurrLayerId) local vIdToErase = {} while nId do if EgtGetName( nId) ~= EDGE_HOLE_NAME then table.insert( vIdToErase, nId) end nId = EgtGetNext( nId) end EgtErase( vIdToErase) -- Deseleziono la superficie corrente e aggiorno la grafica EgtDeselectAll() -- Aggiorno la Grafica EgtDraw()