예제 #1
0
        private static void LoadBridgesSecondaryData(string secondaryFileName, ref List <string> warnings)
        {
            //Create new item in SecondaryGroups structure (if it is not
            //already there) with data from secondaryFileName.

            if (Universal.SecondaryGroups.ContainsKey(secondaryFileName))
            {
                //Do not load the data from this file since it is already in memory.
                //In memory it could have been modified but we want to keep it as it
                //is, just as Word and Excel does when a file is loaded again:
                //it keeps the modifications.
            }
            else //Load this file to SecondaryGroups.
            {
                if (File.Exists(secondaryFileName))
                {
                    try
                    {
                        StreamReader secondaryFile;
                        secondaryFile = File.OpenText(secondaryFileName);

                        var thisGroup = new Universal.SecondaryGroup();
                        thisGroup.Component = "BRIDGES";
                        thisGroup.FileName  = secondaryFileName;
                        thisGroup.NPoints   = Convert.ToInt64(secondaryFile.ReadLine());
                        var thisTable = new Universal.SecondaryTable[thisGroup.NPoints];

                        //Read every line with 5 values: X, bed, z lower, z upper, deck
                        for (int j = 0; j <= thisGroup.NPoints - 1; ++j)
                        {
                            string   next = secondaryFile.ReadLine();
                            string[] splt = next.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            thisTable[j].Col3 = splt[3];
                            thisTable[j].Col4 = splt[4];
                        }

                        secondaryFile.Close();

                        //Store bridge profile table:
                        thisGroup.Table = thisTable;

                        //Store this new group of bridge geometries:
                        Universal.SecondaryGroups.Add(secondaryFileName, thisGroup);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(Universal.Idioma("ERROR 3004171244: error reading file ", "ERROR 3004171244: error leyendo archivo ") +
                                        "\n\n" + secondaryFileName + "\n\n" + ex.Message, "RiverFlow2D", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
                else
                {
                    //Bridge profile file doesn't exist in memory.
                    Universal.CreateSecondaryDefaultFile("BRIDGES", secondaryFileName, 5);
                    if (warnings.IndexOf(secondaryFileName) == -1)
                    {
                        warnings.Add(secondaryFileName);
                    }
                }
            }
        }