Files
omagoffice/CompoWindow/CompoWindowVM.vb
T
Emmanuele Sassi 32d9f4fd7a OmagOFFICE 1.9k1 :
- aggiunta gestione angoli di fianco con tallone (bisello)
- ora angolo verso esterno mantiene dimensione totale del pezzo
- gestione ventose con asse rotante a step (STEPS=Val1,Val2,... in GEO di asse)
- aggiunta gestione accorciamento fresate negli angoli
- sistemazione dati TRF da compo e aggiunta codice pezzo
- in DB utensili con nuova lama creazione/aggiornamento note speciali Hofmann
- abilitazione bottoni UnderCut e DripDrill sempre da chiave
- aggiunto secondo offset nei tagli da sotto
- modifiche a componenti per import DXF e nome su linea separata
- dati TRF non più richiesti per default sui componenti
2018-11-13 17:40:30 +00:00

314 lines
13 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, 0) <> 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 b3Part As New BBox3d
EgtGetBBoxGlob(nOutLoopLayer, GDB_BB.STANDARD, b3Part)
' Muovo la regione in Z per evitare problemi in visualizzazione
EgtMove(nRegLayId, New Vector3d(0, 0, DELTAZ_REG), GDB_RT.GLOB)
' Se pezzo con dati normali
If Not m_bTrfData Then
' Se definito nome lo inserisco nel testo
If Not String.IsNullOrWhiteSpace(sName) Then
Dim nTextId = EgtGetFirstInGroup(nRegLayId)
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 & "<br/>" & sText
EgtModifyText(nTextId, sNewText)
Exit While
End If
nTextId = EgtGetNext(nTextId)
End While
End If
' altrimenti se pezzo con dati TRF
Else
' Nome da dati Trf
Dim nTextId = EgtGetFirstInGroup(nRegLayId)
While nTextId <> GDB_ID.NULL
If EgtGetType(nTextId) = GDB_TY.EXT_TEXT Then
Dim sText As String = CompoWindowMap.refCompoManagerVM.bTrfOrderCode & "-" & CompoWindowMap.refCompoManagerVM.bTrfOrderDesc
Dim sText2 As String = CompoWindowMap.refCompoManagerVM.bTrfMatCode & "-" & CompoWindowMap.refCompoManagerVM.bTrfSurfCode
Dim sText3 As String = LenToString(b3Part.DimX(), 0) & " x " & LenToString(b3Part.DimY(), 0) & " x " & LenToString(CompoWindowMap.refCompoManagerVM.bTrfThickness, 0)
Dim dRatio As Double = Math.Max(b3Part.DimX(), b3Part.DimY()) / Math.Min(b3Part.DimX(), b3Part.DimY())
If dRatio < 5 Then
sText = sText & "<br/>" & sText2 & "<br/>" & sText3
Else
sText = sText & " " & sText2 & " " & sText3
End If
EgtModifyText(nTextId, sText)
Dim ptCen As Point3d
EgtCenterPoint(nTextId, ptCen)
Dim b3Text As New BBox3d
EgtGetBBoxGlob(nTextId, GDB_BB.STANDARD, b3Text)
Dim dCoeff As Double = Math.Min(b3Part.DimX() / b3Text.DimX(), b3Part.DimY() / b3Text.DimY()) / 1.25
If dCoeff < 1 Then
EgtScale(nTextId, New Frame3d(ptCen), dCoeff, dCoeff, dCoeff)
End If
Exit While
End If
nTextId = EgtGetNext(nTextId)
End While
' Info di pezzo da dati Trf
EgtSetInfo(Pz, "OC", CompoWindowMap.refCompoManagerVM.bTrfOrderCode)
EgtSetInfo(Pz, "OD", CompoWindowMap.refCompoManagerVM.bTrfOrderDesc)
EgtSetInfo(Pz, "PC", CompoWindowMap.refCompoManagerVM.bTrfPartCode)
EgtSetInfo(Pz, "MT", CompoWindowMap.refCompoManagerVM.bTrfMatCode)
EgtSetInfo(Pz, "SRF", CompoWindowMap.refCompoManagerVM.bTrfSurfCode)
EgtSetInfo(Pz, "L", DoubleToString(b3Part.DimX(), 1))
EgtSetInfo(Pz, "W", DoubleToString(b3Part.DimY(), 1))
EgtSetInfo(Pz, "T", CompoWindowMap.refCompoManagerVM.bTrfThickness)
EgtSetInfo(Pz, "V1", DoubleToString(b3Part.DimX(), 1))
EgtSetInfo(Pz, "V2", DoubleToString(b3Part.DimY(), 1))
End If
' Eventuale testo per indicare il sopra (solo nel caso di rettangolo)
If CompoWindowMap.refCompoManagerVM.Top_Visibility = Visibility.Visible And
CompoWindowMap.refCompoManagerVM.TopIsChecked Then
Dim dDimX As Double = b3Part.DimX()
Dim dDimY As Double = b3Part.DimY()
Dim dH As Double = Math.Min(0.1 * dDimY, 30)
Dim nText As Integer = EgtCreateTextAdv(nRegLayId, 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
' 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()
' Aggiusto per lavorazioni
AdjustFlatPart(nId2)
' Se dati Trf assegno nome univoco
If m_bTrfData Then EgtSetInfo(nId2, "CsvPart", CompoWindowMap.refCompoManagerVM.bTrfOrderCode & "-" & nId2.ToString())
' 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