Exemplo n.º 1
0
        /// <summary>
        /// Sets document to the default element type pane.
        /// It will get all valid default types for the enum and fill the data grid.
        /// </summary>
        public void SetDocument(Document document)
        {
            if (_document == document)
            {
                return;
            }

            _document = document;

            _dataGrid_DefaultElementTypes.Items.Clear();

            foreach (ElementTypeGroup etg in Enum.GetValues(typeof(ElementTypeGroup)))
            {
                if (_finishedTypeGroup.IndexOf(etg) == -1)
                {
                    continue;
                }

                ElementTypeRecord record = new ElementTypeRecord();
                record.ElementTypeGroupName = Enum.GetName(typeof(ElementTypeGroup), etg);

                FilteredElementCollector collector = new FilteredElementCollector(_document);
                collector = collector.OfClass(typeof(ElementType));
                var query = from ElementType et in collector
                            where _document.IsDefaultElementTypeIdValid(etg, et.Id)
                            select et; // Linq query

                ElementId defaultElementTypeId = _document.GetDefaultElementTypeId(etg);

                List <DefaultElementTypeCandidate> defaultElementTypeCandidates = new List <DefaultElementTypeCandidate>();
                foreach (ElementType t in query)
                {
                    DefaultElementTypeCandidate item = new DefaultElementTypeCandidate()
                    {
                        Name             = t.FamilyName + " - " + t.Name,
                        Id               = t.Id,
                        ElementTypeGroup = etg
                    };
                    defaultElementTypeCandidates.Add(item);
                    if (t.Id == defaultElementTypeId)
                    {
                        record.DefaultElementType = item;
                    }
                }
                record.DefaultElementTypeCandidates = defaultElementTypeCandidates;


                int index = _dataGrid_DefaultElementTypes.Items.Add(record);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Responses to the type selection changed.
        /// It will set the selected type as default type.
        /// </summary>
        private void DefaultElementTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 1 && e.RemovedItems.Count == 1)
            {
                System.Windows.Controls.ComboBox cb = sender as System.Windows.Controls.ComboBox;
                if (cb == null)
                {
                    return;
                }

                DefaultElementTypeCandidate item = e.AddedItems[0] as DefaultElementTypeCandidate;
                if (item == null)
                {
                    return;
                }

                _handler.SetData(item.ElementTypeGroup, item.Id);
                _event.Raise();
            }
        }