Files
egtstone3d/SceneButton/SceneButtonVM.vb
T
Daniele Bariletti 0e2641f1cf - proprietà checked per i toggle button
- gestione degli UC per input nella SceneButton.
2025-01-07 09:18:55 +01:00

274 lines
7.8 KiB
VB.net

Imports EgtUILib
Imports EgtWPFLib5
Public Class SceneButtonVM
Private m_TopListBtn As New List(Of ScenaBtn)
Public Property TopListBtn As List(Of ScenaBtn)
Get
Return m_TopListBtn
End Get
Set(value As List(Of ScenaBtn))
m_TopListBtn = value
End Set
End Property
Private m_LeftListBtn As New List(Of ScenaBtn)
Public Property LeftListBtn As List(Of ScenaBtn)
Get
Return m_LeftListBtn
End Get
Set(value As List(Of ScenaBtn))
m_LeftListBtn = value
End Set
End Property
Private m_RightListBtn As New List(Of ScenaBtn)
Public Property RightListBtn As List(Of ScenaBtn)
Get
Return m_RightListBtn
End Get
Set(value As List(Of ScenaBtn))
m_RightListBtn = value
End Set
End Property
Private m_BottomListBtn As New List(Of ScenaBtn)
Public Property BottomListBtn As List(Of ScenaBtn)
Get
Return m_BottomListBtn
End Get
Set(value As List(Of ScenaBtn))
m_BottomListBtn = value
End Set
End Property
Sub New()
SetButtonsLocation("TopListBtn", m_TopListBtn)
SetButtonsLocation("LeftListBtn", m_LeftListBtn)
SetButtonsLocation("RightListBtn", m_RightListBtn)
SetButtonsLocation("BottomListBtn", m_BottomListBtn)
End Sub
Private Sub SetButtonsLocation(PositionList As String, ListBtn As List(Of ScenaBtn))
Dim Index As Integer = 1
Dim sBtnString As String = String.Empty
While GetMainPrivateProfileString(PositionList, "Btn_" & Index.ToString, "", sBtnString) > 0
Dim sItems As String() = Split(sBtnString, ",")
If sItems.Count < 3 Then
' Errore di configurazione comando: mancano dei parametri
EgtOutLog("")
Else
Dim nType As Integer = 0
If sItems(0) = "Button" Then
' Button
ListBtn.Add(New _Button(sItems(1), sItems(2), sItems(3)))
ElseIf sItems(0) = "ToggleButton" Then
' ToggelButton
ListBtn.Add(New _ToggleButton(sItems(1), sItems(2), sItems(3)))
End If
End If
Index = Index + 1
sBtnString = String.Empty
End While
End Sub
Public Function IsTgBtnChecked(Flag As String) As Boolean
' cerco il bottone con il flag richiesto
Dim Btn As _ToggleButton = m_BottomListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
If IsNothing(Btn) Then
Btn = m_RightListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
If IsNothing(Btn) Then
Btn = m_TopListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
If IsNothing(Btn) Then
Btn = m_LeftListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
End If
End If
End If
' restituisco la sua profpriet IsChecked
Return Btn.IsChecked
End Function
Public Function GetButton(Flag As String) As ScenaBtn
' cerco il bottone con il flag richiesto
Dim Btn As _ToggleButton = m_BottomListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
If IsNothing(Btn) Then
Btn = m_RightListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
If IsNothing(Btn) Then
Btn = m_TopListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
If IsNothing(Btn) Then
Btn = m_LeftListBtn.FirstOrDefault(Function(x) x.Flag = Flag)
End If
End If
End If
Return Btn
End Function
End Class
Public Class ScenaBtn
Private m_ResourcesDir As String = "C:\EgtData\EgtSTONE3D\Resources\"
Private m_Name As String = String.Empty
Public Property Name As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_Img As String = String.Empty
Public Property Img As String
Get
Return m_Img
End Get
Set(value As String)
m_Img = value
End Set
End Property
Private m_Flag As String = String.Empty
Public Property Flag As String
Get
Return m_Flag
End Get
Set(value As String)
m_Flag = value
End Set
End Property
Private m_IsEnabled As Boolean = True
Public Property IsEnabled As Boolean
Get
Return m_IsEnabled
End Get
Set(value As Boolean)
m_IsEnabled = value
End Set
End Property
Sub New(_Name As String, _Img As String, _Flag As String)
m_Name = _Name
m_Img = m_ResourcesDir & _Img
m_Flag = _Flag
End Sub
Private m_CmdBtn As ICommand
Public ReadOnly Property CmdBtn As ICommand
Get
If m_CmdBtn Is Nothing Then
m_CmdBtn = New Command(AddressOf MethodBtn)
End If
Return m_CmdBtn
End Get
End Property
Private Sub MethodBtn()
SceneCmd.Exec(m_Flag)
End Sub
End Class
Public Class _Button
Inherits ScenaBtn
Sub New(_Name As String, _Img As String, _Flag As String)
MyBase.New(_Name, _Img, _Flag)
End Sub
End Class
Public Class _ToggleButton
Inherits ScenaBtn
Private m_IsChecked As Boolean = False
Public Property IsChecked As Boolean
Get
Return m_IsChecked
End Get
Set(value As Boolean)
m_IsChecked = value
End Set
End Property
Sub New(_Name As String, _Img As String, _Flag As String)
MyBase.New(_Name, _Img, _Flag)
End Sub
End Class
Module SceneCmd
Public Sub Exec(Flag)
Dim _SceneHostVM As SceneHostVM = DirectCast(Map.refSceneHostV.DataContext, SceneHostVM)
Dim nVeinCtx As Integer = _SceneHostVM.MainScene.GetCtx()
Select Case Flag
Case "AutoPair"
EgtSetCurrentContext(nVeinCtx)
EgtLuaSetGlobIntVar("ASS.nVeinCtx", nVeinCtx)
EgtLuaCallFunction("ASS.PairAll")
Case "Unpair"
SolidManagerM.Unpair(Map.refSceneHostV.m_nIdPart)
Case "Pair"
Map.refSceneButtonV.LoadPairUC()
Case "ResetInters"
SolidManagerM.ResetInters()
Case "Rotate"
Map.refSceneButtonV.LoadRotateUC()
Case Else
Dim x As Boolean = False
End Select
End Sub
Public Sub EnableActionButtons()
'If (m_nIdPart = GDB_ID.NULL) Then Return
''abilito i bottoni che possono eseguire delle azioni
'MoveExpander.IsEnabled = True
'MoveExpander.IsExpanded = True
'TgBtn_Rotation.IsEnabled = True
'Dim PartSolidSel As PartSolid = GetPartSolid(m_nIdPart)
'If Not IsNothing(PartSolidSel) And PartSolidSel.IsPaired() Then
' UnpairBtn.IsEnabled = True
' ExplodeBtn.IsEnabled = True
' ExplodeNormalsBtn.IsEnabled = True
'End If
End Sub
Public Sub DisableActionButtons()
''disabilito tutti i bottoni che eseguono azioni sul pezzo selezionato
''TgBtn_Rotation.IsEnabled = False
'ResetRotationBtn.IsEnabled = False
'UnpairBtn.IsEnabled = False
'ExplodeBtn.IsEnabled = False
'ExplodeNormalsBtn.IsEnabled = False
'MoveExpander.IsEnabled = False
'MoveExpander.IsExpanded = False
End Sub
Public Function DeselectAll() As Boolean
Dim bDeselected As Boolean = True
Dim nOriId As Integer = GDB_ID.NULL
For Each PartSolidSel In m_PartSolidList
'EgtGetInfo(PartSolidSel.PartId, KEY_ORI_ID, nOriId)
'If EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx()) AndAlso EgtExistsObj(nOriId) Then
' If Not (OmagOFFICEMap.refNestingTabVM.DeselectPart(nOriId, False)) Then
' bDeselected = False
' End If
'End If
EgtSetCurrentContext(m_nVeinCtx)
PartSolidSel.DeselectPart()
Next
Map.refSceneHostV.m_nIdPart = GDB_ID.NULL
DisableActionButtons()
Return bDeselected
End Function
End Module