Files
SarmaxWall/DrawPageUC.xaml.vb
Dario Sassi 1e32b5737c SarmaxWall 1.6r8 :
- corretto calcolo numero tavole in Y all'inserimento parete (problema con offset in X aggiunto 3 volte).
2016-06-02 07:05:20 +00:00

779 lines
31 KiB
VB.net

Imports System.Globalization
Imports EgtUILib
Imports EgtUILib.EgtInterface
Public Class DrawPageUC
' Constants
Private Const NUM_VAR As Integer = 4
Private Const LUA_CMP_VARS As String = "CMP"
Private Const LUA_CMP_DRAW As String = "CMP_Draw"
Private Const LUA_REMOVEHOLE As String = "RemoveHole"
Private Const LUA_PREINSERT As String = "PreInsert"
Private Const INFO_CMP As String = "CMP"
Private Const LUA_CMP_WALL As String = "Wall"
Private Const LUA_CMP_DOOR As String = "Door"
Private Const LUA_CMP_WINDOW As String = "Window"
Private Const LUA_CMP_SPACER As String = "Spacer"
Private Const LUA_CMP_INDEX As String = LUA_CMP_VARS & ".Ind"
' Riferimento alla MainWindow
Dim m_MainWindow As MainWindow = Application.Current.MainWindow
' Dichiarazione del UserControl SceneButtons
Friend m_SceneButtons As SceneButtonsUC
' Properties
Private m_sCompoDir As String = String.Empty
Private m_sCompoName As String = String.Empty
Private m_CVars(NUM_VAR - 1) As CompoVar
Private m_bDrawOk As Boolean = False
Private m_bFirst As Boolean = True
' Riferimento alla pagina correntemente attiva
Private m_ActiveComponent As Components = Components.Null
Private m_nStatus As Stat = Stat.Null
' Indica se il componente viene modificato o è nuovo
Private m_bEdit As Boolean = False
' Modalità aggiornamento variabili
Friend m_bShowVar As Boolean = False
Enum Components
Wall
Door
Window
Spacer
Null
End Enum
Enum Stat
Null
Wall
Spacer
End Enum
' Dichiarazione Scene
Friend WithEvents DrawScene As New Scene
Dim DrawSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
Private Sub DrawPage_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 ImportPageGrid
DrawSceneHost.Child = DrawScene
DrawSceneHost.SetValue(Grid.ColumnProperty, 1)
DrawSceneHost.SetValue(Grid.RowProperty, 0)
Me.DrawPageGrid.Children.Add(DrawSceneHost)
' Associo TextBox e Label
TextBox1.Tag = Label1
TextBox2.Tag = Label2
TextBox3.Tag = Label3
TextBox4.Tag = Label4
'Imposto i messaggi letti dal file dei messaggi
WallBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 1) 'Wall - Parete
DoorBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 2) 'Door - Porta
WindowBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 3) 'Window - Finestra
SpacerBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 8) 'Spacer - Distanziale
End Sub
Private Sub DrawPage_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())
DrawScene.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())
DrawScene.SetViewBackground(BackTopColor, BackBotColor)
' imposto colore di evidenziazione
Dim MarkColor As New Color3d(255, 255, 0)
GetPrivateProfileColor(S_SCENE, K_MARK, MarkColor, m_MainWindow.GetIniFile())
DrawScene.SetMarkMaterial(MarkColor)
' imposto colore per superfici selezionate
Dim SelSurfColor As New Color3d(255, 255, 192)
GetPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor, m_MainWindow.GetIniFile())
DrawScene.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())
DrawScene.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())
DrawScene.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())
DrawScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
' inizializzo la scena (DB geometrico + visualizzazione)
DrawScene.Init()
' Imposto griglia
LoadGridData()
' leggo direttorio componenti
GetPrivateProfileString(S_COMPO, K_COMPODIR, "", m_sCompoDir, m_MainWindow.GetIniFile())
m_bFirst = False
Else
EgtSetCurrentContext(DrawScene.GetCtx())
End If
' inibisco selezione diretta da Scene
DrawScene.SetStatusNull()
' Apro e seleziono per default il componente Parete
m_ActiveComponent = Components.Null
m_nStatus = Stat.Null
' Carico componente
EgtNewFile()
HideComponentParameters()
'LoadCurrentCompo(LUA_CMP_WALL)
'WallBtn.IsChecked = True
End Sub
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 bShowGrid As Boolean = (GetPrivateProfileInt(S_GRID, K_SHOWGRID, 1, m_MainWindow.GetIniFile()) <> 0)
EgtSetGridShow(bShowGrid, False)
End Sub
Private Sub WallBtn_Click(sender As Object, e As RoutedEventArgs) Handles WallBtn.Click
Select Case m_ActiveComponent
Case Components.Wall
WallBtn.IsChecked = True
Case Components.Door
WallBtn.IsChecked = False
DoorBtn.IsChecked = True
Case Components.Window
WallBtn.IsChecked = False
WindowBtn.IsChecked = True
Case Components.Null
If m_nStatus <> Stat.Null Then
WallBtn.IsChecked = False
Return
End If
m_ActiveComponent = Components.Wall
' Carico componente
EgtNewFile()
m_bEdit = False
LoadCurrentCompo(LUA_CMP_WALL)
m_nStatus = Stat.Wall
WallBtn.IsChecked = True
End Select
End Sub
Private Sub DoorBtn_Click(sender As Object, e As RoutedEventArgs) Handles DoorBtn.Click
Select Case m_ActiveComponent
Case Components.Wall
WallBtn.IsChecked = True
DoorBtn.IsChecked = False
Case Components.Door
DoorBtn.IsChecked = True
Case Components.Window
DoorBtn.IsChecked = False
WindowBtn.IsChecked = True
Case Components.Null
If m_nStatus <> Stat.Wall Then
DoorBtn.IsChecked = False
Return
End If
m_ActiveComponent = Components.Door
' Carico componente
m_bEdit = False
LoadCurrentCompo(LUA_CMP_DOOR)
DoorBtn.IsChecked = True
End Select
End Sub
Private Sub WindowBtn_Click(sender As Object, e As RoutedEventArgs) Handles WindowBtn.Click
Select Case m_ActiveComponent
Case Components.Wall
WallBtn.IsChecked = True
WindowBtn.IsChecked = False
Case Components.Door
DoorBtn.IsChecked = True
WindowBtn.IsChecked = False
Case Components.Window
WindowBtn.IsChecked = True
Case Components.Null
If m_nStatus <> Stat.Wall Then
WindowBtn.IsChecked = False
Return
End If
m_ActiveComponent = Components.Window
' Carico componente
m_bEdit = False
LoadCurrentCompo(LUA_CMP_WINDOW)
WindowBtn.IsChecked = True
End Select
End Sub
Private Sub SpacerBtn_Checked(sender As Object, e As RoutedEventArgs) Handles SpacerBtn.Checked
Select Case m_ActiveComponent
Case Components.Wall
WallBtn.IsChecked = True
Case Components.Door
WallBtn.IsChecked = False
DoorBtn.IsChecked = True
Case Components.Window
WallBtn.IsChecked = False
WindowBtn.IsChecked = True
Case Components.Null
If m_nStatus <> Stat.Null Then
SpacerBtn.IsChecked = False
Return
End If
m_ActiveComponent = Components.Spacer
' Carico componente
EgtNewFile()
m_bEdit = False
LoadCurrentCompo(LUA_CMP_SPACER)
m_nStatus = Stat.Spacer
SpacerBtn.IsChecked = True
End Select
End Sub
Private Sub AddBtn_Click(sender As Object, e As RoutedEventArgs) Handles AddBtn.Click
ResetBtns()
m_ActiveComponent = Components.Null
' Deseleziono oggetto corrente e aggiorno visualizzazione
EgtDeselectAll()
EgtDraw()
End Sub
Private Sub CancelBtn_Click(sender As Object, e As RoutedEventArgs) Handles CancelBtn.Click
' Leggo l'indice del componente corrente
Dim nCmp As Integer = 0
If Not EgtLuaGetGlobIntVar(LUA_CMP_INDEX, nCmp) Or nCmp < 1 Then
Return
End If
Dim sCmp As String = nCmp.ToString()
' Lancio cancellazione
If Not EgtLuaExecLine(LUA_REMOVEHOLE & "(" & nCmp & ")") Then
EgtOutLog("Error in RemoveHole execution")
Return
End If
' Sistemo interfaccia
ResetBtns()
m_ActiveComponent = Components.Null
' Deseleziono oggetto corrente e aggiorno visualizzazione
EgtDeselectAll()
EgtDraw()
End Sub
Private Sub ResetBtns()
WallBtn.IsChecked = False
DoorBtn.IsChecked = False
WindowBtn.IsChecked = False
SpacerBtn.IsChecked = False
HideComponentParameters()
End Sub
Private Sub OnMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DrawScene.OnMouseDownScene
' Si può selezionare solo con il tasto sinistro e se stato NULL
If e.Button <> Windows.Forms.MouseButtons.Left Or Not DrawScene.IsStatusNull() Then
Return
End If
' Si può selezionare solo se non si sta già editando un componente
If m_ActiveComponent <> Components.Null Then
Return
End If
' Verifico se selezionato indicativo di componente (wall, door o window)
EgtSetObjFilterForSelect(True, True, True, True, True)
Dim nSel As Integer
EgtSelect(e.Location, 2 * Scene.DIM_SEL, 2 * Scene.DIM_SEL, nSel)
Dim sCompo As String = String.Empty
Dim nId As Integer = EgtGetFirstObjInSelWin()
While nId <> GDB_ID.NULL
If EgtGetInfo(nId, INFO_CMP, sCompo) Then
Exit While
End If
nId = EgtGetNextObjInSelWin()
End While
If String.IsNullOrWhiteSpace(sCompo) Then
Return
End If
' Recupero l'indice del componente
Dim sName As String = String.Empty
If Not EgtGetName(nId, sName) Then
Return
End If
Dim nCmp As Integer = -1
Try
nCmp = CInt(sName)
Catch ex As Exception
Return
End Try
' Aggiorno lo stato della finestra
If sCompo = LUA_CMP_WALL And nCmp = 0 Then
m_ActiveComponent = Components.Wall
WallBtn.IsChecked = True
ElseIf sCompo = LUA_CMP_DOOR And nCmp > 0 Then
m_ActiveComponent = Components.Door
DoorBtn.IsChecked = True
ElseIf sCompo = LUA_CMP_WINDOW And nCmp > 0 Then
m_ActiveComponent = Components.Window
WindowBtn.IsChecked = True
ElseIf sCompo = LUA_CMP_SPACER And nCmp = 0 Then
m_ActiveComponent = Components.Spacer
SpacerBtn.IsChecked = True
Else
Return
End If
' Rendo corrente il componente
m_sCompoName = sCompo
' Pulisco l'ambiente lua
ResetLuaVariables()
' Carico il file
Dim bOk As Boolean = ExecCompoFile()
' Leggo le variabili da Lua (per sapere numero, nome e tipo)
ReadVariables()
' Imposto le variabili del componente
For i As Integer = 1 To NUM_VAR
' leggo il valore della variabile
If m_CVars(i - 1) IsNot Nothing Then
Dim sVar As String = String.Empty
If EgtGetInfo(nId, "V" & i.ToString(), sVar) Then
m_CVars(i - 1).FromString(sVar)
' aggiorno la corrispondente variabile lua
If Not m_CVars(i - 1).ToLua() Then
Dim sErr As String = String.Empty
EgtLuaGetLastError(sErr)
EgtOutLog(sErr)
End If
End If
End If
Next
' Imposto l'indice del componente
If Not EgtLuaSetGlobIntVar(LUA_CMP_INDEX, nCmp) Then
Return
End If
' Eseguo il componente
Dim sMsg As String = String.Empty
bOk = bOk AndAlso MakePreview(sMsg)
If Not bOk Then
EgtOutLog("Error in Component " & sCompo & " " & sMsg)
End If
MessageLabel.Content = sMsg
MessageLabel.Background = If(m_bDrawOk, Brushes.White, Brushes.Tomato)
DrawScene.ZoomAll()
m_bEdit = True
' Aggiorno griglia
ShowVariables()
' Visualizzo bottoni Add e Cancel, e MessageLabel
ShowComponentsButtons()
End Sub
Private Sub HideComponentParameters()
Label1.Visibility = Windows.Visibility.Hidden
Label2.Visibility = Windows.Visibility.Hidden
Label3.Visibility = Windows.Visibility.Hidden
Label4.Visibility = Windows.Visibility.Hidden
TextBox1.Visibility = Windows.Visibility.Hidden
TextBox2.Visibility = Windows.Visibility.Hidden
TextBox3.Visibility = Windows.Visibility.Hidden
TextBox4.Visibility = Windows.Visibility.Hidden
MessageLabel.Content = String.Empty
MessageLabel.Visibility = Windows.Visibility.Hidden
AddBtn.Visibility = Windows.Visibility.Hidden
CancelBtn.Visibility = Windows.Visibility.Hidden
End Sub
Public Sub UpdateView()
' aggiorno le variabili dalla griglia
UpdateVariables()
' ricalcolo il disegno
Dim sMsg As String = String.Empty
MakePreview(sMsg)
MessageLabel.Content = sMsg
MessageLabel.Background = If(m_bDrawOk, Brushes.White, Brushes.Tomato)
' aggiorno visualizzazione
EgtSetView(VT.TOP, False)
EgtZoom(ZM.ALL)
End Sub
Private Function ExecCompoFile() As Boolean
' Costruisco path completa del componente
Dim sPath = m_sCompoDir & "\" & m_sCompoName & ".lua"
' Carico il file
Return EgtLuaExecFile(sPath)
End Function
Private Sub LoadCurrentCompo(ByVal sCompo As String)
m_sCompoName = sCompo
' Pulisco l'ambiente lua
ResetLuaVariables()
' Carico il file ed eseguo in modalità anteprima
Dim bOk As Boolean = ExecCompoFile()
Dim sMsg As String = String.Empty
bOk = bOk AndAlso MakePreview(sMsg)
If Not bOk Then
EgtOutLog("Error in Component " & sCompo & " " & sMsg)
End If
MessageLabel.Content = sMsg
MessageLabel.Background = If(m_bDrawOk, Brushes.White, Brushes.Tomato)
DrawScene.ZoomAll()
' Leggo variabili e aggiorno griglia
ReadVariables()
ShowVariables()
' Visualizzo bottoni Add e Cancel, e MessageLabel
ShowComponentsButtons()
End Sub
Private Function ReadVariables() As Boolean
' Recupero nome, tipo e valore delle variabili globali
For i As Integer = 1 To NUM_VAR
Dim CVar = New CompoVar
CVar.m_nInd = i
If CVar.NameTypeValueFromLua() Then
m_CVars(i - 1) = CVar
Else
m_CVars(i - 1) = Nothing
End If
Next
Return True
End Function
Private Function ShowVariables() As Boolean
' Aggiorno la griglia dalle variabili
m_bShowVar = True
For i As Integer = 1 To NUM_VAR
If m_CVars(i - 1) IsNot Nothing Then
GetNameEdit(i).Content = m_CVars(i - 1).m_sName
GetNameEdit(i).Visibility = Windows.Visibility.Visible
GetValueEdit(i).Text = m_CVars(i - 1).ToString()
GetValueEdit(i).Visibility = Windows.Visibility.Visible
Else
GetNameEdit(i).Visibility = Windows.Visibility.Hidden
GetValueEdit(i).Visibility = Windows.Visibility.Hidden
End If
Next
m_bShowVar = False
Return True
End Function
Private Function ShowComponentsButtons() As Boolean
MessageLabel.Visibility = Windows.Visibility.Visible
'Imposto i messaggi per componente nuovo o modificato
If m_bEdit Then
AddBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 6) 'Edit - Modifica
CancelBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 7) 'Remove - Rimuovi
Else
AddBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 4) 'Add - Aggiungi
CancelBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 5) 'Cancel - Annulla
End If
AddBtn.Visibility = Windows.Visibility.Visible
If m_ActiveComponent = Components.Wall Or m_ActiveComponent = Components.Spacer Then
CancelBtn.Visibility = Windows.Visibility.Hidden
Else
CancelBtn.Visibility = Windows.Visibility.Visible
End If
Return True
End Function
Private Function UpdateVariables() As Boolean
' aggiorno le variabili
For i As Integer = 1 To NUM_VAR
If m_CVars(i - 1) IsNot Nothing Then
' interpreto il valore, se non riesco ripristino default
If Not m_CVars(i - 1).FromString(GetValueEdit(i).Text) Then
GetValueEdit(i).Text = m_CVars(i - 1).ToString()
End If
' aggiorno la corrispondente variabile lua
If Not m_CVars(i - 1).ToLua() Then
Dim sErr As String = String.Empty
EgtLuaGetLastError(sErr)
EgtOutLog(sErr)
End If
End If
Next
Return True
End Function
Private Function ResetLuaVariables() As Boolean
EgtLuaResetGlobVar(LUA_CMP_VARS)
EgtLuaResetGlobVar(LUA_CMP_DRAW)
Return False
End Function
Private Function MakePreview(ByRef sMsg As String) As Boolean
If Not EgtLuaExecLine(LUA_CMP_DRAW & "(true)") Then
sMsg = "Error in component execution"
m_bDrawOk = False
Else
EgtLuaGetGlobStringVar(LUA_CMP_VARS & ".MSG", sMsg)
Dim nErr As Integer = 0
EgtLuaGetGlobIntVar(LUA_CMP_VARS & ".ERR", nErr)
m_bDrawOk = (nErr = 0)
End If
Return m_bDrawOk
End Function
Private Function MakeInsert(ByVal nNbr As Integer) As Boolean
' Lancio funzione pre-inserimento
If Not EgtLuaExecLine(LUA_PREINSERT & "()") Then
EgtOutLog("Error in PreInsert execution")
Return False
End If
' Vettore nomi file temporanei
Dim sTmpFiles As New ArrayList()
' Ciclo di salvataggio dei pezzi
Dim nId As Integer = EgtGetFirstPart()
While nId <> GDB_ID.NULL
' Esporto il pezzo in un file temporaneo
Dim sTmpFile As String = m_MainWindow.GetTempDir() & "\Wall" & nId & ".Nge"
sTmpFiles.Add(sTmpFile)
If Not EgtSaveObjToFile(nId, sTmpFile, NGE.BIN) Then
EgtOutLog("Error in saveObjToFile ")
Return False
End If
' Passo al pezzo successivo
nId = EgtGetNextPart(nId)
End While
' Passo al contesto principale
EgtSetCurrentContext(m_MainWindow.m_PlacePageUC.PlaceScene.GetCtx())
' Parametri di caricamento
Dim dMinX As Double = 0
Dim dMinY As Double = -m_MainWindow.m_PlacePageUC.m_dWidth
Dim dMaxX As Double = m_MainWindow.m_PlacePageUC.m_dLength
Dim dMaxY As Double = 0
Dim dOffset As Double = m_MainWindow.m_PlacePageUC.m_dMinDist
Dim dParkMaxY As Double = m_MainWindow.m_PlacePageUC.m_dParkMaxY
Dim dOffsetX As Double = m_MainWindow.m_PlacePageUC.m_dOffsetX
Dim dOffsetY As Double = m_MainWindow.m_PlacePageUC.m_dOffsetY
Dim dPlankX As Double = m_MainWindow.m_PlacePageUC.m_dPlankX
' Ciclo di caricamento dei pezzi
For Each sTmpfile As String In sTmpFiles
If My.Computer.FileSystem.FileExists(sTmpfile) Then
' Inserisco il pezzo
EgtInsertFile(sTmpfile)
' Ne recupero l'Id
Dim nId2 As Integer = EgtGetLastPart()
' Se non è un distanziale, aggiungo il grezzo
If Not EgtExistsInfo(nId2, "Spacer") Then
Dim nIdRaw As Integer = EgtCreateGroup(nId2, New Frame3d())
EgtSetName(nIdRaw, "Raw")
EgtSetAlpha(nIdRaw, 40)
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(nId2, GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM, ptMin, ptMax)
ptMin.x -= dOffsetX
ptMin.y -= dOffsetY
' Per avere un numero intero di assi in X
Dim dLen As Double = ptMax.x + dOffsetX - ptMin.x
Dim nPlank As Integer = Math.Ceiling(dLen / dPlankX)
ptMax.x = ptMin.x + nPlank * dPlankX
ptMax.y += dOffsetY
EgtCreateSurfTmBBox(nIdRaw, ptMin, ptMax, GDB_RT.GLOB)
End If
' Lo posiziono nel parcheggio
EgtPackBox(nId2, dMinX, -INFINITO, dMaxX, dParkMaxY, dOffset, False)
' Cerco di spostarlo nella tavola
EgtPackBox(nId2, dMinX, dMinY, dMaxX, dMaxY, dOffset, False)
' Cancello il file
My.Computer.FileSystem.DeleteFile(sTmpfile)
End If
Next
Return True
End Function
Private Function GetNameEdit(ByVal nInd As Integer) As Label
Select Case nInd
Case 1
Return Label1
Case 2
Return Label2
Case 3
Return Label3
Case Else
Return Label4
End Select
End Function
Private Function GetValueEdit(ByVal nInd As Integer) As TextBox
Select Case nInd
Case 1
Return TextBox1
Case 2
Return TextBox2
Case 3
Return TextBox3
Case Else
Return TextBox4
End Select
End Function
Private Sub ConfirmBtn_Click(sender As Object, e As RoutedEventArgs) Handles ConfirmBtn.Click
ResetBtns()
m_ActiveComponent = Components.Null
' Inserisco il componente nel DB geometrico principale
If Not MakeInsert(1) Then
Return
End If
' Aggiorno ambiente principale
EgtZoom(ZM.ALL, False)
m_MainWindow.m_PlacePageUC.MyDraw()
' Istruzioni per chiudere DrawPageUC e aprire PlacePage UC
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_DrawPageUC)
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_PlacePageUC)
m_MainWindow.m_ActivePage = MainWindow.Pages.Place
m_MainWindow.DrawBtn.IsChecked = False
m_MainWindow.PlaceBtn.IsChecked = True
End Sub
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
ResetBtns()
m_ActiveComponent = Components.Null
' Istruzioni per chiudere DrawPageUC e aprire PlacePage UC
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_DrawPageUC)
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_PlacePageUC)
m_MainWindow.m_ActivePage = MainWindow.Pages.Place
m_MainWindow.DrawBtn.IsChecked = False
m_MainWindow.PlaceBtn.IsChecked = True
End Sub
Private Sub DrawPage_Unloaded(sender As Object, e As RoutedEventArgs)
' Pulisco l'ambiente lua
ResetLuaVariables()
End Sub
Private Class CompoVar
' Public Members
Public m_nInd As Integer
Public m_sName As String
Public m_nType As Integer
Public m_bVal As Boolean
Public m_nVal As Integer
Public m_dVal As Double
Public m_sVal As String
' Constants
Const LUA_NAME As String = LUA_CMP_VARS & ".N"
Const LUA_TYPE As String = LUA_CMP_VARS & ".T"
Const LUA_VALUE As String = LUA_CMP_VARS & ".V"
Public Sub New()
m_nInd = 0
m_nType = 0
End Sub
Public Overrides Function ToString() As String
Select Case m_nType
Case 1 ' booleano
Return m_bVal.ToString()
Case 2 ' intero
Return m_nVal.ToString()
Case 3 ' lunghezza
Return EgtToUiUnits(m_dVal).ToString("F0", CultureInfo.InvariantCulture)
Case 4 ' double
Return m_dVal.ToString("F0", CultureInfo.InvariantCulture)
Case 5 ' stringa
Return m_sVal
End Select
Return ""
End Function
Public Function FromString(ByVal sVal As String) As Boolean
Select Case m_nType
Case 1 ' booleano
Dim bVal As Boolean = False
If Boolean.TryParse(sVal, bVal) Then
m_bVal = bVal
Return True
End If
Case 2 ' intero
Dim dVal As Double
If EgtLuaEvalNumExpr(sVal, dVal) Then
m_nVal = CInt(dVal)
Return True
End If
Case 3 ' lunghezza
Dim dVal As Double
If EgtLuaEvalNumExpr(sVal, dVal) Then
m_dVal = EgtFromUiUnits(dVal)
Return True
End If
Case 4 ' double
Dim dVal As Double
If EgtLuaEvalNumExpr(sVal, dVal) Then
m_dVal = dVal
Return True
End If
Case 5 'stringa
m_sVal = sVal
Return True
End Select
Return False
End Function
Public Function ToLua() As Boolean
Select Case m_nType
Case 1
Return EgtLuaSetGlobBoolVar(LUA_VALUE & m_nInd.ToString(), m_bVal)
Case 2
Return EgtLuaSetGlobIntVar(LUA_VALUE & m_nInd.ToString(), m_nVal)
Case 3, 4
Return EgtLuaSetGlobNumVar(LUA_VALUE & m_nInd.ToString(), m_dVal)
Case 5
Return EgtLuaSetGlobStringVar(LUA_VALUE & m_nInd.ToString(), m_sVal)
End Select
Return False
End Function
Public Function FromLua() As Boolean
Select Case m_nType
Case 1
Return EgtLuaGetGlobBoolVar(LUA_VALUE & m_nInd.ToString(), m_bVal)
Case 2
Return EgtLuaGetGlobIntVar(LUA_VALUE & m_nInd.ToString(), m_nVal)
Case 3, 4
Return EgtLuaGetGlobNumVar(LUA_VALUE & m_nInd.ToString(), m_dVal)
Case 5
Return EgtLuaGetGlobStringVar(LUA_VALUE & m_nInd.ToString(), m_sVal)
End Select
Return False
End Function
Public Function NameTypeValueFromLua() As Boolean
Dim bOk As Boolean = True
bOk = bOk AndAlso EgtLuaGetGlobStringVar(LUA_NAME & m_nInd.ToString(), m_sName)
bOk = bOk AndAlso EgtLuaGetGlobIntVar(LUA_TYPE & m_nInd.ToString(), m_nType)
Return bOk AndAlso FromLua()
End Function
End Class
End Class