ff30a4d3b6
- gestione nesting allineato (con regione di riferimento a L) - gestione epl pezzi rovinati da OmagVIEW per linee di produzione - piccole migliorie varie.
607 lines
26 KiB
VB.net
607 lines
26 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports OmagCUT.TreeViewItem
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib
|
|
|
|
Public Class CSVPage
|
|
|
|
' 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 prima apertura
|
|
Private m_bFirst As Boolean = True
|
|
' Dati lista
|
|
Private m_sCsvPath As String = String.Empty
|
|
Private m_CsvPartList As New List(Of CsvPart)
|
|
Private m_ItemsList As New ObservableCollection(Of PartCathegoryItem)
|
|
Private m_sCompoDir As String = String.Empty
|
|
' Dati del grezzo
|
|
Private m_nRawId As Integer = GDB_ID.NULL
|
|
Private m_ptRawMin As Point3d
|
|
Private m_ptRawMax As Point3d
|
|
|
|
|
|
Private Sub CSVPage_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
|
|
' Assegno la lista dei pezzi Csv come sorgente del treeview
|
|
PartsTreeView.ItemsSource = m_ItemsList
|
|
' Messaggi
|
|
NewBtn.Content = EgtMsg(MSG_CSVPAGEUC + 3) ' Nuovo
|
|
OpenBtn.Content = EgtMsg(MSG_CSVPAGEUC + 1) ' Apri
|
|
InsertBtn.Content = EgtMsg(MSG_CSVPAGEUC + 2) ' Inserisci
|
|
RemoveBtn.Content = EgtMsg(MSG_CSVPAGEUC + 4) ' Rimuovi
|
|
' Leggo lista pezzi corrente
|
|
Dim sCsvFile As String = String.Empty
|
|
GetPrivateProfileString(S_CSV, K_CSVLASTFILE, "", sCsvFile, m_MainWindow.GetIniFile())
|
|
If Not String.IsNullOrEmpty(sCsvFile) Then
|
|
LoadCsvPartList(sCsvFile)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CSVPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
|
|
' Impostazioni
|
|
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
|
|
m_bActive = True
|
|
' Se prima esecuzione
|
|
If m_bFirst Then
|
|
' Leggo direttorio componenti
|
|
GetPrivateProfileString(S_COMPO, K_COMPODIR, "", m_sCompoDir, m_MainWindow.GetIniFile())
|
|
' Visualizzazione lista
|
|
ShowTreeView()
|
|
m_bFirst = False
|
|
End If
|
|
' Recupero dimensioni del grezzo e kerf
|
|
m_nRawId = EgtGetFirstRawPart()
|
|
GetRawBox(m_ptRawMin, m_ptRawMax)
|
|
End Sub
|
|
|
|
Private Sub CSVPage_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
|
|
m_bActive = False
|
|
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 se selezionato indicativo di pezzo
|
|
EgtSetObjFilterForSelect(True, True, True, True, True)
|
|
Dim nSel As Integer
|
|
EgtSelect(e.Location, Scene.DIM_SEL, Scene.DIM_SEL, nSel)
|
|
Dim nId As Integer = EgtGetFirstObjInSelWin()
|
|
While nId <> GDB_ID.NULL
|
|
' Recupero l'identificativo del pezzo cui appartiene
|
|
Dim nPartId As Integer = EgtGetParent(EgtGetParent(nId))
|
|
Dim bPartInTable As Boolean = (EgtGetParent(nPartId) = m_nRawId)
|
|
If EgtIsPart(nPartId) Or bPartInTable Then
|
|
Dim nStat As Integer = GDB_ST.ON_
|
|
EgtGetStatus(nPartId, nStat)
|
|
' Se già selezionato, lo deselezione
|
|
If nStat = GDB_ST.SEL Then
|
|
EgtDeselectObj(nPartId)
|
|
' Altrimenti lo seleziono
|
|
Else
|
|
EgtSelectObj(nPartId)
|
|
End If
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
|
|
m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Remove(Me)
|
|
m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC.m_NestPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut
|
|
End Sub
|
|
|
|
Private Sub NewBtn_Click(sender As Object, e As RoutedEventArgs) Handles NewBtn.Click
|
|
' Salvo lista dei pezzi attuale
|
|
SaveCsvPartList()
|
|
' Pulisco path e lista dei pezzi Csv
|
|
m_sCsvPath = String.Empty
|
|
m_CsvPartList.Clear()
|
|
' Visualizzazione lista
|
|
ShowTreeView()
|
|
' Registro in ini nessuna path
|
|
WritePrivateProfileString(S_CSV, K_CSVLASTFILE, "", m_MainWindow.GetIniFile())
|
|
End Sub
|
|
|
|
Private Sub OpenBtn_Click(sender As Object, e As RoutedEventArgs) Handles OpenBtn.Click
|
|
' Salvo lista dei pezzi attuale
|
|
SaveCsvPartList()
|
|
' Leggo direttorio corrente dei file CSV
|
|
Dim sCurrDir As String = ""
|
|
GetPrivateProfileString(S_CSV, K_CSVCURRDIR, "C:\", sCurrDir, m_MainWindow.GetIniFile())
|
|
' Apro dialogo scelta file
|
|
Dim OpenFileWnd As New OpenFileWD(m_MainWindow, sCurrDir, ".CSV", ".EPL")
|
|
If Not OpenFileWnd.ShowDialog() Then Return
|
|
' Salvo direttorio corrente
|
|
WritePrivateProfileString(S_CSV, K_CSVCURRDIR, OpenFileWnd.GetFileDir(), m_MainWindow.GetIniFile())
|
|
' Apertura file
|
|
Dim sPath = OpenFileWnd.GetFilePath()
|
|
If String.Compare(Path.GetExtension(sPath), ".CSV", True) = 0 Then
|
|
LoadCsvFile(sPath)
|
|
Else
|
|
LoadCsvPartList(sPath)
|
|
End If
|
|
' Visualizzazione lista
|
|
ShowTreeView()
|
|
End Sub
|
|
|
|
Private Function LoadCsvFile(sCsvPath As String) As Boolean
|
|
' Pulisco path e lista dei pezzi Csv
|
|
m_sCsvPath = String.Empty
|
|
m_CsvPartList.Clear()
|
|
' Definizione variabili
|
|
EgtLuaCreateGlobTable("CSV")
|
|
EgtLuaSetGlobStringVar("CSV.FILE", sCsvPath)
|
|
' Esecuzione
|
|
Dim nErr As Integer = 999
|
|
If EgtLuaExecFile(m_MainWindow.GetCsvAutoDir() & "\CsvRead.lua") AndAlso
|
|
EgtLuaCallFunction("CSV.Read") Then
|
|
' Verifica stato di errore
|
|
EgtLuaGetGlobIntVar("CSV.ERR", nErr)
|
|
End If
|
|
If nErr <> 0 Then
|
|
EgtOutLog("Error in CsvRead : " & nErr.ToString())
|
|
Return False
|
|
End If
|
|
' Assegno path
|
|
m_sCsvPath = sCsvPath
|
|
' Preparo lista dei pezzi
|
|
Dim nNbr As Integer = 0
|
|
EgtLuaGetGlobIntVar("CSV.NBR", nNbr)
|
|
For i As Integer = 1 To nNbr
|
|
Dim OnePart As New CsvPart
|
|
Dim sN As String = i.ToString()
|
|
EgtLuaGetGlobStringVar("CSV.NAME" & sN, OnePart.m_sName)
|
|
OnePart.m_bActive = True
|
|
EgtLuaGetGlobStringVar("CSV.MAT" & sN, OnePart.m_sMaterial)
|
|
EgtLuaGetGlobIntVar("CSV.COUNT" & sN, OnePart.m_nCount)
|
|
OnePart.m_nToNest = OnePart.m_nCount
|
|
EgtLuaGetGlobBoolVar("CSV.RECT" & sN, OnePart.m_bIsRect)
|
|
EgtLuaGetGlobNumVar("CSV.DIMX" & sN, OnePart.m_dDimX)
|
|
EgtLuaGetGlobNumVar("CSV.DIMY" & sN, OnePart.m_dDimY)
|
|
EgtLuaGetGlobNumVar("CSV.TH" & sN, OnePart.m_dTh)
|
|
OnePart.m_nOriInd = i
|
|
' inserisco in lista
|
|
m_CsvPartList.Add(OnePart)
|
|
Next
|
|
EgtLuaResetGlobVar("CSV")
|
|
' Ordinamento lista dei pezzi (ordine crescente su materiale e spessore)
|
|
m_CsvPartList.Sort(Function(x, y)
|
|
Dim nComp As Integer = String.Compare(x.m_sMaterial, y.m_sMaterial, True)
|
|
If nComp = 0 Then
|
|
If Math.Abs(x.m_dTh - y.m_dTh) < EPS_SMALL Then
|
|
Return (x.m_nOriInd - y.m_nOriInd)
|
|
Else
|
|
Return CInt(Math.Ceiling(x.m_dTh - y.m_dTh))
|
|
End If
|
|
Else
|
|
Return nComp
|
|
End If
|
|
End Function)
|
|
' Salvo come epl
|
|
SaveCsvPartList()
|
|
' Rinomino file originale
|
|
Dim sBakPath As String = sCsvPath & ".bak"
|
|
Dim sBakName As String = Path.GetFileName(sBakPath)
|
|
' cancello eventuale vecchio backup
|
|
If My.Computer.FileSystem.FileExists(sBakPath) Then
|
|
My.Computer.FileSystem.DeleteFile(sBakPath)
|
|
End If
|
|
' eseguo rinomina
|
|
My.Computer.FileSystem.RenameFile(sCsvPath, sBakName)
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub ShowTreeView()
|
|
' Path del file Csv
|
|
Dim TempPath As New Text.StringBuilder(260)
|
|
PathCompactPathEx(TempPath, m_sCsvPath, 22, 0)
|
|
CsvPathTxBl.Content = TempPath.ToString()
|
|
' Pezzi del file Csv
|
|
m_ItemsList.Clear()
|
|
Dim sCurrMat As String = String.Empty
|
|
Dim dCurrTh As Double = 0
|
|
Dim nCatToNest As Integer = 0
|
|
Dim nCatCount As Integer = 0
|
|
Dim PartCathegory As New PartCathegoryItem("", 0)
|
|
For i As Integer = 1 To m_CsvPartList.Count()
|
|
' Dati pezzo corrente
|
|
Dim CurrPart As CsvPart = m_CsvPartList(i - 1)
|
|
' Gestione categoria
|
|
If i = 1 Then
|
|
sCurrMat = CurrPart.m_sMaterial
|
|
dCurrTh = CurrPart.m_dTh
|
|
ElseIf String.Compare(sCurrMat, CurrPart.m_sMaterial, True) <> 0 Or
|
|
Math.Abs(dCurrTh - CurrPart.m_dTh) > 10 * EPS_SMALL Then
|
|
PartCathegory.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
|
|
" - " & LenToString(dCurrTh, 2) &
|
|
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
|
|
PartCathegory.IsExpanded = True
|
|
m_ItemsList.Add(PartCathegory)
|
|
sCurrMat = CurrPart.m_sMaterial
|
|
dCurrTh = CurrPart.m_dTh
|
|
PartCathegory = New PartCathegoryItem("", 0)
|
|
nCatToNest = 0
|
|
nCatCount = 0
|
|
End If
|
|
' Gestione pezzo
|
|
nCatToNest += CurrPart.m_nToNest
|
|
nCatCount += CurrPart.m_nCount
|
|
Dim sCount As String = CurrPart.m_nToNest.ToString() & "/" & CurrPart.m_nCount.ToString()
|
|
Dim sDim As String = LenToString(CurrPart.m_dDimX, 1) & "x" & LenToString(CurrPart.m_dDimY, 1)
|
|
PartCathegory.Items.Add(New PartCustomItem(CurrPart.m_sName, i, sCount, sDim, CurrPart.m_bActive))
|
|
Next
|
|
' Inserisco ultima categoria
|
|
PartCathegory.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
|
|
" - " & LenToString(dCurrTh, 2) &
|
|
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
|
|
PartCathegory.IsExpanded = True
|
|
m_ItemsList.Add(PartCathegory)
|
|
End Sub
|
|
|
|
Private Sub PartsTreeView_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs) Handles PartsTreeView.PreviewMouseUp
|
|
If TypeOf PartsTreeView.SelectedItem Is PartCathegoryItem Then
|
|
Dim SelectedCathegory As PartCathegoryItem = DirectCast(PartsTreeView.SelectedItem, PartCathegoryItem)
|
|
SelectedCathegory.IsExpanded = Not SelectedCathegory.IsExpanded
|
|
SelectedCathegory.IsSelected = False
|
|
ElseIf TypeOf PartsTreeView.SelectedItem Is PartCustomItem Then
|
|
Dim SelectedCustom As PartCustomItem = DirectCast(PartsTreeView.SelectedItem, PartCustomItem)
|
|
SelectedCustom.bIsActive = Not SelectedCustom.bIsActive
|
|
m_CsvPartList(SelectedCustom.nType - 1).m_bActive = SelectedCustom.bIsActive
|
|
SelectedCustom.IsSelected = False
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub InsertBtn_Click(sender As Object, e As RoutedEventArgs) Handles InsertBtn.Click
|
|
' Recupero lo spessore della lastra corrente
|
|
Dim dRawHeight As Double = GetRawHeight()
|
|
If dRawHeight < EPS_SMALL Then Return
|
|
' Recupero il materiale della lastra corrente
|
|
Dim sCurrMat As String = String.Empty
|
|
If Not IsNothing(m_MainWindow.m_CurrentMachine.CurrMat) Then
|
|
sCurrMat = m_MainWindow.m_CurrentMachine.CurrMat.sName
|
|
End If
|
|
' Creo la lista dei pezzi inseribili nella lastra corrente
|
|
Dim InsPartList As New List(Of CsvPart)
|
|
For i As Integer = 1 To m_CsvPartList.Count()
|
|
Dim CurrPart As CsvPart = m_CsvPartList(i - 1)
|
|
If CurrPart.m_bActive And
|
|
Math.Abs(CurrPart.m_dTh - dRawHeight) < 100 * EPS_SMALL And
|
|
(String.IsNullOrWhiteSpace(CurrPart.m_sMaterial) Or
|
|
String.IsNullOrWhiteSpace(sCurrMat) Or
|
|
String.Compare(CurrPart.m_sMaterial, sCurrMat, True) = 0) Then
|
|
InsPartList.Add(CurrPart)
|
|
End If
|
|
Next
|
|
' Lancio l'inserimento dei pezzi
|
|
ExecInsert(InsPartList)
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno TreeView
|
|
ShowTreeView()
|
|
End Sub
|
|
|
|
Private Function ExecInsert(InsPartList As List(Of CsvPart)) As Boolean
|
|
' Ordino la lista dei pezzi secondo le Y decrescenti
|
|
InsPartList.Sort(Function(x, y)
|
|
If Math.Abs(x.m_dDimY - y.m_dDimY) < EPS_SMALL Then
|
|
Return (x.m_nOriInd - y.m_nOriInd)
|
|
Else
|
|
Return CInt(Math.Ceiling(y.m_dDimY - x.m_dDimY))
|
|
End If
|
|
End Function)
|
|
' Creo o svuoto gruppo temporaneo per i pezzi
|
|
Dim nIpGrp As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, "CSV")
|
|
If nIpGrp = GDB_ID.NULL Then
|
|
nIpGrp = EgtCreateGroup(GDB_ID.ROOT)
|
|
If nIpGrp = GDB_ID.NULL Then Return False
|
|
EgtSetName(nIpGrp, "CSV")
|
|
Else
|
|
EgtEmptyGroup(nIpGrp)
|
|
End If
|
|
EgtSetLevel(nIpGrp, GDB_LV.TEMP)
|
|
EgtSetStatus(nIpGrp, GDB_ST.OFF)
|
|
' Carico lua per creare rettangoli
|
|
Dim sLuaPath = m_sCompoDir & "\Rettangolo.lua"
|
|
If Not EgtLuaExecFile(sLuaPath) Then Return False
|
|
' Inserisco nel gruppo un nuovo componente per ogni pezzo da inserire
|
|
For i As Integer = 1 To InsPartList.Count()
|
|
Dim CurrPart As CsvPart = InsPartList(i - 1)
|
|
' Definizione variabili
|
|
EgtLuaSetGlobNumVar("CMP.V1", Math.Max(CurrPart.m_dDimX, CurrPart.m_dDimY))
|
|
EgtLuaSetGlobNumVar("CMP.V2", Math.Min(CurrPart.m_dDimX, CurrPart.m_dDimY))
|
|
EgtLuaSetGlobStringVar("CMP.INFO", CurrPart.m_sName)
|
|
' Esecuzione componente
|
|
If Not EgtLuaExecLine("CMP_Draw(false)") Then Return False
|
|
' Recupero Id del nuovo componente
|
|
Dim nId As Integer = EgtGetLastPart()
|
|
If nId = GDB_ID.NULL Then Return False
|
|
CurrPart.m_nId = nId
|
|
' Muovo la regione in Z per evitare problemi in visualizzazione
|
|
Dim nRegId = EgtGetFirstNameInGroup(nId, NAME_REGION)
|
|
EgtMove(nRegId, New Vector3d(0, 0, DELTAZ_REG), GDB_RT.GLOB)
|
|
' Aggiusto per lavorazioni
|
|
AdjustFlatPart(nId)
|
|
' Aggiungo info su CSV di origine
|
|
EgtSetInfo(nId, INFO_CSV_PATH, m_sCsvPath)
|
|
EgtSetInfo(nId, INFO_CSV_PART, CurrPart.m_sName)
|
|
' Lo sposto nel gruppo speciale
|
|
EgtRelocate(nId, nIpGrp)
|
|
Next
|
|
EgtLuaResetGlobVar("CMP")
|
|
EgtLuaResetGlobVar("CMP_Draw")
|
|
' Provo ad inserire i pezzi
|
|
For i As Integer = 1 To InsPartList.Count()
|
|
Dim CurrPart As CsvPart = InsPartList(i - 1)
|
|
While CurrPart.m_nToNest > 0
|
|
If PackOnePart(CurrPart.m_nId) Then
|
|
CurrPart.m_nToNest -= 1
|
|
Else
|
|
Exit While
|
|
End If
|
|
End While
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function PackOnePart(nId As Integer) As Boolean
|
|
' Dimensioni del pezzo
|
|
Dim ptPartMin, ptPartMax As Point3d
|
|
If Not EgtGetBBox(nId, GDB_BB.IGNORE_DIM + GDB_BB.IGNORE_TEXT, ptPartMin, ptPartMax) Then Return False
|
|
Dim dPartLen As Double = ptPartMax.x - ptPartMin.x
|
|
Dim dPartHeight As Double = ptPartMax.y - ptPartMin.y
|
|
' Centro del grezzo
|
|
Dim nRawCenId = EgtGetFirstNameInGroup(m_nRawId, "RawCenter")
|
|
Dim ptRawCenter As Point3d
|
|
EgtStartPoint(nRawCenId, GDB_ID.ROOT, ptRawCenter)
|
|
Dim dRawCenX = ptRawCenter.x - m_ptRawMin.x
|
|
Dim dRawCenY = ptRawCenter.y - m_ptRawMin.y
|
|
' Inserisco il pezzo nel grezzo, in centro in XY e in alto in Z
|
|
Dim ptP As New Point3d(dRawCenX - 0.5 * dPartLen, dRawCenY - 0.5 * dPartHeight, m_ptRawMax.z - m_ptRawMin.z)
|
|
' Ne creo una copia nella radice
|
|
Dim nId2 As Integer = EgtCopyGlob(nId, GDB_ID.ROOT)
|
|
If EgtAddPartToRawPart(nId2, ptP, m_nRawId) Then
|
|
' Aggiungo le lavorazioni standard
|
|
AddMachinings(nId2, True, False)
|
|
' Eseguo nesting
|
|
Dim bFit As Boolean = False
|
|
If m_MainWindow.m_CadCutPageUC.m_NestPage.UpdateNestRegions() Then
|
|
Dim bAligned As Boolean = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_NEST_ALIGNED, 0, m_MainWindow.GetMachIniFile()) <> 0)
|
|
m_MainWindow.m_CadCutPageUC.m_NestPage.EnableReferenceRegion(bAligned)
|
|
If Not EgtExistsInfo(m_nRawId, KEY_RAWBYPOINTS) Then
|
|
bFit = EgtPackPartInRectangle(nId2, True, True)
|
|
End If
|
|
If Not bFit Then
|
|
bFit = EgtPackPart(nId2, True, True)
|
|
End If
|
|
End If
|
|
' Gestione risultato nesting
|
|
If bFit Then
|
|
Return True
|
|
Else
|
|
EraseMachinings(nId2)
|
|
EgtRemovePartFromRawPart(nId2)
|
|
EgtErase(nId2)
|
|
End If
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Private Sub RemoveBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemoveBtn.Click
|
|
' Elenco eventuali altre liste Csv riferite dai pezzi
|
|
Dim bOther As Boolean = False
|
|
Dim sOtherCsv As String = String.Empty
|
|
' Rimuovo i pezzi selezionati della lista CSV corrente e ne aggiorno i contatori
|
|
Dim nId As Integer = EgtGetFirstSelectedObj()
|
|
While nId <> GDB_ID.NULL
|
|
Dim nNextId As Integer = EgtGetNextSelectedObj()
|
|
If Not RemoveOnePart(nId) Then
|
|
bOther = True
|
|
Dim sCsvPath As String = String.Empty
|
|
If EgtGetInfo(nId, INFO_CSV_PATH, sCsvPath) Then
|
|
Dim sCsvName As String = Path.GetFileNameWithoutExtension(sCsvPath)
|
|
If sOtherCsv.IndexOf(sCsvName) = -1 Then
|
|
sOtherCsv = sOtherCsv & sCsvName & ", "
|
|
End If
|
|
End If
|
|
End If
|
|
nId = nNextId
|
|
End While
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno TreeView
|
|
ShowTreeView()
|
|
' Eventuale messaggi di pezzi liberi o da altre liste
|
|
If bOther Then
|
|
' Pezzi non rimossi perché liberi
|
|
Dim sOut As String = EgtMsg(MSG_EGTMSGBOX + 13)
|
|
If Not String.IsNullOrWhiteSpace(sOtherCsv) Then
|
|
' o di altre liste Csv
|
|
sOut &= EgtMsg(MSG_EGTMSGBOX + 14) & " (" & sOtherCsv.TrimEnd(", ".ToCharArray()) & ")"
|
|
End If
|
|
Dim WarnMsg As New EgtMsgBox(m_MainWindow, "", sOut, EgtMsgBox.Buttons.OK, EgtMsgBox.Icons.NULL, 0, 1)
|
|
End If
|
|
End Sub
|
|
|
|
Private Function RemoveOnePart(nId As Integer) As Boolean
|
|
' Verifico sia nel grezzo
|
|
If EgtGetParent(nId) <> m_nRawId Then Return False
|
|
' Recupero identificativi da Info
|
|
Dim sCsvPath As String = String.Empty
|
|
EgtGetInfo(nId, INFO_CSV_PATH, sCsvPath)
|
|
Dim sName As String = String.Empty
|
|
EgtGetInfo(nId, INFO_CSV_PART, sName)
|
|
' Verifico che il pezzo appartenga a questo Csv
|
|
If String.Compare(sCsvPath, m_sCsvPath, True) = 0 Then
|
|
' Cerco il pezzo nella lista dei pezzi
|
|
For i = 1 To m_CsvPartList.Count()
|
|
Dim CurrPart As CsvPart = m_CsvPartList(i - 1)
|
|
If String.Compare(sName, CurrPart.m_sName, True) = 0 Then
|
|
' Rimuovo le lavorazioni
|
|
EraseMachinings(nId)
|
|
' Rimuovo dal grezzo
|
|
EgtRemovePartFromRawPart(nId)
|
|
' Cancello il pezzo
|
|
EgtErase(nId)
|
|
' Aggiorno il contatore
|
|
CurrPart.m_nToNest += 1
|
|
' Esco
|
|
Return True
|
|
End If
|
|
Next
|
|
End If
|
|
' Pezzo non appartenente al Csv corrente
|
|
Return False
|
|
End Function
|
|
|
|
Friend Sub SaveCsvPartList()
|
|
' Se non c'è nulla di attivo, non faccio alcunché
|
|
If String.IsNullOrEmpty(m_sCsvPath) Then
|
|
EgtOutLog("CSV List missing")
|
|
Return
|
|
End If
|
|
' Path del file
|
|
Dim sFile As String = Path.ChangeExtension(m_sCsvPath, ".epl")
|
|
' Gestione file
|
|
Try
|
|
' Apro file
|
|
Dim Writer As New IO.StreamWriter(sFile, False)
|
|
' Intestazione
|
|
Writer.WriteLine("[General]")
|
|
Writer.WriteLine("Path=" & m_sCsvPath)
|
|
' Ciclo sui pezzi
|
|
For i As Integer = 1 To m_CsvPartList.Count()
|
|
Dim CurrPart As CsvPart = m_CsvPartList(i - 1)
|
|
Writer.WriteLine("[P" & i.ToString() & "]")
|
|
Writer.WriteLine("Nam=" & CurrPart.m_sName)
|
|
Writer.WriteLine("Mat=" & CurrPart.m_sMaterial)
|
|
Writer.WriteLine("Act=" & If(CurrPart.m_bActive, "1", "0"))
|
|
Writer.WriteLine("Cnt=" & CurrPart.m_nCount.ToString())
|
|
Writer.WriteLine("Add=" & CurrPart.m_nAdd.ToString())
|
|
Writer.WriteLine("ToN=" & CurrPart.m_nToNest.ToString())
|
|
Writer.WriteLine("Rct=" & If(CurrPart.m_bIsRect, "1", "0"))
|
|
Writer.WriteLine("DX=" & DoubleToString(CurrPart.m_dDimX, 4))
|
|
Writer.WriteLine("DY=" & DoubleToString(CurrPart.m_dDimY, 4))
|
|
Writer.WriteLine("Th=" & DoubleToString(CurrPart.m_dTh, 4))
|
|
Writer.WriteLine("OIn=" & CurrPart.m_nOriInd.ToString())
|
|
Next
|
|
' Terminatore
|
|
Writer.WriteLine("[END]")
|
|
' Chiudo file
|
|
Writer.Close()
|
|
' Registro in ini path
|
|
WritePrivateProfileString(S_CSV, K_CSVLASTFILE, sFile, m_MainWindow.GetIniFile())
|
|
' Errore
|
|
Catch ex As Exception
|
|
EgtOutLog("CSV List error writing " & sFile)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub LoadCsvPartList(sFile As String)
|
|
' Pulisco path e lista dei pezzi Csv
|
|
m_sCsvPath = String.Empty
|
|
m_CsvPartList.Clear()
|
|
' Gestione file
|
|
Try
|
|
' Apro file
|
|
Dim Reader As New IO.StreamReader(sFile, False)
|
|
' Lettura intestazione
|
|
Dim sLine As String = Reader.ReadLine()
|
|
While sLine <> Nothing
|
|
If sLine = "[General]" Then
|
|
' non devo fare alcunché
|
|
ElseIf sLine.Length() >= 5 AndAlso sLine.Substring(0, 5) = "Path=" Then
|
|
Dim sItems() As String = sLine.Split("=".ToCharArray)
|
|
If sItems.Count() >= 2 Then
|
|
m_sCsvPath = sItems(1)
|
|
End If
|
|
Else
|
|
Exit While
|
|
End If
|
|
sLine = Reader.ReadLine()
|
|
End While
|
|
' Ciclo di lettura dei pezzi
|
|
Dim nI As Integer = 1
|
|
Dim sPart As String = "[P" & nI.ToString() & "]"
|
|
Dim OnePart As New CsvPart
|
|
While sLine <> Nothing
|
|
' Inizio pezzo o fine del file
|
|
If sLine = sPart Or sLine = "[END]" Then
|
|
' se esiste pezzo precedente, lo salvo
|
|
If nI > 1 Then
|
|
' inserisco in lista
|
|
m_CsvPartList.Add(OnePart)
|
|
End If
|
|
' predisposizioni per prossimo pezzo
|
|
nI += 1
|
|
sPart = "[P" & nI.ToString() & "]"
|
|
OnePart = New CsvPart
|
|
' Dato
|
|
Else
|
|
Dim sItems() As String = sLine.Split("=".ToCharArray)
|
|
If sItems.Count() >= 2 Then
|
|
If sItems(0) = "Nam" Then
|
|
OnePart.m_sName = sItems(1)
|
|
ElseIf sItems(0) = "Mat" Then
|
|
OnePart.m_sMaterial = sItems(1)
|
|
ElseIf sItems(0) = "Act" Then
|
|
OnePart.m_bActive = If(sItems(1) = "0", False, True)
|
|
ElseIf sItems(0) = "Cnt" Then
|
|
StringToInt(sItems(1), OnePart.m_nCount)
|
|
ElseIf sItems(0) = "Add" Then
|
|
StringToInt(sItems(1), OnePart.m_nAdd)
|
|
ElseIf sItems(0) = "ToN" Then
|
|
StringToInt(sItems(1), OnePart.m_nToNest)
|
|
ElseIf sItems(0) = "Rct" Then
|
|
OnePart.m_bIsRect = If(sItems(1) = "0", False, True)
|
|
ElseIf sItems(0) = "DX" Then
|
|
StringToDouble(sItems(1), OnePart.m_dDimX)
|
|
ElseIf sItems(0) = "DY" Then
|
|
StringToDouble(sItems(1), OnePart.m_dDimY)
|
|
ElseIf sItems(0) = "Th" Then
|
|
StringToDouble(sItems(1), OnePart.m_dTh)
|
|
ElseIf sItems(0) = "OIn" Then
|
|
StringToInt(sItems(1), OnePart.m_nOriInd)
|
|
End If
|
|
End If
|
|
End If
|
|
sLine = Reader.ReadLine()
|
|
End While
|
|
' Chiudo il file
|
|
Reader.Close()
|
|
' Errore
|
|
Catch ex As Exception
|
|
EgtOutLog("Error reading " & sFile)
|
|
End Try
|
|
End Sub
|
|
|
|
'-----------------------------------------------------------------------------------------------
|
|
Private Class CsvPart
|
|
Public m_sName As String = String.Empty
|
|
Public m_sMaterial As String = String.Empty
|
|
Public m_bActive As Boolean = True
|
|
Public m_nCount As Integer = 0
|
|
Public m_nAdd As Integer = 0
|
|
Public m_nToNest As Integer = 0
|
|
Public m_bIsRect As Boolean = True
|
|
Public m_dDimX As Double = 0
|
|
Public m_dDimY As Double = 0
|
|
Public m_dTh As Double = 0
|
|
Public m_nOriInd As Integer = 0
|
|
Public m_nId As Integer = GDB_ID.NULL
|
|
End Class
|
|
|
|
End Class
|