Esempio n. 1
0
        public GateInkCanvas(UIGates.IC ic, ICList icl)
            : this(((Gates.IC)ic.AbGate).Circuit, icl) 
        {
            ICName = ic.AbGate.Name;

            foreach (KeyValuePair<Gates.AbstractGate, GateLocation> gp in ic.locationHints)
            {
                if (gp.Key is Gates.IC)
                {
                    // must get terminal id template
                    UIGates.IC templateic = icl.GetIC(gp.Key.Name);
                    
                    AddGate(UIGates.IC.CreateFromTemplate( (Gates.IC)gp.Key, templateic), gp.Value);
                } else
                AddGate(gp.Key, gp.Value);
            }
           // this.Loaded += ((sender, e) =>
            {
                foreach (KeyValuePair<Gates.AbstractGate, GateLocation> gp in ic.locationHints)
                {
                    for (int i = 0; i < gp.Key.NumberOfInputs; i++)
                    {
                        Gates.Terminal inp = new Gates.Terminal(i, gp.Key);
                        if (c.GetSource(inp) != null)
                        {
                            c_CircuitConnection(c, inp,
                                c.GetSource(inp));
                        }
                    }
                }
            }//);

            this.Loaded += (sender, e) => { UpdateWireConnections(); };
        }
Esempio n. 2
0
        public void circuitInkCanvas_StylusUp(object sender, StylusEventArgs e)
        {
            if (IsPieMenuVisible)
            {
                PieMenuHitTestEventArgs hitargs = new PieMenuHitTestEventArgs(e.GetPosition(this), e, PieMenuHitTestEventArgs.EventType.Up);
                hitPieMenuHandler(this, hitargs);
            }

            //Make Pie Menu Invisible
            PieMenuEventArgs args = new PieMenuEventArgs(false);
            triggerPieMenuHandler(this, args);

            Point mp2 = e.GetPosition(circuitInkCanvas);

            foreach (UIElement gate in circuitInkCanvas.Children)
            {
                if (gate is Gate)
                {
                    Gate g = gate as Gate;
                    Rect grect = new Rect(g.Margin.Left - 10, g.Margin.Top - 10, g.Width + 10, g.Height + 10);

                    bool condition = false;
                    condition = grect.Contains(mp2);
                    if (condition)
                    {
                        uigate_StylusUp(g ,e);
                        break;
                    }
                }else if(gate is ConnectedWire)
                {
                    HitTestResult result = VisualTreeHelper.HitTest(gate, mp2);
                    if(result != null)
                    {
                        Debug.WriteLine("Hit Test Wire circuitInkCanvas_StylusUp");
                        //Image stroke starts from one terminal and stop at this wire
                        //1. through this wire, create new wire to connect existing wire's 
                        //if stroke starts from input terminal from one gate, then search for input terminal from existing wire.
                        //otherwise stroke starts from the output termianl from one gate, then search for output terminal from existing wire. 
                        ConnectedWire myWire = gate as ConnectedWire;

                        //new wire's destination is mp2; new wire's orignal is ???
                        if (onGateStroke)
                        { 
                            //start the stroke from gate terminal
                            Gate.TerminalID tid = myWire.OriginTerminalID;

                            Gates.Terminal origin = null, dest = null;

                            if (tid.isInput && dragging == DragState.CONNECT_FROM &&
                                !wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))
                            {
                                origin = new Gates.Terminal(beginTID.ID, beginTID.abgate);
                                dest = new Gates.Terminal(tid.ID, tid.abgate);
                            }


                            if (!tid.isInput && dragging == DragState.CONNECT_TO)
                            {
                                origin = new Gates.Terminal(tid.ID, tid.abgate);
                                dest = new Gates.Terminal(beginTID.ID, beginTID.abgate);

                            }

                            if (origin != null)
                            {
                                c[dest] = origin;
                                UndoRedo.ConnectWire cw = new UndoRedo.ConnectWire(c, origin, dest);

                                if (UndoProvider != null)
                                    UndoProvider.Add(cw);
                            }
                        }
                        break;
                    }
                }
            }

            dragging = DragState.NONE;
            //dragSelect.Width = 0;
            //dragSelect.Height = 0;
            //dragSelect.Margin = new Thickness(0, 0, 0, 0);
            //dragSelect.Visibility = Visibility.Hidden;

            dragWire.Destination = new Point(0, 0);
            dragWire.Origin = new Point(0, 0);

            // unhightlight all
            foreach (Gates.AbstractGate ag in gates.Keys)
            {

                for (int i = 0; i < ag.Output.Length; i++)
                {
                    gates[ag].FindTerminal(false, i).t.Highlight = false;
                }

                for (int i = 0; i < ag.NumberOfInputs; i++)
                {
                    gates[ag].FindTerminal(true, i).t.Highlight = false;
                }
            }

            if (UndoProvider != null && moves != null && moves.Count > 0)
                UndoProvider.Add(moves);
            moves = null;

            ReadyToSelect = false;
        }
Esempio n. 3
0
        private bool CheckRemoveGate(Stroke stroke)
        {
            Rect strokeBound = stroke.GetBounds();

            bool removeGate = false;

            List<Gate> removedGates = new List<Gate>();
            
            for(int i = 0; i < circuitInkCanvas.Children.Count; i++)
            {
                UIElement gate = circuitInkCanvas.Children[i];
                
                if (gate is Gate)
                {
                    Gate g = gate as Gate;

                    Rect grect = new Rect(g.Margin.Left + 40, g.Margin.Top + 40, g.Width - 40, g.Height - 40);

                    if (strokeBound.Contains(grect))
                    {   
                        //this.RemoveGate(g);
                        removedGates.Add(g);
                        removeGate = true;
                    } 
                }else if(gate is ConnectedWire)
                {
                    ConnectedWire wire = gate as ConnectedWire;

                    //Debug.WriteLine("Stroke Rect Bound: " + strokeBound.ToString());
                    //Debug.WriteLine("Wire Origin is " + wire.Origin.ToString());
                    //Debug.WriteLine("Wire Destination is " + wire.Destination.ToString());

                    //Debug.WriteLine("Wire Outer Margin is " + wire.Outer.Margin.ToString());

                    HitTestResult result = null;
                    int count = 0;
                    foreach(StylusPoint pt in stroke.StylusPoints)
                    {
                        result = VisualTreeHelper.HitTest(wire, pt.ToPoint());
                        if(result != null)
                        {
                            count++;
                        }
                    }

                    //Debug.WriteLine("Count is " + count.ToString());
                    if(count >= 3)
                    {

                        //trigger remove wire
                        //From connectedWire to get terminal

                        Gates.Terminal t = new Gates.Terminal(wire.DestTerminalID.ID, wire.DestinationGate);
                        c.Disconnect1(t);
                        circuitInkCanvas.Children.Remove(wire);

                        /*
                        for (int j = 0; j < wire.DestinationGate.NumberOfInputs; j++)
                        {
                            Gates.Terminal t = new Gates.Terminal(j, wire.DestinationGate);

                            //Gates.Terminal t = new Gates.Terminal(j, wire.OriginGate);
                            if (t != null)
                            {
                                c.Disconnect1(t);

                                circuitInkCanvas.Children.Remove(wire);
                            }
                        }
                         */
                        
                        removeGate = true;
                    }
                }
            }
            
            if(removeGate)
            {
                foreach (Gate g in removedGates)
                {
                    this.RemoveGate(g);
                } 
                return true;
            }

            return false;
         }
Esempio n. 4
0
        void uigate_StylusUp(object sender, StylusEventArgs e)
        {
            Point mp2 = e.GetPosition(circuitInkCanvas);
            Gate tg = (Gate)sender;

            Rect gRect = new Rect(tg.Margin.Left, tg.Margin.Top, tg.Width, tg.Height);

            if (dragging == DragState.CONNECT_FROM ||
            dragging == DragState.CONNECT_TO)
            {
                foreach (Gate.TerminalID tid in (Gate)sender)
                {
                    Rect tRect = GetTerminalBounds(tg, gRect, tid);
                    bool condition = tRect.Contains(mp2);
                    if(condition)
                    //if (mp2.X >= tRect.Value.Left - 10 && mp2.X <= tRect.Value.Right + 10
                    //   && mp2.Y >= tRect.Value.Top - 10 && mp2.Y <= tRect.Value.Bottom + 10)
                    //if (tid.t.IsMouseOver)
                    {
                        Gates.Terminal origin = null, dest = null;

                        if (tid.isInput && dragging == DragState.CONNECT_FROM &&
                            !wires.ContainsKey(new Gates.Terminal(tid.ID, tid.abgate)))
                        {
                            origin = new Gates.Terminal(beginTID.ID, beginTID.abgate);
                            dest = new Gates.Terminal(tid.ID, tid.abgate);
                        }


                        if (!tid.isInput && dragging == DragState.CONNECT_TO)
                        {
                            origin = new Gates.Terminal(tid.ID, tid.abgate);
                            dest = new Gates.Terminal(beginTID.ID, beginTID.abgate);

                        }

                        if (origin != null)
                        {
                            c[dest] = origin;
                            UndoRedo.ConnectWire cw = new UndoRedo.ConnectWire(c, origin, dest);

                            if (UndoProvider != null)
                                UndoProvider.Add(cw);
                        }

                        break;
                    }
                }
            }
        }