Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/BTLParam/BTLParamVM.vb
T

450 lines
15 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5
Public Class BTLParamVM
Inherits VMBase
Protected m_BTLParamM As BTLParamM
Public ReadOnly Property BTLParamM As BTLParamM
Get
Return m_BTLParamM
End Get
End Property
Private m_BTLFeatureM As BTLFeatureM
Public ReadOnly Property bIsP As Boolean
Get
Return m_BTLParamM.bIsP
End Get
End Property
Public Property bIsModified As Boolean
Get
Return m_BTLParamM.bIsModified
End Get
Set(value As Boolean)
m_BTLParamM.bIsModified = value
End Set
End Property
Public ReadOnly Property Custom_Visibility As Visibility
Get
If bIsP Then
Return Visibility.Collapsed
Else
Return Visibility.Visible
End If
End Get
End Property
' parametri da struttura
Public Property sName As String
Get
Return m_BTLParamM.sName
End Get
Set(value As String)
m_BTLParamM.sName = value
End Set
End Property
Public ReadOnly Property nId As Integer
Get
Return m_BTLParamM.nId
End Get
End Property
Public Property sDescription As String
Get
Return m_BTLParamM.sDescription
End Get
Set(value As String)
m_BTLParamM.sDescription = value
End Set
End Property
Public ReadOnly Property sMin As String
Get
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_
Return DoubleToString(m_BTLParamM.dMin, 3)
Case BTLParamType.LENGTH
Return LenToString(m_BTLParamM.dMin, 3)
Case Else
Return ""
End Select
End Get
End Property
Public ReadOnly Property sMax As String
Get
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_
Return DoubleToString(m_BTLParamM.dMax, 3)
Case BTLParamType.LENGTH
Return LenToString(m_BTLParamM.dMax, 3)
Case Else
Return ""
End Select
End Get
End Property
' parametri da geometria
Public Property sValue As String
Get
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_
Return DoubleToString(m_BTLParamM.dValue, 3)
Case BTLParamType.LENGTH
Return LenToString(m_BTLParamM.dValue, 3)
Case Else ' stringhe
Return m_BTLParamM.sValue
End Select
Return If(m_BTLParamM.nType = BTLParamType.LENGTH, LenToString(m_BTLParamM.dValue, 3), DoubleToString(m_BTLParamM.dValue, 3))
End Get
Set(value As String)
Dim dNewValue As Double
' trasformo valori
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_
StringToDouble(value, dNewValue)
Case BTLParamType.LENGTH
StringToLen(value, dNewValue)
Case Else
' per string non faccio nulla
End Select
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_, BTLParamType.LENGTH
' verifico che sia compreso tra minimo e massimo
If dNewValue < m_BTLParamM.dMin OrElse dNewValue > m_BTLParamM.dMax Then
MessageBox.Show("Valore non compreso tra minimo e massimo", "Error")
NotifyPropertyChanged("sValue")
Return
End If
UpdateParamValue(dNewValue, "")
Case Else
UpdateParamValue(0, value)
End Select
NotifyPropertyChanged(NameOf(bCustom))
End Set
End Property
Public Property dValue As Double
Get
Return m_BTLParamM.dValue
End Get
Set(value As Double)
m_BTLParamM.dValue = value
NotifyPropertyChanged(NameOf(sValue))
End Set
End Property
Public Property sDefault As String
Get
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_
Return DoubleToString(m_BTLParamM.dDefault, 3)
Case BTLParamType.LENGTH
Return LenToString(m_BTLParamM.dDefault, 3)
Case Else
Return ""
End Select
End Get
Set(value As String)
Dim dNewValue As Double
' trasformo valori
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_
StringToDouble(value, dNewValue)
Case BTLParamType.LENGTH
StringToLen(value, dNewValue)
Case Else
' per string non faccio nulla
End Select
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_, BTLParamType.LENGTH
' verifico che sia compreso tra minimo e massimo
If dNewValue < m_BTLParamM.dMin OrElse dNewValue > m_BTLParamM.dMax Then
MessageBox.Show("Valore non compreso tra minimo e massimo", "Error")
NotifyPropertyChanged(NameOf(sDefault))
Return
End If
m_BTLParamM.dDefault = dNewValue
m_BTLParamM.bIsModified = True
Case Else
m_BTLParamM.dDefault = 0
m_BTLParamM.bIsModified = True
End Select
End Set
End Property
Public ReadOnly Property nType As BTLParamType
Get
Return m_BTLParamM.nType
End Get
End Property
Protected m_sDrawPath As String
Public ReadOnly Property sDrawPath As String
Get
Return Map.refMainWindowVM.MainWindowM.sResourcesRoot & "\Parameters\" & m_BTLFeatureM.sDescGRP & "_" & m_BTLParamM.sName & "_" & m_BTLFeatureM.nSelGRP & ".gif"
End Get
End Property
Public Property bCustom As Boolean
Get
Return m_BTLParamM.bCustom
End Get
Set(value As Boolean)
' Se de-checko il parametro settiamo il suo valore a quello di default
Dim bFound As Boolean = False
If Not value Then
' Cerco PRC nella PRCList (L_ o T_ in base a GRPType) di ConfigurationPageVM
Dim GRPType As Integer = Me.m_BTLFeatureM.nSelGRP
Dim PRC As Integer = Me.m_BTLFeatureM.nPRC
If GRPType = 0 Then
For Each PRCItem In Map.refConfigurationPageVM.L_PRCList
If PRCItem.nPRC = PRC Then
' ciclo sui Q dei PRCItem per trovare quello corrispondente al Q corrente
' e a questo assegniamo il valore di Default
For Each QParam In PRCItem.QBTLParamVMList
If QParam.sName = Me.sName Then
Me.sValue = QParam.sDefault
NotifyPropertyChanged(NameOf(sValue))
bFound = True
Exit For
End If
Next
End If
If bFound Then Exit For
Next
ElseIf GRPType = 1 Then
For Each PRCItem In Map.refConfigurationPageVM.T_PRCList
If PRCItem.nPRC = PRC Then
' ciclo sui Q dei PRCItem per trovare quello corrispondente al Q corrente
' e a questo assegniamo il valore di Default
For Each QParam In PRCItem.QBTLParamVMList
If QParam.sName = Me.sName Then
Me.sValue = QParam.sDefault
NotifyPropertyChanged(NameOf(sValue))
bFound = True
Exit For
End If
Next
End If
If bFound Then Exit For
Next
End If
End If
If bFound Then
m_BTLParamM.bCustom = value
' setto nel DB che il parametro attuale è custom o meno
EgtSetInfo(m_BTLFeatureM.nFeatureId, "Q" & m_BTLParamM.nId.ToString("D2") & "A", If(value, 1, ""))
NotifyPropertyChanged(NameOf(bCustom))
End If
End Set
End Property
#Region "CONSTRUCTOR"
Sub New(BTLParamM As BTLParamM, BTLFeatureM As BTLFeatureM)
m_BTLParamM = BTLParamM
m_BTLFeatureM = BTLFeatureM
End Sub
Sub New(BTLParamM As BTLParamM)
m_BTLParamM = BTLParamM
m_BTLFeatureM = Nothing
End Sub
'' new per double e length
'Sub New(ParentFeature As BTLFeatureVM, IsP As Boolean, nType As BTLParamType, sParamName As String, dMin As Double, dMax As Double, dDefault As Double, sDescription As String)
' MyBase.New(ParentFeature, IsP, nType, sParamName, dMin, dMax, dDefault, sDescription)
'End Sub
'' new per stringhe
'Sub New(ParentFeature As BTLFeatureVM, IsP As Boolean, nType As BTLParamType, sParamName As String, sDescription As String)
' MyBase.New(ParentFeature, IsP, nType, sParamName, sDescription)
'End Sub
'' new per combobox
'Sub New(ParentFeature As BTLFeatureVM, IsP As Boolean, nType As BTLParamType, sParamName As String, nMin As Integer, nMax As Integer, nDefault As Integer, sDescription As String, ValueList As List(Of String))
' MyBase.New(ParentFeature, IsP, nType, sParamName, nMin, nMax, nDefault, sDescription, ValueList)
'End Sub
'' new per parametro vuoto
'Sub New(IsP As Boolean, nType As BTLParamType, sParamName As String)
' MyBase.New(IsP, nType, sParamName)
'End Sub
#End Region ' CONSTRUCTOR
Friend Sub UpdateParamValue(dNewValue As Double, sNewValue As String, Optional bDraw As Boolean = True)
' se P
If m_BTLParamM.bIsP Then
' annullo eventuali rotazioni ed inversione
ResetRotInv()
' aggiorno la feature con nuovo valore
Dim vPar() As Double = Nothing
Dim sPar As String = String.Empty
m_BTLFeatureM.CalcParamArray(vPar, sPar)
' modifico parametro cambiato con value
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_, BTLParamType.LENGTH
vPar(m_BTLParamM.nId - 1) = dNewValue
Case BTLParamType.STRING_
sPar = sNewValue
End Select
Dim bOK As Boolean = m_BTLFeatureM.UpdateParams(m_BTLFeatureM.nSelGRP, m_BTLFeatureM.nPRC, m_BTLFeatureM.nSelSIDE, m_BTLFeatureM.sDES,
m_BTLFeatureM.nPRID, m_BTLFeatureM.frFRAME, vPar, sPar, Map.refMachinePanelVM.SelectedMachine.nType)
If bOK Then
Select Case m_BTLParamM.nType
Case BTLParamType.DOUBLE_, BTLParamType.LENGTH
m_BTLParamM.dValue = dNewValue
NotifyPropertyChanged(NameOf(sValue))
Case BTLParamType.STRING_
m_BTLParamM.sValue = sNewValue
NotifyPropertyChanged(NameOf(sValue))
End Select
Else
NotifyPropertyChanged("sValue")
End If
' ripristino eventuali rotazioni ed inversione
If bDraw Then EgtDraw()
Else
' se Q
If EgtSetInfo(m_BTLFeatureM.nFeatureId, "Q" & m_BTLParamM.nId.ToString("D2"), dNewValue) Then
m_BTLParamM.dValue = dNewValue
NotifyPropertyChanged(NameOf(dValue))
' se parametro diverso da quello di default setto il Custom ad attivo
Dim GRPType As Integer = Me.m_BTLFeatureM.nSelGRP
Dim PRC As Integer = Me.m_BTLFeatureM.nPRC
Dim bFound As Boolean = False
' cerco PRC nella PRCList (L_ o T_ in base a GRPType) di ConfigurationPageVM
If GRPType = 0 Then
For Each PRCItem In Map.refConfigurationPageVM.L_PRCList
If PRCItem.nPRC = PRC Then
' ciclo sui Q dei PRCItem per trovare quello corrispondente al Q corrente
' e a questo assegniamo il valore di Default
For Each QParam In PRCItem.QBTLParamVMList
If QParam.sName = Me.sName Then
Dim dDefault As Double = 0
StringToDouble(QParam.sDefault, dDefault)
m_BTLParamM.bCustom = (Me.dValue <> dDefault)
bFound = True
Exit For
End If
Next
End If
If bFound Then Exit For
Next
ElseIf GRPType = 1 Then
For Each PRCItem In Map.refConfigurationPageVM.T_PRCList
If PRCItem.nPRC = PRC Then
' ciclo sui Q dei PRCItem per trovare quello corrispondente al Q corrente
' e a questo assegniamo il valore di Default
For Each QParam In PRCItem.QBTLParamVMList
If QParam.sName = Me.sName Then
Dim dDefault As Double = 0
StringToDouble(QParam.sDefault, dDefault)
m_BTLParamM.bCustom = (Me.dValue <> dDefault)
bFound = True
Exit For
End If
Next
End If
If bFound Then Exit For
Next
End If
' setto nel DB il fatto che il parametro attuale è custom o meno
EgtSetInfo(m_BTLFeatureM.nFeatureId, "Q" & m_BTLParamM.nId.ToString("D2") & "A", If(bCustom, 1, ""))
NotifyPropertyChanged(NameOf(bCustom))
' imposto modificato per copie
EgtDuploSetModified(m_BTLFeatureM.ParentPart.nPartId)
End If
End If
End Sub
Private Sub ResetRotInv()
If m_BTLFeatureM.ParentPart.nINVERTED Then
End If
End Sub
End Class
'Friend Class BTLParamDouble
' Inherits BTLParam
' Private m_dDefault As Double
' Friend ReadOnly Property dDefault As Double
' Get
' Return m_dDefault
' End Get
' End Property
'End Class
'Friend Class BTLParamString
' Inherits BTLParam
' ' parametri da geometria
' Private m_sValue As String
' Public Property sValue As String
' Get
' Return m_sValue
' End Get
' Set(value As String)
' m_sValue = value
' 'EgtSetPParam(m_nFeatureId, m_sName, value)
' EgtDraw()
' End Set
' End Property
' Sub New(ParentFeature As BTLFeature, IsP As Boolean, nType As BTLParamType, sParamName As String, sDescription As String)
' MyBase.New(ParentFeature, IsP, nType, sParamName, sDescription)
' End Sub
'End Class
'Friend Class BTLParamCombo
' Inherits BTLParam
' ' parametri da struttura
' Dim m_nMin As Integer
' Dim m_nMax As Integer
' Dim m_ValueList As List(Of String)
' ' parametri da geometria
' Private m_nSelValue As Integer
' Public Property nSelValue As Integer
' Get
' Return m_nSelValue
' End Get
' Set(value As Integer)
' m_nSelValue = value
' End Set
' End Property
' Private m_nDefault As Integer
' Friend ReadOnly Property nDefault As Integer
' Get
' Return m_nDefault
' End Get
' End Property
' Sub New(ParentFeature As BTLFeature, IsP As Boolean, nType As BTLParamType, sParamName As String, nMin As Integer, nMax As Integer, nDefault As Integer, sDescription As String, ValueList As List(Of String))
' MyBase.New(ParentFeature, IsP, nType, sParamName, sDescription)
' m_nMin = nMin
' m_nMax = nMax
' m_nDefault = nDefault
' m_ValueList = ValueList
' End Sub
'End Class