Exemple #1
0
        public void AddSlave(int entry, float angle, float distance, int id = 0)
        {
            foreach (FormationDataEntry row in dataList)
            {
                if (row.Entry == entry)
                {
                    row.AddSlave(angle, distance, id);
                    return;
                }
            }

            // no entry found create new one
            FormationDataEntry slaveEntry = AddEntry(entry);

            slaveEntry.AddSlave(angle, distance);
        }
Exemple #2
0
        public void Load(string fileName = "Datas.json")
        {
            if (!File.Exists(fileName))
            {
                return;
            }

            string json = File.ReadAllText(fileName);
            List <FormationDataEntry> newList = JSONSerializer.Deserialize <List <FormationDataEntry> >(json);

            // Check the values and add them to data list
            List <int> usedEntries = new List <int>();

            for (int i = 0; i < newList.Count; ++i)
            {
                FormationDataEntry formationEntry = newList[i];

                if (usedEntries.BinarySearch(formationEntry.Entry) > 0)
                {
                    continue;
                }

                usedEntries.Add(formationEntry.Entry);
                FormationDataEntry newEntry = new FormationDataEntry(formationEntry.Entry, formationEntry.MasterX, formationEntry.MasterY, formationEntry.MasterO);
                dataList.Add(newEntry);

                if (formationEntry.Entry >= AvailableEntryID)
                {
                    AvailableEntryID = formationEntry.Entry + 1;
                }

                List <int> usedIds = new List <int>();
                for (int j = 0; j < formationEntry.slaveEntries.Count; ++j)
                {
                    SlaveDataEntry slaveEntry = formationEntry.slaveEntries[j];

                    if (usedIds.BinarySearch(slaveEntry.ID) > 0)
                    {
                        continue;
                    }

                    usedIds.Add(slaveEntry.ID);

                    newEntry.AddSlave(slaveEntry.Angle, slaveEntry.Distance, slaveEntry.ID);
                }
            }
        }
Exemple #3
0
        private void MainDataDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int   id        = -1;
            float angle     = -1;
            float dist      = -1;
            int   validCell = 0;

            DataGridViewRow currRow = MainDataDGV.CurrentRow;

            foreach (DataGridViewCell cell in currRow.Cells)
            {
                switch (cell.ColumnIndex)
                {
                case 0:
                    if (cell.Value == null)
                    {
                        continue;
                    }
                    if (!ValidateInt(cell.Value.ToString(), out id))
                    {
                        cell.Style.BackColor = Color.IndianRed;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.LawnGreen;
                        ++validCell;
                    }
                    break;

                case 1:
                    if (cell.Value == null)
                    {
                        continue;
                    }
                    if (!ValidateFloat(cell.Value.ToString(), out angle))
                    {
                        cell.Style.BackColor = Color.IndianRed;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.LawnGreen;
                        ++validCell;
                    }
                    break;

                case 2:
                    if (cell.Value == null)
                    {
                        continue;
                    }
                    if (!ValidateFloat(cell.Value.ToString(), out dist))
                    {
                        cell.Style.BackColor = Color.IndianRed;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.LawnGreen;
                        ++validCell;
                    }
                    break;

                default:
                    break;
                }
            }

            if (validCell == 3)
            {
                foreach (DataGridViewCell cell in currRow.Cells)
                {
                    cell.Style.BackColor = Color.Green;
                }

                int currentid = -1;
                if (currRow.Tag != null)
                {
                    currentid = (int)currRow.Tag;
                }

                SlaveDataEntry slaveEntry = CurrentSelectedEntry.AddSlave(angle, dist, currentid);
                AddObject(currRow, slaveEntry);
            }
            else
            {
                if (currRow.Tag != null)
                {
                    RemoveObject((int)currRow.Tag);
                }
            }
        }