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 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) 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 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(nNbr As Integer, sName As String) As Boolean ' ricarico componente corrente ExecCompoFile() ' aggiorno variabili CompoWindowMap.refCompoParamPageVM.UpdateVariables() ' 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() ' 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 '' Sistemo gocciolatoi 'm_SideAngle.CreateDripGeom(nId2) ' 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.15 * dDimY, 30) Dim nText As Integer = EgtCreateTextAdv(nRegId, New Point3d(dDimX / 2, dDimY - 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) ' 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 Return True End Function Friend Function MakeCompoInsert(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 ' 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 = OmagOFFICEMap.refMainWindowVM.MainWindowM.sTempDir & "\FlatPartCompo.Nge" If Not EgtSaveObjToFile(1, sTmpFile, NGE.BIN) Then Return False End If ' Passo al contesto principale EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.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 ' Aggiusto per lavorazioni AdjustFlatPart(nId2) ' Inserisco in parcheggio EstCalc.StoreOnePart(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