Imports System.Globalization Imports EgtUILib Public Class RawPartPageUC ' Riferimento alla MainWindow Dim m_MainWindow As MainWindow = Application.Current.MainWindow Dim WithEvents m_CurrProjPage As CurrentProjectPageUC ' Flag di pagina attiva Private m_bActive As Boolean = False ' Dati per Drag Private m_bDrag As Boolean = False Private m_ptPrev As Point3d ' Modalità aggiornamento variabili Friend m_bShowVar As Boolean = False ' Dimensioni grezzo rettangolare Private m_RawLength As Double Private m_RawWidth As Double Private m_RawHeight As Double Private m_RawOffsX As Double Private m_RawOffsY As Double Private m_RawKerf As Double Private Sub RawPartPage_Initialized(sender As Object, e As EventArgs) 'Associazione della lista materiali alla combobox MaterialsCmbx.ItemsSource = m_MainWindow.m_MaterialsList 'Associazione tag textbox e label per visualizzare nome nella calcolatrice LengthTxBx.Tag = LengthLbl WidthTxBx.Tag = WidthLbl HeightTxBx.Tag = HeightLbl OffsetXTxBx.Tag = OffsetXLbl OffsetYTxBx.Tag = OffsetYLbl KerfTxBx.Tag = KerfLbl 'Imposto i messaggi letti dal file dei messaggi RectangleBtn.Content = EgtMsg(MSG_ROWPARTPAGEUC + 1) 'Rectangle - Rettangolo ByPointsBtn.Content = EgtMsg(MSG_ROWPARTPAGEUC + 2) 'By points - Per punti LengthLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 3) 'Length - Lunghezza WidthLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 4) 'Width - Larghezza HeightLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 5) 'Height - Spessore OffsetXLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 6) 'Offset X OffsetYLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 7) 'Offset Y KerfLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 8) 'Kerf MaterialLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 9) 'Material - Materiale DamagedAreaLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 10) 'Damaged area - Zona rovinata NewBtn.Content = EgtMsg(MSG_ROWPARTPAGEUC + 11) 'New - Nuovo DeleteBtn.Content = EgtMsg(MSG_ROWPARTPAGEUC + 12) 'Delete - Cancella PointsLbl.Content = EgtMsg(MSG_ROWPARTPAGEUC + 13) 'Points - Punti AddBtn.Content = EgtMsg(MSG_ROWPARTPAGEUC + 14) 'Add - Aggiungi RemoveBtn.Content = EgtMsg(MSG_ROWPARTPAGEUC + 15) 'Remove - Rimuovi End Sub Private Sub RawPartPage_Loaded(sender As Object, e As RoutedEventArgs) m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC m_bActive = True ' Nascondo eventuali pezzi in parcheggio HideParkedParts() ' Visualizzo eventuale foto m_MainWindow.m_CurrentProjectPageUC.ShowPhoto(True) ' Se esiste già il grezzo... Dim nRawId As Integer = EgtGetFirstRawPart() If nRawId <> GDB_ID.NULL Then ' origine tavola Dim ptOri As Point3d EgtGetTableRef1(ptOri) ' box grezzo Dim ptMin, ptMax As Point3d Dim nFlag As Integer = GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM EgtGetBBoxGlob(nRawId, nFlag, ptMin, ptMax) ' kerf EgtGetInfo(nRawId, "Kerf", m_RawKerf) ' aggiorno dati grezzo m_RawLength = ptMax.x - ptMin.x - 2 * m_RawKerf m_RawWidth = ptMax.y - ptMin.y - 2 * m_RawKerf m_RawHeight = ptMax.z - ptMin.z m_RawOffsX = ptMin.x - ptOri.x + m_RawKerf m_RawOffsY = ptMin.y - ptOri.y + m_RawKerf ' aggiorno l'apparenza del grezzo AdjustRawPartOnStart() ' Altrimenti lo definisco Else ' Leggo da Ini gli ultimi valori m_RawLength = GetPrivateProfileDouble(S_RAWPART, K_RAWLENGTH, 2500, m_MainWindow.GetIniFile()) m_RawWidth = GetPrivateProfileDouble(S_RAWPART, K_RAWWIDTH, 1500, m_MainWindow.GetIniFile()) m_RawHeight = GetPrivateProfileDouble(S_RAWPART, K_RAWHEIGHT, 30, m_MainWindow.GetIniFile()) m_RawOffsX = GetPrivateProfileDouble(S_RAWPART, K_RAWOFFSX, 100, m_MainWindow.GetIniFile()) m_RawOffsY = GetPrivateProfileDouble(S_RAWPART, K_RAWOFFSY, 100, m_MainWindow.GetIniFile()) m_RawKerf = GetPrivateProfileDouble(S_RAWPART, K_RAWKERF, 50, m_MainWindow.GetIniFile()) End If ' Deseleziono pezzi EgtDeselectAll() ' Seleziono modalità rettangolo RectangleBtn.IsChecked = True ' Assegno dati grezzo rettangolare ai textbox m_bShowVar = True LengthTxBx.Text = DoubleToString(m_RawLength, 2) WidthTxBx.Text = DoubleToString(m_RawWidth, 2) HeightTxBx.Text = DoubleToString(m_RawHeight, 2) OffsetXTxBx.Text = DoubleToString(m_RawOffsX, 2) OffsetYTxBx.Text = DoubleToString(m_RawOffsY, 2) KerfTxBx.Text = DoubleToString(m_RawKerf, 2) m_bShowVar = False ' Aggiorno grezzo UpdateRawPart() ' Imposto il materiale corrente nella combobox MaterialsCmbx.SelectedIndex = m_MainWindow.m_nCurrentMaterial 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 ' Verifico se selezionato indicativo di grezzo Dim nSolidId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, "RawSolid") 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 If nSolidId <> GDB_ID.NULL And nId = nSolidId Then m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev) Exit While End If End While End Sub Private Sub OnMyMouseMoveScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseMoveScene ' Verifico di essere il gestore attivo If Not m_bActive Then Return End If ' Verifico di essere in modalità drag If Not m_bDrag Then Return End If ' Ricavo il punto corrente in coordinate mondo Dim ptCurr As Point3d EgtUnProjectPoint(e.Location, ptCurr) ' Ricavo il vettore di movimento Dim vtMove As Vector3d = ptCurr - m_ptPrev ' Muovo il grezzo EgtMoveRawPart(m_CurrProjPage.m_nRawId, vtMove) EgtDraw() ' Aggiorno gli offset m_RawOffsX += vtMove.x m_RawOffsY += vtMove.y m_bShowVar = True OffsetXTxBx.Text = DoubleToString(m_RawOffsX, 2) OffsetYTxBx.Text = DoubleToString(m_RawOffsY, 2) m_bShowVar = False ' Aggiorno il punto precedente m_ptPrev = ptCurr End Sub Private Sub OnMyMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseUpScene ' Verifico di essere il gestore attivo If Not m_bActive Then Return End If ' Disabilito modalità drag m_bDrag = False End Sub Private Sub MaterialsCmbx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles MaterialsCmbx.SelectionChanged m_MainWindow.m_nCurrentMaterial = MaterialsCmbx.SelectedIndex m_CurrProjPage.MaterialTxBx.Text = m_MainWindow.m_MaterialsList(m_MainWindow.m_nCurrentMaterial).Name End Sub Private Sub ExitBtnUC_Click(sender As Object, e As RoutedEventArgs) ' Sistemo il grezzo AdjustRawPartOnExit() ' Ripristino visualizzazione di eventuali pezzi in parcheggio ShowParkedParts() ' Imposto spessore del grezzo m_CurrProjPage.m_dRawHeight = GetRawHeight() m_CurrProjPage.HeightTxBx.Text = m_CurrProjPage.m_dRawHeight ' Salvo nel file Ini le dimensioni del grezzo WritePrivateProfileString(S_RAWPART, K_RAWLENGTH, DoubleToString(m_RawLength, 2), m_MainWindow.GetIniFile()) WritePrivateProfileString(S_RAWPART, K_RAWWIDTH, DoubleToString(m_RawWidth, 2), m_MainWindow.GetIniFile()) WritePrivateProfileString(S_RAWPART, K_RAWHEIGHT, DoubleToString(m_RawHeight, 2), m_MainWindow.GetIniFile()) WritePrivateProfileString(S_RAWPART, K_RAWOFFSX, DoubleToString(m_RawOffsX, 2), m_MainWindow.GetIniFile()) WritePrivateProfileString(S_RAWPART, K_RAWOFFSY, DoubleToString(m_RawOffsY, 2), m_MainWindow.GetIniFile()) WritePrivateProfileString(S_RAWPART, K_RAWKERF, DoubleToString(m_RawKerf, 2), m_MainWindow.GetIniFile()) ' Esco dalla pagina m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(Me) m_CurrProjPage.CurrProjGrid.Visibility = Windows.Visibility.Visible m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC) m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut End Sub Private Sub RectangleBtnUC_Click(sender As Object, e As RoutedEventArgs) Handles RectangleBtn.Click 'Seleziono il bottone RectangleBtn RectangleBtn.IsChecked = True End Sub Public Function GetRawHeight() As Double Dim nRawId As Integer = EgtGetFirstRawPart() Dim nSolidRawId As Integer = EgtGetFirstNameInGroup(nRawId, "RawSolid") If nSolidRawId = GDB_ID.NULL Then Return 0 End If ' box grezzo Dim ptMin, ptMax As Point3d Dim nFlag As Integer = GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM EgtGetBBoxGlob(nSolidRawId, nFlag, ptMin, ptMax) Return ptMax.z - ptMin.z End Function Friend Sub UpdateRawPart() ' Raccolgo i dati del grezzo rettangolare Dim dLength As Double If Not StringToDouble(LengthTxBx.Text, dLength) Or dLength < EPS_SMALL Then Return End If m_RawLength = dLength Dim dWidth As Double If Not StringToDouble(WidthTxBx.Text, dWidth) Or dWidth < EPS_SMALL Then Return End If m_RawWidth = dWidth Dim dHeight As Double If Not StringToDouble(HeightTxBx.Text, dHeight) Or dHeight < EPS_SMALL Then Return End If m_RawHeight = dHeight Dim dOffsetX As Double If Not StringToDouble(OffsetXTxBx.Text, dOffsetX) Then Return End If m_RawOffsX = dOffsetX Dim dOffsetY As Double If Not StringToDouble(OffsetYTxBx.Text, dOffsetY) Then Return End If m_RawOffsY = dOffsetY Dim dKerf As Double If Not StringToDouble(KerfTxBx.Text, dKerf) Then Return End If If dKerf < EPS_SMALL Then dKerf = 0 End If m_RawKerf = dKerf ' Se non esiste già il grezzo lo inserisco Dim nRawId As Integer = EgtGetFirstRawPart() If nRawId = GDB_ID.NULL Then ' recupero il colore Dim Col As New Color3d(64, 192, 255, 40) GetPrivateProfileColor(S_RAWPART, K_RAWCOLOR, Col, m_MainWindow.GetIniFile()) ' in presenza di foto rendo molto più trasparente If m_CurrProjPage.GetPhoto() <> GDB_ID.NULL Then Col.A = 20 End If m_CurrProjPage.m_nRawId = EgtAddRawPart(Point3d.ORIG(), m_RawLength + 2 * m_RawKerf, m_RawWidth + 2 * m_RawKerf, m_RawHeight, Col) ' Altrimenti lo modifico Else m_CurrProjPage.m_nRawId = nRawId EgtModifyRawPartSize(nRawId, m_RawLength + 2 * m_RawKerf, m_RawWidth + 2 * m_RawKerf, m_RawHeight) End If UpdateRawPartKerf() ' Sistemo la posizione EgtMoveToCornerRawPart(m_CurrProjPage.m_nRawId, New Point3d(m_RawOffsX - m_RawKerf, m_RawOffsY - m_RawKerf, 0), MCH_CR.BL) ' Aggiorno visualizzazione EgtZoom(ZM.ALL) End Sub Private Function UpdateRawPartKerf() As Boolean ' Recupero il vecchio valore del kerf Dim dOldKerf As Double If Not EgtGetInfo(m_CurrProjPage.m_nRawId, "Kerf", dOldKerf) Then dOldKerf = GetPrivateProfileDouble(S_RAWPART, K_RAWKERF, 30, m_MainWindow.GetIniFile()) End If ' Cancello eventuale vecchio contorno di kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, "Kerf") EgtErase(nKerfId) ' box grezzo Dim ptMin, ptMax As Point3d Dim nFlag As Integer = GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM EgtGetBBoxGlob(m_CurrProjPage.m_nRawId, nFlag, ptMin, ptMax) ptMin.x += m_RawKerf ptMin.y += m_RawKerf ptMin.z = ptMax.z ptMax.x -= m_RawKerf ptMax.y -= m_RawKerf ' Creo il nuovo contorno del kerf nKerfId = EgtCreateRectangle2P(m_CurrProjPage.m_nRawId, ptMin, ptMax, GDB_RT.GLOB) EgtSetName(nKerfId, "Kerf") Dim Col As New Color3d(255, 0, 0, 100) GetPrivateProfileColor(S_RAWPART, K_KERFCOLOR, Col, m_MainWindow.GetIniFile()) EgtSetColor(nKerfId, Col) ' Salvo il nuovo valore EgtSetInfo(m_CurrProjPage.m_nRawId, "Kerf", DoubleToString(m_RawKerf, 4)) Return True End Function Private Sub AdjustRawPartOnStart() ' Se non c'è la foto va già bene così If m_CurrProjPage.GetPhoto() = GDB_ID.NULL Then Return End If ' Disabilito la texture della foto Dim nSolidId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, "RawSolid") EgtRemoveInfo(nSolidId, "!TNA") ' Sistemo il colore Dim Col As New Color3d(64, 192, 255, 40) GetPrivateProfileColor(S_RAWPART, K_RAWCOLOR, Col, m_MainWindow.GetIniFile()) Col.A = 20 EgtSetColor(nSolidId, Col, True) End Sub Private Sub AdjustRawPartOnExit() ' Se non c'è la foto va già bene così If m_CurrProjPage.GetPhoto() = GDB_ID.NULL Then Return End If ' Carico la texture della foto Dim nSolidId = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, "RawSolid") EgtSetInfo(nSolidId, "!TNA", "Raw") ' Sistemo il riferimento della texture Dim refGlob As New Frame3d EgtGetGroupGlobFrame(m_CurrProjPage.m_nRawId, refGlob) Dim refTxt As New Frame3d m_CurrProjPage.GetPhotoTextureRef(refTxt) refTxt.ToLoc(refGlob) EgtSetInfo(nSolidId, "!TFR", refTxt) ' Sistemo il colore EgtSetColor(nSolidId, New Color3d(255, 255, 255, 100), True) End Sub Private Sub RawPartPage_Unloaded(sender As Object, e As RoutedEventArgs) ' Nascondo eventuale foto m_MainWindow.m_CurrentProjectPageUC.ShowPhoto(False) m_bActive = False End Sub End Class