Files
OmagCUT/RawPartPageUC.xaml.vb
T
Emmanuele Sassi bccfb5ca36 OmagCUT :
- Aggiunta navigazione tra le pagine di scelta dei componenti.
- Aggiunti componenti curvi.
2016-02-17 16:22:30 +00:00

650 lines
29 KiB
VB.net

Imports System.Globalization
Imports EgtUILib
Imports EgtWPFLib
Public Class RawPartPageUC
' Riferimento alla MainWindow
Dim m_MainWindow As MainWindow = Application.Current.MainWindow
Dim WithEvents m_CurrProjPage As CurrentProjectPageUC
' Definizione pagina di scelta della lavorazione corrente
Dim m_ChooseMachiningPage As ChooseMachining
' Flag di pagina attiva
Private m_bActive As Boolean = False
' Dati per Drag
Private m_bDrag As Boolean = False
Private m_ptPrev As Point3d
Private m_nDragEnt As Integer = 0
' Modalità aggiornamento variabili
Friend m_bShowVar As Boolean = False
' Dati tavola
Private m_TableLength As Double = 0
Private m_TableWidth As Double = 0
' Dimensioni grezzo rettangolare
Private m_RawLength As Double = 0
Private m_RawWidth As Double = 0
Private m_RawHeight As Double = 0
Private m_RawOffsX As Double = 0
Private m_RawOffsY As Double = 0
Private m_RawKerf As Double = 0
' Costante minima dimensione del grezzo
Private MIN_RAW_DIM As Double = 10
Private Sub RawPartPage_Initialized(sender As Object, e As EventArgs)
'Associazione della lista materiali alla combobox
MaterialsCmbx.ItemsSource = m_MainWindow.m_CurrentMachine.Materials
'Associazione tag textbox e label per visualizzare nome nella calcolatrice
LengthTxBx.Tag = LengthTxBl
WidthTxBx.Tag = WidthTxBl
HeightTxBx.Tag = HeightTxBl
OffsetXTxBx.Tag = OffsetXTxBl
OffsetYTxBx.Tag = OffsetYTxBl
KerfTxBx.Tag = KerfTxBl
'Imposto i messaggi letti dal file dei messaggi
RectangleBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 1) 'Rectangle - Rettangolo
ByPointsBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 2) 'By points - Per punti
LengthTxBl.Text = EgtMsg(MSG_RAWPARTPAGEUC + 3) 'Length - Lunghezza
WidthTxBl.Text = EgtMsg(MSG_RAWPARTPAGEUC + 4) 'Width - Larghezza
HeightTxBl.Text = EgtMsg(MSG_RAWPARTPAGEUC + 5) 'Height - Spessore
OffsetXTxBl.Text = EgtMsg(MSG_RAWPARTPAGEUC + 6) 'Offset X
OffsetYTxBl.Text = EgtMsg(MSG_RAWPARTPAGEUC + 7) 'Offset Y
KerfTxBl.Text = EgtMsg(MSG_RAWPARTPAGEUC + 8) 'Kerf
MaterialGpBx.Header = EgtMsg(MSG_RAWPARTPAGEUC + 9) 'Material - Materiale
DamagedAreaGpBx.Header = EgtMsg(MSG_RAWPARTPAGEUC + 10) 'Damaged area - Zona rovinata
NewBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 11) 'New - Nuovo
DeleteBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 12) 'Delete - Cancella
PointsGpBx.Header = EgtMsg(MSG_RAWPARTPAGEUC + 13) 'Points - Punti
AddBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 14) 'Add - Aggiungi
RemoveBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 15) 'Remove - Rimuovi
RawProbingBtn.Content = EgtMsg(MSG_RAWPARTPAGEUC + 23)
End Sub
Private Sub RawPartPage_Loaded(sender As Object, e As RoutedEventArgs)
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
m_bActive = True
' Dimensioni tavola
Dim ptMin, ptMax As Point3d
If EgtGetTableArea(1, ptMin, ptMax) Then
m_TableLength = ptMax.x - ptMin.x
m_TableWidth = ptMax.y - ptMin.y
End If
' Nascondo eventuali pezzi in parcheggio
HideParkedParts()
' Visualizzo eventuale foto
m_MainWindow.m_CurrentProjectPageUC.ShowPhoto(True)
' Se esiste già il grezzo...
Dim ptRawMin, ptRawMax As Point3d
If GetRawBox(ptRawMin, ptRawMax) Then
' origine tavola
Dim ptOri As Point3d
EgtGetTableRef(1, ptOri)
' kerf
EgtGetInfo(EgtGetFirstRawPart(), KEY_KERF, m_RawKerf)
' aggiorno dati grezzo
m_RawLength = ptRawMax.x - ptRawMin.x - 2 * m_RawKerf
m_RawWidth = ptRawMax.y - ptRawMin.y - 2 * m_RawKerf
m_RawHeight = ptRawMax.z - ptRawMin.z
m_RawOffsX = ptRawMin.x - ptOri.x + m_RawKerf
m_RawOffsY = ptRawMin.y - ptOri.y + m_RawKerf
' aggiorno l'apparenza del grezzo
AdjustRawPartOnStart()
' Altrimenti lo definisco
Else
' Leggo da Ini gli ultimi valori
m_RawLength = GetPrivateProfileDouble(S_RAWPART, K_RAWLENGTH, 2500, m_MainWindow.GetIniFile())
m_RawWidth = GetPrivateProfileDouble(S_RAWPART, K_RAWWIDTH, 1500, m_MainWindow.GetIniFile())
m_RawHeight = GetPrivateProfileDouble(S_RAWPART, K_RAWHEIGHT, 30, m_MainWindow.GetIniFile())
m_RawOffsX = GetPrivateProfileDouble(S_RAWPART, K_RAWOFFSX, 100, m_MainWindow.GetIniFile())
m_RawOffsY = GetPrivateProfileDouble(S_RAWPART, K_RAWOFFSY, 100, m_MainWindow.GetIniFile())
m_RawKerf = GetPrivateProfileDouble(S_RAWPART, K_RAWKERF, 50, m_MainWindow.GetIniFile())
End If
' Deseleziono pezzi
EgtDeselectAll()
' Seleziono modalità rettangolo
RectangleBtn.IsChecked = True
' Assegno dati grezzo rettangolare ai textbox
m_bShowVar = True
LengthTxBx.Text = LenToString(m_RawLength, 2)
WidthTxBx.Text = LenToString(m_RawWidth, 2)
HeightTxBx.Text = LenToString(m_RawHeight, 2)
OffsetXTxBx.Text = LenToString(m_RawOffsX, 2)
OffsetYTxBx.Text = LenToString(m_RawOffsY, 2)
KerfTxBx.Text = LenToString(m_RawKerf, 2)
m_bShowVar = False
' Aggiorno grezzo
UpdateRawPart()
' Imposto il materiale corrente nella combobox
MaterialsCmbx.SelectedItem = m_MainWindow.m_CurrentMachine.CurrMat
End Sub
Private Sub OnMyMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseDownScene
' Verifico di essere il gestore attivo
If Not m_bActive Then
Return
End If
' Si può selezionare solo con il tasto sinistro e se stato NULL
If e.Button <> Windows.Forms.MouseButtons.Left Or
Not m_CurrProjPage.CurrentProjectScene.IsStatusNull() Then
Return
End If
' Verifico cosa selezionato
Dim nSolidId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_RAW_SOLID)
Dim nKerfId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_KERF)
EgtSetObjFilterForSelect(True, True, True, True, True)
Dim nSel As Integer
EgtSelect(e.Location, 2 * Scene.DIM_SEL, 2 * Scene.DIM_SEL, nSel)
Dim nId As Integer = EgtGetFirstObjInSelWin()
While nId <> GDB_ID.NULL
If nSolidId <> GDB_ID.NULL And nId = nSolidId Then
m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev)
m_nDragEnt = 0
ElseIf nKerfId <> GDB_ID.NULL And nId = nKerfId Then
m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev)
Dim dDist, dU As Double
If Not EgtGetMinDistPointCurve(m_ptPrev.Loc(nKerfId), nKerfId, dDist, dU) Then
m_bDrag = False
End If
m_nDragEnt = Math.Ceiling(dU)
' Privilegio il kerf, pertanto esco
Exit While
End If
nId = EgtGetNextObjInSelWin()
End While
End Sub
Private Sub OnMyMouseMoveScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseMoveScene
' Verifico di essere il gestore attivo
If Not m_bActive Then
Return
End If
' Verifico di essere in modalità drag
If Not m_bDrag Then
Return
End If
' Ricavo il punto corrente in coordinate mondo
Dim ptCurr As Point3d
EgtUnProjectPoint(e.Location, ptCurr)
' Se movimento del grezzo
If m_nDragEnt = 0 Then
' Ricavo il vettore di movimento (tengo solo XY)
Dim vtMove As Vector3d = ptCurr - m_ptPrev
vtMove.z = 0
' Muovo il grezzo
If EgtMoveRawPart(m_CurrProjPage.m_nRawId, vtMove) Then
EgtDraw()
' Aggiorno gli offset
m_RawOffsX += vtMove.x
m_RawOffsY += vtMove.y
m_bShowVar = True
OffsetXTxBx.Text = LenToString(m_RawOffsX, 2)
OffsetYTxBx.Text = LenToString(m_RawOffsY, 2)
m_bShowVar = False
End If
' se sposto lato sotto
ElseIf m_nDragEnt = 1 Then
Dim dDelta = ptCurr.y - m_ptPrev.y
If m_RawWidth - dDelta > MIN_RAW_DIM And m_RawOffsY + dDelta > m_RawKerf Then
m_RawWidth -= dDelta
m_RawOffsY += dDelta
EgtModifyRawPartSize(m_CurrProjPage.m_nRawId, m_RawLength + 2 * m_RawKerf,
m_RawWidth + 2 * m_RawKerf, m_RawHeight)
UpdateRawPartKerf()
Dim vtMove As New Vector3d(0, dDelta, 0)
EgtMoveRawPart(m_CurrProjPage.m_nRawId, vtMove)
EgtDraw()
m_bShowVar = True
WidthTxBx.Text = LenToString(m_RawWidth, 2)
OffsetYTxBx.Text = LenToString(m_RawOffsY, 2)
m_bShowVar = False
End If
' se sposto lato a destra
ElseIf m_nDragEnt = 2 Then
Dim dDelta = ptCurr.x - m_ptPrev.x
If m_RawLength + dDelta > MIN_RAW_DIM And
m_RawOffsX + m_RawLength + dDelta + m_RawKerf < m_TableLength Then
m_RawLength += dDelta
EgtModifyRawPartSize(m_CurrProjPage.m_nRawId, m_RawLength + 2 * m_RawKerf,
m_RawWidth + 2 * m_RawKerf, m_RawHeight)
UpdateRawPartKerf()
EgtDraw()
m_bShowVar = True
LengthTxBx.Text = LenToString(m_RawLength, 2)
m_bShowVar = False
End If
' se sposto lato sopra
ElseIf m_nDragEnt = 3 Then
Dim dDelta = ptCurr.y - m_ptPrev.y
If m_RawWidth + dDelta > MIN_RAW_DIM And
m_RawOffsY + m_RawWidth + dDelta + m_RawKerf < m_TableWidth Then
m_RawWidth += dDelta
EgtModifyRawPartSize(m_CurrProjPage.m_nRawId, m_RawLength + 2 * m_RawKerf,
m_RawWidth + 2 * m_RawKerf, m_RawHeight)
UpdateRawPartKerf()
EgtDraw()
m_bShowVar = True
WidthTxBx.Text = LenToString(m_RawWidth, 2)
m_bShowVar = False
End If
' se sposto lato a sinistra
ElseIf m_nDragEnt = 4 Then
Dim dDelta = ptCurr.x - m_ptPrev.x
If m_RawLength - dDelta > MIN_RAW_DIM And m_RawOffsX + dDelta > m_RawKerf Then
m_RawLength -= dDelta
m_RawOffsX += dDelta
EgtModifyRawPartSize(m_CurrProjPage.m_nRawId, m_RawLength + 2 * m_RawKerf,
m_RawWidth + 2 * m_RawKerf, m_RawHeight)
UpdateRawPartKerf()
Dim vtMove As New Vector3d(dDelta, 0, 0)
EgtMoveRawPart(m_CurrProjPage.m_nRawId, vtMove)
EgtDraw()
m_bShowVar = True
LengthTxBx.Text = LenToString(m_RawLength, 2)
OffsetXTxBx.Text = LenToString(m_RawOffsX, 2)
m_bShowVar = False
End If
End If
' Aggiorno il punto precedente
m_ptPrev = ptCurr
End Sub
Private Sub OnMyMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseUpScene
' Verifico di essere il gestore attivo
If Not m_bActive Then
Return
End If
' Disabilito modalità drag
m_bDrag = False
End Sub
Private Sub MaterialsCmbx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles MaterialsCmbx.SelectionChanged
If Not IsNothing(MaterialsCmbx.SelectedItem) Then
m_MainWindow.m_CurrentMachine.CurrMat = MaterialsCmbx.SelectedItem
m_CurrProjPage.MaterialTxBx.Text = m_MainWindow.m_CurrentMachine.CurrMat.sName
Else
m_MainWindow.m_CurrentMachine.CurrMat = Nothing
m_CurrProjPage.MaterialTxBx.Text = "Non definito"
End If
End Sub
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
' Apro pagina di selezione della lavorazione prima di chiudere il grezzo
m_ChooseMachiningPage = New ChooseMachining(m_MainWindow)
If m_ChooseMachiningPage.DialogResult Then
' Sistemo il grezzo
AdjustRawPartOnExit()
' Ripristino visualizzazione di eventuali pezzi in parcheggio
ShowParkedParts()
' Imposto spessore del grezzo
m_CurrProjPage.m_dRawHeight = GetRawHeight()
m_CurrProjPage.UpdateHeightTxBx()
' Salvo nel file Ini le dimensioni del grezzo (sempre in mm)
WritePrivateProfileString(S_RAWPART, K_RAWLENGTH, DoubleToString(m_RawLength, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_RAWPART, K_RAWWIDTH, DoubleToString(m_RawWidth, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_RAWPART, K_RAWHEIGHT, DoubleToString(m_RawHeight, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_RAWPART, K_RAWOFFSX, DoubleToString(m_RawOffsX, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_RAWPART, K_RAWOFFSY, DoubleToString(m_RawOffsY, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_RAWPART, K_RAWKERF, DoubleToString(m_RawKerf, 2), m_MainWindow.GetIniFile())
' Esco dalla pagina
m_bActive = False
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(Me)
m_CurrProjPage.CurrProjGrid.Visibility = Windows.Visibility.Visible
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC)
m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut
End If
End Sub
Private Sub RectangleBtnUC_Click(sender As Object, e As RoutedEventArgs) Handles RectangleBtn.Click
'Seleziono il bottone RectangleBtn
RectangleBtn.IsChecked = True
End Sub
Friend Sub UpdateRawPart(Optional bHeightModified As Boolean = False)
' Se cambiato spessore e c'è foto, aggiorno quota fotografia
If bHeightModified And m_CurrProjPage.GetPhoto() <> GDB_ID.NULL Then
' Aggiorno spessore in progetto corrente
m_CurrProjPage.m_dRawHeight = m_RawHeight
m_CurrProjPage.UpdateHeightTxBx()
' Ricarico fotografia
Dim sPath As String = String.Empty
EgtGetPhotoPath(m_CurrProjPage.GetPhoto(), sPath)
m_MainWindow.m_CadCutPageUC.PostPhoto(sPath)
End If
' Recupero il colore
Dim Col As New Color3d(64, 192, 255, 40)
GetPrivateProfileColor(S_RAWPART, K_RAWCOLOR, Col, m_MainWindow.GetIniFile())
' in presenza di foto rendo molto più trasparente
If m_CurrProjPage.GetPhoto() <> GDB_ID.NULL Then
Col.A = 20
End If
' Se non esiste già il grezzo e richiesto, lo inserisco
Dim nRawId As Integer = EgtGetFirstRawPart()
If nRawId = GDB_ID.NULL And m_RawHeight > EPS_SMALL Then
m_CurrProjPage.m_nRawId = EgtAddRawPart(Point3d.ORIG(), m_RawLength + 2 * m_RawKerf,
m_RawWidth + 2 * m_RawKerf, m_RawHeight, Col)
' se esiste e da cancellare
ElseIf m_RawHeight < EPS_SMALL Then
EgtRemoveRawPart(nRawId)
m_CurrProjPage.m_nRawId = GDB_ID.NULL
' Altrimenti lo modifico
Else
m_CurrProjPage.m_nRawId = nRawId
EgtModifyRawPart(nRawId, Point3d.ORIG(), m_RawLength + 2 * m_RawKerf,
m_RawWidth + 2 * m_RawKerf, m_RawHeight, Col)
End If
' Se non cancellato
If m_RawHeight > EPS_SMALL Then
UpdateRawPartKerf()
' Sistemo la posizione
Dim ptRef As New Point3d(m_RawOffsX - m_RawKerf, m_RawOffsY - m_RawKerf, m_CurrProjPage.m_dAddTable)
If EgtMoveToCornerRawPart(m_CurrProjPage.m_nRawId, ptRef, MCH_CR.BL) Then
OkBtn.IsEnabled = True
m_CurrProjPage.ClearMessage()
Else
OkBtn.IsEnabled = False
m_CurrProjPage.SetErrorMessage("Errore nella posizione o dimensione del grezzo")
End If
End If
' Aggiorno visualizzazione
EgtZoom(ZM.ALL)
End Sub
Private Function UpdateRawPartKerf() As Boolean
' Se non c'è il grezzo, esco
If m_CurrProjPage.m_nRawId = GDB_ID.NULL Then
Return False
End If
' Recupero il vecchio valore del kerf
Dim dOldKerf As Double
If Not EgtGetInfo(m_CurrProjPage.m_nRawId, KEY_KERF, dOldKerf) Then
dOldKerf = GetPrivateProfileDouble(S_RAWPART, K_RAWKERF, 30, m_MainWindow.GetIniFile())
End If
' Cancello eventuale vecchio contorno di kerf
Dim nKerfId As Integer = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_KERF)
EgtErase(nKerfId)
' Cancello eventuale vecchia regione fuori kerf per nesting
Dim nOutKerfId As Integer = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_OUTKERF)
EgtErase(nOutKerfId)
' box grezzo
Dim ptMin, ptMax As Point3d
GetRawBox(ptMin, ptMax)
ptMin.x += m_RawKerf
ptMin.y += m_RawKerf
ptMin.z = ptMax.z
ptMax.x -= m_RawKerf
ptMax.y -= m_RawKerf
' Creo il nuovo contorno del kerf
nKerfId = EgtCreateRectangle2P(m_CurrProjPage.m_nRawId, ptMin, ptMax, GDB_RT.GLOB)
EgtSetName(nKerfId, NAME_KERF)
Dim Col As New Color3d(255, 0, 0, 100)
GetPrivateProfileColor(S_RAWPART, K_KERFCOLOR, Col, m_MainWindow.GetIniFile())
EgtSetColor(nKerfId, Col)
' Salvo il nuovo valore (sempre in mm)
EgtSetInfo(m_CurrProjPage.m_nRawId, KEY_KERF, DoubleToString(m_RawKerf, 4))
Return True
End Function
Private Sub AdjustRawPartOnStart()
' Se non c'è la foto va già bene così
If m_CurrProjPage.GetPhoto() = GDB_ID.NULL Then
Return
End If
' Disabilito la texture sul grezzo
Dim nSolidId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_RAW_SOLID)
EgtRemoveTextureData(nSolidId)
' Sistemo il colore
Dim Col As New Color3d(64, 192, 255, 40)
GetPrivateProfileColor(S_RAWPART, K_RAWCOLOR, Col, m_MainWindow.GetIniFile())
Col.A = 20
EgtSetColor(nSolidId, Col, True)
End Sub
Private Sub AdjustRawPartOnExit()
' Se non c'è il grezzo, esco
If m_CurrProjPage.m_nRawId = GDB_ID.NULL Then
Return
End If
' Se non c'è la foto va già bene così
If m_CurrProjPage.GetPhoto() = GDB_ID.NULL Then
Return
End If
' Carico la texture della foto sul grezzo
Dim nSolidId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_RAW_SOLID)
EgtSetTextureName(nSolidId, PHOTO_NAME)
' Sistemo il riferimento della texture
Dim refTxr As New Frame3d
m_CurrProjPage.GetPhotoTextureRef(refTxr)
EgtSetTextureFrame(nSolidId, refTxr, GDB_RT.GLOB)
' Sistemo il colore
EgtSetColor(nSolidId, New Color3d(255, 255, 255, 100), True)
' Nascondo la foto
m_MainWindow.m_CurrentProjectPageUC.ShowPhoto(False)
m_bActive = False
End Sub
Private Sub LengthTxBx_EgtClosed(sender As Object, e As EventArgs) Handles LengthTxBx.EgtClosed
Dim dLength As Double
If Not StringToLen(LengthTxBx.Text, dLength) Or dLength < EPS_SMALL Then
Return
End If
Dim dMaxLen = m_TableLength - m_RawOffsX - m_RawKerf
If dLength <= dMaxLen Then
m_CurrProjPage.ClearMessage()
m_RawLength = dLength
UpdateRawPart()
Else
LengthTxBx.Text = LenToString(m_RawLength, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 16) & " " & LenToString(dMaxLen, 2)) 'Massima lunghezza =
End If
End Sub
Private Sub WidthTxBx_EgtClosed(sender As Object, e As EventArgs) Handles WidthTxBx.EgtClosed
Dim dWidth As Double
If Not StringToLen(WidthTxBx.Text, dWidth) Or dWidth < EPS_SMALL Then
Return
End If
Dim dMaxWidth = m_TableWidth - m_RawOffsY - m_RawKerf
If dWidth <= dMaxWidth Then
m_CurrProjPage.ClearMessage()
m_RawWidth = dWidth
UpdateRawPart()
Else
WidthTxBx.Text = LenToString(m_RawWidth, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 17) & " " & LenToString(dMaxWidth, 2)) 'Massima larghezza =
End If
End Sub
Private Sub HeightTxBx_EgtClosed(sender As Object, e As EventArgs) Handles HeightTxBx.EgtClosed
Dim dHeight As Double
If Not StringToLen(HeightTxBx.Text, dHeight) Then
Return
End If
If dHeight > -EPS_ZERO Then
m_CurrProjPage.ClearMessage()
If Math.Abs(dHeight - m_RawHeight) > EPS_SMALL Then
m_RawHeight = dHeight
UpdateRawPart(True)
End If
Else
HeightTxBx.Text = LenToString(m_RawHeight, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 18)) 'Non sono ammessi spessori negativi
End If
End Sub
Private Sub OffsetXTxBx_EgtClosed(sender As Object, e As EventArgs) Handles OffsetXTxBx.EgtClosed
Dim dOffsetX As Double
If Not StringToLen(OffsetXTxBx.Text, dOffsetX) Then
Return
End If
Dim dMinOffsetX = m_RawKerf
If dOffsetX >= dMinOffsetX Then
m_RawOffsX = dOffsetX
UpdateRawPart()
Else
OffsetXTxBx.Text = LenToString(m_RawOffsX, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 19) & " " & LenToString(dMinOffsetX, 2)) 'Minimo offset X =
End If
End Sub
Private Sub OffsetYTxBx_EgtClosed(sender As Object, e As EventArgs) Handles OffsetYTxBx.EgtClosed
Dim dOffsetY As Double
If Not StringToLen(OffsetYTxBx.Text, dOffsetY) Then
Return
End If
Dim dMinOffsetY = m_RawKerf
If dOffsetY >= dMinOffsetY Then
m_RawOffsY = dOffsetY
UpdateRawPart()
Else
OffsetYTxBx.Text = LenToString(m_RawOffsY, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 20) & " " & LenToString(dMinOffsetY, 2)) 'Minimo offset Y =
End If
End Sub
Private Sub KerfTxBx_EgtClosed(sender As Object, e As EventArgs) Handles KerfTxBx.EgtClosed
Dim dKerf As Double
If Not StringToLen(KerfTxBx.Text, dKerf) Then
Return
End If
Dim dMinKerf = 0
Dim dMaxKerf = Math.Min(Math.Min(m_RawOffsX, m_RawOffsY),
Math.Min(m_TableLength - m_RawLength - m_RawOffsX, m_TableWidth - m_RawWidth - m_RawOffsY))
If dKerf >= dMinKerf And dKerf <= dMaxKerf Then
m_RawKerf = dKerf
UpdateRawPart()
ElseIf dKerf < dMinKerf Then
KerfTxBx.Text = LenToString(m_RawKerf, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 21) & " " & LenToString(dMinKerf, 2)) 'Minimo kerf =
Else
KerfTxBx.Text = LenToString(m_RawKerf, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 22) & " " & LenToString(dMaxKerf, 2)) 'Massimo kerf =
End If
End Sub
Private Sub RawProbingBtn_Click(sender As Object, e As RoutedEventArgs) Handles RawProbingBtn.Click
' Recupero origine tavola rispetto allo 0 macchina
Dim TableRef As Point3d
EgtGetTableRef(1, TableRef)
' Recupero file LUA
EgtLuaExecFile(m_MainWindow.GetMachinesRootDir() & "\" & m_MainWindow.GetCurrMachine() & "\DirectCmd\RawProbing.lua")
' Imposto parametri
EgtLuaSetGlobNumVar("CMD.MIDRAWX", m_RawOffsX + m_RawLength / 2)
EgtLuaSetGlobNumVar("CMD.MIDRAWY", m_RawOffsY + m_RawWidth / 2)
EgtLuaSetGlobNumVar("CMD.THICK", m_RawHeight)
EgtLuaSetGlobNumVar("CMD.TABLEX", TableRef.x)
EgtLuaSetGlobNumVar("CMD.TABLEY", TableRef.y)
EgtLuaSetGlobNumVar("CMD.TABLEZ", TableRef.z)
EgtLuaCallFunction("CMD.CmdString")
' Leggo variabili
Dim CmdString As String = String.Empty
EgtLuaGetGlobStringVar("CMD.CMDSTRING", CmdString)
' Reset lua
EgtLuaResetGlobVar("CMD")
' Modifico stringa per inserire i newline
CmdString = CmdString.Replace("<br/>", Environment.NewLine)
' Creo file...
Dim FilePath As String = m_MainWindow.GetCncDir() & "\RawProbing.xpi"
' ...e ci scrivo
Dim Writer As New IO.StreamWriter(FilePath, False)
Writer.Write(CmdString)
Writer.Close()
' Verifico se sono connesso alla macchina prima di continuare
If Not m_MainWindow.m_bNCLink Then
Exit Sub
End If
' Mando file al CN
m_MainWindow.m_CNCommunication.SendProgram(FilePath, 900)
' Aspetto e lo avvio
System.Threading.Thread.Sleep(300)
m_MainWindow.m_CNCommunication.m_CN.DGeneralFunctions_CycleStart()
' Creo MsgBox di attesa
Dim MsgBoxStateInfo As New EgtMsgBox(m_MainWindow, EgtMsg(MSG_RAWPARTPAGEUC + 25), EgtMsg(MSG_RAWPARTPAGEUC + 26), True, EgtMsgBox.Icons.NULL)
Dim ProbingStateNameVar As String = String.Empty
GetPrivateProfileString(S_MACH_PROBING, K_PROBINGSTATEVAR, "", ProbingStateNameVar, m_MainWindow.GetMachIniFile())
m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 0
m_MainWindow.m_CNCommunication.m_CN.ReadEls_Add_Parameter(ProbingStateNameVar, 1)
' Definisco flag tastatura
Dim bProbingOk As Boolean = False
For I = 0 To 120
If m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 1 Then
Dim L108Val As Integer = m_MainWindow.m_CNCommunication.m_CN.d_DReadELS_value
Select Case L108Val
Case 0
' Non faccio alcunchè perchè sta tastando
Case 1
' Tastatura completata
bProbingOk = True
Exit For
Case 2
' Errore
bProbingOk = False
Exit For
End Select
End If
System.Threading.Thread.Sleep(1000)
' Incremento progressbar
MsgBoxStateInfo.LoadingPrBr_Value += 100 / 120
' Costringo ad aggiornare GUI
Dim nDummy As Integer
Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, New Action(Function() nDummy = 0))
Next
If bProbingOk Then
' Leggo spessore misurato
Dim RawThicknessNameVar As String = String.Empty
GetPrivateProfileString(S_MACH_PROBING, K_PROBINGSTATEVAR, "", RawThicknessNameVar, m_MainWindow.GetMachIniFile())
m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 0
m_MainWindow.m_CNCommunication.m_CN.ReadEls_Add_Parameter(RawThicknessNameVar, 1)
Dim RawThickness As Double = 0
For I = 0 To 20
If m_MainWindow.m_CNCommunication.m_CN.n_DReadELS_handle = 1 Then
RawThickness = m_MainWindow.m_CNCommunication.m_CN.d_DReadELS_value
MsgBoxStateInfo.LoadingPrBr_Value = 100
MsgBoxStateInfo.Text = EgtMsg(MSG_RAWPARTPAGEUC + 27)
' Costringo ad aggiornare GUI
Dim nDummy As Integer
Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, New Action(Function() nDummy = 0))
System.Threading.Thread.Sleep(1500)
'Trasformo misura rilevata in mm
If m_MainWindow.m_CNCommunication.m_CN.Is_G71_active() Then
RawThickness *= ONEMM / 1000
Else
RawThickness *= ONEINCH / 1000
End If
' Imposto spessore misurato come altezza grezzo
If RawThickness > -EPS_ZERO Then
m_CurrProjPage.ClearMessage()
If Math.Abs(RawThickness - m_RawHeight) > EPS_SMALL Then
HeightTxBx.Text = RawThickness
m_RawHeight = RawThickness
UpdateRawPart(True)
End If
Else
HeightTxBx.Text = LenToString(m_RawHeight, 2)
m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_RAWPARTPAGEUC + 18)) 'Non sono ammessi spessori negativi
End If
' Chiudo msgbox
MsgBoxStateInfo.Close()
Exit For
End If
System.Threading.Thread.Sleep(100)
Next
Else
MsgBoxStateInfo.Text = EgtMsg(MSG_RAWPARTPAGEUC + 28)
' Costringo ad aggiornare GUI
Dim nDummy As Integer
Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, New Action(Function() nDummy = 0))
System.Threading.Thread.Sleep(1500)
MsgBoxStateInfo.Close()
End If
End Sub
Private Sub RawPartPage_Unloaded(sender As Object, e As RoutedEventArgs)
End Sub
End Class