Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 private Rect GetTerminalBounds(Gate tg, Rect gRect, Gate.TerminalID tid)
 {
     //Warning: Without Rotation support right now
     //All the heuristic values
     
     //TODO tg rotation
     if(tg is UIGates.UserInput)
     {
        return new Rect(gRect.Left  + (gRect.Width * 3) / 4, gRect.Top, gRect.Width / 4, gRect.Height);
     }
     else if (tg is UIGates.UserOutput)
     {
         return new Rect(gRect.Left - 10, gRect.Top, gRect.Width / 4 + 10, gRect.Height);
     }
     else if(tg is UIGates.Not)
     {  
         if(tid.isInput)
         {
             return new Rect(gRect.Left - 10, gRect.Top, gRect.Width / 4 + 10, gRect.Height);
         }
         else
         {
             return new Rect(gRect.Left + (gRect.Width * 3) / 4, gRect.Top, gRect.Width / 4 + 10, gRect.Height);
         }
     }else
     {
         //AND,XOR and OR
         //Input Terminal
         if(tid.isInput)
         {
             if (tid.ID == 0)
             {
                 //Down input side
                 return new Rect(gRect.Left - 10, gRect.Top + gRect.Height / 2, gRect.Width / 4 + 10, gRect.Height / 2);
             }
             else
             {
                 //Upper input side
                 return new Rect(gRect.Left - 10, gRect.Top, gRect.Width / 4 + 10, gRect.Height / 2);
             }
             
         }
         else
         {
             return new Rect(gRect.Left + (gRect.Width * 3) / 4, gRect.Top, gRect.Width / 4 + 10, gRect.Height);
         }
        
     }
 }
Ejemplo n.º 3
0
        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);
            circuitInkCanvas.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);
            uigate.StylusUp +=new StylusEventHandler(uigate_StylusUp);

          /*
            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 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;
            }
             * 
             * */

            //BOKANG
            /*
            if (uigate is UIGates.UserIO) {
                ((UIGates.UserIO)uigate).UndoProvider = UndoProvider;
                if (uigate is UIGates.UserInput)
                {
                    string inputLabel = UserIOLabelList.inputLabelList[0];
                    ((UIGates.UserInput)uigate).UserIOLabel = inputLabel;
                    UserIOLabelList.inputLabelList.Remove(inputLabel);
                }
                else if (uigate is UIGates.UserOutput)
                {
                    string outputLabel = UserIOLabelList.outputLabelList[0];
                    ((UIGates.UserOutput)uigate).UserIOLabel = outputLabel;
                    UserIOLabelList.outputLabelList.Remove(outputLabel);
                }
            }
             * */
            
            if (uigate is UIGates.Comment)
                ((UIGates.Comment)uigate).UndoProvider = UndoProvider;
             SetInfoLine(uigate);
        }
Ejemplo n.º 4
0
        public void RemoveGate(Gate uigate)
        {
            c.Remove(uigate.AbGate);
            uigate.MouseDown -= new MouseButtonEventHandler(uigate_MouseDown);
            //uigate.MouseUp -= new MouseButtonEventHandler(uigate_MouseUp);
            uigate.StylusUp -= new StylusEventHandler(uigate_StylusUp);

            if (uigate is UIGates.UserIO)
            {
                if (uigate is UIGates.UserInput)
                {
                    string inputLabel = ((UIGates.UserInput)uigate).UserIOLabel;
                    UserIOLabelList.inputLabelList.Add(inputLabel);
                }
                else if (uigate is UIGates.UserOutput)
                {
                    string outputLabel = ((UIGates.UserOutput)uigate).UserIOLabel;
                    UserIOLabelList.outputLabelList.Add(outputLabel);
                }
            }

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

        }
Ejemplo n.º 5
0
        private void SetInfoLine(Gate g)
        {
            if (_ro)
            {
            }
            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";
                }

            }
        }
Ejemplo n.º 6
0
 public GTerm(Gates.AbstractGate gate, double offset, Gate.Position pos)
 {
     this.pos = pos;
     this.offset = offset;
     this.gate = gate;
 }