779 lines
33 KiB
VB.net
779 lines
33 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Module CsvM
|
|
|
|
' Dati lista
|
|
Private m_sCsvPath As String = String.Empty
|
|
Public ReadOnly Property CsvPath As String
|
|
Get
|
|
Return m_sCsvPath
|
|
End Get
|
|
End Property
|
|
Private m_sFilePath As String = String.Empty
|
|
Public ReadOnly Property FilePath As String
|
|
Get
|
|
Return m_sFilePath
|
|
End Get
|
|
End Property
|
|
Private m_CsvPartList As New List(Of CsvPart)
|
|
Public ReadOnly Property CsvPartList As List(Of CsvPart)
|
|
Get
|
|
Return m_CsvPartList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_bCsvPartListModified As Boolean = False
|
|
Private m_sCompoDir As String = String.Empty
|
|
|
|
#Region "METHODS"
|
|
|
|
Public Sub InitCsvM()
|
|
' Leggo direttorio componenti
|
|
GetMainPrivateProfileString(S_COMPO, K_COMPODIR, "", m_sCompoDir)
|
|
' Leggo lista pezzi corrente
|
|
Dim sCsvFile As String = String.Empty
|
|
GetMainPrivateProfileString(S_CSV, K_CSVLASTFILE, "", sCsvFile)
|
|
If Not String.IsNullOrEmpty(sCsvFile) Then
|
|
LoadCsvPartList(sCsvFile)
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub NewCmd()
|
|
' Salvo lista dei pezzi attuale (se modificata)
|
|
SaveCsvPartList()
|
|
' Pulisco path e lista dei pezzi Csv
|
|
m_sCsvPath = String.Empty
|
|
m_CsvPartList.Clear()
|
|
m_bCsvPartListModified = False
|
|
' Registro in ini nessuna path
|
|
WriteMainPrivateProfileString(S_CSV, K_CSVLASTFILE, "")
|
|
End Sub
|
|
|
|
Public Sub Open()
|
|
' Leggo direttorio corrente dei file CSV
|
|
Dim sCurrDir As String = ""
|
|
GetMainPrivateProfileString(S_CSV, K_CSVCURRDIR, "C:\", sCurrDir)
|
|
' Apro dialogo scelta file
|
|
Dim CsvFileDlg As New Microsoft.Win32.OpenFileDialog()
|
|
If Directory.Exists(sCurrDir) Then CsvFileDlg.InitialDirectory = sCurrDir
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
Dim sFilterDialog As String = String.Empty
|
|
Dim sDeniedFiles As List(Of String) = CreateListOfDeniedFiles()
|
|
If bFull Then
|
|
sFilterDialog = "Csv file (*.csv;*.epl)|*.csv;*.epl;Merge.epl"
|
|
Else
|
|
sFilterDialog = "Csv file (*.csv)|*.csv"
|
|
End If
|
|
CsvFileDlg.Filter = sFilterDialog
|
|
|
|
If Not CsvFileDlg.ShowDialog() Then Return
|
|
|
|
' Salvo lista dei pezzi attuale
|
|
SaveCsvPartList()
|
|
|
|
' Salvo direttorio corrente
|
|
WriteMainPrivateProfileString(S_CSV, K_CSVCURRDIR, Path.GetDirectoryName(CsvFileDlg.FileName))
|
|
' Apertura file
|
|
Dim sPath = CsvFileDlg.FileName
|
|
' se necessario cambio estensione del file
|
|
If String.Compare(Path.GetExtension(sPath), ".CSV", True) = 0 Then
|
|
LoadCsvFile(sPath)
|
|
Else
|
|
LoadCsvPartList(sPath)
|
|
End If
|
|
End Sub
|
|
|
|
Private Function CreateListOfDeniedFiles() As List(Of String)
|
|
Dim LocalList As New List(Of String)
|
|
LocalList.Add("MERGE")
|
|
Dim Index1 As Integer = 0
|
|
Dim Index2 As Integer = 0
|
|
For Index1 = 0 To m_CsvPartList.Count - 1
|
|
Dim sFileName As String = m_CsvPartList(Index1).m_sPath
|
|
sFileName = Path.GetFileNameWithoutExtension(sFileName).ToUpper.Trim()
|
|
Dim bNewFile As Boolean = True
|
|
For Index2 = 0 To LocalList.Count - 1
|
|
If sFileName = LocalList(Index2) Then
|
|
bNewFile = False
|
|
Exit For
|
|
End If
|
|
Next
|
|
If bNewFile Then
|
|
LocalList.Add(Path.GetFileNameWithoutExtension(sFileName).ToUpper.Trim)
|
|
End If
|
|
Next
|
|
Return LocalList
|
|
End Function
|
|
|
|
Private Function LoadCsvFile(sCsvPath As String) As Boolean
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
' aggiungo i pezzi su una lista temporanea
|
|
Dim LocalPartList As New List(Of CsvPart)
|
|
' Eseguo la lettura del file Csv
|
|
If Not ReadCsvFile(sCsvPath, LocalPartList) Then
|
|
'Errore nella lettura del file CSV
|
|
MessageBox.Show(EgtMsg(91206), "Error", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return False
|
|
End If
|
|
|
|
' Creo un nuovo file che ospitarà il merge de
|
|
Dim sNewMergeFile As String = Path.GetDirectoryName(m_sCsvPath) & "\Merge.csv"
|
|
m_sCsvPath = sNewMergeFile
|
|
m_sFilePath = m_sCsvPath
|
|
|
|
' Elimino pezzi nulli
|
|
RemoveWrongParts(LocalPartList)
|
|
' Aggiorno
|
|
If bFull Then
|
|
MySaveCsvPartList(LocalPartList)
|
|
' 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)
|
|
End If
|
|
' attacco i nuovi pezzi alla lista corrente
|
|
For Each Item As CsvPart In LocalPartList
|
|
m_CsvPartList.Add(Item)
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub LoadCsvPartList(sFile As String)
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
' Se Csv semplificato non va letta
|
|
If Not bFull Then Return
|
|
|
|
' aggiungo i pezzi su una lista temporanea
|
|
Dim LocalPartList As New List(Of CsvPart)
|
|
|
|
' Lettura del file
|
|
If ReadCsvPartList(sFile, LocalPartList) Then
|
|
' Creo un nuovo file che ospitarà il merge de
|
|
Dim sNewMergeFile As String = Path.GetDirectoryName(m_sCsvPath) & "\Merge.csv"
|
|
m_sCsvPath = sNewMergeFile
|
|
m_sFilePath = m_sCsvPath
|
|
End If
|
|
' Elimino pezzi nulli
|
|
RemoveWrongParts(LocalPartList)
|
|
' attacco i nuovi pezzi alla lista corrente
|
|
For Each Item As CsvPart In LocalPartList
|
|
m_CsvPartList.Add(Item)
|
|
Next
|
|
End Sub
|
|
|
|
Public Sub Insert()
|
|
' Recupero lo spessore della lastra corrente
|
|
Dim dRawHeight As Double = EstCalc.GetRawHeight()
|
|
If dRawHeight < EPS_SMALL Then Return
|
|
' Recupero il materiale della lastra corrente
|
|
Dim sCurrMat As String = String.Empty
|
|
If Not IsNothing(CurrentMachine.CurrMat) Then
|
|
sCurrMat = CurrentMachine.CurrMat.sName
|
|
End If
|
|
' Recupero la tolleranza sullo spessore
|
|
Dim dToler As Double = GetMainPrivateProfileDouble(S_CSV, K_THICKTOLERANCE, 100 * EPS_SMALL)
|
|
dToler = Math.Max(dToler, 100 * EPS_SMALL)
|
|
' 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) < dToler And
|
|
(String.IsNullOrWhiteSpace(CurrPart.m_sMaterial) Or
|
|
String.IsNullOrWhiteSpace(sCurrMat) Or
|
|
sCurrMat = "***" Or
|
|
String.Compare(CurrPart.m_sMaterial, sCurrMat, True) = 0) Then
|
|
InsPartList.Add(CurrPart)
|
|
End If
|
|
Next
|
|
' Lancio l'inserimento dei pezzi
|
|
ExecInsert(InsPartList)
|
|
' Dichiaro lista modificata
|
|
m_bCsvPartListModified = True
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Function ExecInsert(InsPartList As List(Of CsvPart)) As Boolean
|
|
Dim bMaxDimOnX As Boolean = (GetMainPrivateProfileInt(S_CSV, K_MAXDIMONX, 1) <> 0)
|
|
If bMaxDimOnX Then
|
|
' Ordino la lista dei pezzi secondo la dimensione minima decrescente (va su Y)
|
|
InsPartList.Sort(Function(P, Q)
|
|
Dim dPMin As Double = Math.Min(P.m_dDimX, P.m_dDimY)
|
|
Dim dQMin As Double = Math.Min(Q.m_dDimX, Q.m_dDimY)
|
|
If Math.Abs(dPMin - dQMin) < EPS_SMALL Then
|
|
Return (P.m_nOriInd - Q.m_nOriInd)
|
|
Else
|
|
Return CInt(Math.Ceiling(dQMin - dPMin))
|
|
End If
|
|
End Function)
|
|
Else
|
|
' Ordino la lista dei pezzi secondo le Y decrescenti
|
|
InsPartList.Sort(Function(P, Q)
|
|
If Math.Abs(P.m_dDimY - Q.m_dDimY) < EPS_SMALL Then
|
|
Return (P.m_nOriInd - Q.m_nOriInd)
|
|
Else
|
|
Return CInt(Math.Ceiling(Q.m_dDimY - P.m_dDimY))
|
|
End If
|
|
End Function)
|
|
End If
|
|
' 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
|
|
Dim dDimX = CurrPart.m_dDimX
|
|
Dim dDimY = CurrPart.m_dDimY
|
|
If bMaxDimOnX And dDimY > dDimX Then
|
|
Dim dTemp As Double = dDimX
|
|
dDimX = dDimY
|
|
dDimY = dTemp
|
|
End If
|
|
EgtLuaSetGlobNumVar("CMP.V1", dDimX)
|
|
EgtLuaSetGlobNumVar("CMP.V2", 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)
|
|
' Eventuale testo per indicare il sopra
|
|
If Not bMaxDimOnX Then
|
|
Dim dH As Double = Math.Min(0.1 * dDimY, 30)
|
|
Dim nText As Integer = EgtCreateTextAdv(nRegId, New Point3d(dDimX / 2, dDimY - 0.6 * dH, 0), 0, "*TOP*", "", 500, False, dH, 1, 0, INS_POS.MC)
|
|
EgtSetColor(nText, New Color3d(0, 0, 0))
|
|
End If
|
|
' Aggiusto per lavorazioni
|
|
AdjustFlatPart(nId)
|
|
' Aggiungo info su CSV di origine
|
|
EgtSetInfo(nId, INFO_CSV_PATH, CurrPart.m_sPath)
|
|
EgtSetInfo(nId, INFO_CSV_PART, CurrPart.m_sName)
|
|
EgtSetInfo(nId, INFO_CSV_ORD, CurrPart.m_sOrd)
|
|
EgtSetInfo(nId, INFO_CSV_DIST, CurrPart.m_sDist)
|
|
EgtSetInfo(nId, INFO_CSV_MAT, CurrPart.m_sMaterial)
|
|
' Imposto colore testi
|
|
EstCalc.SetTextColor(nRegId)
|
|
' Lo sposto nel gruppo speciale
|
|
EgtRelocate(nId, nIpGrp)
|
|
|
|
' assegno l'identificatico del pezzo, se esiste
|
|
If Not String.IsNullOrEmpty(CurrPart.m_sRefGuid) Then
|
|
' GuidCode dovrebbe contenere 36 caratteri, il precode 5: tot = 41
|
|
If CurrPart.m_sRefGuid.Count <= 36 Then
|
|
Dim sPreGuid As String = CreatePreGuidCode(CurrPart.m_nId)
|
|
CurrPart.m_sRefGuid = sPreGuid & CurrPart.m_sRefGuid
|
|
End If
|
|
EgtSetInfo(CurrPart.m_nId, INFO_REFGROUP, CurrPart.m_sRefGuid)
|
|
End If
|
|
Dim nRegLayId As Integer = EgtGetFirstNameInGroup(CurrPart.m_nId, NAME_REGION)
|
|
' Imposto il colore del pezzo inserito nel progetto
|
|
EgtSetColor(nRegLayId, CurrPart.m_cColor)
|
|
Dim EntId As Integer = EgtGetFirstInGroup(nRegLayId)
|
|
While EntId <> GDB_ID.NULL
|
|
If EgtGetType(EntId) = GDB_TY.SRF_FRGN Then EgtSetColor(EntId, CurrPart.m_cColor)
|
|
EntId = EgtGetNext(EntId)
|
|
End While
|
|
|
|
Next
|
|
EgtLuaResetGlobVar("CMP")
|
|
EgtLuaResetGlobVar("CMP_Draw")
|
|
' Provo ad inserire i pezzi
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
Dim bDirect As Boolean = bFull And (GetMainPrivateProfileInt(S_CSV, K_CSVDIRECT, 1) <> 0)
|
|
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, bDirect) Then
|
|
CurrPart.m_nToNest -= 1
|
|
Else
|
|
Exit While
|
|
End If
|
|
End While
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function PackOnePart(nId As Integer, bDirect As Boolean) As Boolean
|
|
' Creo una copia del pezzo nella radice
|
|
Dim nId2 As Integer = EgtCopyGlob(nId, GDB_ID.ROOT)
|
|
If nId2 = GDB_ID.NULL Then Return False
|
|
' Lo inserisco direttamente
|
|
If bDirect Then
|
|
' Aggiungo riferimento e lo inserisco in VeinMatching
|
|
VeinMatching.SetRefOnPart(nId2)
|
|
VeinMatching.AddPart(nId2, True)
|
|
' Provo inserimento in lastra
|
|
If EstCalc.InsertOnePart(nId2, CurrentMachine.bAligned, CurrentMachine.bReducedCut) Then
|
|
' Eventuale notifica al VeinMatching
|
|
VeinMatching.OnInsertPartInRaw(nId2)
|
|
Return True
|
|
Else
|
|
' Eventuale cancellazione per VM
|
|
VeinMatching.OnRemovePart(nId2)
|
|
' Cancellazione del pezzo
|
|
EraseMachinings(nId2)
|
|
EgtRemovePartFromRawPart(nId2)
|
|
EgtErase(nId2)
|
|
Return False
|
|
End If
|
|
' altrimenti lo metto in parcheggio
|
|
Else
|
|
' Aggiungo riferimento e lo inserisco in VeinMatching
|
|
VeinMatching.SetRefOnPart(nId2)
|
|
VeinMatching.AddPart(nId2, True)
|
|
' Inserisco in parcheggio
|
|
EstCalc.StoreOnePart(nId2, True)
|
|
Return True
|
|
End If
|
|
End Function
|
|
|
|
Public Sub Remove(ByRef bOther As Boolean, ByRef sOtherCsv As String)
|
|
' 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
|
|
' Dichiaro lista modificata
|
|
m_bCsvPartListModified = True
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Function RemoveOnePart(nId As Integer) As Boolean
|
|
' 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 SearchCurrCSV(sCsvPath) 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 And String.Compare(sCsvPath, CurrPart.m_sPath, True) = 0 Then
|
|
' Se era nel grezzo
|
|
If EgtGetParent(nId) = EstCalc.GetRawId() Then
|
|
' Rimuovo le lavorazioni
|
|
EraseMachinings(nId)
|
|
' Rimuovo dal grezzo
|
|
EgtRemovePartFromRawPart(nId)
|
|
End If
|
|
' recupero il Guid del pezzo corrente (potrebbe essere stato modificato a causa di rotazioni quando il pezzo è passato in parcheggio)
|
|
Dim sCurrRefGuid As String = String.Empty
|
|
EgtGetInfo(nId, INFO_REFGROUP, sCurrRefGuid)
|
|
' Eventuale cancellazione per VM
|
|
VeinMatching.OnRemovePart(nId)
|
|
' Cancello il pezzo
|
|
EgtErase(nId)
|
|
' aggiorno il layer che indica il numero di pezzi in parcheggio (se sRefGroup<>"")
|
|
EstCalc.CountPartInFamily(sCurrRefGuid)
|
|
' Aggiorno il contatore
|
|
CurrPart.m_nToNest += 1
|
|
' ricreo la lista delle famiglie di pezzi presenti in parcheggio
|
|
GetFamilyGroupInPark()
|
|
' Esco
|
|
Return True
|
|
End If
|
|
Next
|
|
End If
|
|
' Pezzo non appartenente al Csv corrente
|
|
Return False
|
|
End Function
|
|
|
|
Private Function SearchCurrCSV(ByVal sCSVFile As String) As Boolean
|
|
For i As Integer = 1 To m_CsvPartList.Count()
|
|
Dim CurrPart As CsvPart = m_CsvPartList(i - 1)
|
|
If String.Compare(sCSVFile, CurrPart.m_sPath, True) = 0 Then
|
|
Return True
|
|
End If
|
|
Next
|
|
Return False
|
|
End Function
|
|
|
|
Private Function ReadCsvFile(sCsvPath As String, ByRef LocalCsvPartList As List(Of CsvPart)) As Boolean
|
|
' Pulisco path e lista dei pezzi Csv
|
|
m_sCsvPath = String.Empty
|
|
' Definizione variabili
|
|
EgtLuaCreateGlobTable("CSV")
|
|
EgtLuaSetGlobStringVar("CSV.FILE", sCsvPath)
|
|
' Esecuzione
|
|
Dim nErr As Integer = 999
|
|
Dim sReader As String = String.Empty
|
|
GetMainPrivateProfileString(S_CSV, K_READER, "CsvRead.lua", sReader)
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
Dim sLuaScript As String = OmagOFFICEMap.refMainWindowVM.MainWindowM.sCsvAutoDir & If(bFull, "\" & sReader, "\CsvSimplRead.lua")
|
|
If EgtLuaExecFile(sLuaScript) 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()
|
|
OnePart.m_sPath = sCsvPath
|
|
EgtLuaGetGlobStringVar("CSV.NAME" & sN, OnePart.m_sName)
|
|
OnePart.m_bActive = True
|
|
EgtLuaGetGlobStringVar("CSV.ORD" & sN, OnePart.m_sOrd)
|
|
EgtLuaGetGlobStringVar("CSV.DIST" & sN, OnePart.m_sDist)
|
|
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)
|
|
EgtLuaGetGlobNumVar("CSV.A1_" & sN, OnePart.m_dAng1)
|
|
EgtLuaGetGlobNumVar("CSV.H1_" & sN, OnePart.m_dHeel1)
|
|
EgtLuaGetGlobNumVar("CSV.A2_" & sN, OnePart.m_dAng2)
|
|
EgtLuaGetGlobNumVar("CSV.H2_" & sN, OnePart.m_dHeel2)
|
|
EgtLuaGetGlobNumVar("CSV.A3_" & sN, OnePart.m_dAng3)
|
|
EgtLuaGetGlobNumVar("CSV.H3_" & sN, OnePart.m_dHeel3)
|
|
EgtLuaGetGlobNumVar("CSV.A4_" & sN, OnePart.m_dAng4)
|
|
EgtLuaGetGlobNumVar("CSV.H4_" & sN, OnePart.m_dHeel4)
|
|
OnePart.m_nOriInd = i
|
|
If OnePart.m_nCount > 1 Then
|
|
OnePart.m_sRefGuid = System.Guid.NewGuid.ToString
|
|
End If
|
|
' inserisco in lista
|
|
LocalCsvPartList.Add(OnePart)
|
|
Next
|
|
EgtLuaResetGlobVar("CSV")
|
|
' Ordinamento lista dei pezzi (ordine crescente su materiale e spessore)
|
|
LocalCsvPartList.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)
|
|
Return True
|
|
End Function
|
|
|
|
Public Function WriteCsvPartList(sFile As String, sCsvPath As String, LocalCsvPartList As List(Of CsvPart)) As Boolean
|
|
Try
|
|
' Apro file
|
|
Dim Writer As New IO.StreamWriter(sFile, False)
|
|
' Intestazione
|
|
Writer.WriteLine("[General]")
|
|
Writer.WriteLine("Path=" & sCsvPath)
|
|
' Ciclo sui pezzi
|
|
For i As Integer = 1 To LocalCsvPartList.Count()
|
|
Dim CurrPart As CsvPart = LocalCsvPartList(i - 1)
|
|
Writer.WriteLine("[P" & i.ToString() & "]")
|
|
Writer.WriteLine("Path=" & CurrPart.m_sPath)
|
|
Writer.WriteLine("Nam=" & CurrPart.m_sName)
|
|
Writer.WriteLine("Ord=" & CurrPart.m_sOrd)
|
|
Writer.WriteLine("Dist=" & CurrPart.m_sDist)
|
|
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("A1=" & DoubleToString(CurrPart.m_dAng1, 4))
|
|
Writer.WriteLine("H1=" & DoubleToString(CurrPart.m_dHeel1, 4))
|
|
Writer.WriteLine("A2=" & DoubleToString(CurrPart.m_dAng2, 4))
|
|
Writer.WriteLine("H2=" & DoubleToString(CurrPart.m_dHeel2, 4))
|
|
Writer.WriteLine("A3=" & DoubleToString(CurrPart.m_dAng3, 4))
|
|
Writer.WriteLine("H3=" & DoubleToString(CurrPart.m_dHeel3, 4))
|
|
Writer.WriteLine("A4=" & DoubleToString(CurrPart.m_dAng4, 4))
|
|
Writer.WriteLine("H4=" & DoubleToString(CurrPart.m_dHeel4, 4))
|
|
Writer.WriteLine("OIn=" & CurrPart.m_nOriInd.ToString())
|
|
Writer.WriteLine("Guid=" & CurrPart.m_sRefGuid)
|
|
Next
|
|
' Terminatore
|
|
Writer.WriteLine("[END]")
|
|
' Chiudo file
|
|
Writer.Close()
|
|
' Dichiaro lista non più modificata
|
|
m_bCsvPartListModified = False
|
|
' Registro in ini path
|
|
WriteMainPrivateProfileString(S_CSV, K_CSVLASTFILE, sFile)
|
|
Return True
|
|
' Errore
|
|
Catch ex As Exception
|
|
EgtOutLog("CSV List error writing " & sFile)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
' dato l'elenco completo dei file salvo ogni singolo epl
|
|
Friend Function WriteCsvMergePartList(CsvPartList As List(Of CsvPart)) As Boolean
|
|
Dim bOk As Boolean = True
|
|
Dim LocalPartList As New List(Of CsvPart)
|
|
Dim Index As Integer = 0
|
|
' devo dividere la lista in tante parti quanti sono i file che lo costituiscono
|
|
While Index < CsvPartList.Count
|
|
Dim CurrFile As String = CsvPartList(Index).m_sPath
|
|
Dim sFile As String = Path.ChangeExtension(CurrFile, ".epl")
|
|
LocalPartList.Clear()
|
|
While CurrFile = CsvPartList(Index).m_sPath
|
|
LocalPartList.Add(CsvPartList(Index))
|
|
Index += 1
|
|
' se terminata la lista
|
|
If Index = CsvPartList.Count Then
|
|
Exit While
|
|
End If
|
|
End While
|
|
' salvo l'elenco corrente
|
|
bOk = WriteCsvPartList(sFile, CurrFile, LocalPartList) And bOk
|
|
End While
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Sub SaveCsvPartList()
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
' Se Csv semplificato non va salvata
|
|
If Not bFull Then Return
|
|
' 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_sFilePath, ".epl")
|
|
' Scrittura dei file
|
|
If WriteCsvMergePartList(m_CsvPartList) Then
|
|
' Scrittura dei file Merge
|
|
If WriteCsvPartList(sFile, m_sCsvPath, m_CsvPartList) Then
|
|
WriteMainPrivateProfileString(S_CSV, K_CSVLASTFILE, sFile)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub MySaveCsvPartList(ByVal CurrPartList As List(Of CsvPart))
|
|
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
|
|
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
|
|
' Se Csv semplificato non va salvata
|
|
If Not bFull Then Return
|
|
Dim sCurrPath As String = String.Empty
|
|
' recupero dalla lista il nome del file corrente
|
|
For Each Item As CsvPart In CurrPartList
|
|
sCurrPath = Item.m_sPath
|
|
Next
|
|
' se non trov il nome del file assocciato all'elenco di pezzi esco
|
|
If String.IsNullOrEmpty(sCurrPath) Then
|
|
EgtOutLog("CSV Curr list missing")
|
|
Return
|
|
End If
|
|
' Path del file
|
|
Dim sFile As String = Path.ChangeExtension(sCurrPath, ".epl")
|
|
' Scrittura del file
|
|
WriteCsvPartList(sFile, sCurrPath, CurrPartList)
|
|
End Sub
|
|
|
|
Private Function ReadCsvPartList(sFile As String, LocalCsvPartList As List(Of CsvPart)) As Boolean
|
|
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
|
|
LocalCsvPartList.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) = "Path" Then
|
|
OnePart.m_sPath = sItems(1)
|
|
ElseIf sItems(0) = "Nam" Then
|
|
OnePart.m_sName = sItems(1)
|
|
ElseIf sItems(0) = "Ord" Then
|
|
OnePart.m_sOrd = sItems(1)
|
|
ElseIf sItems(0) = "Dist" Then
|
|
OnePart.m_sDist = 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) = "A1" Then
|
|
StringToDouble(sItems(1), OnePart.m_dAng1)
|
|
ElseIf sItems(0) = "H1" Then
|
|
StringToDouble(sItems(1), OnePart.m_dHeel1)
|
|
ElseIf sItems(0) = "A2" Then
|
|
StringToDouble(sItems(1), OnePart.m_dAng2)
|
|
ElseIf sItems(0) = "H2" Then
|
|
StringToDouble(sItems(1), OnePart.m_dHeel2)
|
|
ElseIf sItems(0) = "A3" Then
|
|
StringToDouble(sItems(1), OnePart.m_dAng3)
|
|
ElseIf sItems(0) = "H3" Then
|
|
StringToDouble(sItems(1), OnePart.m_dHeel3)
|
|
ElseIf sItems(0) = "A4" Then
|
|
StringToDouble(sItems(1), OnePart.m_dAng4)
|
|
ElseIf sItems(0) = "H4" Then
|
|
StringToDouble(sItems(1), OnePart.m_dHeel4)
|
|
ElseIf sItems(0) = "OIn" Then
|
|
StringToInt(sItems(1), OnePart.m_nOriInd)
|
|
ElseIf sItems(0) = "Guid" Then
|
|
OnePart.m_sRefGuid = sItems(1).Trim
|
|
End If
|
|
End If
|
|
End If
|
|
sLine = Reader.ReadLine()
|
|
End While
|
|
' Chiudo il file
|
|
Reader.Close()
|
|
' Dichiaro lista non modificata
|
|
m_bCsvPartListModified = False
|
|
Return True
|
|
' Errore
|
|
Catch ex As Exception
|
|
EgtOutLog("Error reading " & sFile)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Friend Function RemoveNotToNestParts(ByRef CsvPartList As List(Of CsvPart)) As Boolean
|
|
For i As Integer = CsvPartList.Count() - 1 To 0 Step -1
|
|
If CsvPartList(i).m_nToNest = 0 Then
|
|
CsvPartList.RemoveAt(i)
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function RemoveWrongParts(ByRef CsvPartList As List(Of CsvPart)) As Boolean
|
|
For i As Integer = CsvPartList.Count() - 1 To 0 Step -1
|
|
If Not CsvPartList(i).m_bIsRect Or CsvPartList(i).m_dDimX < EPS_SMALL Or CsvPartList(i).m_dDimY < EPS_SMALL Then
|
|
CsvPartList.RemoveAt(i)
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
#End Region ' METHODS
|
|
|
|
End Module
|
|
|
|
Public Class CsvPart
|
|
Public m_sPath As String = String.Empty
|
|
Public m_sName As String = String.Empty
|
|
Public m_sOrd As String = String.Empty
|
|
Public m_sDist 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_dAng1 As Double = 0
|
|
Public m_dHeel1 As Double = 0
|
|
Public m_dAng2 As Double = 0
|
|
Public m_dHeel2 As Double = 0
|
|
Public m_dAng3 As Double = 0
|
|
Public m_dHeel3 As Double = 0
|
|
Public m_dAng4 As Double = 0
|
|
Public m_dHeel4 As Double = 0
|
|
Public m_nOriInd As Integer = 0
|
|
Public m_nId As Integer = GDB_ID.NULL
|
|
' definsco il riferimento al gruppo
|
|
Public m_sRefGuid As String = System.Guid.NewGuid.ToString
|
|
' definisco il colore del gruppo che sto inserendo
|
|
Public m_cColor As Color3d = CompoColor(IniFile.m_sIniFile)
|
|
End Class
|