d6eee85a02
- aggiunta creazione grezzo da riconoscimento contorno da fotografia.
407 lines
15 KiB
VB.net
407 lines
15 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Class SimulationPageUC
|
|
' Riferimenti a pagine
|
|
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
|
|
Private m_CurrProjPage As CurrentProjectPageUC
|
|
|
|
' Stato di visualizzazione della macchina
|
|
Private m_nMachLook As Integer = MCH_LOOK.ALL
|
|
' Utensile corrente
|
|
Private m_sCurrTool As String = String.Empty
|
|
' Stato e comando correnti
|
|
Public Enum SIM_ST As Integer
|
|
ST_STOP = 1
|
|
ST_PLAY = 2
|
|
ST_STEP = 3
|
|
ST_PAUSE = 4
|
|
End Enum
|
|
Private m_nStatus As Integer = SIM_ST.ST_STOP
|
|
' Stato bottone Play
|
|
Private m_bPlay As Boolean = True
|
|
' Coefficiente per valore Slider
|
|
Private m_SliderX As Double = 1
|
|
|
|
' Numero di assi in simulazione
|
|
Private m_SimulationAxesNum As Integer = 5
|
|
|
|
Friend Sub ResetSimulation()
|
|
' Termino la simulazione
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
EgtSimStop()
|
|
' Salvo valore dello slider
|
|
Dim sVal As String = DoubleToString(SpeedSlider.Value, 1)
|
|
WritePrivateProfileString(S_SIMUL, K_SLIDERVAL, sVal, m_MainWindow.GetIniFile())
|
|
' Torno alla prima fase
|
|
EgtSetCurrPhase(1, True)
|
|
' Ripristino visibilità standard
|
|
EgtSetMachineLook(MCH_LOOK.TAB)
|
|
End Sub
|
|
|
|
Private Sub SimulationPage_Initialized(sender As Object, e As EventArgs)
|
|
|
|
PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Play.png", UriKind.Relative))
|
|
m_SimulationAxesNum = GetPrivateProfileInt(S_AXES, K_SIMULATIONAXESNUM, 5, m_MainWindow.GetMachIniFile())
|
|
For Index = 0 To AxesUniformGrid.Children.Count - 1
|
|
If Index > m_SimulationAxesNum - 1 And Index < AxesUniformGrid.Children.Count - 2 Then
|
|
If TypeOf AxesUniformGrid.Children(Index) Is Grid Then
|
|
Dim AxisGrid As Grid = DirectCast(AxesUniformGrid.Children(Index), Grid)
|
|
AxisGrid.Visibility = Windows.Visibility.Collapsed
|
|
End If
|
|
End If
|
|
Next
|
|
If m_SimulationAxesNum <= 5 Then
|
|
AxesUniformGrid.Rows = 7
|
|
AxesBoder.SetValue(Grid.RowSpanProperty, 1)
|
|
AxesBoder.SetValue(Grid.RowProperty, 1)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub SimulationPage_Loaded(sender As Object, e As RoutedEventArgs)
|
|
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
|
|
Dim bOk As Boolean = True
|
|
' Verifico l'attrezzaggio degli utensili utilizzati
|
|
Dim sMissingTools As String = String.Empty
|
|
Dim bSetup As Boolean = VerifySetup(sMissingTools)
|
|
' 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()
|
|
End If
|
|
Dim bModif As Boolean = TestAllMachiningsForStrict()
|
|
If bModif Then
|
|
m_CurrProjPage.SetWarningMessage(EgtMsg(90321)) 'Ridotte alcune lavorazioni per evitare interferenze
|
|
End If
|
|
End If
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Disabilito impostazione modificato
|
|
EgtDisableModified()
|
|
' Aggiorno le lavorazioni
|
|
bOk = UpdateAllMachiningsToolpaths() And bOk
|
|
' Se errore in setup, lo segnalo
|
|
If Not bSetup Then
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90322) & " " & sMissingTools) 'Mancano gli utensili : ...
|
|
' Se errore in generazione, segnalo l'errore
|
|
ElseIf Not bOk Then
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90314)) 'Errore nella generazione del programma CN
|
|
End If
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Salvo il progetto con le lavorazioni
|
|
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\" & "MachProj.nge"
|
|
m_CurrProjPage.SaveFile(sMchPath)
|
|
' Nascondo eventuali pezzi in parcheggio
|
|
HideParkedParts()
|
|
' Nascondo eventuale contorno da foto
|
|
m_CurrProjPage.ShowContour(False)
|
|
' Imposto prima fase
|
|
EgtSetCurrPhase(1)
|
|
ShowAllCurrPhaseMachinings()
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Visualizzo opportunamente la macchina
|
|
m_nMachLook = MCH_LOOK.ALL
|
|
EgtSetMachineLook(m_nMachLook)
|
|
' Imposto vista 3d isometrica di tutto
|
|
EgtSetView(VT.ISO_SE, False)
|
|
EgtZoom(ZM.ALL)
|
|
' Imposto stato corrente
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
m_bPlay = True
|
|
m_SliderX = GetPrivateProfileDouble(S_SIMUL, K_SLIDERX, 1, m_MainWindow.GetIniFile())
|
|
Dim SliderVal As Double = GetPrivateProfileDouble(S_SIMUL, K_SLIDERVAL, 10, m_MainWindow.GetIniFile())
|
|
SpeedSlider.Value = SliderVal
|
|
' Porto la testa in home
|
|
EgtSimStart()
|
|
EgtSimHome()
|
|
LoadCurrTools()
|
|
EgtDraw()
|
|
ShowCncData()
|
|
End Sub
|
|
|
|
Private Sub StepBtn_Click(sender As Object, e As RoutedEventArgs) Handles StepBtn.Click
|
|
m_CurrProjPage.ClearMessage()
|
|
' Se stato stop, devo avviare simulazione
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
m_nStatus = SIM_ST.ST_STEP
|
|
ExecSim()
|
|
' Aggiorno bottone
|
|
SetPlayPauseBtnToPlay()
|
|
' Alrimenti imposto solo il nuovo stato
|
|
Else
|
|
m_nStatus = SIM_ST.ST_STEP
|
|
' Aggiornamenti per bottone Play/Pause
|
|
SetPlayPauseBtnToPause()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub PlayPauseBtn_Click(sender As Object, e As RoutedEventArgs) Handles PlayPauseBtn.Click
|
|
m_CurrProjPage.ClearMessage()
|
|
If m_bPlay Then
|
|
' Aggiorno bottone
|
|
SetPlayPauseBtnToPause()
|
|
' Eseguo
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
' Lancio simulazione
|
|
m_nStatus = SIM_ST.ST_PLAY
|
|
ExecSim()
|
|
' Aggiorno bottone
|
|
SetPlayPauseBtnToPlay()
|
|
ElseIf m_nStatus = SIM_ST.ST_PAUSE Then
|
|
m_nStatus = SIM_ST.ST_PLAY
|
|
End If
|
|
Else
|
|
' Aggiorno bottone
|
|
SetPlayPauseBtnToPlay()
|
|
' Se play o step, imposto stato pausa
|
|
If m_nStatus = SIM_ST.ST_PLAY Or m_nStatus = SIM_ST.ST_STEP Then
|
|
m_nStatus = SIM_ST.ST_PAUSE
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub SetPlayPauseBtnToPlay()
|
|
m_bPlay = True
|
|
PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Play.png", UriKind.Relative))
|
|
End Sub
|
|
|
|
Private Sub SetPlayPauseBtnToPause()
|
|
m_bPlay = False
|
|
PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Pause.png", UriKind.Relative))
|
|
End Sub
|
|
|
|
Private Sub StopBtn_Click(sender As Object, e As RoutedEventArgs) Handles StopBtn.Click
|
|
m_CurrProjPage.ClearMessage()
|
|
' Se stato già stop, porto in home
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
' Vado in home
|
|
EgtSimHome()
|
|
' Imposto prima fase
|
|
EgtSetCurrPhase(1, True)
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
End If
|
|
' Imposto il nuovo stato
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
End Sub
|
|
|
|
Private Sub SpeedSlider_ValueChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Double))
|
|
If e.OldValue <> 0 Then
|
|
EgtSimSetStep(SpeedSlider.Value * m_SliderX)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ExecSim()
|
|
EgtSimStart()
|
|
LoadCurrTools()
|
|
EgtSimSetStep(SpeedSlider.Value * m_SliderX)
|
|
While m_nStatus <> SIM_ST.ST_STOP
|
|
' Se simulazione in svolgimento
|
|
If m_nStatus = SIM_ST.ST_PLAY Or m_nStatus = SIM_ST.ST_STEP Then
|
|
' Eseguo movimento
|
|
Dim nMove As Integer
|
|
Dim bMove As Boolean = EgtSimMove(nMove)
|
|
' Se arrivato a fine step e sono in step
|
|
If bMove Then
|
|
If m_nStatus = SIM_ST.ST_STEP And nMove = MCH_SIM.END_STEP Then
|
|
' Imposto stato Pausa
|
|
m_nStatus = SIM_ST.ST_PAUSE
|
|
' Aggiornamenti per bottone Play/Pause
|
|
SetPlayPauseBtnToPlay()
|
|
End If
|
|
' Se movimento non riuscito
|
|
Else
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
' Aggiornamenti per bottone Play/Pause
|
|
SetPlayPauseBtnToPlay()
|
|
Select Case nMove
|
|
Case MCH_SIM.END_
|
|
m_CurrProjPage.SetInfoMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 1)) 'Simulazione completata
|
|
Case MCH_SIM.OUTSTROKE
|
|
Dim sInfo As String = String.Empty
|
|
EgtGetOutstrokeInfo(sInfo)
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 2) & " " & sInfo) 'Extracorsa ...
|
|
Case MCH_SIM.DIR_ERR
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 3)) 'Direzione utensile irraggiungibile
|
|
Case Else
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 4)) 'Errore
|
|
End Select
|
|
End If
|
|
' Aggiorno stato visualizzazione macchina (dipende anche da utensile)
|
|
UpdateMachView()
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
Else
|
|
' Per evitare di ciclare rapidissimamente e consumare inutilmente CPU
|
|
System.Threading.Thread.Sleep(1)
|
|
End If
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub ShowCncData()
|
|
' Assi
|
|
Dim nInd As Integer = 0
|
|
ShowAxisNameVal(nInd, A1Name.Text, A1Value.Text)
|
|
ShowAxisNameVal(nInd, A2Name.Text, A2Value.Text)
|
|
ShowAxisNameVal(nInd, A3Name.Text, A3Value.Text)
|
|
ShowAxisNameVal(nInd, A4Name.Text, A4Value.Text)
|
|
ShowAxisNameVal(nInd, A5Name.Text, A5Value.Text)
|
|
If m_SimulationAxesNum >= 6 Then
|
|
ShowAxisNameVal(nInd, A6Name.Text, A6Value.Text)
|
|
End If
|
|
If m_SimulationAxesNum >= 7 Then
|
|
ShowAxisNameVal(nInd, A7Name.Text, A7Value.Text)
|
|
End If
|
|
If m_SimulationAxesNum >= 8 Then
|
|
ShowAxisNameVal(nInd, A8Name.Text, A8Value.Text)
|
|
End If
|
|
If m_SimulationAxesNum >= 9 Then
|
|
ShowAxisNameVal(nInd, A9Name.Text, A9Value.Text)
|
|
End If
|
|
If m_SimulationAxesNum = 10 Then
|
|
ShowAxisNameVal(nInd, A10Name.Text, A10Value.Text)
|
|
End If
|
|
' Tipo di movimento e feed
|
|
ShowMoveTypeFeed()
|
|
' Nome utensile e speed
|
|
ShowToolNameSpeed()
|
|
End Sub
|
|
|
|
Private Function ShowAxisNameVal(ByRef nInd As Integer, ByRef sName As String, ByRef sVal As String) As Boolean
|
|
Dim sInfo As String = String.Empty
|
|
Dim bLinear As Boolean = True
|
|
Dim dVal As Double = 0
|
|
If EgtSimGetAxisInfoPos(nInd, sInfo, bLinear, dVal) Then
|
|
If sInfo <> "**" Then
|
|
sName = sInfo
|
|
sVal = If(bLinear, LenToString(dVal, -3), DoubleToString(dVal, -3))
|
|
nInd += 1
|
|
Return True
|
|
Else
|
|
nInd += 1
|
|
Return ShowAxisNameVal(nInd, sName, sVal)
|
|
End If
|
|
Else
|
|
sName = String.Empty
|
|
sVal = String.Empty
|
|
nInd += 1
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Private Function ShowMoveTypeFeed() As Boolean
|
|
Dim nG As Integer = 0
|
|
Dim dFeed As Double = 0
|
|
If EgtSimGetMoveInfo(nG, dFeed) Then
|
|
If nG <> 0 Then
|
|
GCodeTxBl.Text = "G" & nG.ToString()
|
|
FValueTxBl.Text = "F" & LenToString(dFeed, 0)
|
|
Else
|
|
GCodeTxBl.Text = "G" & nG.ToString()
|
|
FValueTxBl.Text = ""
|
|
End If
|
|
Return True
|
|
Else
|
|
GCodeTxBl.Text = ""
|
|
FValueTxBl.Text = ""
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Private Function ShowToolNameSpeed() As Boolean
|
|
Dim sTool As String = String.Empty
|
|
Dim dSpeed As Double = 0
|
|
If EgtSimGetToolInfo(sTool, dSpeed) Then
|
|
TNameTxBl.Text = sTool
|
|
SValueTxBl.Text = "S" & DoubleToString(dSpeed, 0)
|
|
Return True
|
|
Else
|
|
TNameTxBl.Text = ""
|
|
SValueTxBl.Text = ""
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Private Function LoadCurrTools() As Boolean
|
|
' Imposto la lama corrente
|
|
Dim sSaw As String = m_MainWindow.m_CurrentMachine.sCurrSaw
|
|
If Not EgtLoadTool("H1", 1, sSaw) Then
|
|
Return False
|
|
End If
|
|
' Imposto eventuale secondo utensile montato
|
|
If m_MainWindow.m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL Then
|
|
Dim sTool As String = m_MainWindow.m_CurrentMachine.sCurrDrill
|
|
If String.IsNullOrEmpty(sTool) Then sTool = m_MainWindow.m_CurrentMachine.sCurrMill
|
|
If Not String.IsNullOrEmpty(sTool) AndAlso Not EgtLoadTool("H1", 2, sTool) Then
|
|
Return False
|
|
End If
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub MachViewModeBtn_Click(sender As Object, e As RoutedEventArgs) Handles MachViewModeBtn.Click
|
|
' aggiorno lo stato
|
|
Select Case m_nMachLook
|
|
Case MCH_LOOK.ALL
|
|
m_nMachLook = MCH_LOOK.TAB_HEAD
|
|
Case MCH_LOOK.TAB_HEAD
|
|
m_nMachLook = MCH_LOOK.TAB_TOOL
|
|
Case Else
|
|
m_nMachLook = MCH_LOOK.ALL
|
|
End Select
|
|
' aggiorno lo stato della macchina e la sua visualizzazione
|
|
EgtSetMachineLook(m_nMachLook)
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub UpdateMachView()
|
|
' Se cambiato utensile, aggiorno stato visualizzazione macchina
|
|
Dim sTool As String = String.Empty
|
|
Dim dSpeed As Double = 0
|
|
If EgtSimGetToolInfo(sTool, dSpeed) Then
|
|
If sTool <> m_sCurrTool Then
|
|
m_sCurrTool = sTool
|
|
EgtSetMachineLook(m_nMachLook)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ExitBtnUC_Click(sender As Object, e As RoutedEventArgs)
|
|
' Mi assicuro di terminare la simulazione
|
|
ResetSimulation()
|
|
' Nascondo tutte le lavorazioni
|
|
HideAllMachinings()
|
|
' Cancello eventuali messaggi
|
|
m_CurrProjPage.ClearMessage()
|
|
' Imposto vista 2D
|
|
EgtSetView(VT.TOP, False)
|
|
EgtZoom(ZM.ALL)
|
|
' Abilito impostazione modificato
|
|
EgtEnableModified()
|
|
' Esco dalla pagina
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(Me)
|
|
m_CurrProjPage.CurrProjGrid.Visibility = Windows.Visibility.Visible
|
|
If m_MainWindow.m_PrevActivePage = MainWindow.Pages.CadCut Then
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut
|
|
Else
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_FrameCutPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.FrameCut
|
|
End If
|
|
|
|
End Sub
|
|
|
|
End Class
|