11db87cec5
- migliorato salvataggio con nome - correzioni a spezzatura grezzo.
273 lines
12 KiB
VB.net
273 lines
12 KiB
VB.net
Imports EgtUILib
|
|
Imports EgtWPFLib
|
|
Imports System.Reflection
|
|
Imports System.Globalization
|
|
|
|
Public Class CadCutPageUC
|
|
|
|
' Riferimenti a pagine
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
Private m_CurrProjPage As CurrentProjectPageUC
|
|
|
|
' Dichiarazione delle Page UserControl
|
|
Friend WithEvents m_NestPage As NestPageUC
|
|
Friend m_SplitPage As SplitPageUC
|
|
Friend m_MoveRawPartPage As MoveRawPartPage
|
|
|
|
' Riferimento alla finestra di salvataggio con nome
|
|
Friend m_SaveNameWD As SaveNameWD
|
|
|
|
' Variabile che indica la modalità
|
|
Friend m_MovePartPage As MovePartsPages
|
|
|
|
' Oggetto di gestione della macchina fotografica
|
|
Friend m_Camera As New Camera
|
|
|
|
' Elenco pagine interne a cadcutpage
|
|
Friend Enum MovePartsPages As Integer
|
|
Nest
|
|
Split
|
|
MoveRawPart
|
|
End Enum
|
|
|
|
Private Sub CadCutPage_Initialized(sender As Object, e As EventArgs)
|
|
|
|
' Creazione delle Page UserControl
|
|
m_NestPage = New NestPageUC
|
|
m_SplitPage = New SplitPageUC
|
|
m_MoveRawPartPage = New MoveRawPartPage
|
|
|
|
' Posizionamento nella griglia delle Page UserControl
|
|
m_NestPage.SetValue(Grid.RowSpanProperty, 3)
|
|
m_NestPage.SetValue(Grid.ColumnSpanProperty, 2)
|
|
m_SplitPage.SetValue(Grid.RowSpanProperty, 3)
|
|
m_SplitPage.SetValue(Grid.ColumnSpanProperty, 3)
|
|
m_MoveRawPartPage.SetValue(Grid.RowSpanProperty, 3)
|
|
m_MoveRawPartPage.SetValue(Grid.ColumnSpanProperty, 3)
|
|
|
|
' Nascondo progress e label per messaggi
|
|
PhotoProgress.Visibility = Windows.Visibility.Hidden
|
|
|
|
' Imposto i messaggi letti dal file dei messaggi
|
|
SimulateBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 1) 'Simulate - Simula
|
|
WorkBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 2) 'Work - Lavora
|
|
NewBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 3)
|
|
LoadBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 4)
|
|
SaveBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 5)
|
|
SaveNameBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 6)
|
|
End Sub
|
|
|
|
Private Sub CadCutPage_Loaded(sender As Object, e As RoutedEventArgs)
|
|
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
|
|
' Seleziono UserControl di apertura
|
|
CadCutPageGrid.Children.Add(m_NestPage)
|
|
m_MovePartPage = MovePartsPages.Nest
|
|
'm_bNesting = True
|
|
SplitImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Split.png", UriKind.Relative))
|
|
EgtZoom(ZM.ALL)
|
|
' Inizializzo gestore macchina fotografica
|
|
m_Camera.Init()
|
|
End Sub
|
|
|
|
Private Sub PhotoBtn_Click(sender As Object, e As RoutedEventArgs) Handles PhotoBtn.Click
|
|
' Se macchina fotografica abilitata, faccio una foto
|
|
If m_Camera.GetCameraLink() Then
|
|
If Not m_Camera.CameraClick() Then
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90313)) 'Fotografia non riuscita
|
|
End If
|
|
' Altrimenti lancio browser di immagini
|
|
Else
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_PhotoPage)
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub PostPhoto(ByVal sPath As String)
|
|
' Carico la foto
|
|
m_MainWindow.m_CurrentProjectPageUC.LoadPhoto(sPath)
|
|
' Aggiorno visualizzazione
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Sub RawPartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RawPartBtn.Click
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrProjGrid.Visibility = Windows.Visibility.Hidden
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(Me)
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_RawPartPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.RawPart
|
|
End Sub
|
|
|
|
Private Sub DrawBtn_Click(sender As Object, e As RoutedEventArgs) Handles DrawBtn.Click
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_DrawPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Draw
|
|
End Sub
|
|
|
|
Private Sub ImportBtn_Click(sender As Object, e As RoutedEventArgs) Handles ImportBtn.Click
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_ImportPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Import
|
|
End Sub
|
|
|
|
Private Sub CadCutPage_Unloaded(sender As Object, e As RoutedEventArgs)
|
|
' Chiudo tutti gli UserControl attivi
|
|
Select Case m_MovePartPage
|
|
Case MovePartsPages.Nest
|
|
CadCutPageGrid.Children.Remove(m_NestPage)
|
|
Case MovePartsPages.Split
|
|
CadCutPageGrid.Children.Remove(m_SplitPage)
|
|
Case MovePartsPages.MoveRawPart
|
|
CadCutPageGrid.Children.Remove(m_MoveRawPartPage)
|
|
End Select
|
|
End Sub
|
|
|
|
Private Sub SplitBtn_Click(sender As Object, e As RoutedEventArgs) Handles SplitBtn.Click
|
|
Select Case m_MovePartPage
|
|
Case MovePartsPages.Nest
|
|
SplitImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Nest.png", UriKind.Relative))
|
|
CadCutPageGrid.Children.Remove(m_NestPage)
|
|
CadCutPageGrid.Children.Add(m_SplitPage)
|
|
m_MovePartPage = MovePartsPages.Split
|
|
' !!! Provvisorio : riparto da capo !!!
|
|
' Cancello tutte le lavorazioni
|
|
EraseMachinings(GDB_ID.NULL)
|
|
' Reinserisco tutte le lavorazioni
|
|
AddMachinings(GDB_ID.NULL, True, False)
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
Case MovePartsPages.Split
|
|
SplitImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Split.png", UriKind.Relative))
|
|
CadCutPageGrid.Children.Remove(m_SplitPage)
|
|
CadCutPageGrid.Children.Add(m_NestPage)
|
|
m_MovePartPage = MovePartsPages.Nest
|
|
End Select
|
|
End Sub
|
|
|
|
Private Sub NewBtn_Click(sender As Object, e As RoutedEventArgs) Handles NewBtn.Click
|
|
' Se progetto modificato, chiedo se salvarlo
|
|
If EgtGetModified() Then
|
|
Dim SaveCurrProj As New EgtMsgBox(m_MainWindow, "", EgtMsg(MSG_EGTMSGBOX + 1), EgtMsgBox.Buttons.YES_NO_CANCEL, EgtMsgBox.Icons.NULL)
|
|
Select Case SaveCurrProj.DialogResult
|
|
Case 0 ' Annulla
|
|
Return
|
|
Case 1 ' Si
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveProject()
|
|
Case 2 ' No
|
|
' Non devo fare alcunchè
|
|
End Select
|
|
End If
|
|
' Cancello progetto salvato con nome da file ini
|
|
WritePrivateProfileString(S_GENERAL, K_LASTNAMEPROJ, "", m_MainWindow.GetIniFile())
|
|
m_MainWindow.m_CurrentProjectPageUC.NewProject()
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Sub LoadBtn_Click(sender As Object, e As RoutedEventArgs) Handles LoadBtn.Click
|
|
' Se progetto modificato, chiedo se salvarlo
|
|
If EgtGetModified() Then
|
|
Dim SaveCurrProj As New EgtMsgBox(m_MainWindow, "", EgtMsg(MSG_EGTMSGBOX + 1), EgtMsgBox.Buttons.YES_NO_CANCEL, EgtMsgBox.Icons.NULL)
|
|
Select Case SaveCurrProj.DialogResult
|
|
Case 0 ' Annulla
|
|
Return
|
|
Case 1 ' Si
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveNameProject()
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveProject()
|
|
Case 2 ' No
|
|
' Non devo fare alcunchè
|
|
End Select
|
|
End If
|
|
' Passo alla pagina di apertura con preview
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_OpenPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Open
|
|
End Sub
|
|
|
|
Friend Sub PostLoad(ByVal sCurrDir As String, sCurrFile As String)
|
|
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
|
|
If Not m_MainWindow.m_CurrentProjectPageUC.LoadProject(sCurrDir & "\" & sCurrFile) Then
|
|
m_MainWindow.m_CurrentProjectPageUC.NewProject()
|
|
Else
|
|
' Verifico se file salvato con nome guardando il nome della cartella in cui si trova
|
|
Dim sSaveNameDir As String = String.Empty
|
|
GetPrivateProfileString(S_GENERAL, K_SAVENAMEDIR, "", sSaveNameDir, m_MainWindow.GetIniFile())
|
|
If sCurrDir = sSaveNameDir Then
|
|
WritePrivateProfileString(S_GENERAL, K_LASTNAMEPROJ, sCurrFile.Substring(0, sCurrFile.Length - 4), m_MainWindow.GetIniFile())
|
|
' Salvo equivalente con indice
|
|
m_MainWindow.m_CurrentProjectPageUC.SetNextProjectIndex()
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveProject()
|
|
Else
|
|
WritePrivateProfileString(S_GENERAL, K_LASTNAMEPROJ, String.Empty, m_MainWindow.GetIniFile())
|
|
End If
|
|
End If
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
|
|
' Recupero nome corrente
|
|
Dim sCurrNameProj As String = String.Empty
|
|
GetPrivateProfileString(S_GENERAL, K_LASTNAMEPROJ, "", sCurrNameProj, m_MainWindow.GetIniFile())
|
|
' Se vuoto vado alla salva con nome
|
|
If String.IsNullOrEmpty(sCurrNameProj) Then
|
|
SaveNameBtn_Click(sender, e)
|
|
Return
|
|
End If
|
|
' Salvataggio con nome
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveNameProject()
|
|
' Slvataggio con numero ciclico
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveProject()
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub SaveNameBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveNameBtn.Click
|
|
m_SaveNameWD = New SaveNameWD(m_MainWindow)
|
|
m_SaveNameWD.ShowDialog()
|
|
End Sub
|
|
|
|
Private Sub SimulateBtn_Click(sender As Object, e As RoutedEventArgs) Handles SimulateBtn.Click
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrProjGrid.Visibility = Windows.Visibility.Hidden
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(m_MainWindow.m_CadCutPageUC)
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_SimulationPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Simulation
|
|
End Sub
|
|
|
|
Private Sub WorkBtn_Click(sender As Object, e As RoutedEventArgs) Handles WorkBtn.Click
|
|
Dim bOk As Boolean = True
|
|
' Se non c'è ordine delle lavorazioni, ne faccio uno automatico
|
|
If Not m_CurrProjPage.GetOrderMachiningFlag() Then
|
|
bOk = SortAllMachinings()
|
|
If bOk Then
|
|
m_CurrProjPage.SetOrderMachiningFlag()
|
|
Dim bModif As Boolean = TestAllMachiningsForStrict()
|
|
If bModif Then
|
|
m_CurrProjPage.SetWarningMessage(EgtMsg(90321)) 'Ridotte alcune lavorazioni per evitare interferenze
|
|
End If
|
|
End If
|
|
End If
|
|
' Disabilito impostazione modificato
|
|
EgtDisableModified()
|
|
' Aggiorno le lavorazioni
|
|
bOk = UpdateAllMachiningsToolpaths() And bOk
|
|
' Salvo il progetto con le lavorazioni
|
|
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\MachProj.nge"
|
|
m_MainWindow.m_CurrentProjectPageUC.SaveFile(sMchPath)
|
|
' Genero file CNC (lancio anche se errore in precedenza)
|
|
Dim sCncPath As String = m_MainWindow.GetCncDir() & "\CadCut.xpi"
|
|
bOk = EgtGenerate(sCncPath, "OmagCut") And bOk
|
|
' Ripristino come fase corrente quella iniziale
|
|
EgtSetCurrPhase(1)
|
|
' Abilito impostazione modificato
|
|
EgtEnableModified()
|
|
' Se errore in generazione, segnalo l'errore ed esco
|
|
If Not bOk Then
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90314)) 'Errore nella generazione del programma CN
|
|
Return
|
|
End If
|
|
' Download programma (eventuali errori sono segnalati dalla funzione)
|
|
If m_MainWindow.m_CNCommunication.SendProgram(sCncPath, 900) Then
|
|
' copio il progetto corrente come progetto in lavorazione
|
|
Dim sWrkPath As String = m_MainWindow.GetTempDir() & "\" & "WorkProj.nge"
|
|
My.Computer.FileSystem.CopyFile(sMchPath, sWrkPath, True)
|
|
End If
|
|
End Sub
|
|
|
|
End Class
|