Beispiel #1
0
        private void g_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {

            BackgroundWorker bg = new BackgroundWorker();
            bg.DoWork += (s2, e2) => { System.Threading.Thread.Sleep(500); };
            bg.RunWorkerCompleted += (s2, e2) => { DragDrop.DragDropHelper.Cancel(); };

            if (_ro)
                return;

            foreach (Window w in Application.Current.Windows)
            {
                if (((Window1)w).BasedOn != null &&
                    ((Window1)w).MyEditLevel == Window1.EditLevel.EDIT &&
                    ((Window1)w).BasedOn.AbGate.Name == ((UIGates.IC)sender).AbGate.Name)
                {
                    w.Activate();
                    return;
                }
            }

            UIGates.IC template = ((UIGates.IC)sender).CreateUserInstance() as UIGates.IC;
            ((Gates.IC)template.AbGate).Circuit.Start();
            Window1 icw = new Window1(template, icl, Window1.EditLevel.EDIT);


            icw.Show();
            icw.Closing += (s2, e2) =>
            {
                try
                {

                    
                    // only replace gates if changes made
                    if (!icw.gateCanvas.UndoProvider.IsAtSavePoint)
                    {
                        UIGates.IC oic = icl.GetIC(icw.BasedOn.AbGate.Name);
                        UIGates.IC nic = icw.GetIC();

                        // check for recursion
                        // can bypass the selector if you are sneaky
                        foreach (Gates.AbstractGate ag in ((Gates.IC)nic.AbGate).Circuit)
                        {
                            if (ag is Gates.IC)
                            {
                                if (((Gates.IC)ag).DeepIncludes(((UIGates.IC)nic).AbGate.Name)) 
                                {
                                    MessageBox.Show("Recursive circuit detected");
                                    return;
                                }
                            }
                        }

                        // check for decreased inputs
                        // can't undo
                        if (oic.AbGate.NumberOfInputs > nic.AbGate.NumberOfInputs)
                        {
                            if (MessageBox.Show("Reducing the number of inputs will affect all instances of this IC in all circuits.  This operation cannot be undone. Proceed?", "Danger Zone", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) != MessageBoxResult.Yes)
                                return;


                        }

                        icl[icl.IndexOf(oic)] = nic;
                        if (undoProvider != null)
                            undoProvider.Add(new UndoRedo.ReplaceIC(icl, oic, nic));

                    }

                }
                catch (Exception) { } // can fail if this IC has been removed

                ((Gates.IC)template.AbGate).Circuit.Stop();

            };

            icl.ChangeIC += (s2, e2) =>
            {
                if (e2.original.AbGate.Name == ((UIGates.IC)sender).AbGate.Name)
                {
                    if (e2.newic == null)
                    {
                        icw.Close();
                    }
                    else
                    {
                        // find the gate being edited
                        foreach (UIGates.IC g in spGates.Children)
                            if (g.AbGate.Name == e2.newic.AbGate.Name)
                                icw.RefreshGateCanvas(g.CreateUserInstance() as UIGates.IC);
                    }
                }
            };
            
            

        }
Beispiel #2
0
 private void uigate_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     Window1 icw = new Window1((UIGates.IC)sender, icl, Window1.EditLevel.VIEW);
     
     icw.Show();
     Gates.AbstractGate org = ((UIGates.IC)sender).AbGate;
     c.ReplaceGates += (s2, e2) =>
     {
         if (e2.ContainsKey(org))
         {
             if (e2[org] == null)
             {
                 icw.Close();
             }
             else
             {
                 icw.RefreshGateCanvas((UIGates.IC)gates[e2[org]]);
                 org = e2[org];
             }
         }
     };
     
     
     
 }
Beispiel #3
0
        private void g_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            BackgroundWorker bg = new BackgroundWorker();

            bg.DoWork             += (s2, e2) => { System.Threading.Thread.Sleep(500); };
            bg.RunWorkerCompleted += (s2, e2) => { DragDrop.DragDropHelper.Cancel(); };

            if (_ro)
            {
                return;
            }

            foreach (Window w in Application.Current.Windows)
            {
                if (((Window1)w).BasedOn != null &&
                    ((Window1)w).MyEditLevel == Window1.EditLevel.EDIT &&
                    ((Window1)w).BasedOn.AbGate.Name == ((UIGates.IC)sender).AbGate.Name)
                {
                    w.Activate();
                    return;
                }
            }

            UIGates.IC template = ((UIGates.IC)sender).CreateUserInstance() as UIGates.IC;
            ((Gates.IC)template.AbGate).Circuit.Start();
            Window1 icw = new Window1(template, icl, Window1.EditLevel.EDIT);


            icw.Show();
            icw.Closing += (s2, e2) =>
            {
                try
                {
                    // only replace gates if changes made
                    if (!icw.gateCanvas.UndoProvider.IsAtSavePoint)
                    {
                        UIGates.IC oic = icl.GetIC(icw.BasedOn.AbGate.Name);
                        UIGates.IC nic = icw.GetIC();

                        // check for recursion
                        // can bypass the selector if you are sneaky
                        foreach (Gates.AbstractGate ag in ((Gates.IC)nic.AbGate).Circuit)
                        {
                            if (ag is Gates.IC)
                            {
                                if (((Gates.IC)ag).DeepIncludes(((UIGates.IC)nic).AbGate.Name))
                                {
                                    MessageBox.Show("Recursive circuit detected");
                                    return;
                                }
                            }
                        }

                        // check for decreased inputs
                        // can't undo
                        if (oic.AbGate.NumberOfInputs > nic.AbGate.NumberOfInputs)
                        {
                            if (MessageBox.Show("Reducing the number of inputs will affect all instances of this IC in all circuits.  This operation cannot be undone. Proceed?", "Danger Zone", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) != MessageBoxResult.Yes)
                            {
                                return;
                            }
                        }

                        icl[icl.IndexOf(oic)] = nic;
                        if (undoProvider != null)
                        {
                            undoProvider.Add(new UndoRedo.ReplaceIC(icl, oic, nic));
                        }
                    }
                }
                catch (Exception) { } // can fail if this IC has been removed

                ((Gates.IC)template.AbGate).Circuit.Stop();
            };

            icl.ChangeIC += (s2, e2) =>
            {
                if (e2.original.AbGate.Name == ((UIGates.IC)sender).AbGate.Name)
                {
                    if (e2.newic == null)
                    {
                        icw.Close();
                    }
                    else
                    {
                        // find the gate being edited
                        foreach (UIGates.IC g in spGates.Children)
                        {
                            if (g.AbGate.Name == e2.newic.AbGate.Name)
                            {
                                icw.RefreshGateCanvas(g.CreateUserInstance() as UIGates.IC);
                            }
                        }
                    }
                }
            };
        }