Ejemplo n.º 1
0
        private void onLayerCreated(Object sender, SystemNotificationAnimEventArgs e)
        {
#if DEBUG
            MaxListener.PrintToListener("onLayerCreated");
#endif
            List <LayerTreeNode> createdNodes = new List <LayerTreeNode>();
            foreach (UIntPtr handle in e.Handles)
            {
                // TODO: Add handlemap ref to this class.
                // LayerTreeNode newNode = NodeControl.Create.CreateTreeNode(NlmTreeNode.NodeClass.Layer, handle);
                LayerTreeNode newNode = new LayerTreeNode(handle, NodeControl.HandleMap);
                createdNodes.Add(newNode);
            }
            ListView.AddObjects(createdNodes);
            ListView.Sort(ListView.NlmColumns.NameColumn, SortOrder.Ascending);
        }
Ejemplo n.º 2
0
        // TODO: Change List to IEnumerable
        public void MoveTreeNodes(IEnumerable <BaseTreeNode> children, BaseTreeNode newParent)
        {
            // Removing root nodes is expensive.
            // In order to speed things up, build an array of root nodes to delete.
            List <BaseTreeNode> rootRemoveNodes = new List <BaseTreeNode>();
            List <BaseTreeNode> rootAddNodes    = new List <BaseTreeNode>();

            foreach (BaseTreeNode child in children)
            {
                if (!(child.Parent == null && newParent == null))
                {
                    // If the parent is null it's a root node.
                    // If there is a parent, remove it from children.
                    if (child.Parent == null)
                    {
                        rootRemoveNodes.Add(child);
                    }
                    else
                    {
                        child.Parent.Children.Remove(child);
                    }
                    // Set the child to the new parent.
                    child.Parent = newParent;
                    // If the new parent is null, it should become a root node.
                    // If newParent is not null, add it to the children.
                    if (newParent == null)
                    {
                        rootAddNodes.Add(child);
                    }
                    else
                    {
                        newParent.Children.Add(child);
                    }
                }
            }
            // Finally, add all new root nodes to the listview and refresh nodes.
            if (rootRemoveNodes.Count > 0)
            {
                ListView.RemoveObjects(rootRemoveNodes);
            }
            if (rootAddNodes.Count > 0)
            {
                ListView.AddObjects(rootAddNodes);
            }
        }
Ejemplo n.º 3
0
        private void onSystemPostMerge(Object sender, SystemNotificationObjectEventArgs e)
        {
#if DEBUG
            MaxListener.PrintToListener("onSystemPostMerge");
#endif
            try
            {
                ListView.BeginUpdate();

                // Collect existing layer and folder nodes.
                IEnumerable <FolderTreeNode> existingFolderNodes = NodeControl.Query.FolderNodes;
                IEnumerable <LayerTreeNode>  existingLayerNodes  = NodeControl.Query.LayerNodes;

                // Unfortunately no event is fired for nodes that are added to layers that already exist.
                // For this reason we need to refresh the children in every layer.
                NodeControl.Create.AddMissingChildObjects(existingLayerNodes);
                ListView.RefreshObjects(existingLayerNodes.ToList());

                // After merge, get all new layers that need to be added to NLM.
                // Old layers are collected because no notification happens for nodes added to existing layers :/
                List <IILayer> newLayers = new List <IILayer>();
                foreach (IILayer layer in MaxLayers.Layers)
                {
                    UIntPtr handle = MaxAnimatable.GetHandleByAnim(layer as IAnimatable);
                    if (!NodeControl.HandleMap.ContainsHandle(handle))
                    {
                        newLayers.Add(layer);
                    }
                }

                // Check each new layer for any folder data saved on the attribute.
                // If any data exists, append it ot folderDataList.
                List <BaseTreeNode> treeNodeList   = new List <BaseTreeNode>();
                List <FolderData>   folderDataList = new List <FolderData>();
                foreach (IILayer layer in newLayers)
                {
                    List <FolderData> parentFolders = MaxIO.LoadParentFolderData(layer as IAnimatable, ListView);
                    if (parentFolders != null)
                    {
                        foreach (FolderData folderData in parentFolders)
                        {
                            if (!folderDataList.Contains(folderData))
                            {
                                folderDataList.Add(folderData);
                            }
                        }
                    }
                }

                // We only add new folders, so build a hashtable of already existing folder nodes.
                // This hashtable is passed to the Build methods, which checks before creating a new node.
                Hashtable folderNodeIdMap = new Hashtable();
                foreach (FolderTreeNode folderNode in existingFolderNodes)
                {
                    folderNodeIdMap.Add(folderNode.ID, folderNode);
                }

                // Build new folder and layer nodes, and append them to the treeNodeList.
                NodeControl.Create.BuildFolderNodes(treeNodeList, folderDataList, folderNodeIdMap);
                NodeControl.Create.BuildLayerAndObjectNodes(treeNodeList, newLayers, folderNodeIdMap);

                // Finally, add the new objects.
                ListView.AddObjects(treeNodeList);
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                ListView.EndUpdate();
            }
        }