Imports System.Threading Imports System.Windows.Threading Imports System.IO Imports System.Collections.ObjectModel Imports EgtWPFLib5 Imports EgtPHOTOLib Imports EgtUILib Public Class RawPartTabVM Inherits VMBase ' Timer Private m_TimerIsBusy As Boolean = False Private m_RefreshTimer As New DispatcherTimer Friend OmagPhoto As OmagPhotoV Private m_OmagPhotoVM As OmagPhotoVM Private m_bSlabIsSelectedFromDB As Boolean = False #Region "FIELDS & PROPERTIES" ' Colori standard Private m_RawCol As New Color3d(64, 192, 255, 40) Private m_KerfCol As New Color3d(255, 0, 0, 100) ' Dati tavola Private m_ptTableMin As Point3d Private m_dTableLength As Double = 0 Private m_dTableWidth As Double = 0 ' Dati per Drag Private m_bDrag As Boolean = False Private m_ptPrev As Point3d Private m_nDragEnt As Integer = -1 Private m_dDragPar As Double = 0 ' Modalità operazione su punti grezzo Private m_nPtMode As PTMODE = PTMODE.MOVE ' Modalità operazione su punti aree danneggiate Private m_nPtDmgMode As DMGMODE = DMGMODE.NONE ' Variabile che indica la zona danneggiata selezionata Private m_nSelDmg As Integer ' Layer per crocette temporanee Private m_nTempLay As Integer = GDB_ID.NULL ' Layer per crocette dei punti REG Friend m_nRegGroupId As Integer = GDB_ID.NULL ' Numero di spot inseriti nel grezzo corrente Private m_nCountSpot As Integer = 0 ' Gruppo Spot attualmente selezionato Private m_nCurrSpotRegId As Integer = GDB_ID.NULL Private Const COUNTSPOT As String = "CountSpot" Private Const REG As String = "Reg" Private Const SPOTREG_ As String = "SpotReg_" Private Const RADSPOT As Double = 20 ' Costante minima dimensione del grezzo Private Const MIN_RAW_DIM As Double = 10 ' Costante distanza di sicurezza del grezzo dal bordo Private Const SAFE_RAW_DIST As Double = 5 ' Costante raggio cerchietto Private Const RAD_CIRCLE As Double = 30 ' Stati dialogo tipo contorno Enum Type As Integer RECTANGLE = 0 BY_POINTS = 1 FROM_PHOTO = 2 End Enum ' Costanti modalità di creazione grezzo Private Enum RAWMODE As Integer RECTANGLE = 0 BY_POINTS = 1 FROM_PHOTO = 2 DAMAGED = 3 End Enum ' Costanti modo operazione punti Private Enum PTMODE MOVE = 0 ADD = 1 REMOVE = 2 End Enum ' Costanti modo operazione zone danneggiate Private Enum DMGMODE NONE = 0 ADD = 1 REMOVE = 2 End Enum Private m_SlabIdVisibility As Visibility Public Property SlabIdVisibility As Visibility Get Return m_SlabIdVisibility End Get Set(value As Visibility) If value <> m_SlabIdVisibility Then m_SlabIdVisibility = value NotifyPropertyChanged("SlabIdVisibility") End If End Set End Property Private m_SlabIdIsEnabled As Boolean Public Property SlabIdIsEnabled As Boolean Get Return m_SlabIdIsEnabled End Get Set(value As Boolean) If value <> m_SlabIdIsEnabled Then m_SlabIdIsEnabled = value NotifyPropertyChanged("SlabIdIsEnabled") End If End Set End Property Private m_PhotoWithMouse As Boolean Public Property PhotoWithMouse As Boolean Get Return m_PhotoWithMouse End Get Set(value As Boolean) m_PhotoWithMouse = value NotifyPropertyChanged("PhotoWithMouse") End Set End Property Private m_dPhotoOffsetX As Double Public Property PhotoOffsetX As String Get Return LenToString(m_dPhotoOffsetX, 2) End Get Set(value As String) Dim dVal As Double = 0 If StringToLen(value, dVal) Then ModifyPhoto(New Vector3d(dVal - m_dPhotoOffsetX, 0, 0)) End If End Set End Property Private Sub SetPhotoOffsetX(value As Double) m_dPhotoOffsetX = value NotifyPropertyChanged("PhotoOffsetX") End Sub Private m_dPhotoOffsetY As Double Public Property PhotoOffsetY As String Get Return LenToString(m_dPhotoOffsetY, 2) End Get Set(value As String) Dim dVal As Double = 0 If StringToLen(value, dVal) Then ModifyPhoto(New Vector3d(0, dVal - m_dPhotoOffsetY, 0)) End If End Set End Property Private Sub SetPhotoOffsetY(value As Double) m_dPhotoOffsetY = value NotifyPropertyChanged("PhotoOffsetY") End Sub Private m_dPhotoRot As Double Public Property PhotoRot As String Get Return LenToString(m_dPhotoRot, 2) End Get Set(value As String) Dim dVal As Double = 0 If StringToDouble(value, dVal) Then ModifyPhoto(dVal - m_dPhotoRot) End If End Set End Property Private Sub SetPhotoRot(value As Double) m_dPhotoRot = value NotifyPropertyChanged("PhotoRot") End Sub Private m_OutlineIsChecked As Boolean Public Property OutlineIsChecked As Boolean Get Return m_OutlineIsChecked End Get Set(value As Boolean) If value <> m_OutlineIsChecked Then m_OutlineIsChecked = value RawModeView() If m_OutlineIsChecked Then UpdateCircles() Else m_SelType = Type.BY_POINTS NotifyPropertyChanged("SelType") RemoveCircles() End If EgtDraw() NotifyPropertyChanged("OutlineIsChecked") End If End Set End Property Private m_TypeList As New List(Of String) Public ReadOnly Property TypeList As List(Of String) Get Return m_TypeList End Get End Property Private m_SelType As Integer Public Property SelType As Integer Get Return m_SelType End Get Set(value As Integer) m_SelType = value Select Case m_SelType Case Type.RECTANGLE RawModeView() RemoveCircles() RecalcRawPart() Case Type.BY_POINTS RawModeView() UpdateCircles() EgtDraw() Case Type.FROM_PHOTO RawModeView() RemoveCircles() CreateRawFromPhotoContour() EgtDraw() End Select End Set End Property Private m_TypeIsEnabled As Boolean Public Property TypeIsEnabled As Boolean Get Return m_TypeIsEnabled End Get Set(value As Boolean) If value <> m_TypeIsEnabled Then m_TypeIsEnabled = value NotifyPropertyChanged("TypeIsEnabled") End If End Set End Property #Region "Parametri Grezzo" Private m_dLength As Double Public Property Length As String Get If m_InvertKerf < 0 Then Return LenToString(m_dLength + 2 * m_dKerf, 2) Else Return LenToString(m_dLength, 2) End If 'Return LenToString(m_dLength, 2) End Get Set(value As String) Dim dLength As Double = 0 Dim dMaxLen As Double = m_dTableLength - m_dOffsetX - m_dKerf * m_InvertKerf If Not StringToLen(value, dLength) Then Return End If If dLength > EPS_SMALL And dLength < dMaxLen + EPS_SMALL Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() If m_InvertKerf < 0 Then m_dLength = dLength - 2 * m_dKerf Else m_dLength = dLength End If RecalcRawPart() ElseIf dLength <= EPS_SMALL Then NotifyPropertyChanged("Length") Else NotifyPropertyChanged("Length") ' Massima lunghezza = Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 16) & " " & LenToString(dMaxLen, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If End Set End Property Private Sub SetLength(value As Double) m_dLength = value NotifyPropertyChanged("Length") End Sub Private m_LengthIsEnabled As Boolean Public Property LengthIsEnabled As Boolean Get Return m_LengthIsEnabled End Get Set(value As Boolean) If value <> m_LengthIsEnabled Then m_LengthIsEnabled = value NotifyPropertyChanged("LengthIsEnabled") End If End Set End Property Private m_dWidth As Double Public Property Width As String Get If m_InvertKerf < 0 Then Return LenToString(m_dWidth + 2 * m_dKerf, 2) Else Return LenToString(m_dWidth, 2) End If End Get Set(value As String) Dim dWidth As Double = 0 Dim dMaxWidth As Double = m_dTableWidth - m_dOffsetY - m_dKerf * m_InvertKerf If Not StringToLen(value, dWidth) Then Return End If If dWidth > EPS_SMALL And dWidth < dMaxWidth + EPS_SMALL Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() If m_InvertKerf < 0 Then m_dWidth = dWidth - 2 * m_dKerf Else m_dWidth = dWidth End If RecalcRawPart() ElseIf dWidth <= EPS_SMALL Then NotifyPropertyChanged("Width") Else NotifyPropertyChanged("Width") ' Massima larghezza = Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 17) & " " & LenToString(dMaxWidth, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If End Set End Property Private Sub SetWidth(value As Double) m_dWidth = value NotifyPropertyChanged("Width") End Sub Private m_WidthIsEnabled As Boolean Public Property WidthIsEnabled As Boolean Get Return m_WidthIsEnabled End Get Set(value As Boolean) If value <> m_WidthIsEnabled Then m_WidthIsEnabled = value NotifyPropertyChanged("WidthIsEnabled") End If End Set End Property Private m_dHeight As Double Public Property Height As String Get Return LenToString(m_dHeight, 2) End Get Set(value As String) Dim dHeight As Double = 0 If StringToLen(value, dHeight) And dHeight > -EPS_ZERO Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() Dim dPrevHeight As Double = m_dHeight m_dHeight = dHeight UpdateRawPartHeight() UpdateTabState() MoveAllSpotRegistration(New Vector3d(0, 0, m_dHeight - dPrevHeight)) EstCalc.SetSlabHeight(dHeight) OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.NotifyPropertyChanged("MachGroupToolTip") Else ' Non sono ammessi spessori negativi Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 18) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If NotifyPropertyChanged("Height") End Set End Property Private Sub SetHeight(value As Double) m_dHeight = value NotifyPropertyChanged("Height") End Sub Private m_HeightIsEnabled As Boolean Public Property HeightIsEnabled As Boolean Get Return m_HeightIsEnabled End Get Set(value As Boolean) If value <> m_HeightIsEnabled Then m_HeightIsEnabled = value NotifyPropertyChanged("HeightIsEnabled") End If End Set End Property Private m_dOffsetX As Double Public Property OffsetX As String Get If m_InvertKerf < 0 Then Return LenToString(m_dOffsetX - m_dKerf, 2) Else Return LenToString(m_dOffsetX, 2) End If End Get Set(value As String) Dim dOffsetX As Double = 0 Dim dMinOffsetX As Double = m_dKerf Dim dMaxOffsetX As Double = m_dTableLength - m_dLength - m_dKerf If Not StringToLen(value, dOffsetX) Then Return End If If m_InvertKerf > 0 And dOffsetX > dMinOffsetX - EPS_SMALL And dOffsetX < dMaxOffsetX + EPS_SMALL Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() m_dOffsetX = dOffsetX RecalcRawPart() ElseIf m_InvertKerf < 0 And dOffsetX >= 0 And dOffsetX < dMaxOffsetX + m_dKerf Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() m_dOffsetX = dOffsetX RecalcRawPart() ElseIf dOffsetX <= dMinOffsetX - EPS_SMALL Then NotifyPropertyChanged("OffsetX") ' Minimo offset X = If m_InvertKerf < 0 Then Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 19) & " " & LenToString(0, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) Else Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 19) & " " & LenToString(dMinOffsetX, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If Else NotifyPropertyChanged("OffsetX") ' Massimo offset X = If m_InvertKerf < 0 Then Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 48) & " " & LenToString(dMaxOffsetX + m_dKerf, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) Else Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 48) & " " & LenToString(dMaxOffsetX, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If End If End Set End Property Private Sub SetOffsetX(value As Double) m_dOffsetX = value NotifyPropertyChanged("OffsetX") End Sub Private m_OffsetXIsEnabled As Boolean Public Property OffsetXIsEnabled As Boolean Get Return m_OffsetXIsEnabled End Get Set(value As Boolean) If value <> m_OffsetXIsEnabled Then m_OffsetXIsEnabled = value NotifyPropertyChanged("OffsetXIsEnabled") End If End Set End Property Private m_dOffsetY As Double Public Property OffsetY As String Get If m_InvertKerf < 0 Then Return LenToString(m_dOffsetY - m_dKerf, 2) Else Return LenToString(m_dOffsetY, 2) End If End Get Set(value As String) Dim dOffsetY As Double = 0 Dim dMinOffsetY As Double = m_dKerf Dim dMaxOffsetY As Double = m_dTableWidth - m_dWidth - m_dKerf If Not StringToLen(value, dOffsetY) Then Return End If If m_InvertKerf > 0 And dOffsetY > dMinOffsetY - EPS_SMALL And dOffsetY < dMaxOffsetY + EPS_SMALL Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() m_dOffsetY = dOffsetY RecalcRawPart() ElseIf m_InvertKerf < 0 And dOffsetY >= 0 And dOffsetY < dMaxOffsetY + m_dKerf Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() m_dOffsetY = dOffsetY RecalcRawPart() ElseIf dOffsetY <= dMinOffsetY - EPS_SMALL Then NotifyPropertyChanged("OffsetY") ' Minimo offset Y = If m_InvertKerf < 0 Then Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 20) & " " & LenToString(0, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) Else Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 20) & " " & LenToString(dMinOffsetY, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If Else NotifyPropertyChanged("OffsetY") ' Massimo offset Y = If m_InvertKerf < 0 Then Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 49) & " " & LenToString(m_dWidth + m_dKerf, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) Else Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 49) & " " & LenToString(m_dWidth + m_dKerf, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If End If End Set End Property Private Sub SetOffsetY(value As Double) m_dOffsetY = value NotifyPropertyChanged("OffsetY") End Sub Private m_OffsetYIsEnabled As Boolean Public Property OffsetYIsEnabled As Boolean Get Return m_OffsetYIsEnabled End Get Set(value As Boolean) If value <> m_OffsetYIsEnabled Then m_OffsetYIsEnabled = value NotifyPropertyChanged("OffsetYIsEnabled") End If End Set End Property Private m_PrecKerf As Double = 1 Private m_InvertKerf As Double = 1 Public ReadOnly Property InvertKerf As Double Get Return m_InvertKerf End Get End Property Public Sub SetInvertKerf(dvalue As Double) m_InvertKerf = dvalue NotifyPropertyChanged("InvertKerf") End Sub Private m_dKerf As Double Public Property Kerf As String Get Return LenToString(m_dKerf * m_InvertKerf, 2) End Get Set(value As String) Dim dKerf As Double = 0 Dim dMaxKerf As Double = Math.Min(Math.Min(m_dOffsetX, m_dOffsetY), Math.Min(m_dTableLength - m_dLength - m_dOffsetX, m_dTableWidth - m_dWidth - m_dOffsetY)) ' recuper il segno del valore del Kerf precedente Dim dInvertKerf As Double = 1 EgtGetInfo(EgtGetFirstRawPart(), KEY_INVERT_KERF, dInvertKerf) m_PrecKerf = Math.Abs(m_dKerf) m_PrecKerf = m_PrecKerf * dInvertKerf ' carcio di dati della lastra letti da intrfaccia Dim dRawLength, dRawWidth, dRawOffsetX, dRawOffsetY As Double If Not StringToLen(Length, dRawLength) Then Return If Not StringToLen(Width, dRawWidth) Then Return If Not StringToLen(OffsetY, dRawOffsetY) Then Return If Not StringToLen(OffsetX, dRawOffsetX) Then Return Dim dMinKerf = -Math.Min(dRawLength, dRawWidth) / 2 If Not StringToLen(value, dKerf) Then Return End If ' interrompo il processo di caricamento dati se il valore della TexBox è lo stesso della calsse If dKerf * dInvertKerf = m_dKerf Then Return If dKerf >= 0 And dKerf < dMaxKerf + EPS_SMALL Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() If GetRawMode() <> RAWMODE.FROM_PHOTO Then If m_PrecKerf < 0 Then ' definsco la dimensione del grezzo pari a quella del kerf m_dKerf = 0 AdjustRawPartNegativeKerf() UpdateCircles() UpdateRawPartKerf() m_dKerf = dKerf m_PrecKerf = 0 End If ' Specifico che si tratta di un Kerf negativo (per interfaccia grafica) EgtSetInfo(EstCalc.GetRawId(), KEY_INVERT_KERF, 1) SetInvertKerf(1) ' aggiorno il grezzo m_dLength = dRawLength m_dWidth = dRawWidth m_dOffsetX = dRawOffsetX m_dOffsetY = dRawOffsetY m_dKerf = dKerf ' RecalcRawPart() UpdateRawPartKerf() ' Recupero id contorno kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) ' Modifico il colore EgtSetColor(nKerfId, New Color3d(255, 0, 0)) Else CreateRawFromPhotoContour() End If EgtDraw() ElseIf dKerf > dMinKerf - EPS_SMALL And dKerf < 0 Then If GetRawMode() <> RAWMODE.FROM_PHOTO Then ' Specifico che si tratta di un Kerf negativo (per interfaccia grafica) EgtSetInfo(EstCalc.GetRawId(), KEY_INVERT_KERF, -1) SetInvertKerf(-1) ' aggiorno dati grezzo (partendo dalle dimensioni esterne del grezzo) If m_PrecKerf >= 0 Then m_dLength = dRawLength + 2 * dKerf m_dWidth = dRawWidth + 2 * dKerf m_dOffsetX = dRawOffsetX - dKerf m_dOffsetY = dRawOffsetY - dKerf End If m_dKerf = -dKerf If m_PrecKerf >= 0 Then ' definsco la dimensione del grezzo pari a quella del kerf m_dKerf = 0 AdjustRawPartNegativeKerf(False) EgtDraw() UpdateCircles() EgtDraw() UpdateRawPartKerf() EgtDraw() m_dKerf = -dKerf m_PrecKerf = 0 End If If Not AdjustRawPartNegativeKerf() Then ' se fallisce la generazione (TEMPORANEAMENTE) ripristino l'ultimo valore inserito (vedi riga sopra)! m_dKerf = 0 NotifyPropertyChanged("Kerf") End If EgtDraw() UpdateCircles() EgtDraw() ' RecalcRawPart() 'EstCalc.UpdateRawPart() 'UpdateRawPartKerf() ' Recupero id contorno kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) ' Modifico il colore EgtSetColor(nKerfId, New Color3d(255, 128, 0)) Else CreateRawFromPhotoContour() End If EgtDraw() ElseIf dKerf < dMinKerf Then NotifyPropertyChanged("Kerf") ' Minimo kerf = Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 21) & " " & LenToString(dMinKerf, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) Else NotifyPropertyChanged("Kerf") ' Massimo kerf = Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 22) & " " & LenToString(dMaxKerf, 2) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If End Set End Property Private Sub SetKerf(value As Double) m_dKerf = value NotifyPropertyChanged("Kerf") End Sub Private m_KerfIsEnabled As Boolean Public Property KerfIsEnabled As Boolean Get Return m_KerfIsEnabled End Get Set(value As Boolean) If value <> m_KerfIsEnabled Then m_KerfIsEnabled = value NotifyPropertyChanged("KerfIsEnabled") End If End Set End Property #End Region ' Parametri Grezzo Public ReadOnly Property MaterialList As ObservableCollection(Of Material) Get Return CurrentMachine.Materials End Get End Property Public Property SelMaterial As Material Get Return CurrentMachine.CurrMat End Get Set(value As Material) If Not IsNothing(value) Then CurrentMachine.CurrMat = value EstCalc.SetMaterialName() UpdateTabState() OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.NotifyPropertyChanged("MachGroupToolTip") NotifyPropertyChanged("SelMaterial") End If End Set End Property Private m_AddPoint As Boolean Public Property AddPoint As Boolean Get Return m_AddPoint End Get Set(value As Boolean) If value <> m_AddPoint Then If value Then PhotoWithMouse = False m_AddPoint = value Select Case GetRawMode() Case RAWMODE.BY_POINTS m_RemovePoint = False NotifyPropertyChanged("RemovePoint") m_nPtMode = If(m_AddPoint, PTMODE.ADD, PTMODE.MOVE) Case RAWMODE.DAMAGED ' Verifico ci sia almeno una zona rovinata If EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_DAMAGED) = GDB_ID.NULL Then m_AddPoint = False End If m_RemovePoint = False NotifyPropertyChanged("RemovePoint") m_NewDA = False NotifyPropertyChanged("NewDA") m_DeleteDA = False NotifyPropertyChanged("DeleteDA") m_nPtMode = If(m_AddPoint, PTMODE.ADD, PTMODE.MOVE) m_nPtDmgMode = DMGMODE.NONE End Select NotifyPropertyChanged("AddPoint") End If End Set End Property Private m_RemovePoint As Boolean Public Property RemovePoint As Boolean Get Return m_RemovePoint End Get Set(value As Boolean) If value <> m_RemovePoint Then If value Then PhotoWithMouse = False m_RemovePoint = value Select Case GetRawMode() Case RAWMODE.BY_POINTS m_AddPoint = False NotifyPropertyChanged("AddPoint") m_nPtMode = If(m_RemovePoint, PTMODE.REMOVE, PTMODE.MOVE) Case RAWMODE.DAMAGED ' Verifico ci sia almeno una zona rovinata If EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_DAMAGED) = GDB_ID.NULL Then m_RemovePoint = False End If m_AddPoint = False NotifyPropertyChanged("AddPoint") m_NewDA = False NotifyPropertyChanged("NewDA") m_DeleteDA = False NotifyPropertyChanged("DeleteDA") m_nPtMode = If(m_RemovePoint, PTMODE.REMOVE, PTMODE.MOVE) m_nPtDmgMode = DMGMODE.NONE End Select NotifyPropertyChanged("RemovePoint") End If End Set End Property '-------------------- REGISTRATION '-------------------- Private m_AddPointReg As Boolean Public Property AddPointReg As Boolean Get Return m_AddPointReg End Get Set(value As Boolean) If value <> m_AddPointReg Then If value Then PhotoWithMouse = False m_bDrag = False End If m_AddPointReg = value NotifyPropertyChanged("AddPointReg") m_ModPointReg = False NotifyPropertyChanged("ModPointReg") m_RemovePointReg = False NotifyPropertyChanged("RemovePointReg") End If End Set End Property Private m_ModPointReg As Boolean Public Property ModPointReg As Boolean Get Return m_ModPointReg End Get Set(value As Boolean) If value <> m_ModPointReg Then EgtDeselectAll() EgtResetMark(m_nCurrSpotRegId) EgtDraw() If value Then PhotoWithMouse = False End If m_ModPointReg = value NotifyPropertyChanged("ModPointReg") m_AddPointReg = False NotifyPropertyChanged("AddPointReg") m_RemovePointReg = False NotifyPropertyChanged("RemovePointReg") End If End Set End Property Private m_RemovePointReg As Boolean Public Property RemovePointReg As Boolean Get Return m_RemovePointReg End Get Set(value As Boolean) If value <> m_RemovePointReg Then If value Then PhotoWithMouse = False m_bDrag = False End If m_RemovePointReg = value NotifyPropertyChanged("RemovePointReg") m_AddPointReg = False NotifyPropertyChanged("AddPointReg") m_ModPointReg = False NotifyPropertyChanged("ModPointReg") End If End Set End Property '-------------------- REGISTRATION '-------------------- Private m_PointsVisibility As Visibility Public Property PointsVisibility As Visibility Get Return m_PointsVisibility End Get Set(value As Visibility) If value <> m_PointsVisibility Then m_PointsVisibility = value NotifyPropertyChanged("PointsVisibility") End If End Set End Property Private m_NewDA As Boolean Public Property NewDA As Boolean Get Return m_NewDA End Get Set(value As Boolean) If value <> m_NewDA Then m_NewDA = value NotifyPropertyChanged("NewDA") m_nPtDmgMode = If(m_NewDA, DMGMODE.ADD, DMGMODE.NONE) m_DeleteDA = False NotifyPropertyChanged("DeleteDA") m_AddPoint = False NotifyPropertyChanged("AddPoint") m_RemovePoint = False NotifyPropertyChanged("RemovePoint") End If End Set End Property Private m_DeleteDA As Boolean Public Property DeleteDA As Boolean Get Return m_DeleteDA End Get Set(value As Boolean) If value <> m_DeleteDA Then m_DeleteDA = value ' Verifico ci sia almeno una zona rovinata If EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_DAMAGED) = GDB_ID.NULL Then m_DeleteDA = False End If NotifyPropertyChanged("DeleteDA") m_nPtDmgMode = If(m_DeleteDA, DMGMODE.REMOVE, DMGMODE.NONE) m_NewDA = False NotifyPropertyChanged("NewDA") m_AddPoint = False NotifyPropertyChanged("AddPoint") m_RemovePoint = False NotifyPropertyChanged("RemovePoint") End If End Set End Property Private m_DAVisibility As Visibility Public Property DAVisibility As Visibility Get Return m_DAVisibility End Get Set(value As Visibility) If value <> m_DAVisibility Then m_DAVisibility = value NotifyPropertyChanged("DAVisibility") End If End Set End Property Private m_ConfirmPhotoVisibility As Visibility Public Property ConfirmPhotoVisibility As Visibility Get Return m_ConfirmPhotoVisibility End Get Set(value As Visibility) If value <> m_ConfirmPhotoVisibility Then m_ConfirmPhotoVisibility = value NotifyPropertyChanged("ConfirmPhotoVisibility") End If End Set End Property Private m_CurrMach_Background As Brush = DirectCast(New BrushConverter().ConvertFrom("#1C1D22"), SolidColorBrush) Public Property CurrMach_Background As Brush Get Return m_CurrMach_Background End Get Set(value As Brush) m_CurrMach_Background = value NotifyPropertyChanged("CurrMach_Background") End Set End Property Private m_MaterialFromDB As String = String.Empty Public ReadOnly Property MaterialFromDB As String Get Return m_MaterialFromDB End Get End Property Public Sub SetMaterialFromDB(sMaterial As String) m_MaterialFromDB = sMaterial If Not String.IsNullOrEmpty(m_MaterialFromDB) Then 'EstCalc.SetMaterialPhoto(m_MaterialFromDB) SetVisibilityMaterialFromDB(Visibility.Visible) Else SetVisibilityMaterialFromDB(Visibility.Collapsed) End If NotifyPropertyChanged("MaterialFromDB") End Sub Private m_VisibilityMaterialFromDB As Visibility = Visibility.Collapsed Public ReadOnly Property VisibilityMaterialFromDB As Visibility Get Return m_VisibilityMaterialFromDB End Get End Property Public Sub SetVisibilityMaterialFromDB(VisibilityMaterial As Visibility) m_VisibilityMaterialFromDB = VisibilityMaterial NotifyPropertyChanged("VisibilityMaterialFromDB") End Sub #Region "Messages" Public ReadOnly Property PhotoRotMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 0) End Get End Property Public ReadOnly Property OutlineMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 33) End Get End Property Public ReadOnly Property DamagedAreaMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 10) End Get End Property Public ReadOnly Property LengthMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 3) End Get End Property Public ReadOnly Property WidthMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 4) End Get End Property Public ReadOnly Property HeightMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 5) End Get End Property Public ReadOnly Property OffsetXMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 6) End Get End Property Public ReadOnly Property OffsetYMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 7) End Get End Property Public ReadOnly Property KerfMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 8) End Get End Property Public ReadOnly Property MaterialMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 9) End Get End Property Public ReadOnly Property PointsMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 13) End Get End Property Public ReadOnly Property AddMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 14) End Get End Property Public ReadOnly Property RemoveMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 15) End Get End Property Public ReadOnly Property ModMsg As String Get Return EgtMsg(91668) End Get End Property Public ReadOnly Property NewMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 11) End Get End Property Public ReadOnly Property DeleteMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 12) End Get End Property Public ReadOnly Property ConfirmPhotoMsg As String Get Return EgtMsg(MSG_RAWPARTPAGEUC + 24) End Get End Property Public ReadOnly Property CurrMachMsg As String Get Return EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 9) End Get End Property Public ReadOnly Property PointsRegMsg As String Get Return EgtMsg(91669) End Get End Property #End Region ' Messages #Region "ToolTip" Public ReadOnly Property PhotoToolTip As String Get Return EgtMsg(MSG_RAWPARTTAB + 2) End Get End Property Public ReadOnly Property MovePhotoToolTip As String Get Return EgtMsg(MSG_RAWPARTTAB + 3) End Get End Property #End Region ' ToolTip ' Definizione comandi Private m_cmdCurrMach As ICommand Private m_cmdSlabId As ICommand Private m_cmdPhoto As ICommand Private m_cmdConfirmPhoto As ICommand #End Region ' FIELDS & PROPERTIES #Region "CONSTRUCTOR" Sub New() ' Creo riferimento a questa classe in OmagOFFICEMap OmagOFFICEMap.SetRefRawPartTabVM(Me) If OmagOFFICEMap.refMainWindowVM.MainWindowM.m_SlabDB Then ' Me.OmagPhoto = New OmagPhotoV(Application.Current.MainWindow()) Me.OmagPhoto = New OmagPhotoV If Not PhotoMap.ContinueApplication Then EgtOutLog("Key protection denied to acces to DB photo, set configuration to image directory") End End If End If ' Aggiungo voci alla lista di tipi di definizione grezzo m_TypeList.Add(EgtMsg(MSG_RAWPARTPAGEUC + 1)) m_TypeList.Add(EgtMsg(MSG_RAWPARTPAGEUC + 2)) End Sub #End Region ' CONSTRUCTOR #Region "METHODS" Friend Function InitRawPart() As Boolean EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx()) ' Se abilitati, visualizzo bottone per dati lastra Dim bSlabId As Boolean = (GetMainPrivateProfileInt(S_RAWPART, K_SLABID, 0) <> 0) SlabIdVisibility = If(bSlabId, Windows.Visibility.Visible, Windows.Visibility.Hidden) ' Se disponibile, imposto possibilità di contorno da foto If EstPhoto.GetContour() = GDB_ID.NULL Then If m_TypeList.Count = 3 Then m_TypeList.RemoveAt(2) Else If m_TypeList.Count = 2 Then m_TypeList.Add(EgtMsg(MSG_RAWPARTPAGEUC + 35)) End If ' Colori standard GetMainPrivateProfileColor(S_RAWPART, K_RAWCOLOR, m_RawCol) GetMainPrivateProfileColor(S_RAWPART, K_KERFCOLOR, m_KerfCol) ' Dimensioni tavola Dim ptMin, ptMax As Point3d If EgtGetTableArea(1, ptMin, ptMax) Then m_ptTableMin = ptMin m_dTableLength = ptMax.x - ptMin.x m_dTableWidth = ptMax.y - ptMin.y End If ' Origine tavola Dim ptRef1 As Point3d If EgtGetTableRef(1, ptRef1) Then If Not Point3d.SameApprox(m_ptTableMin, ptRef1) Then EgtOutLog("Error : TableMin e TableRef1 are different") End If End If ' Assegno identificativo del grezzo EstCalc.UpdateRawPart() ' Nascondo eventuali pezzi in parcheggio EstCalc.HideParkedParts() ' Deseleziono pezzi EgtDeselectAll() VeinMatching.OnDeselectAll() ' Visualizzo eventuale foto ShowPhoto(True) ' Se esiste già il grezzo... If EstCalc.GetRawId() <> GDB_ID.NULL Then ' dimensioni del grezzo Dim ptRawMin As Point3d = GetRawPtMin() Dim ptRawMax As Point3d = GetRawPtMax() ' kerf Dim dTmp As Double = 0 Dim dInvertKerf As Double = 1 EgtGetInfo(EgtGetFirstRawPart(), KEY_KERF, dTmp) SetKerf(dTmp) ' aggiorno dati grezzo m_dLength = ptRawMax.x - ptRawMin.x - 2 * m_dKerf m_dWidth = ptRawMax.y - ptRawMin.y - 2 * m_dKerf * dInvertKerf m_dHeight = ptRawMax.z - ptRawMin.z m_dOffsetX = ptRawMin.x - m_ptTableMin.x + m_dKerf * dInvertKerf m_dOffsetY = ptRawMin.y - m_ptTableMin.y + m_dKerf * dInvertKerf ' verifico se il kerf è negativo EgtGetInfo(EgtGetFirstRawPart(), KEY_INVERT_KERF, dInvertKerf) SetInvertKerf(dInvertKerf) ' aggiorno i dati della grafica NotifyPropertyChanged("Length") NotifyPropertyChanged("Width") NotifyPropertyChanged("OffsetX") NotifyPropertyChanged("OffsetY") NotifyPropertyChanged("Height") NotifyPropertyChanged("Kerf") ' aggiorno offset e rotazione foto Dim dPhotoOffsetX, dPhotoOffsetY, dPhotoRot As Double GetPhotoOffsetRot(dPhotoOffsetX, dPhotoOffsetY, dPhotoRot) SetPhotoOffsetX(dPhotoOffsetX) SetPhotoOffsetY(dPhotoOffsetY) SetPhotoRot(dPhotoRot) ' aggiorno l'apparenza del grezzo AdjustRawPartOnStart() ' Altrimenti lo definisco Else ' Leggo da Ini gli ultimi valori e li rendo compatibili con le dimensioni della tavola CreateNewRawFromIniData() ' Imposto spessore lastra EstCalc.SetSlabHeight(m_dHeight) OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.NotifyPropertyChanged("MachGroupToolTip") ' Annullo offset e rotazione foto SetPhotoOffsetX(0) SetPhotoOffsetY(0) SetPhotoRot(0) ' Richiedo ricalcolo quota eventuale foto RecalcRawPart(True) End If ' Abilitazione eventuale bottone per dati slab SlabIdIsEnabled = (EstCalc.GetRawId() <> GDB_ID.NULL) ' Creo layer temporaneo per crocette m_nTempLay = EgtCreateGroup(GDB_ID.ROOT) EgtSetLevel(m_nTempLay, GDB_LV.TEMP) ' Veroifico se esiste il gruppo "REG" Dim nIdRaws As Integer = EgtGetParent(EstCalc.GetRawId()) Dim nIdReg As Integer = EgtGetFirstNameInGroup(EgtGetParent(nIdRaws), "Reg") If nIdReg <> GDB_ID.NULL Then m_nRegGroupId = nIdReg EgtGetInfo(m_nRegGroupId, COUNTSPOT, m_nCountSpot) ' Lo rendo visibile EgtSetStatus(m_nRegGroupId, GDB_ST.ON_) Else ' Creo layer per definire i punti di REG m_nRegGroupId = EgtCreateGroup(EgtGetParent(nIdRaws)) EgtSetName(m_nRegGroupId, REG) m_nCountSpot = 0 End If ' Determino modalità di definizione OutlineIsChecked = True If EgtExistsInfo(EstCalc.GetRawId(), KEY_RAWBYPOINTS) Then SelType = Type.BY_POINTS NotifyPropertyChanged("SelType") PointsVisibility = Visibility.Visible AdjustRawPartPosition() ' Visualizzo crocette UpdateCircles() Else m_SelType = Type.RECTANGLE NotifyPropertyChanged("SelType") PointsVisibility = Visibility.Collapsed AdjustRawPartPosition() End If EgtZoom(ZM.ALL) DAVisibility = Visibility.Collapsed ' Imposto il materiale corrente nella combobox NotifyPropertyChanged("SelMaterial") Return True End Function Private Sub CreateNewRawFromIniData() ' Recupero i dati dal file Ini Dim dRawLen As Double = GetMainPrivateProfileDouble(S_RAWPART, K_RAWLENGTH, 2500) Dim dRawWidth As Double = GetMainPrivateProfileDouble(S_RAWPART, K_RAWWIDTH, 1500) Dim dRawHeight As Double = GetMainPrivateProfileDouble(S_RAWPART, K_RAWHEIGHT, 30) Dim dRawOffsX As Double = GetMainPrivateProfileDouble(S_RAWPART, K_RAWOFFSX, 100) Dim dRawOffsY As Double = GetMainPrivateProfileDouble(S_RAWPART, K_RAWOFFSY, 100) Dim dRawKerf As Double = GetMainPrivateProfileDouble(S_RAWPART, K_RAWKERF, 50) ' Eseguo i controlli If dRawKerf < 0 Then dRawKerf = 0 ElseIf dRawKerf > Math.Min(m_dTableLength, m_dTableWidth) / 5 Then dRawKerf = Math.Min(m_dTableLength, m_dTableWidth) / 5 End If ' assegno il valore del Kerf corrente m_PrecKerf = dRawKerf If dRawLen < 0 Then dRawLen = 100 ElseIf dRawLen > m_dTableLength - 2 * dRawKerf Then dRawLen = m_dTableLength - 2 * dRawKerf End If If dRawWidth < 0 Then dRawWidth = 100 ElseIf dRawWidth > m_dTableWidth - 2 * dRawKerf Then dRawWidth = m_dTableWidth - 2 * dRawKerf End If If dRawOffsX < dRawKerf Then dRawOffsX = dRawKerf If dRawOffsX + dRawLen + 2 * dRawKerf > m_dTableLength Then dRawOffsX = Math.Max(dRawKerf, m_dTableLength - dRawLen - 2 * dRawKerf) dRawLen = Math.Min(dRawLen, m_dTableLength - dRawOffsX - 2 * dRawKerf) End If If dRawOffsY < dRawKerf Then dRawOffsY = dRawKerf If dRawOffsY + dRawWidth + 2 * dRawKerf > m_dTableWidth Then dRawOffsY = Math.Max(dRawKerf, m_dTableWidth - dRawWidth - 2 * dRawKerf) dRawWidth = Math.Min(dRawWidth, m_dTableWidth - dRawOffsY - 2 * dRawKerf) End If ' Assegno i dati SetLength(dRawLen) SetWidth(dRawWidth) SetHeight(dRawHeight) SetOffsetX(dRawOffsX) SetOffsetY(dRawOffsY) SetKerf(dRawKerf) End Sub Friend Function ExitRawPart() As Boolean ' Sistemo il grezzo AdjustRawPartOnExit() ' Rimuovo layer temporaneo per crocette EgtErase(m_nTempLay) ' Rimuovo eventuale contorno del grezzo non utilizzato EstPhoto.RemoveContour() ' Salvo nel file Ini le dimensioni del grezzo (sempre in mm) WriteMainPrivateProfileString(S_RAWPART, K_RAWLENGTH, DoubleToString(m_dLength, 2)) WriteMainPrivateProfileString(S_RAWPART, K_RAWWIDTH, DoubleToString(m_dWidth, 2)) WriteMainPrivateProfileString(S_RAWPART, K_RAWHEIGHT, DoubleToString(m_dHeight, 2)) WriteMainPrivateProfileString(S_RAWPART, K_RAWOFFSX, DoubleToString(m_dOffsetX, 2)) WriteMainPrivateProfileString(S_RAWPART, K_RAWOFFSY, DoubleToString(m_dOffsetY, 2)) WriteMainPrivateProfileString(S_RAWPART, K_RAWKERF, DoubleToString(m_dKerf, 2)) ' Nascondo il gruppo dei punti Reg EgtSetStatus(m_nRegGroupId, GDB_ST.OFF) ' Se ci sono pezzi nel grezzo If EgtGetFirstPartInRawPart(EstCalc.GetRawId()) <> GDB_ID.NULL Then ' Cancello tutte le lavorazioni CamAuto.EraseMachinings(GDB_ID.NULL) ' Reinserisco tutte le lavorazioni piane CamAuto.AddMachinings(GDB_ID.NULL) ' Aggiorno regioni per nesting EstCalc.UpdateNestRegions() EstCalc.EnableReferenceRegion(False) ' Visualizzo i pezzi parcheggiati (per inserire correttamente in parcheggio i pezzi del grezzo) EstCalc.ShowParkedParts() ' Verifico ogni singolo pezzo Dim nPartId As Integer = EgtGetFirstPartInRawPart(EstCalc.GetRawId()) While nPartId <> GDB_ID.NULL Dim nNextPartId = EgtGetNextPartInRawPart(nPartId) If Not EgtVerifyPart(nPartId, CurrentMachine.bReducedCut) Then EstCalc.StoreOnePart(nPartId) VeinMatching.OnRemovePartFromRaw(nPartId) End If nPartId = nNextPartId End While ' Nascondo i pezzi parcheggiati EstCalc.HideParkedParts() End If ' Disabiliti movimento foto con mouse PhotoWithMouse = False Return True End Function Private Function GetRawMode() As RAWMODE Select Case m_SelType Case Type.RECTANGLE Return RAWMODE.RECTANGLE Case Type.BY_POINTS If m_OutlineIsChecked Then Return RAWMODE.BY_POINTS Else Return RAWMODE.DAMAGED End If Case Type.FROM_PHOTO Return RAWMODE.FROM_PHOTO End Select Return RAWMODE.RECTANGLE End Function Private Sub RawModeView() Select Case GetRawMode() Case RAWMODE.RECTANGLE TypeIsEnabled = True LengthIsEnabled = True WidthIsEnabled = True HeightIsEnabled = True OffsetXIsEnabled = True OffsetYIsEnabled = True KerfIsEnabled = True ' Nascondo bottoni per disegno PointsVisibility = Visibility.Collapsed ' Disattivo bottoni zone rovinate e conferma contorno da foto DAVisibility = Visibility.Collapsed ConfirmPhotoVisibility = Visibility.Collapsed Case RAWMODE.BY_POINTS TypeIsEnabled = True LengthIsEnabled = False WidthIsEnabled = False HeightIsEnabled = True OffsetXIsEnabled = False OffsetYIsEnabled = False KerfIsEnabled = True ' Visualizzo bottoni per disegno PointsVisibility = Visibility.Visible ' Disattivo bottoni zone rovinate e conferma contorno da foto DAVisibility = Visibility.Collapsed ConfirmPhotoVisibility = Visibility.Collapsed Case RAWMODE.DAMAGED TypeIsEnabled = False LengthIsEnabled = False WidthIsEnabled = False HeightIsEnabled = False OffsetXIsEnabled = False OffsetYIsEnabled = False KerfIsEnabled = False ' Visualizzo bottoni per disegno PointsVisibility = Visibility.Visible ' Attivo bottoni zone rovinate DAVisibility = Visibility.Visible ' Disattivo bottone conferma contorno da foto ConfirmPhotoVisibility = Visibility.Collapsed Case RAWMODE.FROM_PHOTO TypeIsEnabled = True LengthIsEnabled = False WidthIsEnabled = False HeightIsEnabled = True OffsetXIsEnabled = False OffsetYIsEnabled = False KerfIsEnabled = True ' Nascondo bottoni per punti e zone rovinate PointsVisibility = Visibility.Collapsed DAVisibility = Visibility.Collapsed ' Visualizzo bottone conferma contorno da foto ConfirmPhotoVisibility = Visibility.Visible End Select End Sub Private Sub RecalcRawPart(Optional bHeightModified As Boolean = False) ' Se cambiato spessore e c'è foto, aggiorno quota fotografia If bHeightModified And GetPhoto() <> GDB_ID.NULL Then ' Ricarico fotografia EstPhoto.UpdatePhoto() ' Aggiorno eventuale contorno da foto EstPhoto.UpdateContour() End If ' Recupero il colore (con la foto lo rendo molto più trasparente) Dim Col = m_RawCol ' in presenza di foto rendo molto più trasparente If GetPhoto() <> GDB_ID.NULL Then Col.A = 20 ' Se non esiste già il grezzo e richiesto, lo inserisco Dim nRawId As Integer = EstCalc.GetRawId() If nRawId = GDB_ID.NULL And m_dHeight > EPS_SMALL Then EgtAddRawPart(Point3d.ORIG(), m_dLength + 2 * m_dKerf, m_dWidth + 2 * m_dKerf, m_dHeight, Col) ' se esiste e da cancellare ElseIf m_dHeight < EPS_SMALL Then EgtRemoveRawPart(nRawId) ' Altrimenti lo modifico Else EgtModifyRawPart(nRawId, Point3d.ORIG(), m_dLength + 2 * m_dKerf, m_dWidth + 2 * m_dKerf, m_dHeight, Col) End If ' Se il grezzo esistente If EstCalc.UpdateRawPart() Then AdjustRawPartKerf() ' Sistemo la posizione AdjustRawPartPosition() End If ' Abilitazione eventuale bottone per dati slab SlabIdIsEnabled = (EstCalc.GetRawId() <> GDB_ID.NULL) ' Aggiorno visualizzazione EgtDraw() End Sub Private Function AdjustRawPartPosition() As Boolean Dim ptRef As New Point3d(m_dOffsetX - m_dKerf, m_dOffsetY - m_dKerf, CurrentMachine.dAdditionalTable) If EgtMoveToCornerRawPart(EstCalc.GetRawId(), ptRef, MCH_CR.BL) Then EstCalc.UpdateRawPart() OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() Return True Else ' tento di portare la lastra tutta dentro la tavola Dim bOk As Boolean = EgtMoveToCornerRawPart(EstCalc.GetRawId(), Point3d.ORIG(), MCH_CR.BL) ' aggiorno posizione e offset If EstCalc.UpdateRawPart() Then Dim ptMin As Point3d = GetRawPtMin() m_dOffsetX = ptMin.x - m_ptTableMin.x + m_dKerf m_dOffsetY = ptMin.y - m_ptTableMin.y + m_dKerf NotifyPropertyChanged("OffsetX") NotifyPropertyChanged("OffsetY") End If 'Errore nella posizione o dimensione del grezzo Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 47) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) Return bOk End If End Function Private Function AdjustRawPartKerf() As Boolean ' Se non c'è il grezzo, esco If EstCalc.GetRawId() = GDB_ID.NULL Then Return False ' Cancello eventuale vecchio contorno di kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) EgtErase(nKerfId) ' box grezzo Dim ptMin As Point3d = GetRawPtMin() Dim ptMax As Point3d = GetRawPtMax() ptMin.x += m_dKerf ptMin.y += m_dKerf ptMin.z = ptMax.z ptMax.x -= m_dKerf ptMax.y -= m_dKerf ' Creo il nuovo contorno del kerf nKerfId = EgtCreateRectangle2P(EstCalc.GetRawId(), ptMin, ptMax, GDB_RT.GLOB) EgtSetName(nKerfId, NAME_KERF) EgtSetColor(nKerfId, m_KerfCol) ' Salvo il valore del kerf (sempre in mm) EgtSetInfo(EstCalc.GetRawId(), KEY_KERF, m_dKerf) Return True End Function ' -------------------------------- INIZIO Nuove funzioni per la gestione del Kerf negativo -------------------------------- Private Function AdjustRawPartNegativeKerf(Optional NegativeOffset As Boolean = True) As Boolean ' Se non c'è il grezzo, esco If EstCalc.GetRawId() = GDB_ID.NULL Then Return False ' Cancello eventuale vecchio contorno di kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) Dim nInvert As Double = 1 If Not NegativeOffset Then nInvert = -1 End If Dim dOffset As Double = (-m_dKerf - m_PrecKerf) * nInvert Dim nCount As Integer = 0 Dim bOK As Boolean = EgtOffsetCurve(nKerfId, dOffset, OFF_TYPE.EXTEND) EgtSetColor(nKerfId, m_KerfCol) ' ------ Gestione corretta dei kerf ------ 'Dim nNewKerfId As Integer = EgtOffsetCurveAdv(nKerfId, dOffset, OFF_TYPE.EXTEND, nCount) 'EgtSetColor(nNewKerfId, m_KerfCol) 'EgtSetName(nNewKerfId, "Kerf") 'EgtErase(nKerfId) '----------------------------------------- ' Salvo il valore del kerf (sempre in mm) EgtSetInfo(EstCalc.GetRawId(), KEY_KERF, m_dKerf) Return bOK End Function Private Function AdjustRawPartPositionNegativeKerf() As Boolean ' Sistemo la posizione Dim ptRef As New Point3d(m_dOffsetX, m_dOffsetY, CurrentMachine.dAdditionalTable) If EgtMoveToCornerRawPart(EstCalc.GetRawId(), ptRef, MCH_CR.BL) Then ' Parametro ereditato da OmagCUT ' OkBtn.IsEnabled = True OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() Else ' OkBtn.IsEnabled = False Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 47) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) ' Errore nella posizione o dimensione del grezzo End If ' Aggiorno visualizzazione EgtZoom(ZM.ALL) Return True End Function ' -------------------------------- FINE Nuove funzioni per la gestione del Kerf negativo -------------------------------- Private Sub UpdateRawPartHeight() ' Se da creare If EstCalc.GetRawId() = GDB_ID.NULL Then RecalcRawPart(True) Return ' se da cancellare ElseIf m_dHeight < EPS_SMALL Then ' Se ci sono pezzi If EgtGetFirstPartInRawPart(EstCalc.GetRawId()) <> GDB_ID.NULL Then ' Visualizzo i pezzi parcheggiati (per inserire correttamente in parcheggio i pezzi del grezzo) EstCalc.ShowParkedParts() ' Parcheggio pezzi presenti nel grezzo e li tolgo da VeinMatcing Dim nPartId As Integer = EgtGetFirstPartInRawPart(EstCalc.GetRawId()) While nPartId <> GDB_ID.NULL Dim nNextPartId As Integer = EgtGetNextPartInRawPart(nPartId) EstCalc.StoreOnePart(nPartId) VeinMatching.OnRemovePartFromRaw(nPartId) nPartId = nNextPartId End While ' Cancello tutte le lavorazioni CamAuto.EraseMachinings(GDB_ID.NULL) ' Nascondo i pezzi parcheggiati EstCalc.HideParkedParts() End If ' Elimino il grezzo EgtRemoveRawPart(EstCalc.GetRawId()) ' altrimenti da aggiornare Else ' Salvo vecchia altezza Dim dOldHeight As Double = EstCalc.GetRawHeight() ' Aggiorno solido EgtModifyRawPartHeight(EstCalc.GetRawId(), m_dHeight) ' Vettore spostamento Dim vtMove As New Vector3d(0, 0, m_dHeight - dOldHeight) ' Aggiorno quota kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) If nKerfId <> GDB_ID.NULL Then EgtMove(nKerfId, vtMove) End If ' Se ci sono pezzi ne aggiorno la quota Dim nPartId As Integer = EgtGetFirstPartInRawPart(EstCalc.GetRawId()) While nPartId <> GDB_ID.NULL EgtMovePartInRawPart(nPartId, vtMove) nPartId = EgtGetNextPartInRawPart(nPartId) End While ' aggiorno la posizione dei cerchi del Kerf UpdateCircles() ' Aggiorno la posizione della zona rovinata UpdateDemageArea(vtMove) End If ' aggiorno l'Id del grezzo EstCalc.UpdateRawPart() ' Se c'è foto, aggiorno quota fotografia If GetPhoto() <> GDB_ID.NULL Then ' Ricarico fotografia EstPhoto.UpdatePhoto() ' Aggiorno eventuale contorno da foto EstPhoto.UpdateContour() End If ' Abilitazione eventuale bottone per dati slab SlabIdIsEnabled = (EstCalc.GetRawId() <> GDB_ID.NULL) ' Aggiorno visualizzazione EgtDraw() End Sub Private Sub UpdateRawPartKerf(Optional bDraw As Boolean = True) ' Se non c'è il grezzo, esco If EstCalc.GetRawId() = GDB_ID.NULL Then Return ' Recupero percorso di contorno kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) ' Recupero colore grezzo ( in presenza di foto rendo molto più trasparente) Dim Col = m_RawCol If GetPhoto() <> GDB_ID.NULL Then Col.A = 20 ' Aggiorno il grezzo Dim x As Boolean = EgtModifyRawPart(EstCalc.GetRawId(), nKerfId, m_dKerf, m_ptTableMin.z, m_dHeight, Col) ' Salvo il nuovo valore (sempre in mm) EgtSetInfo(EstCalc.GetRawId(), KEY_KERF, m_dKerf) ' Aggiorno dimensioni e posizione grezzo UpdateRawXYData() ' Aggiorno visualizzazione If bDraw Then EgtDraw() End Sub Private Sub UpdateRawXYData() ' Aggiorno i dati del grezzo EstCalc.UpdateRawPart() ' Aggiorno dimensioni grezzo nel piano XY If EstCalc.GetRawId() <> GDB_ID.NULL Then ' aggiorno dati grezzo m_dLength = EstCalc.GetRawLength() - 2 * m_dKerf m_dWidth = EstCalc.GetRawWidth() - 2 * m_dKerf m_dOffsetX = EstCalc.GetRawPtMin().x + m_dKerf - m_ptTableMin.x m_dOffsetY = EstCalc.GetRawPtMin().y + m_dKerf - m_ptTableMin.y 'If m_InvertKerf < 0 Then ' SetLength(m_dLength + 2 * m_dKerf) ' SetWidth(m_dWidth + 2 * m_dKerf) ' SetOffsetX(m_dOffsetX - m_dKerf) ' SetOffsetY(m_dOffsetY - m_dKerf) ' RecalcRawPart() 'Else ' SetLength(m_dLength) ' SetWidth(m_dWidth) ' SetOffsetX(m_dOffsetX) ' SetOffsetY(m_dOffsetY) ' RecalcRawPart() 'End If ' Assegno dati grezzo rettangolare ai textbox NotifyPropertyChanged("Length") NotifyPropertyChanged("Width") NotifyPropertyChanged("OffsetX") NotifyPropertyChanged("OffsetY") End If ' Aggiorno la posizione del grezzo Dim ptRef As New Point3d(m_dOffsetX - m_dKerf, m_dOffsetY - m_dKerf, CurrentMachine.dAdditionalTable) If EgtMoveToCornerRawPart(EstCalc.GetRawId(), ptRef, MCH_CR.BL) Then EstCalc.UpdateRawPart() OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() Else EstCalc.UpdateRawPart() 'Errore nella posizione o dimensione del grezzo Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 47) OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sMsg, 3, MSG_TYPE.ERROR_) End If End Sub Private Sub UpdateDemageArea(vtMove As Vector3d) Dim nId As Integer = GDB_ID.NULL nId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_DAMAGED) While nId <> GDB_ID.NULL EgtMove(nId, vtMove) nId = EgtGetNext(nId) End While End Sub Private Sub ModifyPhoto(vtMove As Vector3d) ' Non ci deve essere movimento in Z vtMove.z = 0 ' In presenza di contorno, verifico non esca dalla tavola Dim nCrvId As Integer = EstPhoto.GetContour() If nCrvId <> GDB_ID.NULL Then Dim b3Crv As New BBox3d EgtGetBBoxGlob(nCrvId, GDB_BB.STANDARD, b3Crv) b3Crv.Move(vtMove) If b3Crv.Min().x < m_ptTableMin.x + 10 * EPS_SMALL Then vtMove.x += m_ptTableMin.x + 10 * EPS_SMALL - b3Crv.Min().x ElseIf b3Crv.Max().x > m_ptTableMin.x + m_dTableLength + 10 * EPS_SMALL Then vtMove.x += m_ptTableMin.x + m_dTableLength - 10 * EPS_SMALL - b3Crv.Max().x End If If b3Crv.Min().y < m_ptTableMin.y + 10 * EPS_SMALL Then vtMove.y += m_ptTableMin.y + 10 * EPS_SMALL - b3Crv.Min().y ElseIf b3Crv.Max().y > m_ptTableMin.y + m_dTableWidth + 10 * EPS_SMALL Then vtMove.y += m_ptTableMin.y + m_dTableWidth - 10 * EPS_SMALL - b3Crv.Max().y End If End If ' Muovo eventuale grezzo ed eventuali cerchietti Dim nRawId As Integer = EstCalc.GetRawId() If nRawId <> GDB_ID.NULL Then If Not EgtMoveRawPart(EstCalc.GetRawId(), vtMove) Then Return ' Imposto posizione esatta del grezzo dopo movimento Dim b3Raw As New BBox3d EgtGetRawPartBBox(nRawId, b3Raw) If EgtMoveToCornerRawPart(nRawId, (b3Raw.Min() - m_ptTableMin) + Point3d.ORIG(), MCH_CR.BL) Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() End If ' Muovo eventuali cerchietti alle estremità della curva di contorno MoveCircles(vtMove) End If ' Muovo eventuali punti SpotReg If m_nRegGroupId <> GDB_ID.NULL Then MoveAllSpotRegistration(vtMove) End If ' Incremento opportunamente l'offset della fotografia Dim dPhotoOffsetX As Double = m_dPhotoOffsetX + vtMove.x Dim dPhotoOffsetY As Double = m_dPhotoOffsetY + vtMove.y EstPhoto.ChangeOffsetPhoto(dPhotoOffsetX, dPhotoOffsetY) ' Muovo eventuale contorno If nCrvId <> GDB_ID.NULL Then EgtMove(nCrvId, vtMove, GDB_RT.GLOB) ' Aggiorno interfaccia SetPhotoOffsetX(dPhotoOffsetX) SetPhotoOffsetY(dPhotoOffsetY) ' Aggiorno dimensioni e posizione grezzo UpdateRawXYData() ' Aggiorno visualizzazione EgtDraw() End Sub Private Sub ModifyPhoto(dRotAngDeg As Double) ' Recupero il grezzo e il suo centro Dim nRawId As Integer = EstCalc.GetRawId() Dim ptCent As New Point3d If Not EgtGetRawPartCenter(nRawId, ptCent) Then ptCent = m_ptTableMin + New Vector3d(m_dTableLength / 2, m_dTableWidth / 2, 0) End If ' Recupero eventuale contorno Dim nCrvId As Integer = EstPhoto.GetContour() ' Ruoto eventuale grezzo ed eventuali cerchietti If nRawId <> GDB_ID.NULL Then ' Eseguo rotazione complessiva di controllo If Not EgtRotateRawPart(nRawId, Vector3d.Z_AX(), dRotAngDeg) Then Return ' Annullo rotazione complessiva ed eseguo rotazione degli oggetti contenuti nel grezzo EgtRotateRawPart(nRawId, Vector3d.Z_AX(), -dRotAngDeg) Dim nId As Integer = EgtGetFirstInGroup(nRawId) While nId <> GDB_ID.NULL EgtRotate(nId, ptCent, Vector3d.Z_AX(), dRotAngDeg, GDB_RT.GLOB) nId = EgtGetNext(nId) End While ' Imposto posizione esatta del grezzo dopo rotazione Dim b3Raw As New BBox3d EgtGetRawPartBBox(nRawId, b3Raw) If EgtMoveToCornerRawPart(nRawId, (b3Raw.Min() - m_ptTableMin) + Point3d.ORIG(), MCH_CR.BL) Then OmagOFFICEMap.refStatusBarVM.ClearOutputMessage() End If ' Ruoto eventuali cerchietti alle estremità della curva di contorno RotateCircles(ptCent, Vector3d.Z_AX(), dRotAngDeg) End If ' Incremento opportunamente la rotazione della fotografia Dim dPhotoRot As Double = m_dPhotoRot + dRotAngDeg EstPhoto.ChangeRotationPhoto(ptCent, dPhotoRot) ' Ruoto eventuale contorno If nCrvId <> GDB_ID.NULL Then EgtRotate(nCrvId, ptCent, Vector3d.Z_AX(), dRotAngDeg, GDB_RT.GLOB) ' Aggiorno interfaccia SetPhotoRot(dPhotoRot) ' Aggiorno dimensioni e posizione grezzo UpdateRawXYData() ' Aggiorno visualizzazione EgtDraw() End Sub Private Function CreateRawFromPhotoContour() As Boolean ' Calcolo offset interno di kerf dal contorno riconosciuto nella fotografia Dim nCount As Integer = 0 Dim nKerfId As Integer = EgtOffsetCurveAdv(EstPhoto.GetContour(), -m_dKerf, OFF_TYPE.EXTEND, nCount) Dim nSiCnt As Integer = 0 If nKerfId = GDB_ID.NULL OrElse Not EgtCurveIsClosed(nKerfId) OrElse (Not EgtCurveSelfIntersCount(nKerfId, nSiCnt) OrElse nSiCnt > 0) Then EgtOutLog("Error on RawPart from Photo Contour") ' Creo un rettangolo, se possibile Dim nParentId As Integer = EgtGetParent(EstPhoto.GetContour()) Dim b3Crv As New BBox3d If EgtGetBBox(EstPhoto.GetContour(), GDB_BB.STANDARD, b3Crv) Then nKerfId = EgtCreateRectangle2P(nParentId, b3Crv.Min(), b3Crv.Max(), GDB_RT.LOC) nCount = 1 Else Return False End If End If ' Cancello eventuali curve risultato dell'offset oltre la prima For i = 1 To nCount - 1 EgtErase(nKerfId + i) Next ' Cancello il vecchio kerf EgtErase(EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF)) ' Sposto la curva di offset nel gruppo del grezzo e la rinomino come kerf EgtRelocateGlob(nKerfId, EstCalc.GetRawId()) EgtSetName(nKerfId, NAME_KERF) EgtSetColor(nKerfId, m_KerfCol) ' Aggiorno il grezzo, l'ingombro e la posizione UpdateRawPartKerf() Return True End Function Private Sub AdjustRawPartOnStart() ' Se non c'è la foto va già bene così If GetPhoto() = GDB_ID.NULL Then Return ' Disabilito impostazione modificato Dim bOldEnMod = EgtGetEnableModified() If bOldEnMod Then EgtDisableModified() ' Disabilito la texture sul grezzo Dim nSolidId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_RAW_SOLID) EgtRemoveTextureData(nSolidId) ' Sistemo il colore Dim Col = m_RawCol Col.A = 20 EgtSetColor(nSolidId, Col, True) ' Ripristino precedente impostazione modificato If bOldEnMod Then EgtEnableModified() End Sub Private Sub AdjustRawPartOnExit() ' Se non c'è il grezzo, esco dopo aver nascosto eventuale foto If EstCalc.GetRawId() = GDB_ID.NULL Then ShowPhoto(False) Return End If ' Disabilito impostazione modificato Dim bOldEnMod = EgtGetEnableModified() If bOldEnMod Then EgtDisableModified() ' Salvo la modalità di definizione If SelType = Type.RECTANGLE Then EgtRemoveInfo(EstCalc.GetRawId(), KEY_RAWBYPOINTS) Else EgtSetInfo(EstCalc.GetRawId(), KEY_RAWBYPOINTS, 1) End If ' Verifico senso antiorario della curva di kerf Dim nKerfId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) Dim dArea As Double If EgtCurveAreaXY(nKerfId, dArea) AndAlso dArea < 0 Then EgtInvertCurve(nKerfId) End If ' Elimino regioni per nesting RemoveNestRegions() ' Se c'è la foto devo sistemare If GetPhoto() <> GDB_ID.NULL Then ' Carico la texture della foto sul grezzo Dim nSolidId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_RAW_SOLID) EgtSetTextureName(nSolidId, EstPhoto.GetPhotoName()) ' Sistemo il riferimento della texture Dim refTxr As New Frame3d GetPhotoTextureRef(refTxr) EgtSetTextureFrame(nSolidId, refTxr, GDB_RT.GLOB) ' Sistemo il colore Dim colWhite As New Color3d(255, 255, 255, 100) EgtSetColor(nSolidId, colWhite) ' Anche per il contorno Dim nOutlineId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_RAW_OUTLINE) EgtSetColor(nOutlineId, colWhite) EgtSetStatus(nOutlineId, GDB_ST.OFF) ' Nascondo la foto ShowPhoto(False) End If ' Ripristino precedente impostazione modificato If bOldEnMod Then EgtEnableModified() End Sub Private Function RemoveNestRegions() As Boolean ' Cancello eventuale vecchia regione fuori kerf per nesting EgtErase(EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_OUTKERF_REG)) ' Cancello eventuale vecchia regione di riferimento per nesting EgtErase(EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_REF_REG)) ' Cancello eventuali vecchie regioni aree rovinate per nesting Dim nId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_DAMAGED_REG) While nId <> GDB_ID.NULL EgtErase(nId) nId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_DAMAGED_REG) End While Return True End Function Private Sub AddNewDamagedArea() ' Creo triangolo che abbia il punto selezionato come centro (lato 100mm) ' calcolo punto in basso a sinistra Dim ptBottomLeft As Point3d = New Point3d(m_ptPrev.x - 50, m_ptPrev.y - (100 / 6 * Math.Sqrt(3)), m_ptTableMin.z + CurrentMachine.dAdditionalTable + m_dHeight) Dim vtRight As Vector3d = New Vector3d(100, 0, 0) ' creo lato base Dim nBaseId As Integer = EgtCreateLine(EstCalc.GetRawId(), ptBottomLeft, ptBottomLeft + vtRight, GDB_RT.GLOB) ' calcolo vertice superiore del triangolo Dim vtTop As New Vector3d(vtRight) vtTop.Rotate(Vector3d.Z_AX, 60) ' creo lati inclinati Dim nCat1 As Integer = EgtCreateLine(EstCalc.GetRawId(), ptBottomLeft + vtRight, ptBottomLeft + vtTop, GDB_RT.GLOB) Dim nCAt2 As Integer = EgtCreateLine(EstCalc.GetRawId(), ptBottomLeft + vtTop, ptBottomLeft, GDB_RT.GLOB) ' Creo contorno zona rovinata Dim nDmgId As Integer = EgtCreateCurveCompoByChain(EstCalc.GetRawId(), 3, {nBaseId, nCat1, nCAt2}, ptBottomLeft, True) ' Assegno il nome alla CCompo creata EgtSetName(nDmgId, NAME_DAMAGED) ' e il colore EgtSetColor(nDmgId, m_KerfCol) ' Imposto come area danneggiata corrente m_nSelDmg = nDmgId ' Disabilito modalità aggiungi zona rovinata m_nPtDmgMode = DMGMODE.NONE End Sub Private Sub RemoveDamagedArea() ' Elimino area rovinata selezionata EgtErase(m_nSelDmg) ' Dichiaro zona danneggiata non selezionata m_nSelDmg = GDB_ID.NULL ' Disabilito modalità rimuovi zona rovinata m_nPtDmgMode = DMGMODE.NONE End Sub Private Sub UpdateCircles() ' Elimino vecchi punti finali EgtEmptyGroup(m_nTempLay) ' Identificativo curva Dim nId As Integer = GDB_ID.NULL If GetRawMode() = RAWMODE.BY_POINTS Then nId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) ElseIf GetRawMode() = RAWMODE.DAMAGED Then nId = m_nSelDmg End If ' Verifico validità curva If nId = GDB_ID.NULL Then Return ' riferimento globale della stessa Dim frRef As New Frame3d EgtGetGlobFrame(nId, frRef) ' Recupero i punti finali delle diverse entità componenti Dim dU As Double = 1 Dim ptP As Point3d While EgtAtParamPoint(nId, dU, ptP) ptP.ToGlob(frRef) CreateCircle(m_nTempLay, ptP) dU += 1 End While End Sub Private Sub MoveCircles(vtMove As Vector3d) Dim nId As Integer = EgtGetFirstInGroup(m_nTempLay) While nId <> GDB_ID.NULL EgtMove(nId, vtMove, GDB_RT.GLOB) nId = EgtGetNext(nId) End While End Sub Private Sub RotateCircles(ptAx As Point3d, vtAx As Vector3d, dAngDeg As Double) Dim nId As Integer = EgtGetFirstInGroup(m_nTempLay) While nId <> GDB_ID.NULL EgtRotate(nId, ptAx, vtAx, dAngDeg, GDB_RT.GLOB) nId = EgtGetNext(nId) End While End Sub Private Sub RemoveCircles() EgtEmptyGroup(m_nTempLay) End Sub Private Function CreateCircle(nLayerId As Integer, ptP As Point3d) As Boolean ' Aggiungo cerchio Dim nCircId As Integer = EgtCreateCircle(nLayerId, ptP, RAD_CIRCLE) EgtSetColor(nCircId, New Color3d(255, 0, 0)) Return True End Function Private Function MoveSpotRegistration(nIdGroup As Integer, vtMove As Vector3d) As Boolean If nIdGroup = GDB_ID.NULL Then Return False ' Non ci deve essere movimento in Z vtMove.z = 0 ' Recupero il cercio di riferimento Dim nArcId As Integer = EgtGetFirstInGroup(nIdGroup) Dim b3Crv As New BBox3d EgtGetBBoxGlob(nArcId, GDB_BB.STANDARD, b3Crv) b3Crv.Move(vtMove) If b3Crv.Min().x < m_ptTableMin.x + 10 * EPS_SMALL Then vtMove.x += m_ptTableMin.x + 10 * EPS_SMALL - b3Crv.Min().x ElseIf b3Crv.Max().x > m_ptTableMin.x + m_dTableLength + 10 * EPS_SMALL Then vtMove.x += m_ptTableMin.x + m_dTableLength - 10 * EPS_SMALL - b3Crv.Max().x End If If b3Crv.Min().y < m_ptTableMin.y + 10 * EPS_SMALL Then vtMove.y += m_ptTableMin.y + 10 * EPS_SMALL - b3Crv.Min().y ElseIf b3Crv.Max().y > m_ptTableMin.y + m_dTableWidth + 10 * EPS_SMALL Then vtMove.y += m_ptTableMin.y + m_dTableWidth - 10 * EPS_SMALL - b3Crv.Max().y End If ' muovo il gruppo EgtMove(nIdGroup, vtMove) EgtDraw() Return True End Function Friend Sub MoveAllSpotRegistration(vtMove As Vector3d, Optional bOnlyOfficeSpot As Boolean = True) Dim nId As Integer = EgtGetFirstInGroup(OmagOFFICEMap.refRawPartTabVM.m_nRegGroupId) While nId <> GDB_ID.NULL Dim sName As String = String.Empty EgtGetName(nId, sName) If Not sName.Contains("CUT") Or Not bOnlyOfficeSpot Then EgtMove(nId, vtMove) End If nId = EgtGetNext(nId) End While EgtDraw() End Sub Private Function CreateSpotRegistration(nLayerIdReg As Integer, ptP As Point3d, nIndexSpot As Integer) As Boolean ' creo uno specifico layer per ogni spot (definito da una croce inscritta in un cerchio) Dim nIdSpotLay As Integer = EgtCreateGroup(nLayerIdReg) ' Aggiungo cerchio Dim nCircId As Integer = EgtCreateCircle(nIdSpotLay, ptP, RADSPOT) ' Inserisco una croce all'interno del Dim nLineVId As Integer = EgtCreateLinePVL(nIdSpotLay, ptP, Vector3d.Y_AX, RADSPOT) EgtExtendCurveStartByLen(nLineVId, RADSPOT) Dim nLineHId As Integer = EgtCreateLinePVL(nIdSpotLay, ptP, Vector3d.X_AX, RADSPOT) EgtExtendCurveStartByLen(nLineHId, RADSPOT) Dim nTextId As Integer = EgtCreateText(nIdSpotLay, ptP + New Vector3d(1, 1, 0), nIndexSpot.ToString, 10) ' coloro gli oggetti appena creati ed assegno il nome Dim bOk As Boolean = EgtSetColor(nCircId, New Color3d(0, 0, 0)) bOk = bOk And EgtSetName(nCircId, SPOTREG_ & "Arc") bOk = bOk And EgtSetColor(nLineVId, New Color3d(0, 0, 0)) bOk = bOk And EgtSetName(nLineVId, SPOTREG_ & "LineV") bOk = bOk And EgtSetColor(nLineHId, New Color3d(0, 0, 0)) bOk = bOk And EgtSetName(nLineHId, SPOTREG_ & "LineH") bOk = bOk And EgtSetColor(nTextId, New Color3d(255, 0, 0)) bOk = bOk And EgtSetName(nTextId, SPOTREG_ & "Text") ' assegno il nome del gruppo corrente bOk = bOk And EgtSetName(nIdSpotLay, SPOTREG_ & nIndexSpot.ToString) If bOk Then ' Aggiorno il contatore degli Spot EgtSetInfo(nLayerIdReg, COUNTSPOT, nIndexSpot) m_nCountSpot = nIndexSpot End If Return bOk End Function Private Function RemoveSpotRegistration(nSpotRegId As Integer) As Boolean Dim nIndSpotReg As Integer = GetIndexGroupSpotReg(nSpotRegId) If Not EgtErase(nSpotRegId) Then Return False ' faccio scorrere tutti i gruppi ed eventualmente li rinomino Dim n_IdSR As Integer = EgtGetFirstInGroup(m_nRegGroupId) m_nCountSpot -= 1 EgtSetInfo(m_nRegGroupId, COUNTSPOT, m_nCountSpot) While n_IdSR <> GDB_ID.NULL Dim nCurrIndSpotReg As Integer = GetIndexGroupSpotReg(n_IdSR) If nCurrIndSpotReg > nIndSpotReg Then ' Recupero il testo Dim nIdtext As Integer = EgtGetFirstNameInGroup(n_IdSR, SPOTREG_ & "Text") nCurrIndSpotReg -= 1 EgtModifyText(nIdtext, nCurrIndSpotReg.ToString) EgtSetName(n_IdSR, SPOTREG_ & nCurrIndSpotReg.ToString) End If n_IdSR = EgtGetNext(n_IdSR) End While EgtDraw() Return True End Function Private Function GetIndexGroupSpotReg(nSpotRegId As Integer) As Integer Dim sNameParent As String = String.Empty EgtGetName(nSpotRegId, sNameParent) ' Ricavo l'indice dal nome Dim sItems As String() = sNameParent.Split("_"c) Dim nCurrIndex As Integer = 0 If sItems.Count = 2 Then If Not Integer.TryParse(sItems(1), nCurrIndex) Then nCurrIndex = -1 End If End If Return nCurrIndex End Function Private Function ValidateCurrMachMatThick() As Boolean ' Verifico che le lavorazioni correnti siano compatibili con materiale e spessore ' Lama Dim bOk As Boolean = True EgtMdbSetCurrMachining(CurrentMachine.sCurrSawing) bOk = bOk And CurrMachWindowVM.VerifyMatThickCompatibility() ' Fresa If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrMilling) Then EgtMdbSetCurrMachining(CurrentMachine.sCurrMilling) bOk = bOk And CurrMachWindowVM.VerifyMatThickCompatibility() End If ' Foretto If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrDrilling) Then EgtMdbSetCurrMachining(CurrentMachine.sCurrDrilling) bOk = bOk And CurrMachWindowVM.VerifyMatThickCompatibility() End If Return bOk End Function Private Function ValidateCurrMachToolIsInSetUp() As Boolean Dim bOk As Boolean = True Dim sTUUID As String = String.Empty If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrSawing) Then EgtMdbSetCurrMachining(CurrentMachine.sCurrSawing) EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID) bOk = bOk And SetUpUtility.IsToolInSetUp(sTUUID) End If ' Fresa If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrMilling) Then EgtMdbSetCurrMachining(CurrentMachine.sCurrMilling) sTUUID = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID) bOk = bOk And SetUpUtility.IsToolInSetUp(sTUUID) End If ' Foretto If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrDrilling) Then EgtMdbSetCurrMachining(CurrentMachine.sCurrDrilling) sTUUID = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTUUID) bOk = bOk And SetUpUtility.IsToolInSetUp(sTUUID) End If Return bOk End Function Private Sub UpdateTabState() If ValidateCurrMachMatThick() Then OmagOFFICEMap.refOptionPanelVM.NestTabIsEnabled = True OmagOFFICEMap.refOptionPanelVM.MachTabIsEnabled = True OmagOFFICEMap.refOptionPanelVM.SimulTabIsEnabled = True OmagOFFICEMap.refOptionPanelVM.RawPart_Background = OmagOFFICEDictionary.TabControl_Header_Background CurrMach_Background = DirectCast(New BrushConverter().ConvertFrom("#1C1D22"), SolidColorBrush) Else OmagOFFICEMap.refOptionPanelVM.NestTabIsEnabled = False OmagOFFICEMap.refOptionPanelVM.MachTabIsEnabled = False OmagOFFICEMap.refOptionPanelVM.SimulTabIsEnabled = False OmagOFFICEMap.refOptionPanelVM.RawPart_Background = Brushes.Red CurrMach_Background = Brushes.Red End If If Not ValidateCurrMachToolIsInSetUp() Then OmagOFFICEMap.refMachinePanelVM.SetUp_Background = Brushes.Red Else OmagOFFICEMap.refMachinePanelVM.SetUp_Background = DirectCast(New BrushConverter().ConvertFrom("#1C1D22"), SolidColorBrush) End If If String.IsNullOrWhiteSpace(CurrentMachine.sCurrSawing) And String.IsNullOrWhiteSpace(CurrentMachine.sCurrWaterJetting) Then CurrMach_Background = Brushes.Red End If End Sub Friend Sub Refresh(PrevMeasureUnit As MeasureUnitOpt) NotifyPropertyChanged("Length") NotifyPropertyChanged("Width") NotifyPropertyChanged("Height") NotifyPropertyChanged("OffsetX") NotifyPropertyChanged("OffsetY") NotifyPropertyChanged("Kerf") End Sub #End Region ' METHODS #Region "COMMANDS" #Region "CurrMachCommand" Public ReadOnly Property CurrMachCommand As ICommand Get If m_cmdCurrMach Is Nothing Then m_cmdCurrMach = New Command(AddressOf CurrMach) End If Return m_cmdCurrMach End Get End Property Public Sub CurrMach(ByVal param As Object) ' Apro finestra di configurazione delle lavorazioni correnti Dim CurrMachWindow As New CurrMachWindowV(Application.Current.MainWindow, New CurrMachWindowVM) CurrMachWindow.ShowDialog() UpdateTabState() OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.NotifyPropertyChanged("MachGroupToolTip") End Sub #End Region ' CurrMachCommand #Region "SlabIdCommand" Public ReadOnly Property SlabIdCommand As ICommand Get If m_cmdSlabId Is Nothing Then m_cmdSlabId = New Command(AddressOf SlabId) End If Return m_cmdSlabId End Get End Property Public Sub SlabId(ByVal param As Object) Dim nRawId As Integer = EstCalc.GetRawId() If nRawId = GDB_ID.NULL Then Return ' Finestra input dati Dim DlgSlabIdVM As New SlabIdWindowVM() Dim DlgSlabIdV As New SlabIdWindowV(Application.Current.MainWindow, DlgSlabIdVM) ' Recupero eventuali vecchi dati della lastra Dim sBlockName As String = "" : Dim sSlabNbr As String = "" EgtGetInfo(nRawId, INFO_RAW_BLOCK, sBlockName) EgtGetInfo(nRawId, INFO_RAW_SLABNBR, sSlabNbr) DlgSlabIdVM.SetData(sBlockName, sSlabNbr) ' Visualizzo finestra richiesta dati If DlgSlabIdV.ShowDialog() Then DlgSlabIdVM.GetData(sBlockName, sSlabNbr) ' Assegno info EgtSetInfo(nRawId, INFO_RAW_BLOCK, sBlockName) EgtSetInfo(nRawId, INFO_RAW_SLABNBR, sSlabNbr) ' Aggiorno nome lastra If Not String.IsNullOrWhiteSpace(sBlockName) And Not String.IsNullOrWhiteSpace(sBlockName) Then Dim sSlabName = sBlockName & "-" & sSlabNbr EstCalc.SetSlabName(sSlabName) ' notifico il MachGroup Corrente OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.NotifyPropertyChanged("MachGroupToolTip") End If ' Cancello vecchio BarCode e se definito inserisco nuovo Dim sBarCode As String = sBlockName & " - " & sSlabNbr ShowBarCode(nRawId, sBarCode) ' Aggiorno visualizzazione EgtDraw() End If End Sub #End Region ' SlabIdCommand #Region "PhotoCommand" Public ReadOnly Property PhotoCommand As ICommand Get If m_cmdPhoto Is Nothing Then m_cmdPhoto = New Command(AddressOf Photo) End If Return m_cmdPhoto End Get End Property Public Sub ClosePhotoWnd() m_bSlabIsSelectedFromDB = True OmagPhoto.Close() End Sub Public Sub Photo(ByVal param As Object) Dim sPhoto As String = String.Empty Dim sSlabNameDB As String = "" Dim nSlabId As Integer = 0 Dim sBlockCode As String = "" Dim sSlabCode As String = "" Dim sSlabName As String = "" Dim sMat As String = "" ' cancello eventuali nome di materiali da DB SetMaterialFromDB(String.Empty) If OmagOFFICEMap.refMainWindowVM.MainWindowM.m_SlabDB Then ' recupero il nome del progetto corrente Dim sFileProject As String = String.Empty EgtGetCurrFilePath(sFileProject) ' devo verificare se attualmente c'è una foto di lastra nel MachGroup corrente If Not IsNothing(OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup) Then Dim CurrMachGroup As MachGroup = OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup sSlabNameDB = GetSlabName() End If SetMaterialFromDB(GetMaterialPhoto()) ' salvo il contesto corrente del programma Dim nCurrentContetxt As Integer = EgtGetCurrentContext() MainData.SetPreviousContext(nCurrentContetxt) 'If Not IsNothing(MainData.ContextSTONELib) Or MainData.ContextSTONELib <> 0 Then If MainData.ContextSTONELib <> 0 Then EgtSetCurrentContext(MainData.ContextSTONELib) End If ' imposto come prima pagina sempre la lista, altrimenti compare l'ultima selezione PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST ' assegno il nome della lastra corrente, se eseguo una nuova selezione la rendo AVAILABLE PhotoMap.refOptionPanelVM.sSlabId = sSlabNameDB PhotoMap.refOptionPanelVM.sProjectAssigned = sFileProject ' imposto la ricerca attiva PhotoMap.refSearchPanelVM.SetSearchPanel_Visibility(True) PhotoMap.refSearchPanelVM.InitSearchPanel() ' inizializzo la ricerca a tutti le lastre di tipo "AVAILABLE" (=1) PhotoMap.refSearchPanelVM.State = 1 ' Resetto la data corrente per la prima ricerca PhotoMap.refSearchPanelVM.StartAddedDate = Nothing PhotoMap.refSearchPanelVM.NotifyPropertyChanged("StartAddedDate") PhotoMap.refSearchPanelVM.EndAddedDate = Nothing PhotoMap.refSearchPanelVM.NotifyPropertyChanged("EndAddedDate") PhotoMap.refSearchPanelVM.Search() ' inserisco in elenco solo i materiali della macchina corrente AddHandler PhotoMap.refOptionPanelVM.SlabIsSelectedOFFICE, AddressOf OmagOFFICEMap.refRawPartTabVM.ClosePhotoWnd ' lancio il timer di aggiornamento dell'interfaccia, per la gestione di due OmagPHOTO che accedono allo stesso SQL AddHandler m_RefreshTimer.Tick, AddressOf RefreshTimer_Tick m_RefreshTimer.Interval = TimeSpan.FromMilliseconds(2000) m_RefreshTimer.Start() ' apro la finestra per accedere al DB delle lastre (Devo crea una nuova istanza perchè la chiusura elimina la stessa) Me.OmagPhoto = New OmagPhotoV Me.OmagPhoto.ShowDialog() m_RefreshTimer.Stop() EgtSetCurrentContext(EgtPHOTOLib.MainData.PreviousContext) EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx()) ' se non seleziono nessun lastra esco If Not m_bSlabIsSelectedFromDB Then Return m_bSlabIsSelectedFromDB = False Dim LocalSlab As Slab = EgtPHOTOLib.PhotoMap.refOptionPanelVM.SelSlab ' rimuovo la precedente lastra dalla lista OmagOFFICEMap.refMachGroupPanelVM.SlabNameListCurr.Remove(sSlabNameDB) EgtPHOTOLib.PhotoMap.refOptionPanelVM.SetAvailableSlab(sSlabNameDB) sPhoto = LocalSlab.ImagePath sSlabNameDB = LocalSlab.Id ' imposto lo spessore della lastra Height = LocalSlab.Thickness ' imposto il tipo di materiale If Not IsNothing(LocalSlab.Material) Then Dim bMaterialExists As Boolean = False For Each ItemMaterial In MaterialList If LocalSlab.Material = ItemMaterial.sName Then SelMaterial = ItemMaterial bMaterialExists = True Exit For End If Next If Not bMaterialExists Then EstCalc.SetMaterialPhoto(LocalSlab.Material) SetMaterialFromDB(LocalSlab.Material) End If End If ' aggiungo la nuova lastra OmagOFFICEMap.refMachGroupPanelVM.SlabNameListCurr.Add(sSlabNameDB) EgtPHOTOLib.PhotoMap.refOptionPanelVM.SetAssignedSlab(sSlabNameDB) ' Provo ad assegnare il nome della macchinata Dim sName As String = LocalSlab.Id EgtGetMachGroupNewName(sName) If sName <> LocalSlab.Id Then EgtOutLog("Nome lastra (Id lastra) già presente nell'elenco delle macchinate correnti!") Else OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.SetName(LocalSlab.Id) EgtChangeMachGroupName(EgtGetCurrMachGroup, LocalSlab.Id) End If Else ' Apro dialogo per scelta immagine Dim PhotoDlg As New Microsoft.Win32.OpenFileDialog() PhotoDlg.Title = "Open" PhotoDlg.Filter = "Image file(*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp" PhotoDlg.FilterIndex = 1 GetMainPrivateProfileString(S_GENERAL, K_IMAGEDIR, "", PhotoDlg.InitialDirectory) If Not Directory.Exists(PhotoDlg.InitialDirectory) Then PhotoDlg.InitialDirectory = "" If Not PhotoDlg.ShowDialog Then Return sPhoto = PhotoDlg.FileName End If ' Salvo nuovo direttorio corrente per immagini WriteMainPrivateProfileString(S_GENERAL, K_IMAGEDIR, Path.GetDirectoryName(sPhoto)) ' Annullo offset e rotazione foto SetPhotoOffsetX(0) SetPhotoOffsetY(0) SetPhotoRot(0) ' Carico immagine If Not EstPhoto.LoadPhoto(sPhoto, nSlabId, sBlockCode, sSlabCode, sSlabName, sMat) Then ' Ripristino offset e rotazione foto Dim dPhotoOffsetX, dPhotoOffsetY, dPhotoRot As Double GetPhotoOffsetRot(dPhotoOffsetX, dPhotoOffsetY, dPhotoRot) SetPhotoOffsetX(dPhotoOffsetX) SetPhotoOffsetY(dPhotoOffsetY) SetPhotoRot(dPhotoRot) ' Errore nel caricamento della fotografia MessageBox.Show(EgtMsg(MSG_RAWPARTTAB + 1), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error) Return End If ' Se da DB aggiorno nome lastra If OmagOFFICEMap.refMainWindowVM.MainWindowM.m_SlabDB Then sSlabName = sSlabNameDB ' Aggiorno immagini nel VeinMatching VeinMatching.RemoveUnusedPhotos() ' Parcheggio tutti i pezzi presenti nella lastra Dim nPartId As Integer = EgtGetFirstPartInRawPart(GetRawId()) While nPartId <> GDB_ID.NULL ' Recupero identificativo del successivo Dim nNextPartId As Integer = EgtGetNextPartInRawPart(nPartId) ' Metto in parcheggio EstCalc.StoreOnePart(nPartId) ' Notifica al VeinMatching VeinMatching.OnRemovePartFromRaw(nPartId) ' Passo al successivo nPartId = nNextPartId End While EstCalc.HideParkedParts() ' Imposto nome e spessore lastra If Not String.IsNullOrEmpty(sSlabName) Then EstCalc.SetSlabName(sSlabName) If Not String.IsNullOrEmpty(sBlockCode) Then EstCalc.SetBlockCode(sBlockCode) If Not String.IsNullOrEmpty(sSlabCode) Then EstCalc.SetSlabCode(sSlabCode) EstCalc.SetSlabHeight(m_dHeight) ' Visualizzo eventuale codice Dim sBarCode As String = sBlockCode & " - " & sSlabCode ShowBarCode(EstCalc.GetRawId(), sBarCode) ' notifico il MachGroup Corrente OmagOFFICEMap.refMachGroupPanelVM.SelectedMachGroup.NotifyPropertyChanged("MachGroupToolTip") ' Carico contorno EstPhoto.LoadContour(sPhoto) Dim nCntId As Integer = EstPhoto.GetContour() ' Se disponibile, imposto possibilità di contorno da foto If nCntId = GDB_ID.NULL Then If m_TypeList.Count = 3 Then m_TypeList.RemoveAt(2) Else If m_TypeList.Count = 2 Then m_TypeList.Add(EgtMsg(MSG_RAWPARTPAGEUC + 35)) SelType = Type.FROM_PHOTO NotifyPropertyChanged("SelType") End If ' Se sporge dalla tavola, lo centro sulla stessa If nCntId <> GDB_ID.NULL Then Dim b3Cnt As New BBox3d EgtGetBBoxGlob(nCntId, GDB_BB.STANDARD, b3Cnt) Dim b3Tab As New BBox3d(m_ptTableMin, m_ptTableMin + New Vector3d(m_dTableLength, m_dTableWidth, 0)) If Not b3Tab.EnclosesXY(b3Cnt) Then ModifyPhoto(b3Tab.Center() - b3Cnt.Center()) End If ' Abilito movimento foto con mouse PhotoWithMouse = True ' Aggiorno visualizzazione EgtDraw() End Sub ' per la gestione di due OmagPHOTO che accedono allo stesso SQL Private Sub RefreshTimer_Tick() If Not m_TimerIsBusy And PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST Then m_TimerIsBusy = True m_RefreshTimer.Stop() EgtPHOTOLib.PhotoMap.refListPageVM.RefreshLisPage() m_TimerIsBusy = False m_RefreshTimer.Start() End If End Sub #End Region ' PhotoCommand #Region "ConfirmPhotoCommand" Public ReadOnly Property ConfirmPhotoCommand As ICommand Get If m_cmdConfirmPhoto Is Nothing Then m_cmdConfirmPhoto = New Command(AddressOf ConfirmPhoto) End If Return m_cmdConfirmPhoto End Get End Property Public Sub ConfirmPhoto(ByVal param As Object) ' Passo in modalità per punti SelType = RAWMODE.BY_POINTS NotifyPropertyChanged("SelType") ' Disabilito eventuale movimento foto con mouse PhotoWithMouse = False End Sub #End Region ' ConfirmPhotoCommand #End Region ' COMMANDS #Region "EVENTS" Friend Sub OnMouseDownScene(sender As Object, e As Windows.Forms.MouseEventArgs) ' Verifico cosa selezionato Dim nSolidId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_RAW_SOLID) Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) Dim nPhotoId As Integer = GetPhoto() EgtSetObjFilterForSelWin(True, True, True, True, True) Dim nSel As Integer EgtSelect(e.Location, 2 * Scene.DIM_SEL, 2 * Scene.DIM_SEL, nSel) ' Ricavo nome dell'entità selezionata e identificativo Dim nSelId As Integer = EgtGetFirstObjInSelWin() Dim sName As String = String.Empty While nSelId <> GDB_ID.NULL sName = String.Empty EgtGetName(nSelId, sName) If m_PhotoWithMouse Then If nSelId = nPhotoId Then m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev) m_nDragEnt = -1 m_dDragPar = -1 Exit While End If ' ---------- SELEZIONE SpotReg ---------- ElseIf m_AddPointReg Then ' Acquisisco punto da disegno EgtUnProjectPoint(e.Location, m_ptPrev) Dim ptRawMax As Point3d = GetRawPtMax() m_ptPrev.z = ptRawMax.z + 0.1 ' Inserisco un nuovo punto registrazione CreateSpotRegistration(m_nRegGroupId, m_ptPrev, m_nCountSpot + 1) EgtDraw() ' disattivo il comando di inserimento m_AddPointReg = False NotifyPropertyChanged("AddPointReg") Return ElseIf m_ModPointReg Then If sName.StartsWith(SPOTREG_) Then EgtDeselectAll() EgtResetMark(m_nCurrSpotRegId) ' recupero recupero il centro della prima curva Dim nArcId As Integer = EgtGetFirstInGroup(nSelId) Dim nIdParent As Integer = EgtGetParent(nSelId) EgtSelectGroupObjs(nIdParent) EgtSetMark(nIdParent) EgtDraw() ' Acquisisco punto da disegno EgtUnProjectPoint(e.Location, m_ptPrev) m_bDrag = True m_nDragEnt = nIdParent ' Salvo l'Id del punto SpotReg da spostare m_nCurrSpotRegId = nIdParent ' esco dal ciclo Return End If ElseIf m_RemovePointReg Then If sName.StartsWith(SPOTREG_) Then ' recupero recupero il centro della prima curva Dim nIdParent As Integer = EgtGetParent(nSelId) RemoveSpotRegistration(nIdParent) EgtDraw() EgtErase(nIdParent) m_RemovePointReg = False NotifyPropertyChanged("RemovePointReg") ' esco dal ciclo Return End If ' ---------- SELEZIONE SpotReg ---------- ElseIf sName = NAME_RAW_SOLID Then m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev) m_nDragEnt = -1 m_dDragPar = -1 ElseIf sName = NAME_KERF And (GetRawMode() = RAWMODE.RECTANGLE Or GetRawMode() = RAWMODE.BY_POINTS) Then m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev) Dim dDist, dU As Double If Not EgtPointCurveDist(m_ptPrev.Loc(nKerfId), nKerfId, nKerfId, dDist, dU) Then m_bDrag = False End If m_nDragEnt = CInt(Math.Ceiling(dU)) m_dDragPar = dU ' Privilegio il kerf, pertanto esco Exit While ElseIf sName = NAME_DAMAGED And GetRawMode() = RAWMODE.DAMAGED Then m_bDrag = EgtUnProjectPoint(e.Location, m_ptPrev) Dim dDist, dU As Double If Not EgtPointCurveDist(m_ptPrev.Loc(nSelId), nSelId, nSelId, dDist, dU) Then m_bDrag = False End If m_nDragEnt = CInt(Math.Ceiling(dU)) m_dDragPar = dU m_nSelDmg = nSelId ' Aggiorno cerchi UpdateCircles() EgtDraw() ' Privilegio l'area danneggiata, pertanto esco Exit While End If nSelId = EgtGetNextObjInSelWin() End While ' se drag e modalità punti If m_bDrag And Not m_PhotoWithMouse And GetRawMode() = RAWMODE.BY_POINTS Then ' se aggiungi punto If m_nPtMode = PTMODE.ADD Then If EgtAddCurveCompoJoint(nKerfId, m_dDragPar) Then m_dDragPar = Math.Ceiling(m_dDragPar) ' il grezzo non è cambiato, perchè il nuovo punto è sulla vecchia linea m_AddPoint = False NotifyPropertyChanged("AddPoint") m_nPtMode = PTMODE.MOVE ' Aggiorno cerchi UpdateCircles() EgtDraw() ' altrimenti Else ' verifico se abbastanza vicino ad un estremo Dim ptJoint As Point3d If Not EgtAtParamPoint(nKerfId, Math.Round(m_dDragPar), GDB_ID.ROOT, ptJoint) OrElse Point3d.SqDistXY(ptJoint, m_ptPrev) > RAD_CIRCLE * RAD_CIRCLE Then ' se premuto Alt, permetto di muovere il grezzo If (Keyboard.Modifiers And ModifierKeys.Alt) > 0 Then m_nDragEnt = -1 Else m_bDrag = False End If End If ' se rimuovi If m_nDragEnt <> -1 And m_nPtMode = PTMODE.REMOVE Then ' ci devono essere almeno 4 punti If EgtGetCurveCompoJointCount(nKerfId) >= 4 Then EgtRemoveCurveCompoJoint(nKerfId, CInt(m_dDragPar)) ' Aggiorno il solido del grezzo, l'ingombro e la posizione UpdateRawPartKerf(False) ' Aggiorno cerchi UpdateCircles() EgtDraw() End If m_RemovePoint = False NotifyPropertyChanged("RemovePoint") m_nPtMode = PTMODE.MOVE m_bDrag = False End If End If ' se drag e modalità zona danneggiata ElseIf m_bDrag And GetRawMode() = RAWMODE.DAMAGED Then ' se aggiungi zona rovinata If m_nPtDmgMode = DMGMODE.ADD Then AddNewDamagedArea() ' Aggiorno m_NewDA = False NotifyPropertyChanged("NewDA") UpdateCircles() EgtDraw() ' se rimuovi zona rovinata ElseIf m_nPtDmgMode = DMGMODE.REMOVE Then ' Verifico di essere sulla zona danneggiata Dim ptNear As Point3d If EgtAtParamPoint(m_nSelDmg, m_dDragPar, GDB_ID.ROOT, ptNear) And Point3d.SqDistXY(ptNear, m_ptPrev) <= RAD_CIRCLE * RAD_CIRCLE Then RemoveDamagedArea() ' Aggiorno m_DeleteDA = False NotifyPropertyChanged("DeleteDA") End If ' Aggiorno cerchi UpdateCircles() EgtDraw() ' altrimenti eventuali operazioni di punto Else ' se aggiungi punto If m_nPtMode = PTMODE.ADD Then If EgtAddCurveCompoJoint(m_nSelDmg, m_dDragPar) Then m_dDragPar = Math.Ceiling(m_dDragPar) ' il grezzo non è cambiato, perchè il nuovo punto è sulla vecchia linea m_AddPoint = False NotifyPropertyChanged("AddPoint") m_nPtMode = PTMODE.MOVE ' Aggiorno cerchi UpdateCircles() EgtDraw() ' altrimenti Else ' verifico di essere abbastanza vicino ad un estremo Dim ptJoint As Point3d If Not EgtAtParamPoint(m_nSelDmg, Math.Round(m_dDragPar), GDB_ID.ROOT, ptJoint) OrElse Point3d.SqDistXY(ptJoint, m_ptPrev) > RAD_CIRCLE * RAD_CIRCLE Then m_bDrag = False End If ' se rimuovi If m_bDrag And m_nPtMode = PTMODE.REMOVE Then ' ci devono essere almeno 4 punti If EgtGetCurveCompoJointCount(m_nSelDmg) >= 4 Then EgtRemoveCurveCompoJoint(m_nSelDmg, CInt(m_dDragPar)) ' aggiorno il solido del grezzo, l'ingombro e la posizione UpdateRawPartKerf(False) ' Aggiorno cerchi UpdateCircles() EgtDraw() End If m_RemovePoint = False NotifyPropertyChanged("RemovePoint") m_nPtMode = PTMODE.MOVE m_bDrag = False End If End If End If End If End Sub Friend Sub OnMouseMoveScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) ' Verifico di essere in modalità drag If Not m_bDrag Then Return ' Ricavo il punto corrente in coordinate mondo Dim ptCurr As Point3d EgtUnProjectPoint(e.Location, ptCurr) ' Eseguo solo se movimento significativo If Point3d.SqDistXY(ptCurr, m_ptPrev) < 0.01 Then Return ' Eseguo modifica If m_PhotoWithMouse Then ModifyPhoto(ptCurr) ElseIf m_ModPointReg Then MoveSpotRegistration(m_nDragEnt, ptCurr - m_ptPrev) Else Select Case GetRawMode() Case RAWMODE.RECTANGLE ModifyRectangle(ptCurr) Case RAWMODE.BY_POINTS ModifyGeneric(ptCurr) Case RAWMODE.DAMAGED ModifyDamaged(ptCurr) End Select End If ' Aggiorno il punto precedente m_ptPrev = ptCurr ' Resetto i ponticelli (per ora non sono in grado di muoverli assieme ai pezzi) ResetAllBridges() End Sub Private Sub ModifyPhoto(ptCurr As Point3d) ModifyPhoto(ptCurr - m_ptPrev) End Sub Private Sub ModifyRectangle(ptCurr As Point3d) ' Se movimento del grezzo If m_nDragEnt = -1 Then ' Ricavo il vettore di movimento (tengo solo XY) Dim vtMove As Vector3d = ptCurr - m_ptPrev vtMove.z = 0 ' Muovo il grezzo If EgtMoveRawPart(EstCalc.GetRawId(), vtMove) Then EstCalc.UpdateRawPart() EgtDraw() ' Aggiorno gli offset m_dOffsetX += vtMove.x m_dOffsetY += vtMove.y NotifyPropertyChanged("OffsetX") NotifyPropertyChanged("OffsetY") End If ' se sposto lato sotto ElseIf m_nDragEnt = 1 Then Dim dDelta = ptCurr.y - m_ptPrev.y If m_dWidth - dDelta > MIN_RAW_DIM And m_dOffsetY + dDelta > m_dKerf Then m_dWidth -= dDelta m_dOffsetY += dDelta EgtModifyRawPartSize(EstCalc.GetRawId(), m_dLength + 2 * m_dKerf, m_dWidth + 2 * m_dKerf, m_dHeight) EstCalc.UpdateRawPart() AdjustRawPartKerf() Dim vtMove As New Vector3d(0, dDelta, 0) EgtMoveRawPart(EstCalc.GetRawId(), vtMove) EstCalc.UpdateRawPart() EgtDraw() NotifyPropertyChanged("Width") NotifyPropertyChanged("OffsetY") End If ' se sposto lato a destra ElseIf m_nDragEnt = 2 Then Dim dDelta = ptCurr.x - m_ptPrev.x If m_dLength + dDelta > MIN_RAW_DIM And m_dOffsetX + m_dLength + dDelta + m_dKerf < m_dTableLength Then m_dLength += dDelta EgtModifyRawPartSize(EstCalc.GetRawId(), m_dLength + 2 * m_dKerf, m_dWidth + 2 * m_dKerf, m_dHeight) EstCalc.UpdateRawPart() AdjustRawPartKerf() EgtDraw() NotifyPropertyChanged("Length") End If ' se sposto lato sopra ElseIf m_nDragEnt = 3 Then Dim dDelta = ptCurr.y - m_ptPrev.y If m_dWidth + dDelta > MIN_RAW_DIM And m_dOffsetY + m_dWidth + dDelta + m_dKerf < m_dTableWidth Then m_dWidth += dDelta EgtModifyRawPartSize(EstCalc.GetRawId(), m_dLength + 2 * m_dKerf, m_dWidth + 2 * m_dKerf, m_dHeight) EstCalc.UpdateRawPart() AdjustRawPartKerf() EgtDraw() NotifyPropertyChanged("Width") End If ' se sposto lato a sinistra ElseIf m_nDragEnt = 4 Then Dim dDelta = ptCurr.x - m_ptPrev.x If m_dLength - dDelta > MIN_RAW_DIM And m_dOffsetX + dDelta > m_dKerf Then m_dLength -= dDelta m_dOffsetX += dDelta EgtModifyRawPartSize(EstCalc.GetRawId(), m_dLength + 2 * m_dKerf, m_dWidth + 2 * m_dKerf, m_dHeight) EstCalc.UpdateRawPart() AdjustRawPartKerf() Dim vtMove As New Vector3d(dDelta, 0, 0) EgtMoveRawPart(EstCalc.GetRawId(), vtMove) EstCalc.UpdateRawPart() EgtDraw() NotifyPropertyChanged("Length") NotifyPropertyChanged("OffsetX") End If End If End Sub Private Sub ModifyGeneric(ptCurr As Point3d) ' Se movimento del grezzo If m_nDragEnt = -1 Then ' Ricavo il vettore di movimento (tengo solo XY) Dim vtMove As Vector3d = ptCurr - m_ptPrev vtMove.z = 0 ' Muovo il grezzo If EgtMoveRawPart(EstCalc.GetRawId(), vtMove) Then EstCalc.UpdateRawPart() ' Aggiorno cerchi UpdateCircles() ' Aggiorno visualizzazione EgtDraw() ' Aggiorno gli offset m_dOffsetX += vtMove.x m_dOffsetY += vtMove.y NotifyPropertyChanged("OffsetX") NotifyPropertyChanged("OffsetY") End If ' Altrimenti movimento di un singolo punto Else ' Limito il punto a stare nella tavola con franco pari al kerf If ptCurr.x < m_ptTableMin.x + m_dKerf Then ptCurr.x = m_ptTableMin.x + m_dKerf + SAFE_RAW_DIST If ptCurr.y < m_ptTableMin.y + m_dKerf Then ptCurr.y = m_ptTableMin.y + m_dKerf + SAFE_RAW_DIST If ptCurr.x > m_ptTableMin.x + m_dTableLength - m_dKerf Then ptCurr.x = m_ptTableMin.x + m_dTableLength - m_dKerf - SAFE_RAW_DIST If ptCurr.y > m_ptTableMin.y + m_dTableWidth - m_dKerf Then ptCurr.y = m_ptTableMin.y + m_dTableWidth - m_dKerf - SAFE_RAW_DIST ' Identificativo curva di kerf Dim nKerfId = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) ' Identifico il punto Dim nU As Integer = CInt(m_dDragPar) ' Aggiusto Z punto movimentato (è in globale) ptCurr.z = m_ptTableMin.z + CurrentMachine.dAdditionalTable + m_dHeight ' Sposto il punto If Not EgtModifyCurveCompoJoint(nKerfId, nU, ptCurr, GDB_RT.GLOB) Then Return ' Aggiorno il grezzo, l'ingombro e la posizione UpdateRawPartKerf(False) ' Aggiorno cerchi UpdateCircles() ' Aggiorno visualizzazione EgtDraw() End If End Sub Private Sub ModifyDamaged(ptCurr As Point3d) ' Se non selezionata entità, esco If m_nDragEnt = -1 Then Return ' Recupero Id kerf Dim nKerfId As Integer = EgtGetFirstNameInGroup(EstCalc.GetRawId(), NAME_KERF) ' Limito il punto a stare nel kerf Dim ptLocCurr As Point3d = ptCurr.Loc(nKerfId) Dim dMinDist As Double Dim ptLocMin As Point3d Dim nSide As Integer If EgtPointCurveDistSide(ptLocCurr, nKerfId, Vector3d.Z_AX, nKerfId, dMinDist, ptLocMin, nSide) And nSide = +1 Then ptCurr = ptLocMin.Glob(nKerfId) End If ' Identifico il punto Dim nU As Integer = CInt(m_dDragPar) ' Aggiusto Z punto movimentato (è in globale) ptCurr.z = m_ptTableMin.z + CurrentMachine.dAdditionalTable + m_dHeight ' Sposto il punto If Not EgtModifyCurveCompoJoint(m_nSelDmg, nU, ptCurr, GDB_RT.GLOB) Then Return ' Aggiorno cerchi UpdateCircles() ' Aggiorno visualizzazione EgtDraw() End Sub Friend Sub OnMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) ' Disabilito modalità drag m_bDrag = False End Sub #End Region ' EVENTS End Class