Пример #1
0
        public ConnectedWire(Gates.AbstractGate originGate, Gate.TerminalID origin, Gates.AbstractGate destGate, Gate.TerminalID dest)
            : base()
        {

            if (origin.isInput || !dest.isInput)
            {
                throw new ArgumentException("Can only connect output (origin) to input (dest)");
            }

            Value = false;
            this.originGate = originGate;
            this.destGate = destGate;
            this.origin = origin;
            this.dest = dest;
            //originGate.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(originGate_PropertyChanged);
            originGate.PropertyChanged += EventDispatcher.CreateBatchDispatchedHandler(originGate, originGate_PropertyChanged);
            Connect();
            
            
        }
Пример #2
0
 public GTerm(Gates.AbstractGate gate, double offset, Gate.Position pos)
 {
     this.pos = pos;
     this.offset = offset;
     this.gate = gate;
 }
Пример #3
0
        /// <summary>
        /// Removes a given gate from the canvas and the circuit.
        /// No undo event created.
        /// </summary>
        /// <param name="uigate"></param>
        public void RemoveGate(Gate uigate)
        {
            c.Remove(uigate.AbGate);
            uigate.MouseDown -= new MouseButtonEventHandler(uigate_MouseDown);
            uigate.MouseUp -= new MouseButtonEventHandler(uigate_MouseUp);

            if (uigate is UIGates.IC)
                uigate.MouseDoubleClick -= new MouseButtonEventHandler(uigate_MouseDoubleClick);


        }
Пример #4
0
        /// <summary>
        /// Add a pre-existing visual gate at a particular location.  The gate will also
        /// be added to the circuit if it is not already a member.
        /// </summary>
        /// <param name="uigate"></param>
        /// <param name="pos"></param>
        public void AddGate(Gate uigate, GateLocation pos)
        {
            

            Gates.AbstractGate gate = uigate.AbGate;

            gates[gate] = uigate;
            uigate.Margin = new Thickness(pos.x, pos.y, 0, 0);
            GC.Children.Add(uigate);
            if (!c.Contains(gate))
                c.Add(gate);

            uigate.RenderTransform = new RotateTransform(pos.angle, uigate.Width / 2.0, uigate.Height / 2.0);
            uigate.Tag = new GateLocation() { x = pos.x, y = pos.y, angle = pos.angle };

            // NOTE that we need a separate angle and transform
            // for the snap-to to work properly
            // so I am using the tag to store the angle
            
            uigate.MouseDown += new MouseButtonEventHandler(uigate_MouseDown);
            uigate.MouseUp += new MouseButtonEventHandler(uigate_MouseUp);

            if (uigate is UIGates.IC)
            {
                uigate.MouseDoubleClick += new MouseButtonEventHandler(uigate_MouseDoubleClick);
                uigate.ContextMenu = new ContextMenu();
                MenuItem inline = new MenuItem();
                inline.Header = "Inline Circuit";
                inline.Tag = uigate;
                uigate.ContextMenu.Items.Add(inline);
                inline.Click += new RoutedEventHandler(inline_Click);
                uigate.ContextMenu.IsEnabled = !IsReadOnly;

            }

            // can add inputs
            if (uigate.AbGate is Gates.IVariableInputs)
            {
                uigate.ContextMenu = new ContextMenu();
                MenuItem addInput = new MenuItem();
                addInput.Header = "Add Input";
                addInput.Tag = uigate;
                uigate.ContextMenu.Items.Add(addInput);
                addInput.Click += (sender2, e2) =>
                {
                    Gates.AbstractGate newgate = ((Gates.IVariableInputs)uigate.AbGate).Clone(uigate.AbGate.NumberOfInputs + 1);
                    c.ReplaceGate(uigate.AbGate, newgate);
                    if (UndoProvider != null)
                        UndoProvider.Add(new UndoRedo.ChangeNumInputs(c, uigate.AbGate, newgate));

                };
                if (uigate.AbGate.NumberOfInputs > 2)
                {
                    MenuItem removeInput = new MenuItem();
                    removeInput.Header = "Remove Input";
                    removeInput.Tag = uigate;
                    uigate.ContextMenu.Items.Add(removeInput);
                    removeInput.Click += (sender2, e2) =>
                    {
                        UndoRedo.Transaction removeInp = new GatesWpf.UndoRedo.Transaction("Remove Input");

                        // remember wires connected to removed input
                        Gates.Terminal dest = new Gates.Terminal(uigate.AbGate.NumberOfInputs - 1, uigate.AbGate);
                        Gates.Terminal origin = c.GetSource(dest);
                        if (origin != null)
                            removeInp.Add(new UndoRedo.Reverse(new UndoRedo.ConnectWire(c, origin, dest)));

                        Gates.AbstractGate newgate = ((Gates.IVariableInputs)uigate.AbGate).Clone(uigate.AbGate.NumberOfInputs - 1);
                        c.ReplaceGate(uigate.AbGate, newgate);
                        
                        removeInp.Add(new UndoRedo.ChangeNumInputs(c, uigate.AbGate, newgate));
                        if (UndoProvider != null)
                            UndoProvider.Add(removeInp);


                    };
                }

                uigate.ContextMenu.IsEnabled = !IsReadOnly;
            }

            if (uigate is UIGates.UserIO)
                ((UIGates.UserIO)uigate).UndoProvider = UndoProvider;

            if (uigate is UIGates.Comment)
                ((UIGates.Comment)uigate).UndoProvider = UndoProvider;

            SetInfoLine(uigate);
            
                
        }
Пример #5
0
        private void SetInfoLine(Gate g)
        {
            if (_ro)
            {
                InfoLine.SetInfo(g, "");

                

            } 
            else
            {
                string infoline = "Left-drag to move, right-drag to rotate, left-drag terminals to connect";

                if (g is UIGates.IC)
                    infoline += ", double-click to view, right-click for options";

                if (g is UIGates.UserIO)
                    infoline += ", right-click to rename";

                if (g is UIGates.Numeric)
                    infoline += ", click on the representation to change";

                if (g is UIGates.Numeric || g is UIGates.Clock || g is UIGates.Comment)
                    infoline += ", click and type to enter a value";

                if (g.AbGate is Gates.IVariableInputs)
                {
                    // can only remove if more than 2
                    infoline += ", right-click to add" + (g.AbGate.NumberOfInputs > 2 ? "/remove" : "") + " inputs";
                }

                InfoLine.SetInfo(g, infoline);

                
            }
        }