protected void SetThisTool(Utensile tool)
        {
            try
            {
                if (tool == null)
                {
                    return;
                }

                var matGuid = Singleton.Instance.MaterialeGuid;

                tool.SelectParameter(matGuid);

                Operazione.SetTool(tool);

                _utensileViewModel = ToolTreeViewItemViewModel.GetViewModel(Operazione.Utensile, null);

                _utensileViewModel.OnUpdated += ChildViewModelUpdated;

                OnPropertyChanged("UtensileViewModel");
            }
            catch (Exception ex)
            {
                throw new Exception("OperazioneViewModel.AutoToolFind");
            }
        }
Beispiel #2
0
        private void UpdateTreeView()
        {
            var previousTreeView = TreeView;

            var newTreeView = new ObservableCollection <TreeViewItemViewModel>();

            var ts = _magazzinoUtensile.GetTools <Utensile>(_measureUnit);

            var tipies = from t in ts
                         group t by t.GetType()
                         into tg
                         select tg;

            foreach (var tipy in tipies)
            {
                string groupName;

                _toolDictName.TryGetValue(tipy.Key, out groupName);

                var toolTypeTreeView = new ToolTypeItemViewModel(groupName);

                toolTypeTreeView.OnItemSelected += OnItemSelected;

                newTreeView.Add(toolTypeTreeView);

                foreach (var utensile in tipy)
                {
                    var t = ToolTreeViewItemViewModel.GetViewModel(utensile, toolTypeTreeView);

                    t.OnItemSelected += OnItemSelected;

                    toolTypeTreeView.Children.Add(t);
                }
            }

            /*
             * Ora itero vecchio albero per mantenere struttura,
             *
             */

            foreach (var treeViewItemViewModel in previousTreeView)
            {
                foreach (var toolTypeItemViewModel in newTreeView)
                {
                    if (treeViewItemViewModel.Label == toolTypeItemViewModel.Label && treeViewItemViewModel.IsExpanded)
                    {
                        toolTypeItemViewModel.IsExpanded = true;

                        var oldChildren = treeViewItemViewModel.Children.OfType <ToolTreeViewItemViewModel>();
                        var newChildre  = toolTypeItemViewModel.Children.OfType <ToolTreeViewItemViewModel>();

                        foreach (var oldChild in oldChildren)
                        {
                            if (oldChild.IsExpanded)
                            {
                                foreach (var newChild in newChildre)
                                {
                                    if (oldChild.Tool.ToolGuid == newChild.Tool.ToolGuid)
                                    {
                                        newChild.IsExpanded = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            TreeView = newTreeView;

            //if (TreeView.Count > 0)
            //    TreeView.Clear();

            //foreach (var keyValuePair in _toolDictName)
            //{
            //    var tools = _magazzinoUtensile.GetTools(keyValuePair.Key, _measureUnit);

            //    var drillTreeItem = new ToolTypeItemViewModel(keyValuePair.Value);

            //    drillTreeItem.OnItemSelected += TOnItemSelected;

            //    foreach (var drillTool in tools)
            //    {
            //        var t = ToolTreeViewItemViewModel.GetViewModel(drillTool, drillTreeItem);

            //        t.OnItemSelected += TOnItemSelected;

            //        drillTreeItem.Children.Add(t);
            //    }

            //    TreeView.Add(drillTreeItem);

            //}
        }