Sub Screenhandling(ByVal prefix, ByVal screenName)
'prefix = prefix for the popup (normally the instance name)
'callItemObjectName = the name of the symbol which opened the pop up (it's relevant for defining the position of the new popup)
' or in case of an extended faceplate the name of the screen window with the parent screen
'screenName = The screenname of the screen which shall be shown
'mainScreen = The screen in which all the screenwindows for the popups are.
'Param-Area----------------------------------------------------------------------------------------------------
'Define the coordinations (x, y) of the plant screen in the Main screen
Dim offsetLeftOptional, offsetTopOptional
offsetLeftOptional = 0
offsetTopOptional = 120
'--------------------------------------------------------------------------------------------------------------
Dim mainScreen, mainScreenName
mainScreenName = HMIRuntime.BaseScreenName
Set mainScreen = HMIRuntime.Screens(mainScreenName)
Dim counter, counter2, counter3, freeScreen, screenOpened, limitFPs
'LBP_LimitFaceplates起始值是16
limitFPs = SmartTags("@NOTP::LBP_LimitFaceplates").Value
'Introduction of all static Variables which are needed in the program
'引入程序中需要的所有静态变量
If HMIRuntime.DataSet(mainScreenName & "pointer") Is Nothing Then
'General settings of screenmanagement
' 屏幕管理常规设置
If HMIRuntime.DataSet("settingCloseIfLimitFPsReached") Is Nothing Then
HMIRuntime.DataSet.Add "settingCloseIfLimitFPsReached",1
End If
If HMIRuntime.DataSet("settingMultibleFPsOfSame") Is Nothing Then
HMIRuntime.DataSet.Add "settingMultibleFPsOfSame",1
End If
If HMIRuntime.DataSet("settingLimitFPPositionInsideProcessArea") Is Nothing Then
HMIRuntime.DataSet.Add "settingLimitFPPositionInsideProcessArea",1
End If
If HMIRuntime.DataSet(mainScreenName & "openedFPs") Is Nothing Then
HMIRuntime.DataSet.Add mainScreenName & "openedFPs",0
End If
HMIRuntime.DataSet.Add mainScreenName & "pointer",1
For counter = 1 To limitFPs
'the array is for saving the opening order
' 该数组用于保存开盘订单
HMIRuntime.DataSet.Add mainScreenName & "array_" & counter & "_screen",0 'Screennumber
Next
End If
'Check witch screens are closed and clear the order in the array
'检查屏幕是否关闭并清除数组中的顺序
Dim highFor, arrayField1, arrayField2, newEmptyField, openedFPs
openedFPs = 0
For counter = 1 To limitFPs
If (mainScreen.ScreenItems("swLBPScreen_" & counter).Visible = False)Then 'Check if there are new not visible windows 检查是否有新的不可见窗口
For counter2 = 1 To limitFPs
'Check if the number of the not visible window is still saved in the databuffer as a screen or a parentscreen. Parentscreen is only importent if settings say that if a screen was closed the extended window shall close automatic
'检查不可见窗口的编号是否仍作为屏幕或父屏幕保存在数据缓冲区中。 仅当设置表明如果屏幕关闭扩展窗口应自动关闭"swMain"时,父屏幕才重要
If (HMIRuntime.DataSet(mainScreenName & "array_" & counter2 & "_screen").Value = counter) Then
'Stuct the databuffer new so that the pointer points on a closed window and all the other closed windows are saved in the fields behind.
' 构造databuffer new,使指针指向一个关闭的窗口,所有其他关闭的窗口都保存在后面的字段中。"swMain"
newEmptyField = counter2
If HMIRuntime.DataSet(mainScreenName & "pointer").Value > newEmptyField Then
highFor = (limitFPs - HMIRuntime.DataSet(mainScreenName & "pointer").Value) + newEmptyField
ElseIf HMIRuntime.DataSet(mainScreenName & "pointer").Value < newEmptyField Then
highFor = newEmptyField - HMIRuntime.DataSet(mainScreenName & "pointer").Value
End If
If (HMIRuntime.DataSet(mainScreenName & "pointer").Value <> newEmptyField) Then
For counter3 = 1 To highFor
arrayField1 = (newEmptyField - counter3) + 1
If arrayField1 < 1 Then
arrayField1 = limitFPs + arrayField1
End If
arrayField2 = newEmptyField - counter3
If arrayField2 < 1 Then
arrayField2 = limitFPs + arrayField2
End If
HMIRuntime.DataSet(mainScreenName & "array_" & arrayField1 & "_screen").Value = HMIRuntime.DataSet(mainScreenName & "array_" & arrayField2 & "_screen").Value
Next
End If
HMIRuntime.DataSet(mainScreenName & "array_" & HMIRuntime.DataSet(mainScreenName & "pointer").Value & "_screen").Value = 0
End If
Next
ElseIf (mainScreen.ScreenItems("swLBPScreen_" & counter).Visible = True)Then
openedFPs = openedFPs + 1
End If
Next
HMIRuntime.DataSet(mainScreenName & "openedFPs").Value = openedFPs
'if the function was only called to close the Msg window of a window which was closed stop here
'如果名称为空则退出
If (screenName = "") Then
Exit Sub
End If
'Check if there are free/closed screens检查是否有空闲/关闭的屏幕
freeScreen = 0
screenOpened = False
For counter = 1 To limitFPs
If (mainScreen.ScreenItems("swLBPScreen_" & counter).Visible = False)Then
freeScreen = counter
ElseIf (mainScreen.ScreenItems("swLBPScreen_" & counter).TagPrefix = prefix) And (mainScreen.ScreenItems("swLBPScreen_" & counter).ScreenName = screenName) Then
'If in the settings is configured that it is not possible to open several windows with the same content the variabele screenOpened is set
' 如果在设置中配置了无法打开具有相同内容的多个窗口,则设置了可变 screenOpened
If HMIRuntime.DataSet("settingMultibleFPsOfSame").Value = 1 Then
screenOpened = True
Exit For
End If
HMIRuntime.Trace "Screen already opened in Screen number " & counter & vbNewLine
End If
Next
'Get the parent screen number out of the object name
'从对象名中获取父屏号
Dim callItemLeft, callItemTop, callItem
Dim positionObject
'如果当前焦点对象是HMIFaceplateObject类型或者画面名称是LBP_Config就执行
If ActiveScreenItem.Type = "HMIFaceplateObject" Or screenName = "LBP_Config" Then
'当前焦点对象放置到positionObject变量中
Set positionObject = ActiveScreenItem
'如果关联的画面的名字不是mainScreenName的名称就执行顶部 左边的偏移设置
If Not positionObject.Parent.ObjectName = mainScreenName Then
callItemLeft = positionObject.Left + offsetLeftOptional
callItemTop = positionObject.Top + positionObject.Height + offsetTopOptional
Else
'关联的画面名字是mainScreenName的名称就
callItemLeft = positionObject.Left
callItemTop = positionObject.Top + positionObject.Height
End If
Else
'当前焦点不是HMIFaceplateObject类型或者画面名称是LBP_Config就执行
Set positionObject = ActiveScreenItem.Parent.Parent
'父对象的名字是否有swLBPScreen_字符串
If InStr(positionObject.ObjectName, "swLBPScreen_") > 0 Then
Else
Set positionObject = ActiveScreenItem.Parent.Parent.Parent.Parent
End If
callItemLeft = positionObject.Left
callItemTop = positionObject.Top + positionObject.Height
End If
Dim screenWidth, screenHeight
If screenName = "LBP_Alarms" Then
screenWidth = 910
screenHeight = 536
Else
screenWidth = 310
screenHeight = 536
End If
'if there are free screens open the new one and save the number of the window in the database如果有空闲屏幕,则打开新的屏幕,并将窗口的数量保存在数据库中
If (freeScreen > 0) And (screenOpened = False) Then
HMIRuntime.DataSet(mainScreenName & "array_" & HMIRuntime.DataSet(mainScreenName & "pointer").Value & "_screen").Value = freeScreen
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).TagPrefix = prefix
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).ScreenName = screenName
'Defining the position of the new Faceplate定义新面板的位置
If (callItemLeft + screenWidth > mainScreen.Width) And (HMIRuntime.DataSet("settingLimitFPPositionInsideProcessArea").Value = 1) Then
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).Left = mainScreen.Width - screenWidth
Else
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).Left = callItemLeft
End If
If (callItemTop + screenHeight > mainScreen.Height) And (HMIRuntime.DataSet("settingLimitFPPositionInsideProcessArea").Value = 1) Then
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).Top = mainScreen.Height - screenHeight
Else
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).Top = callItemTop
End If
mainScreen.ScreenItems("swLBPScreen_" & freeScreen).Visible = True
HMIRuntime.DataSet(mainScreenName & "pointer").Value = HMIRuntime.DataSet(mainScreenName & "pointer").Value + 1
ElseIf (freeScreen = 0) And (screenOpened = False) Then 'if there are no free screens如果没有空闲的屏幕
If HMIRuntime.DataSet("settingCloseIfLimitFPsReached").Value = 1 Then 'open the screen in the oldest screen if the settings allow to close the oldest automatic如果设置允许关闭最老的自动屏幕,则打开最老屏幕的屏幕
Dim helpVar
helpVar = HMIRuntime.DataSet(mainScreenName & "array_" & HMIRuntime.DataSet(mainScreenName & "pointer").Value & "_screen").Value
'Defining the position of the new Faceplate定义新面板的位置
If (callItemLeft + screenWidth > mainScreen.Width) And (HMIRuntime.DataSet("settingLimitFPPositionInsideProcessArea").Value = 1) Then
mainScreen.ScreenItems("swLBPScreen_" & helpVar).Left = mainScreen.Width - screenWidth
Else
mainScreen.ScreenItems("swLBPScreen_" & helpVar).Left = callItemLeft
End If
If (callItemTop + screenHeight > mainScreen.Height) And (HMIRuntime.DataSet("settingLimitFPPositionInsideProcessArea").Value = 1) Then
mainScreen.ScreenItems("swLBPScreen_" & helpVar).Top = mainScreen.Height - screenHeight
Else
mainScreen.ScreenItems("swLBPScreen_" & helpVar).Top = callItemTop
End If
mainScreen.ScreenItems("swLBPScreen_" & helpVar).TagPrefix = prefix
mainScreen.ScreenItems("swLBPScreen_" & helpVar).ScreenName = screenName
mainScreen.ScreenItems("swLBPScreen_" & helpVar).Visible = True
HMIRuntime.DataSet(mainScreenName & "pointer").Value = HMIRuntime.DataSet(mainScreenName & "pointer").Value + 1
Else
mainScreen.ScreenItems("swLimit").Visible = True
End If
End If
If HMIRuntime.DataSet(mainScreenName & "pointer").Value > limitFPs Then
HMIRuntime.DataSet(mainScreenName & "pointer").Value = 1
End If
End Sub