Files
EgtUILib/Scene.vb
T
Dario Sassi d1e3f68709 EgtUILib 1.5j4 :
- nuova gestione con context corrente.
2014-10-15 15:34:27 +00:00

719 lines
27 KiB
VB.net

Imports System.Math
Imports System.IO
Imports System.Globalization
Imports EgtUILib.EgtInterface
Public Class Scene
'---- Constants -------
Public Const DIM_SEL As Integer = 13
'---- Members ---------
Private m_nGseContext As Integer
Private m_nStatus As Integer
Private m_nOldStatus As Integer
Private Enum ST As Integer
NULL = 0
PAN = 1
ROT = 2
ZOOMWIN = 3
ANALYZE = 4
GETDIST = 5
GETDIST2 = 6
End Enum
Private m_nSnapType As Integer
Private m_PrevPoint As Point
Private m_ptPrev As Point3d
Private m_nDefMatRed As Integer
Private m_nDefMatGreen As Integer
Private m_nDefMatBlue As Integer
Private m_nDriver As Integer
Private m_b2Buff As Boolean
Private m_nColorBits As Integer
Private m_nDepthBits As Integer
Private m_nBackTopRed As Integer
Private m_nBackTopGreen As Integer
Private m_nBackTopBlue As Integer
Private m_nBackBotRed As Integer
Private m_nBackBotGreen As Integer
Private m_nBackBotBlue As Integer
'---- Constructor -----
Sub New()
' Chiamata richiesta dalla finestra di progettazione.
InitializeComponent()
' Istruzioni di inizializzazione.
Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
SetStyle(ControlStyles.Opaque, True)
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
m_nGseContext = 0
m_nStatus = ST.NULL
m_nOldStatus = ST.NULL
m_nSnapType = SP_END
m_PrevPoint = Point.Empty
m_nDefMatRed = 255
m_nDefMatGreen = 165
m_nDefMatBlue = 0
m_nDriver = 3
m_b2Buff = True
m_nColorBits = 24
m_nDepthBits = 32
m_nBackTopRed = 140
m_nBackTopGreen = 154
m_nBackTopBlue = 168
m_nBackBotRed = 40
m_nBackBotGreen = 44
m_nBackBotBlue = 48
Cursor = Cursors.Default
End Sub
'---- Initials --------
Public Sub SetDefaultMaterial(ByVal nRed As Integer, ByVal nGreen As Integer, ByVal nBlue As Integer)
m_nDefMatRed = nRed
m_nDefMatGreen = nGreen
m_nDefMatBlue = nBlue
End Sub
Public Sub SetViewAttributes(ByVal nDriver As Integer, ByVal b2Buff As Boolean, ByVal nColorBits As Integer, ByVal nDepthBits As Integer)
m_nDriver = nDriver
m_b2Buff = b2Buff
m_nColorBits = nColorBits
m_nDepthBits = nDepthBits
End Sub
Public Sub SetViewBackground(ByVal nTopRed As Integer, ByVal nTopGreen As Integer, ByVal nTopBlue As Integer,
ByVal nBottomRed As Integer, ByVal nBottomGreen As Integer, ByVal nBottomBlue As Integer)
m_nBackTopRed = nTopRed
m_nBackTopGreen = nTopGreen
m_nBackTopBlue = nTopBlue
m_nBackBotRed = nBottomRed
m_nBackBotGreen = nBottomGreen
m_nBackBotBlue = nBottomBlue
End Sub
'Mettere EgtInit, EgtSetKey e EgtSetFont nell'evento Load del Form, prima di inizializzare la o le Scene
'Mettere EgtExit nell'evento FormClosing
Public Sub Init()
m_nGseContext = EgtInitGeomDB()
EgtSetDefaultMaterial(m_nDefMatRed, m_nDefMatGreen, m_nDefMatBlue)
EgtInitScene(Handle, m_nDriver, m_b2Buff, m_nColorBits, m_nDepthBits)
EgtSetBackground(m_nBackTopRed, m_nBackTopGreen, m_nBackTopBlue,
m_nBackBotRed, m_nBackBotGreen, m_nBackBotBlue)
EgtInitTscExec()
End Sub
Public Function GetCtx() As Integer
Return m_nGseContext
End Function
Protected Overrides Sub OnHandleDestroyed(e As EventArgs)
'EgtExit va spostata nell'evento FormClosing del Form
'EgtExit()
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
' Salvo il contesto corrente e imposto quello della scena
Dim nOldGseCtx = EgtGetCurrentContext()
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(m_nGseContext)
End If
' Eseguo il disegno
EgtDraw()
' Ripristino il contesto originale
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(nOldGseCtx)
End If
End Sub
Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
MyBase.OnPaintBackground(pevent)
End Sub
Protected Overrides Sub OnResize(e As System.EventArgs)
MyBase.OnResize(e)
' Salvo il contesto corrente e imposto quello della scena
Dim nOldGseCtx = EgtGetCurrentContext()
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(m_nGseContext)
End If
' Eseguo ridimensionamento vista
EgtResize(Width, Height)
' Ripristino il contesto originale
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(nOldGseCtx)
End If
End Sub
'---- Events ----------
Public Event OnMouseSelected(ByVal sender As Object, ByVal nId As Integer)
Public Event OnMouseAnalyzed(ByVal sender As Object, ByVal nId As Integer)
Public Event OnMouseDownScene(ByVal sender As Object)
Public Event OnCursorPos(ByVal sender As Object, ByVal sCursorPos As String)
Public Event OnShowDistance(ByVal sender As Object, ByVal sDistance As String)
Public Event OnCloseGetDist(ByVal sender As Object)
Public Event OnNewProject(ByVal sender As Object)
Public Event OnOpeningProject(ByVal sender As Object)
Public Event OnOpenProject(ByVal sender As Object, ByVal sFile As String)
Public Event OnSavingProject(ByVal sender As Object, ByVal sFile As String)
Public Event OnSavedProject(ByVal sender As Object)
Public Event OnImportingProject(ByVal sender As Object)
Public Event OnImportedProject(ByVal sender As Object, ByVal sFile As String)
Public Event OnExportingProject(ByVal sender As Object, ByVal sFile As String)
Public Event OnExportedProject(ByVal sender As Object)
Public Event OnExecutingScript(ByVal sender As Object, ByVal sFile As String)
Public Event OnExecutedScript(ByVal sender As Object)
'---- Mouse -----------
Protected Overrides Sub OnMouseEnter(e As System.EventArgs)
MyBase.OnMouseEnter(e)
Focus()
End Sub
Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
' Imposto il contesto della scena come corrente
EgtSetCurrentContext(m_nGseContext)
If e.Button = Windows.Forms.MouseButtons.Left Then
If m_nStatus = ST.NULL Or m_nStatus = ST.ANALYZE Then
If m_nStatus = ST.NULL Then
Cursor = New Cursor(Me.GetType(), "Select.cur")
Else
Cursor = New Cursor(Me.GetType(), "Analyze.cur")
End If
Dim nId As Integer = GDB_ID_NULL
Dim nSel As Integer
EgtSelect(e.Location, DIM_SEL, DIM_SEL, nSel)
If nSel = 1 Then
nId = EgtGetFirstSelectedObj()
ElseIf nSel > 1 Then
Dim MselDlg As New SelectMulti
MselDlg.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Dim ptScreen As Point = PointToScreen(e.Location)
ptScreen.Offset(10, 0)
MselDlg.Location = ptScreen
If MselDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
nId = MselDlg.GetId()
End If
End If
If nId <> GDB_ID_NULL Then
If m_nStatus = ST.NULL Then
RaiseEvent OnMouseSelected(Me, nId)
Else
RaiseEvent OnMouseAnalyzed(Me, nId)
End If
End If
ElseIf m_nStatus = ST.GETDIST Then
If EgtGetSelectedSnapPoint(m_nSnapType, e.Location.X, e.Location.Y, DIM_SEL, DIM_SEL, m_ptPrev) Then
' salvo il punto di riferimento
Dim ptWin As Point3d
EgtProjectPoint(m_ptPrev, ptWin)
m_PrevPoint = New Point(ptWin.x, ptWin.y)
m_nStatus = ST.GETDIST2
End If
ElseIf m_nStatus = ST.GETDIST2 Then
Dim ptSel As Point3d
If EgtGetSelectedSnapPoint(m_nSnapType, e.Location.X, e.Location.Y, DIM_SEL, DIM_SEL, ptSel) Then
' disegno la linea (coordinate geo globali)
EgtSetGeoLine(m_ptPrev, ptSel)
' calcolo la distanza e il delta e li visualizzo
Dim dX As Double = ptSel.x - m_ptPrev.x
Dim dY As Double = ptSel.y - m_ptPrev.y
Dim dZ As Double = ptSel.z - m_ptPrev.z
Dim dDist As Double = Sqrt(dX * dX + dY * dY + dZ * dZ)
Dim sOut As New System.Text.StringBuilder
sOut.Append("Dist=")
sOut.Append(dDist.ToString("F4", CultureInfo.InvariantCulture))
sOut.Append(" dX=")
sOut.Append(dX.ToString("F4", CultureInfo.InvariantCulture))
sOut.Append(" dY=")
sOut.Append(dY.ToString("F4", CultureInfo.InvariantCulture))
sOut.Append(" dZ=")
sOut.Append(dZ.ToString("F4", CultureInfo.InvariantCulture))
' lancio l'evento per visualizzare la distanza
RaiseEvent OnShowDistance(Me, sOut.ToString())
m_nStatus = ST.NULL
m_nOldStatus = ST.NULL
End If
End If
ElseIf e.Button = Windows.Forms.MouseButtons.Middle Then
If (Control.ModifierKeys And Keys.Shift) = Keys.Shift Then
If m_nStatus = ST.ANALYZE Or m_nStatus = ST.GETDIST Or m_nStatus = ST.GETDIST2 Then
m_nOldStatus = m_nStatus
End If
m_nStatus = ST.ZOOMWIN
Cursor = New Cursor(Me.GetType(), "ZoomWin.cur")
ElseIf (Control.ModifierKeys And Keys.Control) = Keys.Control Then
If m_nStatus = ST.ANALYZE Or m_nStatus = ST.GETDIST Or m_nStatus = ST.GETDIST2 Then
m_nOldStatus = m_nStatus
End If
m_nStatus = ST.ROT
Cursor = New Cursor(Me.GetType(), "Rotate.cur")
Else
If m_nStatus = ST.ANALYZE Or m_nStatus = ST.GETDIST Or m_nStatus = ST.GETDIST2 Then
m_nOldStatus = m_nStatus
End If
m_nStatus = ST.PAN
Cursor = New Cursor(Me.GetType(), "Pan.cur")
End If
m_PrevPoint = e.Location
Else
MyBase.OnMouseDown(e)
End If
Focus()
RaiseEvent OnMouseDownScene(Me)
End Sub
Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
' salvo il contesto corrente e imposto quello della scena
Dim nOldGseCtx = EgtGetCurrentContext()
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(m_nGseContext)
End If
' rilascio tasto medio (rotella)
If e.Button = Windows.Forms.MouseButtons.Middle Then
If m_nStatus = ST.ZOOMWIN Then
EgtResetWinRect(False)
EgtZoomWin(m_PrevPoint, e.Location, True)
End If
' eventuale ripristino vecchio stato
If m_nOldStatus = ST.ANALYZE Then
m_nStatus = m_nOldStatus
Cursor = New Cursor(Me.GetType(), "Analyze.cur")
ElseIf m_nOldStatus = ST.GETDIST Or m_nOldStatus = ST.GETDIST2 Then
m_nStatus = m_nOldStatus
Cursor = New Cursor(Me.GetType(), "GetDist.cur")
' reset dello stato se non NULL
ElseIf m_nStatus <> ST.NULL Then
m_nStatus = ST.NULL
Cursor = New Cursor(Me.GetType(), "Select.cur")
End If
' rilascio tasto destro
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
If m_nStatus = ST.NULL Then
MenuScene.Visible = True
For Each i As ToolStripMenuItem In MenuScene.Items
If i.Name = "cmdDeselectAll" Then
i.Visible = True
Else
i.Visible = False
End If
Next
ElseIf m_nStatus = ST.GETDIST Or m_nStatus = ST.GETDIST2 Then
MenuScene.Visible = True
For Each i As ToolStripMenuItem In MenuScene.Items
If i.Name = "cmdEndPoint" Then
i.Visible = True
i.Checked = (m_nSnapType = SP_END)
ElseIf i.Name = "cmdMidPoint" Then
i.Visible = True
i.Checked = (m_nSnapType = SP_MID)
ElseIf i.Name = "cmdCenterPoint" Then
i.Visible = True
i.Checked = (m_nSnapType = SP_CENTER)
ElseIf i.Name = "cmdNearPoint" Then
i.Visible = True
i.Checked = (m_nSnapType = SP_NEAR)
Else
i.Visible = False
End If
Next
Else
MenuScene.Visible = False
End If
' tutti gli altri casi
Else
MyBase.OnMouseUp(e)
End If
' Ripristino il contesto originale
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(nOldGseCtx)
End If
End Sub
Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)
' salvo il contesto corrente e imposto quello della scena
Dim nOldGseCtx = EgtGetCurrentContext()
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(m_nGseContext)
End If
'Visualizzo le coordinate del mouse
ShowCursorPos(e.Location)
'In base allo stato...
If e.Button = Windows.Forms.MouseButtons.Middle Then
If m_nStatus = ST.ZOOMWIN Then
Cursor = New Cursor(Me.GetType(), "ZoomWin.cur")
EgtSetWinRect(m_PrevPoint, e.Location, True)
'Il punto di riferimento deve rimanere quello originale
ElseIf m_nStatus = ST.ROT Then
Cursor = New Cursor(Me.GetType(), "Rotate.cur")
EgtRotateCamera(m_PrevPoint, e.Location, True)
m_PrevPoint = e.Location
ElseIf m_nStatus = ST.PAN Then
Cursor = New Cursor(Me.GetType(), "Pan.cur")
EgtPanCamera(m_PrevPoint, e.Location, True)
m_PrevPoint = e.Location
Else
m_nStatus = ST.NULL
Cursor = New Cursor(Me.GetType(), "Select.cur")
End If
ElseIf m_nStatus = ST.GETDIST Then
Cursor = New Cursor(Me.GetType(), "GetDist.cur")
ElseIf m_nStatus = ST.GETDIST2 Then
Cursor = New Cursor(Me.GetType(), "GetDist.cur")
Dim ptP As Point3d
EgtUnProjectPoint(e.Location, ptP)
EgtSetGeoLine(m_ptPrev, ptP)
ElseIf m_nStatus = ST.ANALYZE Then
Cursor = New Cursor(Me.GetType(), "Analyze.cur")
Else
MyBase.OnMouseMove(e)
End If
If m_nStatus = ST.NULL Then
Cursor = New Cursor(Me.GetType(), "Select.cur")
End If
' Ripristino il contesto originale
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(nOldGseCtx)
End If
End Sub
Protected Overrides Sub OnMouseWheel(e As System.Windows.Forms.MouseEventArgs)
' devo essere nello stato NULL o ANALYZE o GETDIST
If m_nStatus <> ST.NULL And m_nStatus <> ST.ANALYZE And m_nStatus <> ST.GETDIST And m_nStatus <> ST.GETDIST2 Then
Return
End If
' trascuro rotazioni molto piccole
If Abs(e.Delta) < 30 Then
Return
End If
' calcolo coefficiente
Const WHEEL_DELTA As Double = 120
Dim dCoeff As Double = 1 - 0.1 * Abs(e.Delta) / WHEEL_DELTA
If e.Delta < 0 Then
dCoeff = 1 / dCoeff
End If
' salvo il contesto corrente e imposto quello della scena
Dim nOldGseCtx = EgtGetCurrentContext()
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(m_nGseContext)
End If
' eseguo zoom
EgtZoomOnPoint(e.Location, dCoeff, True)
' Ripristino il contesto originale
If nOldGseCtx <> m_nGseContext Then
EgtSetCurrentContext(nOldGseCtx)
End If
End Sub
Private Sub ShowCursorPos(ByVal WinXY As Point)
'ricavo punto 3d
Dim ptWorld As Point3d
EgtUnProjectPoint(WinXY, ptWorld)
'ricavo direzione di vista
Dim nDir As Integer
EgtGetCameraDir(nDir)
'costruisco stringa con dati
Dim sCursorPos As New System.Text.StringBuilder
Select Case nDir
Case CT_TOP, CT_BOTTOM
sCursorPos.Append("X=")
sCursorPos.Append(ptWorld.x.ToString("F4", CultureInfo.InvariantCulture))
sCursorPos.Append(" Y=")
sCursorPos.Append(ptWorld.y.ToString("F4", CultureInfo.InvariantCulture))
Case CT_FRONT, CT_BACK
sCursorPos.Append("X=")
sCursorPos.Append(ptWorld.x.ToString("F4", CultureInfo.InvariantCulture))
sCursorPos.Append(" Z=")
sCursorPos.Append(ptWorld.z.ToString("F4", CultureInfo.InvariantCulture))
Case CT_LEFT, CT_RIGHT
sCursorPos.Append("Y=")
sCursorPos.Append(ptWorld.y.ToString("F4", CultureInfo.InvariantCulture))
sCursorPos.Append(" Z=")
sCursorPos.Append(ptWorld.z.ToString("F4", CultureInfo.InvariantCulture))
Case Else
sCursorPos.Append(" ")
End Select
' lancio l'evento per visualizzare la stringa
RaiseEvent OnCursorPos(Me, sCursorPos.ToString)
End Sub
Private Sub MenuScene_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles MenuScene.ItemClicked
If e.ClickedItem.Name = "cmdDeselectAll" Then
EgtDeselectAll()
EgtDraw()
ElseIf e.ClickedItem.Name = "cmdEndPoint" Then
m_nSnapType = SP_END
ElseIf e.ClickedItem.Name = "cmdMidPoint" Then
m_nSnapType = SP_MID
ElseIf e.ClickedItem.Name = "cmdCenterPoint" Then
m_nSnapType = SP_CENTER
ElseIf e.ClickedItem.Name = "cmdNearPoint" Then
m_nSnapType = SP_NEAR
End If
End Sub
'---- Main Buttons ----
Public Function NewProject() As Boolean
Dim bOk As Boolean = EgtNewFile()
EgtZoom(ZM_ALL)
If bOk Then
RaiseEvent OnNewProject(Me)
Else
MessageBox.Show("Error on new file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return bOk
End Function
Public Function OpenProject()
'Scelta file con dialogo
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.Title = "Open"
OpenFileDialog.Filter = "New geometry EgalTech(*.nge)|*.nge" &
"|New font EgalTech(*.nfe)|*.nfe" &
"|All Files (*.*)|*.*"
OpenFileDialog.FilterIndex = 1
If OpenFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
Return True
End If
'Prima del caricamento
RaiseEvent OnOpeningProject(Me)
'Caricamento del progetto
Cursor = Cursors.WaitCursor
Dim bOk As Boolean = EgtOpenFile(OpenFileDialog.FileName)
EgtZoom(m_nGseContext, ZM_ALL)
Cursor = Cursors.Default
'Gestione risultato
If bOk Then
RaiseEvent OnOpenProject(Me, OpenFileDialog.FileName)
Else
MessageBox.Show("Error opening file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return bOk
End Function
Public Function SaveProject(Optional ByVal sFile As String = "")
'Assegnazione nome file con dialogo
Dim SaveFileDialog As New SaveFileDialog
SaveFileDialog.Title = "Save"
SaveFileDialog.Filter = "New geometry EgalTech(*.nge)|*.nge"
SaveFileDialog.FileName = sFile
If SaveFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
Return True
End If
'Prima del salvataggio
RaiseEvent OnSavingProject(Me, SaveFileDialog.FileName)
'Salvataggio del progetto
Cursor = Cursors.WaitCursor
Dim bOk As Boolean = EgtSaveFile(SaveFileDialog.FileName, NGE_CMPTEXT)
Cursor = Cursors.Default
'Gestione risultato
If bOk Then
RaiseEvent OnSavedProject(Me)
Else
MessageBox.Show("Error saving file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return bOk
End Function
Public Function ImportProject()
'Scelta file con dialogo
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.Title = "Import"
OpenFileDialog.Filter = "Drawing Exchange Fmt(*.dxf)|*.dxf" &
"|Stereolithography (*.stl)|*.stl" &
"|Part program ISO (*.cnc)|*.cnc" &
"|All Files (*.*)|*.*"
OpenFileDialog.FilterIndex = 1
If OpenFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
Return True
End If
'Riconoscimento tipo file
Dim nFileType As Integer = EgtGetFileType(OpenFileDialog.FileName)
If nFileType <> FT_DXF And nFileType <> FT_STL And nFileType <> FT_CNC Then
MessageBox.Show("File type unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
'Prima del caricamento
RaiseEvent OnImportingProject(Me)
'Pulizia GeomDB
Cursor = Cursors.WaitCursor
Dim bOk As Boolean = EgtNewFile()
'Importazione
If nFileType = FT_DXF Then
bOk = bOk And EgtImportDxf(OpenFileDialog.FileName)
ElseIf nFileType = FT_STL Then
bOk = bOk And EgtImportStl(OpenFileDialog.FileName)
ElseIf nFileType = FT_CNC Then
bOk = bOk And EgtImportCnc(OpenFileDialog.FileName)
End If
EgtZoom(m_nGseContext, ZM_ALL)
Cursor = Cursors.Default
'Gestione risultato
If bOk Then
RaiseEvent OnImportedProject(Me, OpenFileDialog.FileName)
Else
MessageBox.Show("Error importing file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return bOk
End Function
Public Function ExportProject(Optional ByVal sFile As String = "")
'Assegnazione nome file con dialogo
Dim SaveFileDialog As New SaveFileDialog
SaveFileDialog.Title = "Export"
SaveFileDialog.Filter = "Drawing Exchange Fmt(*.dxf)|*.dxf" &
"|Stereolithography (*.stl)|*.stl" &
"|All Files (*.*)|*.*"
SaveFileDialog.FileName = sFile
If SaveFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
Return True
End If
'Riconoscimento tipo file
Dim nFileType As Integer = EgtGetFileType(SaveFileDialog.FileName)
If nFileType <> FT_DXF And nFileType <> FT_STL Then
MessageBox.Show("File type unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
'Prima dell'esportazione
RaiseEvent OnExportingProject(Me, SaveFileDialog.FileName)
'Esportazione del progetto
Cursor = Cursors.WaitCursor
Dim bOk As Boolean = False
If nFileType = FT_DXF Then
bOk = EgtExportDxf(GDB_ID_ROOT, SaveFileDialog.FileName)
ElseIf nFileType = FT_STL Then
bOk = EgtExportStl(GDB_ID_ROOT, SaveFileDialog.FileName)
End If
Cursor = Cursors.Default
'Gestione risultato
If bOk Then
RaiseEvent OnExportedProject(Me)
Else
MessageBox.Show("Error exporting file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return bOk
End Function
Public Function Exec()
'Scelta file con dialogo
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.Title = "Exec Script"
OpenFileDialog.Filter = "Lua commands(*.lua)|*.lua" &
"|Test commands(*.tsc)|*.tsc" &
"|All Files (*.*)|*.*"
OpenFileDialog.FilterIndex = 1
If OpenFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
Return True
End If
'Ne verifico il tipo
Dim sExt As String = UCase(Path.GetExtension(OpenFileDialog.FileName))
If (sExt <> ".LUA" And sExt <> ".TSC") Then
MessageBox.Show("Script type unknow", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
'Prima dell'esecuzione
RaiseEvent OnExecutingScript(Me, OpenFileDialog.FileName)
'Esecuzione
Cursor = Cursors.WaitCursor
Dim bOk As Boolean = False
If (sExt = ".LUA") Then
bOk = EgtLuaExecFile(OpenFileDialog.FileName)
Else
bOk = EgtTscExecFile(OpenFileDialog.FileName)
End If
EgtZoom(m_nGseContext, ZM_ALL)
Cursor = Cursors.Default
'Gestione risultato
If bOk Then
RaiseEvent OnExecutedScript(Me)
ElseIf (sExt = ".LUA") Then
Dim sError As String = String.Empty
EgtLuaGetLastError(sError)
MessageBox.Show(sError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Error executing file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return bOk
End Function
'---- Distance Operations -------------
Public Sub SetStatusGetDistance()
m_nStatus = ST.GETDIST
End Sub
Public Sub ResetStatusGetDistance()
If m_nStatus = ST.GETDIST Or m_nStatus = ST.GETDIST2 Then
m_nStatus = ST.NULL
m_nOldStatus = ST.NULL
End If
EgtResetGeoLine()
RaiseEvent OnCloseGetDist(Me)
End Sub
'---- Analyze Operations -------------
Public Sub SetStatusAnalyze()
m_nStatus = ST.ANALYZE
End Sub
Public Sub ResetStatusAnalyze()
If m_nStatus = ST.ANALYZE Then
m_nStatus = ST.NULL
m_nOldStatus = ST.NULL
End If
End Sub
'---- Zoom Buttons ----
Public Sub ZoomAll()
EgtZoom(ZM_ALL)
End Sub
Public Sub ZoomIn()
EgtZoom(ZM_IN)
End Sub
Public Sub ZoomOut()
EgtZoom(ZM_OUT)
End Sub
'---- Rendering Buttons ----
Public Sub WireFrame()
EgtSetShowMode(SM_WIREFRAME)
End Sub
Public Sub HiddenLine()
EgtSetShowMode(SM_HIDDENLINE)
End Sub
Public Sub Shading()
EgtSetShowMode(SM_SHADING)
End Sub
'---- LookFrom Buttons ----
Public Sub TopView()
EgtSetView(CT_TOP)
End Sub
Public Sub IsoView()
EgtSetView(CT_ISO_SW)
End Sub
Public Sub FrontView()
EgtSetView(CT_FRONT)
End Sub
Public Sub BackView()
EgtSetView(CT_BACK)
End Sub
Public Sub LeftView()
EgtSetView(CT_LEFT)
End Sub
Public Sub RightView()
EgtSetView(CT_RIGHT)
End Sub
End Class