6eb7484901
- aggiunta la modalità ReduceTwistRMF.
136 lines
4.7 KiB
Lua
136 lines
4.7 KiB
Lua
-- ReduceTwistRMF.lua by Egalware s.r.l. 2026/04/21
|
|
|
|
require( 'EgtBase')
|
|
_ENV = EgtProtectGlobal()
|
|
EgtEnableDebug( true)
|
|
|
|
local nType = ...
|
|
tbTypes = {
|
|
STD = 0, -- standard
|
|
RMF = 1 -- con rotation minimizing frame
|
|
}
|
|
if not nType then
|
|
nType = tbTypes.STD
|
|
end
|
|
|
|
-- Carico le costanti di Trimming
|
|
EgtAddToPackagePath( EgtGetSourceDir() .. '?.lua')
|
|
local GlobVar = require( 'TrimmingLib')
|
|
-- Costante di Errore
|
|
local ERROR_REDUCE_TWIST = 'Error in Reduce Surf Twist : '
|
|
|
|
-- Recupero il Part e Layer di Trimming corrente ( o di riferimento)
|
|
local nCurrPartId = EgtGetCurrPart()
|
|
local nCurrLayerId = GlobVar.GetTrimmingLayerRefId( EgtGetCurrLayer())
|
|
if not GlobVar.IsTrimmingLayer( nCurrLayerId) then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Not a valid Trimming Layer', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
-- Recupero le Info
|
|
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_REDUCE_TWIST .. 'No Trimming Machining created', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
|
|
local vIdEdges = {}
|
|
local nId = EgtGetFirstInGroup( nCurrLayerId)
|
|
while nId do
|
|
-- verifico che sia una Curva e che sia di Bordo
|
|
if EgtGetName( nId) == EDGES_NAME then
|
|
-- Verifico che sia una Curva
|
|
local nType = EgtGetType( nId)
|
|
if nType ~= GDB_TY.CRV_LINE and nType ~= GDB_TY.CRV_ARC and nType ~= GDB_TY.CRV_BEZ and nType ~= GDB_TY.CRV_COMPO then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Invalid Border', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
table.insert( vIdEdges, nId)
|
|
end
|
|
nId = EgtGetNext( nId)
|
|
end
|
|
|
|
-- Se nel gruppo di Edit delle curve non ne ho esattamente 2 di bordo, errore
|
|
if #vIdEdges ~= 2 then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Not 2 Border Curves', 'Error', 'ERROR', 'OK')
|
|
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
|
|
EgtErase( nLayerEditSyncId)
|
|
return
|
|
end
|
|
|
|
-- verifico ci sia la superficie
|
|
local nSurf = GDB_ID.NULL
|
|
nId = EgtGetFirstInGroup(nCurrLayerId)
|
|
while nId do
|
|
if EgtGetType(nId) == GDB_TY.SRF_BEZ then nSurf = nId end
|
|
nId = EgtGetNext( nId)
|
|
end
|
|
|
|
if nSurf == GDB_ID.NULL then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'No surface to regolarize', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
|
|
-- Verifico che esista il Layer di Edit per le curve di Sincronizzazione
|
|
local nLayerEditSyncId = GlobVar.GetCurrentEditSyncCurvesLayer( nCurrPartId, nCurrLayerId)
|
|
if nLayerEditSyncId == nil or nLayerEditSyncId == GDB_ID.NULL then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Click Edit SyncLines before trying to reduce twist', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
|
|
-- verifico che siano selezionate due curve nel layer delle SynLines
|
|
local nSel = EgtGetFirstSelectedObj()
|
|
local vSyncSel = {}
|
|
while nSel do
|
|
-- verifico che sia una curva e che sia nel layer delle SyncLines
|
|
if EgtGetName( nSel) == SYNC_LINE_NAME then
|
|
table.insert(vSyncSel, nSel)
|
|
else
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Invalid Curve Selected', 'Error', 'ERROR', 'OK')
|
|
return
|
|
end
|
|
nSel = EgtGetNextSelectedObj()
|
|
end
|
|
|
|
-- verifico che siano selezionate solo due curve
|
|
if #vSyncSel ~= 2 then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Two SyncLines selected needed', 'Error', 'ERROR', 'OK')
|
|
EgtSetStatus( nCurrLayerId, GDB_ST.ON)
|
|
return
|
|
end
|
|
|
|
-- creo il layer e setto le info e colori
|
|
local nEditSurfLayer = GlobVar.CreateEditSurfLayer( nCurrPartId, nCurrLayerId)
|
|
local sInfoVal = EgtNumToString(vSyncSel[1])..","..EgtNumToString(vSyncSel[2])
|
|
EgtSetInfo(nCurrLayerId, KEY_SYNC_LINES_REGOLARIZATION, sInfoVal)
|
|
EgtSetColor(vSyncSel[1], EDIT_SURF_SYNC_COLOR)
|
|
EgtSetColor(vSyncSel[2], EDIT_SURF_SYNC_COLOR)
|
|
|
|
|
|
local nNewSurfId = EgtRegolarizeSurfaceLocally( nEditSurfLayer, nSurf,vSyncSel[1],vSyncSel[2],dLinTol, nType)
|
|
|
|
if nNewSurfId == nil or nNewSurfId == GDB_ID.NULL then
|
|
EgtOutBox( ERROR_REDUCE_TWIST .. 'Failed Reduction of twist', 'Error', 'ERROR', 'OK')
|
|
EgtErase(nEditSurfLayer)
|
|
return
|
|
end
|
|
EgtSetName(nNewSurfId,EDIT_SURF_NEWSURF_NAME)
|
|
|
|
---- richiedo i bordi alla nuova superficie e li metto nel layer temporaneo della modifica alla superficie
|
|
local nCrv1 = EgtSurfBezierGetCurveU( nNewSurfId, 0., nEditSurfLayer)
|
|
local nCrv2 = EgtSurfBezierGetCurveU( nNewSurfId, 1., nEditSurfLayer)
|
|
local vIdNewEdges = {nCrv1, nCrv2}
|
|
|
|
EgtSetColor( vIdNewEdges[1], EDIT_SURF_BORDER_COLOR)
|
|
EgtSetColor( vIdNewEdges[2], EDIT_SURF_BORDER_COLOR)
|
|
EgtSetName( vIdNewEdges[1], EDIT_SURF_NEWBORDER_NAME)
|
|
EgtSetName( vIdNewEdges[2], EDIT_SURF_NEWBORDER_NAME)
|
|
|
|
-- nascondo i bordi e la superficie originale
|
|
EgtSetStatus( nSurf, GDB_ST.OFF)
|
|
EgtSetStatus( vIdEdges[1], GDB_ST.OFF)
|
|
EgtSetStatus( vIdEdges[2], GDB_ST.OFF)
|
|
|
|
EgtDraw() |