Exemplo n.º 1
0
        /// <summary>
        /// Freezes / Unfreezes all IILayer objects.
        /// </summary>
        public static void FreezeUnfreezeAll()
        {
            Boolean        isFrozen     = false;
            IILayerManager LayerManager = GlobalInterface.Instance.COREInterface13.LayerManager;

            for (int i = 0; i < LayerManager.LayerCount; i++)
            {
                IILayer layer = LayerManager.GetLayer(i);
                if (!layer.IsFrozen)
                {
                    isFrozen = true;
                }
            }
            for (int i = 0; i < LayerManager.LayerCount; i++)
            {
                IILayer layer = LayerManager.GetLayer(i);

#if Max2013 || Max2014
                layer.IsFrozen = isFrozen;
#endif

#if Max2015
                layer.Freeze(isFrozen, false);
#endif
            }

            MaxUI.RedrawViewportsNow();
        }
Exemplo n.º 2
0
 protected override void Dispose(bool disposing)
 {
     MaxUI.RefreshButtonStates();
     base.Dispose(disposing);
 }
Exemplo n.º 3
0
        //TODO:
        // Perhaps move this to a new class / node control. It's pretty huge.
        // Use MaxLayers static class to manipulate max objects instead of in code here.

        /// <summary>
        /// Isolate selected TreeNodes in Nested Layer Manager.
        /// Any TreeNode that is not isolated is disabled, and the respective node hidden in Max.
        /// </summary>
        /// <param name="sender">An NLMCheckButton that contains a checked property.</param>
        /// <param name="e">NLM Button Event Args, that contain a pointer to the listview.</param>
        public static void onIsolateSelection(Object sender, ClickEventArgs e)
        {
            // If the sender is not an NLMCheckButton, the request has come from somewhere else (right click or shortcut).
            // For this reason, change the check state of the button UI which will raise this event again.
            if (!(sender is NlmCheckButton))
            {
                e.ListView.ButtonPanelLeft.IsolateSelectedButton.Checked = !e.ListView.ButtonPanelLeft.IsolateSelectedButton.Checked;
                return;
            }

            NlmTreeListView listView = e.ListView;
            NlmCheckButton  button   = sender as NlmCheckButton;

            // Pause UI from refreshing.
            try
            {
                listView.BeginUpdate();

                // Isolate selected if button checked.
                if (button.Checked)
                {
                    // This method has some serious processing going on, so hashsets are used to maximise performance.
                    // Calculate all enabled nodes and disabled nodes.
                    HashSet <BaseTreeNode> enabledNodes  = new HashSet <BaseTreeNode>(listView.NodeControl.Query.SelectionAndAllChildNodes);
                    HashSet <BaseTreeNode> disabledNodes = new HashSet <BaseTreeNode>(listView.NodeControl.Query.AllNodes.Where(x => !enabledNodes.Contains(x)));

                    // Disable disabled nodes.
                    listView.DisableObjects(disabledNodes);

                    // Now we need to work out what maxNodes and layers to temporarily hide.
                    // Firstly, get the highest selected objects.
                    IEnumerable <ObjectTreeNode> selectedNodes = listView.NodeControl.Query.SelectedAncestors
                                                                 .Where(x => (x is ObjectTreeNode)).Cast <ObjectTreeNode>();
                    HashSet <IILayer> onLayers = new HashSet <IILayer>();

                    // If objects are selected, we need to ensure that the layer is not hidden.
                    // If any objects are selected, append the layer to the onLayers hashset.
                    foreach (ObjectTreeNode objectTreeNode in selectedNodes)
                    {
                        IINode maxNode = MaxAnimatable.GetAnimByHandle(objectTreeNode.Handle) as IINode;

                        if (maxNode == null)
                        {
                            continue;
                        }

                        IILayer layer = MaxLayers.GetLayer(maxNode);
                        if (!onLayers.Contains(layer))
                        {
                            onLayers.Add(layer);
                        }
                    }

                    // Ensure that the layer is on so that objects are visible.
                    // The layer is only turned on if an object is selected, and no ancestor is selected.
                    // For any object that is not selected, the object needs to be hidden.
                    foreach (IILayer layer in onLayers)
                    {
                        if (layer.IsHidden)
                        {
#if Max2013 || Max2014
                            layer.IsHidden = false;
#endif
#if Max2015
                            layer.Hide(false, false);
#endif
                        }

                        foreach (IINode maxNode in MaxLayers.GetChildNodes(layer))
                        {
                            UIntPtr maxNodeHandle = MaxAnimatable.GetHandleByAnim(maxNode);
                            if (!selectedNodes.Any(x => (x).Handle == maxNodeHandle) && !maxNode.IsObjectHidden)
                            {
                                listView.DisabledHandles.Add(maxNodeHandle);
                                maxNode.Hide(true);
                            }
                        }
                    }

                    // Loop through all layers that should be turned off.
                    // If the layer should be hidden (because it is not in onLayers or in enabledLayers), hide it.
                    IEnumerable <LayerTreeNode> enabledLayers = enabledNodes.Where(x => (x is LayerTreeNode)).Cast <LayerTreeNode>();
                    IEnumerable <IILayer>       offLayers     = MaxLayers.Layers.Where(x => !onLayers.Contains(x));
                    foreach (IILayer layer in offLayers)
                    {
                        UIntPtr layerHandle = MaxAnimatable.GetHandleByAnim(layer);
                        if (!layer.IsHidden && !enabledLayers.Any(x => (x).Handle == layerHandle))
                        {
#if Max2013 || Max2014
                            layer.IsHidden = true;
#endif
#if Max2015
                            layer.Hide(true, false);
#endif
                            listView.DisabledHandles.Add(layerHandle);
                        }
                    }
                }
                // Remove isolation and restore state if unchecked.
                else
                {
                    // Enable all objects.
                    listView.EnableObjects(listView.DisabledObjects);

                    // Turn on all handles that were turned off.
                    foreach (UIntPtr handle in listView.DisabledHandles)
                    {
                        IAnimatable maxAnim  = MaxAnimatable.GetAnimByHandle(handle);
                        IILayer     maxLayer = maxAnim as IILayer;
                        if (maxLayer != null)
                        {
#if Max2013 || Max2014
                            maxLayer.IsHidden = false;
#endif
#if Max2015
                            maxLayer.Hide(false, false);
#endif
                            continue;
                        }
                        IINode maxNode = maxAnim as IINode;
                        if (maxNode != null)
                        {
                            maxNode.Hide(false);
                            continue;
                        }
                    }

                    // Clear list of handles.
                    listView.DisabledHandles.Clear();
                }
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                listView.EndUpdate();
            }
            MaxUI.RedrawViewportsNow();
        }
Exemplo n.º 4
0
 public static void onDeleteSelection(Object sender, ClickEventArgs e)
 {
     e.ListView.NodeControl.Destroy.DeleteSelection();
     MaxUI.RedrawViewportsNow();
 }
Exemplo n.º 5
0
        public Boolean Click(OlvListViewHitTestInfo hti)
        {
            if (hti.ColumnIndex > 0)
            {
                if (hti.Column == ListView.NlmColumns.ColorColumn)
                {
                    // Should the check states be changed on the selection, or on an item outside of selection.
                    // If inside selection, suppress change in selection by returning true.
                    // If outside selection, change the single item and return false.
                    if (hti.Item.Selected)
                    {
                        NlmMaxColorPicker colorPicker = new NlmMaxColorPicker(hti, true, ListView);
                        colorPicker.ShowModeless();
                        return(true);
                    }
                    else
                    {
                        NlmMaxColorPicker colorPicker = new NlmMaxColorPicker(hti, false, ListView);
                        colorPicker.ShowModeless();
                        // Returning false annoyingly pushes the window to the back.
                        // TODO: Somehow make this dialog modal, or at least parented to 3ds Max, and sort out the focus issue.
                        return(true);
                    }
                }
                if (hti.Column == ListView.NlmColumns.CurrentColumn)
                {
                    BaseTreeNode treeNode = hti.RowObject as BaseTreeNode;
                    if (treeNode is LayerTreeNode)
                    {
                        ListView.BeginUpdate();
                        hti.Column.PutValue(treeNode, true);
                        ListView.EndUpdate();
                    }
                    return(hti.Item.Selected);
                }
                else
                {
                    Boolean    htiItemSelected = hti.Item.Selected;
                    INLMColumn column          = hti.Column as INLMColumn;

                    // Should the check states be changed on the selection, or on an item outside of selection.
                    // If inside selection, suppress change in selection by returning true.
                    // If outside selection, change the single item and return false.
                    if (htiItemSelected)
                    {
                        column.AspectEngine.ToggleCheckStates(hti.RowObject);
                        ListView.RefreshObjects(ListView.SelectedObjects);
                    }
                    else
                    {
                        column.AspectEngine.ToggleCheckState(hti.RowObject);
                        ListView.RefreshObject(hti.RowObject);
                    }

                    MaxUI.RedrawViewportsNow();
                    return(htiItemSelected);
                }
            }
            return(false);
            // Returning true means selection does not change, returning false means it does.
        }