Files
SarmaxWall/PlacePageUC.xaml.vb
T
Emmanuele Sassi d07fa7216e SarmaxWall:
- Prima versione della pagina Options.
2015-09-28 09:26:33 +00:00

603 lines
27 KiB
VB.net

Imports EgtUILib
Public Class PlacePageUC
' Riferimento alla MainWindow
Private m_MainWindow As MainWindow = Application.Current.MainWindow
' Dichiarazione del UserControl SceneButtons
Friend m_SceneButtons As SceneButtonsUC
' Properties
Private m_bFirst As Boolean = True
' Dichiarazione Scene
Friend WithEvents PlaceScene As New Scene
Private PlaceSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
' Flag per pezzi selezionati in tavola o fuori
Private m_nPartPos As Integer = PART_POS.NONE_TABLE
Enum PART_POS As Integer
IN_TABLE = -1
NONE_TABLE = 0
OUT_TABLE = 1
End Enum
' Dati per Drag
Private m_bDrag As Boolean = False
Private m_ptPrev As Point3d
' Dati macchina
Friend m_dLength As Double = 0
Friend m_dWidth As Double = 0
Friend m_dOffsetX As Double = 0
Friend m_dOffsetY As Double = 0
Friend m_dMinDist As Double = 0
Friend m_dParkMaxY As Double = -1000
' Dati movimento
Friend m_dStep As Double = 0
Friend m_dMaxStep As Double = 0
Private m_bMaximizeMove As Boolean = False
' Spessore layer (strato)
Private m_dLayerThick As Double = 0
Private Sub PlacePage_Initialized(sender As Object, e As EventArgs)
'Creazione del UserCOntrol SceneButtons
m_SceneButtons = New SceneButtonsUC
'Posizionemento nella griglia del UserControl SceneButtons
m_SceneButtons.SetValue(Grid.ColumnProperty, 0)
BottomButtonsGrid.Children.Add(m_SceneButtons)
'Assegnazione scena all'host e posizionamento nella PlacePageGrid
PlaceSceneHost.Child = PlaceScene
PlaceSceneHost.SetValue(Grid.ColumnProperty, 1)
PlaceSceneHost.SetValue(Grid.RowProperty, 0)
Me.PlacePageGrid.Children.Add(PlaceSceneHost)
'Imposto i messaggi letti dal file dei messaggi
GenerateBtn.Content = EgtMsg(MSG_PLACEPAGEUC + 1) 'Generate - Genera
SendBtn.Content = EgtMsg(MSG_PLACEPAGEUC + 2) 'Send - Trasmetti
WallPositioningLbl.Content = EgtMsg(MSG_PLACEPAGEUC + 3) 'Wall position - Posizionamento parete
InsertWallTxt.Text = EgtMsg(MSG_PLACEPAGEUC + 4) 'Insert wall - Inserisci parete
StoreWallTxt.Text = EgtMsg(MSG_PLACEPAGEUC + 5) 'Store wall - Parcheggia parete
RemoveWallBtn.Content = EgtMsg(MSG_PLACEPAGEUC + 6) 'Remove wall - Elimina parete
LayerThicknessLbl.Text = EgtMsg(MSG_PLACEPAGEUC + 7) 'Layer thickness - Spessore strato
PlankNumFirstLayerLbl.Text = EgtMsg(MSG_PLACEPAGEUC + 8) ' - Numero tavola primo piano
' Associo TextBox e Label
Dim TempLabel1 As New Label
TempLabel1.Content = LayerThicknessLbl.Text
LayerThicknessTxBx.Tag = TempLabel1
Dim TempLabel2 As New Label
TempLabel2.Content = PlankNumFirstLayerLbl.Text
PlankNumFirstLayerTxBx.Tag = TempLabel2
End Sub
Private Sub PlacePage_Loaded(sender As Object, e As RoutedEventArgs)
If m_bFirst Then
' imposto colore di default
Dim DefColor As New Color3d(0, 0, 0)
GetPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor, m_MainWindow.GetIniFile())
PlaceScene.SetDefaultMaterial(DefColor)
' imposto colori sfondo
Dim BackTopColor As New Color3d(192, 192, 192)
GetPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor, m_MainWindow.GetIniFile())
Dim BackBotColor As New Color3d(BackTopColor)
GetPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor, m_MainWindow.GetIniFile())
PlaceScene.SetViewBackground(BackTopColor, BackBotColor)
' imposto colore di evidenziazione
Dim MarkColor As New Color3d(255, 255, 0)
GetPrivateProfileColor(S_SCENE, K_MARK, MarkColor, m_MainWindow.GetIniFile())
PlaceScene.SetMarkMaterial(MarkColor)
' imposto colore per superfici selezionate
Dim SelSurfColor As New Color3d(255, 255, 192)
GetPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor, m_MainWindow.GetIniFile())
PlaceScene.SetSelSurfMaterial(SelSurfColor)
' imposto tipo e colore del rettangolo di zoom
Dim bOutline As Boolean = True
Dim ZwColor As New Color3d(0, 0, 0)
GetPrivateProfileZoomWin(S_SCENE, K_ZOOMWIN, bOutline, ZwColor, m_MainWindow.GetIniFile())
PlaceScene.SetZoomWinAttribs(bOutline, ZwColor)
' imposto colore della linea di distanza
Dim DstLnColor As New Color3d(255, 0, 0)
GetPrivateProfileColor(S_SCENE, K_DISTLINE, DstLnColor, m_MainWindow.GetIniFile())
PlaceScene.SetDistLineMaterial(DstLnColor)
' imposto parametri OpenGL
Dim nDriver As Integer = GetPrivateProfileInt(S_OPENGL, K_DRIVER, 3, m_MainWindow.GetIniFile())
Dim b2Buff As Boolean = (GetPrivateProfileInt(S_OPENGL, K_DOUBLEBUFFER, 1, m_MainWindow.GetIniFile()) <> 0)
Dim nColorBits As Integer = GetPrivateProfileInt(S_OPENGL, K_COLORBITS, 32, m_MainWindow.GetIniFile())
Dim nDepthBits As Integer = GetPrivateProfileInt(S_OPENGL, K_DEPTHBITS, 32, m_MainWindow.GetIniFile())
PlaceScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
' inizializzo la scena (DB geometrico + visualizzazione) e verifico presenza chiave
If Not PlaceScene.Init() Then
Dim m_MissingKeyWindow As New MissingKeyWD
m_MissingKeyWindow.Top = m_MainWindow.Top + (m_MainWindow.Height / 2 - m_MissingKeyWindow.Height / 2)
m_MissingKeyWindow.Left = m_MainWindow.Left + (m_MainWindow.Width / 2 - m_MissingKeyWindow.Width / 2)
m_MainWindow.Close()
m_MissingKeyWindow.Show()
End If
' Se richiesto, carico l'ultimo progetto
Dim nAutoLoad As Integer = GetPrivateProfileInt(S_GENERAL, K_AUTOLOADLASTPROJ, 0, m_MainWindow.GetIniFile())
If nAutoLoad <> 0 Then
If Not LoadLastProject() Then
EgtOutLog("Error loading last project")
End If
End If
' Carico la macchina
EgtDisableModified()
If Not LoadMachine() Then
EgtOutLog("Error loading machine")
End If
EgtEnableModified()
' carico i parametri di posizionamento
m_dOffsetX = GetPrivateProfileDouble(S_MACHINE, K_OFFSETX, 0, m_MainWindow.GetIniFile())
m_dOffsetY = GetPrivateProfileDouble(S_MACHINE, K_OFFSETY, 0, m_MainWindow.GetIniFile())
m_dMinDist = GetPrivateProfileDouble(S_MACHINE, K_MINDIST, 0, m_MainWindow.GetIniFile())
' carico e calcolo i parametri di movimento
m_dStep = GetPrivateProfileDouble(S_MACHINE, K_STEP, 0, m_MainWindow.GetIniFile())
m_dMaxStep = Math.Max(m_dLength - m_dOffsetX, m_dWidth - m_dOffsetY)
' carico lo spessore dei layer e lo visualizzo
m_dLayerThick = GetPrivateProfileDouble(S_MACHINE, K_LAYERTHICK, 0, m_MainWindow.GetIniFile())
LayerThicknessTxBx.Text = m_dLayerThick
' carico la griglia
LoadGridData()
m_bFirst = False
Else
EgtSetCurrentContext(PlaceScene.GetCtx())
End If
' inibisco selezione diretta da Scene
PlaceScene.SetStatusNull()
End Sub
Private Sub MaximizeMoveBtn_Click(sender As Object, e As RoutedEventArgs) Handles MaximizeMoveBtn.Click
If MaximizeMoveBtn.IsChecked Then
m_bMaximizeMove = True
Else
m_bMaximizeMove = False
End If
End Sub
Private Function LoadLastProject() As Boolean
' Carico l'ultimo progetto
Dim sPath As String = m_MainWindow.GetDataDir() & "\0000.nge"
If Not EgtOpenFile(sPath) Then
Return False
End If
' Recupero il contrassegno
Dim nMarkId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_PROJMARK)
If nMarkId = GDB_ID.NULL Then
EgtNewFile()
EgtResetModified()
Return False
End If
' Leggo lo stato di modificato
Dim nModif As Integer = 1
EgtGetInfo(nMarkId, INFO_MODIF, nModif)
' Cancello macchina e contrassegno
Dim nMachineId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_MACHINE)
EgtErase(nMachineId)
EgtErase(nMarkId)
' Imposto lo stato originale di modificato
If nModif <> 0 Then
EgtSetModified()
Else
EgtResetModified()
End If
Return True
End Function
Private Function LoadMachine() As Boolean
' Recupero path del file macchina
Dim sMachFile As String = String.Empty
GetPrivateProfileString(S_MACHINE, K_GEOMETRY, "", sMachFile, m_MainWindow.GetIniFile())
' Carico la macchina
If Not EgtInsertFile(sMachFile) Then
Return False
End If
' Recupero la macchina e la imposto a livello System
Dim nMachineId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_MACHINE)
If nMachineId = GDB_ID.NULL Or EgtGetType(nMachineId) <> GDB_TY.GROUP Then
Return False
End If
EgtSetLevel(nMachineId, GDB_LV.SYSTEM)
' Eseguo zoom all
EgtZoom(ZM.ALL)
' Recupero la tavola
Dim nTableId As Integer = EgtGetFirstNameInGroup(nMachineId, NAME_TABLE)
If nTableId = GDB_ID.NULL Or EgtGetType(nMachineId) <> GDB_TY.GROUP Then
Return False
End If
' Recupero dimensioni tavola
EgtGetInfo(nTableId, KEY_TABLENGTH, m_dLength)
EgtGetInfo(nTableId, KEY_TABWIDTH, m_dWidth)
' Inserisco contrassegno di progetto SarmaxWall valido
Dim nMarkId As Integer = EgtCreateGroup(GDB_ID.ROOT)
EgtSetName(nMarkId, NAME_PROJMARK)
EgtSetLevel(nMarkId, GDB_LV.SYSTEM)
Return True
End Function
Private Sub LoadGridData()
Dim dSnapStep As Double = GetPrivateProfileDouble(S_GRID, K_SNAPSTEP, 10, m_MainWindow.GetIniFile())
Dim nMinLineSStep As Integer = GetPrivateProfileInt(S_GRID, K_MINLINESSTEP, 1, m_MainWindow.GetIniFile())
Dim nMajLineSStep As Integer = GetPrivateProfileInt(S_GRID, K_MAJLINESSTEP, 10, m_MainWindow.GetIniFile())
Dim nExtSStep As Integer = GetPrivateProfileInt(S_GRID, K_EXTSSTEP, 50, m_MainWindow.GetIniFile())
Dim MinLnColor As New Color3d(160, 160, 160)
GetPrivateProfileColor(S_GRID, K_MINLNCOLOR, MinLnColor, m_MainWindow.GetIniFile())
Dim MajLnColor As New Color3d(160, 160, 160)
GetPrivateProfileColor(S_GRID, K_MAJLNCOLOR, MajLnColor, m_MainWindow.GetIniFile())
EgtSetGridFrame(Frame3d.GLOB)
EgtSetGridGeo(dSnapStep, nMinLineSStep, nMajLineSStep, nExtSStep)
EgtSetGridColor(MinLnColor, MajLnColor)
Dim frGrid As New Frame3d(New Point3d(m_dOffsetX, m_dOffsetY, 0))
EgtSetGridFrame(frGrid)
Dim bShowGrid As Boolean = (GetPrivateProfileInt(S_GRID, K_SHOWGRID, 1, m_MainWindow.GetIniFile()) <> 0)
EgtSetGridShow(bShowGrid, False)
End Sub
Friend Sub MyDraw()
EgtDraw()
If EgtGetModified() Then
MessageTxBx.Text = ""
MessageBrd.Background = Brushes.White
End If
End Sub
Private Sub OnMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PlaceScene.OnMouseDownScene
' Si può selezionare solo con il tasto sinistro e se stato NULL
If e.Button <> Windows.Forms.MouseButtons.Left Or Not PlaceScene.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))
If EgtIsPart(nPartId) Then
Dim nStat As Integer = GDB_ST.ON_
EgtGetStatus(nPartId, nStat)
Dim bInTable As Boolean = IsPartInTable(nPartId)
' Se selezionato o posizione oggetto incompatibile con flag posizione selezionati
If nStat = GDB_ST.SEL Or
(bInTable And m_nPartPos = PART_POS.OUT_TABLE) Or
(Not bInTable And m_nPartPos = PART_POS.IN_TABLE) Then
' Deseleziono
EgtDeselectObj(nPartId)
' Se nessun pezzo selezionato, reset flag posizione selezionati
If EgtGetSelectedObjCount() = 0 Then
m_nPartPos = PART_POS.NONE_TABLE
End If
Else
EgtSelectObj(nPartId)
' Set flag posizione selezionati
m_nPartPos = IIf(bInTable, PART_POS.IN_TABLE, PART_POS.OUT_TABLE)
End If
MyDraw()
Exit While
End If
nId = EgtGetNextObjInSelWin()
End While
' Dati per drag
m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev)
End Sub
Private Sub OnMouseMoveScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PlaceScene.OnMouseMoveScene
If Not m_bDrag Or m_nPartPos <> PART_POS.IN_TABLE Then
Return
End If
' Ricavo il punto corrente in coordinate mondo
Dim ptCurr As Point3d
EgtUnProjectPoint(e.Location, ptCurr)
' Ricavo il vettore di movimento
Dim vtMove As Vector3d = ptCurr - m_ptPrev
' Muovo i pezzi selezionati di quanto possibile
EgtMoveSelectedCluster(vtMove, m_dOffsetX, m_dOffsetY, m_dLength, m_dWidth, m_dMinDist)
MyDraw()
' Aggiorno il punto precedente
'm_ptPrev += vtMove
m_ptPrev = ptCurr
End Sub
Private Sub OnMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PlaceScene.OnMouseUpScene
' Disabilito modalità drag
m_bDrag = False
End Sub
Private Function IsPartInTable(ByVal nPartId As Integer) As Boolean
If Not EgtIsPart(nPartId) Then
Return False
End If
Dim ptMin, ptMax As Point3d
Dim BBF_FLAG As Integer = GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM
If Not EgtGetBBoxGlob(nPartId, BBF_FLAG, ptMin, ptMax) Then
Return False
End If
If ptMax.x < m_dOffsetX - EPS_SMALL Or ptMin.x > m_dLength + EPS_SMALL Or
ptMax.y < m_dOffsetY - EPS_SMALL Or ptMin.y > m_dWidth + EPS_SMALL Then
Return False
End If
Return True
End Function
Private Sub UpBtn_Click(sender As Object, e As RoutedEventArgs) Handles UpBtn.Click
Dim dStep As Double = IIf(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMoveSelectedCluster(New Vector3d(0, dStep, 0), m_dOffsetX, m_dOffsetY, m_dLength, m_dWidth, m_dMinDist)
MyDraw()
End Sub
Private Sub DownBtn_Click(sender As Object, e As RoutedEventArgs) Handles DownBtn.Click
Dim dStep As Double = IIf(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMoveSelectedCluster(New Vector3d(0, -dStep, 0), m_dOffsetX, m_dOffsetY, m_dLength, m_dWidth, m_dMinDist)
MyDraw()
End Sub
Private Sub RightBtn_Click(sender As Object, e As RoutedEventArgs) Handles RightBtn.Click
Dim dStep As Double = IIf(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMoveSelectedCluster(New Vector3d(dStep, 0, 0), m_dOffsetX, m_dOffsetY, m_dLength, m_dWidth, m_dMinDist)
MyDraw()
End Sub
Private Sub LeftBtn_Click(sender As Object, e As RoutedEventArgs) Handles LeftBtn.Click
Dim dStep As Double = IIf(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMoveSelectedCluster(New Vector3d(-dStep, 0, 0), m_dOffsetX, m_dOffsetY, m_dLength, m_dWidth, m_dMinDist)
MyDraw()
End Sub
Private Sub RotateCounterClockwiseBtn_Click(sender As Object, e As RoutedEventArgs) Handles RotateCounterClockwiseBtn.Click
RotateCluster(90)
MyDraw()
End Sub
Private Sub RotateClockwiseBtn_Click(sender As Object, e As RoutedEventArgs) Handles RotateClockwiseBtn.Click
RotateCluster(-90)
MyDraw()
End Sub
Private Sub RotateHalfTurnBtn_Click(sender As Object, e As RoutedEventArgs) Handles RotateHalfTurnBtn.Click
' Se non ci sono pezzi selezionati, esco
Dim nCount As Integer = EgtGetSelectedObjCount()
If nCount = 0 Then
Return
End If
' Se un solo pezzo, non sono necessarie verifiche
If nCount = 1 Then
' Recupero il box del cluster di pezzi
Dim ptMin As Point3d
Dim ptMax As Point3d
If Not EgtGetSelectedClusterBBoxGlob(ptMin, ptMax) Then
Return
End If
' Ne derivo il centro di rotazione come centro del cluster
Dim ptCen As Point3d = Point3d.Media(ptMin, ptMax, 0.5)
' Rotazione dei pezzi attorno al loro centro
EgtRotate(GDB_ID.SEL, ptCen, Vector3d.Z_AX(), 180, GDB_RT.GLOB)
MyDraw()
Return
End If
' Caso generale
RotateCluster(180)
MyDraw()
End Sub
Private Function RotateCluster(ByVal dAngRotDeg As Double) As Boolean
' Se non ci sono pezzi selezionati, esco
If EgtGetSelectedObjCount() = 0 Then
Return True
End If
' Recupero il box del cluster di pezzi
Dim ptMin As Point3d
Dim ptMax As Point3d
If Not EgtGetSelectedClusterBBoxGlob(ptMin, ptMax) Then
Return False
End If
' Ne derivo il centro di rotazione come centro del cluster
Dim ptCen As Point3d = Point3d.Media(ptMin, ptMax, 0.5)
' Rotazione dei pezzi attorno al loro centro
EgtRotate(GDB_ID.SEL, ptCen, Vector3d.Z_AX(), dAngRotDeg, GDB_RT.GLOB)
' Se pezzi in parcheggio, li risistemo qui (sempre possibile)
If m_nPartPos <> PART_POS.IN_TABLE Then
EgtPackSelectedCluster(m_dOffsetX, -INFINITO, m_dLength, m_dParkMaxY, m_dMinDist, False)
Return True
End If
' Se pezzi in tavola, cerco di sistemarli qui (se impossibile, annullo la rotazione)
' Recupero nuovo box
EgtGetSelectedClusterBBoxGlob(ptMin, ptMax)
' Se non esce dalla tavola, provo un pack sul posto
If ptMin.x > m_dOffsetX - EPS_SMALL And ptMin.y > m_dOffsetY - EPS_SMALL And
ptMax.x < m_dLength + EPS_SMALL And ptMax.y < m_dWidth + EPS_SMALL Then
If EgtPackSelectedCluster(ptMin.x, ptMin.y, ptMax.x + 1, ptMax.y + 1, m_dMinDist, True) Then
Return True
End If
End If
' Provo un pack un poco più esteso
Dim dDim As Double = Math.Max(ptMax.x - ptMin.x, ptMax.y - ptMin.y)
ptMin.x = ptCen.x - 0.5 * dDim
ptMin.y = ptCen.y - 0.5 * dDim
ptMax.x = ptCen.x + 0.5 * dDim
ptMax.y = ptCen.y + 0.5 * dDim
If (ptMin.x < m_dOffsetX) Then
ptMax.x += m_dOffsetX - ptMin.x
ptMax.x = Math.Min(ptMax.x, m_dLength)
ptMin.x = m_dOffsetX
End If
If (ptMin.y < m_dOffsetY) Then
ptMax.y += m_dOffsetY - ptMin.y
ptMax.y = Math.Min(ptMax.y, m_dWidth)
ptMin.y = m_dOffsetY
End If
If (ptMax.x > m_dLength) Then
ptMin.x += m_dLength - ptMax.x
ptMin.x = Math.Max(ptMin.x, m_dOffsetX)
ptMax.x = m_dLength
End If
If (ptMax.y > m_dWidth) Then
ptMin.y += m_dWidth - ptMax.y
ptMin.y = Math.Max(ptMin.y, m_dOffsetY)
ptMax.y = m_dWidth
End If
If EgtPackSelectedCluster(ptMin.x, ptMin.y, ptMax.x + 1, ptMax.y + 1, m_dMinDist, True) Then
Return True
End If
' Provo un pack sull'intera tavola
If EgtPackSelectedCluster(m_dOffsetX, m_dOffsetY, m_dLength, m_dWidth, m_dMinDist, True) Then
Return True
End If
' Non è possibile ruotare rimanendo in tavola, annullo l'azione
EgtRotate(GDB_ID.SEL, ptCen, Vector3d.Z_AX(), -dAngRotDeg, GDB_RT.GLOB)
Return False
End Function
Private Sub InsertWallBtn_Click(sender As Object, e As RoutedEventArgs) Handles InsertWallBtn.Click
' Parametri di caricamento
Dim dMinX As Double = m_dOffsetX
Dim dMinY As Double = m_dOffsetY
Dim dMaxX As Double = m_dLength
Dim dMaxY As Double = m_dWidth
Dim dOffset As Double = m_dMinDist
' Ciclo di inserimento in tavola dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero successivo selezionato
Dim nNextId = EgtGetNextSelectedObj()
' Se pezzo in parcheggio, metto nella tavola
If EgtIsPart(nId) And Not IsPartInTable(nId) Then
If Not EgtPackPart(nId, dMinX, dMinY, dMaxX, dMaxY, dOffset, True) Then
EgtDeselectObj(nId)
End If
End If
' Passo al successivo selezionato
nId = nNextId
End While
' Aggiorno flag selezionati
m_nPartPos = IIf(EgtGetSelectedObjCount() > 0, PART_POS.IN_TABLE, PART_POS.NONE_TABLE)
' Aggiorno vista
MyDraw()
End Sub
Private Sub StoreWallBtn_Click(sender As Object, e As RoutedEventArgs) Handles StoreWallBtn.Click
' Parametri di caricamento
Dim dMinX As Double = m_dOffsetX
Dim dMinY As Double = m_dOffsetY
Dim dMaxX As Double = m_dLength
Dim dMaxY As Double = m_dWidth
Dim dOffset As Double = m_dMinDist
Dim dParkMaxY As Double = m_dParkMaxY
' Ciclo di parcheggio dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Se pezzo, metto in parcheggio (sempre possibile)
If EgtIsPart(nId) Then
EgtPackPart(nId, dMinX, -INFINITO, dMaxX, dParkMaxY, dOffset, False)
End If
' Passo al successivo selezionato
nId = EgtGetNextSelectedObj()
End While
' Imposto flag posizione pezzi su parcheggio
m_nPartPos = PART_POS.OUT_TABLE
' Aggiorno vista
MyDraw()
End Sub
Private Sub RemoveWallBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemoveWallBtn.Click
' Ciclo di cancellazione dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero indice del successivo
Dim nNextId = EgtGetNextSelectedObj()
' Se pezzo cancello
If EgtIsPart(nId) Then
EgtErase(nId)
End If
' Passo al successivo selezionato
nId = nNextId
End While
' Imposto flag posizione pezzi
m_nPartPos = PART_POS.NONE_TABLE
' Aggiorno vista
MyDraw()
End Sub
Private Sub GenerateBtn_Click(sender As Object, e As RoutedEventArgs) Handles GenerateBtn.Click
' Recupero numero progressivo valido come nome ultimo progetto
Dim nLastProj As Integer = GetPrivateProfileInt(S_GENERAL, K_LASTPROJ, 1, m_MainWindow.GetIniFile())
' Se modificato, lo incremento e lo salvo
If EgtGetModified() Then
' Recupero massimo numero di progetti
Dim nMaxProj As Integer = GetPrivateProfileInt(S_GENERAL, K_MAXPROJ, 100, m_MainWindow.GetIniFile())
' Sistemo nuovo nome numerico
nLastProj += 1
If nLastProj > nMaxProj Then
nLastProj = 1
End If
WritePrivateProfileString(S_GENERAL, K_LASTPROJ, nLastProj.ToString(), m_MainWindow.GetIniFile())
' Salvo il progetto corrente
Dim sPath As String = m_MainWindow.GetDataDir() & "\" & nLastProj.ToString("D4") & ".nge"
If Not EgtSaveFile(sPath, NGE.CMPTEXT) Then
Dim sOut As String = "Error saving file " & sPath
EgtOutLog(sOut)
Else
EgtResetModified()
End If
' Cancello eventuali vecchi file di dati e report
Dim sDPath As String = m_MainWindow.GetDataDir() & "\" & nLastProj.ToString("D4") & ".dat"
If My.Computer.FileSystem.FileExists(sDPath) Then
My.Computer.FileSystem.DeleteFile(sDPath)
End If
Dim sRPath As String = m_MainWindow.GetDataDir() & "\" & nLastProj.ToString("D4") & ".txt"
If My.Computer.FileSystem.FileExists(sRPath) Then
My.Computer.FileSystem.DeleteFile(sRPath)
End If
End If
' Lancio la generazione con Lua
' assegno variabili
EgtLuaCreateGlobTable("PROC")
Dim sDataFile As String = m_MainWindow.GetDataDir() & "\" & nLastProj.ToString("D4") & ".dat"
EgtLuaSetGlobStringVar("PROC.DATAFILE", sDataFile)
Dim sReportFile As String = m_MainWindow.GetDataDir() & "\" & nLastProj.ToString("D4") & ".txt"
EgtLuaSetGlobStringVar("PROC.REPORTFILE", sReportFile)
EgtLuaSetGlobStringVar("PROC.TEMPDIR", m_MainWindow.GetTempDir())
EgtLuaEvalNumExpr(LayerThicknessTxBx.Text, m_dLayerThick)
EgtLuaSetGlobNumVar("PROC.LAYTH", m_dLayerThick)
EgtLuaSetGlobNumVar("PROC.OFFSETX", m_dOffsetX)
EgtLuaSetGlobNumVar("PROC.OFFSETY", m_dOffsetY)
' eseguo
Dim sLuaPath As String = String.Empty
GetPrivateProfileString(S_MACHINE, K_PROCESSOR, "", sLuaPath, m_MainWindow.GetIniFile())
EgtDisableModified()
If Not EgtLuaExecFile(sLuaPath) Then
Dim sOut As String = "Error running processor " & sLuaPath
EgtOutLog(sOut)
End If
EgtEnableModified()
' recupero stato di esecuzione
Dim nErr As Integer = 1000
EgtLuaGetGlobIntVar("PROC.ERR", nErr)
If nErr = 0 Then
MessageTxBx.Text = EgtMsg(MSG_PLACEPAGEUC + 10) ' Generazione riuscita
MessageBrd.Background = Brushes.Green
Else
MessageTxBx.Text = EgtMsg(MSG_PLACEPAGEUC + 11) ' Errore in generazione
MessageBrd.Background = Brushes.Tomato
End If
' cancello variabili
EgtLuaResetGlobVar("PROC")
End Sub
Private Sub SendBtn_Click(sender As Object, e As RoutedEventArgs) Handles SendBtn.Click
End Sub
End Class