Exemple #1
0
        public static List <VanetComonent> ImportNetwok(string netName)
        {
            List <VanetComonent> re = new List <VanetComonent>();
            string pathString       = dbSettings.PathString + netName;

            string[] lines = File.ReadAllLines(pathString);

            foreach (string lin in lines)
            {
                VanetComonent c = GetVanetComonent(lin);
                re.Add(c);
            }
            return(re);
        }
Exemple #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NetworkTopolgy topolog   = new NetworkTopolgy();
            bool           isCreated = topolog.createNewTopology(txt_networkName.Text);

            if (isCreated)
            {
                this.WindowState = WindowState.Minimized;

                foreach (Junction jun in mianwindow.MyJunctions)
                {
                    VanetComonent com = new VanetComonent();
                    com.Pox           = jun.Margin.Left;
                    com.Poy           = jun.Margin.Top;
                    com.Width         = jun.Width;
                    com.Height        = jun.Height;
                    com.ComponentType = ComponentType.Junction;
                    topolog.SaveVanetComponent(com, txt_networkName.Text);
                }



                foreach (RoadSegment seg in mianwindow.MyRoadSegments)
                {
                    VanetComonent com = new VanetComonent();
                    com.Pox             = seg.Margin.Left;
                    com.Poy             = seg.Margin.Top;
                    com.Width           = seg.Width;
                    com.Height          = seg.Height;
                    com.ComponentType   = ComponentType.RoadSegment;
                    com.RoadOrientation = seg.Roadorientation;
                    com.LanesCount      = seg.LanesCount;
                    topolog.SaveVanetComponent(com, txt_networkName.Text);
                }



                this.Close();
            }
            else
            {
                MessageBox.Show("please change network name!");
            }
        }
Exemple #3
0
        /// <summary>
        /// "0Pox","1Poy", "2Width", "3Height","4ComponentType",  "5RoadOrientation", "6LanesCount"
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public static VanetComonent GetVanetComonent(string line)
        {
            try
            {
                VanetComonent re      = new VanetComonent();
                string[]      linecom = line.Split(';');
                re.Pox    = Convert.ToDouble(linecom[0].Split('=')[1]);
                re.Poy    = Convert.ToDouble(linecom[1].Split('=')[1]);
                re.Width  = Convert.ToDouble(linecom[2].Split('=')[1]);
                re.Height = Convert.ToDouble(linecom[3].Split('=')[1]); //

                if (linecom[4].Split('=')[1] == "RoadSegment")          // TYPE.
                {
                    re.ComponentType = ComponentType.RoadSegment;
                    if (linecom[5].Split('=')[1] == "Vertical")
                    {
                        re.RoadOrientation = RoadOrientation.Vertical;
                    }
                    else
                    {
                        re.RoadOrientation = RoadOrientation.Horizontal;
                    }
                    re.LanesCount = Convert.ToInt16(linecom[6].Split('=')[1]);
                }
                else
                {
                    re.ComponentType = ComponentType.Junction;
                }
                //LanesCount


                return(re);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message + ". For help:" + exp.HelpLink + ".");
            }

            return(null);;
        }
Exemple #4
0
        public bool SaveVanetComponent(VanetComonent vantComp, string TopologName)
        {
            string pathString = dbSettings.PathString + TopologName + ".txt";
            string line       = "";

            string[] cols;
            string[] vals;

            if (vantComp.ComponentType == ComponentType.RoadSegment)
            {
                cols = new string[]
                {
                    "Pox",
                    "Poy",
                    "Width",
                    "Height",
                    "ComponentType",
                    "RoadOrientation",
                    "LanesCount"
                };
                vals = new string[]
                {
                    vantComp.Pox.ToString(),
                        vantComp.Poy.ToString(),
                        vantComp.Width.ToString(),
                        vantComp.Height.ToString(),
                        vantComp.ComponentType.ToString(),
                        vantComp.RoadOrientation.ToString(),
                        vantComp.LanesCount.ToString()
                };

                for (int i = 0; i < cols.Length; i++)
                {
                    line += cols[i] + "=" + vals[i] + ";";
                }
            }
            else if (vantComp.ComponentType == ComponentType.Junction)
            {
                cols = new string[]
                {
                    "Pox",
                    "Poy",
                    "Width",
                    "Height",
                    "ComponentType",
                };
                vals = new string[]
                {
                    vantComp.Pox.ToString(),
                        vantComp.Poy.ToString(),
                        vantComp.Width.ToString(),
                        vantComp.Height.ToString(),
                        vantComp.ComponentType.ToString(),
                };

                for (int i = 0; i < cols.Length; i++)
                {
                    line += cols[i] + "=" + vals[i] + ";";
                }
            }

            FileStream   fs1 = new FileStream(pathString, FileMode.Append, FileAccess.Write);
            StreamWriter sw  = new StreamWriter(fs1);

            sw.WriteLine(line);
            sw.Close();
            fs1.Close();

            return(true);
        }