Imports System.Collections.ObjectModel
Imports System.IO
Imports System.ComponentModel
Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5

Public Class PartVM
   Inherits Core.PartVM

#Region "FIELDS & PROPERTIES"

#Region "Supervisor"

   Private m_bDO As Boolean
   Public Property bDO As Boolean
      Get
         Return m_bDo
      End Get
      Set(value As Boolean)
         EgtSetInfo(m_PartM.nPartId, MGR_PRT_DO, If(value, 1, 0))
         m_bDo = value
         For Each Feature As BTLFeatureVM In FeatureVMList
            Feature.SetDo(value)
         Next
         EgtDraw()
      End Set
   End Property
   Friend Sub SetDo(bValue As Boolean)
      EgtSetInfo(m_PartM.nPartId, MGR_PRT_DO, If(bValue, 1, 0))
      m_bDO = bValue
      NotifyPropertyChanged(NameOf(bDO))
   End Sub

   Public Property bFLIP As Boolean
      Get
         Return m_PartM.nFLIP <> 0
      End Get
      Set(value As Boolean)
         Return
      End Set
   End Property

#End Region    ' Supervisor

#End Region    ' FIELDS & PROPERTIES

#Region "CONSTRUCTOR"

   Sub New(PartM As PartM, ParentMachGroupVM As MyMachGroupVM)
      MyBase.New(PartM, ParentMachGroupVM)
   End Sub

#End Region    ' CONSTRUCTOR

#Region "METHODS"

#Region "Feature"

   Protected Overrides Sub CreateBTLFeatureVMList()
      Dim all As List(Of BTLFeatureVM) = (From BTLFeatureM In m_PartM.GetBTLFeatures()
                                          Select New BTLFeatureVM(BTLFeatureM)).ToList()

      For Each BTLFeatureVM As BTLFeatureVM In all
         AddHandler BTLFeatureVM.PropertyChanged, AddressOf OnBTLFeatureVMPropertyChanged
      Next

      m_FeatureVMList = New ObservableCollection(Of Core.BTLFeatureVM)(all)
      AddHandler m_FeatureVMList.CollectionChanged, AddressOf OnBTLFeatureVMListChanged

   End Sub

#End Region    ' Feature

#End Region    ' METHODS

#Region "EVENTS"


   Protected Overrides Sub OnBTLFeatureVMPropertyChanged(sender As Object, e As PropertyChangedEventArgs)
      Select Case e.PropertyName
         Case NameOf(sender.bDO)
            ' disattivo pezzo se tutte feature disattive, altrimenti lo attivo
            Dim bFound As Boolean = False
            For Each Feature In FeatureVMList
               If Feature.bDO Then
                  bFound = True
                  Exit For
               End If
            Next
            SetDo(bFound)
      End Select
   End Sub

#End Region    ' EVENTS

End Class
