Files
Dario Sassi 993e7e86a2 EgtCAM5 2.7f2 :
- modifiche per aggiunta utensile di tipo Probe e lavorazione Probing.
2025-06-10 18:38:46 +02:00

529 lines
21 KiB
VB.net

Imports System.ComponentModel
Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
Public Class MachiningParameterExpanderVM
Inherits VMBase
''' <summary>
''' Evento che permette di mettere il focus sullo slider
''' </summary>
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("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)
Dim nOldSliderValue As Integer = m_SliderValue
m_SliderValue = Math.Min( Math.Max( m_SliderValue + value, 1), m_SliderScale)
Dim nStep As Integer = m_SliderValue - nOldSliderValue
If nStep = 0 Then Return
Dim nId As Integer = EgtPreviewMachiningTool(m_nPtEntId, nStep)
If nId <> GDB_ID.NULL Then m_nPtEntId = nId
EgtDraw()
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 FiveAxisMachiningParameterExpanderV
Dim SurfRoughExpanderV As SurfRoughingParameterExpanderV
Dim ProbExpanderV As ProbingParameterExpanderV
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 FiveAxisMachiningParameterExpanderV
FiveAxExpanderV.DataContext = m_CurrOperation
Return FiveAxExpanderV
Case MCH_OY.SURFROUGHING
If IsNothing(SurfRoughExpanderV) Then SurfRoughExpanderV = New SurfRoughingParameterExpanderV
SurfRoughExpanderV.DataContext = m_CurrOperation
Return SurfRoughExpanderV
Case MCH_OY.PROBING
If IsNothing(ProbExpanderV) Then ProbExpanderV = New ProbingParameterExpanderV
ProbExpanderV.DataContext = m_CurrOperation
Return ProbExpanderV
End Select
'MachiningParameterExpanderItem.ReadOperationParam()
Return Nothing
End Get
End Property
#Region "Messages"
Public ReadOnly Property UpdateMachiningBtnMsg As String
Get
Return EgtMsg(MSG_OPERATION + 3) 'Applica Lavorazione
End Get
End Property
Public ReadOnly Property ViewToolBtnMsg As String
Get
Return EgtMsg(MSG_OPERATION + 13) 'Anteprima Utensile
End Get
End Property
Public ReadOnly Property NextStepToolBtnMsg As String
Get
Return EgtMsg(MSG_OPERATION + 14) 'Avanti
End Get
End Property
Public ReadOnly Property PrevStepToolBtnMsg As String
Get
Return EgtMsg(MSG_OPERATION + 15) '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("ParamExpanderPageV")
End Sub
#End Region ' Constructor
#Region "METHODS"
''' <summary>
''' Funzione che attiva l'evento che mette il focus sullo slider
''' </summary>
Public Sub FocusSlider()
RaiseEvent m_EventFocusOnSlider()
End Sub
#End Region ' Methods
#Region "COMMANDS"
#Region "UpdateMachiningCommand"
''' <summary>
''' Restituisce funzione per ricalcolo lavorazione.
''' </summary>
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
''' <summary>
''' Ricalcola una lavorazione.
''' </summary>
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)
Return
End If
' Verifico se forzato ricalcolo da interfaccia
Dim bRecalc As Boolean = ((Keyboard.Modifiers And ModifierKeys.Shift) <> 0)
' Aggiorno parametri di lavorazione
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()
' Imposto geometria
Dim vId() As Integer = Nothing
Dim vSub() As Integer = Nothing
SelData.GetAllIdSub(vId, vSub)
EgtSetMachiningGeometry(vId, vSub)
' Gestione standard per altre entità (curve, testi, ...)
Else
' Imposto geometria
EgtSetMachiningGeometry(SelectedGeometry.ToArray)
End If
' Rigenero la lavorazione
If Not EgtApplyMachining(bRecalc) 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)
Else
' Errore nel calcolo della lavorazione!
MessageBox.Show(EgtMsg(5345), EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Error)
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("CurrOperation_IsModified")
NotifyPropertyChanged("UpdateMachiningBtn_Background")
End Sub
Private Sub ErrorOnOperation(ErrorOnOperation As Boolean) Handles m_CurrOperation.m_ErrorOnOperation
m_CurrOperation_ErrorOnOperation = ErrorOnOperation
' NotifyPropertyChanged("CurrOperation_ErrorOnOperation")
NotifyPropertyChanged("UpdateMachiningBtn_Background")
End Sub
End Class
''' <summary>
''' Class that represent a Converter that use machining type and param type, to set the visibility state of the param type.
''' </summary>
Public Class OperationParamVisibilityConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Select Case CInt(value)
Case MCH_OY.NONE
Return Visibility.Hidden
Case MCH_OY.DISP
Return TMDbParamVisibility.OperationDisposition(CInt(parameter))
Case MCH_OY.DRILLING
Return TMDbParamVisibility.Drilling(CInt(parameter))
Case MCH_OY.SAWING
Return TMDbParamVisibility.Sawing(CInt(parameter))
Case MCH_OY.MILLING
Return TMDbParamVisibility.Milling(CInt(parameter))
Case MCH_OY.POCKETING
Return TMDbParamVisibility.Pocketing(CInt(parameter))
Case MCH_OY.MORTISING
Return TMDbParamVisibility.Mortising(CInt(parameter))
Case MCH_OY.SAWROUGHING
Return TMDbParamVisibility.Sawroughing(CInt(parameter))
Case MCH_OY.SAWFINISHING
Return TMDbParamVisibility.Sawfinishing(CInt(parameter))
Case MCH_OY.GENMACHINING
Return TMDbParamVisibility.GenMachining(CInt(parameter))
Case MCH_OY.CHISELING
Return TMDbParamVisibility.Chiseling(CInt(parameter))
Case MCH_OY.SURFFINISHING
Return TMDbParamVisibility.SurfFinishing(CInt(parameter))
Case MCH_OY.SURFROUGHING
Return TMDbParamVisibility.SurfRoughing(CInt(parameter))
Case MCH_OY.WATERJETTING
Return TMDbParamVisibility.WaterJetting(CInt(parameter))
Case MCH_OY.FIVEAXISMILLING
Return TMDbParamVisibility.FiveAxMachining(CInt(parameter))
Case Else
Return Visibility.Hidden
End Select
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException
End Function
End Class
''' <summary>
''' Class that represent a Converter that convert mm in inch if necessary for the param depth.
''' </summary>
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