38e8002865
- possibilità di confermare progetti senza pezzi.
768 lines
32 KiB
VB.net
768 lines
32 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
|
|
' Pagine e bottoni
|
|
Private m_OptionsPageUC As OptionsPageUC
|
|
Private m_SceneButtons As SceneButtonsUC
|
|
' 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_sProjDir As String = String.Empty
|
|
Private m_sIniFile As String = String.Empty
|
|
Private m_nDebug As Integer = 0
|
|
' Variabile con la lingua corrente
|
|
Friend m_CurrLanguage As Language
|
|
' 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
|
|
' Scene
|
|
Friend WithEvents CurrentProjectScene As New Scene
|
|
Private CurrentProjectSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
|
|
Friend m_nTopViewRotStep As Integer = 0
|
|
' Timer per aggiornamento interfaccia
|
|
Private m_IdleTimer As New DispatcherTimer(DispatcherPriority.ApplicationIdle)
|
|
' Lista dei pezzi attivi
|
|
Private m_vParts As New List(Of Integer)
|
|
|
|
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 GetProjectDir() As String
|
|
Return m_sProjDir
|
|
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)
|
|
' Impostazione direttorio per progetto corrente
|
|
If GetPrivateProfileString(S_GENERAL, K_PROJDIR, "", m_sProjDir, m_sIniFile) = 0 Then
|
|
m_sProjDir = m_sDataRoot & "\" & PROJ_DFL_DIR
|
|
End If
|
|
' Imposto tipo di chiave
|
|
EgtSetLockType(KEY_TYPE.ANY)
|
|
' 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()
|
|
' 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
|
|
' Messaggi sui bottoni
|
|
OkAllBtn.Content = EgtMsg(91301) 'Pezzi Tutti Validi
|
|
OkPartBtn.Content = EgtMsg(91302) 'Pezzo Valido
|
|
RuinedPartBtn.Content = EgtMsg(91303) 'Pezzo Rovinato
|
|
PrintBtn.Content = EgtMsg(91306) 'Stampa
|
|
LabelBtn.Content = EgtMsg(91304) 'Stampa Etichetta
|
|
ConfirmBtn.Content = EgtMsg(91305) 'Conferma
|
|
' Abilitazione stampa etichetta
|
|
LabelBtn.IsEnabled = False
|
|
' 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
|
|
' dimensione lineare max in pixel delle textures
|
|
Dim nTxrMaxLinPix As Integer = GetPrivateProfileInt(S_SCENE, K_TEXMAXLINPIX, 4096, GetIniFile())
|
|
EgtSetTextureMaxLinPixels(nTxrMaxLinPix)
|
|
' Leggo angolo rotazione vista top
|
|
m_nTopViewRotStep = GetPrivateProfileInt(S_SCENE, K_TOPVIEWROTSTEP, 0, GetIniFile())
|
|
' Inizializzo gestore lavorazioni
|
|
EgtInitMachMgr(GetMachinesRootDir())
|
|
' Carico progetto in scarico
|
|
If LoadProject() Then
|
|
' Se c'è file segnalazione nuovo lo trasformo in segnalazione bloccato
|
|
If My.Computer.FileSystem.FileExists(m_sProjDir & "\" & CURR_PROJ_NEW) Then
|
|
' Rinomino segnalazione nuovo in segnalazione blocco
|
|
My.Computer.FileSystem.MoveFile(m_sProjDir & "\" & CURR_PROJ_NEW, m_sProjDir & "\" & CURR_PROJ_LOCK, True)
|
|
End If
|
|
Else
|
|
NewProject()
|
|
End If
|
|
' Aggiorno la visualizzazione
|
|
EgtSetGenericView(0, (m_nTopViewRotStep - 1) * 90)
|
|
EgtZoom(ZM.ALL)
|
|
' Controllo abilitazione bottone conferma
|
|
UpdateConfirmBtn()
|
|
' 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 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
|
|
' 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))
|
|
' Verifico sia un pezzo attivo
|
|
Dim bIsPart As Boolean = (m_vParts.FindIndex(Function(x) x = nPartId) >= 0)
|
|
If bIsPart Then
|
|
Dim nStat As Integer = GDB_ST.ON_
|
|
EgtGetStatus(nPartId, nStat)
|
|
' Se già selezionato deseleziono
|
|
If nStat = GDB_ST.SEL Then
|
|
EgtDeselectObj(nPartId)
|
|
' Altrimenti seleziono
|
|
Else
|
|
EgtDeselectAll()
|
|
EgtSelectObj(nPartId)
|
|
End If
|
|
EgtDraw()
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub OkAllBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkAllBtn.Click
|
|
' Dichiaro validi tutti i pezzi
|
|
For Each nPartId As Integer In m_vParts
|
|
SetPartStatus(nPartId, True)
|
|
Next
|
|
' Aggiorno la visualizzazione
|
|
EgtDeselectAll()
|
|
EgtDraw()
|
|
' Controllo abilitazione bottone conferma
|
|
UpdateConfirmBtn()
|
|
End Sub
|
|
|
|
Private Sub OkPartBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkPartBtn.Click
|
|
If SetPartStatus(EgtGetFirstSelectedObj(), True) Then
|
|
' Aggiorno la visualizzazione
|
|
EgtDeselectAll()
|
|
EgtDraw()
|
|
' Controllo abilitazione bottone conferma
|
|
UpdateConfirmBtn()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub RuinedPartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RuinedPartBtn.Click
|
|
If SetPartStatus(EgtGetFirstSelectedObj(), False) Then
|
|
' Aggiorno la visualizzazione
|
|
EgtDeselectAll()
|
|
EgtDraw()
|
|
' Controllo abilitazione bottone conferma
|
|
UpdateConfirmBtn()
|
|
End If
|
|
End Sub
|
|
|
|
Private Function SetPartStatus(nPartId As Integer, bOk As Boolean) As Boolean
|
|
' Verifico esistenza
|
|
If nPartId = GDB_ID.NULL Then Return False
|
|
' Cerco layer regione
|
|
Dim nRegId = EgtGetFirstNameInGroup(nPartId, NAME_REGION)
|
|
If nRegId = GDB_ID.NULL Then Return False
|
|
' Cerco prima regione nel layer
|
|
Dim nId = EgtGetFirstInGroup(nRegId)
|
|
While nId <> GDB_ID.NULL
|
|
If EgtGetType(nId) = GDB_TY.SRF_FRGN Then
|
|
If bOk Then
|
|
EgtSetColor(nId, New Color3d(0, 255, 0, 80)) ' Verde
|
|
Else
|
|
EgtSetColor(nId, New Color3d(255, 0, 0, 80)) ' Rosso
|
|
End If
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNext(nId)
|
|
End While
|
|
' Se non trovato, errore
|
|
If nId = GDB_ID.NULL Then Return False
|
|
' Assegno stato a pezzo
|
|
EgtSetInfo(nPartId, INFO_PARTOK, If(bOk, "1", "0"))
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub PrintBtn_Click(sender As Object, e As RoutedEventArgs) Handles PrintBtn.Click
|
|
|
|
Dim printDlg As New PrintDialog
|
|
|
|
If printDlg.ShowDialog() Then
|
|
|
|
' Recupero le dimensioni dell'area di stampa
|
|
Dim dW As Double = printDlg.PrintableAreaWidth
|
|
Dim dH As Double = printDlg.PrintableAreaHeight
|
|
|
|
' Nascondo la tavola ed eseguo zoom su quello che rimane
|
|
Dim nTabId As Integer = EgtGetTableId(MAIN_TAB)
|
|
EgtSetStatus(nTabId, GDB_ST.OFF)
|
|
EgtZoom(ZM.ALL, False)
|
|
|
|
' Prendo l'immagine per la stampa
|
|
Dim colWhite As New Color3d(255, 255, 255)
|
|
Dim nImgW As Integer = 4000
|
|
Dim nImgH As Integer = 2400
|
|
Dim sPath As String = m_sTempDir & "\Image.png"
|
|
If Not EgtGetImage(SM.HIDDENLINE, colWhite, colWhite, nImgW, nImgH, sPath) Then
|
|
EgtOutLog("Errore creazione immagine di stampa")
|
|
Return
|
|
End If
|
|
|
|
' Ripristino la visualizzazione della tavola
|
|
EgtSetStatus(nTabId, GDB_ST.ON_)
|
|
EgtZoom(ZM.ALL)
|
|
Thread.Sleep(10)
|
|
|
|
Try
|
|
' Metodo complesso di stampa che permette di rilasciare il file :
|
|
' carico la bitmap e la metto in uno stream in memoria
|
|
Dim stream As System.IO.Stream = New System.IO.MemoryStream()
|
|
Dim bitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(sPath)
|
|
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
|
|
bitmap.Dispose()
|
|
' la sposto in una BitmapImage
|
|
Dim bitImage As New System.Windows.Media.Imaging.BitmapImage()
|
|
bitImage.BeginInit()
|
|
bitImage.StreamSource = stream
|
|
bitImage.EndInit()
|
|
' la sposto in un Visual Control
|
|
Dim tmpImg As New Image
|
|
tmpImg.BeginInit()
|
|
tmpImg.Source = bitImage
|
|
tmpImg.Margin = New Thickness(30)
|
|
' ruoto a seconda dell'aspetto della pagina
|
|
If (dH > dW And nImgH < nImgW) Or (dH < dW And nImgH > nImgW) Then
|
|
tmpImg.LayoutTransform = New RotateTransform(-90)
|
|
End If
|
|
tmpImg.EndInit()
|
|
' eseguo la stampa
|
|
printDlg.PrintVisual(tmpImg, "Parts Layout")
|
|
Catch
|
|
EgtOutLog("Errore esecuzione stampa")
|
|
End Try
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub UpdateConfirmBtn()
|
|
' Verifico che i pezzi siano stati tutti settati
|
|
Dim bConfirm As Boolean = True
|
|
For Each nPartId As Integer In m_vParts
|
|
If Not EgtExistsInfo(nPartId, INFO_PARTOK) Then
|
|
bConfirm = False
|
|
End If
|
|
Next
|
|
' Aggiorno stato bottone
|
|
ConfirmBtn.IsEnabled = bConfirm
|
|
' Verifico se già data conferma
|
|
Dim bDone As Boolean = False
|
|
If bConfirm Then bDone = Not My.Computer.FileSystem.FileExists(m_sProjDir & "\" & CURR_PROJ_LOCK)
|
|
UpdateBackgroundConfirmBtn(bDone)
|
|
End Sub
|
|
|
|
Private Sub UpdateBackgroundConfirmBtn(bDone As Boolean)
|
|
If bDone Then
|
|
ConfirmBtn.Background = Brushes.LightGreen
|
|
Else
|
|
ConfirmBtn.Background = Brushes.LightGray
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ConfirmBtn_Click(sender As Object, e As RoutedEventArgs) Handles ConfirmBtn.Click
|
|
' Se esiste file di lock
|
|
If My.Computer.FileSystem.FileExists(m_sProjDir & "\" & CURR_PROJ_LOCK) Then
|
|
' Emetto stato pezzi
|
|
If SavePartStatus() Then
|
|
' Rimuovo file di lock
|
|
My.Computer.FileSystem.DeleteFile(m_sProjDir & "\" & CURR_PROJ_LOCK)
|
|
' Aggiorno sfondo bottone
|
|
UpdateBackgroundConfirmBtn(True)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Function SavePartStatus() As Boolean
|
|
' Gestione file
|
|
Try
|
|
' Recupero materiale
|
|
Dim sMaterial As String = String.Empty
|
|
EgtGetInfo(EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_PROJMARK), INFO_PROJMAT, sMaterial)
|
|
' Recupero spessore
|
|
Dim nSolidRawId As Integer = EgtGetFirstNameInGroup(EgtGetFirstRawPart(), NAME_RAW_SOLID)
|
|
Dim b3RawBox As New BBox3d
|
|
EgtGetBBoxGlob(nSolidRawId, GDB_BB.STANDARD, b3RawBox)
|
|
Dim dThick As Double = If(b3RawBox.IsEmpty(), 0, b3RawBox.DimZ())
|
|
' Recupero path originale di carico
|
|
Dim sCutPath As String = String.Empty
|
|
EgtGetInfo(EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_PROJMARK), INFO_LOADPATH, sCutPath)
|
|
' Apro i file
|
|
Dim RuinedWrt As New IO.StreamWriter(m_sProjDir & "\" & CURR_PROJ_EPL, False)
|
|
Dim ProdWrt As New IO.StreamWriter(m_sProjDir & "\" & CURR_PROJ_PPL, False)
|
|
' Intestazioni
|
|
RuinedWrt.WriteLine("[General]")
|
|
If String.IsNullOrEmpty(sCutPath) Then
|
|
RuinedWrt.WriteLine("Path=*RuinedParts*")
|
|
Else
|
|
RuinedWrt.WriteLine("Path=" & sCutPath)
|
|
End If
|
|
ProdWrt.WriteLine("[General]")
|
|
If String.IsNullOrEmpty(sCutPath) Then
|
|
ProdWrt.WriteLine("Path=*ProducedParts*")
|
|
Else
|
|
ProdWrt.WriteLine("Path=" & sCutPath)
|
|
End If
|
|
' Ciclo sui pezzi
|
|
Dim nI As Integer = 0
|
|
Dim nJ As Integer = 0
|
|
For Each nPartId As Integer In m_vParts
|
|
Dim nOk As Integer = 1
|
|
If EgtGetInfo(nPartId, INFO_PARTOK, nOk) And nOk = 0 Then
|
|
nI += 1
|
|
RuinedWrt.WriteLine("[P" & nI.ToString() & "]")
|
|
Dim sName As String = String.Empty
|
|
EgtGetInfo(nPartId, INFO_CSV_PART, sName)
|
|
RuinedWrt.WriteLine("Nam=" & sName)
|
|
RuinedWrt.WriteLine("Mat=" & sMaterial)
|
|
RuinedWrt.WriteLine("Act=1")
|
|
RuinedWrt.WriteLine("Cnt=0")
|
|
RuinedWrt.WriteLine("Add=1")
|
|
RuinedWrt.WriteLine("ToN=1")
|
|
Dim sCompo As String = String.Empty
|
|
EgtGetInfo(nPartId, "CMP", sCompo)
|
|
RuinedWrt.WriteLine("Rct=" & If(sCompo = "Rettangolo", "1", "0"))
|
|
Dim dDimX As Double = 0
|
|
EgtGetInfo(nPartId, "V1", dDimX)
|
|
RuinedWrt.WriteLine("DX=" & DoubleToString(dDimX, 4))
|
|
Dim dDimY As Double = 0
|
|
EgtGetInfo(nPartId, "V2", dDimY)
|
|
RuinedWrt.WriteLine("DY=" & DoubleToString(dDimY, 4))
|
|
RuinedWrt.WriteLine("Th=" & DoubleToString(dThick, 4))
|
|
RuinedWrt.WriteLine("OIn=" & nI.ToString())
|
|
Else
|
|
nJ += 1
|
|
ProdWrt.WriteLine("[P" & nJ.ToString() & "]")
|
|
Dim sName As String = String.Empty
|
|
EgtGetInfo(nPartId, INFO_CSV_PART, sName)
|
|
ProdWrt.WriteLine("Nam=" & sName)
|
|
ProdWrt.WriteLine("Mat=" & sMaterial)
|
|
ProdWrt.WriteLine("Act=1")
|
|
ProdWrt.WriteLine("Cnt=1")
|
|
ProdWrt.WriteLine("Add=0")
|
|
ProdWrt.WriteLine("ToN=0")
|
|
Dim sCompo As String = String.Empty
|
|
EgtGetInfo(nPartId, "CMP", sCompo)
|
|
ProdWrt.WriteLine("Rct=" & If(sCompo = "Rettangolo", "1", "0"))
|
|
Dim dDimX As Double = 0
|
|
EgtGetInfo(nPartId, "V1", dDimX)
|
|
ProdWrt.WriteLine("DX=" & DoubleToString(dDimX, 4))
|
|
Dim dDimY As Double = 0
|
|
EgtGetInfo(nPartId, "V2", dDimY)
|
|
ProdWrt.WriteLine("DY=" & DoubleToString(dDimY, 4))
|
|
ProdWrt.WriteLine("Th=" & DoubleToString(dThick, 4))
|
|
ProdWrt.WriteLine("OIn=" & nJ.ToString())
|
|
End If
|
|
Next
|
|
' Terminatori
|
|
RuinedWrt.WriteLine("[END]")
|
|
ProdWrt.WriteLine("[END]")
|
|
' Chiudo i file
|
|
RuinedWrt.Close()
|
|
ProdWrt.Close()
|
|
Return True
|
|
' Errore
|
|
Catch ex As Exception
|
|
EgtOutLog("Error writing epl file")
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Private Sub OptionsBtn_Click(sender As Object, e As RoutedEventArgs) Handles OptionsBtn.Click
|
|
Dim OptionPage As New OptionsPageUC(Me)
|
|
End Sub
|
|
|
|
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs)
|
|
' Salvo progetto
|
|
SaveProject()
|
|
' 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
|
|
|
|
' 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
|
|
|
|
' OnIdle
|
|
Private Sub OnIdle()
|
|
' Se non c'è segnalazione di nuovo progetto, esco
|
|
If Not My.Computer.FileSystem.FileExists(m_sProjDir & "\" & CURR_PROJ_NEW) Then Return
|
|
' Rinomino segnalazione nuovo in segnalazione blocco
|
|
My.Computer.FileSystem.MoveFile(m_sProjDir & "\" & CURR_PROJ_NEW, m_sProjDir & "\" & CURR_PROJ_LOCK, True)
|
|
' Carico nuovo progetto
|
|
LoadProject()
|
|
' Aggiorno la visualizzazione
|
|
EgtSetGenericView(0, (m_nTopViewRotStep - 1) * 90)
|
|
EgtZoom(ZM.ALL)
|
|
' Controllo abilitazione bottone conferma
|
|
UpdateConfirmBtn()
|
|
End Sub
|
|
|
|
Private Function LoadProject() As Boolean
|
|
' Reset elenco pezzi
|
|
m_vParts.Clear()
|
|
' Carico il file
|
|
If Not EgtOpenFile(m_sProjDir & "\" & CURR_PROJ_NAME) Then Return False
|
|
' Rendo corrente il primo (e unico gruppo di lavoro)
|
|
If Not EgtSetCurrMachGroup(EgtGetFirstMachGroup()) Then Return False
|
|
' Visualizzo solo la tavola della macchina
|
|
EgtShowOnlyTable(True)
|
|
' Attivo ultima fase di lavorazione
|
|
EgtSetCurrPhase(EgtGetPhaseCount())
|
|
' Nascondo lavorazioni
|
|
HideAllMachinings()
|
|
' Recupero elenco dei pezzi attivi nella fase
|
|
MakePartList()
|
|
' Nascondo parti ausiliarie per nesting
|
|
Dim nRawId = EgtGetFirstRawPart()
|
|
Dim nSoId = EgtGetFirstNameInGroup(nRawId, NAME_OUTKERF_REG)
|
|
EgtSetStatus(nSoId, GDB_ST.OFF)
|
|
Dim nRrId = EgtGetFirstNameInGroup(nRawId, NAME_REF_REG)
|
|
EgtSetStatus(nRrId, GDB_ST.OFF)
|
|
' Nascondo preview lavorazioni nei pezzi
|
|
For Each nPartId As Integer In m_vParts
|
|
Dim nPV = EgtGetFirstNameInGroup(nPartId, NAME_PREVIEW)
|
|
If nPV <> GDB_ID.NULL Then
|
|
EgtSetStatus(nPV, GDB_ST.OFF)
|
|
End If
|
|
Next
|
|
' Assegno colore blu ai pezzi non classificati
|
|
For Each nPartId As Integer In m_vParts
|
|
' Se pezzo già classificato, passo al successivo
|
|
Dim nOk As Integer = -1
|
|
If EgtGetInfo(nPartId, INFO_PARTOK, nOk) Then Continue For
|
|
' Cerco layer regione
|
|
Dim nRegId = EgtGetFirstNameInGroup(nPartId, NAME_REGION)
|
|
If nRegId = GDB_ID.NULL Then Return False
|
|
' Cerco prima regione nel layer
|
|
Dim nId = EgtGetFirstInGroup(nRegId)
|
|
While nId <> GDB_ID.NULL
|
|
If EgtGetType(nId) = GDB_TY.SRF_FRGN Then
|
|
EgtSetColor(nId, New Color3d(0, 255, 255, 80)) ' Aqua
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNext(nId)
|
|
End While
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function NewProject() As Boolean
|
|
' Reset elenco pezzi
|
|
m_vParts.Clear()
|
|
' 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
|
|
|
|
Private Function SaveProject() As Boolean
|
|
' Verifico non sia progetto vuoto
|
|
If m_vParts.Count() = 0 Then Return True
|
|
' Salvo il file
|
|
If Not EgtSaveFile(m_sProjDir & "\" & CURR_PROJ_NAME, NGE.CMPTEXT) Then Return False
|
|
Return True
|
|
End Function
|
|
|
|
Private Function HideAllMachinings() As Boolean
|
|
Dim nId As Integer = EgtGetFirstOperation()
|
|
While nId <> GDB_ID.NULL
|
|
If EgtGetOperationType(nId) <> MCH_OY.DISP Then
|
|
EgtSetOperationStatus(nId, False)
|
|
End If
|
|
nId = EgtGetNextOperation(nId)
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
Private Function MakePartList() As Boolean
|
|
' Ciclo su tutti i grezzi dell'ultima fase
|
|
Dim nLastPhase = EgtGetPhaseCount()
|
|
Dim nRawId As Integer = EgtGetFirstRawPart()
|
|
While nRawId <> GDB_ID.NULL
|
|
If EgtVerifyRawPartPhase(nRawId, nLastPhase) Then
|
|
' Ciclo su tutti i pezzi del grezzo
|
|
Dim nPartId As Integer = EgtGetFirstPartInRawPart(nRawId)
|
|
While nPartId <> GDB_ID.NULL
|
|
m_vParts.Add(nPartId)
|
|
nPartId = EgtGetNextPartInRawPart(nPartId)
|
|
End While
|
|
End If
|
|
nRawId = EgtGetNextRawPart(nRawId)
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
End Class |