Beispiel #1
0
 protected static Gate GetGate(string name)
 {
     name = name.ToLower();
     if (NoStatedGates.TryGetValue(name, out var gate))
     {
         return(gate);
     }
     return(Gates[name]());
 }
Beispiel #2
0
        internal void GenerateSource()
        {
            int busCount = 0;

            for (int i = 0; i < Gates.Count(); i++)
            {
                var record = new DepartureInfo();
                record.Name          = Buses[busCount];
                record.RouteName     = Routes[i];
                record.Gate          = Gates[i];
                record.DepartureTime = DateTime.Now.AddHours(i % 2 == 0 ? 1.5:2);
                record.Icon          = ImageSource.FromResource("FilterListView.Images." + "Bus" + busCount + ".png");
                SecondLVCollection.Add(record);
                if (busCount == 4)
                {
                    busCount = 0;
                }
                else
                {
                    busCount++;
                }
            }
            ItemTapCommand     = new Command <Syncfusion.ListView.XForms.ItemTappedEventArgs>(ItemTapped);
            FavoriteTapCommand = new Command <object>(FavoriteTapped);
            ResetTapCommand    = new Command <object>(ResetTapped);
        }
Beispiel #3
0
        public FalstadCircuit(TTLGateTypeEnum gateTypes)
        {
            var andGate  = new AndGate(gateTypes, 2);
            var inverter = new Inverter(gateTypes);

            Gates.Add(andGate);
            Gates.Add(inverter);

            Connections.Add(new Connection
            {
                Source      = Input,
                Termination = andGate.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = Input,
                Termination = inverter.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = inverter,
                Termination = andGate.Inputs[1]
            });
        }
Beispiel #4
0
    public void CreateNewGates(int wave = 0)
    {
        Wave                  waveDefinition     = WaveDefinitions[wave];
        List <Entity>         spawnedEntities    = SpawnEntitiesFromDefinition(waveDefinition);
        List <Entity>         randomizedEntities = RandomizeList(spawnedEntities);
        List <List <Entity> > gatesEntities      = SplitEntityList(randomizedEntities);

        for (int idx = 0; idx < gatesEntities.Count; idx++)
        {
            Gate newGate = new Gate()
            {
                Position        = _floor.GetRandomSpawnLocation(),
                EntitiesToSpawn = gatesEntities[idx]
            };
            newGate.Init();
            GetTree().Root.CallDeferred("add_child", newGate);
            Gates.Add(newGate);
            newGate.Connect("Complete", this, "OnGateComplete");
            if (idx == 0)
            {
                newGate.ActivateOnReady = true;
            }
            else
            {
                Gates[idx - 1].Connect("ThresholdReached", newGate, "Activate");
            }
        }
    }
Beispiel #5
0
        public List <Gates> SelectGates(int currentUserType, int deploymentId)
        {
            MySqlParameter[] parameters = new MySqlParameter[] {
                new MySqlParameter("currentUserType", currentUserType),
                new MySqlParameter("p_deploymentId", deploymentId)
            };
            List <Gates> gatesCol = new List <Gates>();
            DataTable    dt       = MySQLDB.MySQLDBHelper.ExecuteSelectCommand("GetGates", CommandType.StoredProcedure, parameters);
            Gates        objGate  = null;

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    objGate              = new Gates();
                    objGate.GateId       = Convert.ToInt32(dr["GateId"].ToString());
                    objGate.GateName     = dr["GateName"].ToString();
                    objGate.DeploymentId = Convert.ToInt32(dr["DeploymentId"].ToString());
                    gatesCol.Add(objGate);
                }
            }
            dt.Clear();
            dt.Dispose();
            return(gatesCol);
        }
Beispiel #6
0
        private void PositionAndHold(Gates.AbstractGate g)
        {
            // determine quadrant
            Point gp = pos(g).GetPoint();
            // the goal here is to make the bracket square
            // and not rectangular if one side is longer


            double dx = gp.X - avgX;
            double dy = gp.Y - avgY;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                // left or right
                // note that we invert Y for left so it goes from bottom to top
                if (dx < 0)
                    posGates.Add(new GTerm(g, -gp.Y, Gate.Position.LEFT));
                else
                    posGates.Add(new GTerm(g, gp.Y, Gate.Position.RIGHT));
            }
            else
            {
                // top or bottom
                if (dy < 0)
                    posGates.Add(new GTerm(g, gp.X, Gate.Position.TOP));
                else
                    posGates.Add(new GTerm(g, gp.X, Gate.Position.BOTTOM));
            }

        }
Beispiel #7
0
        public HalfAdder(TTLGateTypeEnum gateType)
        {
            var xorGate = new XorGate(gateType, 2);
            var andGate = new AndGate(gateType, 2);

            Gates.Add(xorGate);
            Gates.Add(andGate);

            Connections.Add(new Connection
            {
                Source      = A,
                Termination = xorGate.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = B,
                Termination = xorGate.Inputs[1]
            });

            Connections.Add(new Connection
            {
                Source      = A,
                Termination = andGate.Inputs[0]
            });

            Connections.Add(new Connection
            {
                Source      = B,
                Termination = andGate.Inputs[1]
            });
        }
Beispiel #8
0
        public override void Tick()
        {
            lock (ThreadLocker)
            {
                if (GetGameSession() == null)
                {
                    Invalidate();
                    return;
                }

                if (!Controller.Active || EntityState == EntityStates.DEAD)
                {
                    return;
                }

                base.Tick();

                LevelChecker();
                TickBoosters();
                AssembleEnemyWarn();
                TickEvents();
                TickTechs();
                TickAbilities();
                TickQuests();
                TickAnnouncements();
                Skylab.Tick();
                Gates.Tick();
                State.Tick();
                Information.Tick();
            }
        }
Beispiel #9
0
        private void Gates_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            Gate gate;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                int addIndex = e.NewStartingIndex;
                foreach (object item in e.NewItems)
                {
                    gate = item as Gate;
                    if (gate != null)
                    {
                        RegisterRefModel gateRow = _model.GetRefFromOffset(addIndex);
                        Gates.Insert(addIndex, new GateVM(_model, gateRow, _column));
                        for (int i = addIndex + 1; i < _gates.Count; i++)
                        {
                            _gates[i].UpdateRow(i);
                        }
                        if (_gates.Count == 2)
                        {
                            _gates[0].UpdateDeleteRowCommand(true);
                            _gates[1].UpdateDeleteRowCommand(true);
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                foreach (object item in e.NewItems)
                {
                    gate = item as Gate;
                    for (int i = gate.Begin; i <= gate.End; i++)
                    {
                        Gates[i].Refresh();
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                int oldRow = e.OldStartingIndex;
                foreach (object item in e.OldItems)
                {
                    if (item is Gate)
                    {
                        Gates.RemoveAt(oldRow);
                        for (int i = oldRow; i < _gates.Count; i++)
                        {
                            _gates[i].UpdateRow(i);
                        }
                        if (_gates.Count == 1)
                        {
                            _gates[0].UpdateDeleteRowCommand(false);
                        }
                    }
                }
                break;
            }
            OnPropertyChanged("ScaleCenterY");
        }
Beispiel #10
0
        public void CarOut(string licensePlate, int camId)
        {
            Gate gate = Gates.FirstOrDefault(gt => gt.Id == camId);

            if (gate == null)
            {
                Form.Invoke((MethodInvoker) delegate { ConsoleLog.Add("Kameros klaida"); });
                return;
            }

            Vehicle vehicle = NotParkedVehicles.FirstOrDefault(veh => veh.LicensePlate == licensePlate);

            if (vehicle == null)
            {
                Form.Invoke((MethodInvoker) delegate { ConsoleLog.Add("Mašina sistemoje nerasta!!! " + licensePlate); });
                gate.OpenVehicle(licensePlate, false);
                return;
            }

            if (!vehicle.Paid)
            {
                if (ResidentsList.FirstOrDefault(s => s.LicensePlate == vehicle.LicensePlate) == null)
                {
                    Form.Invoke((MethodInvoker) delegate { ConsoleLog.Add("Važiuoja nesusimokėjus " + vehicle); });
                    return;
                }

                vehicle.Resident = true;
                vehicle.Paid     = true;
            }

            gate.OpenVehicle(licensePlate, false);
        }
Beispiel #11
0
        /// <summary>
        /// Get new gate
        /// </summary>
        /// <returns>Gate</returns>
        private static Gates GetNewGate()
        {
            Gates gate = Gates.G1;

            CheckEnum(out gate, "gate");
            return(gate);
        }
Beispiel #12
0
    private Transform CreateButton(int col, int row, int startHeight, int buttonNumber, bool isToggle)
    {
        // Button dimensions are the same as the prefab, so I don't change them here.
        var button = _assetPool.SpawnTransform(Constants.TAG_BUTTON);

        button.GetComponent <Collider>().material = noFrictionMaterial;

        var buttonCoordinates = new Vector3(col, startHeight, row);
        var buttonDimensions  = new Vector3(.5f, .25f, .5f);

        button.position = TransformUtils.GetLocalPositionFromGridCoordinates(buttonCoordinates, buttonDimensions);
        button.name     = CreateUniqueItemName(Constants.TAG_BUTTON + "_" + (isToggle ? "T_" : "NT_") + buttonNumber);
        button.GetComponent <ButtonController>().Toggleable = isToggle;

        // If gates already exist for this button, make sure to assign this button to them.
        List <Transform> gatesList;

        if (Gates.TryGetValue(buttonNumber, out gatesList))
        {
            foreach (var gate in gatesList)
            {
                gate.GetComponent <GateController>().Button = button.gameObject;
            }
        }

        Buttons[buttonNumber] = button.gameObject;
        return(button);
    }
Beispiel #13
0
        private bool IsEnabled(object thing)
        {
            var payload = new InstrumentationPayload {
                FeatureName = Name,
                Operation   = "enabled?",
            };

            if (thing != null)
            {
                payload.Thing = thing;
            }
            using (Instrumenter.InstrumentFeature(payload))
            {
                var  values   = GateValues;
                var  openGate = Gates.FirstOrDefault(gate => InstrumentGate(gate, "open?", thing, x => x.IsOpen(thing, values[x.Key], Name)));
                bool result;
                if (openGate != null)
                {
                    payload.GateName = openGate.Name;
                    result           = true;
                }
                else
                {
                    result = false;
                }
                payload.Result = result;
                return(result);
            }
        }
Beispiel #14
0
        public override string ToString()
        {
            var sb           = "Inputs: ";
            var inputWires   = InputWires;
            var usedInputs   = new List <int>();
            var inputWiresSB = "";

            foreach (BigWire wire in inputWires)
            {
                if (usedInputs.Contains(wire.InputIndex))
                {
                    continue;
                }

                inputWiresSB += wire.InputIndex + ", ";
                usedInputs.Add(wire.InputIndex);
            }
            sb += inputWiresSB.Substring(0, inputWiresSB.Length - 2) + " | ";
            foreach (BigGate gate in Gates)
            {
                sb += "Gate" + Gates.IndexOf(gate) + ": " + gate.Display(Gates) + " | ";
            }

            sb += "Output: Gate" + Gates.IndexOf(OutputGate);
            return(sb.ToString());
        }
Beispiel #15
0
        /// <summary>
        /// Recieve all information from user about flight for adding or editing
        /// </summary>
        /// <returns>flight</returns>
        private static Flight AskForFlight()
        {
            string       temp = string.Empty, flightNumber;
            Terminals    terminal = Terminals.A;
            Airlines     airline = Airlines.Airunes;
            DateTime     departDate = DateTime.Now, arrivDate = DateTime.Now;
            Cities       arrival = Cities.Berlin, departure = Cities.Berlin;
            Gates        gate   = Gates.G1;
            FlightStatus status = FlightStatus.Unknown;

            Console.WriteLine("Enter the flight number");
            flightNumber = Console.ReadLine().Trim();

            CheckEnum(out airline, "airline");

            CheckDate(out departDate, "departure");

            CheckDate(out arrivDate, "arrival");

            CheckEnum(out departure, "departure port");

            CheckEnum(out arrival, "arrival port");

            CheckEnum(out terminal, "terminal");

            CheckEnum(out gate, "gate");

            CheckEnum(out status, "flight status");

            return(new Flight(airline, flightNumber, departDate, arrivDate, departure, arrival, terminal, gate, status));
        }
Beispiel #16
0
        public static bool EqualsZero(Byte2 a)
        {
            var eq0high = EqualsZero(a.High);
            var eq0low  = EqualsZero(a.Low);

            return(Gates.And(eq0high, eq0low));
        }
Beispiel #17
0
        public static Byte2 Subtract(Byte2 a, Byte2 b)
        {
            var inverted    = Gates.Invert16(b);
            var incremented = Increment(inverted);

            return(AddByte2(a, incremented, false).Low);
        }
Beispiel #18
0
 public ParkingLotTests()
 {
     clock = new TestClock();
     lot   = new ParkingLot(clock, 15, TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(0));
     lot   = new ParkingLot(clock, new FotexPriceStrategy());
     Gates.Reset();
 }
Beispiel #19
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        public GateExtensionsUnitTests()
        {
            UnitTestDataSetLoader <GateDataSet> loader = new UnitTestDataSetLoader <GateDataSet>(new LocalCache(), new UnitTestResourceMonitor());

            UnitTestGateDataSet dataSetOverride = new UnitTestGateDataSet(ResourceNames.Gates, ResourceNames.TestGroups);

            dataSetOverride.Load(new Dictionary <string, IResourceDetails>(2, StringComparer.OrdinalIgnoreCase)
            {
                { ResourceNames.Gates, EmbeddedResources.GetEmbeddedResourceAsResourceDetails(ResourceNames.Gates, GetType()) },
                { ResourceNames.TestGroups, EmbeddedResources.GetEmbeddedResourceAsResourceDetails(ResourceNames.TestGroups, GetType()) }
            });

            loader.OverrideLoadedDataSet(dataSetOverride);

            Gate gate = new Gate("ActiveGate1");

            dataSetOverride.AddGateOverride(gate.Name, gate);

            gate = new Gate("ActiveGate2");
            dataSetOverride.AddGateOverride(gate.Name, gate);

            gate = new Gate("InactiveGate1")
            {
                UserTypes = UserGroupTypes.None
            };
            dataSetOverride.AddGateOverride(gate.Name, gate);

            gate = new Gate("InactiveGate2")
            {
                UserTypes = UserGroupTypes.None
            };
            dataSetOverride.AddGateOverride(gate.Name, gate);
            Gates = new Gates(loader);
        }
 public override void Draw(CircuitEditor editor, Context cr)
 {
     if (PlacingComponent)
     {
         // FIXME: Render this will a bit of transaprency
         Gates.AndGate(cr, new Circuit.AndGate(VisualPosition, CompOrientation));
     }
 }
Beispiel #21
0
 private Gate FindGate(Guid id)
 {
     if (!GateDict.ContainsKey(id))
     {
         GateDict[id] = Gates.Find(x => x.ID == id);
     }
     return(GateDict[id]);
 }
        public static bool Do(bool s, bool d1, bool d0)
        {
            var nand1 = Gates.Nand(s, d1);

            var nand2 = Gates.Nand(Gates.Invert(s), d0);

            return(Gates.Nand(nand1, nand2));
        }
        public static Byte2 Do(bool zero, bool negate, Byte2 data)
        {
            var selectZero = Select16.Do(zero, new Byte2(0), data);

            var selectNegate = Select16.Do(negate, Gates.Invert16(selectZero), selectZero);

            return(selectNegate);
        }
Beispiel #24
0
 protected int AddGate(Gate gate)
 {
     Gates.Add(gate);
     if (!WireDict.ContainsKey(gate.ID))
     {
         WireDict.Add(gate.ID, new List <Wire>());
     }
     return(Gates.Count - 1);
 }
Beispiel #25
0
 public int UpdateGate(Gates p_Gate)
 {
     MySqlParameter[] parameters = new MySqlParameter[] {
         new MySqlParameter("p_GateId", p_Gate.GateId),
         new MySqlParameter("p_DeploymentId", p_Gate.DeploymentId),
         new MySqlParameter("p_GateName", p_Gate.GateName)
     };
     return(MySQLDB.MySQLDBHelper.ExecuteNonQuery("UpdateGate", CommandType.StoredProcedure, parameters));
 }
        /// <summary>
        /// Sends a data bit to one of two output channels.
        /// </summary>
        /// <param name="s">Determines if the data bit is dispatched through c1 or c0</param>
        /// <param name="data">Data</param>
        public static Channels Do(bool s, bool data)
        {
            var invS = Gates.Invert(s);

            var channel0 = Gates.And(invS, data);
            var channel1 = Gates.And(s, data);

            return(new Channels(channel0, channel1));
        }
        public void Commit()
        {
            foreach (var gate in Gates.GetAll())
            {
                gate.Flights = Flights.GetAll().Where(f => f.GateId == gate.Id).OrderBy(f => f.Arrival);
            }

            Committed = true;
        }
Beispiel #28
0
                public override void Emulate(Gates gates)
                {
                    var input = Input(gates, Input1);

                    if (input != null)
                    {
                        Output = (ushort)~input;
                    }
                }
Beispiel #29
0
        /// <summary>
        /// A latch component stores and outputs a single bit.
        /// When st(store) is 1, the value on d is stored and emitted.
        /// When st is 0, the value of d is ignored, and the previously stored value is still emitted.
        /// </summary>
        /// <param name="st">Store: yes/no</param>
        /// <param name="d">Data</param>
        /// <param name="clock">Clock signal</param>
        /// <returns>The previously stored value</returns>
        public bool Do(bool st, bool d, bool clock)
        {
            var invertedCLock = Gates.Invert(clock);

            var storeButNotClockTick = Gates.And(st, invertedCLock);

            var output = _latch1.Do(storeButNotClockTick, d);

            return(_latch2.Do(clock, output));
        }
Beispiel #30
0
 protected Gate AddGateIndexed(Gate gate)
 {
     Gates.Add(gate);
     if (!WireDict.ContainsKey(gate.ID))
     {
         WireDict.Add(gate.ID, new List <Wire>());
     }
     gate.index = Gates.Count - 1;
     return(gate);
 }
Beispiel #31
0
                public override void Emulate(Gates gates)
                {
                    var input1 = Input(gates, Input1);
                    var input2 = Input(gates, Input2);

                    if (input1 != null && input2 != null)
                    {
                        Output = (ushort)(input1 >> input2);
                    }
                }
Beispiel #32
0
        public Clock(Gates.IOGates.Clock gate)
            : base(gate, new TerminalID[] { new TerminalID(false, 0, Position.TOP) })
        {

            _clock = gate;



            Rectangle r = new Rectangle();
            r.Margin = new System.Windows.Thickness(5, 17, 5, 17);
            r.Width = this.Width - 10;
            r.Height = this.Height - 34;
            r.Stroke = Brushes.Black;
            r.StrokeThickness = 2;
            r.Fill = Brushes.White;
            myCanvas.Children.Add(r);

            Path ph = new Path();
            ph.Data = StreamGeometry.Parse("M 10,22 h 5 v 5 h -5 v 5 h 5 v 5 h -5 v 5 h 5");
            ph.Stroke = Brushes.Black;
            ph.StrokeThickness = 2;
            ph.Fill = Brushes.White;
            myCanvas.Children.Add(ph);

            nval = new TextBox();
            nval.Margin = new System.Windows.Thickness(20, 23, 10, 23);
            nval.FontFamily = new FontFamily("Courier New");
            nval.FontSize = 12;
            nval.TextAlignment = TextAlignment.Center;
            nval.Width = 34;
            nval.Height = 18;
            nval.Background = Brushes.AntiqueWhite;


            Binding bind = new Binding("Milliseconds");
            bind.Source = _clock;
            bind.FallbackValue = "0";
            bind.Mode = BindingMode.TwoWay;
            bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            bind.ValidatesOnExceptions = true;
            nval.SetBinding(TextBox.TextProperty, bind);


            Binding bindve = new Binding("(Validation.Errors)[0].Exception.InnerException.Message");
            bindve.Source = nval;
            bindve.Mode = BindingMode.OneWay;
            bindve.FallbackValue = "Clock period in milliseconds";
            nval.SetBinding(TextBox.ToolTipProperty, bindve);


            myCanvas.Children.Add(nval);


        }
Beispiel #33
0
	void Start ()
	{
		gates = gameObject.GetComponent<Gates> ();
		door = gameObject.GetComponent<DoorScript> ();
		door.enabled = false;
		animator = gameObject.GetComponent<Animator> ();
		dialogue = GameObject.Find("Dialogue").GetComponent<Text> ();
		Renderer renderer = GetComponentInChildren<Renderer>();
		renderer.material.shader = Shader.Find ("Toon/Lit Outline");

	}
Beispiel #34
0
 public ShapeGate(Gates.AbstractGate abgate, string path)
     : base(abgate,
          CreateTerminals(abgate.NumberOfInputs))
 {
     ph = new Path();
     ph.StrokeEndLineCap = PenLineCap.Square;
     ph.StrokeStartLineCap = PenLineCap.Triangle;
     ph.Data = StreamGeometry.Parse(path);
     ph.Stroke = Brushes.Black;
     ph.StrokeThickness = 2;
     ph.Fill = Brushes.White;
     myCanvas.Children.Add(ph);
 }
Beispiel #35
0
        public IC(Gates.IC gate, TerminalID[] termsid)
            : base(gate, termsid)
        {

            locationHints = new Dictionary<Gates.AbstractGate, GateLocation>();

            // may need to length the gate symbol
            // to accomodate the label


            // load the terminal tooltips
            foreach (TerminalID tid in _termsid)
            {
                Gates.AbstractGate ab;
                if (tid.isInput)
                    ab = gate.Inputs[tid.ID];
                else
                    ab = gate.Outputs[tid.ID];
                tid.t.ToolTip = ab.Name;
            }



            r = new Rectangle();
            r.Margin = new System.Windows.Thickness(12, 17, 12, 17);
            r.Width = this.Width - 24;
            r.Height = this.Height - 34;
            r.Stroke = Brushes.Black;
            r.StrokeThickness = 2;
            r.Fill = Brushes.White;
            myCanvas.Children.Add(r);


            nm = new TextBox();
            nm.Text = gate.Name;
            nm.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            nm.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            nm.TextAlignment = TextAlignment.Center;
            nm.Margin = new System.Windows.Thickness(20, this.Height / 2 - 12, 20, this.Height / 2 - 12);
            nm.Width = this.Width - 40;
            nm.Height = 24;
            nm.BorderThickness = new Thickness(0);
            IsReadOnly = true;
            myCanvas.Children.Add(nm);

            nm.LostFocus += new RoutedEventHandler(nm_LostFocus);
            nm.KeyDown += new System.Windows.Input.KeyEventHandler(nm_KeyDown);
            ResizeDueToName();
        }
Beispiel #36
0
 private void Visit(Gates.IC ic)
 {
     if (!visited.Contains(ic.Name))
     {
         visited.Add(ic.Name);
         foreach (Gates.AbstractGate ag in ic.Circuit)
         {
             if (ag is Gates.IC)
             {
                 Visit((Gates.IC)ag);
             }
         }
         results.Add(ic);
     }
 }
Beispiel #37
0
        public Comment(Gates.IOGates.Comment cmt)
            : base(cmt, new TerminalID[0])
        {

            ph = new Path();

            ph.Stroke = Brushes.Black;
            ph.StrokeThickness = 2;
            ph.Fill = Brushes.White;
            ph.Margin = new System.Windows.Thickness(15);
            myCanvas.Children.Add(ph);


            nm = new TextBox();
            nm.Text = cmt.Value;
            nm.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            nm.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            nm.Margin = new System.Windows.Thickness(20);
            nm.Width = this.Width - 40;
            nm.Height = this.Height - 40;
            nm.BorderThickness = new Thickness(0);

            myCanvas.Children.Add(nm);

            nm.TextChanged += (sender, e) =>
            {
                cmt.Value = nm.Text;
            };
            nm.LostFocus += (sender, e) =>
            {
                // because I don't want to create an undo event
                // for every single keypress!
                if (UndoProvider != null)
                    UndoProvider.Add(new UndoRedo.ChangeUserText(this, prevcmt, nm.Text, txt => { cmt.Value = txt; }));

                prevcmt = nm.Text;
            };
            cmt.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "Value")
                    ResizeDueToName();

            };
            ResizeDueToName();


        }
Beispiel #38
0
 public static PropertyChangedEventHandler CreateBatchDispatchedHandler(Gates.AbstractGate g, PropertyChangedEventHandler handler)
 {
     if (bw == null)
     {
         bw = new Thread(bw_DoWork);
         bw.IsBackground = true;
         bw.Priority = ThreadPriority.BelowNormal;
         bw.Start();
     }
     return new PropertyChangedEventHandler((sender, e) =>
     {
         lock (BatchNotifications)
         {
             BatchNotifications[new KeyValuePair<Gates.AbstractGate, PropertyChangedEventHandler>(g, handler)] = new Action(() => { handler(sender, e); });
             
         }
     });
 }
Beispiel #39
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();
        }
Beispiel #40
0
        public UserIO(Gates.IOGates.UserIO gate, TerminalID[] termids)
            : base(gate, termids)
        {
            _uio = gate;

            _gate.PropertyChanged += EventDispatcher.CreateBatchDispatchedHandler(_gate, _ui_PropertyChanged);

            txtName = new TextBox();
            txtName.Margin = new System.Windows.Thickness(5, 22, 5, 22);
            txtName.Visibility = System.Windows.Visibility.Hidden;
            txtName.Width = 54;
            txtName.Height = 20;
            txtName.LostFocus += new System.Windows.RoutedEventHandler(txtName_LostFocus);
            txtName.KeyDown += new System.Windows.Input.KeyEventHandler(txtName_KeyDown);

            //ContextMenu = new System.Windows.Controls.ContextMenu();
            //MenuItem rename = new MenuItem();
            //rename.Header = "Rename...";
            //rename.Click += new System.Windows.RoutedEventHandler(rename_Click);
            //ContextMenu.Items.Add(rename);
        }
Beispiel #41
0
        private static TerminalID[] CreateTIDs(Gates.IOGates.AbstractNumeric gate)
        {
            // note that only ONE of these can be true
            // but we do an add so that it works for whichever
            // one is selected
            TerminalID[] tids = new TerminalID[gate.NumberOfInputs + gate.Output.Length];
            int tidx = 0;
            // for the top line we invert the ordering
            // this matches standard IC numbering
            // AND provides for matching up of LSB
            for (int i = 0; i < gate.NumberOfInputs; i++)
                tids[tidx++] = new TerminalID(true, gate.NumberOfInputs - i - 1, Position.TOP);

            // for the bottom, we will purposefully
            // violate standard IC numbering
            // BECAUSE we want the visual appearance of
            // a binary # to line up with the illuminated ports
            for (int i = 0; i < gate.Output.Length; i++)
                tids[tidx++] = new TerminalID(false, gate.Output.Length - i - 1, Position.BOTTOM);
            
            return tids;
        }
Beispiel #42
0
 public And(Gates.AbstractGate abgate) : base(abgate, "M 17,17 v 30 h 15 a 2,2 1 0 0 0,-30 h -15") 
 { 
     this.SizeChanged += ShapeGate_SizeChanged; 
 }
Beispiel #43
0
 public Buffer(Gates.AbstractGate abgate) : base(abgate, "M 12,12 v 8 l 8,-4 l -8,-4") 
 {
     this.Width = 32;
     this.Height = 32;
 }
Beispiel #44
0
 public Xnor(Gates.AbstractGate abgate) : base(abgate, "M 13,47 c 5,-10 5,-20 0,-30 M 13,17 c 5,10 5,20 0,30 M 18,17 h 2 c 10,0 20,5 25,15 c -5,10 -15,15 -25,15 h -2 c 5,-10 5,-20 0,-30 M 46,33.5 a 3,3 1 1 1 0.1,0.1") { }
Beispiel #45
0
 // we draw the outer curve twice, because otherwise it creates a block
 // and breaks the lines
 public Xor(Gates.AbstractGate abgate) : base(abgate, "M 13,47 c 5,-10 5,-20 0,-30 M 13,17 c 5,10 5,20 0,30 M 18,17 h 7 c 10,0 20,5 25,15 c -5,10 -15,15 -25,15 h -7 c 5,-10 5,-20 0,-30") { }
Beispiel #46
0
 public Nand(Gates.AbstractGate abgate) : base(abgate, "M 15,17 v 30 h 15 a 2,2 1 0 0 0,-30 h -15 M 46,33.5 a 3,3 1 1 1 0.1,0.1") 
 {
     this.SizeChanged += ShapeGate_SizeChanged; 
 }
Beispiel #47
0
 public Nor(Gates.AbstractGate abgate) : base(abgate, "M 15,17 h 5 c 10,0 20,5 25,15 c -5,10 -15,15 -25,15 h -5 c 5,-10 5,-20 0,-30 M 46,33.5 a 3,3 1 1 1 0.1,0.1") 
 {
     this.SizeChanged += ShapeGate_SizeChanged; 
 }
Beispiel #48
0
        private void c_CircuitConnection(Gates.Circuit sender, Gates.Terminal input, Gates.Terminal output)
        {
            Wire cw = wires.ContainsKey(input) ? wires[input] : null;
            if (cw != null)
            {
                circuitInkCanvas.Children.Remove(cw);
                wires.Remove(input);
            }
            if (output != null)
            {
                Gate inp = gates[input.gate];
                Gate outp = gates[output.gate];
                ConnectedWire ncw = new ConnectedWire(output.gate, outp.FindTerminal(false, output.portNumber),
                    input.gate, inp.FindTerminal(true, input.portNumber));
                ncw.Value = output.gate.Output[output.portNumber];
                wires[input] = ncw;
                circuitInkCanvas.Children.Insert(0, ncw);
                ncw.Connect();

                ncw.MouseDown += (snd, e) =>
                {
                    if (!IsReadOnly)
                    {

                        Gates.Terminal t = c.GetSource(input);
                        c.Disconnect(input);

                        
                        if (UndoProvider != null)
                            UndoProvider.Add(new UndoRedo.Reverse(new UndoRedo.ConnectWire(c, t, input), "Disconnect Wire"));                        
                    }
                };
            }
        }
Beispiel #49
0
        public UserOutput(Gates.IOGates.UserOutput gate)
            : base(gate,
           new TerminalID[] { 
                new TerminalID(true, 0 , Position.LEFT)})
        {


            Ellipse r = new Ellipse();
            r.Margin = new System.Windows.Thickness(15);
            r.Width = 34;
            r.Height = 34;
            r.Stroke = Brushes.Black;
            r.StrokeThickness = 2;
            r.Fill = Brushes.White;
            myCanvas.Children.Add(r);

            _r = new Ellipse();
            _r.Margin = new System.Windows.Thickness(20);
            _r.Width = 24;
            _r.Height = 24;
            _r.Stroke = Brushes.Black;
            _r.StrokeThickness = 2;
            SetFill();

            myCanvas.Children.Add(_r);
            myCanvas.Children.Add(txtName);

        }
Beispiel #50
0
        public UserInput(Gates.IOGates.UserInput gate)
            : base(gate,
           new TerminalID[] { 
                new TerminalID(false, 0 , Position.RIGHT)})
        {


            Rectangle r = new Rectangle();
            r.Margin = new System.Windows.Thickness(15);
            r.Width = 34;
            r.Height = 34;
            r.Stroke = Brushes.Black;
            r.StrokeThickness = 2;
            r.Fill = Brushes.White;
            myCanvas.Children.Add(r);

            _r = new Rectangle();
            _r.Margin = new System.Windows.Thickness(20);
            _r.Width = 24;
            _r.Height = 24;
            _r.Stroke = Brushes.Black;
            _r.StrokeThickness = 2;
            SetFill();

            _r.MouseEnter += new System.Windows.Input.MouseEventHandler(r_MouseEnter);
            _r.MouseLeave += new System.Windows.Input.MouseEventHandler(r_MouseLeave);
            _r.MouseDown += new System.Windows.Input.MouseButtonEventHandler(r_MouseDown);


            myCanvas.Children.Add(_r);
            myCanvas.Children.Add(txtName);


        }
Beispiel #51
0
        /// <summary>
        /// The "template" here is used as a visual template, that is, a descriptor of
        /// how the terminals should be laid out and a provided of location hints.
        /// The IC becomes the actual circuit within the return value.
        /// Accordingly, it is assumed that the template will be of the same
        /// "type" as the IC.
        /// </summary>
        /// <param name="ic"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        public static IC CreateFromTemplate(Gates.IC ic, IC template)
        {
            UIGates.IC nuic = new UIGates.IC(ic, template.CloneTerminals());
            template.DuplicateLocationHinting(nuic);
            return nuic;

        }
Beispiel #52
0
 public GTerm(Gates.AbstractGate gate, double offset, Gate.Position pos)
 {
     this.pos = pos;
     this.offset = offset;
     this.gate = gate;
 }
Beispiel #53
0
 public Not(Gates.AbstractGate abgate) : base(abgate, "M 15,17 v 30 l 30,-15 l -30,-15 M 46,33.5 a 3,3 1 1 1 0.1,0.1") { }
Beispiel #54
0
 public Or(Gates.AbstractGate abgate) : base(abgate, "M 15,17 h 10 c 10,0 20,5 25,15 c -5,10 -15,15 -25,15 h -10 c 5,-10 5,-20 0,-30") 
 {
     this.SizeChanged += ShapeGate_SizeChanged; 
 }
Beispiel #55
0
        protected GateInkCanvas(Gates.Circuit c, ICList icl)
        {
            InitializeComponent();

            #region Initialization

            this.icl = icl;
            this.c = c;

            c.CircuitConnection += new Gates.Circuit.CircuitConnectionEventHandler(c_CircuitConnection);
            c.ListChanged += new System.ComponentModel.ListChangedEventHandler(c_ListChanged);
            c.ReplaceGates += new Gates.Circuit.ReplaceGatesEventHandler(c_ReplaceGates);

            circuitInkCanvas.EditingMode = InkCanvasEditingMode.Ink;
            circuitInkCanvas.DefaultDrawingAttributes.Width = 2;

            // Add a listener to ResultsUpdated event.
            circuitInkCanvas.InkAnalyzer.ResultsUpdated += new ResultsUpdatedEventHandler(_inkAnalyzer_ResultsUpdated);
            circuitInkCanvas.Strokes.StrokesChanged += OnStrokesChanged;

            #endregion

            //only for piemenu selector trigger
            circuitInkCanvas.StylusDown += new StylusDownEventHandler(circuitInkCanvas_StylusDown);
            circuitInkCanvas.StylusMove += new StylusEventHandler(circuitInkCanvas_StylusMove);

            circuitInkCanvas.PreviewMouseDown += new MouseButtonEventHandler(circuitInkCanvas_PreviewMouseDown);
            circuitInkCanvas.PreviewStylusMove += new StylusEventHandler(circuitInkCanvas_PreviewStylusMove);
            circuitInkCanvas.StylusUp += new StylusEventHandler(circuitInkCanvas_StylusUp);
            circuitInkCanvas.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(circuitInkCanvas_StrokeCollected);
        }
Beispiel #56
0
 public Gate FindGate(Gates.AbstractGate abGate)
 {
     return gates[abGate];
 }
Beispiel #57
0
        private void c_ReplaceGates(Gates.Circuit sender, Dictionary<Gates.AbstractGate, Gates.AbstractGate> replacements)
        {
            foreach (KeyValuePair<Gates.AbstractGate, Gates.AbstractGate> replacement in replacements)
            {
                if (oldgatepositions.ContainsKey(replacement.Key) && replacement.Value != null)
                {
                    GateLocation np = oldgatepositions[replacement.Key];
                    gates[replacement.Value].Margin = new Thickness(np.x, np.y, 0, 0);
                    ((RotateTransform)gates[replacement.Value].RenderTransform).Angle = np.angle;
                    ((GateLocation)gates[replacement.Value].Tag).x = np.x;
                    ((GateLocation)gates[replacement.Value].Tag).y = np.y;
                    ((GateLocation)gates[replacement.Value].Tag).angle = np.angle;
                }
            }
            foreach (Gate tic in gates.Values)
            {
                if (tic is UIGates.IC)
                    ((UIGates.IC)tic).UpdateLocationHints(replacements);
            }

            UpdateLayout();
            // otherwise the wires don't know where to go
            UpdateWireConnections();
        }
Beispiel #58
0
 public ChangeNumInputs(Gates.Circuit c, Gates.AbstractGate original, Gates.AbstractGate replacement)
 {
     this.c = c;
     this.orig_gate = original;
     this.new_gate = replacement;
 }
Beispiel #59
0
        public void AddGate(Gates.AbstractGate gate, GateLocation pos)
        {
            // maybe we could use extension methods
            // to add a method to create a UIGate for each AbstractGate?

            Gate uigate;
            if (gate is Gates.BasicGates.And)
            {
                uigate = new UIGates.And((Gates.BasicGates.And)gate);
            }
            else if (gate is Gates.BasicGates.Not)
            {
                uigate = new UIGates.Not((Gates.BasicGates.Not)gate);
            }
            else if (gate is Gates.BasicGates.Or)
            {
                uigate = new UIGates.Or((Gates.BasicGates.Or)gate);
            }
            else if (gate is Gates.BasicGates.Nand)
            {
                uigate = new UIGates.Nand((Gates.BasicGates.Nand)gate);
            }
            else if (gate is Gates.BasicGates.Nor)
            {
                uigate = new UIGates.Nor((Gates.BasicGates.Nor)gate);
            }
            else if (gate is Gates.BasicGates.Xor)
            {
                uigate = new UIGates.Xor((Gates.BasicGates.Xor)gate);
            }
            else if (gate is Gates.BasicGates.Xnor)
            {
                uigate = new UIGates.Xnor((Gates.BasicGates.Xnor)gate);
            }
            else if (gate is Gates.BasicGates.Buffer)
            {
                uigate = new UIGates.Buffer((Gates.BasicGates.Buffer)gate);
            }
            else if (gate is Gates.IOGates.UserInput)
            {
                uigate = new UIGates.UserInput((Gates.IOGates.UserInput)gate);
            }
            else if (gate is Gates.IOGates.UserOutput)
            {
                uigate = new UIGates.UserOutput((Gates.IOGates.UserOutput)gate);
            }
            else if (gate is Gates.IOGates.AbstractNumeric)
            {
                uigate = new UIGates.Numeric((Gates.IOGates.AbstractNumeric)gate);
            }
            else if (gate is Gates.IOGates.Clock)
            {
                uigate = new UIGates.Clock((Gates.IOGates.Clock)gate);
            }
            else if (gate is Gates.IOGates.Comment)
            {
                uigate = new UIGates.Comment((Gates.IOGates.Comment)gate);
            }
            else if (gate is Gates.IC)
            {
                uigate = UIGates.IC.CreateFromTemplate((Gates.IC)gate, icl.GetIC(gate.Name));
            }
            else throw new ArgumentException("gate not of known subclass");

            AddGate(uigate, pos);
        }
Beispiel #60
0
        public ConnectWire(Gates.Circuit c, Gates.Terminal origin, Gates.Terminal dest)
        {
            this.c = c;
            this.origin = origin;
            this.dest = dest;

            c.ReplaceGates += (sender2, e2) =>
            {
                if (e2.ContainsKey(origin.gate) && e2[origin.gate] != null)
                {
                    origin.gate = e2[origin.gate];
                }

                if (e2.ContainsKey(dest.gate) && e2[dest.gate] != null)
                {
                    dest.gate = e2[dest.gate];
                }
            };
        }