Files
3dprinting/LuaLibs/RunViewManager.lua
T
SaraP 34f90a1271 3dPrinting :
- utilizzo delle regioni con numero diverso di passate per forare pareti
- correzioni varie.
2022-09-15 17:17:14 +02:00

196 lines
7.7 KiB
Lua

-- RunViewManager.lua by Egaltech s.r.l. 2022/07/03
-- Gestione visualizzazione per Stampa 3d
-- Tabella per definizione modulo
local RunViewManager = {}
-- Intestazioni
require( 'EgtBase')
EgtOutLog( ' RunViewManager started', 1)
-- Costanti generali
local AMD = require( 'AddManData')
---------------------------------------------------------------------
local function CalcShow( nShellView, nType)
if nShellView == SHELL_VIEW_TYPE.OUTER then
return ( nType == TYPE.OUTER_SHELL or nType == TYPE.EXTRA_OUTER_SHELL)
elseif nShellView == SHELL_VIEW_TYPE.INNER then
return ( nType == TYPE.INNER_SHELL)
elseif nShellView == SHELL_VIEW_TYPE.INFILL then
return ( nType == TYPE.INFILL)
else --nShellView == SHELL_VIEW_TYPE.ALL
return true
end
end
---------------------------------------------------------------------
local function CalcType( nEntId, nOldType)
local nType = EgtGetInfo( nEntId, KEY_TYPE, 'i')
if not nType or nType == TYPE.LINK or nType == TYPE.COASTING or nType == TYPE.WIPE then
nType = nOldType
end
if nType == TYPE.RIB or nType == TYPE.AUX_SOLID then
nType = TYPE.INFILL
end
if nType == TYPE.EXTRA_SHELL then
nType = TYPE.INNER_SHELL
end
return nType
end
---------------------------------------------------------------------
function RunViewManager.Exec()
local nVisibilityMode = LAYER_VIEW_TYPE.ALL -- 1 = All, 2 = Till Selected, 3 = Only Selected, 4 = From Selected
local nShellType = SHELL_VIEW_TYPE.ALL -- 1 = All, 2 = Outer, 3 = Inner, 4 = infill
local nOldSelLayerId = GDB_ID.NULL
-- leggo ultimi valori
local nViewId = EgtGetFirstNameInGroup( GDB_ID.ROOT, VIEWPARAMS)
if nViewId then
nVisibilityMode = EgtGetInfo( nViewId, KEY_LAYER_VIEW, 'i')
nShellType = EgtGetInfo( nViewId, KEY_SHELL_VIEW, 'i')
nOldSelLayerId = EgtGetInfo( nViewId, KEY_SEL_LAYER, 'i') or GDB_ID.NULL
end
local sLayerViewCombo = ''
if nVisibilityMode == LAYER_VIEW_TYPE.TILL_SEL then
sLayerViewCombo = 'CB:All,*Till Selected,Only Selected,From Selected'
elseif nVisibilityMode == LAYER_VIEW_TYPE.ONLY_SEL then
sLayerViewCombo = 'CB:All,Till Selected,*Only Selected,From Selected'
elseif nVisibilityMode == LAYER_VIEW_TYPE.FROM_SEL then
sLayerViewCombo = 'CB:All,Till Selected,Only Selected,*From Selected'
else
sLayerViewCombo = 'CB:*All,Till Selected,Only Selected,From Selected'
end
local sShellViewCombo = ''
if nShellType == SHELL_VIEW_TYPE.OUTER then
sShellViewCombo = 'CB:All,*Outer,Inner,Infill'
elseif nShellType == SHELL_VIEW_TYPE.INNER then
sShellViewCombo = 'CB:All,Outer,*Inner,Infill'
elseif nShellType == SHELL_VIEW_TYPE.INFILL then
sShellViewCombo = 'CB:All,Outer,Inner,*Infill'
else
sShellViewCombo = 'CB:*All,Outer,Inner,Infill'
end
ViewValues = EgtDialogBox( 'Slicing visibility manager', { 'Visibility Mode', sLayerViewCombo},
{ 'Shell type', sShellViewCombo})
if not ViewValues or #ViewValues < 2 then return end
if ViewValues[1] == 'All' then
nVisibilityMode = LAYER_VIEW_TYPE.ALL
elseif ViewValues[1] == 'Till Selected' then
nVisibilityMode = LAYER_VIEW_TYPE.TILL_SEL
elseif ViewValues[1] == 'Only Selected' then
nVisibilityMode = LAYER_VIEW_TYPE.ONLY_SEL
elseif ViewValues[1] == 'From Selected' then
nVisibilityMode = LAYER_VIEW_TYPE.FROM_SEL
end
if ViewValues[2] == 'All' then
nShellType = SHELL_VIEW_TYPE.ALL
elseif ViewValues[2] == 'Outer' then
nShellType = SHELL_VIEW_TYPE.OUTER
elseif ViewValues[2] == 'Inner' then
nShellType = SHELL_VIEW_TYPE.INNER
elseif ViewValues[2] == 'Infill' then
nShellType = SHELL_VIEW_TYPE.INFILL
end
-- Recupero ultimo layer selezionato
-- verifico sia un pezzo valido
local sSelLayerName = ''
local bFound = false
local nSelLayerId = EgtGetLastSelectedObj()
while nSelLayerId do
local sSelLayerName = EgtGetName( nSelLayerId)
if sSelLayerName and ( sSelLayerName:sub(1, 5) == SLICE_LAYER or sSelLayerName:sub(3, 7) == SLICE_LAYER) then
bFound = true
break
end
nSelLayerId = EgtGetParent( nSelLayerId)
end
if not bFound then
if nOldSelLayerId and nOldSelLayerId ~= GDB_ID.NULL then
nSelLayerId = nOldSelLayerId
else
if nVisibilityMode ~= LAYER_VIEW_TYPE.ALL then
EgtOutBox( 'No selected element!', 'Warning', 'WARNING')
return
else
nSelLayerId = GDB_ID.NULL
sSelLayerName = ''
end
end
end
-- ciclo sui pezzi
local nPartIndex = 1
local nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex)
while nPartId do
-- ciclo sui layer per dis/attivare il resto
local nLayerIndex = 1
local nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) or EgtGetFirstNameInGroup( nPartId, "__" .. SLICE_LAYER .. nLayerIndex)
while nLayerId do
if nVisibilityMode == LAYER_VIEW_TYPE.ALL then
EgtSetStatus( nLayerId, GDB_ST.ON)
elseif nVisibilityMode == LAYER_VIEW_TYPE.TILL_SEL then
EgtSetStatus( nLayerId, EgtIf( nLayerId <= nSelLayerId, GDB_ST.ON, GDB_ST.OFF))
elseif nVisibilityMode == LAYER_VIEW_TYPE.ONLY_SEL then
EgtSetStatus( nLayerId, EgtIf( nLayerId == nSelLayerId, GDB_ST.ON, GDB_ST.OFF))
elseif nVisibilityMode == LAYER_VIEW_TYPE.FROM_SEL then
EgtSetStatus( nLayerId, EgtIf( nLayerId >= nSelLayerId, GDB_ST.ON, GDB_ST.OFF))
end
local nCrvId = EgtGetFirstGroupInGroup( nLayerId)
while nCrvId do
----
local nOldType = TYPE.OUTER_SHELL
local nPathId = EgtGetFirstNameInGroup( nCrvId, PATH_GRP)
local nShellId = EgtGetFirstInGroup( nPathId)
while nShellId do
local nType = CalcType( nShellId, nOldType)
nOldType = nType
EgtSetStatus( nShellId, EgtIf( CalcShow( nShellType, nType), GDB_ST.ON, GDB_ST.OFF))
nShellId = EgtGetNext( nShellId)
end
----
nOldType = TYPE.OUTER_SHELL
local nSolidId = EgtGetFirstNameInGroup( nCrvId, SOLID_GRP)
local nSurfId = EgtGetFirstInGroup( nSolidId)
while nSurfId do
local nType = CalcType( nSurfId, nOldType)
nOldType = nType
EgtSetStatus( nSurfId, EgtIf( CalcShow( nShellType, nType), GDB_ST.ON, GDB_ST.OFF))
nSurfId = EgtGetNext( nSurfId)
end
----
nOldType = TYPE.OUTER_SHELL
local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP)
nShellId = EgtGetFirstInGroup( nToolPathId)
while nShellId do
local nType = CalcType( nShellId, nOldType)
nOldType = nType
EgtSetStatus( nShellId, EgtIf( CalcShow( nShellType, nType), GDB_ST.ON, GDB_ST.OFF))
nShellId = EgtGetNext( nShellId)
end
nCrvId = EgtGetNext( nCrvId)
end
nLayerIndex = nLayerIndex + 1
nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) or EgtGetFirstNameInGroup( nPartId, "__" .. SLICE_LAYER .. nLayerIndex)
end
nPartIndex = nPartIndex + 1
nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex)
end
-- riporto impostazioni in gruppo apposito
EgtSetInfo( nViewId, KEY_LAYER_VIEW, nVisibilityMode)
EgtSetInfo( nViewId, KEY_SHELL_VIEW, nShellType)
EgtSetInfo( nViewId, KEY_SEL_LAYER, nSelLayerId)
EgtDraw()
end
---------------------------------------------------------------------
return RunViewManager