Imports EgtUILib Public Class MoveRawPartPage ' Riferimento alla MainWindow Private m_MainWindow As MainWindow = Application.Current.MainWindow Private WithEvents m_CurrProjPage As CurrentProjectPageUC ' Flag di pagina attiva Private m_bActive As Boolean = False ' Fase corrente Private m_nCurrPhase As Integer = 0 ' Dati movimento Private m_dStep As Double = 0 Private Sub MoveRawPartPage_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized PrevBtn.IsEnabled = False RemovePartBtn.Content = EgtMsg(MSG_MOVERAWPAGEUC + 1) 'Rimuovi End Sub Private Sub MoveRawPartPage_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC m_bActive = True ' Deseleziono tutto EgtDeselectAll() ' Recupero i tagli allungati prima definiti Dim Cuts(0) As Integer m_MainWindow.m_CadCutPageUC.m_SplitPage.GetSplitCuts(Cuts) ' Aggiorno preview di questi tagli lasciandoli nella lavorazione For Each nCut As Integer In Cuts UpdateMachiningPreview(nCut, False) Next ' Fase precedente Dim nPrevPhase As Integer = EgtGetCurrPhase() ' Creo nuova fase m_nCurrPhase = EgtAddPhase() ' Origine tavola Dim ptOri As Point3d EgtGetTableRef(1, ptOri) Dim vtOri As New Vector3d(ptOri.x, ptOri.y, ptOri.z) ' Se non ci sono tagli allungati, confermo i grezzi If Cuts.Length() = 0 Then ' Ciclo sui grezzi Dim nRawId As Integer = EgtGetFirstRawPart() While nRawId <> GDB_ID.NULL If EgtVerifyRawPartPhase(nRawId, nPrevPhase) Then ' Confermo il grezzo EgtKeepRawPart(nRawId) ' Fisso posizione del grezzo Dim ptMin, ptMax As Point3d GetRawBox(nRawId, ptMin, ptMax) EgtMoveToCornerRawPart(nRawId, ptMin - vtOri, MCH_CR.BL) End If nRawId = EgtGetNextRawPart(nRawId) End While ' Altrimenti eseguo eventuali spezzature dei grezzi e vi sposto i pezzi Else ' eseguo spezzature Dim nRawId As Integer = EgtGetFirstRawPart() While nRawId <> GDB_ID.NULL ' se il grezzo è presente nella fase precedente If EgtVerifyRawPartPhase(nRawId, nPrevPhase) Then ' Calcolo nuovi grezzi Dim nRaw1Id = EgtSplitFlatRawPartWithMachinings(nRawId, Cuts) ' Fisso posizione dei nuovi grezzi Dim nNewRawId = nRaw1Id While nNewRawId <> GDB_ID.NULL Dim ptMin, ptMax As Point3d GetRawBox(nNewRawId, ptMin, ptMax) EgtMoveToCornerRawPart(nNewRawId, ptMin - vtOri, MCH_CR.BL) nNewRawId = EgtGetNextRawPart(nNewRawId) End While ' Assegno ai nuovi grezzi eventuale texture del grezzo originale Dim nSolidId = EgtGetFirstNameInGroup(nRawId, NAME_RAW_SOLID) Dim nameTxr As String = String.Empty If EgtGetTextureName(nSolidId, nameTxr) Then Dim refTxr As New Frame3d EgtGetTextureFrame(nSolidId, GDB_ID.ROOT, refTxr) nNewRawId = nRaw1Id While nNewRawId <> GDB_ID.NULL ' Carico la texture sul nuovo grezzo Dim nNewSolidId = EgtGetFirstNameInGroup(nNewRawId, NAME_RAW_SOLID) EgtSetTextureName(nNewSolidId, nameTxr) ' Sistemo il riferimento della texture EgtSetTextureFrame(nNewSolidId, refTxr, GDB_RT.GLOB) ' Passo al grezzo successivo nNewRawId = EgtGetNextRawPart(nNewRawId) End While End If End If ' passo al successivo grezzo nRawId = EgtGetNextRawPart(nRawId) End While End If ' Sposto tutte le lavorazioni disabilitate e le eventuali inglobate nella nuova fase Dim nId = EgtGetFirstOperation() While nId <> GDB_ID.NULL Dim nNextId = EgtGetNextOperation(nId) If IsValidMachining(nId) And EgtGetOperationPhase(nId) = m_nCurrPhase - 1 And EgtExistsInfo(nId, INFO_MCH_USER_OFF) Then ' sposto la lavorazione EgtChangeOperationPhase(nId, m_nCurrPhase) ' sposto le inglobate Dim sInfo As String = String.Empty If EgtGetInfo(nId, INFO_MCH_OTHMID, sInfo) Then Dim sItems() As String = sInfo.Split(",".ToCharArray) For Each sId In sItems EgtChangeOperationPhase(CInt(sId), m_nCurrPhase) Next End If End If nId = nNextId End While ' Aggiorno visualizzazione EgtDraw() ' carico i parametri di movimento m_dStep = GetPrivateProfileDouble(S_RAWMOVE, K_RAWSTEP, 50, m_MainWindow.GetIniFile()) StepMoveTxBx.Text = LenToString(m_dStep, 3) End Sub Private Sub OnMyMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseDownScene ' Verifico di essere il gestore attivo If Not m_bActive Then Return End If ' Si può selezionare solo con il tasto sinistro e se stato NULL If e.Button <> Windows.Forms.MouseButtons.Left Or Not m_CurrProjPage.CurrentProjectScene.IsStatusNull() Then Return End If ' Gruppo dei grezzi Dim nRawGroupId = EgtGetParent(EgtGetFirstRawPart()) ' Verifico se selezionato indicativo di grezzo attivo EgtSetObjFilterForSelect(True, True, True, True, True) Dim nSel As Integer EgtSelect(e.Location, Scene.DIM_SEL, Scene.DIM_SEL, nSel) Dim nId As Integer = EgtGetFirstObjInSelWin() While nId <> GDB_ID.NULL ' Cerco l'identificativo del grezzo cui appartiene Dim nParentId = EgtGetParent(nId) While nParentId <> GDB_ID.NULL And nParentId <> nRawGroupId nId = nParentId nParentId = EgtGetParent(nId) End While ' Se trovato il grezzo If nParentId = nRawGroupId Then Dim nStat As Integer = GDB_ST.ON_ EgtGetStatus(nId, nStat) If nStat = GDB_ST.SEL Then EgtSetStatus(nId, GDB_ST.ON_) Else EgtSetStatus(nId, GDB_ST.SEL) End If EgtDraw() Exit While End If nId = EgtGetNextObjInSelWin() End While End Sub Private Sub UpBtn_Click(sender As Object, e As RoutedEventArgs) Handles UpBtn.Click Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL EgtMoveRawPart(nRawId, New Vector3d(0, m_dStep, 0)) nRawId = EgtGetNextSelectedObj() End While EgtDraw() End Sub Private Sub DownBtn_Click(sender As Object, e As RoutedEventArgs) Handles DownBtn.Click Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL EgtMoveRawPart(nRawId, New Vector3d(0, -m_dStep, 0)) nRawId = EgtGetNextSelectedObj() End While EgtDraw() End Sub Private Sub RightBtn_Click(sender As Object, e As RoutedEventArgs) Handles RightBtn.Click Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL EgtMoveRawPart(nRawId, New Vector3d(m_dStep, 0, 0)) nRawId = EgtGetNextSelectedObj() End While EgtDraw() End Sub Private Sub LeftBtn_Click(sender As Object, e As RoutedEventArgs) Handles LeftBtn.Click Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL EgtMoveRawPart(nRawId, New Vector3d(-m_dStep, 0, 0)) nRawId = EgtGetNextSelectedObj() End While EgtDraw() End Sub Private Sub RemovePartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemovePartBtn.Click Dim nRawId As Integer = EgtGetFirstSelectedObj() While nRawId <> GDB_ID.NULL EgtRemoveRawPartFromCurrPhase(nRawId) nRawId = EgtGetFirstSelectedObj() End While EgtDraw() End Sub Private Sub StepMoveTxBx_EgtClosed(sender As Object, e As EventArgs) Handles StepMoveTxBx.EgtClosed Dim dStep As Double If StringToLen(StepMoveTxBx.Text, dStep) Then m_dStep = Math.Max(dStep, 2 * EPS_SMALL) End If End Sub Private Sub NextBtn_Click(sender As Object, e As RoutedEventArgs) Handles NextBtn.Click ' Deseleziono tutto EgtDeselectAll() ' Passo alla pagina delle lavorazioni m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Remove(m_MainWindow.m_CadCutPageUC.m_MoveRawPartPage) m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC.m_SplitPage) m_MainWindow.m_CadCutPageUC.m_MovePartPage = CadCutPageUC.MovePartsPages.Split End Sub Private Sub MoveRawPartPage_Unloaded(sender As Object, e As EventArgs) Handles Me.Unloaded m_bActive = False End Sub End Class