Files
omagoffice/CompoWindow/CompoWindowVM.vb
T
Emmanuele Sassi 84bddeec9a OmagOFFICE :
- Gestione dati TRF.
- Stime tempi e costi.
- Lavorazioni da sotto.
2018-08-10 16:40:06 +00:00

270 lines
10 KiB
VB.net

Imports EgtUILib
Imports EgtWPFLib5
Public Class CompoWindowVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Enum CompoPageOpt As Integer
LIST
PARAM
End Enum
Friend 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"
Friend 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"
Friend Const LUA_CMP_WITHINT As String = LUA_CMP_VARS & ".WithInt"
Friend Event m_CloseWindow(bDialogResult As Boolean)
Friend m_SelCompoFamily As CompoItem = Nothing
Friend m_SelCompo As CompoItem = Nothing
Friend m_SelInternalCompo As CompoItem = Nothing
Private m_sCompoDir As String = String.Empty
Friend m_bDrawOk As Boolean = False
' Trf Data
Private m_bTrfData As Boolean = False
Friend ReadOnly Property bTrfData As Boolean
Get
Return m_bTrfData
End Get
End Property
Private m_CompoPage As CompoPageOpt
Public Property CompoPage As CompoPageOpt
Get
Return m_CompoPage
End Get
Set(value As CompoPageOpt)
m_CompoPage = value
If value = CompoPageOpt.LIST Then
CompoWindowMap.refCompoListPageVM.InitCompoListPage()
Else
CompoWindowMap.refCompoParamPageVM.InitCompoParamPage()
End If
NotifyPropertyChanged("CompoPageControl")
End Set
End Property
Private m_CompoListPageV As CompoListPageV
Private m_CompoParamPageV As CompoParamPageV
Public ReadOnly Property CompoPageControl As ContentControl
Get
If m_CompoPage = CompoPageOpt.LIST Then
Return m_CompoListPageV
Else
Return m_CompoParamPageV
End If
End Get
End Property
Private m_CompoManagerV As CompoManagerV
Public ReadOnly Property CompoManagerV As CompoManagerV
Get
Return m_CompoManagerV
End Get
End Property
#Region "Messages"
Public ReadOnly Property TitleMsg As String
Get
Return EgtMsg(MSG_DRAWPAGEUC + 5) ' Disegno Parametrico
End Get
End Property
#End Region ' Messages
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Avvio l'inizializzazione della mappa passandogli il riferimento al CompoWindowVM
CompoWindowMap.BeginInit(Me)
' Creo pagina CompoList
m_CompoListPageV = New CompoListPageV
m_CompoListPageV.DataContext = New CompoListPageVM
' Creo pagina CompoParam
m_CompoParamPageV = New CompoParamPageV
m_CompoParamPageV.DataContext = New CompoParamPageVM
' creo pagina CompoManager
m_CompoManagerV = New CompoManagerV
m_CompoManagerV.DataContext = New CompoManagerVM
' Inizializzo e visualizzo per default la CompoListPage
CompoWindowMap.refCompoListPageVM.InitCompoListPage()
CompoPage = CompoPageOpt.LIST
' Recupero path cartella che contiene i componenti
GetMainPrivateProfileString("Compo", "CompoDir", "", m_sCompoDir)
' Abilitazione lavorazioni da sotto da chiave
CompoWindowMap.refCompoParamPageVM.Drip_IsEnabled = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.UNDER_CUT)
CompoWindowMap.refCompoListPageVM.Drip_IsEnabled = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.UNDER_CUT)
' Abilitazione Nome/TrfData
m_bTrfData = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.TRF_IMPORT) And
(GetMainPrivateProfileInt(S_COMPO, K_TRFDATA, 1) <> 0)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend 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
AdjustFlatPart(EgtGetFirstPart())
Return m_bDrawOk
End Function
Friend Function ExecCompoFile() As Boolean
Dim sPath As String = String.Empty
' Verifico se componente interno o normale e costruisco path completa del componente
If IsNothing(m_SelInternalCompo) Then
sPath = m_sCompoDir & "\" & m_SelCompo.LuaPath
Else
sPath = m_sCompoDir & "\" & m_SelInternalCompo.LuaPath
End If
' Carico il file
Return EgtLuaExecFile(sPath)
End Function
Friend Sub UpdateView()
' verifico ci sia un componente corrente
If IsNothing(m_SelCompo) Then
Return
End If
' aggiorno le variabili dalla griglia
CompoWindowMap.refCompoParamPageVM.UpdateVariables()
' ricalcolo il disegno
Dim sMsg As String = String.Empty
MakePreview(sMsg)
CompoWindowMap.refCompoParamPageVM.SetOutputMessage(sMsg, If(m_bDrawOk, MSG_TYPE.INFO, MSG_TYPE.ERROR_))
' aggiorno visualizzazione
EgtSetView(VT.TOP, False)
EgtZoom(ZM.ALL)
End Sub
Friend Function MakeInsert(ByVal nNbr As Integer, sName As String) As Boolean
' Passo al contesto corrente
EgtSetCurrentContext(CompoWindowMap.refCompoSceneHostV.CompoScene.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
' Calcolo dimensione ingombro Pezzo tramite OutLoop
Dim nOutLoopLayer = EgtGetFirstNameInGroup(Pz, NAME_OUTLOOP)
Dim ptMin, ptMax As Point3d
EgtGetBBoxGlob(nOutLoopLayer, GDB_BB.STANDARD, ptMin, ptMax)
' Scrivo testi per nesting
SideEntityControlVM.WriteSideAngleForNest(CompoWindowMap.refCompoSceneHostV.CompoScene.GetCtx())
' Esporto il pezzo in un file temporaneo
Dim sTmpFile As String = OmagOFFICEMap.refMainWindowVM.MainWindowM.sTempDir & "\FlatPartCompo.Nge"
If Not EgtSaveObjToFile(1, sTmpFile, NGE.BIN) Then
Return False
End If
' Passo al contesto principale
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx())
' Recupero flag per inserimento diretto in grezzo (altrimenti in parcheggio)
Dim bDirect As Boolean = (GetMainPrivateProfileInt(S_NEST, K_DIRECT, 0) <> 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)
' Se definito nome lo inserisco nel testo
If Not String.IsNullOrWhiteSpace(sName) Then
Dim nTextId = EgtGetFirstInGroup(nRegId)
While nTextId <> GDB_ID.NULL
If EgtGetType(nTextId) = GDB_TY.EXT_TEXT Then
Dim sText As String = String.Empty
EgtTextGetContent(nTextId, sText)
Dim sNewText = sName & " " & sText
EgtModifyText(nTextId, sNewText)
Exit While
End If
nTextId = EgtGetNext(nTextId)
End While
End If
' Eventuale testo per indicare il sopra (solo nel caso di rettangolo)
If CompoWindowMap.refCompoManagerVM.TopIsChecked Then
Dim dDimX As Double = ptMax.x - ptMin.x
Dim dDimY As Double = ptMax.y - ptMin.y
Dim dH As Double = Math.Min(0.1 * dDimY, 30)
Dim nText As Integer = EgtCreateTextAdv(nRegId, New Point3d(dDimX / 2, dDimY - 0.6 * dH, 0), 0, "*TOP*", "", 500, False, dH, 1, 0, INS_POS.MC)
EgtSetColor(nText, New Color3d())
End If
' Aggiusto per lavorazioni
AdjustFlatPart(nId2)
' Inserisco in parcheggio
EstCalc.StoreOnePart(nId2, True)
' Aggiungo riferimento e lo inserisco in VeinMatching
VeinMatching.SetRefOnPart(nId2)
VeinMatching.AddPart(nId2, True)
' Se richiesto posizionamento diretto, lo eseguo
If bDirect Then
If EstCalc.InsertOnePart(nId2, CurrentMachine.bAligned, CurrentMachine.bReducedCut) Then
' Eventuale notifica al VeinMatching
VeinMatching.OnInsertPartInRaw(nId2)
End If
End If
Next
' Cancello il file
My.Computer.FileSystem.DeleteFile(sTmpFile)
End If
' Aggiorno ambiente principale
EgtZoom(ZM.ALL)
Return True
End Function
Friend Sub Close(bDialogResult As Boolean)
RaiseEvent m_CloseWindow(bDialogResult)
End Sub
#End Region ' METHODS
End Class