private void GetPins(Dictionary <int, DeviceConnection> deviceConnectionById, Dictionary <int, DeviceSymbol> deviceSymbolById, E3Text text)
        {
            Dictionary <string, SymbolPin> topPinByName    = new Dictionary <string, SymbolPin>();
            Dictionary <string, SymbolPin> bottomPinByName = new Dictionary <string, SymbolPin>();

            foreach (int connectionId in ConnectionIds)
            {
                DeviceConnection connection = deviceConnectionById[connectionId];
                int    connectedId;
                string pinName;
                if (id == connection.StartDeviceId)
                {
                    connectedId = connection.EndDeviceId;
                    pinName     = connection.StartPinName;
                }
                else
                {
                    connectedId = connection.StartDeviceId;
                    pinName     = connection.EndPinName;
                }
                string connectedAssignment = deviceSymbolById[connectedId].Assignment;
                if (!String.IsNullOrEmpty(Assignment) && String.IsNullOrEmpty(connectedAssignment))
                {
                    if (!topPinByName.ContainsKey(pinName))
                    {
                        SymbolPin pin = new SymbolPin(pinName, connection.Signal, text, smallFont);
                        topPinByName.Add(pinName, pin);
                    }
                    topPinByName[pinName].CableIds.Add(connection.CableId);
                }
                else
                {
                    if (!bottomPinByName.ContainsKey(pinName))
                    {
                        SymbolPin pin = new SymbolPin(pinName, connection.Signal, text, smallFont);
                        bottomPinByName.Add(pinName, pin);
                    }
                    bottomPinByName[pinName].CableIds.Add(connection.CableId);
                }
            }
            topPins    = topPinByName.Values.ToList();
            bottomPins = bottomPinByName.Values.ToList();
            NaturalSortingStringComparer stringComparer = new NaturalSortingStringComparer();

            topPins.Sort((p1, p2) => stringComparer.Compare(p1.Name, p2.Name));
            bottomPins.Sort((p1, p2) => stringComparer.Compare(p1.Name, p2.Name));
        }
            public int Compare(CableLayout a, CableLayout b)
            {
                int aId       = a.Id;
                int bId       = b.Id;
                int aDistance = Math.Abs(groupPosition - matePositionByCableId[aId]);
                int bDistance = Math.Abs(groupPosition - matePositionByCableId[bId]);

                if (aDistance < bDistance)
                {
                    return(-1);
                }
                if (aDistance > bDistance)
                {
                    return(1);
                }
                return(stringComparer.Compare(cableInfoById[a.Id].Name, cableInfoById[b.Id].Name));
            }
            public int Compare(CableLayout a, CableLayout b)
            {
                int aId           = a.Id;
                int bId           = b.Id;
                int aMatePosition = matePositionByCableId[aId];
                int bMatePosition = matePositionByCableId[bId];

                if (aMatePosition < bMatePosition)
                {
                    return(-1);
                }
                if (aMatePosition > bMatePosition)
                {
                    return(1);
                }
                return(stringComparer.Compare(cableInfoById[a.Id].Name, cableInfoById[b.Id].Name));
            }
            public int Compare(CableSymbol a, CableSymbol b)
            {
                int aBottomId = bottomGroups.First(g => g.CableIds.Contains(a.CableId)).Id;
                int bBottomId = bottomGroups.First(g => g.CableIds.Contains(b.CableId)).Id;
                int diff      = optimalBottomPositionById[aBottomId] - optimalBottomPositionById[bBottomId];

                if (diff != 0)
                {
                    return(diff);
                }
                int aTopId = topGroups.First(g => g.CableIds.Contains(a.CableId)).Id;
                int bTopId = topGroups.First(g => g.CableIds.Contains(b.CableId)).Id;

                diff = optimalTopPositionById[aTopId] - optimalTopPositionById[bTopId];
                if (diff != 0)
                {
                    return(diff);
                }
                return(stringComparer.Compare(a.CableName, b.CableName));
            }
        private void SortSymbols()
        {
            NaturalSortingStringComparer stringComparer = new NaturalSortingStringComparer();

            deviceSymbols.Sort((ds1, ds2) => stringComparer.Compare(ds1.Name, ds2.Name));
        }
 private void GetPins(Dictionary<int, DeviceConnection> deviceConnectionById, Dictionary<int, DeviceSymbol> deviceSymbolById, E3Text text)
 {
     Dictionary<string, SymbolPin> topPinByName = new Dictionary<string, SymbolPin>();
     Dictionary<string, SymbolPin>  bottomPinByName = new Dictionary<string, SymbolPin>();
     foreach (int connectionId in ConnectionIds)
     {
         DeviceConnection connection = deviceConnectionById[connectionId];
         int connectedId;
         string pinName;
         if (id == connection.StartDeviceId)
         {
             connectedId = connection.EndDeviceId;
             pinName = connection.StartPinName;
         }
         else
         {
             connectedId = connection.StartDeviceId;
             pinName = connection.EndPinName;
         }
         string connectedAssignment = deviceSymbolById[connectedId].Assignment;
         if (!String.IsNullOrEmpty(Assignment) && String.IsNullOrEmpty(connectedAssignment))
         {
             if (!topPinByName.ContainsKey(pinName))
             {
                 SymbolPin pin = new SymbolPin(pinName, connection.Signal, text, smallFont);
                 topPinByName.Add(pinName, pin);
             }
             topPinByName[pinName].CableIds.Add(connection.CableId);
         }
         else
         {
             if (!bottomPinByName.ContainsKey(pinName))
             {
                 SymbolPin pin = new SymbolPin(pinName, connection.Signal, text, smallFont);
                 bottomPinByName.Add(pinName, pin);
             }
             bottomPinByName[pinName].CableIds.Add(connection.CableId);
         }
     }
     topPins = topPinByName.Values.ToList();
     bottomPins = bottomPinByName.Values.ToList();
     NaturalSortingStringComparer stringComparer = new NaturalSortingStringComparer();
     topPins.Sort((p1,p2)=>stringComparer.Compare(p1.Name, p2.Name));
     bottomPins.Sort((p1, p2) => stringComparer.Compare(p1.Name, p2.Name));
 }