4c72912757
- in comunicazione per linea tolto reset prima di inviare programma - in lavoro corrente per linea carico progetto opportuno in base alle variabili macchina - in CSV salvo epl con Nuovo e Apri (oltre che all'uscita).
331 lines
15 KiB
VB.net
331 lines
15 KiB
VB.net
Imports EgtUILib
|
|
Imports EgtWPFLib
|
|
|
|
Public Class ProjectMgrUC
|
|
|
|
' Riferimenti a pagine
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
Private m_CurrProjPage As CurrentProjectPageUC
|
|
Private m_CurrMachine As CurrentMachine
|
|
Private m_CurrNcComm As CNCommunication
|
|
|
|
' Riferimento alla finestra di salvataggio con nome
|
|
Friend m_SaveNameWD As SaveNameWD
|
|
|
|
Private Sub ProjectMgrUC_Initialized(sender As Object, e As EventArgs) Handles Me.Loaded
|
|
|
|
' Imposto i messaggi letti dal file dei messaggi
|
|
NewBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 3)
|
|
LoadBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 4)
|
|
SaveBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 5)
|
|
SaveNameBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 6)
|
|
CSVBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 8)
|
|
ResetCutBtn.Content = EgtMsg(MSG_NESTPAGEUC + 6)
|
|
SimulateBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 1) 'Simulate - Simula
|
|
WorkBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 2) 'Work - Lavora
|
|
End Sub
|
|
|
|
Private Sub ProjectMgrUC_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
|
|
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
|
|
m_CurrMachine = m_MainWindow.m_CurrentMachine
|
|
m_CurrNcComm = m_MainWindow.m_CNCommunication
|
|
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_CurrProjPage.SaveNamedProject()
|
|
m_CurrProjPage.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())
|
|
' Se macchina con due tavole, chiedo su quale si vuole operare
|
|
Dim sTabName As String = MAIN_TAB
|
|
If EgtGetTableId(SECOND_TAB) <> GDB_ID.NULL Then
|
|
' Tavolo da usare ?
|
|
Dim TableToUse As New EgtMsgBox(m_MainWindow, "", EgtMsg(91111), EgtMsgBox.Buttons.ONE_TWO, EgtMsgBox.Icons.NULL)
|
|
Select Case TableToUse.DialogResult
|
|
Case 1 ' 1
|
|
' si conferma la tavola principale
|
|
Case 0 ' 2
|
|
sTabName = SECOND_TAB
|
|
End Select
|
|
End If
|
|
' Creo nuovo progetto
|
|
m_CurrProjPage.NewProject(sTabName)
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Sub LoadBtn_Click(sender As Object, e As RoutedEventArgs) Handles LoadBtn.Click
|
|
' Cancello eventuali messaggi
|
|
m_CurrProjPage.ClearMessage()
|
|
' 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_CurrProjPage.SaveNamedProject()
|
|
m_CurrProjPage.SaveProject()
|
|
Case 2 ' No
|
|
' Non devo fare alcunchè
|
|
End Select
|
|
End If
|
|
' Imposto la pagina attualmente attiva come Previous
|
|
m_MainWindow.m_PrevActivePage = m_MainWindow.m_ActivePage
|
|
' 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_CurrProjPage.CurrentProjectScene.GetCtx())
|
|
If Not m_CurrProjPage.LoadProject(sCurrDir & "\" & sCurrFile) Then
|
|
m_CurrProjPage.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_CurrProjPage.SetNextProjectIndex()
|
|
m_CurrProjPage.SaveProject()
|
|
Else
|
|
WritePrivateProfileString(S_GENERAL, K_LASTNAMEPROJ, String.Empty, m_MainWindow.GetIniFile())
|
|
End If
|
|
End If
|
|
' Verifico se andare nel CadCut o nel FrameCut
|
|
Dim nPrjType As Integer = m_CurrProjPage.GetCurrentProjectType()
|
|
If nPrjType = CurrentProjectPageUC.PRJ_TYPE.FLATS And
|
|
m_MainWindow.m_PrevActivePage <> MainWindow.Pages.CadCut Then
|
|
m_CurrProjPage.CurrentProjectPageGrid.Children.Remove(m_MainWindow.m_FrameCutPageUC)
|
|
m_CurrProjPage.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut
|
|
m_MainWindow.FrameCutBtn.IsChecked = False
|
|
m_MainWindow.CadCutBtn.IsChecked = True
|
|
ElseIf nPrjType = CurrentProjectPageUC.PRJ_TYPE.FRAMES And
|
|
m_MainWindow.m_PrevActivePage <> MainWindow.Pages.FrameCut Then
|
|
m_CurrProjPage.CurrentProjectPageGrid.Children.Remove(m_MainWindow.m_CadCutPageUC)
|
|
m_CurrProjPage.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_FrameCutPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.FrameCut
|
|
m_MainWindow.CadCutBtn.IsChecked = False
|
|
m_MainWindow.FrameCutBtn.IsChecked = True
|
|
Else
|
|
m_MainWindow.m_ActivePage = m_MainWindow.m_PrevActivePage
|
|
End If
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
|
|
' Salvataggio con nome (solo se nome definito)
|
|
m_CurrProjPage.SaveNamedProject()
|
|
' Salvataggio con numero ciclico
|
|
m_CurrProjPage.SaveProject()
|
|
' Se cornici, ripristino visualizzazione lavorazioni
|
|
If m_MainWindow.m_ActivePage = MainWindow.Pages.FrameCut Then
|
|
ShowAllCurrPhaseMachinings()
|
|
End If
|
|
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 CSVBtn_Click(sender As Object, e As RoutedEventArgs) Handles CSVBtn.Click
|
|
m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Remove(m_MainWindow.m_CadCutPageUC.m_NestPage)
|
|
m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC.m_CSVPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.CSV
|
|
m_MainWindow.m_PrevActivePage = MainWindow.Pages.CadCut
|
|
End Sub
|
|
|
|
Private Sub ResetCutBtn_Click(sender As Object, e As RoutedEventArgs) Handles ResetCutBtn.Click
|
|
' Cancello eventuali messaggi
|
|
m_CurrProjPage.ClearMessage()
|
|
' Cancello tutte le lavorazioni
|
|
EraseMachinings(GDB_ID.NULL)
|
|
' Se progetto con pezzi piani
|
|
Dim nPrjType As Integer = m_CurrProjPage.GetCurrentProjectType()
|
|
If nPrjType = CurrentProjectPageUC.PRJ_TYPE.FLATS Then
|
|
' Reinserisco tutte le lavorazioni piane
|
|
AddMachinings(GDB_ID.NULL, True, False)
|
|
' Se altrimenti progetto con cornici
|
|
ElseIf nPrjType = CurrentProjectPageUC.PRJ_TYPE.FRAMES Then
|
|
' Reinserisco tutte le lavorazioni delle cornici
|
|
AddFrameMachinings()
|
|
End If
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub SimulateBtn_Click(sender As Object, e As RoutedEventArgs) Handles SimulateBtn.Click
|
|
m_CurrProjPage.CurrProjGrid.Visibility = Windows.Visibility.Hidden
|
|
If m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut Then
|
|
m_CurrProjPage.CurrentProjectPageGrid.Children.Remove(m_MainWindow.m_CadCutPageUC)
|
|
m_MainWindow.m_PrevActivePage = MainWindow.Pages.CadCut
|
|
Else
|
|
m_CurrProjPage.CurrentProjectPageGrid.Children.Remove(m_MainWindow.m_FrameCutPageUC)
|
|
m_MainWindow.m_PrevActivePage = MainWindow.Pages.FrameCut
|
|
End If
|
|
m_CurrProjPage.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
|
|
' Verifico l'attrezzaggio degli utensili utilizzati
|
|
Dim sMissingTools As String = String.Empty
|
|
If Not VerifySetup(sMissingTools) Then
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90322) & " " & sMissingTools) 'Mancano gli utensili : ...
|
|
Return
|
|
End If
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Se pezzi piani e non c'è ordine delle lavorazioni, ne faccio uno automatico
|
|
Dim nPrjType As Integer = m_CurrProjPage.GetCurrentProjectType()
|
|
If nPrjType = CurrentProjectPageUC.PRJ_TYPE.FLATS And
|
|
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
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Disabilito impostazione modificato
|
|
EgtDisableModified()
|
|
' Aggiorno le lavorazioni
|
|
bOk = UpdateAllMachiningsToolpaths() And bOk
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Inserisco indice di progetto
|
|
m_CurrProjPage.SetProjectIndexFlag()
|
|
' Inserisco il materiale
|
|
m_CurrProjPage.SetProjectMaterial()
|
|
' Salvo il progetto con le lavorazioni
|
|
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\MachProj.nge"
|
|
m_CurrProjPage.SaveFile(sMchPath)
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Genero file CNC (lancio anche se errore in precedenza)
|
|
Dim sCncPath As String = m_MainWindow.GetCncDir() & "\CadCut" & m_CurrMachine.sIsoFileExt
|
|
bOk = EgtGenerate(sCncPath, "OmagCut") And bOk
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Ripristino come fase corrente quella iniziale
|
|
EgtSetCurrPhase(1)
|
|
' Se nesting di pezzi piani, nascondo tutte le lavorazioni
|
|
If m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut Then
|
|
HideAllMachinings()
|
|
Else
|
|
ShowAllCurrPhaseMachinings()
|
|
End If
|
|
' 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
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Se macchina normale
|
|
If Not m_CurrMachine.bProdLine Then
|
|
' Download programma (eventuali errori sono segnalati dalla funzione)
|
|
If m_CurrNcComm.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
|
|
' Altrimenti linea di produzione
|
|
Else
|
|
' Se non collegato alla macchina
|
|
If Not m_MainWindow.m_bNCLink Then
|
|
m_CurrProjPage.SetWarningMessage(EgtMsg(90316)) 'Non connesso alla macchina
|
|
' copio il progetto corrente come progetto in lavorazione
|
|
Dim sWrkPath As String = m_MainWindow.GetTempDir() & "\" & "WorkProj.nge"
|
|
My.Computer.FileSystem.CopyFile(sMchPath, sWrkPath, True)
|
|
Return
|
|
End If
|
|
' Verifico non sia già stato trasmesso
|
|
If m_CurrProjPage.GetProjectNcProgSent() <> 0 Then
|
|
' Programma già trasmesso, vuoi ritrasmetterlo ?
|
|
Dim AskTransm As New EgtMsgBox(m_MainWindow, "", EgtMsg(90319),
|
|
EgtMsgBox.Buttons.YES_NO_CANCEL, EgtMsgBox.Icons.NULL, 2)
|
|
If AskTransm.DialogResult <> 1 Then Return
|
|
End If
|
|
' Leggo variabile relativa al programma 1 (standard E80021)
|
|
m_CurrNcComm.m_CN.n_DReadELS_handle = 0
|
|
m_CurrNcComm.m_CN.ReadEls_Add_Parameter(m_CurrMachine.sVarProg1, 1)
|
|
Dim nVarProg1 As Integer = 99
|
|
For I = 0 To 20
|
|
System.Threading.Thread.Sleep(100)
|
|
If m_CurrNcComm.m_CN.n_DReadELS_handle = 1 Then
|
|
nVarProg1 = m_CurrNcComm.m_CN.d_DReadELS_value
|
|
Exit For
|
|
End If
|
|
Next
|
|
' Leggo variabile relativa al programma 2 (standard E80022)
|
|
m_CurrNcComm.m_CN.n_DReadELS_handle = 0
|
|
m_CurrNcComm.m_CN.ReadEls_Add_Parameter(m_CurrMachine.sVarProg2, 1)
|
|
Dim nVarProg2 As Integer = 99
|
|
For I = 0 To 20
|
|
System.Threading.Thread.Sleep(100)
|
|
If m_CurrNcComm.m_CN.n_DReadELS_handle = 1 Then
|
|
nVarProg2 = m_CurrNcComm.m_CN.d_DReadELS_value
|
|
Exit For
|
|
End If
|
|
Next
|
|
' Verifico se posso scrivere nell'area 1
|
|
If nVarProg1 = 0 And nVarProg2 <> 1 Then
|
|
If m_CurrNcComm.SendProgram(sCncPath, m_CurrMachine.nProg1, False) Then
|
|
' Dichiaro part program inviato
|
|
m_CurrProjPage.SetProjectNcProgSent(1)
|
|
' Copio il progetto corrente come progetto in lavorazione
|
|
Dim sWrkPath As String = m_MainWindow.GetTempDir() & "\" & "WorkProj1.nge"
|
|
My.Computer.FileSystem.CopyFile(sMchPath, sWrkPath, True)
|
|
' Salvo il progetto
|
|
m_CurrProjPage.SaveProject()
|
|
' Dichiaro programma inviato
|
|
m_CurrNcComm.m_CN.DVariables_WriteVariables2(m_CurrMachine.sVarProg1, "1")
|
|
Return
|
|
End If
|
|
' Altrimenti verifico se posso scrivere nell'area 2
|
|
ElseIf nVarProg2 = 0 And nVarProg1 <> 1 Then
|
|
If m_CurrNcComm.SendProgram(sCncPath, m_CurrMachine.nProg2, False) Then
|
|
' Dichiaro part program inviato
|
|
m_CurrProjPage.SetProjectNcProgSent(2)
|
|
' Copio il progetto corrente come progetto in lavorazione
|
|
Dim sWrkPath As String = m_MainWindow.GetTempDir() & "\" & "WorkProj2.nge"
|
|
My.Computer.FileSystem.CopyFile(sMchPath, sWrkPath, True)
|
|
' Salvo il progetto
|
|
m_CurrProjPage.SaveProject()
|
|
' Dichiaro programma inviato
|
|
m_CurrNcComm.m_CN.DVariables_WriteVariables2(m_CurrMachine.sVarProg2, "1")
|
|
Return
|
|
End If
|
|
' Altrimenti aree di memoria non disponibili
|
|
Else
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90318)) 'La macchina non accetta il programma CN
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
End Class
|