public LayerData(LayerTreeNode treeNode, NlmTreeListView listView, HandleMap handleMap) { ParentIDs = new List <Guid>(); // Node Properties ID = treeNode.ID; if (treeNode.Parent == null) { ParentIDs.Add(new Guid()); } else { ParentIDs.Add(treeNode.Parent.ID); } foreach (LayerTreeNode instanceParent in handleMap.GetTreeNodesByHandle(treeNode.Handle)) { if (instanceParent != treeNode) { if (instanceParent.Parent == null) { ParentIDs.Add(new Guid()); } else { ParentIDs.Add(instanceParent.Parent.ID); } } } // Column Properties Visible = treeNode.Visible; Freeze = treeNode.Freeze; Render = treeNode.Render; Box = treeNode.Box; Expanded = listView.IsExpanded(treeNode); }
/// <summary> /// Deletes the selected treenodes, including associated max nodes. /// All children of selection are also deleted. /// Max nodes will not be deleted if not all instanced nodes are selected. /// If every layer 0 instance is selected, nothing will happen. /// </summary> public void DeleteSelection() { #if DEBUG System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); #endif ListView.NodeControl.MaxEvents.NodeEvents.Unregister(); ListView.NodeControl.MaxEvents.LayerEvents.LayerDeleted.UnregisterNotification(); // Don't do anything if every single layer 0 is selected. IILayer layer0 = MaxLayers.GetLayer(0); UIntPtr layer0handle = MaxAnimatable.GetHandleByAnim(layer0); List <BaseTreeNode> layerTreeNodes = HandleMap.GetTreeNodesByHandle(layer0handle); if (layerTreeNodes.All(x => NodeQuery.SelectionAndAllChildNodes.Contains(x))) { return; } // Collect the selection IEnumerables to use. HashSet <BaseTreeNode> selectionAndAllChildren = new HashSet <BaseTreeNode> (NodeQuery.SelectionAndAllChildNodes); // Calculate layer and object handles. IEnumerable <UIntPtr> objectHandles = selectionAndAllChildren.Where (x => x is ObjectTreeNode).Cast <ObjectTreeNode>().Select(x => x.Handle); IEnumerable <UIntPtr> layerHandles = selectionAndAllChildren.Where (x => x is LayerTreeNode).Cast <LayerTreeNode>().Select(x => x.Handle); // Delete handles from max. foreach (UIntPtr handle in objectHandles) { List <BaseTreeNode> instances = HandleMap.GetTreeNodesByHandle(handle); if (instances.Count() > 1) { if (!instances.All(x => selectionAndAllChildren.Contains(x))) { continue; } } MaxNodes.DeleteNode(handle); } foreach (UIntPtr handle in layerHandles) { List <BaseTreeNode> instances = HandleMap.GetTreeNodesByHandle(handle); if (instances.Count() > 1) { if (!instances.All(x => selectionAndAllChildren.Contains(x))) { continue; } } MaxLayers.DeleteLayer(handle); } // And now to delete the tree nodes now there are no max nodes. DeleteTreeNodes(selectionAndAllChildren); // The default behaviour of the listview is to maintain selection based on item index. // This is not very desirable, as the selection should be nothing. ListView.SelectedObjects = new Object[] {}; ListView.NodeControl.MaxEvents.LayerEvents.LayerDeleted.RegisterNotification(); ListView.NodeControl.MaxEvents.NodeEvents.Register(); #if DEBUG stopwatch.Stop(); MaxListener.PrintToListener("DeleteSelection completed in: " + stopwatch.ElapsedMilliseconds); #endif }