Files
OmagCUT/DirectCuts/FlatteningCut.xaml.vb
T
Dario Sassi daeaec3b6b OmagCUT :
- correzioni a spianature con fresa (tagli diretti)
- migliorie a foro singolo (tagli diretti).
2026-04-23 16:53:43 +02:00

905 lines
40 KiB
VB.net

Imports EgtUILib
Imports EgtUILib.EgtInterface
Imports OmagCUT.MainWindow
Public Class FlatteningCut
' Riferimenti a pagine
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
Private WithEvents m_CurrProjPage As CurrentProjectPageUC
' Flag di pagina attiva
Private m_bActive As Boolean = False
' Flag di simulazione in corso
Private m_bSimul As Boolean = False
' Definizione del taglio diretto di questa pagina
Private Const FLATTENING As String = "Flattening"
' 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 P1 acquisito
Private m_bPointP1Ok As Boolean = False
Private m_ptTipP1 As Point3d
Private m_vtToolP1 As Vector3d
' Parametri P2 acquisito
Private m_bPointP2Ok As Boolean = False
Private m_ptTipP2 As Point3d
Private m_vtToolP2 As Vector3d
' Parametri della lavorazione
Private m_bCutOk As Boolean = False
Private m_dDepth As Double = 0
Private m_dAngO As Double = 180
Private m_dLen As Double = 500
Private m_dWid As Double = 500
Private m_dOverlap As Double = 1
Private m_dZReleased As Double = 50 ' alteza di uscita utensile
Private m_bHeadSide As Boolean = False
Private m_nMachType As Integer = 1
Private m_bRotLock As Boolean = False
Private m_bChainedPath As Boolean = True
Private m_nTool As Integer = 0
' Array delle modalità di acquisizione dei punti
Private m_PointsModeArray(2) As String
' Array delle tipologia di lavorazione della spianatura
Private m_TypeArray(2) As String
' Punto selezionato nel disegno
Private m_ptPrev As Point3d
' Layer per crocette temporanee
Private m_nTempLay As Integer = GDB_ID.NULL
' Array degliutensili disponibili (lama e fresa)
Private m_ToolsArray(1) As String
' Costanti
Private Const MAX_TAB_DEPTH As Double = 10.0
Private Const MIN_CUT_LEN As Double = 10.0
Private Const MIN_CUT_WID As Double = 10.0
Private Const MAX_SIDE_ANG As Double = 60.0
' Costanti che indicano la modalità di acquisizione dei punti
Private Enum PT_MODE As Integer
SAW = 0
LASER = 1
DRAW = 2
End Enum
' Costanti che indicano la tipologia di lavorazione della spianatura
Private Enum MACH_TYPE As Integer
ZIGZAG = 0
ONEWAY = 1
SPIRAL = 2
End Enum
'Costante che indica il lato in cui posizionare i tagli
Private Enum CutSide As Integer
Left
Right
End Enum
Private Enum TOOL As Integer
SAW = 0
MILL = 1
End Enum
' Per abilitare la spianatura con la FRESA deve essere imposatato a TRUE il flag "Usa Fresa" nella pagina MACCHINA (campo INCISIONI)
Private Sub FlatteningCut_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
' Creo lista modalità di acquisizione punto
m_PointsModeArray(PT_MODE.SAW) = EgtMsg(90224) ' Lama
m_PointsModeArray(PT_MODE.LASER) = EgtMsg(90212) ' Laser
m_PointsModeArray(PT_MODE.DRAW) = EgtMsg(90225) ' Disegno
' la associo alla combobox
PointModeCmBx.ItemsSource = m_PointsModeArray
' Creo lista tipo lavorazione
m_TypeArray(MACH_TYPE.ZIGZAG) = EgtMsg(90838) ' ZigZag
m_TypeArray(MACH_TYPE.ONEWAY) = EgtMsg(90839) ' OneWay
m_TypeArray(MACH_TYPE.SPIRAL) = EgtMsg(90851) ' Spirale
' la associo alla combobox
TypeCmBx.ItemsSource = m_TypeArray
' assegno messaggi
Point1Btn.ToolTip = EgtMsg(90210) ' Acquisisci P1
Point2Btn.ToolTip = EgtMsg(90211) ' Acquisisci P2
DepthTxBl.Text = EgtMsg(90213) ' Affondamento
LenghtTxBl.Text = EgtMsg(90214) ' Lunghezza
DirectionTxBl.Text = EgtMsg(90215) ' Direzione
WidthTxBl.Text = EgtMsg(90226) ' Larghezza
OverlapTxBl.Text = EgtMsg(90227) ' Sovrapposizione
ZReleasedTxBl.Text = EgtMsg(91235) ' Z Svincolo
SideTxBl.Text = EgtMsg(90223) ' Tagli lato motore
RotLockTxBl.Text = EgtMsg(90229) ' Blocca Asse C
ChainedPathTxBl.Text = EgtMsg(91236) ' Chained path
SimulBtn.ToolTip = EgtMsg(90301) ' Simula
OkBtn.ToolTip = EgtMsg(90230) ' Esegui
' tipo di utensile in uso per la lavorazione
m_ToolsArray(TOOL.SAW) = EgtMsg(90224) ' Lama
m_ToolsArray(TOOL.MILL) = EgtMsg(91237) ' Fresa
SelToolCmBx.ItemsSource = m_ToolsArray
' Carico i dati dell'ultimo taglio
m_dDepth = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_DEPTH, m_dDepth, m_MainWindow.GetIniFile())
m_dAngO = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_ANGH, m_dAngO, m_MainWindow.GetIniFile())
m_dLen = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_LENGTH, m_dLen, m_MainWindow.GetIniFile())
m_dWid = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_WIDTH, m_dWid, m_MainWindow.GetIniFile())
m_dOverlap = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_OVERLAP, m_dOverlap, m_MainWindow.GetIniFile())
m_dZReleased = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_Z_RELEASED, m_dZReleased, m_MainWindow.GetIniFile())
m_bHeadSide = (GetPrivateProfileInt(S_DIRECTCUTS, K_DC_FLATT_HEADSIDE, 0, m_MainWindow.GetIniFile()) <> 0)
m_nMachType = GetPrivateProfileInt(S_DIRECTCUTS, K_DC_FLATT_MACHTYPE, m_nMachType, m_MainWindow.GetIniFile())
m_bRotLock = (GetPrivateProfileInt(S_DIRECTCUTS, K_DC_FLATT_ROTLOCK, 0, m_MainWindow.GetIniFile()) <> 0)
m_bChainedPath = (GetPrivateProfileInt(S_DIRECTCUTS, K_DC_FLAT_CHAINEDPATH, 0, m_MainWindow.GetIniFile()) <> 0)
m_nTool = GetPrivateProfileInt(S_MACH_NEST, K_MACH_ENGRAVING_WITHMILL, 1, m_MainWindow.GetMachIniFile())
m_ptTipP1.x = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_POSX, m_ptTipP1.x, m_MainWindow.GetIniFile())
m_ptTipP1.y = GetPrivateProfileDouble(S_DIRECTCUTS, K_DC_FLATT_POSY, m_ptTipP1.y, m_MainWindow.GetIniFile())
End Sub
Private Sub FlatteningCut_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
' Attivo la pagina
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
m_bActive = True
' Se rientro da simulazione
If m_bSimul Then
m_bSimul = False
' Disabilito registrazione progetto modificato
EgtDisableModified()
' Aggiorno visualizzazione
SetMachineInCurrPos()
m_MainWindow.m_DirectCutPageUC.m_bShowMachine = True
EgtSetMachineLook(m_MainWindow.m_DirectCutPageUC.m_nMachLook)
EgtDraw()
Return
End If
' Disabilito registrazione progetto modificato
EgtDisableModified()
' Creo layer temporaneo per crocette
m_nTempLay = EgtCreateGroup(GDB_ID.ROOT)
EgtSetLevel(m_nTempLay, GDB_LV.TEMP)
' 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 GetRawBox(m_ptRawMin, m_ptRawMax) Then
m_bRawOk = False
EgtOutLog("Error on RawBox")
End If
' Reset punto acquisito
m_bPointP1Ok = False
m_bPointP2Ok = False
' Inizializzo primo punto acquisito dal disegno
m_ptPrev = m_ptTipP1 + (m_ptTabOri - Point3d.ORIG())
m_ptPrev.z = m_ptRawMax.z
' Disegno crocetta che indica il punto acquisito
CreateCross(m_nTempLay, m_ptPrev)
' Imposto modalità di acquisizione punti
PointModeCmBx.SelectedIndex = PT_MODE.DRAW
SetCoordVisibility(True)
ShowCoord()
' Assegno parametri di lavorazione già definiti
DepthTxBx.Text = LenToString(m_dDepth, 1)
DirectionTxBx.Text = DoubleToString(m_dAngO - m_MainWindow.m_CurrentMachine.dDeltaC, 2)
LenghtTxBx.Text = LenToString(m_dLen, 1)
WidthTxBx.Text = LenToString(m_dWid, 2)
OverlapTxBx.Text = LenToString(m_dOverlap, 2)
ZReleasedTxBx.Text = LenToString(m_dZReleased, 2)
' carico la quota di svincolo per la spianatura
EgtMdbSetGeneralParam(MCH_GP.SAFEZ, m_dZReleased)
EgtMdbSave()
SideChBx.IsChecked = m_bHeadSide
TypeCmBx.SelectedIndex = m_nMachType
RotLockChBx.IsChecked = m_bRotLock
ChainedPathChBx.IsChecked = m_bChainedPath
' Assegno l'utensile definito in macchina per la fresatura
SelToolCmBx.SelectedIndex = m_nTool
' Reset taglio e disabilito bottone esecuzione
m_bCutOk = False
UpdateSimulOkBtn()
' Disabilito bottone secondo punto
Point2Btn.IsEnabled = False
' Deseleziono bottone primo punto
Point1Btn.IsChecked = False
' Aggiorno visualizzazione
EgtDraw()
End Sub
Friend Sub FlatteningCut_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
' Salvo i dati correnti
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_DEPTH, DoubleToString(m_dDepth, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_ANGH, DoubleToString(m_dAngO, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_LENGTH, DoubleToString(m_dLen, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_WIDTH, DoubleToString(m_dWid, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_OVERLAP, DoubleToString(m_dOverlap, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_Z_RELEASED, DoubleToString(m_dZReleased, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_HEADSIDE, If(m_bHeadSide, "1", "0"), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_MACHTYPE, m_nMachType.ToString(), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_ROTLOCK, If(m_bRotLock, "1", "0"), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_POSX, DoubleToString(m_ptTipP1.x, 2), m_MainWindow.GetIniFile())
WritePrivateProfileString(S_DIRECTCUTS, K_DC_FLATT_POSY, DoubleToString(m_ptTipP1.y, 2), m_MainWindow.GetIniFile())
' Se non vado in simulazione
If Not m_bSimul Then
' imposto la Z di sicurezza corretta
EgtMdbSetGeneralParam(MCH_GP.SAFEZ, DirectCutPageUC.m_dZSafe)
EgtMdbSave()
' Dichiaro sottopagina da non riattivare
m_MainWindow.m_DirectCutPageUC.m_ControlsDirectCutUC.m_ActiveDirectCutPage = ControlsDirectCutUC.DirectCutPages.DirectCut
' Rimuovo layer temporaneo per crocette
EgtErase(m_nTempLay)
' Rimuovo eventuale pezzo per taglio diretto
EraseDirectCutPart()
' Riattivo eventuali lavorazioni presenti
ActivateAllMachinings()
' Abilito registrazione progetto modificato
EgtEnableModified()
' Nascondo la macchina
m_MainWindow.m_DirectCutPageUC.m_bShowMachine = False
EgtSetMachineLook(MCH_LOOK.TAB)
EgtDraw()
End If
' Dichiaro pagina non attiva
m_bActive = False
End Sub
Private Sub UpdateSimulOkBtn()
If m_bCutOk Then
SimulBtn.IsEnabled = True
SimulBtn.Foreground = Brushes.Black
OkBtn.IsEnabled = True
OkBtn.Foreground = Brushes.Black
Else
SimulBtn.IsEnabled = False
SimulBtn.Foreground = Brushes.DarkGray
OkBtn.IsEnabled = False
OkBtn.Foreground = Brushes.DarkGray
End If
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
' 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
' Rimuovo eventuali crocette create acquisendo i punti nel disegno
EgtEmptyGroup(m_nTempLay)
' Acquisisco punto da disegno
EgtUnProjectPoint(e.Location, m_ptPrev)
' Aggiusto Z punto acquisito (è in globale)
Dim dPtPrevZ As Double = m_ptPrev.z
m_ptPrev.z = m_ptRawMax.z
' Se direzione di vista calcolabile e da sopra posso aggiustare anche XY
Dim dAngVertDeg, dAngHorizDeg As Double
If EgtGetGenericView(dAngVertDeg, dAngHorizDeg) Then
Dim vtDir As Vector3d = Vector3d.FromSpherical(1, dAngVertDeg, dAngHorizDeg)
If vtDir.z > EPS_SMALL Then
m_ptPrev.z = dPtPrevZ
m_ptPrev += vtDir * (m_ptRawMax.z - m_ptPrev.z) / vtDir.z
End If
End If
' Visualizzo coordinate (rispetto a 0 tavola)
ShowCoord()
' Disegno crocetta che indica il punto acquisito
CreateCross(m_nTempLay, m_ptPrev)
EgtDraw()
End Sub
Private Sub PointModeCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles PointModeCmBx.SelectionChanged
SetCoordVisibility(PointModeCmBx.SelectedIndex = PT_MODE.DRAW)
End Sub
Private Sub Point1Btn_Click(sender As Object, e As RoutedEventArgs) Handles Point1Btn.Click
' Rimuovo eventuali crocette create acquisendo i punti nel disegno
EgtEmptyGroup(m_nTempLay)
' Reset punto non acquisito
m_bPointP1Ok = False
' Verifico configurazione tavola e grezzo
If Not m_bRawOk Then Return
' forzo utilizzo testa H1 solo per macchina con 2 teste
Dim bIsMultiCut As Boolean = (EgtGetHeadId("H101") <> GDB_ID.NULL)
' Ricavo dati lama corrente
Dim sSaw As String = m_MainWindow.m_CurrentMachine.sCurrSaw
If bIsMultiCut Then
EgtSetCalcTool(sSaw, "H1", 1)
End If
' Se acquisizone lama o laser
If PointModeCmBx.SelectedIndex = PT_MODE.SAW Or PointModeCmBx.SelectedIndex = PT_MODE.LASER Then
' 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
' Se macchina multicut il primo asse rotante restituito è quello della tavola
Dim vAng() As Double = {dR1, dR2, 0}
If bIsMultiCut Then
vAng(0) = 0
vAng(1) = dR1
vAng(2) = dR2
End If
' Se punto da laser
If PointModeCmBx.SelectedIndex = PT_MODE.LASER Then
' Imposto come testa corrente il laser (senza utensile ovviamente)
If Not EgtSetCalcTool("", "H3", 1) Then Return
' Trasformo in posizione punta utensile in basso
If Not EgtGetCalcTipFromPositions(dL1, dL2, dL3, vAng, True, m_ptTipP1) Then Return
' Ora imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then Return
' Altrimenti da lama
Else
' Imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then Return
' Trasformo in posizione punta utensile in basso
If Not EgtGetCalcTipFromPositions(dL1, dL2, dL3, vAng, True, m_ptTipP1) Then Return
End If
' Calcolo direzione asse lama
If Not EgtGetCalcToolDirFromAngles(vAng, m_vtToolP1) Then Return
' Porto il tip nell'origine tavola
m_ptTipP1.ToLoc(New Frame3d(m_ptTabOri))
m_bPointP1Ok = True
' Assegno angoli
Dim dTLen, dTAngV, dTAngO As Double
m_vtToolP1.ToSpherical(dTLen, dTAngV, dTAngO)
m_dAngO = dTAngO + 90
DirectionTxBx.Text = DoubleToString(m_dAngO - m_MainWindow.m_CurrentMachine.dDeltaC, 2)
' Altrimenti da disegno
Else
' Assegno punto selezionato nel disegno a m_ptTipP1
m_ptTipP1 = m_ptPrev
' Porto il tip nell'origine tavola
m_ptTipP1.ToLoc(New Frame3d(m_ptTabOri))
m_bPointP1Ok = True
' Imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then Return
End If
' Disegno il taglio
CreateFlatteningCut()
' Disegno la macchina nella sua posizione reale
SetMachineInCurrPos()
m_MainWindow.m_DirectCutPageUC.m_bShowMachine = True
EgtSetMachineLook(m_MainWindow.m_DirectCutPageUC.m_nMachLook)
EgtDraw()
' Seleziono il bottone per indicare che il primo punto è stato acquisito
Point1Btn.IsChecked = True
' Abilito e deseleziono secondo punto
Point2Btn.IsEnabled = True
Point2Btn.IsChecked = False
' Annullo secondo punto selezionato
m_bPointP2Ok = False
End Sub
Private Sub Point2Btn_Click(sender As Object, e As RoutedEventArgs) Handles Point2Btn.Click
' Rimuovo eventuali crocette create acquisendo i punti nel disegno
EgtEmptyGroup(m_nTempLay)
' Deseleziono il bottone (poichè si seleziona automaticamente) così nel caso ci sia un errore rimane deselezionato
Point2Btn.IsChecked = False
' Reset punto non acquisito
m_bPointP2Ok = False
' Verifico configurazione tavola e grezzo
If Not m_bRawOk Then Return
' forzo utilizzo testa H1 solo per macchina con 2 teste
Dim bIsMultiCut As Boolean = (EgtGetHeadId("H101") <> GDB_ID.NULL)
' Ricavo dati lama corrente
Dim sSaw As String = m_MainWindow.m_CurrentMachine.sCurrSaw
If bIsMultiCut Then
EgtSetCalcTool(sSaw, "H1", 1)
End If
' Se acquisizone lama o laser
If PointModeCmBx.SelectedIndex = PT_MODE.SAW Or PointModeCmBx.SelectedIndex = PT_MODE.LASER Then
' 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
' Se macchina multicut il primo asse rotante restituito è quello della tavola
Dim vAng() As Double = {dR1, dR2, 0}
If bIsMultiCut Then
vAng(0) = 0
vAng(1) = dR1
vAng(2) = dR2
End If
' Se punto da laser
If PointModeCmBx.SelectedIndex = PT_MODE.LASER Then
' Imposto come testa corrente il laser (senza utensile ovviamente)
If Not EgtSetCalcTool("", "H3", 1) Then Return
' Trasformo in posizione punta utensile in basso
If Not EgtGetCalcTipFromPositions(dL1, dL2, dL3, vAng, True, m_ptTipP2) Then Return
' Ora imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then Return
' Altrimenti da lama
Else
' Imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then Return
' Trasformo in posizione punta utensile in basso
If Not EgtGetCalcTipFromPositions(dL1, dL2, dL3, vAng, True, m_ptTipP2) Then Return
End If
' Calcolo direzione asse lama
If Not EgtGetCalcToolDirFromAngles(dR1, dR2, m_vtToolP2) Then Return
' Porto il tip nell'origine tavola
m_ptTipP2.ToLoc(New Frame3d(m_ptTabOri))
m_bPointP2Ok = True
' Altrimenti da disegno
Else
' Assegno punto selezionato nel disegno a m_ptTipP2
m_ptTipP2 = m_ptPrev
' Porto il tip nell'origine tavola
m_ptTipP2.ToLoc(New Frame3d(m_ptTabOri))
m_bPointP2Ok = True
' Imposto la lama corrente
If Not EgtSetCalcTool(sSaw, "H1", 1) Then Return
End If
' Se il secondo punto non coincide con il primo, disegno il taglio
Dim vtDiff As Vector3d = m_ptTipP2 - m_ptTipP1
vtDiff.z = 0
Dim dLen As Double
Dim dAngVertDeg As Double
Dim dAngOrizzDeg As Double
vtDiff.ToSpherical(dLen, dAngVertDeg, dAngOrizzDeg)
If dLen > EPS_SMALL Then
m_dLen = dLen
LenghtTxBx.Text = LenToString(dLen, 1)
m_dAngO = dAngOrizzDeg
DirectionTxBx.Text = DoubleToString(m_dAngO - m_MainWindow.m_CurrentMachine.dDeltaC, 2)
CreateFlatteningCut()
' Disegno la macchina nella sua posizione reale
SetMachineInCurrPos()
m_MainWindow.m_DirectCutPageUC.m_bShowMachine = True
EgtSetMachineLook(m_MainWindow.m_DirectCutPageUC.m_nMachLook)
EgtDraw()
' Seleziono il bottone per indicare che il secondo punto è stato acquisito
Point2Btn.IsChecked = True
Else
Point1Btn_Click(sender, e)
' Deseleziono il bottone per indicare che il secondo punto non è stato acquisito perchè uguale al primo
Point2Btn.IsChecked = False
End If
End Sub
Private Sub DepthTxBx_EgtClosed(sender As Object, e As EventArgs) Handles DepthTxBx.EgtClosed
' Verifico che l'affondamento impostato non sia superiore a quello massimo
Dim dMaxDepth = m_ptRawMax.z - m_ptRawMin.z + m_MainWindow.m_CurrentMachine.MaxTabDepth
Dim dDepth As Double = 0
StringToLen(DepthTxBx.Text, dDepth)
If dDepth < 0 Then
m_dDepth = 0
ElseIf dDepth > dMaxDepth Then
m_dDepth = dMaxDepth
Else
m_dDepth = dDepth
End If
DepthTxBx.Text = LenToString(m_dDepth, 2)
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub LenghtTxBx_EgtClosed(sender As Object, e As EventArgs) Handles LenghtTxBx.EgtClosed
' Verifico che la lunghezza del taglio impostata non sia inferiore a quella minima
Dim dLenght As Double = 0
StringToLen(LenghtTxBx.Text, dLenght)
If dLenght < MIN_CUT_LEN Then
m_dLen = MIN_CUT_LEN
Else
m_dLen = dLenght
End If
LenghtTxBx.Text = LenToString(m_dLen, 2)
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub WidthTxBx_EgtClosed(sender As Object, e As EventArgs) Handles WidthTxBx.EgtClosed
' Recupero il valore di larghezza impostato
Dim dWidth As Double = 0
StringToLen(WidthTxBx.Text, dWidth)
' Recupero l'impronta dell'utensile corrente
Dim dThick As Double = GetToolFootprint()
' La larghezza della spianatura non può essere inferiore all'impronta dell'utensile (spessore per lama, diametro per fresa)
m_dWid = Math.Max(dWidth, dThick)
WidthTxBx.Text = LenToString(m_dWid, 2)
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub DirectionTxBx_EgtClosed(sender As Object, e As EventArgs) Handles DirectionTxBx.EgtClosed
' Assegno il nuovo valore di direzione
Dim dDirection As Double = 0
StringToDouble(DirectionTxBx.Text, dDirection)
dDirection += m_MainWindow.m_CurrentMachine.dDeltaC
m_dAngO = dDirection
' Dichiaro non più usato P2
m_bPointP2Ok = False
Point2Btn.IsChecked = False
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub OverlapTxBx_EgtClosed(sender As Object, e As EventArgs) Handles OverlapTxBx.EgtClosed
' Recupero spessore della lama correntemente attiva
Dim dThick As Double = GetToolFootprint()
' Verifico che la sovrapposizione non sia superiore allo spessore della lama (meno 1mm di offset)
Dim dOverlap As Double = 0
Const MIN_OFFSET As Double = 1.0
StringToLen(OverlapTxBx.Text, dOverlap)
If dOverlap < 0 Then
m_dOverlap = 0
ElseIf dOverlap > dThick - MIN_OFFSET Then
m_dOverlap = dThick - MIN_OFFSET
Else
m_dOverlap = dOverlap
End If
OverlapTxBx.Text = LenToString(m_dOverlap, 2)
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub ZReleasedTxBx_EgtClosed(sender As Object, e As EventArgs) Handles ZReleasedTxBx.EgtClosed
Dim dSafeZ As Double = 0
StringToLen(ZReleasedTxBx.Text, dSafeZ)
m_dZReleased = dSafeZ
EgtMdbSetGeneralParam(MCH_GP.SAFEZ, dSafeZ)
'EgtMdbSave()
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub SideChBx_Click(sender As Object, e As EventArgs) Handles SideChBx.Click
m_bHeadSide = SideChBx.IsChecked
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub TypeCmBx_SelectionChanged(sender As Object, e As EventArgs) Handles TypeCmBx.SelectionChanged
m_nMachType = TypeCmBx.SelectedIndex
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub SelToolCmBx_SelectionChanged(sender As Object, e As EventArgs) Handles SelToolCmBx.SelectionChanged
m_nTool = SelToolCmBx.SelectedIndex
' Disabilito il concatenamento
ChainedPathChBx.IsEnabled = (m_nTool = TOOL.MILL)
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub RotLockChBx_Click(sender As Object, e As EventArgs) Handles RotLockChBx.Click
m_bRotLock = RotLockChBx.IsChecked
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub ChainedPathChBx_Click(sender As Object, e As EventArgs) Handles ChainedPathChBx.Click
m_bChainedPath = ChainedPathChBx.IsChecked
' Disegno il taglio
CreateFlatteningCut()
SetMachineInCurrPos()
EgtDraw()
End Sub
Private Sub XcoordTxBx_EgtClosed(sender As Object, e As EventArgs) Handles XcoordTxBx.EgtClosed
' Recupero il valore della coordinata (in 0 Tab)
Dim dXcoord As Double = 0
StringToLen(XcoordTxBx.Text, dXcoord)
XcoordTxBx.Text = LenToString(dXcoord, 2)
' lo assegno al punto corrente (in 0 Macc)
m_ptPrev.x = dXcoord + m_ptTabOri.x
' Rimuovo eventuali crocette create acquisendo i punti nel disegno
EgtEmptyGroup(m_nTempLay)
' Disegno crocetta che indica il punto acquisito
CreateCross(m_nTempLay, m_ptPrev)
EgtDraw()
End Sub
Private Sub YcoordTxBx_EgtClosed(sender As Object, e As EventArgs) Handles YcoordTxBx.EgtClosed
' Recupero il valore della coordinata (in 0 Tab)
Dim dYcoord As Double = 0
StringToLen(YcoordTxBx.Text, dYcoord)
YcoordTxBx.Text = LenToString(dYcoord, 2)
' lo assegno al punto corrente (in 0 Macc)
m_ptPrev.y = dYcoord + m_ptTabOri.y
' Rimuovo eventuali crocette create acquisendo i punti nel disegno
EgtEmptyGroup(m_nTempLay)
' Disegno crocetta che indica il punto acquisito
CreateCross(m_nTempLay, m_ptPrev)
EgtDraw()
End Sub
Private Sub SimulBtn_Click(sender As Object, e As RoutedEventArgs) Handles SimulBtn.Click
' Verifico ci sia un taglio valido
If Not m_bCutOk Then Return
' Salvo il progetto con le lavorazioni
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\" & "DirectProj.nge"
m_MainWindow.m_CurrentProjectPageUC.SaveFile(sMchPath, False)
' Predispongo passaggio a simulazione
m_bSimul = True
m_CurrProjPage.m_SceneButtons.MeasureBtn.IsChecked = False
m_CurrProjPage.CurrProjGrid.Visibility = Windows.Visibility.Hidden
m_MainWindow.m_DirectCutPageUC.m_ControlsDirectCutUC.LeftButtonGrid.Children.Remove(Me)
m_CurrProjPage.CurrentProjectPageGrid.Children.Remove(m_MainWindow.m_DirectCutPageUC)
m_MainWindow.m_PrevActivePage = MainWindow.Pages.DirectCut
m_CurrProjPage.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_SimulationPage)
m_MainWindow.m_ActivePage = MainWindow.Pages.Simulation
End Sub
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
#If TRIAL Then
m_CurrProjPage.SetWarningMessage("Trial Version")
#Else
' Verifico non sia versione Ufficio
If m_MainWindow.GetKeyOption(MainWindow.KEY_OPT.OFFICE_TYPE) Then
m_CurrProjPage.SetWarningMessage("Office Version")
Return
End If
' Verifico ci sia un taglio valido
If Not m_bCutOk Then Return
' Salvo il progetto con le lavorazioni
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\" & "DirectProj.nge"
m_MainWindow.m_CurrentProjectPageUC.SaveFile(sMchPath, False)
' Genero file CNC (lancio anche se errore in precedenza)
Dim sCncPath As String = m_MainWindow.GetCncDir() & "\DirectCut" & m_MainWindow.m_CurrentMachine.sIsoFileExt
Dim bOk As Boolean = EgtGenerate(sCncPath, "OmagCut ver." & m_MainWindow.GetVersion())
' 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
Dim sNameProg As Integer = 900
sNameProg = GetPrivateProfileInt(S_PARTPROGRAM, "NameProg", sNameProg, m_MainWindow.GetMachIniFile)
' Download programma (eventuali errori sono segnalati dalla funzione)
If m_MainWindow.m_CNCommunication.SendProgram(sCncPath, sNameProg) 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)
' lancio eventuale lua post-trasmissione
m_MainWindow.ExecSentProgScript(True)
End If
#End If
End Sub
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
EgtMdbSetGeneralParam(MCH_GP.SAFEZ, DirectCutPageUC.m_dZSafe)
EgtMdbSave()
m_MainWindow.m_DirectCutPageUC.m_ControlsDirectCutUC.LeftButtonGrid.Children.Remove(Me)
End Sub
' ricavo impronta di lavorazione (in larghezza) in funzione dell'utensile selezionato
Private Function GetToolFootprint() As Double
Dim dFootPrint As Double = 0
' se richiesta lama
If m_nTool <> TOOL.MILL Then
If EgtTdbSetCurrTool(m_MainWindow.m_CurrentMachine.sCurrSaw) Then
EgtTdbGetCurrToolParam(MCH_TP.THICK, dFootPrint)
Else
EgtOutLog("In ToolDB missing saw " & m_MainWindow.m_CurrentMachine.sCurrSaw)
End If
' altrimenti è richiesta fresa
Else
Dim sCurrMill = m_MainWindow.m_CurrentMachine.sCurrMill
If String.IsNullOrWhiteSpace( sCurrMill) Then sCurrMill = GetMillFromMilling(m_MainWindow.m_CurrentMachine.sCurrMilling)
' recupero informazioni della fresa in uso
If EgtTdbSetCurrTool(sCurrMill) Then
EgtTdbGetCurrToolParam(MCH_TP.DIAM, dFootPrint)
Else
EgtOutLog("In ToolDB missing mill " & m_MainWindow.m_CurrentMachine.sCurrSaw)
End If
End If
Return dFootPrint
End Function
Private Function CreateFlatteningCut() As Boolean
' Verifico sia definito il punto iniziale e il grezzo
If Not m_bPointP1Ok Or Not m_bRawOk Then
m_bCutOk = False
Return False
End If
' Spessore grezzo
Dim dRawHeight As Double = 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 As Integer = EgtCreateGroup(GDB_ID.ROOT)
EgtSetName(nPartId, NAME_DIRECTCUT)
Dim nLayerId As Integer = EgtCreateGroup(nPartId)
EgtSetName(nLayerId, NAME_ONPATH)
' Creo il taglio
Dim ptStart As Point3d = m_ptTipP1
ptStart.z = 0
Dim nCutId As Integer = EgtCreateLinePDL(nLayerId, ptStart, m_dAngO, m_dLen)
' Indico che è un taglio Diretto di tipo Flattening
EgtSetInfo(nCutId, INFO_DIRECTCUT, FlagDirectCuts.Flattening)
EgtSetInfo(nCutId, INFO_ENGR_MILL, m_nTool)
' Imposto affondamento e angolo di fianco sul taglio
EgtSetInfo(nCutId, INFO_DEPTH, m_dDepth)
Dim dThick As Double = GetToolFootprint()
EgtSetInfo(nCutId, INFO_WIDTH, dThick)
EgtSetInfo(nCutId, INFO_SIDE_ANGLE, 0)
' Imposto prima direzione
EgtSetInfo(nCutId, INFO_DIR, 1)
' Eventuale riduzione lavorazione
Dim bReducePath As Boolean = ( GetPrivateProfileInt(S_MACH_NEST, K_MACH_STARTCENTERTOOLPATH, 0, m_MainWindow.GetMachIniFile()) = 0)
' Per fresatura eventuale riduzione della geometria
If m_nTool = TOOL.MILL Then
If bReducePath Then ExtendLenghtMillPath(nCutId, -dThick / 2)
EgtSetInfo(nCutId, INFO_STRICT, 0)
' per tagli con lama eventuale riduzione della lavorazione
Else
EgtSetInfo(nCutId, INFO_STRICT, If( bReducePath, 3, 0))
End If
' Eventuale bloccaggio rotazione asse C tra le passate
If RotLockChBx.IsChecked Then
EgtSetInfo(nCutId, INFO_ENABLE_INVERT, False)
End If
EgtSetInfo(nCutId, INFO_STEP_TYPE, m_nMachType)
' Funzione che crea eventuali tagli successivi al primo
MultiplyCut(nLayerId, nCutId)
' Creo layer per crocetta di riferimento
Dim nCrossLayerId = EgtCreateGroup(nPartId)
' Aggiungo crocetta/e
If m_bPointP1Ok Then
CreateCross(nCrossLayerId, ptStart)
End If
If m_bPointP2Ok Then
Dim ptEnd As Point3d = m_ptTipP2
ptEnd.z = 0
CreateCross(nCrossLayerId, ptEnd)
End If
' Calcolo punto di inserimento nel grezzo
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(nPartId, 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) AndAlso UpdateAllMachiningsToolpaths()
EgtSetCurrPhase(1)
' Eventuale eliminazione Home finale
If Not m_MainWindow.m_CurrentMachine.bDirectCutsFinalHome Then
RemoveFinalHome()
End If
UpdateSimulOkBtn()
Return m_bCutOk
End Function
Private Function MultiplyCut(nLayerId As Integer, nCutId As Integer) As Boolean
' Recupero impronta della lama o fresa utilizzata
Dim dThick As Double = GetToolFootprint()
If dThick = 0 Then Return False
' Salvo la curva originale nella lista dei percorsi da concatenare
Dim CutsList As New List(Of Integer)
CutsList.Add(nCutId)
' Imposto angolo di rotazione a seconda del lato dei tagli
Dim dRotAngO As Double = If(SideChBx.IsChecked(), -90, 90)
' Calcolo numero di passate necessarie a coprire l'area impostata e lunghezza vettore delta
Dim dDelta As Double = dThick - m_dOverlap
Dim dWidth As Double = m_dWid - dThick
Dim nStepNum As Integer = CInt(Math.Ceiling(dWidth / dDelta)) + 1
If nStepNum > 1 Then dDelta = dWidth / (nStepNum - 1)
' Definisco vettore di spostamento
Dim vtDelta As Vector3d = Vector3d.FromPolar(dDelta, m_dAngO)
vtDelta.Rotate(Vector3d.Z_AX, dRotAngO)
' Creo le ripetizioni
For Index As Integer = 1 To nStepNum - 1
Dim vtPerpMove As Vector3d = Index * vtDelta
' Creo copie
Dim nCut2Id = EgtCopyGlob(nCutId, nLayerId)
EgtMove(nCut2Id, vtPerpMove, GDB_RT.GLOB)
' Assegno info direzione a seconda del tipo di spianatura
Dim nDir As Integer = 1
If TypeCmBx.SelectedIndex = MACH_TYPE.ZIGZAG And Index Mod 2 <> 0 Then nDir = 2
EgtSetInfo(nCut2Id, INFO_DIR, nDir)
' Inserisco nell'elenco delle curve eventualmente da concatenare
CutsList.Add(nCut2Id)
Next
' Se fresatura e richiesto percorso concatenato
If m_nTool = TOOL.MILL And m_bChainedPath Then
' Trasformo la prima curva in composita (copiando tutte le info)
Dim vsInfo As String() = Nothing
EgtGetAllInfo( CutsList(0), vsInfo)
Dim nCompoCrv As Integer = EgtCreateCurveCompo(nLayerId, CutsList(0), True)
For Each sInfo As String In vsInfo
Dim KeyAndVal As String() = sInfo.Split( "=".ToCharArray)
If KeyAndVal.Count() >= 2 Then EgtSetInfo( nCompoCrv, KeyAndVal(0), KeyAndVal(1))
Next
' Accodo opportunamente le curve successive
For Index As Integer = 1 To CutsList.Count - 1
' Inverto le curve di ritorno (di indice dispari in lista)
If Index Mod 2 <> 0 Then EgtInvertCurve( CutsList(Index))
' Aggiungo il collegamento
Dim ptStart As Point3d
EgtStartPoint(CutsList(Index), CutsList(Index), ptStart)
EgtAddCurveCompoLine( nCompoCrv, ptStart)
' Aggiungo la curva
EgtAddCurveCompoCurve( nCompoCrv, CutsList(Index), true)
Next
End If
Return True
End Function
Private Sub ExtendLenghtMillPath(IdCurv As Integer, dExtend As Double,
Optional bStart As Boolean = True, Optional bEnd As Boolean = True)
If bStart Then
Dim ptStart As Point3d
EgtStartPoint(IdCurv, IdCurv, ptStart)
EgtTrimExtendCurveByLen(IdCurv, dExtend, ptStart)
End If
If bEnd Then
Dim ptEnd As Point3d
EgtEndPoint(IdCurv, IdCurv, ptEnd)
EgtTrimExtendCurveByLen(IdCurv, dExtend, ptEnd)
End If
End Sub
Private Function CreateCross(nLayerId As Integer, ptP As Point3d) As Boolean
' Aggiungo crocette
Dim vtCrossX As New Vector3d(20, 0, 0)
Dim vtCrossY As New Vector3d(0, 20, 0)
Dim nCrossId1 = EgtCreateLine(nLayerId, ptP + (-vtCrossX), ptP + vtCrossX)
EgtSetColor(nCrossId1, New Color3d(255, 0, 0))
Dim nCrossId2 = EgtCreateLine(nLayerId, ptP + (-vtCrossY), ptP + vtCrossY)
EgtSetColor(nCrossId2, New Color3d(255, 0, 0))
Return True
End Function
Private Sub SetCoordVisibility(bShow As Boolean)
XcoordTxBl.Visibility = If(bShow, Windows.Visibility.Visible, Windows.Visibility.Hidden)
XcoordTxBx.Visibility = If(bShow, Windows.Visibility.Visible, Windows.Visibility.Hidden)
YcoordTxBl.Visibility = If(bShow, Windows.Visibility.Visible, Windows.Visibility.Hidden)
YcoordTxBx.Visibility = If(bShow, Windows.Visibility.Visible, Windows.Visibility.Hidden)
End Sub
Private Sub ShowCoord()
Dim ptText As Point3d = m_ptPrev
ptText.ToLoc(New Frame3d(m_ptTabOri))
XcoordTxBx.Text = LenToString(ptText.x, 2)
YcoordTxBx.Text = LenToString(ptText.y, 2)
End Sub
Private Function SetMachineInCurrPos() As Boolean
' 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 False
' 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
If Not m_MainWindow.m_CNCommunication.GetAxesNames(sL1, sL2, sL3, sR1, sR2) Then Return False
' Visualizzo macchina in posizione
EgtSetAxisPos(sL1, dL1)
EgtSetAxisPos(sL2, dL2)
EgtSetAxisPos(sL3, dL3)
EgtSetAxisPos(sR1, dR1)
EgtSetAxisPos(sR2, dR2)
Return True
End Function
End Class