Ejemplo n.º 1
0
        public static void onCreateFolder(Object sender, ClickEventArgs e)
        {
            NlmTreeListView listView = e.ListView;

            // Calculate unique name in current level.
            IEnumerable <FolderTreeNode> folderNodes = listView.NodeControl.Query.FolderNodes;

            String folderName = "Folder";
            Int32  index      = 1;

            while (folderNodes.Any(x => x.Name == folderName + index.ToString("000")))
            {
                index += 1;
            }
            folderName += index.ToString("000");

            // Create folder node.
            FolderTreeNode folderTreeNode = new FolderTreeNode(folderName);

            // Get parent node.
            BaseTreeNode parentTreeNode = null;

            if (listView.SelectedObjects.Count > 0)
            {
                BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode;
                if (treeNode is FolderTreeNode)
                {
                    parentTreeNode = treeNode;
                }
                if (treeNode is LayerTreeNode)
                {
                    parentTreeNode = treeNode.Parent;
                }
            }

            // Add folder to listview, ensure is visible by expanding parents.
            listView.AddObject(folderTreeNode, parentTreeNode);
            if (parentTreeNode != null)
            {
                listView.Expand(parentTreeNode);
            }

            // Scroll to new item.
            Int32 parentIndex = listView.IndexOf(folderTreeNode);

            if (parentIndex != -1)
            {
                listView.EnsureVisible(parentIndex);
            }

            // Sort, select, and begin edit.
            listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            listView.SelectedObjects = new List <Object> {
                folderTreeNode
            };
            listView.EditModel(folderTreeNode);
        }
Ejemplo n.º 2
0
        private static void onCreateLayer(Object sender, ClickEventArgs e, Boolean addSelection)
        {
            NlmTreeListView listView = e.ListView;

            listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.UnregisterNotification();

            IILayer layer  = MaxLayers.CreateLayer(true, addSelection);
            UIntPtr handle = MaxAnimatable.GetHandleByAnim(layer);

            LayerTreeNode layerTreeNode = new LayerTreeNode(handle, listView.NodeControl.HandleMap);

            // Get parent node.
            BaseTreeNode parentTreeNode = null;

            if (listView.SelectedObjects.Count > 0)
            {
                BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode;
                if (treeNode is FolderTreeNode)
                {
                    parentTreeNode = treeNode;
                }
                if (treeNode is LayerTreeNode)
                {
                    parentTreeNode = treeNode.Parent;
                }
            }

            // Add folder to listview, ensure is visible by expanding parents.
            listView.AddObject(layerTreeNode, parentTreeNode);
            if (parentTreeNode != null)
            {
                listView.Expand(parentTreeNode);
            }

            // Scroll to new item.
            Int32 parentIndex = listView.IndexOf(layerTreeNode);

            if (parentIndex != -1)
            {
                listView.EnsureVisible(parentIndex);
            }

            // Sort, select
            listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            listView.SelectedObjects = new List <Object> {
                layerTreeNode
            };

            // Focus on the listview to ensure text entry goes to the edit box, and begin edit.
            listView.Focus();
            listView.EditModel(layerTreeNode);

            // Register notification.
            listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.RegisterNotification();
        }
Ejemplo n.º 3
0
        private void onNodeCreated(object sender, SystemNotificationAnimEventArgs e)
        {
#if DEBUG
            MaxListener.PrintToListener("onNodeCreated");
#endif
            try
            {
                ListView.BeginUpdate();

                List <BaseTreeNode> refreshNodes = new List <BaseTreeNode>();
                foreach (UIntPtr handle in e.Handles)
                {
                    IAnimatable anim = MaxAnimatable.GetAnimByHandle(handle);
                    if (anim == null)
                    {
                        return;
                    }

                    IINode  node        = anim as IINode;
                    IILayer layer       = MaxLayers.GetLayer(node);
                    UIntPtr layerHandle = MaxAnimatable.GetHandleByAnim(layer);
                    ObjectTreeNode.ObjectClass objectClass = MaxNodes.GetObjectClass(node);

                    List <BaseTreeNode> layerTreeNodes = NodeControl.HandleMap.GetTreeNodesByHandle(layerHandle);
                    foreach (BaseTreeNode layerTreeNode in layerTreeNodes)
                    {
                        ObjectTreeNode objectTreeNode = new ObjectTreeNode(objectClass, handle, NodeControl.HandleMap);
                        NodeControl.Parent.AddChild(objectTreeNode, layerTreeNode, false);

                        if (!refreshNodes.Contains(layerTreeNode))
                        {
                            refreshNodes.Add(layerTreeNode);
                        }
                    }
                }
                MaxListener.PrintToListener(refreshNodes.Count.ToString());
                ListView.RefreshObjects(refreshNodes);
                ListView.Sort(ListView.NlmColumns.NameColumn, SortOrder.Ascending);
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                ListView.EndUpdate();
            }
        }
Ejemplo n.º 4
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.º 5
0
        public override void LayerChanged(ITab <UIntPtr> nodes)
        {
#if DEBUG
            MaxListener.PrintToListener("NodeEventCallback > LayerChanged");
#endif
            List <BaseTreeNode> deleteNodes = new List <BaseTreeNode>();
            List <Tuple <BaseTreeNode, BaseTreeNode> > addNodes = new List <Tuple <BaseTreeNode, BaseTreeNode> >();

            for (int i = 0; i < nodes.Count; i++)
            {
                UIntPtr maxNodeHandle = nodes[(IntPtr)i];
                IINode  maxNode       = MaxAnimatable.GetAnimByHandle(maxNodeHandle) as IINode;
                IILayer maxLayer      = MaxLayers.GetLayer(maxNode);
                UIntPtr layerHandle   = MaxAnimatable.GetHandleByAnim(maxLayer);

                // We need to handle the following scenarios:
                //  An object being moved to another layer.
                //  Objects on instances layers moving to uninstanced layers.
                //  Objects on uninstanced layers moving to instanced layers.

                // The easiest way to do this is to remove old object nodes and create new ones.
                // This should be pretty fast, and this event should fire relatively rarely,
                // but it may have to be rethought if it's too slow.

                // First we remove the old nodes.
                List <BaseTreeNode> objectTreeNodes = NodeControl.HandleMap.GetTreeNodesByHandle(maxNodeHandle);
                deleteNodes.AddRange(objectTreeNodes);

                // Then we add the object node to the new layer.
                List <BaseTreeNode> layerTreeNodes = NodeControl.HandleMap.GetTreeNodesByHandle(layerHandle);
                foreach (BaseTreeNode layerTreeNode in layerTreeNodes)
                {
                    ObjectTreeNode newObjectTreeNode = new ObjectTreeNode(MaxNodes.GetObjectClass(maxNode), maxNodeHandle, NodeControl.HandleMap);
                    addNodes.Add(new Tuple <BaseTreeNode, BaseTreeNode> (newObjectTreeNode, layerTreeNode));
                }
            }

            // And finally we actually do the update all at once.
            NodeControl.Destroy.DeleteTreeNodes(deleteNodes);
            foreach (Tuple <BaseTreeNode, BaseTreeNode> tuple in addNodes)
            {
                NodeControl.Parent.AddChild(tuple.Item1, tuple.Item2, false);
            }

            // And sort :)
            ListView.Sort(ListView.NlmColumns.NameColumn, SortOrder.Ascending);
        }
Ejemplo n.º 6
0
        public static void onAddSelectedObjectsToLayer(Object sender, ClickEventArgs e)
        {
            // TODO:
            // This is quite slow compared to the NodeEventCallback LayerChanged. Look at that for tips.
            // Do we really need BeginUpdate and EndUpdate? Calculate which objects to refresh.
            // Also fix crappy bug where adding children to an expanded layer does not redraw properly.

            NlmTreeListView listView = e.ListView;

            try
            {
                listView.BeginUpdate();

                IList selection = listView.SelectedObjects;
                if (selection.Count == 1)
                {
                    LayerTreeNode layerTreeNode = selection[0] as LayerTreeNode;
                    if (layerTreeNode != null)
                    {
                        List <BaseTreeNode> moveTreeNodes = new List <BaseTreeNode>();

                        IAnimatable layerAnim = MaxAnimatable.GetAnimByHandle(layerTreeNode.Handle);
                        foreach (IINode maxNode in MaxNodes.SelectedNodes)
                        {
                            UIntPtr             maxNodeHandle = MaxAnimatable.GetHandleByAnim(maxNode as IAnimatable);
                            List <BaseTreeNode> treeNodes     = listView.NodeControl.HandleMap.GetTreeNodesByHandle(maxNodeHandle);
                            foreach (BaseTreeNode treeNode in treeNodes)
                            {
                                moveTreeNodes.Add(treeNode);
                            }
                            MaxNodes.MoveNodeToLayer(maxNode, layerAnim as IILayer);
                        }
                        listView.NodeControl.Parent.MoveTreeNodes(moveTreeNodes, layerTreeNode);
                    }
                }

                listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                e.ListView.EndUpdate();
            }
        }
Ejemplo n.º 7
0
        public static void onInstanceSelectedLayers(Object sender, ClickEventArgs e)
        {
            NlmTreeListView listView = e.ListView;

            // Multiple items are being added, so let's use BeginUpdate.
            try
            {
                listView.BeginUpdate();

                foreach (BaseTreeNode treeNode in listView.SelectedObjects)
                {
                    LayerTreeNode layerTreeNode = treeNode as LayerTreeNode;
                    if (layerTreeNode != null)
                    {
                        LayerTreeNode newLayerTreeNode = new LayerTreeNode(layerTreeNode.Handle, listView.NodeControl.HandleMap);

                        foreach (ObjectTreeNode objectTreeNode in treeNode.Children)
                        {
                            ObjectTreeNode newObjectTreeNode = new ObjectTreeNode(objectTreeNode.Class, objectTreeNode.Handle, listView.NodeControl.HandleMap);
                            newObjectTreeNode.Parent = newLayerTreeNode;
                            newLayerTreeNode.Children.Add(newObjectTreeNode);
                        }

                        //foreach (LayerTreeNode instanceNode in layerTreeNode.Instances)
                        //{
                        //    instanceNode.Instances.Add(newLayerTreeNode);
                        //    newLayerTreeNode.Instances.Add(instanceNode);
                        //}
                        //layerTreeNode.Instances.Add(newLayerTreeNode);
                        //newLayerTreeNode.Instances.Add(layerTreeNode);

                        listView.AddObject(newLayerTreeNode, treeNode.Parent);
                    }
                }

                listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                listView.EndUpdate();
            }
        }
Ejemplo n.º 8
0
        public void BuildSceneTree()
        {
            // Create list of tree nodes to append to control.
            // Create folder node hashtable and use ID as key.
            // The hashtable is used to reparent nodes using stored parent ID's.
            List <BaseTreeNode> treeNodeList       = new List <BaseTreeNode>();
            Hashtable           folderNodeIdMap    = new Hashtable();
            List <FolderData>   folderNodeDataList = MaxIO.LoadFolderRootNodeData();

            // These methods add the nodes to the tree node list.
            if (folderNodeDataList != null)
            {
                // We only add folder nodes if the data list obtained is not null.
                BuildFolderNodes(treeNodeList, folderNodeDataList, folderNodeIdMap);
            }
            BuildLayerAndObjectNodes(treeNodeList, MaxLayers.Layers, folderNodeIdMap);

            // Finally, add the list to the listview.
            ListView.Roots = treeNodeList;
            ListView.NodeControl.CollapseExpand.ExpandWasExpanded(treeNodeList);

            // And now sort :)
            ListView.Sort(ListView.NlmColumns.NameColumn, SortOrder.Ascending);
        }
Ejemplo n.º 9
0
        // Move nodes to new parent after a drag drop operation.
        private void DragDropMoveNodes(BaseTreeNode target, IList dragNodes)
        {
            IList selection = ListView.SelectedObjects;

            ListView.BeginUpdate();

            MaxEvents.NodeEvents.Unregister();

            IEnumerable <BaseTreeNode> dragNodesEnum = dragNodes.Cast <BaseTreeNode>();

            // Are layers or folders being dropped on layers?
            // If so, make the target the parent of the target.
            if (dragNodesEnum.All(x => x is LayerTreeNode) && target is LayerTreeNode || dragNodesEnum.All(x => x is FolderTreeNode) && target is LayerTreeNode)
            {
                target = target.Parent;
            }
            // Are objects being dropped on objects?
            // If so, make the target the parent of the target.
            if (dragNodesEnum.All(x => x is ObjectTreeNode) && target is ObjectTreeNode)
            {
                target = target.Parent;
            }

            // Do we move to the root or move under a treeNode?
            // If the target is null, we have to move to root.
            if (target != null && target is LayerTreeNode)
            {
                // Move the treenodes in the listView.
                NodeParentEngine.MoveTreeNodes(dragNodes.Cast <BaseTreeNode>().ToList(), target);

                //TODO:
                //IEnumerable<UIntPtr> handles = dragNodes.Cast<IEnumerable<BaseTreeNode>>()
                //     .Where(x => x is ObjectTreeNode)
                //     .Cast<ObjectTreeNode>()
                //     .Select(x => x.Handle);

                // Move nodes to new layer in max.
                List <UIntPtr> handles = new List <UIntPtr>();
                foreach (BaseTreeNode child in dragNodes)
                {
                    ObjectTreeNode objectChild = child as ObjectTreeNode;
                    if (objectChild != null)
                    {
                        handles.Add(objectChild.Handle);
                    }
                }
                IILayer layer = MaxAnimatable.GetAnimByHandle(((LayerTreeNode)target).Handle) as IILayer;
                if (layer != null)
                {
                    MaxNodes.MoveNodesToLayer(handles, layer);
                }
            }
            else
            {
                NodeParentEngine.MoveTreeNodes(dragNodes.Cast <BaseTreeNode>().ToList(), target);
            }

            MaxEvents.NodeEvents.Register();

            // Default after drop behaviour tries to select nodes based on itemIndex. As nodes have moved this does not work.
            // Instead, return saved selection to SelectedObjects property, and make sure dropped Objects are visible.
            if (!ListView.IsExpanded(target))
            {
                ListView.Expand(target);
            }
            ListView.Sort(ListView.NlmColumns.NameColumn, SortOrder.Ascending);
            ListView.SelectedObjects = selection;
            ListView.EndUpdate();
        }