Exemple #1
0
        public void AddPowerLine(Line line)
        {
            //todo use one func
            if (PowerLines.Any(l => l.Input == line.Input &&
                               l.Output == line.Output &&
                               l.InputMarker == line.InputMarker &&
                               l.OutputMarker == line.OutputMarker))
            {
                return;
            }

            var s1 = Segments.FirstOrDefault(s => s.Position == line.Input);
            var s2 = Segments.FirstOrDefault(s => s.Position == line.Output);

            if (s1 != null)
            {
                var m1 = s1.Connectors.FirstOrDefault(p => p.Marker == line.InputMarker);
                if (s2 != null)
                {
                    var m2 = s2.Connectors.FirstOrDefault(p => p.Marker == line.OutputMarker);

                    if (m1 != null && m2 != null)
                    {
                        m1.ConnectedTo.Add(s2.Identifier.ToString());
                        m2.ConnectedTo.Add(s1.Identifier.ToString());
                        PowerLines.Add(line);
                    }
                }
            }
        }
Exemple #2
0
        public void RemovePowerLine(Line line)
        {
            //todo use one func

            var found = PowerLines.FirstOrDefault(l => l.Input == line.Input &&
                                                  l.Output == line.Output &&
                                                  l.InputMarker == line.InputMarker &&
                                                  l.OutputMarker == line.OutputMarker);

            if (found == null)
            {
                return;
            }

            var s1 = Segments.FirstOrDefault(s => s.Position == line.Input);
            var s2 = Segments.FirstOrDefault(s => s.Position == line.Output);

            if (s1 != null && s2 != null)
            {
                var toRemove = new List <Connector> ();
                s1.Connectors.Where(p => p.Marker == line.InputMarker)
                .ToList().ForEach(m => {
                    m.ConnectedTo.Remove(s2.Identifier.ToString());
                    if (m.Marker == AppController.Instance.Config.LeftPower ||
                        m.Marker == AppController.Instance.Config.RightPower)
                    {
                        toRemove.Add(m);
                    }
                });

                toRemove.ForEach(c => s1.Connectors.Remove(c));
                toRemove.Clear();

                s2.Connectors.Where(p => p.Marker == line.OutputMarker)
                .ToList().ForEach(m =>
                {
                    m.ConnectedTo.Remove(s1.Identifier.ToString());
                    if (m.Marker == AppController.Instance.Config.LeftPower ||
                        m.Marker == AppController.Instance.Config.RightPower)
                    {
                        toRemove.Add(m);
                    }
                });

                toRemove.ForEach(c => s2.Connectors.Remove(c));
            }

            PowerLines.Remove(found);
        }
Exemple #3
0
 public bool IsEmpty()
 {
     return(Segments.All(s => s.Type == ElementType.None) && PowerLines.Count() == 0);
 }
Exemple #4
0
 ///
 /// \brief Sets the powerLines object for the lever
 ///
 /// \param [in] lines The powerLines object
 /// \param [in] num The ID of the lever
 /// \return No return value
 ///
 /// \details
 ///
 public void setLines(PowerLines lines, int num)
 {
     this.lines = lines;
     this.num   = num;
 }