Imports EgtUILib Imports EgtWPFLib5 Public Class MachiningParameterExpanderVM Inherits VMBase ''' ''' Evento che permette di mettere il focus sullo slider ''' Friend Event m_EventFocusOnSlider() Private WithEvents m_CurrOperation As MachiningTreeViewItem Public Property CurrOperation As MachiningTreeViewItem Get Return m_CurrOperation End Get Set(value As MachiningTreeViewItem) m_CurrOperation = value End Set End Property Private m_CurrOperation_IsModified As Boolean Public Property CurrOperation_IsModified As Boolean Get Return m_CurrOperation_IsModified End Get Set(value As Boolean) m_CurrOperation_IsModified = value End Set End Property Private m_CurrOperation_ErrorOnOperation As Boolean Public Property CurrOperation_ErrorOnOperation As Boolean Get Return m_CurrOperation_ErrorOnOperation End Get Set(value As Boolean) m_CurrOperation_ErrorOnOperation = value End Set End Property Private m_UpdateMachiningBtn_Background As SolidColorBrush = Brushes.LightGray Public ReadOnly Property UpdateMachiningBtn_Background As SolidColorBrush Get If m_CurrOperation_ErrorOnOperation Then Return Brushes.Red ElseIf m_CurrOperation_IsModified Then Return Brushes.Gold Else Return Brushes.LightGray End If End Get End Property Private m_bPreviewTool As Boolean = False Public Property ViewTool As Boolean Get Return m_bPreviewTool End Get Set(value As Boolean) If value Then EgtPreparePreviewMachiningTool() m_bPreviewTool = True ResetSliderValue() Else EgtRemovePreviewMachiningTool() m_bPreviewTool = False ResetSliderValue() End If EgtDraw() End Set End Property Friend Sub SetViewTool(value As Boolean) ViewTool = value NotifyPropertyChanged(NameOf(ViewTool)) End Sub ' Slider per muovere l'utensile in aggiunta ai pulsanti indietro e avanti Private m_SliderScale As Integer = 100 Public ReadOnly Property SliderScale As Integer Get Return m_SliderScale End Get End Property Friend Sub SetSliderScale(value As Integer) m_SliderScale = Math.Max(value, 1) If m_SliderScale <= 10 Then m_SliderTick = 1 Else m_SliderTick = CInt(m_SliderScale / 10) End If NotifyPropertyChanged(NameOf(SliderScale)) NotifyPropertyChanged(NameOf(SliderTick)) End Sub Private m_SliderTick As Integer = 10 Public ReadOnly Property SliderTick As Integer Get Return m_SliderTick End Get End Property Private m_nPtEntId As Integer = GDB_ID.NULL Private m_SliderValue As Integer = 1 Public Property SliderValue As Integer Get Return m_SliderValue End Get Set(value As Integer) If m_bPreviewTool Then Dim nId As Integer = EgtPreviewMachiningTool(m_nPtEntId, value - m_SliderValue) If nId <> GDB_ID.NULL Then m_nPtEntId = nId EgtDraw() End If m_SliderValue = value End Set End Property Friend Sub ResetSliderValue() If m_bPreviewTool Then m_nPtEntId = EgtPreviewMachiningTool(GDB_ID.NULL, MCH_PTM.AFTER) Else m_nPtEntId = GDB_ID.NULL End If m_SliderValue = 1 NotifyPropertyChanged(NameOf(SliderValue)) End Sub Friend Sub SetSliderValue(value As Integer) m_SliderValue += value NotifyPropertyChanged(NameOf(SliderValue)) End Sub Dim WoodDrillParamExpanderV As WoodDrillingParameterExpanderV Dim WoodSawParamExpanderV As WoodSawingParameterExpanderV Dim WoodMillParamExpanderV As WoodMillingParameterExpanderV Dim BeamMillParamExpanderV As BeamMillingParameterExpanderV Dim PocketParamExpanderV As PocketingParameterExpanderV Dim MortiseParamExpanderV As MortisingParameterExpanderV Dim GenMachinParamExpanderV As GenMachiningParameterExpanderV Dim ChiselParamExpanderV As ChiselingParameterExpanderV Dim StoneSawParamExpanderV As StoneSawingParameterExpanderV Dim StoneSawFinishParamExpanderV As StoneSawFinishingParameterExpanderV Dim StoneSawRoughParamExpanderV As StoneSawRoughingParameterExpanderV Dim StoneMillParamExpanderV As StoneMillingParameterExpanderV Dim StoneDrillParamExpanderV As StoneDrillingParameterExpanderV Dim SurfFinishParamExpanderV As SurfFinishingParameterExpanderV Dim WjParamExpanderV As WaterjettingParameterExpanderV Dim FiveAxExpanderV As FiveAxisMachinigParameterExpanderV Dim SurfRoughExpanderV As SurfRoughingParameterExpanderV Private Sub Dummy() End Sub Public ReadOnly Property ParamExpanderPageV As ContentControl Get ' !!! Inizializzo delegati con funzione vuota, per evitare problemi !!! MachiningTreeViewItem.m_delRemoveMachining = AddressOf Dummy MachiningTreeViewItem.m_delErrorOnMachining = AddressOf Dummy MachiningTreeViewItem.m_delIsEnabledBtns = AddressOf Dummy FamilyMachiningTreeViewItem.m_delIsEnabledBtns = AddressOf Dummy MachiningTreeViewItem.m_delNotifyPropertyChanged = AddressOf Dummy FamilyMachiningTreeViewItem.m_delNotifyPropertyChanged = AddressOf Dummy Dim sName = String.Empty Dim nType As Integer EgtGetMachiningParam(MCH_MP.NAME, sName) EgtGetMachiningParam(MCH_MP.TYPE, nType) m_CurrOperation = New MachiningTreeViewItem(sName, DirectCast(nType, MCH_MY)) m_CurrOperation.ReadOperationParam() ' Riferimento a operazione selezionata EgtWPFLib5.MachiningTreeViewItem.sh_SelMach = m_CurrOperation IsModified(False) ErrorOnOperation(False) ' EgtGetMachiningParam(MCH_MP.TYPE, m_Type) If IsNothing(nType) Then Return Nothing Dim MatType As MaterialType = EgtWPFLib5.MachiningTreeViewItem.m_MatType EgtWPFLib5.MachiningTreeViewItem.m_MPE_SysNotes_Visibility = IniFile.m_nUserLevel > 9 Select Case nType Case MCH_OY.DRILLING If MatType = MaterialType.STONE Then If IsNothing(StoneDrillParamExpanderV) Then StoneDrillParamExpanderV = New StoneDrillingParameterExpanderV StoneDrillParamExpanderV.DataContext = m_CurrOperation Return StoneDrillParamExpanderV Else If IsNothing(WoodDrillParamExpanderV) Then WoodDrillParamExpanderV = New WoodDrillingParameterExpanderV WoodDrillParamExpanderV.DataContext = m_CurrOperation Return WoodDrillParamExpanderV End If Case MCH_OY.SAWING If MatType = MaterialType.STONE Then If IsNothing(StoneSawParamExpanderV) Then StoneSawParamExpanderV = New StoneSawingParameterExpanderV StoneSawParamExpanderV.DataContext = m_CurrOperation Return StoneSawParamExpanderV Else If IsNothing(WoodSawParamExpanderV) Then WoodSawParamExpanderV = New WoodSawingParameterExpanderV WoodSawParamExpanderV.DataContext = m_CurrOperation Return WoodSawParamExpanderV End If Case MCH_OY.MILLING If MatType = MaterialType.BEAM Then If IsNothing(BeamMillParamExpanderV) Then BeamMillParamExpanderV = New BeamMillingParameterExpanderV BeamMillParamExpanderV.DataContext = m_CurrOperation Return BeamMillParamExpanderV ElseIf MatType = MaterialType.STONE Then If IsNothing(StoneMillParamExpanderV) Then StoneMillParamExpanderV = New StoneMillingParameterExpanderV StoneMillParamExpanderV.DataContext = m_CurrOperation Return StoneMillParamExpanderV Else If IsNothing(WoodMillParamExpanderV) Then WoodMillParamExpanderV = New WoodMillingParameterExpanderV WoodMillParamExpanderV.DataContext = m_CurrOperation Return WoodMillParamExpanderV End If Case MCH_OY.SAWROUGHING If IsNothing(StoneSawRoughParamExpanderV) Then StoneSawRoughParamExpanderV = New StoneSawRoughingParameterExpanderV StoneSawRoughParamExpanderV.DataContext = m_CurrOperation Return StoneSawRoughParamExpanderV Case MCH_OY.SAWFINISHING If IsNothing(StoneSawFinishParamExpanderV) Then StoneSawFinishParamExpanderV = New StoneSawFinishingParameterExpanderV StoneSawFinishParamExpanderV.DataContext = m_CurrOperation Return StoneSawFinishParamExpanderV Case MCH_OY.POCKETING If MatType = MaterialType.STONE Or MatType = MaterialType.STONE5 Then ' se macchina di tipo STONE ricavo il tipo di utensile Dim sMachiningToolName = String.Empty EgtMdbSetCurrMachining(sName) EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, sMachiningToolName) EgtTdbSetCurrTool(sMachiningToolName) Dim dValue As Double = 0 Dim nToolType As Integer EgtTdbGetCurrToolParam(MCH_TP.TYPE, nToolType) ' se utensile di tipo POLISHING rendo visibili i campi sugli epicicli If nToolType = MCH_TY.MILL_POLISHING Then m_CurrOperation.Epicycles_Visibility = Visibility.Visible End If If IsNothing(PocketParamExpanderV) Then PocketParamExpanderV = New PocketingParameterExpanderV PocketParamExpanderV.DataContext = m_CurrOperation Return PocketParamExpanderV Case MCH_OY.MORTISING If IsNothing(MortiseParamExpanderV) Then MortiseParamExpanderV = New MortisingParameterExpanderV MortiseParamExpanderV.DataContext = m_CurrOperation Return MortiseParamExpanderV Case MCH_OY.GENMACHINING If IsNothing(GenMachinParamExpanderV) Then GenMachinParamExpanderV = New GenMachiningParameterExpanderV GenMachinParamExpanderV.DataContext = m_CurrOperation Return GenMachinParamExpanderV Case MCH_OY.CHISELING If IsNothing(ChiselParamExpanderV) Then ChiselParamExpanderV = New ChiselingParameterExpanderV ChiselParamExpanderV.DataContext = m_CurrOperation Return ChiselParamExpanderV Case MCH_OY.SURFFINISHING If IsNothing(SurfFinishParamExpanderV) Then SurfFinishParamExpanderV = New SurfFinishingParameterExpanderV SurfFinishParamExpanderV.DataContext = m_CurrOperation Return SurfFinishParamExpanderV Case MCH_OY.WATERJETTING If IsNothing(WjParamExpanderV) Then WjParamExpanderV = New WaterjettingParameterExpanderV WjParamExpanderV.DataContext = m_CurrOperation Return WjParamExpanderV Case MCH_OY.FIVEAXISMILLING If IsNothing(FiveAxExpanderV) Then FiveAxExpanderV = New FiveAxisMachinigParameterExpanderV FiveAxExpanderV.DataContext = m_CurrOperation Return FiveAxExpanderV Case MCH_OY.SURFROUGHING If IsNothing(SurfRoughExpanderV) Then SurfRoughExpanderV = New SurfRoughingParameterExpanderV SurfRoughExpanderV.DataContext = m_CurrOperation Return SurfRoughExpanderV End Select Return Nothing End Get End Property #Region "Messages" Public ReadOnly Property UpdateMachiningBtnMsg As String Get Return EgtMsg(5403) ' Applica Lavorazione End Get End Property Public ReadOnly Property ViewToolBtnMsg As String Get Return EgtMsg(5413) ' Anteprima Utensile End Get End Property Public ReadOnly Property NextStepToolBtnMsg As String Get Return EgtMsg(5414) ' Avanti End Get End Property Public ReadOnly Property PrevStepToolBtnMsg As String Get Return EgtMsg(5415) ' Indietro End Get End Property #End Region ' Messages ' Definizione comando Private m_cmdNextStepTool As ICommand Private m_cmdPrevStepTool As ICommand Private m_cmdUpdateMachining As ICommand #Region "CONSTRUCTOR" Sub New() EgtWPFLib5.MachiningDbWindowVM.m_sMachineIniPath = IniFile.m_sCurrMachIniFilePath Map.SetRefMachiningParameterExpanderVM(Me) NotifyPropertyChanged(NameOf(ParamExpanderPageV)) End Sub #End Region ' Constructor #Region "METHODS" ''' ''' Funzione che attiva l'evento che mette il focus sullo slider ''' Public Sub FocusSlider() RaiseEvent m_EventFocusOnSlider() End Sub #End Region ' Methods #Region "COMMANDS" #Region "UpdateMachiningCommand" ''' ''' Restituisce funzione per ricalcolo lavorazione. ''' Public ReadOnly Property UpdateMachiningCommand As ICommand Get If m_cmdUpdateMachining Is Nothing Then m_cmdUpdateMachining = New RelayCommand(AddressOf UpdateMachining) End If Return m_cmdUpdateMachining End Get End Property ''' ''' Ricalcola una lavorazione. ''' Public Sub UpdateMachining(ByVal param As Object) ' Verifico la presenza di errori: se ci sono li mostro in una MessageBox ed esco da UpdateMachining If m_CurrOperation_ErrorOnOperation Then Dim sErrorList As String = String.Empty For Each [property] As String In EgtWPFLib5.MachiningTreeViewItem.ValidatedProperties If Not String.IsNullOrEmpty(m_CurrOperation.GetErrorString([property])) Then sErrorList += Environment.NewLine + " - " + m_CurrOperation.GetErrorString([property]) End If Next [property] 'MessageBox.Show(EgtMsg(5423) + sErrorList, EgtMsg(30009), MessageBoxButton.OK, MessageBoxImage.Exclamation) EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(5423) + sErrorList, EgtMsg(30009), MessageBoxButton.OK, MessageBoxImage.Exclamation) ' La lavorazione non può essere applicata per i seguenti motivi: ATTENZIONE Return End If Dim bRecalc As Boolean = False If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then bRecalc = True Else ' Controllo se il tipo e' dr o sr o lr bRecalc e' true come quando viene selezionato Shift For Each ItemNote As NoteListBoxItem In m_CurrOperation.NotesList bRecalc = ItemNote.Type.Equals("dr") OrElse ItemNote.Type.Equals("lr") OrElse ItemNote.Type.Equals("sr") OrElse ItemNote.Type.Equals("br") If bRecalc Then Exit For Next End If ' La modifica di alcuni parametri forza il ricalcolo della geometria Dim ModifiedGeometry As Boolean = m_CurrOperation.m_IsModifiedSelectedFaceUseType ' aggiorno valori modificati m_CurrOperation.WriteOperationParam() ' Carico tutta la geometria selezionata in una lista Dim SelectedGeometry As New List(Of Integer) Dim EntityIndex As Integer = EgtGetFirstSelectedObj() While EntityIndex <> GDB_ID.NULL SelectedGeometry.Add(EntityIndex) EntityIndex = EgtGetNextSelectedObj() End While ' Gestione speciale per superfici ( si aggiunge l'identificazione della faccia) If SelectedGeometry.Count() > 0 AndAlso (EgtGetType(SelectedGeometry(0)) = GDB_TY.SRF_MESH Or EgtGetType(SelectedGeometry(0)) = GDB_TY.SRF_FRGN) Then ' Aggiorno lista speciale con facce SelData.VerifyIdSub() ' Verifico se geometria cambiata, confrontando selezione attuale con facet con geometria di lavorazione Dim nInd As Integer = 0 Dim nMchId, nMchSub As Integer EgtGetMachiningGeometry(nInd, nMchId, nMchSub) Dim nSelId, nSelSub As Integer SelData.GetIdSub(nInd, nSelId, nSelSub) While Not ModifiedGeometry And (nMchId <> GDB_ID.NULL Or nSelId <> GDB_ID.NULL) ' Controllo uguaglianza If nMchId <> nSelId Or nMchSub <> nSelSub Then ModifiedGeometry = True ' Passo al successivo nInd += 1 EgtGetMachiningGeometry(nInd, nMchId, nMchSub) SelData.GetIdSub(nInd, nSelId, nSelSub) End While If ModifiedGeometry Then Dim vId() As Integer = Nothing Dim vSub() As Integer = Nothing SelData.GetAllIdSub(vId, vSub) EgtSetMachiningGeometry(vId, vSub) End If ' Gestione standard per altre entità (curve, testi, ...) Else ' Verifico se geometria cambiata, confrontando selezione attuale con geometria di lavorazione Dim nInd As Integer = 0 Dim nMchId, nMchSub As Integer EgtGetMachiningGeometry(nInd, nMchId, nMchSub) Dim nSelId As Integer nSelId = If(nInd < SelectedGeometry.Count(), SelectedGeometry(nInd), GDB_ID.NULL) While Not ModifiedGeometry And (nMchId <> GDB_ID.NULL Or nSelId <> GDB_ID.NULL) ' Controllo uguaglianza If nMchId <> nSelId Then ModifiedGeometry = True ' Passo al successivo nInd += 1 EgtGetMachiningGeometry(nInd, nMchId, nMchSub) nSelId = If(nInd < SelectedGeometry.Count(), SelectedGeometry(nInd), GDB_ID.NULL) End While ' Imposto geometria selezionata come geometria di lavorazione If ModifiedGeometry Then EgtSetMachiningGeometry(SelectedGeometry.ToArray) End If End If ' Ricalcolo la lavorazione If Not EgtApplyMachining(bRecalc Or ModifiedGeometry) Then If EgtGetLastMachMgrErrorId() <> 0 Then Dim sErr As String = EgtGetLastMachMgrErrorString() Dim sInfo As String = String.Empty EgtGetOutstrokeInfo(sInfo) If Not String.IsNullOrEmpty(sInfo) Then sErr &= " " & sInfo 'MessageBox.Show(sErr, EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Exclamation) EgtMessageBoxV.Show(Application.Current.MainWindow, sErr, EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Exclamation) ' ERRORE Else ' Errore nel calcolo della lavorazione! 'MessageBox.Show(EgtMsg(5345), EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Error) EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(5345), EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Error) ' Errore nel calcolo della lavorazione! ERRORE End If Else If EgtGetMachMgrWarningId(0) <> 0 Then Dim sWarn As String = EgtGetMachMgrWarningString(0) Map.refStatusBarVM.NotifyStatusOutput(sWarn) Else Map.refStatusBarVM.NotifyStatusOutput("") End If End If ' Restart visualizzazione utensile SetSliderScale( EgtGetPreviewMachiningToolStepCount()) SetViewTool(True) IsModified(False) ErrorOnOperation(False) EgtDraw() Map.refProjectVM.EmitTitle() End Sub #End Region ' UpdateMachiningCommand #End Region ' Commands Private Sub IsModified(IsModified As Boolean) Handles m_CurrOperation.m_IsModified m_CurrOperation_IsModified = IsModified NotifyPropertyChanged(NameOf(UpdateMachiningBtn_Background)) End Sub Private Sub ErrorOnOperation(ErrorOnOperation As Boolean) Handles m_CurrOperation.m_ErrorOnOperation m_CurrOperation_ErrorOnOperation = ErrorOnOperation NotifyPropertyChanged(NameOf(UpdateMachiningBtn_Background)) End Sub End Class ''' ''' Class that represent a Converter that convert mm in inch if necessary for the param depth. ''' Public Class DepthUnitConverter Implements IValueConverter Friend Const INCHTOMM As String = "*25.4" Friend Const INCHSYMBOL As String = """" Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert If Not IsNothing(value) Then value = CStr(value).Replace(INCHTOMM, INCHSYMBOL) End If Return value End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack If Not IsNothing(value) Then value = CStr(value).Replace(INCHSYMBOL, INCHTOMM) End If Return value End Function End Class