Imports System.Collections.ObjectModel Imports System.Windows Imports System.Windows.Input Imports System.Windows.Media Imports EgtUILib Imports EgtWPFLib5 Public Class BTLFeature Inherits VMBase ' Feature a cui appartiene il parametro Protected m_ParentPart As BTLPart Public ReadOnly Property ParentPart As BTLPart Get Return m_ParentPart End Get End Property ' Id geometrico della feature Protected m_nFeatureId As Integer Public ReadOnly Property nFeatureId As Integer Get Return m_nFeatureId End Get End Property Public Sub SetFeatureId(nFeatureId As Integer) m_nFeatureId = nFeatureId End Sub ' lista dei gruppi Protected m_GRPList As New ObservableCollection(Of Integer) Public Property GRPList As ObservableCollection(Of Integer) Get Return m_GRPList End Get Set(value As ObservableCollection(Of Integer)) m_GRPList = value End Set End Property Protected m_nSelGRP As Integer = -1 Public Overridable Property nSelGRP As Integer Get Return m_nSelGRP End Get Set(value As Integer) m_nSelGRP = value End Set End Property ' Processo Protected m_nPRC As Integer Public Property nPRC As Integer Get Return m_nPRC End Get Set(value As Integer) m_nPRC = value End Set End Property ' Lato Protected m_SIDEList As New ObservableCollection(Of Integer)({1, 2, 3, 4}) Public Property SIDEList As ObservableCollection(Of Integer) Get Return m_SIDEList End Get Set(value As ObservableCollection(Of Integer)) m_SIDEList = value End Set End Property Protected m_nSelSIDE As Integer = -1 Public Overridable Property nSelSIDE As Integer Get Return m_nSelSIDE End Get Set(value As Integer) m_nSelSIDE = value End Set End Property ' Nome Protected m_sName As String Public ReadOnly Property sName As String Get Return m_sName End Get End Property Public Sub SetName(sName As String) m_sName = sName End Sub Protected m_bDO As Boolean Public Overridable Property bDO As Boolean Get Return m_bDO End Get Set(value As Boolean) m_bDO = value End Set End Property Protected m_nPRID As Integer Public Property nPRID As Integer Get Return m_nPRID End Get Set(value As Integer) m_nPRID = value End Set End Property Protected m_sDES As String = String.Empty Public Property sDES As String Get Return m_sDES End Get Set(value As String) m_sDES = value End Set End Property Protected m_frFRAME As New Frame3d Public Property frFRAME As Frame3d Get Return m_frFRAME End Get Set(value As Frame3d) m_frFRAME = value End Set End Property Protected m_nState As CalcStates = -1 Public ReadOnly Property nState As CalcStates Get Return m_nState End Get End Property Protected m_nCALC_ERR As Integer = -1 Public ReadOnly Property nCALC_ERR As Integer Get Return m_nCALC_ERR End Get End Property Protected m_nCALC_ROT As Integer Public ReadOnly Property nCALC_ROT As Integer Get Return m_nCALC_ROT End Get End Property Protected m_nCALC_FALL As Integer Public ReadOnly Property nCALC_FALL As Integer Get Return m_nCALC_FALL End Get End Property Protected m_sCALC_MSG As String Public ReadOnly Property nCALC_MSG As String Get Return m_sCALC_MSG End Get End Property ' lista dei parametri della feature Protected m_PParamList As ObservableCollection(Of BTLParam) Public Property PParamList As ObservableCollection(Of BTLParam) Get Return m_PParamList End Get Set(value As ObservableCollection(Of BTLParam)) m_PParamList = value End Set End Property Protected m_SelPParam As BTLParam Public Overridable Property SelPParam As BTLParam Get Return m_SelPParam End Get Set(value As BTLParam) m_SelPParam = value End Set End Property ' lista dei parametri della feature Protected m_QParamList As ObservableCollection(Of BTLParam) Public Property QParamList As ObservableCollection(Of BTLParam) Get Return m_QParamList End Get Set(value As ObservableCollection(Of BTLParam)) m_QParamList = value End Set End Property Protected m_SelQParam As BTLParam Public Overridable Property SelQParam As BTLParam Get Return m_SelQParam End Get Set(value As BTLParam) m_SelQParam = value End Set End Property #Region "MESSAGES" Public ReadOnly Property Name_Msg As String Get Return EgtMsg(61614) End Get End Property Public ReadOnly Property Value_Msg As String Get Return EgtMsg(61615) End Get End Property Public ReadOnly Property Min_Msg As String Get Return EgtMsg(61616) End Get End Property Public ReadOnly Property Max_Msg As String Get Return EgtMsg(61617) End Get End Property #End Region Sub New(ParentPart As BTLPart, nFeatureId As Integer) m_ParentPart = ParentPart m_nFeatureId = nFeatureId m_PParamList = New ObservableCollection(Of BTLParam) m_QParamList = New ObservableCollection(Of BTLParam) End Sub Sub New(nPRC As Integer, nGRP As Integer, nSIDE As Integer) m_PParamList = New ObservableCollection(Of BTLParam) m_QParamList = New ObservableCollection(Of BTLParam) m_nPRC = nPRC m_nSelGRP = nGRP m_nSelSIDE = nSIDE m_bDO = True End Sub ' funzione che crea l'elenco dei parametri Public Overridable Sub CreateFeatureParams() Dim ParamIndex As Integer = 1 Dim NewBTLParam As BTLParam = Nothing ' leggo tutti i P della feature While BTLIniFile.GetBeamPrivateProfileParam(m_nSelGRP, m_nPRC, True, ParamIndex, Me, NewBTLParam) m_PParamList.Add(NewBTLParam) ParamIndex += 1 End While ' leggo tutti i Q della feature ParamIndex = 1 While BTLIniFile.GetBeamPrivateProfileParam(m_nSelGRP, m_nPRC, False, ParamIndex, Me, NewBTLParam) m_QParamList.Add(NewBTLParam) ParamIndex += 1 End While End Sub ' funzione che legge il valore corrente del parametro Public Function ReadFeatureParams() As Boolean Return ReadFeatureParams(PParamList) And ReadFeatureParams(QParamList) End Function Private Function ReadFeatureParams(ParamList As ObservableCollection(Of Core.BTLParam)) As Boolean ' leggo valore parametro da struttura geometrica For Each Param As BTLParam In ParamList If Param.nType = BTLParamType.DOUBLE_ Or Param.nType = BTLParamType.LENGTH Then Dim dParamValue As Double = 0 If Not EgtGetInfo(m_nFeatureId, Param.sName, dParamValue) Then dParamValue = 0 End If Param.dValue = dParamValue ElseIf Param.nType = BTLParamType.STRING_ Then Dim sParamValue As String = String.Empty EgtGetInfo(m_nFeatureId, Param.sName, sParamValue) Param.sValue = sParamValue ElseIf Param.nType = BTLParamType.COMBO Then Dim nParamValue As Integer EgtGetInfo(m_nFeatureId, Param.sName, nParamValue) Param.nSelValue = nParamValue End If Next Return False End Function ' funzione che setta i valori di default a tutti i parametri Public Function SetDefaultValues() As Boolean Return SetDefaultValues(PParamList) And SetDefaultValues(QParamList) End Function Private Function SetDefaultValues(ParamList As ObservableCollection(Of Core.BTLParam)) As Boolean ' leggo valore parametro da struttura geometrica For Each Param As BTLParam In ParamList If Param.nType = BTLParamType.DOUBLE_ Or Param.nType = BTLParamType.LENGTH Then Param.dValue = Param.dDefault ElseIf Param.nType = BTLParamType.STRING_ Then Param.sValue = "" ElseIf Param.nType = BTLParamType.COMBO Then Param.nSelValue = Param.dDefault End If Next Return False End Function ' funzione che calcola array dei valori dei parametri Public Function CalcParamArray(ByRef vPar() As Double, ByRef sPar As String) As Boolean ' verifico che lista parametri non sia vuota If IsNothing(m_PParamList) OrElse m_PParamList.Count = 0 Then Return False ' caclcolo lunghezza array Dim nLastParId As Integer = m_PParamList(m_PParamList.Count - 1).nId - 1 Dim vTempPar(nLastParId) As Double Dim sTempPar As String = String.Empty ' carico tutti i parametri su array For ParIndex = 0 To m_PParamList.Count - 1 Dim BTLPar As BTLParam = DirectCast(m_PParamList(ParIndex), BTLParam) Select Case BTLPar.nType Case BTLParamType.DOUBLE_, BTLParamType.LENGTH vTempPar(BTLPar.nId - 1) = BTLPar.dValue Case BTLParamType.STRING_ sTempPar = BTLPar.sValue 'Case BTLParamType.COMBO ' Dim cBTLPar As BTLParamCombo = DirectCast(ParentFeature.PParamList(ParIndex), BTLParamCombo) ' vPar(ParIndex) = cBTLPar. End Select Next vPar = vTempPar If String.IsNullOrEmpty(sTempPar) Then sPar = " " Else sPar = sTempPar End If Return True End Function Public Overridable Function Copy() As BTLFeature ' creo nuova feature Dim vPar() As Double = Nothing Dim sPar As String = String.Empty Me.CalcParamArray(vPar, sPar) ' aggiorno la feature con nuovo valore EgtBeamSetPart(Me.ParentPart.nPartId) Dim nNewFeatureId As Integer = EgtBeamAddProcess(Me.nSelGRP, Me.nPRC, Me.nSelSIDE, Me.sDES, Me.ParentPart.NewProcId(), Me.frFRAME, vPar, sPar) ' se è stata creata If nNewFeatureId <> GDB_ID.NULL Then Dim NewFeat As New BTLFeature(Me.ParentPart, nNewFeatureId) ' la aggiungo a struttura BTL corrente Me.ParentPart.FeatureList.Add(NewFeat) Return NewFeat End If Return Nothing End Function Public Overridable Function Copy(DestBTLPart As BTLPart) As Boolean ' creo nuova feature Dim vPar() As Double Dim sPar As String = String.Empty Me.CalcParamArray(vPar, sPar) ' aggiorno la feature con nuovo valore EgtBeamSetPart(DestBTLPart.nPartId) Dim nNewFeatureId As Integer = EgtBeamAddProcess(Me.nSelGRP, Me.nPRC, Me.nSelSIDE, Me.sDES, DestBTLPart.NewProcId(), Me.frFRAME, vPar, sPar) ' se è stata creata If nNewFeatureId <> GDB_ID.NULL Then Dim NewFeat As New BTLFeature(Me.ParentPart, nNewFeatureId) ' la aggiungo a struttura BTL pezzo di destinazione DestBTLPart.FeatureList.Add(NewFeat) Return True End If Return False End Function ' funzione che aggiorna parametri della feature Public Function UpdateParams(nNewGRP As Integer, nNewPRC As Integer, nNewSIDE As Integer, sNewDesc As String, nNewProcId As Integer, frNewRef As Frame3d, vNewPar() As Double, sNewPar As String) As Boolean ' aggiorno la feature con nuovo valore Dim vPar() As Double = Nothing Dim sPar As String = String.Empty CalcParamArray(vPar, sPar) Dim nFeatureId As Integer = EgtBeamModifyProcess(Me.nFeatureId, nNewGRP, nNewPRC, nNewSIDE, sNewDesc, nNewProcId, frNewRef, vNewPar, sNewPar) If nFeatureId <> GDB_ID.NULL Then SetFeatureId(nFeatureId) ' imposto modificato per copie EgtDuploSetModified(ParentPart.nPartId) Return True Else MessageBox.Show("Impossible create feature with this values", "Error") nFeatureId = EgtBeamModifyProcess(Me.nFeatureId, Me.nSelGRP, Me.nPRC, Me.nSelSIDE, "", Me.nPRID, New Frame3d(), vPar, sPar) SetFeatureId(nFeatureId) Return False End If End Function ' funzione che restituisce se la feature è un contorno libero Public Function IsFreeContour() As Boolean Return m_nPRC = 250 OrElse m_nPRC = 251 OrElse m_nPRC = 252 End Function End Class