Imports EgtUILib Imports EgtWPFLib5 Public Class SceneButtonVM Inherits VMBase #Region "FIELDS & PROPERTIES" Public Shared m_nIndexList As Integer = 0 Public Shared m_nIndexList_1 As Integer = 0 Public Shared m_nIndexList_2 As Integer = 0 Private m_TopListBtn As New List(Of SceneBtn) Public Property TopListBtn As List(Of SceneBtn) Get Return m_TopListBtn End Get Set(value As List(Of SceneBtn)) m_TopListBtn = value End Set End Property Private m_LeftListBtn As New List(Of SceneBtn) Public Property LeftListBtn As List(Of SceneBtn) Get Return m_LeftListBtn End Get Set(value As List(Of SceneBtn)) m_LeftListBtn = value End Set End Property Private m_RightListBtn As New List(Of SceneBtn) Public Property RightListBtn As List(Of SceneBtn) Get Return m_RightListBtn End Get Set(value As List(Of SceneBtn)) m_RightListBtn = value End Set End Property Private m_BottomListBtn As New List(Of SceneBtn) Public Property BottomListBtn As List(Of SceneBtn) Get Return m_BottomListBtn End Get Set(value As List(Of SceneBtn)) m_BottomListBtn = value End Set End Property Private m_BottomCenterListBtn As New List(Of SceneBtn) Public Property BottomCenterListBtn As List(Of SceneBtn) Get Return m_BottomCenterListBtn End Get Set(value As List(Of SceneBtn)) m_BottomCenterListBtn = value End Set End Property Private m_TopPanelListGroupBtn As New List(Of GroupSceneBtn) Public Property TopPanelListGroupBtn As List(Of GroupSceneBtn) Get Return m_TopPanelListGroupBtn End Get Set(value As List(Of GroupSceneBtn)) m_TopPanelListGroupBtn = value End Set End Property Friend Enum TopPanel As Integer TOP_PANEL = 0 TOP_PANEL_1 = 1 End Enum Private m_SelSelTopPanel As TopPanel = TopPanel.TOP_PANEL Public Property SelTopPanel As Integer Get Return m_SelSelTopPanel End Get Set(value As Integer) m_SelSelTopPanel = value End Set End Property Friend Sub SetSelTopPanel(TopOtion As TopPanel) m_SelSelTopPanel = TopOtion NotifyPropertyChanged(NameOf(SelTopPanel)) End Sub #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New() Map.SetRefSceneButtonVM(Me) LoadButtons() LoadGroupButtons() End Sub #End Region ' Constructor #Region "METHODS" ''' ''' Funzione che carica i bottoni ''' Private Sub LoadButtons() SetButtonsLocation(TOPLIST_BTN, m_TopListBtn) SetButtonsLocation(LEFTLIST_BTN, m_LeftListBtn) SetButtonsLocation(RIGHTLIST_BTN, m_RightListBtn) SetButtonsLocation(BOTTOMLIST_BTN, m_BottomListBtn) SetButtonsLocation(BOTTOMCENTERLIST_BTN, m_BottomCenterListBtn) End Sub Private Sub LoadGroupButtons() Dim Index As Integer = 1 Dim SubTitle As String = String.Empty Dim sKeyTitle As String = TOPPANELLIST_BTN & "_" & Index.ToString() While GetMainPrivateProfileString(sKeyTitle, ConstEgtStone3D.SUBTITLE, "", SubTitle) > 0 SetGroupButtonsLocation(sKeyTitle, m_TopPanelListGroupBtn) Index += 1 sKeyTitle = TOPPANELLIST_BTN & "_" & Index.ToString() End While End Sub ''' ''' Funzione che permette di posizionare i bottoni letti da file ini ''' ''' ''' Private Sub SetButtonsLocation(PositionList As String, ListBtn As List(Of SceneBtn)) 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))) ElseIf sItems(0) = "ButtonComboBox" And sItems.Count >= 4 Then ' Button che apre una combo box ListBtn.Add(New _ButtonComboBox(sItems(1), sItems(2), sItems(3), sItems(4))) End If End If Index += 1 sBtnString = String.Empty End While End Sub Private Sub SetGroupButtonsLocation(PositionList As String, ListGroupBtn As List(Of GroupSceneBtn)) Dim LocalListSceneBtn As New List(Of SceneBtn) Dim SubTitle As String = String.Empty Dim Title As String = String.Empty SetButtonsLocation(PositionList, LocalListSceneBtn) GetMainPrivateProfileString(PositionList, ConstEgtStone3D.SUBTITLE, "", SubTitle) Title = SplitSubTitle(SubTitle) ListGroupBtn.Add(New GroupSceneBtn(LocalListSceneBtn, Title)) End Sub Public Function IsTgBtnChecked(Flag As String) As Boolean ' cerco il bottone con il flag richiesto Dim Btn As _ToggleButton = GetButton(Flag) Dim bIsChecked As Boolean = False If Not IsNothing(Btn) Then bIsChecked = Btn.IsChecked ' restituisco la sua proprietà IsChecked Return bIsChecked End Function Public Function GetButton(Flag As String) As SceneBtn ' cerco il bottone con il flag richiesto Dim Btn As SceneBtn = m_BottomListBtn.FirstOrDefault(Function(x) x.Flag = Flag) If Not IsNothing(Btn) Then Return Btn Btn = m_RightListBtn.FirstOrDefault(Function(x) x.Flag = Flag) If Not IsNothing(Btn) Then Return Btn Btn = m_TopListBtn.FirstOrDefault(Function(x) x.Flag = Flag) If Not IsNothing(Btn) Then Return Btn Btn = m_LeftListBtn.FirstOrDefault(Function(x) x.Flag = Flag) If Not IsNothing(Btn) Then Return Btn Btn = m_BottomCenterListBtn.FirstOrDefault(Function(x) x.Flag = Flag) Return Btn End Function Private Function SplitSubTitle(SubTitle As String) As String Dim subTitleList As String() = SubTitle.Split("/"c) For IndexTitle As Integer = 0 To subTitleList.Count - 1 If IsNumeric(subTitleList(IndexTitle)) AndAlso Not EgtMsg(subTitleList(IndexTitle)).StartsWith("Msg") Then Return EgtMsg(subTitleList(IndexTitle)) Else Return subTitleList(IndexTitle + 1) End If Next Return String.Empty End Function #End Region ' Methods End Class Public Class GroupSceneBtn #Region "FIELDS & PROPERTIES" Private m_SubTitle As String Public Property SubTitle As String Get Return m_SubTitle End Get Set(value As String) m_SubTitle = value End Set End Property Private m_TopPanelListBtn As New List(Of SceneBtn) Public Property TopPanelListBtn As List(Of SceneBtn) Get Return m_TopPanelListBtn End Get Set(value As List(Of SceneBtn)) m_TopPanelListBtn = value End Set End Property #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New(TopPanelListBtn As List(Of SceneBtn), sSubTitle As String) m_TopPanelListBtn = TopPanelListBtn m_SubTitle = sSubTitle End Sub #End Region ' Constructor End Class Public Class SceneBtn Inherits VMBase #Region "FIELDS & PROPETIES" 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 #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New(_Name As String, _Img As String, _Flag As String) m_Name = _Name m_Img = Map.refMainWindowVM.MainWindowM.sResourcesDir & "\" & _Img m_Flag = _Flag End Sub #End Region ' Constructor #Region "COMMANDS" #Region "CmdBtn" 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 Region ' CmdBtn #End Region ' Commands End Class Public Class _Button Inherits SceneBtn #Region "CONSTRUCTOR" Sub New(_Name As String, _Img As String, _Flag As String) MyBase.New(_Name, _Img, _Flag) End Sub #End Region ' Constructor End Class Public Class _ToggleButton Inherits SceneBtn #Region "FIELDS & PROPERTIES" Private m_IsChecked As Boolean = False Public Property IsChecked As Boolean Get Return m_IsChecked End Get Set(value As Boolean) m_IsChecked = value NotifyPropertyChanged(NameOf(IsChecked)) End Set End Property #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New(_Name As String, _Img As String, _Flag As String) MyBase.New(_Name, _Img, _Flag) End Sub #End Region ' Constructor End Class Public Class _ButtonComboBox Inherits SceneBtn #Region "FIELDS & PROPERTIES" Private m_SourceList As New List(Of String) Public Property SourceList As List(Of String) Get Return m_SourceList End Get Set(value As List(Of String)) m_SourceList = value End Set End Property #End Region ' Fields & Properties #Region "CONSTRUCTOR" Sub New(_Name As String, _Img As String, _Flag As String, _PrototypeList As String) MyBase.New(_Name, _Img, _Flag) 'conversione da _PrototypeList a _List ''''' da implementare m_SourceList = New List(Of String)({"Becca", "Bacca", "Bionda", "Mora"}) 'm_SourceList = _List End Sub #End Region ' Constructor End Class Module SceneCmd #Region "METHODS" Public Sub Exec(Flag) Dim _SceneHostVM As SceneHostVM = DirectCast(Map.refSceneHostV.DataContext, SceneHostVM) Dim nVeinCtx As Integer = _SceneHostVM.MainScene.GetCtx() Select Case Flag Case EGT_AUTOPAIR EgtSetCurrentContext(nVeinCtx) EgtLuaSetGlobIntVar("ASS.nVeinCtx", nVeinCtx) EgtLuaCallFunction("ASS.PairAll") Case EGT_UNPAIR SolidManagerM.Unpair(Map.refSceneHostV.m_nIdPart) Case EGT_PAIR Map.refSceneButtonV.LoadPairUC() Case EGT_RESET_INTERS SolidManagerM.ResetInters() Case EGT_ROTATE Map.refSceneButtonV.LoadRotateUC() Case EGT_MOVE Map.refSceneButtonV.LoadMoveUC() Case EGT_UNDO Undo() Case EGT_REDO Redo() Case EGT_SEL_TYPE Map.refSceneButtonV.MenuSelType.IsOpen = True Case EGT_IMPORT_LOOP ImportLoop() Case EGT_CREATE_SOLID_LOOP SolidManagerM.CreateSolidFromLoops(Map.refSceneHostV.m_nIdPart) Case EGT_PANEL Map.refSceneButtonV.LoadPanelUC() Map.refSceneHostV.m_SelType = GDB_TY.CRV_LINE SolidManagerM.ShowLoopEdges() Case "ExportProject" ExportProjectNge() Case "Delete" SolidManagerM.Delete(Map.refSceneHostV.m_nIdPart) Case Else Dim x As Boolean = False End Select End Sub Friend Sub Undo() ' se con questa operazione torno all'inizio disattivo il bottone undo SolidManagerM.UndoEvent() SolidManagerM.ManageUndoRedo() EgtDraw() End Sub Friend Sub Redo() ' se con questa operazione ho finito la storia disponibile disattivo il bottone redo SolidManagerM.RedoEvent() SolidManagerM.ManageUndoRedo() EgtDraw() End Sub ''' ''' Funzione che permette di importare un file nge ''' Private Sub ImportLoop() Dim ImportDialog As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With { .Title = EgtMsg(91127), ' Importa .Filter = "nge files (*.nge)|*.nge", .FilterIndex = 1, .InitialDirectory = "C:\EgtData\EgtStone3D\Temp", .Mode = 1 } If Not ImportDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then Return If String.IsNullOrEmpty(ImportDialog.FileName) Then Return Dim sFilePath As String = ImportDialog.FileName EgtInsertFile(sFilePath) ' rinomino il part aggiungendo un UUID Dim nPart As Integer = EgtGetLastPart() Dim sName As String = String.Empty EgtGetName(nPart, sName) Dim sUUID As String = "" EgtLuaCallFunction("TOOL.GetNewUUID") EgtLuaGetGlobStringVar("TOOL.UUID", sUUID) If sName <> String.Empty Then sName = sUUID & "_" & sName Else sName = sUUID & "_ImportedLoop" End If EgtSetName(nPart, sName) Dim nRefLay As Integer = EgtCreateGroup(nPart) EgtSetName(nRefLay, "Ref") End Sub Public Sub EnableActionButtons() 'If (m_nIdPart = GDB_ID.NULL) Then Return ''abilito i bottoni che possono eseguire delle azioni '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 'UnpairBtn.IsEnabled = False 'ExplodeBtn.IsEnabled = False 'ExplodeNormalsBtn.IsEnabled = 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 '' deseleziono nel nesting '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 Public Sub AddPanel(nId As Integer) Dim PanelVM As PanelVM = DirectCast(Map.refSceneButtonV.m_PanelUC.DataContext, PanelVM) PanelVM.AddPanel(nId) End Sub Public Sub ExportProjectNge() ' creo una copia del contesto corrente Dim sSavePath As String = "C:\\EgtData\\EgtStone3D\\Temp\\export.nge" EgtSaveFile(sSavePath, 2) Dim nTempContext As Integer = EgtInitContext() ' setto il contesto temporaneo come corrente EgtSetCurrentContext(nTempContext) EgtOpenFile(sSavePath) Dim nPart As Integer = EgtGetFirstPart() Dim HorizontalOffset As Double = 0 While nPart <> GDB_ID.NULL Dim nNextPart As Integer = EgtGetNext(nPart) Dim sName As String = String.Empty EgtGetName(nPart, sName) If sName = "SOLID" Then EgtErase(nPart) Else ' accendo il part e il layer della regione EgtSetStatus(nPart, GDB_ST.ON_) Dim nRefLay As Integer = EgtGetFirstNameInGroup(nPart, "Region") EgtSetStatus(nRefLay, GDB_ST.ON_) ' riporto il part nell'origine EgtChangeGroupFrame(nPart, New Frame3d()) ' lo posizione affiancato agli altri Dim vtMove As New Vector3d(HorizontalOffset, 0, 0) EgtMove(nPart, vtMove, GDB_RT.GLOB) Dim BBox As New BBox3d EgtGetBBoxGlob(nPart, 0, BBox) HorizontalOffset += BBox.DimX + 5 End If nPart = nNextPart End While EgtSaveFile(sSavePath, 2) ' reimposto il contesto della scena principale e cancello il contesto temporaneo EgtSetCurrentContext(SolidManagerM.m_nVeinCtx) EgtDeleteContext(nTempContext) End Sub #End Region ' Methods End Module Public Class SplitConverter Implements IValueConverter Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert Dim dValue As Double = CDbl(value) Dim sParam() As String = DirectCast(parameter, TextBlock).Text.Split("_"c) Dim dParam As Double = CDbl(Map.refSceneButtonVM.TopPanelListGroupBtn(CInt(sParam(1))).TopPanelListBtn.Count()) + 1 Return (Math.Floor(dParam / 2)) * 35 End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Throw New NotImplementedException End Function End Class