62aaa2601a
- aggiunta gestione utensili con attrezzaggio manuale e automatico da toolchanger - corretta gestione interni di componenti - migliorata gestione grezzo principale sempre di fase 1.
810 lines
32 KiB
VB.net
810 lines
32 KiB
VB.net
Imports System.Globalization
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib
|
|
|
|
Public Class DrawPageUC
|
|
|
|
' Constants
|
|
Private Const NUM_VAR As Integer = 10
|
|
Private Const LUA_CMP_VARS As String = "CMP"
|
|
Private Const LUA_CMP_DRAW As String = "CMP_Draw"
|
|
Private Const INFO_VAR As String = "Var"
|
|
Private Const INFO_CMP As String = "CMP"
|
|
Private Const INFO_ID As String = "ID"
|
|
Friend Const LUA_CMP_INDEX As String = LUA_CMP_VARS & ".Ind"
|
|
Friend Const LUA_CMP_INTERNAL As String = LUA_CMP_VARS & ".Int"
|
|
Friend Const LUA_REMOVEHOLE As String = "RemoveHole"
|
|
|
|
'Riferimento alla MainWindow
|
|
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
|
|
|
|
' Dichiarazione delle Page UserControl
|
|
Friend m_MainComponentPage As MainComponentPageUC
|
|
Friend m_CompoDimension As CompoDimensionUC
|
|
Friend m_SideAngle As SideAngleUC
|
|
|
|
' Variabile che indica se componenti interni o esterni
|
|
Friend m_bInternalCompo As Boolean = False
|
|
|
|
' Properties
|
|
Private m_sCompoDir As String = String.Empty
|
|
Private m_sCompoName As String = String.Empty
|
|
Private m_CVars(NUM_VAR - 1) As CompoVar
|
|
Friend m_bDrawOk As Boolean = False
|
|
Private m_bFirst As Boolean = True
|
|
|
|
Friend ReadOnly Property sCompoName As String
|
|
Get
|
|
Return m_sCompoName
|
|
End Get
|
|
End Property
|
|
|
|
Friend Sub ResetCompoName()
|
|
m_sCompoName = String.Empty
|
|
End Sub
|
|
|
|
Friend Function GetParamType(nI As Integer) As Integer
|
|
If nI >= 0 And nI < NUM_VAR Then Return m_CVars(nI).m_nType
|
|
Return 0
|
|
End Function
|
|
|
|
' Dichiarazione Scene
|
|
Friend WithEvents DrawScene As New Scene
|
|
Dim DrawSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
|
|
|
|
'Riferimento alla pagina correntemente attiva
|
|
Friend m_ActiveComponentPage As Pages
|
|
|
|
' Modalità aggiornamento variabili
|
|
Friend m_bShowVar As Boolean = False
|
|
|
|
Enum Pages
|
|
MainComponent
|
|
SecondaryComponent
|
|
InternalComponent
|
|
Draw
|
|
CompoDimension
|
|
SideAngle
|
|
End Enum
|
|
|
|
Private Sub DrawPage_Initialized(sender As Object, e As EventArgs)
|
|
|
|
'Creazione delle Page UserControl
|
|
m_MainComponentPage = New MainComponentPageUC
|
|
m_CompoDimension = New CompoDimensionUC
|
|
m_SideAngle = New SideAngleUC
|
|
'Posizionemento nella griglia delle Page UserControl
|
|
m_MainComponentPage.SetValue(Grid.ColumnSpanProperty, 2)
|
|
m_MainComponentPage.SetValue(Grid.RowSpanProperty, 4)
|
|
m_CompoDimension.SetValue(Grid.ColumnSpanProperty, 2)
|
|
m_CompoDimension.SetValue(Grid.RowSpanProperty, 4)
|
|
m_SideAngle.SetValue(Grid.RowSpanProperty, 1)
|
|
|
|
'Assegnazione scena all'host e posizionamento nella ImportPageGrid
|
|
DrawSceneHost.Child = DrawScene
|
|
DrawSceneHost.SetValue(Grid.ColumnProperty, 1)
|
|
DrawSceneHost.SetValue(Grid.RowProperty, 0)
|
|
Me.DrawPageGrd.Children.Add(DrawSceneHost)
|
|
|
|
'Imposto i messaggi letti dal file dei messaggi
|
|
PartNumTxBl.Text = EgtMsg(MSG_DRAWPAGEUC + 1) 'Part Number - Numero pezzi
|
|
DimensionBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 2)
|
|
SideAngleBtn.Content = EgtMsg(MSG_DRAWPAGEUC + 3)
|
|
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())
|
|
' Imposto componenti esterni
|
|
m_bInternalCompo = False
|
|
m_bFirst = False
|
|
Else
|
|
' Imposto contesto
|
|
EgtSetCurrentContext(DrawScene.GetCtx())
|
|
' Imposto griglia
|
|
LoadGridData()
|
|
End If
|
|
|
|
' inibisco selezione diretta da Scene
|
|
DrawScene.SetStatusNull()
|
|
' pulisco la scena e relativo db
|
|
EgtNewFile()
|
|
EgtDraw()
|
|
|
|
'Seleziono la Tab e la Page di apertura
|
|
VariablesGrd.Children.Remove(m_CompoDimension)
|
|
LeftButtonGrd.Children.Add(m_MainComponentPage)
|
|
m_ActiveComponentPage = Pages.MainComponent
|
|
MessageGrid.Visibility = Windows.Visibility.Hidden
|
|
BackBtn.Visibility = Windows.Visibility.Hidden
|
|
PartNumberGrd.Visibility = Windows.Visibility.Hidden
|
|
|
|
' Valore di default del numero pezzi
|
|
PartNumTxBx.Text = "1"
|
|
|
|
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_ActiveComponentPage <> Pages.InternalComponent Then
|
|
Return
|
|
End If
|
|
' Verifico se selezionato indicativo di componente (wall, door o window)
|
|
EgtSetObjFilterForSelWin(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
|
|
' Salvo l'indice della superficie di selezione
|
|
Dim nSurfSelId As Integer = nId
|
|
' Recupero l'indice del componente
|
|
Dim sName As String = String.Empty
|
|
If Not EgtGetName(nId, sName) Then Return
|
|
Dim nCmp As Integer = -1
|
|
If Not StringToInt(sName, nCmp) Then Return
|
|
' Rendo corrente il componente
|
|
m_sCompoName = sCompo & ".lua"
|
|
' Pulisco l'ambiente lua
|
|
ResetLuaVariables()
|
|
' Carico il file
|
|
Dim bOk As Boolean = ExecCompoFile()
|
|
If Not bOk Then
|
|
EgtOutLog("Error in Component " & sCompo)
|
|
End If
|
|
MessageTxBl.Text = ""
|
|
MessageGrid.Background = Brushes.Transparent
|
|
' Leggo le variabili da Lua (per sapere numero, nome e tipo)
|
|
ReadAndShowVariables()
|
|
' 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, False)
|
|
' 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
|
|
ShowVariables()
|
|
' Imposto l'indice del componente
|
|
If Not EgtLuaSetGlobIntVar(LUA_CMP_INDEX, nCmp) Then Return
|
|
' Evidenzio la sua regione di selezione
|
|
EgtSelectObj(nSurfSelId)
|
|
' Rendo visibili le eventuali etichette del componente
|
|
Dim nHLId As Integer = EgtGetFirstNameInGroup(EgtGetFirstGroupInGroup(GDB_ID.ROOT), "HoleLabels")
|
|
While nHLId <> GDB_ID.NULL
|
|
Dim nCmpInfo As Integer = 0
|
|
If EgtGetInfo(nHLId, "ID", nCmpInfo) AndAlso nCmp = nCmpInfo Then
|
|
EgtSetStatus(nHLId, GDB_ST.ON_)
|
|
Exit While
|
|
End If
|
|
nHLId = EgtGetNextName(nHLId, "HoleLabels")
|
|
End While
|
|
DrawScene.ZoomAll()
|
|
' Aggiorno griglia
|
|
LeftButtonGrd.Children.Remove(m_CompoDimension.m_InternalCompoPage)
|
|
VariablesGrd.Children.Add(m_MainWindow.m_DrawPageUC.m_CompoDimension)
|
|
End Sub
|
|
|
|
Private Sub LoadGridData()
|
|
Dim dSnapStep As Double = If(EgtUiUnitsAreMM(),
|
|
GetPrivateProfileDouble(S_GRID, K_SNAPSTEP, 10, m_MainWindow.GetIniFile()),
|
|
GetPrivateProfileDouble(S_GRID, K_SNAPSTEPINCH, 12.7, 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
|
|
|
|
Public Sub SelectedComponent(sCompo As String)
|
|
' Carico componente
|
|
LoadCurrentCompo(sCompo)
|
|
End Sub
|
|
|
|
Private Sub LoadCurrentCompo(ByVal sCompo As String)
|
|
' Verifico se cambiato
|
|
If sCompo = m_sCompoName Then
|
|
Return
|
|
End If
|
|
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
|
|
' Verifico se compo interno o esterno
|
|
Dim InternalCompo As Integer = -1
|
|
EgtLuaGetGlobIntVar(LUA_CMP_INTERNAL, InternalCompo)
|
|
bOk = bOk AndAlso MakePreview(sMsg)
|
|
If Not bOk And InternalCompo <> 1 Then
|
|
EgtNewFile()
|
|
End If
|
|
MessageTxBl.Text = sMsg
|
|
MessageGrid.Background = If(m_bDrawOk, Brushes.Transparent, Application.Current.FindResource("OmagCut_Red"))
|
|
DrawScene.ZoomAll()
|
|
' leggo variabili e aggiorno griglia
|
|
ReadAndShowVariables()
|
|
' abilito bottoni Vista e Inserisci
|
|
OkBtn.IsEnabled = True
|
|
End Sub
|
|
|
|
Friend Sub BackBtn_Click(sender As Object, e As RoutedEventArgs) Handles BackBtn.Click
|
|
DrawPage_Unloaded(sender, e)
|
|
' Elimino nome del componente precedente
|
|
m_sCompoName = String.Empty
|
|
' Reset inclinazioni
|
|
m_SideAngle.DeleteSideAngle()
|
|
If String.IsNullOrEmpty(m_MainComponentPage.m_SecondaryComponentPage.m_sCurrCompo) Then
|
|
DrawPage_Loaded(sender, e)
|
|
Else
|
|
LoadSecondaryPage()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub LoadSecondaryPage()
|
|
EgtSetCurrentContext(DrawScene.GetCtx())
|
|
|
|
' inibisco selezione diretta da Scene
|
|
DrawScene.SetStatusNull()
|
|
' pulisco la scena e relativo db
|
|
EgtNewFile()
|
|
EgtDraw()
|
|
|
|
' Seleziono la Tab e la Page di apertura
|
|
VariablesGrd.Children.Remove(m_CompoDimension)
|
|
LeftButtonGrd.Children.Add(m_MainComponentPage.m_SecondaryComponentPage)
|
|
m_ActiveComponentPage = Pages.MainComponent
|
|
MessageGrid.Visibility = Windows.Visibility.Hidden
|
|
BackBtn.Visibility = Windows.Visibility.Hidden
|
|
PartNumberGrd.Visibility = Windows.Visibility.Hidden
|
|
|
|
' Valore di default del numero pezzi
|
|
PartNumTxBx.Text = "1"
|
|
|
|
End Sub
|
|
|
|
Public Sub UpdateView()
|
|
' verifico ci sia un componente corrente
|
|
If String.IsNullOrWhiteSpace(m_sCompoName) Then
|
|
Return
|
|
End If
|
|
' aggiorno le variabili dalla griglia
|
|
UpdateVariables()
|
|
' ricalcolo il disegno
|
|
Dim sMsg As String = String.Empty
|
|
MakePreview(sMsg)
|
|
MessageTxBl.Text = sMsg
|
|
MessageGrid.Background = If(m_bDrawOk, Brushes.Transparent, Application.Current.FindResource("OmagCut_Red"))
|
|
' 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
|
|
' Carico il file
|
|
Return EgtLuaExecFile(sPath)
|
|
End Function
|
|
|
|
Private Function ReadAndShowVariables() 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
|
|
|
|
' Aggiorno la griglia dalle variabili
|
|
m_bShowVar = True
|
|
|
|
' Conto numero variabili definite e da nascondere
|
|
Dim nShow As Integer = GetDefinedVarCount()
|
|
Dim nHide As Integer = NUM_VAR - nShow
|
|
|
|
For i As Integer = 1 To nHide
|
|
m_CompoDimension.GetNameEdit(i).Visibility = Windows.Visibility.Hidden
|
|
m_CompoDimension.GetValueEdit(i).Visibility = Windows.Visibility.Hidden
|
|
Next
|
|
For i As Integer = 1 To nShow
|
|
Dim j As Integer = nHide + i
|
|
m_CompoDimension.GetNameEdit(j).Text = m_CVars(i - 1).m_sName
|
|
m_CompoDimension.GetNameEdit(j).Visibility = Windows.Visibility.Visible
|
|
m_CompoDimension.GetValueEdit(j).Text = m_CVars(i - 1).ToString()
|
|
m_CompoDimension.GetValueEdit(j).Visibility = Windows.Visibility.Visible
|
|
Next
|
|
m_bShowVar = False
|
|
Return True
|
|
End Function
|
|
|
|
Private Function ShowVariables() As Boolean
|
|
' Conto numero variabili definite e nascoste
|
|
Dim nShow As Integer = GetDefinedVarCount()
|
|
Dim nHide As Integer = NUM_VAR - nShow
|
|
' Aggiorno i valori visualizzati
|
|
m_bShowVar = True
|
|
For i As Integer = 1 To nShow
|
|
Dim j As Integer = nHide + i
|
|
m_CompoDimension.GetValueEdit(j).Text = m_CVars(i - 1).ToString()
|
|
Next
|
|
m_bShowVar = False
|
|
Return True
|
|
End Function
|
|
|
|
Private Function UpdateVariables() As Boolean
|
|
' Conto numero variabili definite e da nascondere
|
|
Dim nShow As Integer = GetDefinedVarCount()
|
|
Dim nHide As Integer = NUM_VAR - nShow
|
|
' aggiorno le variabili
|
|
For i As Integer = 1 To nShow
|
|
Dim j As Integer = nHide + i
|
|
' interpreto il valore, se non riesco ripristino default
|
|
If Not m_CVars(i - 1).FromString(m_CompoDimension.GetValueEdit(j).Text) Then
|
|
m_CompoDimension.GetValueEdit(j).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
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function GetDefinedVarCount() As Integer
|
|
Dim nCount As Integer = 0
|
|
For i As Integer = 1 To NUM_VAR
|
|
If m_CVars(i - 1) IsNot Nothing Then
|
|
nCount += 1
|
|
End If
|
|
Next
|
|
Return nCount
|
|
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
|
|
' ricarico componente corrente
|
|
ExecCompoFile()
|
|
' aggiorno variabili
|
|
UpdateVariables()
|
|
' Recupero flag per inserimento diretto in grezzo (altrimenti in parcheggio)
|
|
Dim bDirect As Boolean = (GetPrivateProfileInt(S_NEST, K_DIRECT, 0, m_MainWindow.GetIniFile()) <> 0)
|
|
' elimino eventuali precedenti pezzi vuoti
|
|
EgtEraseEmptyParts()
|
|
' eseguo inserimento
|
|
For i As Integer = 1 To nNbr
|
|
' Inserisco il componente
|
|
If Not EgtLuaExecLine(LUA_CMP_DRAW & "(false)") Then
|
|
Dim sErr As String = String.Empty
|
|
EgtLuaGetLastError(sErr)
|
|
EgtOutLog(sErr)
|
|
Exit For
|
|
End If
|
|
' Ne recupero l'Id
|
|
Dim nId2 As Integer = EgtGetLastPart()
|
|
' Ne recupero il layer OutLoop
|
|
Dim nOutLoopLayer As Integer = EgtGetFirstNameInGroup(nId2, NAME_OUTLOOP)
|
|
' Calcolo dimensione ingombro OutLoop
|
|
Dim ptMin, ptMax As Point3d
|
|
EgtGetBBoxGlob(nOutLoopLayer, GDB_BB.STANDARD, ptMin, ptMax)
|
|
Dim dBBoxRad As Double = 0.5 * Point3d.DistXY(ptMin, ptMax)
|
|
' Ricavo nome layer con testi inclinazioni
|
|
Dim TextLayer As Integer = EgtGetFirstNameInGroup(nId2, SIDE_ANGLE_LAYER)
|
|
' Se presente lo svuoto
|
|
If TextLayer <> GDB_ID.NULL Then
|
|
EgtEmptyGroup(TextLayer)
|
|
' altrimenti lo creo
|
|
Else
|
|
TextLayer = EgtCreateGroup(nId2)
|
|
EgtSetName(TextLayer, SIDE_ANGLE_LAYER)
|
|
End If
|
|
' Modifico inclinazione lati
|
|
For Each Entity In m_SideAngle.m_SideAngleEntityList
|
|
Dim nCurrEntityName As Integer = EgtGetFirstNameInGroup(nOutLoopLayer, Entity.sEntityName)
|
|
If Math.Abs(Entity.dSideAngle) > EPS_ANG_SMALL Then
|
|
' Scrivo nuovo angolo nelle info
|
|
EgtSetInfo(nCurrEntityName, INFO_SIDE_ANGLE, Entity.dSideAngle)
|
|
' Creo testo con angolo di inclinazione per nesting
|
|
Dim sText As String = DoubleToString(Entity.dSideAngle, 1) & "°"
|
|
SideAngleUC.AddTextToLine(sText, TextLayer, nCurrEntityName, 10, dBBoxRad, False)
|
|
Else
|
|
' Cancello inclinazione nell'apposito campo info
|
|
EgtRemoveInfo(nCurrEntityName, INFO_SIDE_ANGLE)
|
|
End If
|
|
Next
|
|
' Muovo la regione in Z per evitare problemi in visualizzazione
|
|
Dim nRegId = EgtGetFirstNameInGroup(nId2, NAME_REGION)
|
|
EgtMove(nRegId, New Vector3d(0, 0, DELTAZ_REG), GDB_RT.GLOB)
|
|
' Aggiusto per lavorazioni
|
|
AdjustFlatPart(nId2)
|
|
' Inserisco in parcheggio
|
|
m_MainWindow.m_CadCutPageUC.m_NestPage.StoreOnePart(nId2, True)
|
|
' Se richiesto posizionamento diretto, lo eseguo
|
|
If bDirect Then
|
|
m_MainWindow.m_CadCutPageUC.m_NestPage.InsertOnePart(nId2)
|
|
End If
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function MakeCompoInsert(ByVal nNbr As Integer) As Boolean
|
|
' Passo al contesto corrente
|
|
EgtSetCurrentContext(m_MainWindow.m_DrawPageUC.DrawScene.GetCtx())
|
|
' Cancello layer regioni per selezione buchi
|
|
Dim Pz As Integer = EgtGetFirstGroupInGroup(GDB_ID.ROOT)
|
|
Dim SelectRegion As Integer = EgtGetFirstNameInGroup(Pz, "SelectRegion")
|
|
EgtErase(SelectRegion)
|
|
' Cancello layer etichette, quotatura,ausiliario e box
|
|
EgtErase(EgtGetFirstNameInGroup(Pz, "LayAux"))
|
|
EgtErase(EgtGetFirstNameInGroup(Pz, "Etichette"))
|
|
EgtErase(EgtGetFirstNameInGroup(Pz, "Quotature"))
|
|
EgtErase(EgtGetFirstNameInGroup(Pz, "Box"))
|
|
' Cancello layer etichette dei componenti interni (buchi)
|
|
Dim nHLId As Integer = EgtGetFirstNameInGroup(Pz, "HoleLabels")
|
|
While nHLId <> GDB_ID.NULL
|
|
EgtErase(nHLId)
|
|
nHLId = EgtGetFirstNameInGroup(Pz, "HoleLabels")
|
|
End While
|
|
' Attivo visualizzazione misura
|
|
Dim nRegLayId As Integer = EgtGetFirstNameInGroup(Pz, NAME_REGION)
|
|
Dim nId As Integer = EgtGetFirstInGroup(nRegLayId)
|
|
While nId <> GDB_ID.NULL
|
|
If EgtGetType(nId) = GDB_TY.EXT_TEXT Then
|
|
EgtSetStatus(nId, GDB_ST.ON_)
|
|
End If
|
|
nId = EgtGetNext(nId)
|
|
End While
|
|
' Layer OutLoop
|
|
Dim nOutLoopLayer = EgtGetFirstNameInGroup(Pz, NAME_OUTLOOP)
|
|
' Calcolo dimensione ingombro OutLoop
|
|
Dim ptMin, ptMax As Point3d
|
|
EgtGetBBoxGlob(nOutLoopLayer, GDB_BB.STANDARD, ptMin, ptMax)
|
|
Dim dBBoxRad As Double = 0.5 * Point3d.DistXY(ptMin, ptMax)
|
|
' Ricavo nome layer con testi inclinazioni
|
|
Dim TextLayer As Integer = EgtGetFirstNameInGroup(Pz, SIDE_ANGLE_LAYER)
|
|
' Se presente lo svuoto
|
|
If TextLayer <> GDB_ID.NULL Then
|
|
EgtEmptyGroup(TextLayer)
|
|
' altrimenti lo creo
|
|
Else
|
|
TextLayer = EgtCreateGroup(Pz)
|
|
EgtSetName(TextLayer, SIDE_ANGLE_LAYER)
|
|
End If
|
|
' Modifico inclinazione lati
|
|
For Each Entity In m_SideAngle.m_SideAngleEntityList
|
|
Dim nCurrEntityName As Integer = EgtGetFirstNameInGroup(nOutLoopLayer, Entity.sEntityName)
|
|
If Math.Abs(Entity.dSideAngle) > EPS_ANG_SMALL Then
|
|
' Scrivo nuovo angolo nelle info
|
|
EgtSetInfo(nCurrEntityName, INFO_SIDE_ANGLE, Entity.dSideAngle)
|
|
' Creo testo con angolo di inclinazione per nesting
|
|
Dim sText As String = DoubleToString(Entity.dSideAngle, 1) & "°"
|
|
SideAngleUC.AddTextToLine(sText, TextLayer, nCurrEntityName, 10, dBBoxRad, False)
|
|
Else
|
|
' Cancello inclinazione nell'apposito campo info
|
|
EgtRemoveInfo(nCurrEntityName, INFO_SIDE_ANGLE)
|
|
End If
|
|
Next
|
|
' Esporto il pezzo in un file temporaneo
|
|
Dim sTmpFile As String = m_MainWindow.GetTempDir() & "\FlatPartCompo.Nge"
|
|
If Not EgtSaveObjToFile(1, sTmpFile, NGE.BIN) Then
|
|
Return False
|
|
End If
|
|
' Passo al contesto principale
|
|
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
|
|
' Recupero flag per inserimento diretto in grezzo (altrimenti in parcheggio)
|
|
Dim bDirect As Boolean = (GetPrivateProfileInt(S_NEST, K_DIRECT, 0, m_MainWindow.GetIniFile()) <> 0)
|
|
' Elimino eventuali precedenti pezzi vuoti
|
|
EgtEraseEmptyParts()
|
|
If My.Computer.FileSystem.FileExists(sTmpFile) Then
|
|
' eseguo inserimento
|
|
For i As Integer = 1 To nNbr
|
|
' Inserisco il pezzo
|
|
EgtInsertFile(sTmpFile)
|
|
' Ne recupero l'Id
|
|
Dim nId2 As Integer = EgtGetLastPart()
|
|
' Muovo la regione in Z per evitare problemi in visualizzazione
|
|
Dim nRegId = EgtGetFirstNameInGroup(nId2, NAME_REGION)
|
|
EgtMove(nRegId, New Vector3d(0, 0, DELTAZ_REG), GDB_RT.GLOB)
|
|
' Aggiusto per lavorazioni
|
|
AdjustFlatPart(nId2)
|
|
' Inserisco in parcheggio
|
|
m_MainWindow.m_CadCutPageUC.m_NestPage.StoreOnePart(nId2, True)
|
|
' Se richiesto posizionamento diretto, lo eseguo
|
|
If bDirect Then
|
|
m_MainWindow.m_CadCutPageUC.m_NestPage.InsertOnePart(nId2)
|
|
End If
|
|
Next
|
|
' Cancello il file
|
|
My.Computer.FileSystem.DeleteFile(sTmpFile)
|
|
End If
|
|
' Aggiorno ambiente principale
|
|
EgtZoom(ZM.ALL)
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
|
|
' se sto definendo un componente interno non posso uscire
|
|
If m_ActiveComponentPage = Pages.CompoDimension And m_bInternalCompo Then
|
|
Return
|
|
End If
|
|
' se errore esco
|
|
If Not m_bDrawOk Then
|
|
Return
|
|
End If
|
|
' Leggo numero di pezzi da inserire
|
|
Dim InsNbr As Integer = Int32.Parse(PartNumTxBx.Text)
|
|
' Passo al contesto principale
|
|
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
|
|
If Not m_bInternalCompo Then
|
|
' Inserisco il componente nel DB geometrico principale
|
|
MakeInsert(InsNbr)
|
|
Else
|
|
MakeCompoInsert(InsNbr)
|
|
End If
|
|
' Aggiorno ambiente principale
|
|
EgtZoom(ZM.ALL)
|
|
' Elimino nome del componente precedente
|
|
m_sCompoName = String.Empty
|
|
' Reset inclinazioni
|
|
m_SideAngle.DeleteSideAngle()
|
|
'Chiudo compo interni nel caso siano aperti
|
|
LeftButtonGrd.Children.Remove(m_CompoDimension.m_InternalCompoPage)
|
|
'Istruzioni per chiudere ImportPageUC e aprire CadCutPageUC
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_DrawPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut
|
|
|
|
End Sub
|
|
|
|
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
|
|
' Elimino nome del componente precedente
|
|
m_sCompoName = String.Empty
|
|
' Reset inclinazioni
|
|
m_SideAngle.DeleteSideAngle()
|
|
'Chiudo compo interni nel caso siano aperti
|
|
LeftButtonGrd.Children.Remove(m_CompoDimension.m_InternalCompoPage)
|
|
'Istruzioni per chiudere ImportPageUC e aprire CadCutPageUC
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_DrawPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut
|
|
End Sub
|
|
|
|
Private Sub DrawPage_Unloaded(sender As Object, e As RoutedEventArgs)
|
|
'Seleziono la Tab e la Page di apertura
|
|
Select Case m_ActiveComponentPage
|
|
Case Pages.MainComponent
|
|
LeftButtonGrd.Children.Remove(m_MainComponentPage)
|
|
Case Pages.SecondaryComponent
|
|
LeftButtonGrd.Children.Remove(m_MainComponentPage.m_SecondaryComponentPage)
|
|
Case Pages.InternalComponent
|
|
LeftButtonGrd.Children.Remove(m_MainWindow.m_DrawPageUC.m_CompoDimension.m_InternalCompoPage)
|
|
Case Pages.CompoDimension
|
|
VariablesGrd.Children.Remove(m_CompoDimension)
|
|
Case Pages.SideAngle
|
|
VariablesGrd.Children.Remove(m_SideAngle)
|
|
End Select
|
|
|
|
' Pulisco l'ambiente lua
|
|
ResetLuaVariables()
|
|
|
|
End Sub
|
|
|
|
Private Sub DimensionBtn_Click(sender As Object, e As RoutedEventArgs) Handles DimensionBtn.Click
|
|
If DimensionBtn.IsChecked Then
|
|
VariablesGrd.Children.Remove(m_SideAngle)
|
|
VariablesGrd.Children.Add(m_CompoDimension)
|
|
SideAngleBtn.IsChecked = False
|
|
Else
|
|
DimensionBtn.IsChecked = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub SideAngleBtn_Click(sender As Object, e As RoutedEventArgs) Handles SideAngleBtn.Click
|
|
If SideAngleBtn.IsChecked Then
|
|
VariablesGrd.Children.Remove(m_CompoDimension)
|
|
VariablesGrd.Children.Add(m_SideAngle)
|
|
DimensionBtn.IsChecked = False
|
|
Else
|
|
SideAngleBtn.IsChecked = True
|
|
End If
|
|
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 DoubleToString(EgtToUiUnits(m_dVal), 4)
|
|
Case 4 ' double
|
|
Return DoubleToString(m_dVal, 4)
|
|
Case 5 ' stringa
|
|
Return m_sVal
|
|
End Select
|
|
Return ""
|
|
End Function
|
|
|
|
Public Function FromString(ByVal sVal As String, Optional bConvertUnits As Boolean = True) 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 nVal As Integer
|
|
If StringToInt(sVal, nVal) Then
|
|
m_nVal = nVal
|
|
Return True
|
|
End If
|
|
Case 3 ' lunghezza
|
|
Dim dVal As Double
|
|
If StringToDouble(sVal, dVal) Then
|
|
If bConvertUnits Then
|
|
m_dVal = EgtFromUiUnits(dVal)
|
|
Else
|
|
m_dVal = dVal
|
|
End If
|
|
Return True
|
|
End If
|
|
Case 4 ' double
|
|
Dim dVal As Double
|
|
If StringToDouble(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 |