Files
egwwindowlua/Profiles/WinLib/WinManageProject.lua
SaraP 5dd44069bc - correzione telaio triangolare
- gestione delle giunzioni come vettore
- modificato il calcolo delle sottaree generate da uno split
- aggiunta info lato di riferimento per lavorazione dowels
- correzioni varie per telai non rettangolari.
2024-07-05 12:15:11 +02:00

265 lines
11 KiB
Lua

--
-- EEEEEEEEEE GGGGGG TTTTTTTTTTTTTT
-- EEEEEEEEEE GGGGGGGGGG TTTTTTTTTTTTTT
-- EEEE GGGG GGGG TTTT
-- EEEE GGGG TTTT
-- EEEEEEE GGGG GGGGGGG TTTT
-- EEEEEEE GGGG GGGGGGG TTTT
-- EEEE GGGG GGGG TTTT
-- EEEE GGGG GGGG TTTT
-- EEEEEEEEEE GGGGGGGGGG TTTT
-- EEEEEEEEEE GGGGGG TTTT
--
-- by Egalware s.r.l.
-- Window project software by Egalware s.r.l. 2023/05/02
-- Tabella per definizione modulo
local WinManageProject = {}
-- Include
require( 'EgtBase')
_G.package.loaded.WinConst = nil
require( 'WinConst')
_G.package.loaded.WinJWDConst = nil
require( 'WinJWDConst')
_G.package.loaded.WinCreate = nil
local WinCreate = require( 'WinCreate')
_G.package.loaded.JSON = nil
local JSON = require( 'JSON')
-- funzioni
local function ConvertCurveToTableEntity( nCurveId)
-- verifico il tipo di entita'
local nBaseOutlineType = EgtGetType( nCurveId)
if nBaseOutlineType == GDB_TY.CRV_LINE then
local ptStart = EgtSP( nCurveId)
local ptEnd = EgtEP( nCurveId)
return { [JWD_CRV_TYPE] = nBaseOutlineType, [JWD_POINT_START] = ptStart, [JWD_POINT_END] = ptEnd}
elseif nBaseOutlineType == GDB_TY.CRV_ARC then
local ptStart = EgtSP( nCurveId)
local ptEnd = EgtEP( nCurveId)
local ptMid = EgtMP( nCurveId)
return { [JWD_CRV_TYPE] = nBaseOutlineType, [JWD_POINT_START] = ptStart, [JWD_POINT_END] = ptEnd, [JWD_POINT_MID] = ptMid}
elseif nBaseOutlineType == GDB_TY.CRV_COMPO then
-- local ptStart = EgtSP( nCurveId)
-- local ptEnd = EgtEP( nCurveId)
-- local ptMid = EgtMP( nCurveId)
-- return { Type = nBaseOutlineType, ptStart = ptStart, ptEnd = ptEnd, ptMid = ptMid}
end
end
-- funzione ricorsiva che legge le aree e ne riporta i dati in tabella
local function ConvertAreaToTable( nAreaId)
local AreaTable = {}
local nAreaType = EgtGetInfo( nAreaId, WIN_AREATYPE, 'i')
AreaTable[JWD_AREA_TYPE] = nAreaType
if nAreaType == WIN_AREATYPES.NULL then
-- non faccio nulla
elseif nAreaType == WIN_AREATYPES.FRAME then
-- recupero outline del frame
local nBaseOutlineLayerId = EgtGetFirstNameInGroup( nAreaId, WIN_AREAOUTLINE, 'i')
local JointTable = {}
-- recupero tipo giunzioni
local nJointBL = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_BL, 'i')
local nJointBR = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_BR, 'i')
local nJointTL = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_TL, 'i')
local nJointTR = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_TR, 'i')
JointTable[JWD_JOINT_BL] = nJointBL
JointTable[JWD_JOINT_BR] = nJointBR
JointTable[JWD_JOINT_TL] = nJointTL
JointTable[JWD_JOINT_TR] = nJointTR
local OutlineTable = {}
-- recupero contorno
local nBaseOutlineId = EgtGetFirstInGroup( nBaseOutlineLayerId)
local nBaseOutlineIndex = 1
while nBaseOutlineId do
local Entity = ConvertCurveToTableEntity( nBaseOutlineId)
table.insert( OutlineTable, Entity)
nBaseOutlineIndex = nBaseOutlineIndex + 1
nBaseOutlineId = EgtGetNext( nBaseOutlineId)
end
AreaTable[JWD_JOINT] = JointTable
AreaTable[JWD_OUTLINE] = OutlineTable
-- verifico se c'e' BottomRail
local nBottomRailId = EgtGetInfo( nBaseOutlineLayerId, WIN_BOTTOMRAIL, 'i')
if nBottomRailId then
AreaTable[JWD_BOTTOM_RAIL] = 1
end
elseif nAreaType == WIN_AREATYPES.SASH then
local nBaseOutlineLayerId = EgtGetFirstNameInGroup( nAreaId, WIN_AREAOUTLINE)
local JointTable = {}
-- recupero tipo giunzioni
local nJointBL = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_BL, 'i')
local nJointBR = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_BR, 'i')
local nJointTL = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_TL, 'i')
local nJointTR = EgtGetInfo( nBaseOutlineLayerId, WIN_JOINT_TR, 'i')
JointTable[JWD_JOINT_BL] = nJointBL
JointTable[JWD_JOINT_BR] = nJointBR
JointTable[JWD_JOINT_TL] = nJointTL
JointTable[JWD_JOINT_TR] = nJointTR
AreaTable[JWD_JOINT] = JointTable
local nSashType = EgtGetInfo( nAreaId, WIN_SASHTYPE, 'i')
if nSashType then
AreaTable[JWD_SASH_TYPE] = nSashType
end
elseif nAreaType == WIN_AREATYPES.FILL then
local nFillType = EgtGetInfo( nAreaId, WIN_FILLTYPE, 'i')
AreaTable[JWD_FILL_TYPE] = nFillType
elseif nAreaType == WIN_AREATYPES.SPLIT then
end
-- verifico se c'e' Split
local nSplitLayerId = EgtGetFirstNameInGroup( nAreaId, WIN_BASESPLIT)
if nSplitLayerId then
local SplitTable = {}
local nSplitId = EgtGetFirstInGroup( nSplitLayerId)
local Entity = ConvertCurveToTableEntity( nSplitId)
table.insert( SplitTable, Entity)
AreaTable[JWD_SPLIT] = SplitTable
end
-- ciclo sulle aree contenute
local nChildAreaId = EgtGetFirstNameInGroup( nAreaId, WIN_AREAASTERISK)
local nChildIndex = 1
while nChildAreaId do
local ChildTable = ConvertAreaToTable( nChildAreaId)
local AreaName = JWD_AREA .. nChildIndex
AreaTable[AreaName] = ChildTable
nChildIndex = nChildIndex + 1
nChildAreaId = EgtGetNextName( nChildAreaId, WIN_AREAASTERISK)
end
return AreaTable
end
-- funzione che converte una curva descritta in tabella in una geometria
local function ConvertCurveTableToEntity( nDrawFrameLayerId, CurrCurve)
if CurrCurve[JWD_CRV_TYPE] == GDB_TY.CRV_LINE then
EgtLine( nDrawFrameLayerId, Point3d(CurrCurve[JWD_POINT_START]), Point3d(CurrCurve[JWD_POINT_END]))
elseif CurrCurve[JWD_CRV_TYPE] == GDB_TY.CRV_ARC then
EgtArc3P( nDrawFrameLayerId, Point3d(CurrCurve[JWD_POINT_START]), Point3d(CurrCurve[JWD_POINT_MID]), Point3d(CurrCurve[JWD_POINT_END]))
elseif CurrCurve[JWD_CRV_TYPE] == GDB_TY.CRV_COMPO then
-- local ptStart = EgtSP( nBaseOutlineId)
-- local ptEnd = EgtEP( nBaseOutlineId)
-- local ptMid = EgtMP( nBaseOutlineId)
-- local Entity = { Type = nBaseOutlineType, ptStart = ptStart, ptEnd = ptEnd, ptMid = ptMid}
end
end
-- funzione ricorsiva che legge le aree in tabella e crea le geometrie
local function ConvertTableToGeometry( AreaTable, nAreaId)
if AreaTable[JWD_AREA_TYPE] == WIN_AREATYPES.NULL then
elseif AreaTable[JWD_AREA_TYPE] == WIN_AREATYPES.FRAME then
-- creo gruppo e layer per contorno
local nDrawFramePartId = EgtGroup( GDB_ID.ROOT)
EgtSetName( nDrawFramePartId, 'DrawFrame')
local nDrawFrameLayerId = EgtGroup( nDrawFramePartId)
for nIndex = 1, #AreaTable[JWD_OUTLINE] do
local CurrCurve = AreaTable[JWD_OUTLINE][nIndex]
ConvertCurveTableToEntity( nDrawFrameLayerId, CurrCurve)
end
local nFrameBottomId = EgtGetFirstInGroup(nDrawFrameLayerId)
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtGetNext(nFrameBottomId)
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTopId = EgtGetNext(nFrameRightId)
EgtSetName( nFrameTopId, WIN_TOP)
local nFrameLeftId = EgtGetNext(nFrameTopId)
EgtSetName( nFrameLeftId, WIN_LEFT)
-- creo frame
nAreaId = WinCreate.CreateGenFrame( {nFrameBottomId, nFrameRightId, nFrameTopId, nFrameLeftId}, {AreaTable[JWD_JOINT][JWD_JOINT_BL], AreaTable[JWD_JOINT][JWD_JOINT_BR], AreaTable[JWD_JOINT][JWD_JOINT_TR], AreaTable[JWD_JOINT][JWD_JOINT_TL]})
-- elimino contorno frame
EgtErase( nDrawFramePartId)
-- se BottomRail
if AreaTable[JWD_BOTTOM_RAIL] and AreaTable[JWD_BOTTOM_RAIL] == 1 then
WinCreate.AddBottomRail( nAreaId)
end
elseif AreaTable[JWD_AREA_TYPE] == WIN_AREATYPES.SASH then
nAreaId = WinCreate.AddSash( nAreaId, {AreaTable[JWD_JOINT][JWD_JOINT_BL], AreaTable[JWD_JOINT][JWD_JOINT_BR], AreaTable[JWD_JOINT][JWD_JOINT_TR], AreaTable[JWD_JOINT][JWD_JOINT_TL]}, AreaTable[JWD_SASH_TYPE])
elseif AreaTable[JWD_AREA_TYPE] == WIN_AREATYPES.FILL then
WinCreate.AddFill( nAreaId, AreaTable[JWD_FILL_TYPE])
elseif AreaTable[JWD_AREA_TYPE] == WIN_AREATYPES.SPLIT then
end
-- verifico se c'e' Split
if AreaTable[JWD_SPLIT] then
-- creo gruppo e layer per Split
local nDrawFramePartId = EgtGroup( GDB_ID.ROOT)
EgtSetName( nDrawFramePartId, 'DrawFrame')
local nDrawFrameLayerId = EgtGroup( nDrawFramePartId)
ConvertCurveTableToEntity( nDrawFrameLayerId, AreaTable[JWD_SPLIT][1])
local nArea1Id, nArea2Id = WinCreate.AddGenSplit( nAreaId, EgtGetFirstInGroup(nDrawFrameLayerId), AreaTable["SplitType"])
-- local nArea1Id, nArea2Id = WinCreate.AddGenSplit( nAreaId, EgtGetFirstInGroup(nDrawFrameLayerId))
EgtErase(nDrawFramePartId)
ConvertTableToGeometry( AreaTable[JWD_AREA .. 1], nArea1Id)
ConvertTableToGeometry( AreaTable[JWD_AREA .. 2], nArea2Id)
else
-- ciclo sulle sotto aree
local nChildIndex = 1
while AreaTable[JWD_AREA ..nChildIndex] do
ConvertTableToGeometry( AreaTable[JWD_AREA ..nChildIndex], nAreaId)
nChildIndex = nChildIndex + 1
end
end
end
-- funzione che crea le tabelle gerarchiche dalla struttura geometrica
function WinManageProject.CreateTableFromGeom( nFrameId)
-- creo la tabella
local WinTable = {}
-- riporto la path del profilo
local nProfileId = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PROFILE)
local sProfilePath = EgtGetInfo( nProfileId, WIN_PROFILEPATH)
WinTable[JWD_PROFILE_PATH] = sProfilePath
-- leggo aree
local FrameTable = ConvertAreaToTable( nFrameId)
local AreaName = JWD_AREA .. 1
WinTable[AreaName] = FrameTable
return WinTable
end
-- funzione che crea la struttura geometrica dalle tabelle gerarchiche
function WinManageProject.CreateGeomFromTable( WinTable)
-- importo profilo
if not WinCreate.ImportProfile( WinTable[JWD_PROFILE_PATH]) then
return false
end
-- creo aree
ConvertTableToGeometry( WinTable[JWD_AREA .. 1], GDB_ID.ROOT)
return true
end
-- funzione che dato un progetto gerarchico lo scrive in json su un file
function WinManageProject.WriteToFile( nFrameId, sFilePath)
local sFilePath = EgtChangePathExtension( sFilePath, JWD_EXT)
local WinTable = WinManageProject.CreateTableFromGeom( nFrameId)
local sData = JSON:encode_pretty(WinTable)
local DestFh = io.open( sFilePath, 'w+')
if not DestFh then
EgtOutBox( 'Error opening ' .. sFilePath, 'WriteToFile', 'ERROR')
return
end
DestFh:write( sData)
DestFh:close()
end
-- funzione che dato un file in json ne crea il progetto gerarchico
function WinManageProject.ReadFromFile( sFilePath)
local SouFh = io.open( sFilePath, "rb")
if not SouFh then
EgtOutBox( 'Error opening ' .. sFilePath, 'ReadFromFile', 'ERROR')
return false
end
local content = SouFh:read( "*all")
SouFh:close()
local tData = JSON:decode( content)
if not WinManageProject.CreateGeomFromTable( tData) then
return false
end
return true
end
---------------------------------------------------------------------
return WinManageProject