Files
egwwindowlua/Profiles/WinLib/WinCreate.lua
T
Emmanuele Sassi 695422f484 - gestita mancanza hardware
- gestito handle in ferramenta
2024-06-26 15:45:54 +02:00

635 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)
-- 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 il buco per la finestra a partire da curve generiche
-- TO DO rendere i joints un vettore con un numero variabile a seconda del tipo di finestra
function WinCreate.CreateGenFrame( vFrameCrvs, nJointBL, nJointBR, nJointTL, nJointTR)
-- creo gruppo per telaio
local nFrameAreaId = EgtGroup( GDB_ID.ROOT)
EgtSetName( nFrameAreaId, WIN_AREA .. '(' .. WIN_FRAME .. ')')
-- imposto il tipo
EgtSetInfo( nFrameAreaId, WIN_AREATYPE, WIN_AREATYPES.FRAME)
-- creo il gruppo con le curve di outline
local nAreaOutlineLayerId = EgtGroup( nFrameAreaId)
EgtSetName( nAreaOutlineLayerId, WIN_AREAOUTLINE)
for i = 1, #vFrameCrvs do
EgtRelocateGlob( vFrameCrvs[i], nAreaOutlineLayerId)
end
-- imposto tipo giunzioni
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_BL, nJointBL)
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_BR, nJointBR)
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_TL, nJointTL)
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_TR, nJointTR)
return nFrameAreaId
end
----------------------------------------------------------------------------------
-- funzione che crea le curve che definiscono il telaio in base alla geometria richiesta
local function CreateFrameCurves( nLayerId, nType, dWidth, dHeight, dVal)
if nType == WIN_FRAME_TYPE.RECT then
-- telaio rettangolare
local nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTopId = EgtLine( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( 0, dHeight, 0))
EgtSetName( nFrameTopId, WIN_TOP)
local nFrameLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
elseif nType == WIN_FRAME_TYPE.CHAMFER_SIDE then
-- dHeight è l'altezza del lato sx, dVal è l'altezza del lato dx
local nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dVal, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTopId = EgtLine( nLayerId, Point3d( dWidth, dVal, 0), Point3d( 0, dHeight, 0))
EgtSetName( nFrameTopId, WIN_TOP)
local nFrameLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
elseif nType == WIN_FRAME_TYPE.CHAMFER then
-- dHeight è l'altezza dei lati verticali, dVal è l'altezza complessiva della finestra
local nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTop1Id = EgtLine( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( dWidth / 2, dVal, 0))
local nFrameTop2Id = EgtLine( nLayerId, Point3d( dWidth / 2, dVal, 0), Point3d( 0, dHeight, 0))
EgtSetName( nFrameTop1Id, WIN_TOP)
EgtSetName( nFrameTop2Id, WIN_TOP)
local nFrameLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
elseif nType == WIN_FRAME_TYPE.ROUND_ARC then
-- arco a tutto sesto
local nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight - 0.5 * dWidth, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTopId = EgtArcCPA( nLayerId, Point3d( 0.5 * dWidth, dHeight - 0.5 * dWidth, 0), Point3d( dWidth, dHeight - 0.5 * dWidth, 0), 180, 0)
EgtSetName( nFrameTopId, WIN_TOP)
local nFrameLeftId = EgtLine( nLayerId, Point3d( 0, dHeight - 0.5 * dWidth, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
elseif nType == WIN_FRAME_TYPE.SEGMENTAL_ARC then
-- arco ribassato
-- dHeight è l'altezza dei lati verticali, dVal è l'altezza complessiva della finestra
local nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTopId = EgtArc3P( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( 0.5 * dWidth, dVal, 0), Point3d( 0, dHeight, 0))
EgtSetName( nFrameTopId, WIN_TOP)
local nFrameLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
elseif nType == WIN_FRAME_TYPE.POINTED_ARC then
-- arco a tutto sesto
-- 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 nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dWidth, dHeight, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameTop1Id = EgtArc2PV( nLayerId, Point3d( dWidth, dHeight, 0), Point3d( 0.5 * dWidth, dVal, 0), Y_AX())
EgtSetName( nFrameTop1Id, WIN_TOP)
local nFrameTop2Id = EgtArc2PV( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0.5 * dWidth, dVal, 0), Y_AX())
EgtInvertCurve( nFrameTop2Id)
EgtSetName( nFrameTop2Id, WIN_TOP)
local nFrameLeftId = EgtLine( nLayerId, Point3d( 0, dHeight, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
elseif nType == WIN_FRAME_TYPE.TRG then
local nFrameBottomId = EgtLine( nLayerId, Point3d( 0, 0, 0), Point3d( dWidth, 0, 0))
EgtSetName( nFrameBottomId, WIN_BOTTOM)
local nFrameRightId = EgtLine( nLayerId, Point3d( dWidth, 0, 0), Point3d( dVal, dHeight, 0))
EgtSetName( nFrameRightId, WIN_RIGHT)
local nFrameLeftId = EgtLine( nLayerId, Point3d( dVal, dHeight, 0), Point3d( 0, 0, 0))
EgtSetName( nFrameLeftId, WIN_LEFT)
end
end
----------------------------------------------------------------------------------
-- funzione che crea il telaio a partire da una specifica geometria ( rettangolo, chamfer...)
function WinCreate.CreateFrame( nType, nJointBL, nJointBR, nJointTL, nJointTR, dWidth, dHeight, dHeight2)
-- creo un gruppo temporaneo per le curve di outline
local nTmpLay = EgtGroup( GDB_ID.ROOT)
-- disegno outline
CreateFrameCurves( nTmpLay, nType, dWidth, dHeight, dHeight2)
local nFrameAreaId = WinCreate.CreateGenFrame( EgtGetAllInGroup( nTmpLay), nJointBL, nJointBR, nJointTL, nJointTR)
EgtErase( nTmpLay)
return nFrameAreaId
end
----------------------------------------------------------------------------------
-------------------------------------- ANTA --------------------------------------
----------------------------------------------------------------------------------
-- funzione che aggiunge una anta
function WinCreate.AddSash( nAreaId, nJointBL, nJointBR, nJointTR, nJointTL, nSashType)
-- 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_JOINT_BL, nJointBL)
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_BR, nJointBR)
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_TL, nJointTL)
EgtSetInfo( nAreaOutlineLayerId, WIN_JOINT_TR, nJointTR)
-- imposto tipo di anta se presente
if nSashType then
EgtSetInfo( nSashAreaId, WIN_SASHTYPE, nSashType)
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_JOINT_BL)
EgtRemoveInfo( nAreaOutlineLayerId, WIN_JOINT_BR)
EgtRemoveInfo( nAreaOutlineLayerId, WIN_JOINT_TL)
EgtRemoveInfo( nAreaOutlineLayerId, WIN_JOINT_TR)
-- 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)
EgtSetName( nTempSplitLayerId, WIN_TEMPSPLIT)
-- 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
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
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
nResArea1, nResArea2 = WinCreate.AddSplit( nResArea2, SplitType, MeasureType, PositionList[nIndex], nProportion, nSplitType)
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 do
if nIndex > 1 then
EgtSetInfo( nResArea2, WIN_PRJ_ORIGSPLIT, nAreaLayerId)
end
nResArea1, nResArea2 = WinCreate.AddSplit( nResArea2, SplitType, MeasureType, PositionList[nIndex], nProportion - dAddPosition, nSplitType)
table.insert( AreaList, nResArea1)
if nIndex == #PositionList 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
nResArea1, nResArea2 = WinCreate.AddSplit( nResArea2, SplitType, MeasureType, EgtIf( nIndex == 1, PositionList[nIndex], PositionList[nIndex] / ( 1 - dAddPosition)), nProportion, nSplitType)
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 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)
local nOutlineLayerId = EgtGetFirstNameInGroup( nAreaLayerId, WIN_AREAOUTLINE)
local b3OutlineLayer = EgtGetBBox( nOutlineLayerId, GDB_BB.STANDARD)
-- allungo curva split per cercare intersezioni
EgtExtendCurveStartByLen( nSplitId, 10)
EgtExtendCurveEndByLen( nSplitId, 10)
-- recupero lista intersezioni
local OutlineInters = {}
local nOutlineId = EgtGetFirstInGroup( nOutlineLayerId)
while nOutlineId do
local sName = EgtGetName( nOutlineId)
-- verifico se ci siano intersezioni con questo outline
local ptInters = EgtIP( nSplitId, nOutlineId, EgtSP( nSplitId))
if ptInters then
table.insert( OutlineInters, { Id = nOutlineId, IntersPoint = ptInters})
end
nOutlineId = EgtGetNext( nOutlineId)
end
local ptStartSplit = EgtSP( nSplitId)
local ptEndSplit = EgtEP( nSplitId)
local StartInters
local EndInters
for nIndex = 1, #OutlineInters do
local CurrOutInters = OutlineInters[nIndex]
CurrOutInters.StartDistance = dist( CurrOutInters.IntersPoint, ptStartSplit)
CurrOutInters.EndDistance = dist( CurrOutInters.IntersPoint, ptEndSplit)
if not StartInters or CurrOutInters.StartDistance < StartInters.StartDistance then
StartInters = CurrOutInters
end
if not EndInters or CurrOutInters.EndDistance < EndInters.EndDistance then
EndInters = CurrOutInters
end
end
-- accorcio la curva split su intersezione outline
local dStartSplitInters = EgtCurveParamAtPoint( nSplitId, StartInters.IntersPoint)
EgtTrimCurveStartAtParam( nSplitId, dStartSplitInters)
local dEndSplitInters = EgtCurveParamAtPoint( nSplitId, EndInters.IntersPoint)
EgtTrimCurveEndAtParam( nSplitId, dEndSplitInters)
-- sistemo le info di intersezione
local dPar1 = EgtCurveParamAtPoint( StartInters.Id, StartInters.IntersPoint, 100 * GEO.EPS_SMALL)
local _, dParE1 = EgtCurveDomain( StartInters.Id)
if dPar1 < GEO.EPS_SMALL then
-- intersezione coinvolge anche curva precedente
local nOther = EgtGetPrev( StartInters.Id) or EgtGetLastInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_STARTINTERS, { nOther, StartInters.Id})
elseif abs( dPar1 - dParE1) < GEO.EPS_SMALL then
-- intersezione coinvolge anche curva successiva
local nOther = EgtGetNext( StartInters.Id) or EgtGetFirstInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_STARTINTERS, { StartInters.Id, nOther})
else
EgtSetInfo( nSplitId, WIN_SPLIT_STARTINTERS, { StartInters.Id})
end
local dPar2 = EgtCurveParamAtPoint( EndInters.Id, EndInters.IntersPoint, 100 * GEO.EPS_SMALL)
local _, dParE2 = EgtCurveDomain( EndInters.Id)
if dPar2 < GEO.EPS_SMALL then
-- intersezione coinvolge anche curva precedente
local nOther = EgtGetPrev( EndInters.Id) or EgtGetLastInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_ENDINTERS, { nOther, EndInters.Id})
elseif abs( dPar2 - dParE2) < GEO.EPS_SMALL then
-- intersezione coinvolge anche curva successiva
local nOther = EgtGetNext( EndInters.Id) or EgtGetFirstInGroup( nOutlineLayerId)
EgtSetInfo( nSplitId, WIN_SPLIT_ENDINTERS, { EndInters.Id, nOther})
else
EgtSetInfo( nSplitId, WIN_SPLIT_ENDINTERS, { EndInters.Id})
end
-- assegno nome profilo
EgtSetName( nSplitId, WIN_SPLIT)
-- creo aree
local nArea1Id, nArea2Id = WinCreate.CreateAreaFromSplit( nAreaLayerId, nSplitId)
-- verifico se discende da Frame
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 and nSplitType then
-- imposto tipo di split
EgtSetInfo( nSplitLayerId, WIN_SPLITTYPE, nSplitType)
-- EgtSetInfo( nSplitLayerId, WIN_SPLITTYPE, EgtIf( not nSplitType, WIN_SPLITTYPES.MULLION, nSplitType))
end
return nArea1Id, nArea2Id
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
----------------------------------------------------------------------------------
-- funzione che crea le aree da un taglio split
function WinCreate.CreateAreaFromSplit( nAreaLayerId, nSplitId)
-- creo layer per le due aree
local nArea1Id = EgtGroup( nAreaLayerId)
EgtSetName( nArea1Id , WIN_AREA1)
EgtSetInfo( nArea1Id, WIN_AREATYPE, WIN_AREATYPES.NULL)
local nArea1OutlineLayerId = EgtGroup( nArea1Id)
EgtSetName( nArea1OutlineLayerId , WIN_AREAOUTLINE)
local nArea2Id = EgtGroup( nAreaLayerId)
EgtSetName( nArea2Id , WIN_AREA2)
EgtSetInfo( nArea2Id, WIN_AREATYPE, WIN_AREATYPES.NULL)
local nArea2OutlineLayerId = EgtGroup( nArea2Id)
EgtSetName( nArea2OutlineLayerId , WIN_AREAOUTLINE)
local nOutlineLayerId = EgtGetFirstNameInGroup( nAreaLayerId, WIN_AREAOUTLINE)
local nOutlineId = EgtGetFirstInGroup( nOutlineLayerId)
local nInters = 0
while nOutlineId and nInters ~= 3 do
local sName = EgtGetName( nOutlineId)
-- calcolo intersezioni con questo outline
local ptInters = EgtIP( nSplitId, nOutlineId, EgtSP( nSplitId))
if ptInters then
if nInters == 0 then
-- trovato primo punto di intersezione - inizio area 2
local dStartIntersParam = EgtCurveParamAtPoint( nOutlineId, ptInters)
local _, dParE = EgtCurveDomain( nOutlineId)
if abs( dStartIntersParam - dParE) < GEO.EPS_SMALL then
-- se intersezione nel punto finale della curva la ignoro, la ritroverò analizzando l'outline successivo
else
nInters = 1
local nCopyId = EgtCopy( nOutlineId, nArea2OutlineLayerId)
EgtSetInfo( nCopyId, WIN_SOU, nOutlineId)
EgtRemoveInfo( nCopyId, WIN_CHILD)
AddInfo( nOutlineId, WIN_CHILD, nCopyId)
EgtTrimCurveStartAtParam( nCopyId, dStartIntersParam)
end
elseif nInters == 1 then
-- trovato secondo punto di intersezione - fine area 2
nInters = 2
local nCopyId = EgtCopy( nOutlineId, nArea2OutlineLayerId)
EgtSetInfo( nCopyId, WIN_SOU, nOutlineId)
EgtRemoveInfo( nCopyId, WIN_CHILD)
AddInfo( nOutlineId, WIN_CHILD, nCopyId)
local dEndIntersParam = EgtCurveParamAtPoint( nCopyId, ptInters)
EgtTrimCurveEndAtParam( nCopyId, dEndIntersParam)
-- copio anche split
local nSplitCopyId = EgtCopy( nSplitId, nArea2OutlineLayerId)
EgtSetInfo( nSplitCopyId, WIN_SOU, nSplitId)
EgtRemoveInfo( nSplitCopyId, WIN_CHILD)
AddInfo( nSplitId, WIN_CHILD, nSplitCopyId)
EgtRemoveInfo( nSplitCopyId, WIN_SPLIT_STARTINTERS)
EgtRemoveInfo( nSplitCopyId, WIN_SPLIT_ENDINTERS)
if not AreSamePointExact( EgtEP( nCopyId), EgtSP( nSplitCopyId)) then
EgtInvertCurve( nSplitCopyId)
end
-- verifico direzione per dare nome
local vtMedia = ( ( EgtEV( nSplitCopyId) - EgtSV( nSplitCopyId)) / 2)
if not vtMedia:normalize() then
vtMedia = EgtSV( nSplitCopyId)
end
if abs( vtMedia:getX()) > abs( vtMedia:getY()) then
EgtSetName( nSplitCopyId, WIN_BOTTOM)
else
EgtSetName( nSplitCopyId, WIN_LEFT)
end
-- inizio area 1
local _, dEnd = EgtCurveDomain( nOutlineId)
if abs( dEndIntersParam - dEnd) < GEO.EPS_SMALL then
-- l'intersezione è sul punto finale della curva di outline, quindi è la curva successiva che dà inizio all'area 1
nOutlineId = EgtGetNext( nOutlineId) or EgtGetFirstInGroup( nOutlineLayerId)
end
nCopyId = EgtCopy( nOutlineId, nArea1OutlineLayerId)
EgtSetInfo( nCopyId, WIN_SOU, nOutlineId)
EgtRemoveInfo( nCopyId, WIN_CHILD)
AddInfo( nOutlineId, WIN_CHILD, nCopyId)
local dStartIntersParam = EgtCurveParamAtPoint( nCopyId, ptInters)
EgtTrimCurveStartAtParam( nCopyId, dStartIntersParam)
elseif nInters == 2 then
-- trovato secondo punto di intersezione - fine area 1
nInters = 3
local nCopyId = EgtCopy( nOutlineId, nArea1OutlineLayerId)
EgtSetInfo( nCopyId, WIN_SOU, nOutlineId)
EgtRemoveInfo( nCopyId, WIN_CHILD)
AddInfo( nOutlineId, WIN_CHILD, nCopyId)
local dEndIntersParam = EgtCurveParamAtPoint( nCopyId, ptInters)
EgtTrimCurveEndAtParam( nCopyId, dEndIntersParam)
-- copio anche split
local nSplitCopyId = EgtCopy( nSplitId, nArea1OutlineLayerId)
EgtRemoveName( nSplitCopyId)
EgtSetInfo( nSplitCopyId, WIN_SOU, nSplitId)
EgtRemoveInfo( nSplitCopyId, WIN_CHILD)
AddInfo( nSplitId, WIN_CHILD, nSplitCopyId)
EgtRemoveInfo( nSplitCopyId, WIN_SPLIT_STARTINTERS)
EgtRemoveInfo( nSplitCopyId, WIN_SPLIT_ENDINTERS)
if not AreSamePointExact( EgtEP( nCopyId), EgtSP( nSplitCopyId)) then
EgtInvertCurve( nSplitCopyId)
end
-- verifico direzione per dare nome
local vtMedia = ( ( EgtEV( nSplitCopyId) - EgtSV( nSplitCopyId)) / 2)
if not vtMedia:normalize() then
vtMedia = EgtSV( nSplitCopyId)
end
if abs( vtMedia:getX()) > abs( vtMedia:getY()) then
EgtSetName( nSplitCopyId, WIN_TOP)
else
EgtSetName( nSplitCopyId, WIN_RIGHT)
end
end
elseif nInters == 1 then
-- copio nel profilo 2
local nCopyId = EgtCopy( nOutlineId, nArea2OutlineLayerId)
EgtSetInfo( nCopyId, WIN_SOU, nOutlineId)
EgtRemoveInfo( nCopyId, WIN_CHILD)
AddInfo( nOutlineId, WIN_CHILD, nCopyId)
elseif nInters == 2 then
-- copio nel profilo 1
local nCopyId = EgtCopy( nOutlineId, nArea1OutlineLayerId)
EgtSetInfo( nCopyId, WIN_SOU, nOutlineId)
EgtRemoveInfo( nCopyId, WIN_CHILD)
AddInfo( nOutlineId, WIN_CHILD, nCopyId)
end
-- aggiorno indice
nOutlineId = EgtGetNext( nOutlineId)
-- se arrivato alla fine riparto
if not nOutlineId then
nOutlineId = EgtGetFirstInGroup( nOutlineLayerId)
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
----------------------------------------------------------------------------------
---------------------------------- BOTTOMRAIL ------------------------------------
----------------------------------------------------------------------------------
-- funzione che aggiunge uno zoccolo
function WinCreate.AddBottomRail( nAreaId)
local nAreaType = EgtGetInfo( nAreaId, WIN_AREATYPE, 'i')
if nAreaType == WIN_AREATYPES.FRAME then
-- recupero l'outline bottom
local nBaseOutlineLayerId = EgtGetFirstNameInGroup( nAreaId, WIN_AREAOUTLINE)
-- local nBottomOutlineId = EgtGetFirstNameInGroup( nBaseOutlineLayerId, WIN_BOTTOM)
EgtSetInfo( nBaseOutlineLayerId, WIN_BOTTOMRAIL, 1)
end
end
----------------------------------------------------------------------------------
---------------------------------- FERRAMENTA ------------------------------------
----------------------------------------------------------------------------------
function WinCreate.AddHardware( nFrameId, sFavourite, sHandle)
EgtSetInfo( nFrameId, WIN_HDW_FAVOURITE, sFavourite)
EgtSetInfo( nFrameId, WIN_HDW_HANDLE, sHandle)
end
---------------------------------------------------------------------
return WinCreate