Files
OmagCUT/SingleCutUC.xaml.vb
T
Dario Sassi f8e2af23d3 OmagCUT :
- gestione baffi su tagli di lama
- sistemazione nesting rettangoli.
2015-12-17 10:48:34 +00:00

330 lines
12 KiB
VB.net

Imports EgtUILib
Public Class SingleCutUC
' Riferimento alla MainWindow
Private m_MainWindow As MainWindow = Application.Current.MainWindow
' Spazio per output messaggi
Private m_OutMessageTxBl As TextBlock
' Origine tavola e dati grezzo
Private m_bRawOk As Boolean = False
Private m_ptTabOri As Point3d
Private m_ptRawMin As Point3d
Private m_ptRawMax As Point3d
' Parametri punto acquisito
Private m_bPointOk As Boolean = False
Private m_ptTip As Point3d
Private m_vtTool As Vector3d
' Parametri della lavorazione
Private m_bCutOk As Boolean = False
Private m_dDepth As Double = 0
Private m_dLen As Double = 1000
Private m_dAngO As Double = 180
Private m_dAngV As Double = 0
' Costanti
Private Const MAX_TAB_DEPTH As Double = 10.0
Private Const MIN_CUT_LEN As Double = 10.0
Private Const MAX_SIDE_ANG As Double = 60.0
Private Const DIRECTCUT As String = "DirectCut"
Private Sub SingleCut_Loaded(sender As Object, e As RoutedEventArgs)
m_OutMessageTxBl = m_MainWindow.m_CurrentProjectPageUC.OutMessageTxBl
' Reset punto acquisito
m_bPointOk = False
SawTipTxBl.Text = String.Empty
' Assegno parametri di lavorazione già definiti
DepthTxBx.Text = DoubleToString(m_dDepth, 1)
LenghtTxBx.Text = DoubleToString(m_dLen, 1)
' Origine tavola
m_bRawOk = True
If Not EgtGetTableRef(1, m_ptTabOri) Then
m_bRawOk = False
EgtOutLog("Error on TableRef1")
End If
' Dati del grezzo
If Not m_MainWindow.m_RawPartPage.GetRawBox(m_ptRawMin, m_ptRawMax) Then
m_bRawOk = False
EgtOutLog("Error on RawBox")
End If
' Reset taglio e disabilito bottone esecuzione
m_bCutOk = False
UpdateOkBtn()
' Disabilito registrazione progetto modificato
EgtDisableModified()
End Sub
Private Sub SingleCut_Unloaded(sender As Object, e As RoutedEventArgs)
' Rimuovo eventuale pezzo per taglio diretto
EraseDirectCutPart()
' Riattivo eventuali lavorazioni presenti
ActivateAllMachinings()
' Abilito registrazione progetto modificato
EgtEnableModified()
' Nascondo la macchina
EgtShowOnlyTable(True)
EgtDraw()
End Sub
Private Sub UpdateOkBtn()
If m_bCutOk Then
OkBtn.IsEnabled = True
OkBtn.Foreground = Brushes.Black
Else
OkBtn.IsEnabled = False
OkBtn.Foreground = Brushes.DarkGray
End If
End Sub
Private Sub PointBtn_Click(sender As Object, e As RoutedEventArgs) Handles PointBtn.Click
' Reset punto non acquisito
m_bPointOk = False
SawTipTxBl.Text = String.Empty
' Verifico configurazione tavola e grezzo
If Not m_bRawOk Then
Return
End If
' Recupero la posizione macchina
Dim dL1, dL2, dL3, dR1, dR2 As Double
If Not m_MainWindow.m_CNCommunication.GetAxesPositions(dL1, dL2, dL3, dR1, dR2) Then
Return
End If
' Ricavo dati lama corrente
Dim sSaw As String = String.Empty
GetPrivateProfileString(S_MACH, K_CURRSAW, "", sSaw, m_MainWindow.GetIniFile())
' Se punto da laser
If LaserOnChBx.IsChecked Then
' Imposto come testa corrente il laser (senza utensile ovviamente)
If Not EgtSetCalcTool("", "H3", 1) Then
Return
End If
' Trasformo in posizione punta utensile in basso
If Not EgtGetCalcTipFromPositions(dL1, dL2, dL3, dR1, dR2, True, m_ptTip) Then
Return
End If
' Ora imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then
Return
End If
' Altrimenti da lama
Else
' Imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then
Return
End If
' Trasformo in posizione punta utensile in basso
If Not EgtGetCalcTipFromPositions(dL1, dL2, dL3, dR1, dR2, True, m_ptTip) Then
Return
End If
End If
' Calcolo direzione asse lama
If Not EgtGetCalcToolDirFromAngles(dR1, dR2, m_vtTool) Then
Return
End If
' Porto il tip nell'origine tavola
m_ptTip.ToLoc(New Frame3d(m_ptTabOri))
m_bPointOk = True
' Recupero il nome degli assi macchina
Dim sL1 As String = String.Empty
Dim sL2 As String = String.Empty
Dim sL3 As String = String.Empty
Dim sR1 As String = String.Empty
Dim sR2 As String = String.Empty
m_MainWindow.m_CNCommunication.GetAxesNames(sL1, sL2, sL3, sR1, sR2)
' Visualizzo macchina in posizione
EgtSetAxisPos(sL1, dL1)
EgtSetAxisPos(sL2, dL2)
EgtSetAxisPos(sL3, dL3)
EgtSetAxisPos(sR1, dR1)
EgtSetAxisPos(sR2, dR2)
' Visualizzo quote
Dim sSawTip As String = "X" & DoubleToString(m_ptTip.x, 0) & " Y" & DoubleToString(m_ptTip.y, 0) &
" Z" & DoubleToString(m_ptTip.z, 0) & " C" & DoubleToString(dR1, 0) &
" B" & DoubleToString(dR2, 0)
SawTipTxBl.Text = sSawTip
' Assegno angoli
Dim dTLen, dTAngV, dTAngO As Double
m_vtTool.ToSpherical(dTLen, dTAngV, dTAngO)
m_dAngO = dTAngO + 90
m_dAngV = 90 - dTAngV
DirectionTxBx.Text = DoubleToString(m_dAngO, 2)
SideAngleTxBx.Text = DoubleToString(m_dAngV, 2)
' Disegno il taglio
CreateCut()
EgtShowOnlyTable(False)
EgtDraw()
End Sub
Private Sub DepthTxBx_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles DepthTxBx.PreviewMouseDown
' Predispongo calcolatrice
Dim NumericKeyboardWD As New NumericKeyboardWD(DepthTxBl.Text, DepthTxBx.Text)
' Se inserito nuovo valore
If NumericKeyboardWD.ShowDialog() Then
Dim dMaxDepth = m_ptRawMax.z - m_ptRawMin.z + MAX_TAB_DEPTH
If NumericKeyboardWD.m_DoubleResult < 0 Then
m_dDepth = 0
ElseIf NumericKeyboardWD.m_DoubleResult > dMaxDepth Then
m_dDepth = dMaxDepth
Else
m_dDepth = NumericKeyboardWD.m_DoubleResult
End If
DepthTxBx.Text = DoubleToString(m_dDepth, 2)
End If
' Disegno il taglio
CreateCut()
EgtDraw()
End Sub
Private Sub LenghtTxBx_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles LenghtTxBx.PreviewMouseDown
' Predispongo calcolatrice
Dim NumericKeyboardWD As New NumericKeyboardWD(LenghtTxBl.Text, LenghtTxBx.Text)
' Se inserito nuovo valore
If NumericKeyboardWD.ShowDialog() Then
If NumericKeyboardWD.m_DoubleResult < MIN_CUT_LEN Then
m_dLen = MIN_CUT_LEN
Else
m_dLen = NumericKeyboardWD.m_DoubleResult
End If
LenghtTxBx.Text = DoubleToString(m_dLen, 2)
End If
' Disegno il taglio
CreateCut()
EgtDraw()
End Sub
Private Sub DirectionTxBx_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles DirectionTxBx.PreviewMouseDown
' Predispongo calcolatrice
Dim NumericKeyboardWD As New NumericKeyboardWD(DirectionTxBl.Text, DirectionTxBx.Text, DirectionTxBx)
' Se inserito nuovo valore
If NumericKeyboardWD.ShowDialog() Then
m_dAngO = NumericKeyboardWD.m_DoubleResult
End If
' Disegno il taglio
CreateCut()
EgtDraw()
End Sub
Private Sub SideAngleTxBx_PreviewMouseDown(sender As Object, e As MouseButtonEventArgs) Handles SideAngleTxBx.PreviewMouseDown
' Predispongo calcolatrice
Dim NumericKeyboardWD As New NumericKeyboardWD(SideAngleTxBl.Text, SideAngleTxBx.Text)
' Se inserito nuovo valore
If NumericKeyboardWD.ShowDialog() Then
If NumericKeyboardWD.m_DoubleResult < 0 Then
m_dAngV = 0
ElseIf NumericKeyboardWD.m_DoubleResult > MAX_SIDE_ANG Then
m_dAngV = MAX_SIDE_ANG
Else
m_dAngV = NumericKeyboardWD.m_DoubleResult
End If
SideAngleTxBx.Text = DoubleToString(m_dAngV, 2)
End If
' Disegno il taglio
CreateCut()
EgtDraw()
End Sub
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
' Verifico ci sia un taglio valido
If Not m_bCutOk Then
Return
End If
' Salvo il progetto con le lavorazioni
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\" & "DirectProj.nge"
m_MainWindow.m_CurrentProjectPageUC.SaveFile(sMchPath)
' Genero file CNC (lancio anche se errore in precedenza)
Dim sCncPath As String = m_MainWindow.GetCncDir() & "\DirectCut.xpi"
Dim bOk As Boolean = EgtGenerate(sCncPath, "OmagCut")
' Se errore in generazione, segnalo l'errore ed esco
If Not bOk Then
m_OutMessageTxBl.Text = EgtMsg(90314) 'Errore nella generazione del programma CN
m_OutMessageTxBl.Background = Brushes.Tomato
m_OutMessageTxBl.Visibility = Windows.Visibility.Visible
EgtOutLog(m_OutMessageTxBl.Text)
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
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
m_MainWindow.m_DirectCutPageUC.LeftButtonGrid.Children.Remove(Me)
m_MainWindow.m_DirectCutPageUC.m_ActiveDirectCutPage = DirectCutPageUC.DirectCutPages.DirectCut
End Sub
Private Function CreateCut() As Boolean
' Verifico sia definito il punto iniziale e il grezzo
If Not m_bPointOk Or Not m_bRawOk Then
m_bCutOk = False
Return False
End If
' Spessore grezzo
Dim dRawHeight As Integer = m_ptRawMax.z - m_ptRawMin.z
' Rimuovo eventuale vecchio pezzo per taglio diretto
EraseDirectCutPart()
' Disattivo eventuali lavorazioni presenti
DeactivateAllMachinings()
' Creo nuovo pezzo per il taglio diretto
Dim nPartId = EgtCreateGroup(GDB_ID.ROOT)
EgtSetName(nPartId, DIRECTCUT)
Dim nLayerId = EgtCreateGroup(nPartId)
EgtSetName(nLayerId, "OutLoop")
' Creo il taglio
Dim ptStart As Point3d = m_ptTip
ptStart.z = 0
Dim nCutId = EgtCreateLinePDL(nLayerId, ptStart, m_dAngO, m_dLen)
' Imposto affondamento e angolo di fianco sul taglio
EgtSetInfo(nCutId, "Depth", m_dDepth)
EgtSetInfo(nCutId, "SideAng", m_dAngV)
' Calcolo punto di inserimento nel grezzo
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(nCutId, GDB_BB.STANDARD, ptMin, ptMax)
Dim ptIns As Point3d = ptMin + (m_ptTabOri - m_ptRawMin)
ptIns.z = dRawHeight
' Inserisco il pezzo nel grezzo
EgtAddPartToRawPart(nPartId, ptIns, m_MainWindow.m_CurrentProjectPageUC.m_nRawId)
' Inserisco la lavorazione
m_bCutOk = AddMachinings(nPartId, True, True)
'm_bCutOk = ExecCamDirect()
UpdateOkBtn()
Return m_bCutOk
End Function
Private Function ExecCamDirect() As Boolean
' Inserisco le lavorazioni
Dim sSawMch As String = String.Empty
GetPrivateProfileString(S_MACH, K_CURRMACHINING, "", sSawMch, m_MainWindow.GetIniFile())
EgtLuaCreateGlobTable("CAM")
EgtLuaSetGlobStringVar("CAM.SAWMCH", sSawMch)
Dim bOk As Boolean = EgtLuaExecFile(m_MainWindow.GetCamAutoDir() & "\CamDirect.lua")
Dim nErr As Integer = 999
EgtLuaGetGlobIntVar("CAM.ERR", nErr)
EgtLuaResetGlobVar("CAM")
If nErr <> 0 Then
bOk = False
EgtOutLog("Error in CamDirect : " & nErr.ToString())
End If
Return bOk
End Function
Private Function EraseDirectCutPart()
' Recupero identificativo del pezzo
Dim nDirPartId As Integer = EgtGetFirstNameInGroup(m_MainWindow.m_CurrentProjectPageUC.m_nRawId, DIRECTCUT)
If nDirPartId = GDB_ID.NULL Then
Return True
End If
' Cancello le lavorazioni
EraseMachinings(nDirPartId)
' Tolgo il pezzo dal grezzo
EgtRemovePartFromRawPart(nDirPartId)
' Cancello il pezzo
EgtErase(nDirPartId)
Return True
End Function
End Class