diff --git a/App.config b/App.config new file mode 100644 index 0000000..3fa3cae --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/Application.xaml b/Application.xaml new file mode 100644 index 0000000..5d37f51 --- /dev/null +++ b/Application.xaml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/Application.xaml.vb b/Application.xaml.vb new file mode 100644 index 0000000..d4b39fc --- /dev/null +++ b/Application.xaml.vb @@ -0,0 +1,14 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + Protected Overrides Sub OnStartup(e As StartupEventArgs) + MyBase.OnStartup(e) + ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose + ' Creo la View principale + Me.MainWindow = New MainWindowV + ' Mostro la View principale + Me.MainWindow.Show() + End Sub + +End Class diff --git a/Constants/ConstGen.vb b/Constants/ConstGen.vb new file mode 100644 index 0000000..4f8b30c --- /dev/null +++ b/Constants/ConstGen.vb @@ -0,0 +1,52 @@ +'---------------------------------------------------------------------------- +' EgalTech 2015-2017 +'---------------------------------------------------------------------------- +' File : ConstGen.vb Data : 10.04.17 Versione : 1.8d1 +' Contenuto : Modulo costanti generali. +' +' +' +' Modifiche : 10.04.17 DS Creazione modulo. +' +' +'---------------------------------------------------------------------------- + +Module ConstGen + + ' File con direttorio radice dei dati + Public Const DAT_FILE_NAME As String = "DataRoot.Ini" + Public Const S_DATA As String = "Data" + Public Const K_DATAROOT As String = "DataRoot" + + ' File con dati di licenza + Public Const LIC_FILE_NAME As String = "OmagVIEWPlus.lic" + Public Const S_LICENCE As String = "Licence" + Public Const K_KEY As String = "Key" + + ' Abilitazioni licenza + Friend Enum KEY_OPT As UInteger + CUT_BASE = 1 ' Prodotto OmagCUT + MAN_MANIP = 2 + AUTO_MANIP = 4 + MAN_PHOTO = 8 + AUTO_PHOTO = 16 + AUTO_NESTING = 32 + ENABLE_MILL = 64 + PROCUCTION_LINE = 128 + OFFICE_BASE = 256 ' Prodotto OmagOFFICE + VM_MULTI = 512 + UNDER_CUT = 1024 + CSV_SIMPLE = 2048 + PHOTO_BASE = 4096 ' Prodotto OmagPHOTO + TRF_IMPORT = 8192 + End Enum + + ' File di log generale + Public Const GENLOG_FILE_NAME As String = "OmagVIEWPlusLog#.txt" + + ' Sottodirettorio di configurazione + Public Const CONF_DIR As String = "Config" + ' Sottodirettorio temporaneo + Public Const TEMP_DIR As String = "Temp" + +End Module diff --git a/Constants/ConstIni.vb b/Constants/ConstIni.vb new file mode 100644 index 0000000..acddb29 --- /dev/null +++ b/Constants/ConstIni.vb @@ -0,0 +1,44 @@ +'---------------------------------------------------------------------------- +' EgalTech 2015-2015 +'---------------------------------------------------------------------------- +' File : ConstIni.vb Data : 12.02.15 Versione : 1.6b3 +' Contenuto : Modulo costanti sezione e chiavi per file Ini. +' +' +' +' Modifiche : 12.02.15 DS Creazione modulo. +' +' +'---------------------------------------------------------------------------- + +Module ConstIni + + Public Const INI_FILE_NAME As String = "OmagVIEWPlus.ini" + + Public Const S_GENERAL As String = "General" + Public Const K_DEBUG As String = "Debug" + Public Const K_LICENCE As String = "Licence" + Public Const K_USERLEVEL As String = "UserLevel" + Public Const K_MAXINST As String = "MaxInstances" + Public Const K_INSTANCES As String = "Instances" + Public Const K_COMMANDLOG As String = "CommandLog" + Public Const K_MESSAGESDIR As String = "MessagesDir" + Public Const K_MESSAGES As String = "Messages" + Public Const K_WINPLACE As String = "WinPlace" + Public Const K_SUPPORT As String = "Support" + + Public Const S_LANGUAGES As String = "Languages" + Public Const K_LANGUAGE As String = "Language" + + Public Const S_NUMERICALCONTROL As String = "NumericalControl" + Public Const K_TYPE As String = "Type" + Public Const K_IP As String = "Ip" + Public Const K_RACK As String = "Rack" + Public Const K_SLOT As String = "Slot" + Public Const K_TIMERINTERVAL As String = "TimerInterval" + + Public Const S_VARIABLES As String = "Variables" + Public Const K_ACTIVEWAREHOUSE As String = "ActiveWarehouse" + + +End Module diff --git a/Constants/ConstMsg.vb b/Constants/ConstMsg.vb new file mode 100644 index 0000000..f039130 --- /dev/null +++ b/Constants/ConstMsg.vb @@ -0,0 +1,53 @@ +Module ConstMsg + + Public Const MSG_SETUPERRORS As Integer = 5000 + 1470 + + Public Const MSG_MISSINGKEYWD As Integer = 10100 + Public Const MSG_NUMERICKEYBOARDWD As Integer = 10200 + Public Const MSG_MESSAGEBOX As Integer = 15000 + + Public Const MSG_OMAGCUT As Integer = 90000 + Public Const MSG_GENERAL As Integer = MSG_OMAGCUT + Public Const MSG_WORKINPROGRESSPAGEUC As Integer = MSG_OMAGCUT + 100 + Public Const MSG_DIRECTCUTPAGEUC As Integer = MSG_OMAGCUT + 200 + Public Const MSG_MANUALAXESMOVEPAGEUC As Integer = MSG_OMAGCUT + 220 + Public Const MSG_CADCUTPAGEUC As Integer = MSG_OMAGCUT + 300 + Public Const MSG_NESTPAGEUC As Integer = MSG_OMAGCUT + 330 + Public Const MSG_SPLITPAGEUC As Integer = MSG_OMAGCUT + 340 + Public Const MSG_MOVERAWPAGEUC As Integer = MSG_OMAGCUT + 360 + Public Const MSG_DRAWPAGEUC As Integer = MSG_OMAGCUT + 380 + Public Const MSG_COMPONENTPAGEUC As Integer = MSG_OMAGCUT + 400 + Public Const MSG_IMPORTPAGEUC As Integer = MSG_OMAGCUT + 450 + Public Const MSG_OPENPAGEUC As Integer = MSG_OMAGCUT + 490 + Public Const MSG_RAWPARTPAGEUC As Integer = MSG_OMAGCUT + 500 + Public Const MSG_CHOOSEMACHININGPAGEUC As Integer = MSG_OMAGCUT + 535 + Public Const MSG_SIMULATIONPAGEUC As Integer = MSG_OMAGCUT + 550 + Public Const MSG_FRAMECUTPAGEUC As Integer = MSG_OMAGCUT + 600 + Public Const MSG_MACHINEPAGEUC As Integer = MSG_OMAGCUT + 700 + Public Const MSG_TOOLSDBPAGEUC As Integer = MSG_OMAGCUT + 720 + Public Const MSG_MACHININGSDBPAGEUC As Integer = MSG_OMAGCUT + 760 + Public Const MSG_COMBOBOXPARAM As Integer = MSG_OMAGCUT + 800 + Public Const MSG_ALARMSPAGEUC As Integer = MSG_OMAGCUT + 900 + Public Const MSG_MACHINECNPAGEUC As Integer = MSG_OMAGCUT + 950 + Public Const MSG_OPTIONSPAGEUC As Integer = MSG_OMAGCUT + 980 + Public Const MSG_EGTMSGBOX As Integer = MSG_OMAGCUT + 1100 + Public Const MSG_CSVPAGEUC As Integer = MSG_OMAGCUT + 1200 + + Public Const MSG_OMAGOFFICE As Integer = 91400 + Public Const MSG_OPTIONPANEL As Integer = MSG_OMAGOFFICE + Public Const MSG_MYMACHININGDBWINDOW As Integer = MSG_OMAGOFFICE + 50 + Public Const MSG_TOPCMDBAR As Integer = MSG_OMAGOFFICE + 100 + Public Const MSG_RAWPARTTAB As Integer = MSG_OMAGOFFICE + 150 + Public Const MSG_VEINMATCHING As Integer = MSG_OMAGOFFICE + 200 + Public Const MSG_GENERIC As Integer = MSG_OMAGOFFICE + 250 + + Public Const MSG_EGTWPFLIB5 As Integer = 30000 + Public Const MSG_TOPCOMMANDBAR As Integer = MSG_EGTWPFLIB5 + 500 + Public Const MSG_GRIDVIEWPANEL As Integer = MSG_EGTWPFLIB5 + 800 + Public Const MSG_TOOLDB As Integer = MSG_EGTWPFLIB5 + 1000 + Public Const MSG_TOOLDBERRORS As Integer = MSG_EGTWPFLIB5 + 1100 + Public Const MSG_MACHININGDB As Integer = MSG_EGTWPFLIB5 + 1200 + Public Const MSG_MACHININGDBERRORS As Integer = MSG_EGTWPFLIB5 + 1400 + Public Const MSG_SIMULATION As Integer = MSG_EGTWPFLIB5 + 1600 + +End Module diff --git a/MainWindow/MainWindowM.vb b/MainWindow/MainWindowM.vb new file mode 100644 index 0000000..4fcec4d --- /dev/null +++ b/MainWindow/MainWindowM.vb @@ -0,0 +1,252 @@ +Imports System.Threading +Imports System.Math +Imports EgtUILib +Imports EgtWPFLib5 + +Public Class MainWindowM + +#Region "FIELDS" + + Private m_sDataRoot As String = String.Empty + Friend ReadOnly Property sDataRoot As String + Get + Return m_sDataRoot + End Get + End Property + + Private m_sConfigDir As String = String.Empty + Public ReadOnly Property sConfigDir As String + Get + Return m_sConfigDir + End Get + End Property + + Private m_nDebug As Integer = 0 + + Private m_objMutex As Mutex + + Private m_bFirstInstance As Boolean = False + Friend ReadOnly Property bFirstInstance As Boolean + Get + Return m_bFirstInstance + End Get + End Property + + Private m_nInstance As Integer = 0 + Friend ReadOnly Property nInstance As Integer + Get + Return m_nInstance + End Get + End Property + + Private m_nUserLevel As Integer = 1 + Friend ReadOnly Property nUserLevel As Integer + Get + Return m_nUserLevel + End Get + End Property + + Private m_nKeyLevel As Integer = 0 + Friend ReadOnly Property nKeyLevel As Integer + Get + Return m_nKeyLevel + End Get + End Property + + Private m_nKeyOptions As UInteger = 0 + Friend ReadOnly Property nKeyOptions As Integer + Get + Return m_nKeyOptions + End Get + End Property + + Friend ReadOnly Property sVersion As String + Get + Return My.Application.Info.Version.Major.ToString() & "." & + My.Application.Info.Version.Minor.ToString() & + (ChrW(97 - 1 + My.Application.Info.Version.Build)).ToString() & + My.Application.Info.Version.Revision.ToString() + End Get + End Property + + Private m_sTempDir As String + Friend ReadOnly Property sTempDir As String + Get + Return m_sTempDir + End Get + End Property + Private m_sLogFile As String + Friend ReadOnly Property sLogFile As String + Get + Return m_sLogFile + End Get + End Property + +#End Region ' FIELDS + +#Region "CONSTRUCTOR" + + Sub New() + InitializeEgtEnvironment() + End Sub + +#End Region ' CONSTRUCTOR + +#Region "METHODS" + + Private Sub InitializeEgtEnvironment() + ' Impostazione path radice per i dati + m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory + If EgtUILib.GetPrivateProfileString(S_DATA, K_DATAROOT, "", m_sDataRoot, m_sDataRoot & "\" & DAT_FILE_NAME) = 0 Then + m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory + End If + ' Impostazione direttorio di configurazione + m_sConfigDir = m_sDataRoot & "\" & CONF_DIR + ' Impostazione direttorio per file temporanei + m_sTempDir = m_sDataRoot & "\" & TEMP_DIR + ' Impostazione path Ini file + IniFile.m_sIniFile = m_sConfigDir & "\" & INI_FILE_NAME + ' Verifico indice di istanza + ManageInstance() + ' Imposto tipo di chiave + EgtSetLockType(KEY_TYPE.HW) + ' Leggo e imposto chiave di protezione + Dim sLicFileName As String = String.Empty + GetMainPrivateProfileString(S_GENERAL, K_LICENCE, LIC_FILE_NAME, sLicFileName) + Dim sLicFile As String = m_sConfigDir & "\" & sLicFileName + Dim sKey As String = String.Empty + EgtUILib.GetPrivateProfileString(S_LICENCE, K_KEY, "", sKey, sLicFile) + EgtSetKey(sKey) + ' Recupero livello e opzioni della chiave + Dim bKey As Boolean = EgtGetKeyLevel(9423, 19, 1, m_nKeyLevel) And + EgtGetKeyOptions(9423, 19, 1, m_nKeyOptions) + ' Verifico abilitazione prodotto + Dim bProd As Boolean = GetKeyOption(KEY_OPT.MAN_MANIP) And GetKeyOption(KEY_OPT.AUTO_MANIP) And GetKeyOption(KEY_OPT.PROCUCTION_LINE) + ' Inizializzazione generale di EgtInterface + m_nDebug = GetMainPrivateProfileInt(S_GENERAL, K_DEBUG, 0) + m_sLogFile = m_sTempDir & "\" & GENLOG_FILE_NAME.Replace("#", m_nInstance.ToString()) + Dim sLogMsg As String = "User " & Environment.MachineName & "\" & Environment.UserName & " (" & m_nInstance.ToString() & ")" & vbLf & + My.Application.Info.Title.ToString() & " ver. " & + My.Application.Info.Version.Major.ToString() & + "." & My.Application.Info.Version.Minor.ToString() & + (ChrW(97 - 1 + My.Application.Info.Version.Build)).ToString() & + My.Application.Info.Version.Revision.ToString() + EgtInit(m_nDebug, m_sLogFile, sLogMsg) + EgtSetTempDir(m_sTempDir) + EgtSetIniFile(IniFile.m_sIniFile) + ' Leggo direttorio dei messaggi (se manca uso direttorio di configurazione) + Dim sMsgDir As String = String.Empty + If GetMainPrivateProfileString(S_GENERAL, K_MESSAGESDIR, "", sMsgDir) = 0 Then + sMsgDir = m_sConfigDir + End If + ' Leggo lingua corrente + Dim sLanguage As String = String.Empty + GetMainPrivateProfileString(S_GENERAL, K_MESSAGES, "", sLanguage) + ' Recupero nome file dei messaggi della lingua corrente + Dim sMsgName As String = "EgalTechIta.txt" + Dim nIndex As Integer = 1 + While True + Dim ReadLanguage As Language = GetMainPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex) + If IsNothing(ReadLanguage) Then Exit While + If String.Compare(ReadLanguage.Name, sLanguage, True) = 0 Then + sMsgName = ReadLanguage.FilePath + Exit While + End If + nIndex += 1 + End While + If Not bKey Then + MessageBox.Show("Missing Protection Key. Insert Dongle and restart the program", "Error", MessageBoxButton.OK, MessageBoxImage.Error) + 'End + End If + If Not bProd Then + MessageBox.Show("Program without licence. Load Licence and restart the program.", "Error", MessageBoxButton.OK, MessageBoxImage.Error) + 'End + End If + ' Leggo file messaggi + Dim sMsgFilePath As String = sMsgDir & "\" & sMsgName + If Not EgtLoadMessages(sMsgFilePath) Then + EgtOutLog("Error in EgtLoadMessages") + End If + ' Leggo e imposto livello utilizzatore + m_nUserLevel = Math.Min(m_nKeyLevel, GetMainPrivateProfileInt(S_GENERAL, K_USERLEVEL, 1)) + ' Info su opzioni chiave + EgtOutLog("KeyOptions : " & bKey.ToString() & " " & m_nKeyOptions.ToString() & " " & bProd.ToString()) + End Sub + + Private Sub ManageInstance() + Dim bCreated As Boolean + Try + m_objMutex = New Mutex(False, "Global\OmagVIEWPlus", bCreated) + Catch + bCreated = False + End Try + m_bFirstInstance = bCreated + If bCreated Then + ' Prima istanza + m_nInstance = 1 + ' Aggiorno stato istanze attive + WriteMainPrivateProfileString(S_GENERAL, K_INSTANCES, m_nInstance.ToString()) + Else + ' Leggo il massimo numero di istanze ammesse + Const MAX_INST As Integer = 32 + Dim nMaxInst As Integer = GetMainPrivateProfileInt(S_GENERAL, K_MAXINST, 1) + nMaxInst = Max(1, Min(nMaxInst, MAX_INST)) + ' Cerco il primo indice di istanza libero + Dim nTmp As Integer = GetMainPrivateProfileInt(S_GENERAL, K_INSTANCES, 0) + m_nInstance = 1 + Dim nMask As Integer = 1 + While (nTmp And nMask) <> 0 And m_nInstance < MAX_INST + m_nInstance += 1 + nMask *= 2 + End While + ' Se l'indice supera il massimo + If m_nInstance > nMaxInst Then + ' porto in primo piano la prima istanza + Dim bFound As Boolean = False + ' processi del programma a 32 bit + Dim localProc As Process() = Process.GetProcessesByName("OmagVIEWPlusR32") + For Each p As Process In localProc + If p.Id <> Process.GetCurrentProcess().Id Then + bFound = True + ShowWindow(p.MainWindowHandle, 1) + Exit For + End If + Next + ' se non trovati processi a 32 bit provo a 64 bit + If Not bFound Then + localProc = Process.GetProcessesByName("OmagVIEWPlusR64") + For Each p As Process In localProc + If p.Id <> Process.GetCurrentProcess().Id Then + bFound = True + ShowWindow(p.MainWindowHandle, SW.RESTORE) + Exit For + End If + Next + End If + ' esco dal programma + End + End If + ' Aggiorno stato istanze attive + nTmp += (1 << (m_nInstance - 1)) + WriteMainPrivateProfileString(S_GENERAL, K_INSTANCES, nTmp.ToString()) + End If + End Sub + + Friend Function GetKeyOption(nKeyOpt As KEY_OPT) As Boolean + Return ((m_nKeyOptions And nKeyOpt) <> 0) + End Function + + Friend Sub Close() + ' Terminazione generale di EgtInterface + EgtExit() + ' Rilascio mutex + If Not IsNothing(m_objMutex) Then m_objMutex.Close() + ' Aggiorno istanze usate + Dim nTmp As Integer = GetMainPrivateProfileInt(S_GENERAL, K_INSTANCES, 0) + nTmp -= (1 << (m_nInstance - 1)) + WriteMainPrivateProfileString(S_GENERAL, K_INSTANCES, nTmp.ToString()) + End Sub + +#End Region ' METHODS + +End Class diff --git a/MainWindow/MainWindowV.xaml b/MainWindow/MainWindowV.xaml new file mode 100644 index 0000000..99c706d --- /dev/null +++ b/MainWindow/MainWindowV.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/MainWindow/MainWindowV.xaml.vb b/MainWindow/MainWindowV.xaml.vb new file mode 100644 index 0000000..35d4e68 --- /dev/null +++ b/MainWindow/MainWindowV.xaml.vb @@ -0,0 +1,38 @@ +Imports EgtWPFLib5 + +Class MainWindowV + + Private m_MainWindowVM As MainWindowVM + +#Region "CONSTRUCTOR" + + Sub New() + ' Funzione che interpreta l'xaml + InitializeComponent() + ' Assegno al riferimento locale al VM il VM preso dal DataContext + m_MainWindowVM = DirectCast(Me.DataContext, MainWindowVM) + End Sub + +#End Region ' CONSTRUCTOR + +#Region "EVENTS" + + Private Sub MainWindowV_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded + ' Carico e imposto posizione finestra + WinPosFromIniToWindow(S_GENERAL, K_WINPLACE, Me) + End Sub + + Private Sub MainWindowV_ContentRendered(sender As Object, e As EventArgs) Handles Me.ContentRendered + m_MainWindowVM.ContentRendered() + End Sub + + Private Sub MainWindowV_Unloaded(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Me.Closing + ' Salvo posizione finestra (se non minimizzata) + If WindowState <> WindowState.Minimized Then + WinPosFromWindowToIni(Me, S_GENERAL, K_WINPLACE) + End If + End Sub + +#End Region ' EVENTS + +End Class diff --git a/MainWindow/MainWindowVM.vb b/MainWindow/MainWindowVM.vb new file mode 100644 index 0000000..79d7fcd --- /dev/null +++ b/MainWindow/MainWindowVM.vb @@ -0,0 +1,123 @@ +Imports EgtUILib +Imports EgtWPFLib5 +Imports System.IO + +Public Class MainWindowVM + Inherits VMBase + + ' Riferimento al Model della MainWindow + Private m_MainWindowM As MainWindowM + Friend ReadOnly Property MainWindowM As MainWindowM + Get + Return m_MainWindowM + End Get + End Property + + ' Dichiarazione della classe di connessione al PLC + Friend m_CNCommunication As NCCommunication + + ' Variabile che indica che il programma è stato avviato correttamente (sia la mappa che l'ambiente Egt) + Private m_bInitStatus As Boolean + Friend ReadOnly Property bInitStatus As Boolean + Get + Return m_bInitStatus + End Get + End Property + + ' Titolo + Private m_Title As String + Public Property Title As String + Get + Return m_Title + End Get + Set(value As String) + m_Title = value + NotifyPropertyChanged("Title") + End Set + End Property + + ' definizione comandi + Private m_cmdAboutBox As ICommand + Private m_cmdCloseApplication As ICommand + +#Region "CONSTRUCTOR" + + Sub New() + ' Avvio l'inizializzazione della mappa passandogli il riferimento al MainWindowVM + Map.BeginInit(Me) + ' Creo Model della MainWindow + m_MainWindowM = New MainWindowM + End Sub + +#End Region ' CONSTRUCTOR + +#Region "METHODS" + + Friend Sub SetTitle(sTitle As String) + m_Title = sTitle + NotifyPropertyChanged("Title") + End Sub + + Friend Sub ContentRendered() + ' Verifico che l'inizializzazione di tutte le parti del programma sia andata a buon fine + If Map.EndInit() Then + m_bInitStatus = True + ' altrimenti chiudo il programma + Else + m_bInitStatus = False + End If + ' Creazione gestore comunicazione con PLC + m_CNCommunication = New NCCommunication + SetTitle("OmagVIEWPlus") + End Sub + +#End Region ' METHODS + +#Region "COMMANDS" + +#Region "AboutBoxCommand" + + ' Returns a command that manage the MainWindow_Unloaded command + Public ReadOnly Property AboutBoxCommand() As ICommand + Get + If m_cmdAboutBox Is Nothing Then + m_cmdAboutBox = New Command(AddressOf AboutBox) + End If + Return m_cmdAboutBox + End Get + End Property + + ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. + Public Sub AboutBox(ByVal param As Object) + 'Dim AboutBoxWindow As New AboutBoxV + 'AboutBoxWindow.Owner = Application.Current.MainWindow + 'AboutBoxWindow.ShowDialog() + End Sub + +#End Region ' AboutBoxCommand + +#Region "CloseApplicationCommand" + + ' Returns a command that manage the MainWindow_Unloaded command + Public ReadOnly Property CloseApplicationCommand() As ICommand + Get + If m_cmdCloseApplication Is Nothing Then + m_cmdCloseApplication = New Command(AddressOf CloseApplication) + End If + Return m_cmdCloseApplication + End Get + End Property + + ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. + Public Sub CloseApplication(ByVal param As Object) + ' Termino il Model + m_MainWindowM.Close() + ' Termino il programma + Application.Current.Shutdown() + End Sub + +#End Region ' CloseApplicationCommand + +#End Region ' COMMANDS + +End Class diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb new file mode 100644 index 0000000..d209cd9 --- /dev/null +++ b/My Project/AssemblyInfo.vb @@ -0,0 +1,74 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices +Imports System.Globalization +Imports System.Resources +Imports System.Windows + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + +' Review the values of the assembly attributes + +#If PLATFORM = "x64" Then +#If DEBUG Then + + +#Else + + +#End if +#Else +#If DEBUG Then + + +#Else + + +#End If +#End If + + + + + + +'In order to begin building localizable applications, set +'CultureYouAreCodingWith in your .vbproj file +'inside a . For example, if you are using US english +'in your source files, set the to "en-US". Then uncomment the +'NeutralResourceLanguage attribute below. Update the "en-US" in the line +'below to match the UICulture setting in the project file. + +' + + +'The ThemeInfo attribute describes where any theme specific and generic resource dictionaries can be found. +'1st parameter: where theme specific resource dictionaries are located +'(used if a resource is not found in the page, +' or application resource dictionaries) + +'2nd parameter: where the generic resource dictionary is located +'(used if a resource is not found in the page, +'app, and any theme specific resource dictionaries) + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' + + + diff --git a/My Project/MyExtensions/MyWpfExtension.vb b/My Project/MyExtensions/MyWpfExtension.vb new file mode 100644 index 0000000..2f5639e --- /dev/null +++ b/My Project/MyExtensions/MyWpfExtension.vb @@ -0,0 +1,121 @@ +#If _MyType <> "Empty" Then + +Namespace My + ''' + ''' Module used to define the properties that are available in the My Namespace for WPF + ''' + ''' + _ + Module MyWpfExtension + Private s_Computer As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Devices.Computer) + Private s_User As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.ApplicationServices.User) + Private s_Windows As New ThreadSafeObjectProvider(Of MyWindows) + Private s_Log As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Logging.Log) + ''' + ''' Returns the application object for the running application + ''' + _ + Friend ReadOnly Property Application() As Application + Get + Return CType(Global.System.Windows.Application.Current, Application) + End Get + End Property + ''' + ''' Returns information about the host computer. + ''' + _ + Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.Computer + Get + Return s_Computer.GetInstance() + End Get + End Property + ''' + ''' Returns information for the current user. If you wish to run the application with the current + ''' Windows user credentials, call My.User.InitializeWithWindowsUser(). + ''' + _ + Friend ReadOnly Property User() As Global.Microsoft.VisualBasic.ApplicationServices.User + Get + Return s_User.GetInstance() + End Get + End Property + ''' + ''' Returns the application log. The listeners can be configured by the application's configuration file. + ''' + _ + Friend ReadOnly Property Log() As Global.Microsoft.VisualBasic.Logging.Log + Get + Return s_Log.GetInstance() + End Get + End Property + + ''' + ''' Returns the collection of Windows defined in the project. + ''' + _ + Friend ReadOnly Property Windows() As MyWindows + _ + Get + Return s_Windows.GetInstance() + End Get + End Property + _ + _ + Friend NotInheritable Class MyWindows + _ + Private Shared Function Create__Instance__(Of T As {New, Global.System.Windows.Window})(ByVal Instance As T) As T + If Instance Is Nothing Then + If s_WindowBeingCreated IsNot Nothing Then + If s_WindowBeingCreated.ContainsKey(GetType(T)) = True Then + Throw New Global.System.InvalidOperationException("The window cannot be accessed via My.Windows from the Window constructor.") + End If + Else + s_WindowBeingCreated = New Global.System.Collections.Hashtable() + End If + s_WindowBeingCreated.Add(GetType(T), Nothing) + Return New T() + s_WindowBeingCreated.Remove(GetType(T)) + Else + Return Instance + End If + End Function + _ + _ + Private Sub Dispose__Instance__(Of T As Global.System.Windows.Window)(ByRef instance As T) + instance = Nothing + End Sub + _ + _ + Public Sub New() + MyBase.New() + End Sub + Private Shared s_WindowBeingCreated As Global.System.Collections.Hashtable + Public Overrides Function Equals(ByVal o As Object) As Boolean + Return MyBase.Equals(o) + End Function + Public Overrides Function GetHashCode() As Integer + Return MyBase.GetHashCode + End Function + _ + _ + Friend Overloads Function [GetType]() As Global.System.Type + Return GetType(MyWindows) + End Function + Public Overrides Function ToString() As String + Return MyBase.ToString + End Function + End Class + End Module +End Namespace +Partial Class Application + Inherits Global.System.Windows.Application + _ + _ + Friend ReadOnly Property Info() As Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo + _ + Get + Return New Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo(Global.System.Reflection.Assembly.GetExecutingAssembly()) + End Get + End Property +End Class +#End If \ No newline at end of file diff --git a/My Project/Resources.Designer.vb b/My Project/Resources.Designer.vb new file mode 100644 index 0000000..44192d8 --- /dev/null +++ b/My Project/Resources.Designer.vb @@ -0,0 +1,63 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("OmagVIEWPlus.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/My Project/Resources.resx b/My Project/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/My Project/Settings.Designer.vb b/My Project/Settings.Designer.vb new file mode 100644 index 0000000..e9d8ca5 --- /dev/null +++ b/My Project/Settings.Designer.vb @@ -0,0 +1,71 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + + + _ +Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property +End Class + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.OmagVIEWPlus.MySettings + Get + Return Global.OmagVIEWPlus.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/My Project/Settings.settings b/My Project/Settings.settings new file mode 100644 index 0000000..2b428d2 --- /dev/null +++ b/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/NCCommunication/NCCommunication.vb b/NCCommunication/NCCommunication.vb new file mode 100644 index 0000000..443adc0 --- /dev/null +++ b/NCCommunication/NCCommunication.vb @@ -0,0 +1,323 @@ +Imports System.Windows.Threading +Imports EgtWPFLib5 +Imports Sharp7 + +Public Class NCCommunication + + Public Enum Types As Integer + ' BIT = 0 + ' WORD = 1 + INT = 2 + ' DWORD = 3 + DINT = 4 + REAL = 5 + ' STRING_ = 6 + ' CHAR_ARRAY = 7 + End Enum + + Public Enum Connection_States As Integer + DEBUG = 0 + SIEMENS = 3 + End Enum + + Private m_bFirst As Boolean = True + + ' Timer + Private m_TimerIsBusy As Boolean = False + Private m_RefreshTimer As New DispatcherTimer + + Private m_NC As Nc_Parent = Nothing + Private Connection_State As Connection_States = Connection_States.DEBUG + + Private Sub ShowResult(ByVal Result As Integer) + ' This function returns a textual explaination of the error code + 'TextError.Text = Client.ErrorText(Result) + End Sub + + Public Sub New() + ' lettura tipo di PLC + Dim nType As Integer = GetMainPrivateProfileInt(S_NUMERICALCONTROL, K_TYPE, 0) + Select Case nType + Case Connection_States.DEBUG + Connection_State = Connection_States.DEBUG + Case Connection_States.SIEMENS + ' creazione classe Siemens + m_NC = New Nc_Siemens + ' connessione + Dim bOk As Boolean = m_NC.InitConnection() + If bOk Then + Connection_State = Connection_States.SIEMENS + Else + Connection_State = Connection_States.DEBUG + MessageBox.Show("Impossible connect to the PLC.") + End If + Case Else + Connection_State = Connection_States.DEBUG + End Select + If Connection_State = Connection_States.DEBUG Then + m_NC = New Nc_Debug + End If + ' lancio il timer di aggiornamento dell'interfaccia + 'AddHandler m_RefreshTimer.Tick, AddressOf RefreshTimer_Tick + 'm_RefreshTimer.Interval = TimeSpan.FromMilliseconds(GetMainPrivateProfileInt(S_NUMERICALCONTROL, K_TIMERINTERVAL, 1000)) + 'm_RefreshTimer.Start() + ' Eseguo subito la prima lettura variabili + Refresh() + End Sub + + Private Sub RefreshTimer_Tick() + If Not m_TimerIsBusy Then + m_TimerIsBusy = True + m_RefreshTimer.Stop() + Refresh() + m_TimerIsBusy = False + m_RefreshTimer.Start() + End If + End Sub + + Private Sub Refresh() + 'Dim n1Value As Integer = 0 + 'Dim x As Boolean = m_NC.ReadInt(81, 0, n1Value) + 'Dim y As Boolean = m_NC.WriteInt(81, 0, 547) + ''Dim nValue As Integer = 0 + ''ReadInt32(81, 0, nValue) + 'Dim dValue As Double = 0 + 'm_NC.ReadReal(81, 2, dValue) + + 'Dim dVal As Double = 0 + 'Dim z As Boolean = m_NC.ReadReal(81, 2, dVal) + 'Dim e As Boolean = m_NC.WriteReal(81, 2, 635.8736) + 'Dim b As Boolean = False + 'x = TryCast(m_NC, Nc_Siemens).ReadBool(81, 6, b) + 'x = TryCast(m_NC, Nc_Siemens).WriteBool(81, 6, True) + 'Dim s As String = "" + 'x = TryCast(m_NC, Nc_Siemens).ReadString(81, 8, 6, s) + 'x = TryCast(m_NC, Nc_Siemens).WriteString(81, 8, "tres") + + + + + Dim nValue As Integer = 0 + Dim nValue2 As Integer = 0 + ' Leggo magazzino attivo + Dim ActiveStorage As Warehouses = Warehouses.A + If ReadInt("ActiveStorage", nValue) Then + If nValue >= 0 OrElse nValue < 3 Then ActiveStorage = DirectCast(nValue, Warehouses) + Map.refUnloadingAreaVM.SetActiveWarehouse(ActiveStorage) + End If + ' Calcolo magazzino non attivo + Dim NotActiveStorage As Warehouses = If(ActiveStorage = Warehouses.A, Warehouses.B, Warehouses.A) + ' Leggo box attivo + Dim ActiveBox As Integer = 0 + If ReadInt("ActiveBox", nValue) Then + If nValue >= 0 OrElse nValue <= 6 Then ActiveBox = nValue + Map.refUnloadingAreaVM.SetBoxIsActive(ActiveBox) + End If + If m_bFirst Then + ' Leggo se primo magazzino è pallet o rack + Dim Storage1_IsPallet As Boolean = True + If ReadInt("Storage1_IsPallet", nValue) Then + Storage1_IsPallet = (nValue <> 0) + Map.refUnloadingAreaVM.SetWarehouse_IsPallet(Warehouses.A, Storage1_IsPallet) + End If + ' Leggo se secondo magazzino è pallet o rack + Dim Storage2_IsPallet As Boolean = True + If ReadInt("Storage2_IsPallet", nValue) Then + Storage2_IsPallet = (nValue <> 0) + Map.refUnloadingAreaVM.SetWarehouse_IsPallet(Warehouses.B, Storage2_IsPallet) + End If + Else + 'Verifico se magazzino attivo + If ActiveStorage <> 0 Then + ' Leggo se magazzino attivo è pallet o rack + Dim Storage_IsPallet As Boolean = True + If ReadInt("Storage" & ActiveStorage & "_IsPallet", nValue) Then + Storage_IsPallet = (nValue <> 0) + Map.refUnloadingAreaVM.SetWarehouse_IsPallet(ActiveStorage, Storage_IsPallet) + End If + ' Scrivo se magazzino non attivo è pallet o rack + Storage_IsPallet = True + WriteInt("WStorage" & NotActiveStorage & "_IsPallet", If(Map.refUnloadingAreaVM.WarehouseList(NotActiveStorage - 1).IsPallet, 1, 0)) + ' Non c'è magazzino attivo + Else + WriteInt("WStorage1_IsPallet", If(Map.refUnloadingAreaVM.WarehouseList(Warehouses.A - 1).IsPallet, 1, 0)) + WriteInt("WStorage2_IsPallet", If(Map.refUnloadingAreaVM.WarehouseList(Warehouses.B - 1).IsPallet, 1, 0)) + End If + End If + ' Leggo stato primo magazzino + Dim Storage1_Stato As States = States.NOT_AVAILABLE + If ReadInt("Storage1_Stato", nValue) Then + If nValue >= 0 OrElse nValue <= 3 Then Storage1_Stato = DirectCast(nValue, States) + Map.refUnloadingAreaVM.WarehouseList(0).SetState(Storage1_Stato) + End If + ' Leggo stato secondo magazzino + Dim Storage2_Stato As States = States.NOT_AVAILABLE + If ReadInt("Storage2_Stato", nValue) Then + If nValue >= 0 OrElse nValue <= 3 Then Storage2_Stato = DirectCast(nValue, States) + Map.refUnloadingAreaVM.WarehouseList(1).SetState(Storage2_Stato) + End If + If m_bFirst Then + ' Leggo stati pallet/rack di entrambi i magazzini + Dim StorageX_BoxX_Stato As States = States.NOT_AVAILABLE + For StorageX As Integer = 1 To 2 + Dim MaxBoxX As Integer = If(Map.refUnloadingAreaVM.WarehouseList(StorageX - 1).IsPallet, 6, 3) + For BoxX As Integer = 1 To MaxBoxX + StorageX_BoxX_Stato = States.NOT_AVAILABLE + If ReadInt("Storage" & StorageX & "_Box" & BoxX & "_Stato", nValue) Then + If nValue >= 0 OrElse nValue <= 3 Then StorageX_BoxX_Stato = DirectCast(nValue, States) + Map.refUnloadingAreaVM.SetBoxState(If(StorageX = 1, Warehouses.A, Warehouses.B), BoxX, StorageX_BoxX_Stato) + End If + Next + Next + Else + 'Verifico se magazzino attivo + If ActiveStorage <> 0 Then + ' Leggo stati del magazzino attivo + Dim StorageX_BoxX_Stato As States = States.NOT_AVAILABLE + Dim MaxBoxX As Integer = If(Map.refUnloadingAreaVM.WarehouseList(ActiveStorage - 1).IsPallet, 6, 3) + For BoxX As Integer = 1 To MaxBoxX + StorageX_BoxX_Stato = States.NOT_AVAILABLE + If ReadInt("Storage" & ActiveStorage & "_Box" & BoxX & "_Stato", nValue) Then + If nValue >= 0 OrElse nValue <= 3 Then StorageX_BoxX_Stato = DirectCast(nValue, States) + Map.refUnloadingAreaVM.SetBoxState(If(ActiveStorage = 1, Warehouses.A, Warehouses.B), BoxX, StorageX_BoxX_Stato) + End If + Next + ' Scrivo stati del magazzino non attivo + MaxBoxX = If(Map.refUnloadingAreaVM.WarehouseList(NotActiveStorage - 1).IsPallet, 6, 3) + For BoxX As Integer = 1 To MaxBoxX + Dim nState As Integer = Map.refUnloadingAreaVM.WarehouseList(NotActiveStorage - 1).Boxes(BoxX - 1).State + WriteInt("WStorage" & NotActiveStorage & "_Box" & BoxX & "_Stato", nState) + Next + ' Non c'è magazzino attivo + Else + For StorageX As Integer = 1 To 2 + Dim MaxBoxX As Integer = If(Map.refUnloadingAreaVM.WarehouseList(StorageX - 1).IsPallet, 6, 3) + For BoxX As Integer = 1 To MaxBoxX + Dim nState As Integer = Map.refUnloadingAreaVM.WarehouseList(StorageX - 1).Boxes(BoxX - 1).State + WriteInt("WStorage" & StorageX & "_Box" & BoxX & "_Stato", nState) + Next + Next + End If + + End If + ' Leggo numero massimo righe e colonne + Dim MaxNRighe As Integer = 0 + Dim MaxNColonne As Integer = 0 + If ReadInt("MaxNRighe", nValue) AndAlso ReadInt("MaxNColonne", nValue2) Then + If nValue >= 0 Then MaxNRighe = nValue + If nValue2 >= 0 Then MaxNColonne = nValue2 + Map.refUnloadingAreaVM.MaxFillActiveBox(MaxNRighe, MaxNColonne) + End If + ' Leggo numero riga e colonna corrente su box attivo + Dim ActBox_Livello As Integer = 0 + Dim ActBox_Riga As Integer = 0 + If ReadInt("ActBox_Livello", nValue) AndAlso ReadInt("ActBox_Riga", nValue2) Then + If nValue >= 0 Then ActBox_Livello = nValue + If nValue2 >= 0 Then ActBox_Riga = nValue2 + Map.refUnloadingAreaVM.FillActiveBox(ActBox_Livello, ActBox_Riga) + End If + ' Leggo contatore 1 + Dim Table1Counter As Integer = 0 + If ReadInt("Table1Counter", nValue) Then + If nValue >= 0 Then Table1Counter = nValue + Map.refUnloadingAreaVM.SetTable1Counter(Table1Counter) + End If + ' Leggo contatore 2 + Dim Table2Counter As Integer = 0 + If ReadInt("Table2Counter", nValue) Then + If nValue >= 0 Then Table2Counter = nValue + Map.refUnloadingAreaVM.SetTable2Counter(Table2Counter) + End If + ' Leggo riga corrente tavolo 1 + Dim Table1CurrRow As Integer = 0 + Dim Table1NRow As Integer = 0 + If ReadInt("Table1CurrRow", nValue) AndAlso ReadInt("Table1NRow", nValue2) Then + If nValue >= 0 Then Table1CurrRow = nValue + If nValue2 >= 0 Then Table1NRow = nValue2 + Map.refUnloadingAreaVM.SetTable1Percentage(Table1CurrRow, Table1NRow) + End If + ' Leggo tipo di piastrella + Dim TipoPiastrella As Integer = 0 + If ReadInt("TipoPiastrella", nValue) Then + If nValue >= 1 OrElse nValue <= 5 Then TipoPiastrella = nValue + 'Map.refUnloadingAreaVM.SetBoxIsActive(TipoPiastrella) + End If + ' Leggo spessore + Dim DimensioneZ As Integer = 0 + If ReadInt("DimensioneZ", nValue) Then + If nValue >= 0 Then DimensioneZ = nValue + 'Map.refUnloadingAreaVM.SetBoxIsActive(TipoPiastrella) + End If + ' Leggo ultima lastra + Dim UltimaLastra As Integer = 0 + If ReadInt("UltimaLastra", nValue) Then + If nValue >= 0 Then UltimaLastra = nValue + 'Map.refUnloadingAreaVM.SetBoxIsActive(TipoPiastrella) + End If + ' se Debug, incremento tempo + If Connection_State = Connection_States.DEBUG Then TryCast(m_NC, Nc_Debug).IncrementTime() + + m_bFirst = False + End Sub + + Private Function ReadInt(sVarName As String, ByRef nValue As Integer) As Boolean + Dim bok As Boolean = True + Dim sVar As String = String.Empty + ' Lettura variabile + If GetMainPrivateProfileString(S_VARIABLES, sVarName, "", sVar) > 0 Then + ' Spezzatura nei componenti + Dim sVarSplit() As String = sVar.Split(","c) + If sVarSplit.Length = 3 Then + ' elimino spazi + For Each Var In sVarSplit + Var = Var.Trim + Next + Dim nType As Integer = 0 + Dim Type As Types = 0 + Integer.TryParse(sVarSplit(2), nType) + If nType >= 0 AndAlso nType <= 7 Then Type = DirectCast(nType, Types) + If Type = 2 Then + Dim DbNumber As Integer = 0 + Dim Start As Integer = 0 + Integer.TryParse(sVarSplit(0), DbNumber) + Integer.TryParse(sVarSplit(1), Start) + If m_NC.ReadInt(DbNumber, Start, nValue) Then + Return True + End If + End If + End If + End If + Return False + End Function + + Private Function WriteInt(sVarName As String, nValue As Integer) As Boolean + Dim bok As Boolean = True + Dim sVar As String = String.Empty + ' Lettura variabile + If GetMainPrivateProfileString(S_VARIABLES, sVarName, "", sVar) > 0 Then + ' Spezzatura nei componenti + Dim sVarSplit() As String = sVar.Split(","c) + If sVarSplit.Length = 3 Then + ' elimino spazi + For Each Var In sVarSplit + Var = Var.Trim + Next + Dim nType As Integer = 0 + Dim Type As Types = 0 + Integer.TryParse(sVarSplit(2), nType) + If nType >= 0 AndAlso nType <= 7 Then Type = DirectCast(nType, Types) + If Type = 2 Then + Dim DbNumber As Integer = 0 + Dim Start As Integer = 0 + Integer.TryParse(sVarSplit(0), DbNumber) + Integer.TryParse(sVarSplit(1), Start) + If m_NC.WriteInt(DbNumber, Start, nValue) Then + Return True + End If + End If + End If + End If + Return False + End Function + +End Class diff --git a/NCCommunication/Nc_Debug.vb b/NCCommunication/Nc_Debug.vb new file mode 100644 index 0000000..13490cb --- /dev/null +++ b/NCCommunication/Nc_Debug.vb @@ -0,0 +1,56 @@ +Imports EgtUILib +Imports EgtWPFLib5 + +Public Class Nc_Debug + Inherits Nc_Parent + + Private m_sDebugFilePath As String = Map.refMainWindowVM.MainWindowM.sConfigDir & "\Nc_Debug.ini" + Private m_nTime As Integer = 1 + + Private IntBuffer As Integer = 0 + Private DoubleBuffer As Double = 0 + Private StringBuffer As String ' Buffer + + Friend Overrides Function InitConnection() As Boolean + Return True + End Function + + Friend Overrides Sub CloseConnection() + End Sub + + Friend Overrides Function ReadInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean + Value = GetPrivateProfileInt(m_nTime.ToString, DBNumber & "." & Start, 0, m_sDebugFilePath) + Return True + End Function + + Friend Overrides Function WriteInt(DBNumber As Integer, Start As Integer, Value As Int16) As Boolean + Return WritePrivateProfileString(m_nTime.ToString, DBNumber & "." & Start, Value.ToString, m_sDebugFilePath) + End Function + + Friend Overrides Function ReadDInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean + Value = GetPrivateProfileInt(m_nTime.ToString, DBNumber & "." & Start, 0, m_sDebugFilePath) + Return True + End Function + + Friend Overrides Function WriteDInt(DBNumber As Integer, Start As Integer, Value As Integer) As Boolean + Return WritePrivateProfileString(m_nTime.ToString, DBNumber & "." & Start, Value.ToString, m_sDebugFilePath) + End Function + + Friend Overrides Function ReadReal(DBNumber As Integer, Start As Integer, ByRef Value As Double) As Boolean + Value = GetPrivateProfileDouble(m_nTime.ToString, DBNumber & "." & Start, 0, m_sDebugFilePath) + Return True + End Function + + Friend Overrides Function WriteReal(DBNumber As Integer, Start As Integer, Value As Single) As Boolean + Return WritePrivateProfileString(m_nTime.ToString, DBNumber & "." & Start, DoubleToString(Value, 3), m_sDebugFilePath) + End Function + + Friend Sub SetTime(nTime As Integer) + m_nTime = nTime + End Sub + + Friend Sub IncrementTime() + m_nTime += 1 + End Sub + +End Class diff --git a/NCCommunication/Nc_Parent.vb b/NCCommunication/Nc_Parent.vb new file mode 100644 index 0000000..5f7b5b3 --- /dev/null +++ b/NCCommunication/Nc_Parent.vb @@ -0,0 +1,19 @@ +Public MustInherit Class Nc_Parent + + Friend MustOverride Function InitConnection() As Boolean + + Friend MustOverride Sub CloseConnection() + + Friend MustOverride Function ReadInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean + + Friend MustOverride Function WriteInt(DBNumber As Integer, Start As Integer, Value As Int16) As Boolean + + Friend MustOverride Function ReadDInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean + + Friend MustOverride Function WriteDInt(DBNumber As Integer, Start As Integer, Value As Integer) As Boolean + + Friend MustOverride Function ReadReal(DBNumber As Integer, Start As Integer, ByRef Value As Double) As Boolean + + Friend MustOverride Function WriteReal(DBNumber As Integer, Start As Integer, Value As Single) As Boolean + +End Class diff --git a/NCCommunication/Nc_Siemens.vb b/NCCommunication/Nc_Siemens.vb new file mode 100644 index 0000000..55c6f68 --- /dev/null +++ b/NCCommunication/Nc_Siemens.vb @@ -0,0 +1,120 @@ +Imports EgtWPFLib5 +Imports Sharp7 + +Public Class Nc_Siemens + Inherits Nc_Parent + + Private IntBuffer() As Byte = {0, 0} + Private BoolBuffer() As Byte = {0} + Private DIntBuffer() As Byte = {0, 0, 0, 0} + Private RealBuffer() As Byte = {0, 0, 0, 0} + Private StringBuffer(65536) As Byte ' Buffer + Private Client As New S7Client ' Client Object + + Friend Overrides Function InitConnection() As Boolean + Dim Result As Integer + Dim sIp As String = "" + GetMainPrivateProfileString(S_NUMERICALCONTROL, K_IP, "", sIp) + Dim nRack As Integer = GetMainPrivateProfileInt(S_NUMERICALCONTROL, K_RACK, 0) + Dim nSlot As Integer = GetMainPrivateProfileInt(S_NUMERICALCONTROL, K_SLOT, 0) + Result = Client.ConnectTo(sIp, nRack, nSlot) + Return Result = 0 + End Function + + Friend Overrides Sub CloseConnection() + Client.Disconnect() + End Sub + + Friend Overrides Function ReadInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean + ' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer. + Dim Result As Integer = Client.DBRead(DBNumber, Start, 2, IntBuffer) ' DbNumber, Start, Amount, Buffer + If Result = 0 Then + Value = S7.GetIntAt(IntBuffer, 0) + Return True + End If + Return False + End Function + + Friend Overrides Function WriteInt(DBNumber As Integer, Start As Integer, Value As Int16) As Boolean + S7.SetIntAt(IntBuffer, 0, Value) + ' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer. + Dim Result As Integer = Client.DBWrite(DBNumber, Start, 2, IntBuffer) ' DbNumber, Start, Amount, Buffer + Return Result = 0 + End Function + + Friend Function ReadBool(DBNumber As Integer, Start As Integer, ByRef Value As Boolean) As Boolean + ' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer. + Dim Result As Integer = Client.DBRead(DBNumber, Start, 1, BoolBuffer) ' DbNumber, Start, Amount, Buffer + If Result = 0 Then + Value = BitConverter.ToBoolean(BoolBuffer, 0) + Return True + End If + Return False + End Function + + Friend Function WriteBool(DBNumber As Integer, Start As Integer, Value As Boolean) As Boolean + If Value Then + BoolBuffer(0) = &H1 + Else + BoolBuffer(0) = &H0 + End If + ' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer. + Dim Result As Integer = Client.DBWrite(DBNumber, Start, 1, BoolBuffer) ' DbNumber, Start, Amount, Buffer + Return Result = 0 + End Function + + Friend Overrides Function ReadDInt(DBNumber As Integer, Start As Integer, ByRef Value As Integer) As Boolean + ' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer. + Dim Result As Integer = Client.DBRead(DBNumber, Start, 4, DIntBuffer) ' DbNumber, Start, Amount, Buffer + If Result = 0 Then + Value = S7.GetDIntAt(DIntBuffer, 0) + Return True + End If + Return False + End Function + + Friend Overrides Function WriteDInt(DBNumber As Integer, Start As Integer, Value As Integer) As Boolean + S7.SetDIntAt(DIntBuffer, 0, Value) + ' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer. + Dim Result As Integer = Client.DBWrite(DBNumber, Start, 4, DIntBuffer) ' DbNumber, Start, Amount, Buffer + Return Result = 0 + End Function + + Friend Overrides Function ReadReal(DBNumber As Integer, Start As Integer, ByRef Value As Double) As Boolean + ' Read 4 bytes from the DBNumber starting from Start and puts them into ReadBuffer. + Dim Result As Integer = Client.DBRead(DBNumber, Start, 4, RealBuffer) ' DbNumber, Start, Amount, Buffer + If Result = 0 Then + Value = S7.GetRealAt(RealBuffer, 0) + Return True + End If + Return False + End Function + + Friend Overrides Function WriteReal(DBNumber As Integer, Start As Integer, Value As Single) As Boolean + S7.SetRealAt(RealBuffer, 0, Value) + ' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer. + Dim Result As Integer = Client.DBWrite(DBNumber, Start, 4, RealBuffer) ' DbNumber, Start, Amount, Buffer + Return Result = 0 + End Function + + Friend Function ReadString(DBNumber As Integer, Start As Integer, Length As Integer, ByRef Value As String) As Boolean + ' Read 2 bytes from the DBNumber starting from Start and puts them into ReadBuffer. + Dim Result As Integer = Client.DBRead(DBNumber, Start, Length, StringBuffer) ' DbNumber, Start, Amount, Buffer + If Result = 0 Then + Value = S7.GetStringAt(StringBuffer, 0) + Return True + End If + Return False + End Function + + Friend Function WriteString(DBNumber As Integer, Start As Integer, Value As String) As Boolean + If Value.Length > 65535 Then + Return False + End If + S7.SetStringAt(StringBuffer, 0, 65535, Value) + ' Read "Size" bytes from the DB "DBNumber" starting from 0 and puts them into Buffer. + Dim Result As Integer = Client.DBWrite(DBNumber, Start, Value.Length + 2, StringBuffer) ' DbNumber, Start, Amount, Buffer + Return Result = 0 + End Function + +End Class diff --git a/OmagVIEWPlus.sln b/OmagVIEWPlus.sln new file mode 100644 index 0000000..b9a1a10 --- /dev/null +++ b/OmagVIEWPlus.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "OmagVIEWPlus", "OmagVIEWPlus.vbproj", "{14F465D6-9866-4DB4-AD9D-301B9E0C1338}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {14F465D6-9866-4DB4-AD9D-301B9E0C1338}.Debug|x86.ActiveCfg = Debug|x86 + {14F465D6-9866-4DB4-AD9D-301B9E0C1338}.Debug|x86.Build.0 = Debug|x86 + {14F465D6-9866-4DB4-AD9D-301B9E0C1338}.Release|x86.ActiveCfg = Release|x86 + {14F465D6-9866-4DB4-AD9D-301B9E0C1338}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/OmagVIEWPlus.vbproj b/OmagVIEWPlus.vbproj new file mode 100644 index 0000000..21fe4ad --- /dev/null +++ b/OmagVIEWPlus.vbproj @@ -0,0 +1,263 @@ + + + + + Debug + AnyCPU + {14F465D6-9866-4DB4-AD9D-301B9E0C1338} + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} + WinExe + OmagVIEWPlus + OmagVIEWPlus + v4.0 + Custom + Client + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + On + + + Binary + + + Off + + + On + + + bin\x64\Debug\ + + + true + + + None + x64 + MinimumRecommendedRules.ruleset + + + true + bin\x64\Release\ + + + true + + + pdbonly + x64 + MinimumRecommendedRules.ruleset + + + bin\x86\Debug\ + + + false + + + Full + x86 + MinimumRecommendedRules.ruleset + true + true + true + + + false + bin\x86\Release\ + + + true + + + None + x86 + MinimumRecommendedRules.ruleset + + + + ..\..\EgtProg\DllD32\EgtUILib.dll + + + ..\..\EgtProg\DllD32\EgtWPFLib5.dll + + + ..\..\EgtProg\OmagVIEWPlus\Sharp7.net.dll + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + Application.xaml + Code + + + + + + + + + UnloadingAreaV.xaml + + + + Dictionary.xaml + + + + + + + WarehouseV.xaml + + + + + + + + + + + + + + + + + + + + + + + + + + MainWindowV.xaml + + + + Code + + + Microsoft.VisualBasic.WPF.MyExtension + 1.0.0.0 + + + True + True + Resources.resx + + + True + Settings.settings + True + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + + + SettingsSingleFileGenerator + Settings.Designer.vb + + + + + + + + + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + + + + + + + + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 4.5 + true + + + + + + + + + + + + + + IF "$(PlatformName)"=="x86" IF "$(ConfigurationName)" == "Release" copy $(TargetPath) c:\EgtProg\OmagVIEWPlus\OmagVIEWPlusR32.exe +IF "$(PlatformName)"=="x86" IF "$(ConfigurationName)" == "Debug" copy $(TargetPath) c:\EgtProg\OmagVIEWPlus\OmagVIEWPlusD32.exe + + \ No newline at end of file diff --git a/Resources/LogoOmag.jpg b/Resources/LogoOmag.jpg new file mode 100644 index 0000000..394b443 Binary files /dev/null and b/Resources/LogoOmag.jpg differ diff --git a/Resources/Nastro.png b/Resources/Nastro.png new file mode 100644 index 0000000..308c43b Binary files /dev/null and b/Resources/Nastro.png differ diff --git a/Resources/OmagCUT.ico b/Resources/OmagCUT.ico new file mode 100644 index 0000000..cc99fc7 Binary files /dev/null and b/Resources/OmagCUT.ico differ diff --git a/Resources/Pallet.png b/Resources/Pallet.png new file mode 100644 index 0000000..2614b55 Binary files /dev/null and b/Resources/Pallet.png differ diff --git a/Resources/Rack.png b/Resources/Rack.png new file mode 100644 index 0000000..7e3af6c Binary files /dev/null and b/Resources/Rack.png differ diff --git a/Resources/Source/Pallet.svg b/Resources/Source/Pallet.svg new file mode 100644 index 0000000..97dcebe --- /dev/null +++ b/Resources/Source/Pallet.svg @@ -0,0 +1,124 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/Resources/Tavola1.png b/Resources/Tavola1.png new file mode 100644 index 0000000..0135184 Binary files /dev/null and b/Resources/Tavola1.png differ diff --git a/UnloadingArea/UnloadingAreaV.xaml b/UnloadingArea/UnloadingAreaV.xaml new file mode 100644 index 0000000..3ae232c --- /dev/null +++ b/UnloadingArea/UnloadingAreaV.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UnloadingArea/UnloadingAreaV.xaml.vb b/UnloadingArea/UnloadingAreaV.xaml.vb new file mode 100644 index 0000000..641b141 --- /dev/null +++ b/UnloadingArea/UnloadingAreaV.xaml.vb @@ -0,0 +1,3 @@ +Public Class UnloadingAreaV + +End Class diff --git a/UnloadingArea/UnloadingAreaVM.vb b/UnloadingArea/UnloadingAreaVM.vb new file mode 100644 index 0000000..dec8bd6 --- /dev/null +++ b/UnloadingArea/UnloadingAreaVM.vb @@ -0,0 +1,148 @@ +Imports System.Collections.ObjectModel +Imports EgtWPFLib5 + +Public Class UnloadingAreaVM + Inherits VMBase + + Private m_WarehouseList As New ObservableCollection(Of WarehouseVM) + Public ReadOnly Property WarehouseList As ObservableCollection(Of WarehouseVM) + Get + Return m_WarehouseList + End Get + End Property + + Private m_ActiveWarehouse As Warehouses + Public ReadOnly Property ActiveWarehouse As Warehouses + Get + Return m_ActiveWarehouse + End Get + End Property + + Private m_Table1CurrRow As Integer + Private m_Table1NRow As Integer + Public ReadOnly Property Table1Percentage As String + Get + Return DoubleToString(m_Table1CurrRow / m_Table1NRow * 100, 0) & "%" + End Get + End Property + + Private m_TileType As Integer + Public ReadOnly Property TileType As String + Get + Return m_TileType.ToString + End Get + End Property + Private m_Table1Counter As Integer + Public ReadOnly Property Table1Counter As String + Get + Return m_Table1Counter.ToString + End Get + End Property + Private m_Table2Counter As Integer + Public ReadOnly Property Table2Counter As String + Get + Return m_Table2Counter.ToString + End Get + End Property + Private m_TileThickness As Double + Public ReadOnly Property TileThickness As String + Get + Return LenToString(m_TileThickness, 1) + End Get + End Property + Private m_LastSlab As Boolean + Public ReadOnly Property LastSlab As Boolean + Get + Return m_LastSlab + End Get + End Property + +#Region "CONSTRUCTOR" + + Sub New() + ' Creo riferimento a questa classe in CompoWindowMap + Map.SetRefUnloadingAreaVM(Me) + m_WarehouseList.Add(New WarehouseVM(Warehouses.A)) + m_WarehouseList.Add(New WarehouseVM(Warehouses.B)) + End Sub + +#End Region ' CONSTRUCTOR + +#Region "METHODS" + + Friend Sub SetActiveWarehouse(ActiveWarehouse As Warehouses) + m_ActiveWarehouse = ActiveWarehouse + If ActiveWarehouse = Warehouses.A Then + m_WarehouseList(0).SetIsActive(True) + m_WarehouseList(1).SetIsActive(False) + ElseIf ActiveWarehouse = Warehouses.B Then + m_WarehouseList(0).SetIsActive(False) + m_WarehouseList(1).SetIsActive(True) + End If + 'If ActiveWarehouse <> m_ActiveWarehouse Then + ' m_ActiveWarehouse = ActiveWarehouse + ' For Each Warehouse In m_WarehouseList + ' Warehouse.SetState(If(Warehouse.Id = ActiveWarehouse, States.ACTIVE, States.FULL)) + ' Next + ' m_WarehouseList(ActiveWarehouse - 1).SetState(States.ACTIVE) + 'End If + End Sub + + Friend Sub SetWarehouse_IsPallet(Warehouse As Warehouses, IsPallet As Boolean) + m_WarehouseList(Warehouse - 1).SetIsPallet(IsPallet) + End Sub + + Friend Sub SetBoxIsActive(BoxId As Integer) + If Not m_ActiveWarehouse > 0 AndAlso m_ActiveWarehouse <= 2 Then + m_WarehouseList(Warehouses.A).SetBoxIsActive(0) + m_WarehouseList(Warehouses.A).SetBoxIsActive(0) + End If + m_WarehouseList(m_ActiveWarehouse - 1).SetBoxIsActive(BoxId) + End Sub + + Friend Sub SetBoxState(Warehouse As Warehouses, Id As Integer, State As States) + m_WarehouseList(Warehouse - 1).SetBoxState(Id, State) + End Sub + + Friend Sub FillActiveBox(Livello As Integer, Riga As Integer) + m_WarehouseList(m_ActiveWarehouse - 1).FillActiveBox(Livello, Riga) + End Sub + + Friend Sub MaxFillActiveBox(MaxLivello As Integer, MaxRiga As Integer) + m_WarehouseList(m_ActiveWarehouse - 1).MaxFillActiveBox(MaxLivello, MaxRiga) + End Sub + + Friend Sub SetTable1Counter(Table1Counter As Integer) + m_Table1Counter = Table1Counter + NotifyPropertyChanged("Table1Counter") + End Sub + + Friend Sub SetTable2Counter(Table2Counter As Integer) + m_Table2Counter = Table2Counter + NotifyPropertyChanged("Table2Counter") + End Sub + + Friend Sub SetTable1Percentage(Table1CurrRow As Integer, Table1NRow As Integer) + m_Table1CurrRow = Table1CurrRow + m_Table1NRow = Table1NRow + NotifyPropertyChanged("Table1Percentage") + End Sub + + Friend Sub SetTileType(TyleType As Integer) + m_TileType = TyleType + NotifyPropertyChanged("TileType") + End Sub + + Friend Sub SetTileThickness(TileThickness As Double) + m_TileThickness = TileThickness + NotifyPropertyChanged("TileThickness") + End Sub + + Friend Sub SetLastSlab(LastSlab As Boolean) + m_LastSlab = LastSlab + NotifyPropertyChanged("LastSlab") + End Sub + +#End Region ' METHODS + +End Class diff --git a/Utility/Dictionary.xaml b/Utility/Dictionary.xaml new file mode 100644 index 0000000..487c294 --- /dev/null +++ b/Utility/Dictionary.xaml @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Utility/Dictionary.xaml.vb b/Utility/Dictionary.xaml.vb new file mode 100644 index 0000000..0690f86 --- /dev/null +++ b/Utility/Dictionary.xaml.vb @@ -0,0 +1,30 @@ +Public Class Dictionary + + Public Shared ReadOnly MySceneHostVM As String = "MySceneHostVM" + +#Region "Colors" + + Private m_Omag_Red As SolidColorBrush = Brushes.Red + Public ReadOnly Property Omag_Red As SolidColorBrush + Get + Return m_Omag_Red + End Get + End Property + + Private Shared m_Button_Static_Background As SolidColorBrush = New BrushConverter().ConvertFrom("#FFDDDDDD") + Public Shared ReadOnly Property Button_Static_Background As SolidColorBrush + Get + Return m_Button_Static_Background + End Get + End Property + + Private Shared m_TabControl_Header_Background As LinearGradientBrush = Application.Current.FindResource("TabItem.Static.Background") + Public Shared ReadOnly Property TabControl_Header_Background As LinearGradientBrush + Get + Return m_TabControl_Header_Background + End Get + End Property + +#End Region ' Colors + +End Class diff --git a/Utility/Enums.vb b/Utility/Enums.vb new file mode 100644 index 0000000..d7a5806 --- /dev/null +++ b/Utility/Enums.vb @@ -0,0 +1,14 @@ +Public Module Enums + + Public Enum Warehouses As Integer + A = 1 + B = 2 + End Enum + + Public Enum States As Integer + NOT_AVAILABLE = 0 + AVAILABLE = 1 + FULL = 2 + End Enum + +End Module diff --git a/Utility/Map.vb b/Utility/Map.vb new file mode 100644 index 0000000..9dd361d --- /dev/null +++ b/Utility/Map.vb @@ -0,0 +1,51 @@ +Imports EgtWPFLib5 + +Module Map + + Private m_refMainWindowVM As MainWindowVM + Private m_refUnloadingAreaVM As UnloadingAreaVM + +#Region "Get" + + Public ReadOnly Property refMainWindowVM As MainWindowVM + Get + Return m_refMainWindowVM + End Get + End Property + + Public ReadOnly Property refUnloadingAreaVM As UnloadingAreaVM + Get + Return m_refUnloadingAreaVM + End Get + End Property + +#End Region ' Get + +#Region "Set" + + 'Friend Function SetRefStatusBarVM(StatusBarVM As StatusBarVM) As Boolean + ' LibMap.SetRefStatusBarVM(StatusBarVM) + ' Return Not IsNothing(LibMap.refStatusBarVM) + 'End Function + + Friend Function SetRefUnloadingAreaVM(UnloadingAreaVM As UnloadingAreaVM) As Boolean + m_refUnloadingAreaVM = UnloadingAreaVM + Return Not IsNothing(m_refUnloadingAreaVM) + End Function + +#End Region ' Set + +#Region "Init" + + Friend Function BeginInit(MainWindowVM As MainWindowVM) As Boolean + m_refMainWindowVM = MainWindowVM + Return Not IsNothing(m_refMainWindowVM) + End Function + Friend Function EndInit() As Boolean + ' Verifico se tutti i pezzi necessari sono stati caricati + Return Not IsNothing(m_refMainWindowVM) AndAlso Not IsNothing(m_refUnloadingAreaVM) ' AndAlso LibMap.EndInit() + End Function + +#End Region ' Init + +End Module diff --git a/Warehouse/Box.vb b/Warehouse/Box.vb new file mode 100644 index 0000000..fbbc3c8 --- /dev/null +++ b/Warehouse/Box.vb @@ -0,0 +1,133 @@ +Imports EgtWPFLib5 + +Public Class Box + Inherits VMBase + +#Region "FIELDS & PROPERTIES" + + Private m_refWarehouse As WarehouseVM + + Private m_Id As Integer + + Private m_State As States + Public ReadOnly Property State As States + Get + Return m_State + End Get + End Property + Public Property State_IsChecked As Boolean + Get + Return (m_State <> States.AVAILABLE) + End Get + Set(value As Boolean) + If value Then + m_State = States.NOT_AVAILABLE + Else + m_State = States.AVAILABLE + End If + End Set + End Property + + Private m_Livello As Integer + Private m_Fila As Integer + Private m_MaxLivello As Integer = 1 + Private m_MaxFila As Integer = 1 + + Private m_Warehouse_IsActive As Boolean + Private m_IsActive As Boolean = False + Friend ReadOnly Property IsActive As Boolean + Get + Return m_IsActive + End Get + End Property + + Private m_FillPercentage As Integer = 0 + Public ReadOnly Property nFillPercentage As Integer + Get + Return m_FillPercentage + End Get + End Property + Public ReadOnly Property FillPercentage As String + Get + Return If(m_State = States.NOT_AVAILABLE, "--", m_FillPercentage & " %") + End Get + End Property + + Private m_IsPallet As Boolean + Friend ReadOnly Property IsPallet As Boolean + Get + Return m_IsPallet + End Get + End Property + + Public ReadOnly Property Percentage_Visibility As Visibility + Get + Return If(m_Warehouse_IsActive, Visibility.Visible, Visibility.Collapsed) + End Get + End Property + + Public ReadOnly Property Image_Visibility As Visibility + Get + Return If(Not m_Warehouse_IsActive, Visibility.Visible, Visibility.Collapsed) + End Get + End Property + +#End Region ' FIELDS & PROPERTIES + +#Region "CONSTRUCTOR" + + Sub New(nId As Integer, bIsPallet As Boolean, Warehouse As WarehouseVM) + m_Id = nId + m_IsPallet = bIsPallet + m_refWarehouse = Warehouse + m_State = States.AVAILABLE + End Sub + +#End Region ' CONSTRUCTOR + +#Region "METHODS" + + Friend Sub SetState(State As States) + m_State = State + Select Case m_State + Case States.AVAILABLE, States.NOT_AVAILABLE + m_FillPercentage = 0 + Case States.FULL + m_FillPercentage = 100 + End Select + NotifyPropertyChanged("FillPercentage") + End Sub + + Friend Sub SetWarehouse_IsActive(bIsActive As Boolean) + m_Warehouse_IsActive = bIsActive + NotifyPropertyChanged("Percentage_Visibility") + NotifyPropertyChanged("Image_Visibility") + End Sub + + Friend Sub SetIsActive(IsActive As Boolean) + m_IsActive = IsActive + End Sub + + Friend Sub FillBox(Livello As Integer, Fila As Integer) + m_Livello = Livello + m_Fila = Fila + If m_MaxLivello = 0 OrElse m_MaxFila = 0 Then + m_FillPercentage = 0 + Else + m_FillPercentage = CInt(Math.Round((((m_Livello - 1) * m_MaxFila) + m_Fila) / (m_MaxLivello * m_MaxFila) * 100)) + End If + NotifyPropertyChanged("FillPercentage") + End Sub + + Friend Sub MaxFillBox(MaxLivello As Integer, MaxFila As Integer) + m_MaxLivello = MaxLivello + m_MaxFila = MaxFila + End Sub + +#End Region ' METHODS + +#Region "COMMANDS" + +#End Region ' COMMANDS + +End Class \ No newline at end of file diff --git a/Warehouse/WarehouseV.xaml b/Warehouse/WarehouseV.xaml new file mode 100644 index 0000000..37e6473 --- /dev/null +++ b/Warehouse/WarehouseV.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Warehouse/WarehouseV.xaml.vb b/Warehouse/WarehouseV.xaml.vb new file mode 100644 index 0000000..0974ea0 --- /dev/null +++ b/Warehouse/WarehouseV.xaml.vb @@ -0,0 +1,21 @@ +Public Class WarehouseV + +End Class + +Public Class BoxTemplateSelector + Inherits DataTemplateSelector + + Public Overrides Function SelectTemplate(item As Object, container As DependencyObject) As DataTemplate + Dim element As FrameworkElement = TryCast(container, FrameworkElement) + If element IsNot Nothing AndAlso item IsNot Nothing AndAlso TypeOf item Is Box Then + Dim Box As Box = TryCast(item, Box) + If Box.IsPallet Then + Return TryCast(element.FindResource("PalletTemplate"), DataTemplate) + Else + Return TryCast(element.FindResource("RackTemplate"), DataTemplate) + End If + End If + Return MyBase.SelectTemplate(item, container) + End Function + +End Class \ No newline at end of file diff --git a/Warehouse/WarehouseVM.vb b/Warehouse/WarehouseVM.vb new file mode 100644 index 0000000..7e6ac4d --- /dev/null +++ b/Warehouse/WarehouseVM.vb @@ -0,0 +1,187 @@ +Imports System.Collections.ObjectModel +Imports EgtUILib +Imports EgtWPFLib5 + +Public Class WarehouseVM + Inherits VMBase + +#Region "FIELDS & PROPERTIES" + + Private m_Id As Warehouses + Public ReadOnly Property Id As Warehouses + Get + Return m_Id + End Get + End Property + + Private m_State As States + Friend ReadOnly Property State As States + Get + Return m_State + End Get + End Property + + Private m_IsPallet As Boolean + Public Property IsPallet As Boolean + Get + Return m_IsPallet + End Get + Set(value As Boolean) + If value <> m_IsPallet Then + CreateBoxList(value) + m_IsPallet = value + End If + End Set + End Property + Public Property NotIsPallet As Boolean + Get + Return Not m_IsPallet + End Get + Set(value As Boolean) + If value = m_IsPallet Then + CreateBoxList(Not value) + m_IsPallet = Not value + End If + End Set + End Property + + Private m_IsActive As Boolean = True + Friend ReadOnly Property IsActive As Boolean + Get + Return m_IsActive + End Get + End Property + + Public ReadOnly Property IsEnabled As Boolean + Get + Return Not m_IsActive + End Get + End Property + + Private m_Boxes As New ObservableCollection(Of Box) + Public Property Boxes As ObservableCollection(Of Box) + Get + Return m_Boxes + End Get + Set(value As ObservableCollection(Of Box)) + m_Boxes = value + End Set + End Property + + Private m_ActiveBox_Index As Integer + Private m_ActiveBox As Box + + Public ReadOnly Property FillPercentage As String + Get + Dim Counter As Integer = 0 + Dim Fill As Integer = 0 + For Each Box In Boxes + If Box.State <> States.NOT_AVAILABLE Then + Counter += 1 + Fill += Box.nFillPercentage + End If + Next + Return DoubleToString(Fill / Counter, 0) & "%" + End Get + End Property + + Public ReadOnly Property FillPercentage_Visibility As Visibility + Get + Return If(m_IsActive, Visibility.Visible, Visibility.Collapsed) + End Get + End Property + +#End Region ' FIELDS & PROPERTIES + +#Region "CONSTRUCTOR" + + Sub New(nWarehouse As Warehouses) + m_Id = nWarehouse + NotifyPropertyChanged("Id") + ' valore da leggere da macchina + IsPallet = True + End Sub + +#End Region ' CONSTRUCTOR + +#Region "METHODS" + + Private Sub CreateBoxList(bIsPallet As Boolean) + m_Boxes.Clear() + ' aggiungo i box + Dim nBox As Integer = If(bIsPallet, 6, 3) + For Index = 1 To nBox + Boxes.Add(New Box(Index, bIsPallet, Me)) + Next + End Sub + + Friend Sub SetState(State As States) + m_State = State + End Sub + + Friend Sub SetIsActive(bIsActive As Boolean) + m_IsActive = bIsActive + For Index = 0 To m_Boxes.Count - 1 + m_Boxes(Index).SetWarehouse_IsActive(bIsActive) + Next + NotifyPropertyChanged("IsEnabled") + NotifyPropertyChanged("FillPercentage_Visibility") + End Sub + + Friend Sub SetIsPallet(IsPallet As Boolean) + Me.IsPallet = IsPallet + NotifyPropertyChanged("IsPallet") + NotifyPropertyChanged("NotIsPallet") + End Sub + + Friend Sub SetBoxState(Id As Integer, State As States) + m_Boxes(ConvertBoxIndex(Id) - 1).SetState(State) + End Sub + + Friend Sub SetBoxIsActive(Id As Integer) + If Id > 0 And Id <= 6 Then + m_ActiveBox_Index = Id - 1 + m_ActiveBox = Boxes(ConvertBoxIndex(Id) - 1) + End If + For Each Box In m_Boxes + Box.SetIsActive(Box Is m_ActiveBox) + Next + End Sub + + Friend Sub FillActiveBox(Livello As Integer, Fila As Integer) + m_ActiveBox.FillBox(Livello, Fila) + NotifyPropertyChanged("FillPercentage") + End Sub + + Friend Sub MaxFillActiveBox(MaxLivello As Integer, MaxFila As Integer) + m_ActiveBox.MaxFillBox(MaxLivello, MaxFila) + End Sub + + ' funzione che converte l'indice box che arriva dalla macchina nell'indice box della grafica + ' sono disposti diversamente! + Private Function ConvertBoxIndex(MachineIndex As Integer) As Integer + If IsPallet Then + Select Case MachineIndex + Case 1 + Return 4 + Case 2 + Return 1 + Case 3 + Return 5 + Case 4 + Return 2 + Case 5 + Return 6 + Case 6 + Return 3 + Case Else + Return 4 + End Select + Else + Return MachineIndex + End If + End Function + +#End Region + +End Class \ No newline at end of file