7e67f84aaa
- primo commit.
417 lines
18 KiB
VB.net
417 lines
18 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib
|
|
Imports System.ComponentModel
|
|
Imports System.Threading
|
|
Imports System.Windows.Threading
|
|
|
|
Class MainWindow
|
|
|
|
' Mutex per avere una sola istanza del programma in esecuzione
|
|
Private m_objMutex As New Mutex
|
|
Friend m_OptionsPageUC As OptionsPageUC
|
|
|
|
' Dichiarazione variabili direttori
|
|
Private m_sDataRoot As String = String.Empty
|
|
Private m_sConfigDir As String = String.Empty
|
|
Private m_sTempDir As String = String.Empty
|
|
Private m_sMachinesRoot As String = String.Empty
|
|
Private m_sIniFile As String = String.Empty
|
|
Private m_nDebug As Integer = 0
|
|
|
|
'Dichiarazione variabile contenente la lingua corrente
|
|
Friend m_CurrLanguage As Language
|
|
'Dichiarazione lista delle lingue disponibili e lingua corrente
|
|
Friend m_LanguagesList As New List(Of Language)
|
|
|
|
' Macchina corrente
|
|
Private m_sCurrMachine As String = String.Empty
|
|
|
|
' Opzioni abilitate dalla licenza attiva associata alla chiave
|
|
Private m_nKeyOptions As UInteger
|
|
Friend Enum KEY_OPT As UInteger
|
|
BASE = 1
|
|
MAN_MANIP = 2
|
|
AUTO_MANIP = 4
|
|
MAN_PHOTO = 8
|
|
AUTO_PHOTO = 16
|
|
AUTO_NESTING = 32
|
|
ENABLE_MILL = 64
|
|
PROCUCTION_LINE = 128
|
|
End Enum
|
|
|
|
' Dichiarazione Scene
|
|
Friend WithEvents CurrentProjectScene As New Scene
|
|
Private CurrentProjectSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
|
|
Private m_bFirst As Boolean = True
|
|
|
|
' Dichiarazione delle Page UserControl
|
|
Friend m_SceneButtons As SceneButtonsUC
|
|
|
|
' Timer per aggiornamento interfaccia
|
|
Private m_IdleTimer As New DispatcherTimer(DispatcherPriority.ApplicationIdle)
|
|
|
|
Public Function GetIniFile() As String
|
|
Return m_sIniFile
|
|
End Function
|
|
|
|
Public Function GetTempDir() As String
|
|
Return m_sTempDir
|
|
End Function
|
|
|
|
Public Function GetMachinesRootDir() As String
|
|
Return m_sMachinesRoot
|
|
End Function
|
|
|
|
Public Function GetCurrMachine() As String
|
|
Return m_sCurrMachine
|
|
End Function
|
|
|
|
Friend Function GetKeyOption(nKeyOpt As KEY_OPT) As Boolean
|
|
Return m_nKeyOptions And nKeyOpt
|
|
End Function
|
|
|
|
Friend Function GetKeyOptions() As UInteger
|
|
Return m_nKeyOptions
|
|
End Function
|
|
|
|
Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
|
|
' Verifico sia l'unica istanza
|
|
ManageSingleIstance()
|
|
' Impostazione path radice per i dati
|
|
m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory
|
|
If 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
|
|
m_sIniFile = m_sConfigDir & "\" & INI_FILE_NAME
|
|
' Impostazione direttorio per le macchine
|
|
If GetPrivateProfileString(S_MACH, K_MACHINESDIR, "", m_sMachinesRoot, m_sIniFile) = 0 Then
|
|
m_sMachinesRoot = m_sDataRoot & "\" & MACHINES_DFL_DIR
|
|
End If
|
|
' Recupero nome macchina corrente
|
|
GetPrivateProfileString(S_MACH, K_CURRMACH, "", m_sCurrMachine, m_sIniFile)
|
|
' Leggo e imposto chiave di protezione
|
|
Dim sLicFileName As String = String.Empty
|
|
GetPrivateProfileString(S_GENERAL, K_LICENCE, LIC_FILE_NAME, sLicFileName, m_sIniFile)
|
|
Dim sLicFile As String = m_sConfigDir & "\" & sLicFileName
|
|
Dim sKey As String = String.Empty
|
|
GetPrivateProfileString(S_LICENCE, K_KEY, "", sKey, sLicFile)
|
|
EgtSetKey(sKey)
|
|
' Inizializzazione generale di EgtInterface
|
|
m_nDebug = GetPrivateProfileInt(S_GENERAL, K_DEBUG, 0, m_sIniFile)
|
|
Dim sLogFile As String = m_sTempDir & "\" & GENLOG_FILE_NAME
|
|
Dim sLogMsg As String = My.Application.Info.Description.ToString() & " ver. " & My.Application.Info.Version.ToString()
|
|
EgtInit(m_nDebug, sLogFile, sLogMsg)
|
|
' Leggo direttorio dei messaggi (se manca uso direttorio di configurazione)
|
|
Dim sMsgDir As String = String.Empty
|
|
If GetPrivateProfileString(S_GENERAL, K_MESSAGESDIR, "", sMsgDir, m_sIniFile) = 0 Then
|
|
sMsgDir = m_sConfigDir
|
|
End If
|
|
' Leggo elenco lingue disponibili da file ini
|
|
Dim nIndex As Integer = 1
|
|
Dim ReadLanguage As Language = GetPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex, GetIniFile)
|
|
While Not IsNothing(ReadLanguage)
|
|
m_LanguagesList.Add(ReadLanguage)
|
|
nIndex += 1
|
|
ReadLanguage = GetPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex, GetIniFile)
|
|
End While
|
|
' Leggo file messaggi
|
|
Dim sMsgFile As String = String.Empty
|
|
GetPrivateProfileString(S_GENERAL, K_MESSAGES, "", sMsgFile, m_sIniFile)
|
|
For i As Integer = 0 To m_LanguagesList.Count - 1
|
|
If m_LanguagesList(i).LanguageName = sMsgFile Then
|
|
m_CurrLanguage = m_LanguagesList(i)
|
|
End If
|
|
Next
|
|
Dim sMsgFilePath As String = sMsgDir & "\EgalTechIta.txt"
|
|
If Not IsNothing(m_CurrLanguage) Then
|
|
sMsgFilePath = sMsgDir & "\" & m_CurrLanguage.FileName
|
|
End If
|
|
If Not EgtLoadMessages(sMsgFilePath) Then
|
|
EgtOutLog("Error in EgtLoadMessages")
|
|
End If
|
|
Dim sNfeDir As String = String.Empty
|
|
GetPrivateProfileString(S_GEOMDB, K_NFEFONTDIR, "", sNfeDir, m_sIniFile)
|
|
Dim sDefFont As String = String.Empty
|
|
GetPrivateProfileString(S_GEOMDB, K_DEFAULTFONT, "", sDefFont, m_sIniFile)
|
|
EgtSetFont(sNfeDir, sDefFont)
|
|
' Recupero opzioni della chiave
|
|
Dim bKey As Boolean = EgtGetKeyOptions(9423, 16, 1, m_nKeyOptions)
|
|
EgtOutLog("KeyOptions : " & bKey.ToString() & " " & m_nKeyOptions.ToString())
|
|
' Imposto dir di default per libreria Lua e lancio libreria di base
|
|
Dim sLuaLibsDir As String = String.Empty
|
|
GetPrivateProfileString(S_LUA, K_LIBSDIR, "", sLuaLibsDir, m_sIniFile)
|
|
EgtSetLuaLibs(sLuaLibsDir)
|
|
Dim sLuaBaseLib As String = String.Empty
|
|
GetPrivateProfileString(S_LUA, K_BASELIB, "EgtBase", sLuaBaseLib, m_sIniFile)
|
|
EgtLuaRequire(sLuaBaseLib)
|
|
' Imposto unità di misura per interfaccia utente
|
|
Dim bMM As Boolean = (GetPrivateProfileInt(S_GENERAL, K_MMUNITS, 1, m_sIniFile) <> 0)
|
|
EgtSetUiUnits(bMM)
|
|
' Imposto posizione e dimensioni della MainWindow
|
|
Dim nFlag As Integer
|
|
Dim nLeft As Integer
|
|
Dim nTop As Integer
|
|
Dim nWidth As Integer
|
|
Dim nHeight As Integer
|
|
GetPrivateProfileWinPos(S_GENERAL, K_WINPLACE, nFlag, nLeft, nTop, nWidth, nHeight, m_sIniFile)
|
|
Me.WindowStartupLocation = Windows.WindowStartupLocation.Manual
|
|
Me.Top = nTop
|
|
Me.Left = nLeft
|
|
Me.Height = nHeight
|
|
Me.Width = nWidth
|
|
WindowState = If(nFlag = 1, WindowState.Maximized, WindowState.Normal)
|
|
' Inizializzazione della libreria EgtWPFLib
|
|
EgtWPFInit()
|
|
' Creazione delle Page UserControl
|
|
m_OptionsPageUC = New OptionsPageUC
|
|
' Posizionemento nella griglia delle Page UserControl
|
|
m_OptionsPageUC.SetValue(Grid.ColumnProperty, 0)
|
|
m_OptionsPageUC.SetValue(Grid.RowProperty, 1)
|
|
' Disabilita la possibilità di imitare il click del tasto destro del mouse tenendo premuto il dito sul touch
|
|
' NB: Se abilitato impedisce di utilizzare lo stato Pressed dei Button che quindi non si evidenziano quando premuti
|
|
Stylus.SetIsPressAndHoldEnabled(Me, False)
|
|
|
|
'Assegnazione scena all'host e posizionamento nella PlacePageGrid
|
|
CurrentProjectSceneHost.Child = CurrentProjectScene
|
|
CurrentProjectSceneHost.SetValue(Grid.ColumnProperty, 1)
|
|
CurrentProjectSceneHost.SetValue(Grid.RowProperty, 1)
|
|
Me.SceneGrid.Children.Add(CurrentProjectSceneHost)
|
|
|
|
'Creazione delle Page UserControl
|
|
m_SceneButtons = New SceneButtonsUC
|
|
|
|
' Imposto OnIdle
|
|
AddHandler m_IdleTimer.Tick, AddressOf OnIdle
|
|
End Sub
|
|
|
|
Private Sub ManageSingleIstance()
|
|
Dim bCreated As Boolean
|
|
Try
|
|
m_objMutex = New Mutex(False, "Global\OmagView", bCreated)
|
|
Catch
|
|
bCreated = False
|
|
End Try
|
|
If Not bCreated 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("OmagViewR32")
|
|
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("OmagViewR64")
|
|
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
|
|
End Sub
|
|
|
|
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
|
|
' imposto colore di default
|
|
Dim DefColor As New Color3d(0, 0, 0)
|
|
GetPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor, GetIniFile())
|
|
CurrentProjectScene.SetDefaultMaterial(DefColor)
|
|
' imposto colori sfondo
|
|
Dim BackTopColor As New Color3d(211, 211, 211)
|
|
GetPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor, GetIniFile())
|
|
Dim BackBotColor As New Color3d(211, 211, 211)
|
|
GetPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor, GetIniFile())
|
|
CurrentProjectScene.SetViewBackground(BackTopColor, BackBotColor)
|
|
' imposto colore di evidenziazione
|
|
Dim MarkColor As New Color3d(255, 255, 0)
|
|
GetPrivateProfileColor(S_SCENE, K_MARK, MarkColor, GetIniFile())
|
|
CurrentProjectScene.SetMarkMaterial(MarkColor)
|
|
' imposto colore per superfici selezionate
|
|
Dim SelSurfColor As New Color3d(255, 255, 192)
|
|
GetPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor, GetIniFile())
|
|
CurrentProjectScene.SetSelSurfMaterial(SelSurfColor)
|
|
' imposto tipo e colore del rettangolo di zoom
|
|
Dim bOutline As Boolean = True
|
|
Dim ZwColor As New Color3d(0, 0, 0)
|
|
GetPrivateProfileZoomWin(S_SCENE, K_ZOOMWIN, bOutline, ZwColor, GetIniFile())
|
|
CurrentProjectScene.SetZoomWinAttribs(bOutline, ZwColor)
|
|
' imposto colore della linea di distanza
|
|
Dim DstLnColor As New Color3d(255, 0, 0)
|
|
GetPrivateProfileColor(S_SCENE, K_DISTLINE, DstLnColor, GetIniFile())
|
|
CurrentProjectScene.SetDistLineMaterial(DstLnColor)
|
|
' imposto parametri OpenGL
|
|
Dim nDriver As Integer = GetPrivateProfileInt(S_OPENGL, K_DRIVER, 3, GetIniFile())
|
|
Dim b2Buff As Boolean = (GetPrivateProfileInt(S_OPENGL, K_DOUBLEBUFFER, 1, GetIniFile()) <> 0)
|
|
Dim nColorBits As Integer = GetPrivateProfileInt(S_OPENGL, K_COLORBITS, 32, GetIniFile())
|
|
Dim nDepthBits As Integer = GetPrivateProfileInt(S_OPENGL, K_DEPTHBITS, 32, GetIniFile())
|
|
CurrentProjectScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
|
|
' inizializzo la scena (DB geometrico + visualizzazione) e verifico presenza chiave
|
|
If Not CurrentProjectScene.Init() Then
|
|
' Rimuovo l'host della scena perchè altrimenti rimarrebbe il buco!!
|
|
Me.SceneGrid.Children.Remove(CurrentProjectSceneHost)
|
|
Dim MissingKeyWnd As New EgtMsgBox(Me, EgtMsg(MSG_MISSINGKEYWD + 1), EgtMsg(MSG_MISSINGKEYWD + 2) & " " & EgtMsg(MSG_MISSINGKEYWD + 3), EgtMsgBox.Buttons.OK, EgtMsgBox.Icons.NULL)
|
|
Me.Close()
|
|
End If
|
|
' Inizializzo gestore lavorazioni
|
|
EgtInitMachMgr(GetMachinesRootDir())
|
|
m_bFirst = False
|
|
' Carico progetto in scarico
|
|
If Not LoadProject(m_sTempDir & "\CurrProj.nge") Then
|
|
NewProject()
|
|
End If
|
|
EgtZoom(ZM.ALL)
|
|
' inibisco selezione diretta da Scene
|
|
CurrentProjectScene.SetStatusNull()
|
|
'Posizionemento nella griglia delle Page UserControl
|
|
m_SceneButtons.SetValue(Grid.ColumnProperty, 1)
|
|
MainTabGrid.Children.Add(m_SceneButtons)
|
|
' Lancio timer per aggiornamento interfaccia
|
|
m_IdleTimer.Interval = TimeSpan.FromMilliseconds(100)
|
|
m_IdleTimer.Start()
|
|
End Sub
|
|
|
|
Private Sub OptionsBtn_Click(sender As Object, e As RoutedEventArgs) Handles OptionsBtn.Click
|
|
OptionsBtn.IsChecked = True
|
|
End Sub
|
|
|
|
Private Sub MainWindow_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseDown
|
|
End Sub
|
|
|
|
Private Sub MainWindow_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
|
|
'If (m_NumericKeyboardWD.IsVisible And e.Key = Key.Enter) Then
|
|
' m_NumericKeyboardWD.Visibility = Windows.Visibility.Hidden
|
|
'End If
|
|
End Sub
|
|
|
|
Private Sub OnMyMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles CurrentProjectScene.OnMouseDownScene
|
|
' Si può selezionare solo con il tasto sinistro e se stato NULL
|
|
If e.Button <> Windows.Forms.MouseButtons.Left Or
|
|
Not CurrentProjectScene.IsStatusNull() Then
|
|
Return
|
|
End If
|
|
' Identificativo del grezzo
|
|
Dim nRawId As Integer = EgtGetFirstRawPart()
|
|
' Verifico se selezionato indicativo di pezzo
|
|
EgtSetObjFilterForSelect(True, True, True, True, True)
|
|
Dim nSel As Integer
|
|
EgtSelect(e.Location, Scene.DIM_SEL, Scene.DIM_SEL, nSel)
|
|
Dim nId As Integer = EgtGetFirstObjInSelWin()
|
|
While nId <> GDB_ID.NULL
|
|
' Recupero l'identificativo del pezzo cui appartiene
|
|
Dim nPartId As Integer = EgtGetParent(EgtGetParent(nId))
|
|
Dim bPartInTable As Boolean = (EgtGetParent(nPartId) = nRawId)
|
|
If EgtIsPart(nPartId) Or bPartInTable Then
|
|
Dim nStat As Integer = GDB_ST.ON_
|
|
EgtGetStatus(nPartId, nStat)
|
|
' Se già selezionato deseleziono
|
|
If nStat = GDB_ST.SEL Then
|
|
EgtDeselectObj(nPartId)
|
|
Else
|
|
EgtDeselectAll()
|
|
EgtSelectObj(nPartId)
|
|
End If
|
|
EgtDraw()
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs)
|
|
' Uscita
|
|
MainWindow_Unloaded(sender, e)
|
|
Me.Close()
|
|
End Sub
|
|
|
|
Private Sub MainWindow_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
|
|
' Terminazione generale di EgtInterface
|
|
EgtExit()
|
|
' Rilascio mutex
|
|
m_objMutex.Close()
|
|
End Sub
|
|
|
|
Private Sub MainWindow_ContentRendered(sender As Object, e As EventArgs) Handles Me.ContentRendered
|
|
End Sub
|
|
|
|
Private Sub EgtWPFInit()
|
|
'EgtBasicInfo
|
|
EgtWPFLib.InitializeEgtWPFLib.EgtBasicInfo_Initialization("C:/EgtDev/OmagVIEW",
|
|
1280, 1024, 15, 12,
|
|
"/#Century Gothic",
|
|
"/gothic.ttf",
|
|
Application.Current.FindResource("FontSize_UpperCaseCharacter"),
|
|
Application.Current.FindResource("FontSize_LowerCaseCharacter"))
|
|
' EgtMessageBox
|
|
EgtWPFLib.InitializeEgtWPFLib.EgtMsgBox_Initialization(Application.Current.FindResource("OmagCut_WindowBorder"),
|
|
Application.Current.FindResource("OmagCut_WindowGrayTextButton"),
|
|
Nothing,
|
|
Application.Current.FindResource("FontSize_UpperCaseCharacter"),
|
|
Application.Current.FindResource("FontSize_LowerCaseCharacter"))
|
|
'Inizializzazione della libreria
|
|
EgtWPFLib.InitializeEgtWPFLib.EgtPaths_Initialization()
|
|
End Sub
|
|
|
|
' OnIdle
|
|
Private Sub OnIdle()
|
|
End Sub
|
|
|
|
' Evento che apre AboutBox quando viene clickato il logo
|
|
Private Sub LogoBrd_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles LogoBrd.MouseDown
|
|
Dim AboutBox As New AboutBoxWD(Me)
|
|
End Sub
|
|
|
|
Private Function LoadProject(ByVal sPath As String) As Boolean
|
|
' Carico il file
|
|
If Not EgtOpenFile(sPath) Then
|
|
Return False
|
|
End If
|
|
' Recupero il gruppo di lavoro del file
|
|
Dim nMachGrpId As Integer = EgtGetFirstMachGroup()
|
|
If nMachGrpId = GDB_ID.NULL Then
|
|
Return False
|
|
End If
|
|
' Carico il gruppo e verifico che la sua macchina sia quella corrente
|
|
Dim sFileMachine As String = String.Empty
|
|
If Not EgtSetCurrMachGroup(nMachGrpId) Then
|
|
EgtGetInfo(nMachGrpId, "Machine", sFileMachine)
|
|
Else
|
|
EgtGetCurrMachineName(sFileMachine)
|
|
End If
|
|
' Visualizzo solo la tavola della macchina
|
|
EgtShowOnlyTable(True)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function NewProject() As Boolean
|
|
' Imposto il nuovo progetto
|
|
EgtNewFile()
|
|
' Recupero nome macchina corrente
|
|
Dim sMachine As String = String.Empty
|
|
GetPrivateProfileString(S_MACH, K_CURRMACH, "", sMachine, m_sIniFile)
|
|
' Creo un gruppo di lavoro e carico la macchina corrente
|
|
If EgtAddMachGroup(MACH_GROUP, sMachine) = GDB_ID.NULL Then
|
|
Return False
|
|
End If
|
|
' Imposto la tavola corrente
|
|
If Not EgtSetTable(MAIN_TAB) Then
|
|
Return False
|
|
End If
|
|
EgtShowOnlyTable(True)
|
|
Return True
|
|
End Function
|
|
|
|
End Class |