Files
egwwindowlua/Designing/WinLib/WinCreate.lua
T
2025-09-26 12:50:40 +02:00

696 lines
30 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 WinCreate = {}
-- Include
require( 'EgtBase')
require( 'WinConst')
-- funzioni
----------------------------------------------------------------------------------
local function AddInfo( nId, sInfo, nVal)
local vInfo = EgtGetInfo( nId, sInfo, 'vi') or {}
table.insert( vInfo, nVal)
EgtSetInfo( nId, sInfo, vInfo)
end
----------------------------------------------------------------------------------
-- funzione che importa il profilo
function WinCreate.ImportProfile( sProfilePath)
-- verifico esistenza file
if not EgtExistsFile( sProfilePath) then
EgtOutLog( 'File del profilo non trovato! ' .. sProfilePath)
EgtOutText( 'File del profilo non trovato! ' .. sProfilePath)
EgtPause(5000)
return false
end
-- creo gruppo per il profilo
local nProfileId = EgtGroup( GDB_ID.ROOT)
EgtSetName( nProfileId, WIN_PROFILE)
EgtSetLevel( nProfileId, GDB_LV.SYSTEM)
-- importo profilo prescelto
local bOk = EgtInsertFile( sProfilePath)
-- recupero gruppi importati e li sposto nel gruppo profilo
local nGroupId = EgtGetFirstInGroup( GDB_ID.ROOT)
while nGroupId do
if nGroupId ~= nProfileId then
local nCurrId = nGroupId
nGroupId = EgtGetNext( nGroupId)
EgtRelocateGlob( nCurrId, nProfileId)
EgtSetStatus( nCurrId, GDB_ST.OFF)
else
nGroupId = EgtGetNext( nGroupId)
end
end
-- riporto path nel Part del profilo
EgtSetInfo( nProfileId, WIN_PROFILEPATH, sProfilePath)
return true
end
----------------------------------------------------------------------------------
------------------------------------- TELAIO -------------------------------------
----------------------------------------------------------------------------------
-- funzione che crea le curve che definiscono il telaio in base alla geometria richiesta
local function CreateFrameCurves( nLayerId, nType, dWidth, dHeight, dVal)
-- rettangolo
if nType == WIN_FRAME_TYPES.RECT then
-- telaio rettangolare
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nRightId, WIN_RIGHT)
local nTopId = EgtLine( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( 0, dHeight, 0))
EgtSetName( nTopId, WIN_TOP)
local nLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), ORIG())
EgtSetName( nLeftId, WIN_LEFT)
-- lato top inclinato
elseif nType == WIN_FRAME_TYPES.CHAMFER_SIDE then
-- dHeight è l'altezza del lato sx, dVal è l'altezza del lato dx
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dVal, 0))
EgtSetName( nRightId, WIN_RIGHT)
local nTopId = EgtLine( nLayerId, Point3d( dWidth, dVal, 0), Point3d( 0, dHeight, 0))
EgtSetName( nTopId, WIN_TOP)
local nLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), ORIG())
EgtSetName( nLeftId, WIN_LEFT)
-- triangular arch
elseif nType == WIN_FRAME_TYPES.CHAMFER then
-- dHeight è l'altezza dei lati verticali, dVal è l'altezza complessiva della finestra
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nRightId, WIN_RIGHT)
local nTop1Id = EgtLine( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( dWidth / 2, dVal, 0))
local nTop2Id = EgtLine( nLayerId, Point3d( dWidth / 2, dVal, 0), Point3d( 0, dHeight, 0))
EgtSetName( nTop1Id, WIN_TOP)
EgtSetName( nTop2Id, WIN_TOP)
local nLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), ORIG())
EgtSetName( nLeftId, WIN_LEFT)
-- arco a tutto sesto
elseif nType == WIN_FRAME_TYPES.ROUND_ARC then
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight - 0.5 * dWidth, 0))
EgtSetName( nRightId, WIN_RIGHT)
local nTopId = EgtArcCPA( nLayerId, Point3d( 0.5 * dWidth, dHeight - 0.5 * dWidth, 0), Point3d( dWidth, dHeight - 0.5 * dWidth, 0), 180, 0)
EgtSetName( nTopId, WIN_TOP)
local nLeftId = EgtLine( nLayerId, Point3d( 0, dHeight - 0.5 * dWidth, 0), ORIG())
EgtSetName( nLeftId, WIN_LEFT)
-- arco ribassato
elseif nType == WIN_FRAME_TYPES.SEGMENTAL_ARC then
-- dHeight è l'altezza dei lati verticali, dVal è l'altezza complessiva della finestra
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nRightId, WIN_RIGHT)
local nTopId = EgtArc3P( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( 0.5 * dWidth, dVal, 0), Point3d( 0, dHeight, 0))
EgtSetName( nTopId, WIN_TOP)
local nLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), ORIG())
EgtSetName( nLeftId, WIN_LEFT)
-- arco a tutto sesto
elseif nType == WIN_FRAME_TYPES.POINTED_ARC then
-- dHeight è l'altezza dei lati verticali, dVal è l'altezza complessiva della finestra
-- verifico che le due altezze abbiano valori sensati per realizzare i due archi
if dVal - dHeight < 0.5 * dWidth then
return
end
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nRightId, WIN_RIGHT)
local nTop1Id = EgtArc2PV( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( 0.5 * dWidth, dVal, 0), Y_AX())
EgtSetName( nTop1Id, WIN_TOP)
local nTop2Id = EgtArc2PV( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0.5 * dWidth, dVal, 0), Y_AX())
EgtInvertCurve( nTop2Id)
EgtSetName( nTop2Id, WIN_TOP)
local nLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), ORIG())
EgtSetName( nLeftId, WIN_LEFT)
-- triangolo
elseif nType == WIN_FRAME_TYPES.TRG then
local nBottomId = EgtLine( nLayerId, ORIG(), Point3d( dWidth, 0, 0))
EgtSetName( nBottomId, WIN_BOTTOM)
local nEdge1Id = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dVal, dHeight, 0))
local nEdge2Id = EgtLine( nLayerId, Point3d( dVal, dHeight, 0), ORIG())
-- un lato verticale è right/left, un lato inclinato è top
if dVal < GEO.EPS_SMALL then
EgtSetName( nEdge1Id, WIN_TOP)
EgtSetName( nEdge2Id, WIN_LEFT)
elseif abs( dVal - dWidth) < GEO.EPS_SMALL then
EgtSetName( nEdge1Id, WIN_RIGHT)
EgtSetName( nEdge2Id, WIN_TOP)
else
EgtSetName( nEdge1Id, WIN_TOP)
EgtSetName( nEdge2Id, WIN_TOP)
end
end
end
----------------------------------------------------------------------------------
-- funzione che crea il telaio a partire da una specifica geometria ( rettangolo, chamfer...)
function WinCreate.CreateFrame( nType, vJoints, dWidth, dHeight, dHeight2)
-- creo gruppo per telaio
local nAreaId = EgtGroup( GDB_ID.ROOT)
EgtSetName( nAreaId, WIN_AREA .. '(' .. WIN_FRAME .. ')')
EgtSetLevel( nAreaId, GDB_LV.SYSTEM)
-- imposto il tipo
EgtSetInfo( nAreaId, WIN_AREATYPE, WIN_AREATYPES.FRAME)
-- costruisco le curve di outline
local nOutlineLayerId = EgtGroup( nAreaId)
EgtSetName( nOutlineLayerId, WIN_AREAOUTLINE)
CreateFrameCurves( nOutlineLayerId, nType, dWidth, dHeight, dHeight2)
EgtSetInfo( nAreaId, WIN_FRAME_TYPE, nType)
-- imposto tipo giunzioni
EgtSetInfo( nOutlineLayerId, WIN_JOINTS, vJoints)
return nAreaId
end
----------------------------------------------------------------------------------
-------------------------------------- ANTA --------------------------------------
----------------------------------------------------------------------------------
-- funzione che aggiunge una anta
function WinCreate.AddSash( nAreaId, vJoints, nSashType, nOpeningType)
-- creo nuova area
local nSashAreaId = EgtGroup( nAreaId)
EgtSetName( nSashAreaId, WIN_AREA .. '(' .. WIN_SASH .. ')')
-- imposto il tipo
EgtSetInfo( nSashAreaId, WIN_AREATYPE, WIN_AREATYPES.SASH)
-- recupero outline area precedente
local nPrevAreaOutlineId = EgtGetFirstNameInGroup( nAreaId, WIN_AREAOUTLINE)
-- lo copio per outline area dell'anta
local nAreaOutlineLayerId = EgtGroup( nSashAreaId)
EgtSetName( nAreaOutlineLayerId, WIN_AREAOUTLINE)
local nAreaOutlineId = EgtGetFirstInGroup( nPrevAreaOutlineId)
while nAreaOutlineId do
local nOutlineId = EgtCopy( nAreaOutlineId, nAreaOutlineLayerId)
EgtSetInfo( nOutlineId, WIN_SOU, nAreaOutlineId)
EgtRemoveInfo( nOutlineId, WIN_CHILD)
AddInfo( nAreaOutlineId, WIN_CHILD, nOutlineId)
nAreaOutlineId = EgtGetNext( nAreaOutlineId)
end
-- imposto tipo giunzioni
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINTS, vJoints)
-- imposto tipo di anta e di apertura se presente
if nSashType then
EgtSetInfo( nSashAreaId, WIN_SASHTYPE, nSashType)
end
if nOpeningType then
EgtSetInfo( nSashAreaId, WIN_OPENING_TYPE, nOpeningType)
end
return nSashAreaId
end
----------------------------------------------------------------------------------
-------------------------------------- FILL --------------------------------------
----------------------------------------------------------------------------------
-- funzione che aggiunge un riempimento
function WinCreate.AddFill( nAreaId, FillType)
-- creo nuova area
local nFillAreaId = EgtGroup( nAreaId)
EgtSetName( nFillAreaId, WIN_AREA .. '(' .. WIN_FILL .. ')')
-- imposto il tipo
EgtSetInfo( nFillAreaId, WIN_AREATYPE, WIN_AREATYPES.FILL)
-- recupero outline area precedente
local nPrevAreaOutlineId = EgtGetFirstNameInGroup( nAreaId, WIN_AREAOUTLINE)
-- lo copio per outline area del riempimento
local nAreaOutlineLayerId = EgtGroup( nFillAreaId)
EgtSetName( nAreaOutlineLayerId, WIN_AREAOUTLINE)
local nAreaOutlineId = EgtGetFirstInGroup( nPrevAreaOutlineId)
while nAreaOutlineId do
local nOutlineId = EgtCopy( nAreaOutlineId, nAreaOutlineLayerId)
EgtSetInfo( nOutlineId, WIN_SOU, nAreaOutlineId)
EgtRemoveInfo( nOutlineId, WIN_CHILD)
AddInfo( nAreaOutlineId, WIN_CHILD, nOutlineId)
nAreaOutlineId = EgtGetNext( nAreaOutlineId)
end
-- rimuovo eventuali info di giunzioni
EgtRemoveInfo( nAreaOutlineLayerId, WIN_JOINTS)
-- imposto tipo di fill
EgtSetInfo( nFillAreaId, WIN_FILLTYPE, FillType)
return nFillAreaId
end
----------------------------------------------------------------------------------
------------------------------------- SPLIT --------------------------------------
----------------------------------------------------------------------------------
-- funzione che crea un taglio split
function WinCreate.AddSplit( nAreaLayerId, SplitType, MeasureType, nPosition, nProportion, nSplitType)
-- creo layer temporaneo per split
local nTempSplitLayerId = EgtGroup( nAreaLayerId)
-- recupero contorno area precedente
local nOutlineLayerId = EgtGetFirstNameInGroup( nAreaLayerId, WIN_AREAOUTLINE)
local b3OutlineLayer = EgtGetBBox( nOutlineLayerId, GDB_BB.STANDARD)
local nTotSplitId
if SplitType == WIN_SPLITORIENTATION.VERTICAL then
-- creo linea
local nCalcPosition = 0
if MeasureType == WIN_MEASURE.ABSOLUT then
nCalcPosition = nPosition
elseif MeasureType == WIN_MEASURE.PROPORTIONAL then
nCalcPosition = b3OutlineLayer:getDimX() / nProportion * nPosition
elseif MeasureType == WIN_MEASURE.PERCENTAGE then
nCalcPosition = b3OutlineLayer:getDimX() * nPosition
end
if nCalcPosition > b3OutlineLayer:getDimX() - GEO.EPS_SMALL then
EgtErase( nTempSplitLayerId)
return
end
nTotSplitId = EgtLine( nTempSplitLayerId, b3OutlineLayer:getMin() + X_AX() * nCalcPosition, b3OutlineLayer:getMin() + X_AX() * nCalcPosition + Y_AX() * b3OutlineLayer:getDimY())
elseif SplitType == WIN_SPLITORIENTATION.HORIZONTAL then
-- creo linea
local nCalcPosition = 0
if MeasureType == WIN_MEASURE.ABSOLUT then
nCalcPosition = nPosition
elseif MeasureType == WIN_MEASURE.PROPORTIONAL then
nCalcPosition = b3OutlineLayer:getDimY() / nProportion * nPosition
elseif MeasureType == WIN_MEASURE.PERCENTAGE then
nCalcPosition = b3OutlineLayer:getDimY() * nPosition
end
if nCalcPosition > b3OutlineLayer:getDimY() - GEO.EPS_SMALL then
EgtErase( nTempSplitLayerId)
return
end
nTotSplitId = EgtLine( nTempSplitLayerId, b3OutlineLayer:getMin() + Y_AX() * nCalcPosition, b3OutlineLayer:getMin() + Y_AX() * nCalcPosition + X_AX() * b3OutlineLayer:getDimX())
end
-- calcolo split
local nArea1Id, nArea2Id = WinCreate.AddGenSplit( nAreaLayerId, nTotSplitId, nSplitType)
EgtErase( nTempSplitLayerId)
return nArea1Id, nArea2Id
end
----------------------------------------------------------------------------------
-- funzione che crea tagli split multipli
function WinCreate.AddSplits( nAreaLayerId, SplitType, MeasureType, PositionList, nProportion, nSplitType)
local AreaList = {}
if MeasureType == WIN_MEASURE.ABSOLUT then
local nResArea1
local nResArea2 = nAreaLayerId
for nIndex = 1, #PositionList do
if nIndex > 1 then
EgtSetInfo( nResArea2, WIN_PRJ_ORIGSPLIT, nAreaLayerId)
end
local nCurrentResArea2 = nResArea2
nResArea1, nResArea2 = WinCreate.AddSplit( nResArea2, SplitType, MeasureType, PositionList[nIndex], nProportion, nSplitType)
if not nResArea2 then
table.insert( AreaList, nCurrentResArea2)
break
end
table.insert( AreaList, nResArea1)
if nIndex == #PositionList then
table.insert( AreaList, nResArea2)
end
end
elseif MeasureType == WIN_MEASURE.PROPORTIONAL then
local nResArea1
local nResArea2 = nAreaLayerId
local dAddPosition = 0
for nIndex = 1, #PositionList - 1 do
if nIndex > 1 then
EgtSetInfo( nResArea2, WIN_PRJ_ORIGSPLIT, nAreaLayerId)
end
local nCurrentResArea2 = nResArea2
nResArea1, nResArea2 = WinCreate.AddSplit( nResArea2, SplitType, MeasureType, PositionList[nIndex], nProportion - dAddPosition, nSplitType)
if not nResArea2 then
table.insert( AreaList, nCurrentResArea2)
break
end
table.insert( AreaList, nResArea1)
if nIndex == #PositionList -1 then
table.insert( AreaList, nResArea2)
end
dAddPosition = dAddPosition + PositionList[nIndex]
end
elseif MeasureType == WIN_MEASURE.PERCENTAGE then
local nResArea1
local nResArea2 = nAreaLayerId
local dAddPosition = 0
local sChildAreas = ''
for nIndex = 1, #PositionList do
if nIndex > 1 then
EgtSetInfo( nResArea2, WIN_PRJ_ORIGSPLIT, nAreaLayerId)
sChildAreas = sChildAreas .. nResArea2 .. EgtIf( nIndex < #PositionList, ',', '')
end
local nCurrentResArea2 = nResArea2
nResArea1, nResArea2 = WinCreate.AddSplit( nResArea2, SplitType, MeasureType, EgtIf( nIndex == 1, PositionList[nIndex], PositionList[nIndex] / ( 1 - dAddPosition)), nProportion, nSplitType)
if not nResArea2 then
table.insert( AreaList, nCurrentResArea2)
break
end
table.insert( AreaList, nResArea1)
if nIndex == #PositionList then
table.insert( AreaList, nResArea2)
end
dAddPosition = dAddPosition + PositionList[nIndex]
end
EgtSetInfo( nAreaLayerId, 'ChildSplit', sChildAreas)
end
return AreaList
end
----------------------------------------------------------------------------------
-- funzione che crea tagli split grid
function WinCreate.AddGridSplits( nAreaLayerId, MeasureType, PositionListVert, PositionListHoriz, bStartVertical, nSplitType)
local AreaResult = {}
-- recupero contorno area precedente
local nOutlineLayerId = EgtGetFirstNameInGroup( nAreaLayerId, WIN_AREAOUTLINE)
local b3OutlineLayer = EgtGetBBox( nOutlineLayerId, GDB_BB.STANDARD)
-- calcolo numero parti totali nel caso di misura proporzionale
local nProportionVert = 0
local nProportionHoriz = 0
if MeasureType == WIN_MEASURE.PROPORTIONAL then
for i = 1, #PositionListVert do
nProportionVert = nProportionVert + PositionListVert[i]
end
for i = 1, #PositionListHoriz do
nProportionHoriz = nProportionHoriz + PositionListHoriz[i]
end
end
-- calcolo gli split nella direzione secondaria
local PositionAbs = {}
local PositionList = EgtIf( bStartVertical, PositionListHoriz, PositionListVert)
local nProportion = EgtIf( bStartVertical, nProportionHoriz, nProportionVert)
local dDim = EgtIf( bStartVertical, b3OutlineLayer:getDimY(), b3OutlineLayer:getDimX())
for i = 1, #PositionList do
if MeasureType == WIN_MEASURE.ABSOLUT then
PositionAbs[i] = PositionList[i]
elseif MeasureType == WIN_MEASURE.PROPORTIONAL then
PositionAbs[i] = dDim / nProportion * PositionList[i]
elseif MeasureType == WIN_MEASURE.PERCENTAGE then
PositionAbs[i] = dDim * PositionList[i]
end
end
if bStartVertical then
local AreaList = WinCreate.AddSplits( nAreaLayerId, WIN_SPLITORIENTATION.VERTICAL, MeasureType, PositionListVert, nProportionVert, nSplitType)
for i = 1, #AreaList do
local AreaTemp = WinCreate.AddSplits( AreaList[i], WIN_SPLITORIENTATION.HORIZONTAL, WIN_MEASURE.ABSOLUT, PositionAbs, nProportionHoriz, nSplitType) or {}
for j = 1, #AreaTemp do
table.insert( AreaResult, AreaTemp[j])
end
end
else
local AreaList = WinCreate.AddSplits( nAreaLayerId, WIN_SPLITORIENTATION.HORIZONTAL, MeasureType, PositionListHoriz, nProportionHoriz, nSplitType)
for i = 1, #AreaList do
-- recupero contorno area corrente
local nCurrentOutlineLayerId = EgtGetFirstNameInGroup( AreaList[i], WIN_AREAOUTLINE)
local b3CurrentOutlineLayer = EgtGetBBox( nCurrentOutlineLayerId, GDB_BB.STANDARD)
local dDiff = b3OutlineLayer:getMin():getX() - b3CurrentOutlineLayer:getMin():getX()
if dDiff < - GEO.EPS_SMALL then
local nFirstIndex = #PositionAbs + 1
for k = 1, #PositionAbs do
if PositionAbs[k] + dDiff > GEO.EPS_SMALL then
PositionAbs[k] = PositionAbs[k] + dDiff
nFirstIndex = k
break
elseif k ~= #PositionAbs then
PositionAbs[k + 1] = PositionAbs[k] + PositionAbs[k + 1]
end
end
for k = 1, nFirstIndex - 1 do
table.remove( PositionAbs, 1)
end
end
local AreaTemp = WinCreate.AddSplits( AreaList[i], WIN_SPLITORIENTATION.VERTICAL, WIN_MEASURE.ABSOLUT, PositionAbs, nProportionVert, nSplitType) or {}
for j = 1, #AreaTemp do
table.insert( AreaResult, AreaTemp[j])
end
end
end
return AreaResult
end
----------------------------------------------------------------------------------
-- funzione che assegna il nome alla curva di split nella sottoarea in base alla sua direzione
local function SetSplitName( nSplitId)
local vtMedia = ( ( EgtEV( nSplitId) - EgtSV( nSplitId)) / 2)
if not vtMedia:normalize() then
vtMedia = EgtSV( nSplitId)
end
if abs( vtMedia:getX()) > abs( vtMedia:getY()) then
if vtMedia:getX() > 0 then
EgtSetName( nSplitId, WIN_BOTTOM)
else
EgtSetName( nSplitId, WIN_TOP)
end
else
if vtMedia:getY() > 0 then
EgtSetName( nSplitId, WIN_RIGHT)
else
EgtSetName( nSplitId, WIN_LEFT)
end
end
end
----------------------------------------------------------------------------------
-- funzione che crea le aree da un taglio split
local function CreateAreaFromSplit( nAreaLayerId, nCompo, nSplitId, dPar1, dPar2, vOutlineCrvs)
-- creo layer per le due sottoaree
local nArea1Id = EgtGroup( nAreaLayerId)
EgtSetName( nArea1Id , WIN_AREA .. '1')
EgtSetInfo( nArea1Id, WIN_AREATYPE, WIN_AREATYPES.NULL)
local nArea1OutlineLayerId = EgtGroup( nArea1Id)
EgtSetName( nArea1OutlineLayerId , WIN_AREAOUTLINE)
local nArea2Id = EgtGroup( nAreaLayerId)
EgtSetName( nArea2Id , WIN_AREA .. '2')
EgtSetInfo( nArea2Id, WIN_AREATYPE, WIN_AREATYPES.NULL)
local nArea2OutlineLayerId = EgtGroup( nArea2Id)
EgtSetName( nArea2OutlineLayerId , WIN_AREAOUTLINE)
-- ad ogni sottoarea associo la porzione di curva composita corrispondente
local nCrv1 = EgtCopyGlob( nCompo, nArea1OutlineLayerId)
local nCrv2 = EgtCopyGlob( nCompo, nArea2OutlineLayerId)
EgtTrimCurveStartEndAtParam( nCrv1, dPar2, dPar1)
EgtTrimCurveStartEndAtParam( nCrv2, dPar1, dPar2)
-- copio curva di split
local nSplitId1 = EgtCopyGlob( nSplitId, nArea1OutlineLayerId)
local nSplitId2 = EgtCopyGlob( nSplitId, nArea2OutlineLayerId)
-- verifico se necessaria inversione
if AreSamePointApprox( EgtSP( nSplitId1), EgtSP( nCrv1)) then
EgtInvertCurve( nSplitId1)
end
if AreSamePointApprox( EgtSP( nSplitId2), EgtSP( nCrv2)) then
EgtInvertCurve( nSplitId2)
end
-- assegno il nome in base alla direzione
SetSplitName( nSplitId1)
SetSplitName( nSplitId2)
-- assengo le info di source e child
EgtSetInfo( nSplitId, WIN_CHILD, { nSplitId1, nSplitId2})
EgtSetInfo( nSplitId1, WIN_SOU, nSplitId)
EgtSetInfo( nSplitId2, WIN_SOU, nSplitId)
-- spezzo le curve composite per riottenere le curve originarie di partenza
local nFirst1, nCnt1 = EgtExplodeCurveCompo( nCrv1)
local nFirst2, nCnt2 = EgtExplodeCurveCompo( nCrv2)
-- assegno nome e info
local vCrvs = EgtTableFill( nFirst1, nCnt1)
EgtTableAdd( vCrvs, nFirst2, nCnt2)
for i = 1, #vCrvs do
-- ricavo la curva di outline originale da cui deriva
local ptM = EgtMP( vCrvs[i])
for j = 1, #vOutlineCrvs do
if EgtCurveParamAtPoint( vOutlineCrvs[j], ptM, 100 * GEO.EPS_SMALL) then
-- ne prendo il nome
EgtSetName( vCrvs[i], EgtGetName( vOutlineCrvs[j]))
-- assegno le info di child e source
EgtSetInfo( vCrvs[i], WIN_SOU, vOutlineCrvs[j])
AddInfo( vOutlineCrvs[j], WIN_CHILD, vCrvs[i])
break
end
end
end
-- scorro pezzi del primo e secondo outline per avere bottom come primo
local nFirstInAreaId = EgtGetFirstInGroup( nArea1OutlineLayerId)
local sFirstInAreaName = EgtGetName( nFirstInAreaId)
while sFirstInAreaName ~= WIN_BOTTOM do
EgtRelocate( nFirstInAreaId, nArea1OutlineLayerId)
nFirstInAreaId = EgtGetFirstInGroup( nArea1OutlineLayerId)
sFirstInAreaName = EgtGetName( nFirstInAreaId)
end
nFirstInAreaId = EgtGetFirstInGroup( nArea2OutlineLayerId)
sFirstInAreaName = EgtGetName( nFirstInAreaId)
while sFirstInAreaName ~= WIN_BOTTOM do
EgtRelocate( nFirstInAreaId, nArea2OutlineLayerId)
nFirstInAreaId = EgtGetFirstInGroup( nArea2OutlineLayerId)
sFirstInAreaName = EgtGetName( nFirstInAreaId)
end
return nArea1Id, nArea2Id
end
----------------------------------------------------------------------------------
-- funzione che crea un taglio split da una curva generica
function WinCreate.AddGenSplit( nAreaLayerId, nSplitId, nSplitType)
-- se area nulla diventa di tipo split
local nAreaType = EgtGetInfo( nAreaLayerId, WIN_AREATYPE, 'i')
if nAreaType == WIN_AREATYPES.NULL then
EgtSetInfo( nAreaLayerId, WIN_AREATYPE, WIN_AREATYPES.SPLIT)
end
-- creo layer per split
local nSplitLayerId = EgtGroup( nAreaLayerId)
EgtSetName( nSplitLayerId, WIN_BASESPLIT)
-- sposto curva split nel layer
EgtRelocateGlob( nSplitId, nSplitLayerId)
-- assegno nome profilo
EgtSetName( nSplitId, WIN_SPLIT)
-- verifico se devo impostare tipo di split ( solo se deriva da tipo frame)
if nSplitType then
local nParentAreaId = nAreaLayerId
local nParentAreaType = nAreaType
-- recupero parent fino a trovare frame o sash
while nParentAreaType ~= WIN_AREATYPES.FRAME and nParentAreaType ~= WIN_AREATYPES.SASH do
nParentAreaId = EgtGetParent( nParentAreaId)
nParentAreaType = EgtGetInfo( nParentAreaId, WIN_AREATYPE, 'i')
end
if nParentAreaType == WIN_AREATYPES.FRAME then
-- imposto tipo di split
EgtSetInfo( nSplitLayerId, WIN_SPLITTYPE, nSplitType)
end
end
-- Ricerca delle intersezioni :
-- creo una curva composita a partire da tutte le curve di outline
local nOutlineLayerId = EgtGetFirstNameInGroup( nAreaLayerId, WIN_AREAOUTLINE)
local vOutlineCrvs = EgtGetAllInGroup( nOutlineLayerId)
local nCompo = EgtCurveCompo( nSplitLayerId, vOutlineCrvs, false)
-- allungo curva split per cercare intersezioni
EgtExtendCurveStartByLen( nSplitId, 10)
EgtExtendCurveEndByLen( nSplitId, 10)
-- trovo intersezioni tra composita e lo split
local nFirst, nPntCnt, nCrvCnt = EgtCurveCurveInters( nCompo, nSplitId, nSplitLayerId)
if nCrvCnt ~= 0 or nPntCnt ~= 2 then
-- errore
return
end
-- recupero i due punti di intersezione
local pt1 = EgtSP( nFirst)
local pt2 = EgtSP( nFirst + 1)
EgtErase( { nFirst, nFirst + 1})
-- recupero i parametri di intersezione sulla curva di split
local dSplitParS = EgtCurveParamAtPoint( nSplitId, pt1, 100 * GEO.EPS_SMALL)
local dSplitParE = EgtCurveParamAtPoint( nSplitId, pt2, 100 * GEO.EPS_SMALL)
-- recupero i parametri di intersezione sulla curva composita
local dPar1 = EgtCurveParamAtPoint( nCompo, pt1, 100 * GEO.EPS_SMALL)
local dPar2 = EgtCurveParamAtPoint( nCompo, pt2, 100 * GEO.EPS_SMALL)
-- ricavo i parametri di intersezione legati a start ed end dello split
local dParCrvS = dPar1
local dParCrvE = dPar2
if dSplitParS > dSplitParE then
dSplitParS, dSplitParE = dSplitParE, dSplitParS
dParCrvS, dParCrvE = dParCrvE, dParCrvS
end
-- taglio la curva di split nei punti di intersezione
EgtTrimCurveStartEndAtParam( nSplitId, dSplitParS, dSplitParE)
-- setto info per intersezione start
-- se il parametro è intero allora l'intersezione coinvolge due curve successive
if abs( dParCrvS - ceil( dParCrvS)) < GEO.EPS_SMALL then
local nCrv = vOutlineCrvs[ ceil( dParCrvS) + 1]
local nOther = EgtGetPrev( nCrv) or EgtGetLastInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_STARTINTERS, { nOther, nCrv})
elseif abs( dParCrvS - floor( dParCrvS)) < GEO.EPS_SMALL then
local nCrv = vOutlineCrvs[ floor( dParCrvS) + 1]
local nOther = EgtGetPrev( nCrv) or EgtGetLastInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_STARTINTERS, { nOther, nCrv})
else
-- se il parametro non è intero allora l'intersezione coinvolge una sola curva
local nCrv = vOutlineCrvs[ floor( dParCrvS) + 1]
EgtSetInfo( nSplitId, WIN_SPLIT_STARTINTERS, { nCrv})
end
-- setto info per intersezione end
if abs( dParCrvE - ceil( dParCrvE)) < GEO.EPS_SMALL then
local nCrv = vOutlineCrvs[ ceil( dParCrvE) + 1]
local nOther = EgtGetPrev( nCrv) or EgtGetLastInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_ENDINTERS, { nOther, nCrv})
elseif abs( dParCrvE - floor( dParCrvE)) < GEO.EPS_SMALL then
local nCrv = vOutlineCrvs[ floor( dParCrvE) + 1]
local nOther = EgtGetPrev( nCrv) or EgtGetLastInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_ENDINTERS, { nOther, nCrv})
else
local nCrv = vOutlineCrvs[ floor( dParCrvE) + 1]
EgtSetInfo( nSplitId, WIN_SPLIT_ENDINTERS, { nCrv})
end
-- creo sottoaree
local nArea1, nArea2 = CreateAreaFromSplit( nAreaLayerId, nCompo, nSplitId, dPar1, dPar2, vOutlineCrvs)
EgtErase( nCompo)
return nArea1, nArea2
end
----------------------------------------------------------------------------------
-- funzione che crea tagli split da curve generiche
function WinCreate.AddGenSplits( nAreaLayerId, SplitList)
for nIndex = 1, #SplitList do
WinCreate.AddSplit( nAreaLayerId, SplitList[nIndex])
end
end
----------------------------------------------------------------------------------
---------------------------------- BOTTOMRAIL ------------------------------------
----------------------------------------------------------------------------------
-- funzione che aggiunge uno zoccolo
function WinCreate.AddBottomRail( nAreaId, nNbr)
local nAreaType = EgtGetInfo( nAreaId, WIN_AREATYPE, 'i')
if nAreaType == WIN_AREATYPES.FRAME or nAreaType == WIN_AREATYPES.SASH then
EgtSetInfo( nAreaId, WIN_BOTTOMRAIL, nNbr)
end
end
----------------------------------------------------------------------------------
---------------------------------- SOGLIA ------------------------------------
----------------------------------------------------------------------------------
-- funzione che aggiunge la soglia
function WinCreate.AddThreshold( nAreaId, sThresholdProfile)
local nAreaType = EgtGetInfo( nAreaId, WIN_AREATYPE, 'i')
if nAreaType == WIN_AREATYPES.FRAME then
EgtSetInfo( nAreaId, WIN_THRESHOLD_PROFILE, sThresholdProfile)
end
end
----------------------------------------------------------------------------------
---------------------------------- FERRAMENTA ------------------------------------
----------------------------------------------------------------------------------
function WinCreate.AddHardware( nFrameId, sFavourite, sHandle)
EgtSetInfo( nFrameId, WIN_HDW_FAVOURITE, sFavourite)
EgtSetInfo( nFrameId, WIN_HDW_HANDLE, sHandle)
end
---------------------------------------------------------------------
return WinCreate