Files
trimming/NewTrimming.lua
T
Daniele Bariletti 597c248cfc Trimming :
- gestita la comunicazione tra NewTrimming e Params.
- completata la gestione del flow NewTrimming
- compeltata la gestione del flow Params.
- aggiunta il file per il flow Edit.
2026-09-10 16:19:36 +02:00

105 lines
3.7 KiB
Lua

-- NewTrimming.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_CREATING_NEW_TRIMMING = 'Error in Creating New Trimming : '
-- parametri passati se NewTrimming viene chiamato da Params
local bParamsAlreadyUpdated, bNewSelection = ...
if not bParamsAlreadyUpdated and not bNewSelection then
bParamsAlreadyUpdated = false
bNewSelection = true
end
-- Recupero il Part corrente
local nCurrPartId = EgtGetCurrPart()
if nCurrPartId == nil then
EgtOutBox( ERROR_CREATING_NEW_TRIMMING .. 'Current Part not Found', 'Error', 'ERROR', 'OK')
return
end
local nCurrLayerId, nAuxLay
if not bParamsAlreadyUpdated then
-- apro la finestra Params
local fParams = loadfile( EgtGetSourceDir()..'Params.lua')
nCurrLayerId, nAuxLay = fParams( nCurrPartId, nil)
if not nCurrLayerId or not nAuxLay then return end
else
nCurrLayerId = EgtGetCurrLayer()
if not GlobVar.IsTrimmingLayer( nCurrLayerId) and GlobVar.IsTrimmingHoleLayer(nCurrLayerId) then
EgtOutBox( ERROR_CREATING_NEW_TRIMMING .. 'the current layer is not a trimming layer', 'Error', 'ERROR', 'OK')
return
end
-- se sono stati aggiornati i parametri cancello i bordi e la superficie già calcolati
local nObjId = EgtGetFirstInGroup( nCurrLayerId)
local vEraseId = {}
while nObjId do
if EgtGetType( nObjId) ~= GDB_TY.GROUP then table.insert( vEraseId, nObjId) end
nObjId = EgtGetNext( nObjId)
end
if bNewSelection then
-- se è una nuova selezione devo anche cancellare eventuali superfici già selezionate
nObjId = EgtGetFirstInGroup( nAuxLay)
while nObjId do
table.insert( vEraseId, nObjId)
nObjId = EgtGetNext( nObjId)
end
end
EgtErase(vEraseId)
end
local nRes
if bNewSelection then
-- apro la finestra di Selezione, dopo aver letto le modalità selezionate
local nSurfSelectionType = EgtGetInfo( nCurrLayerId, MCH_TRIMMING.KEY_SELECTION_LAST_SELECTION_TYPE, 'i')
if nSurfSelectionType == -1 or nSurfSelectionType > 2 then
EgtOutBox( ERROR_CREATING_NEW_TRIMMING .. 'Invalid Surf Selection Mode', 'Error', 'ERROR', 'OK')
return
end
local sTitle = ''
local bUseSubId
if nSurfSelectionType == SURF_SEL_LABEL['Single Surface'] then
sTitle = "Select Faces on the single surface"
bUseSubId = true
elseif nSurfSelectionType == SURF_SEL_LABEL['Composite Surface'] then
sTitle = "Select Surfaces"
bUseSubId = false
end
local bWithPreviewFunc = true
local sPreviewFunc = 'SelectSurfaces'..'('.. tostring(nCurrLayerId)
local SelectSurfaces = loadfile( EgtGetSourceDir()..'Select.lua')
_G.SelectSurfaces = SelectSurfaces
local sSelSurfs, tbSelPoints = EgtSelDialog( sTitle, bUseSubId, bWithPreviewFunc, sPreviewFunc)
-- deseleziono le superfici indicate
EgtDeselectAll()
if not sSelSurfs or sSelSurfs == '' then
if sSelSurfs == '' then
EgtOutBox( ERROR_CREATING_NEW_TRIMMING .. 'No surface selected', 'Error', 'ERROR', 'OK')
end
EgtErase( nCurrLayerId)
return
end
-- aggiungo le superfici indicate al layer ausiliario
nRes = SelectSurfaces( nCurrLayerId, sSelSurfs, tbSelPoints)
if not nRes then return end
end
-- creo gli edge dalle superfici
local CreateEdges = loadfile( EgtGetSourceDir()..'CalcBezierEdges.lua')
nRes = CreateEdges( nCurrPartId, nCurrLayerId)
if not nRes then return end
-- creo la superficie
local CreateBezier = loadfile( EgtGetSourceDir()..'CalcBezier.lua')
nRes = CreateBezier( nCurrPartId, nCurrLayerId)
if not nRes then return end
-- aggiorno la grafica
EgtDraw()