示例#1
0
        private void btnSave_As_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.DefaultExt = ".gcg";
            dlg.Filter     = "Gate Circuit Groups (.gcg)|*.gcg";
            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                CircuitXML cxml = new CircuitXML(icl);
                try
                {
                    cxml.Save(dlg.FileName, gateCanvas);
                    _filename         = dlg.FileName;
                    btnSave.IsEnabled = true;
                    UpdateTitle();

                    ((UndoRedo.UndoManager)Resources["undoManager"]).SetSavePoint();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to save circuit as requested: " + ex.ToString());
                }
            }
        }
示例#2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            CircuitXML cxml = new CircuitXML(icl);

            cxml.Save(_filename, gateCanvas);

            ((UndoRedo.UndoManager)Resources["undoManager"]).SetSavePoint();
        }
示例#3
0
        private void btnSave_As_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.DefaultExt = ".gcg";
            dlg.Filter = "Gate Circuit Groups (.gcg)|*.gcg";
            bool? result = dlg.ShowDialog();

            if (result == true)
            {
                CircuitXML cxml = new CircuitXML(icl);
                try
                {
                    cxml.Save(dlg.FileName, gateCanvas);
                    _filename = dlg.FileName;
                    btnSave.IsEnabled = true;
                    UpdateTitle();

                    ((UndoRedo.UndoManager)Resources["undoManager"]).SetSavePoint();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to save circuit as requested: " + ex.ToString());
                }
            }
        }
示例#4
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            
            CircuitXML cxml = new CircuitXML(icl);
            cxml.Save(_filename, gateCanvas);

            ((UndoRedo.UndoManager)Resources["undoManager"]).SetSavePoint();
            
        }
示例#5
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);
            
        }
示例#6
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);
        }