示例#1
0
        /// <summary>
        /// Performs a recursive topological sort of a set of ICs.
        /// The result list may include ICs not in the original ics input
        /// if they are used somewhere within the ics input.  All results
        /// will be dereferenced against the IC list provided so that
        /// the result IC instances are "canonical".
        /// </summary>
        /// <param name="ics"></param>
        /// <param name="icl"></param>
        /// <returns></returns>
        public List <UIGates.IC> Sort(IEnumerable <UIGates.IC> ics, ICList icl)
        {
            List <Gates.IC> gics = new List <Gates.IC>();

            foreach (UIGates.IC ic in ics)
            {
                gics.Add((Gates.IC)ic.AbGate);
            }

            Sort(gics);

            List <UIGates.IC> res = new List <GatesWpf.UIGates.IC>();

            foreach (Gates.IC gic in results)
            {
                res.Add(icl.GetIC(gic.Name));
            }
            return(res);
        }
示例#2
0
        private void AddDragDropGate(int pos, UIGates.IC g)
        {
            g.DataContext = g.CreateUserInstance();


            DragDrop.DragDropHelper.SetIsDragSource(g, true);
            DragDrop.DragDropHelper.SetDragDropControl(g, new DragDrop.GateDragDropAdorner());
            DragDrop.DragDropHelper.SetDropTarget(g, "gateCanvas");
            DragDrop.DragDropHelper.SetAdornerLayer(g, "adornerLayer");


            g.PreviewICNameChanged += (object sender2, string newname, ref bool cancel) =>
            {
                if (newname == "")
                {
                    cancel = true;
                }

                foreach (Gate g2 in icl)
                {
                    if (newname == g2.AbGate.Name)
                    {
                        cancel = true;
                    }
                }
            };

            g.ICNameChanged += (sender2, newname) =>
            {
                UIGates.IC oic = icl.GetIC((g.AbGate.Name));
                UIGates.IC nic = g.CreateUserInstance(newname);
                icl[icl.IndexOf(oic)] = nic;
                if (undoProvider != null)
                {
                    undoProvider.Add(new UndoRedo.ReplaceIC(icl, oic, nic));
                }
            };

            ScaleTransform st = new ScaleTransform();

            st.CenterX = g.Width / 2.0;
            st.CenterY = g.Height / 2.0;
            double fac = 1.0;

            if (g.Width > MAX_SIZE)
            {
                fac = Math.Min(MAX_SIZE / g.Width, fac);
            }

            if (g.Height > MAX_SIZE)
            {
                fac = Math.Min(MAX_SIZE / g.Height, fac);
            }
            st.ScaleY         = fac;
            st.ScaleX         = fac;
            g.LayoutTransform = st;


            g.ContextMenu = new ContextMenu();
            MenuItem exp = new MenuItem();

            exp.Header = "Export...";
            exp.Click += (sender2, e2) =>
            {
                Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                dlg.DefaultExt = ".ic";
                dlg.Filter     = "IC (.ic)|*.ic";
                bool?result = dlg.ShowDialog();

                if (result == true)
                {
                    CircuitXML cxml = new CircuitXML(icl);
                    try
                    {
                        cxml.Save(dlg.FileName, g);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to save IC: " + ex.ToString());
                    }
                }
            };
            g.ContextMenu.Items.Add(exp);
            MenuItem del = new MenuItem();

            del.Header = "Delete";
            del.Click += (sender2, e2) =>
            {
                if (MessageBox.Show("All instances of this IC in all circuits will be removed.  This operation cannot be undone.  Proceed?", "Danger Zone", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    UIGates.IC todel = icl.GetIC(g.AbGate.Name);

                    icl.Remove(todel);
                    if (undoProvider != null)
                    {
                        undoProvider.Clear();
                    }
                }
            };
            g.ContextMenu.Items.Add(del);
            MenuItem hid = new MenuItem();

            hid.Header = "Hide";
            hid.Click += (sender2, e2) =>
            {
                g.Visibility = Visibility.Collapsed;
            };
            //g.ContextMenu.Items.Add(hid);

            spGates.Children.Insert(pos, g);
            g.MouseDoubleClick     += new MouseButtonEventHandler(g_MouseDoubleClick);
            expUserGates.IsExpanded = true;
            g.BringIntoView();
            g.IsReadOnly            = _ro;
            g.ContextMenu.IsEnabled = !_ro;


            if (!string.IsNullOrEmpty(_icname))
            {
                if (((Gates.IC)g.AbGate).DeepIncludes(_icname))
                {
                    g.Visibility = Visibility.Collapsed;
                }
            }

            ((Gates.IC)g.AbGate).Circuit.Start();

            SetInfoLine(g);
        }