public ServiceConfigViewModel(ScenarioModel scenario)
 {
     if (scenario != null)
     {
         if (scenario.Map != null)
         {
             try
             {
                 Width = scenario.Map[0].Width;
                 Height = scenario.Map[0].Height;
                 if (scenario.Map[0].Substrate != null)
                 {
                     Background = new ImageBrush(Helpers.Imaging.ImageManager.BitmapToBitmapImage(scenario.Map[0].Substrate));
                 }
             }
             catch (NullReferenceException)
             {
                 Width = 800;
                 Height = 600;
                 Background = Brushes.LightCoral;
             }
         }
         if (scenario.Services != null)
         {
             _servicesOnMap = new ObservableCollection<ServiceModel>(scenario.Services);
             if (_servicesOnMap.Count > 0)
             {
                 _generator.Init(_servicesOnMap.Max(s => s.Id));
             }
         }
     }
 }
        public Simulation(ScenarioModel scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException("scenario is null");
            }

            //System.Threading.Timer t = new System.Threading.Timer(new System.Threading.TimerCallback((o) => Step()), null, 0, (long)STEP_TIME_MS);

            _scenario = scenario;
            RoadGraph = new Graph<WayPoint, PathFigure>();
            if (_scenario.RoadGraph != null)
            {
                foreach (var node in _scenario.RoadGraph.Nodes)
                {
                    RoadGraph.Add(node);
                }
                foreach (var edge in _scenario.RoadGraph.Edges)
                {
                    var pathGeom = PathGeometry.CreateFromGeometry(PathGeometry.Parse(edge.Data));
                    RoadGraph.AddEdge(edge.Start, edge.End, pathGeom.Figures.First());
                }
            }

            _analisisCollector = new Analisis.AnalisisCollector();
            _map = _scenario.Map;
            _start = _scenario.StartTime;
            _end = _scenario.EndTime;
            _simulationTime = _scenario.StartTime;
            Init(STEP_TIME_MS);
        }
        public MapConfigViewModel(ScenarioModel scenario)
        {
            _scenario = scenario;
            AllWayPoints = new ObservableCollection<WayPointViewModel>();
            Layers = new ObservableCollection<LayerViewModel>();

            if (_scenario != null)
            {
                Map = _scenario.Map;
                foreach (var l in Map)
                {
                    Layers.Add(new LayerViewModel(l));
                }
                if (_scenario.InputOutputPoints != null)
                {
                    AllWayPoints = new ObservableCollection<WayPointViewModel>(from p in _scenario.InputOutputPoints select new WayPointViewModel(_scenario.Services, _scenario.InputOutputPoints, p));
                }
            }
        }
        public RoadGraphConfigViewModel(ScenarioModel scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException("scenario is null");
            }

            GraphPanel = new Canvas();
            GraphPanel.MouseLeftButtonUp += (s, e) => MouseLeftButtonUp(s, e);
            GraphPanel.PreviewMouseLeftButtonDown += (s, e) => PreviewMouseLeftButtonDown(s, e);
            GraphPanel.PreviewMouseLeftButtonUp += (s, e) => PreviewMouseLeftButtonUp(s, e);
            GraphPanel.PreviewMouseMove += (s, e) => PreviewMouseMove(s, e);

            Services = scenario.Services;

            _vertexes = new List<VertexVisual>();
            _edges = new List<EdgeVisual>();

            RoadGraph = new Graph<WayPoint, PathFigure>();
            if (scenario.RoadGraph != null)
            {
                foreach (var edge in scenario.RoadGraph.Edges)
                {
                    var pathGeom = PathGeometry.CreateFromGeometry(PathGeometry.Parse(edge.Data));

                    EdgeVisual ev = new EdgeVisual(pathGeom.Figures.First())
                    {
                        NodeFrom = edge.Start,
                        NodeTo = edge.End,
                        Zoom = Zoom
                    };
                    _edges.Add(ev);
                    GraphPanel.Children.Add(ev);
                }

                foreach (var node in scenario.RoadGraph.Nodes)
                {
                    //int in_count = 0, out_count = 0;
                    //foreach (var edge in RoadGraph.GetEdgesTo(node))
                    //{
                    //    in_count++;
                    //}
                    //foreach (var edge in RoadGraph.GetEdgesFrom(node))
                    //{
                    //    out_count++;
                    //}

                    VertexVisual vv = new VertexVisual(node)
                    {
                        //InCount = in_count,
                        //OutCount = out_count,
                        Zoom = Zoom
                    };
                    _vertexes.Add(vv);
                    GraphPanel.Children.Add(vv);
                }
            }

            GraphPanel.Width = scenario.Map[0].Width;
            GraphPanel.Height = scenario.Map[0].Height;
            if (scenario.Map[0].Substrate!= null)
            {
                GraphPanel.Background = new ImageBrush(Helpers.Imaging.ImageManager.BitmapToBitmapImage(scenario.Map[0].Substrate));
            }
        }
        private void New()
        {
            _scenario = new ScenarioModel();
            _sim = new Core.Simulation(_scenario);

            ScenarioLoaded = true;

            SpeedRatio = 1.0D;

            if (ViewPortCollection.Count() > 0)
            {
                ViewPortSelectionChanged(ViewPortCollection.First().Code);
            }
        }
        private void Loading(string path)
        {
            BusyContent = "Загрузка сценария...";
            IsBusy = true;

            BackgroundWorker bw = new BackgroundWorker();
            bw.RunWorkerCompleted += (s, e) =>
            {
                if (e.Error != null)
                {
                    System.Windows.MessageBox.Show("Сценарий поврежден и не может быть прочитан");
                }

                _sim = new Core.Simulation(_scenario);

                ScenarioLoaded = true;

                if (ViewPortCollection.Count() > 0)
                {
                    ViewPortSelectionChanged(ViewPortCollection.First().Code);
                }

                while (Properties.Settings.Default.LastScenarios.Contains(path))
                {
                    Properties.Settings.Default.LastScenarios.Remove(path);
                }
                Properties.Settings.Default.LastScenarios.Add(path);
                Properties.Settings.Default.Save();

                OnPropertyChanged("WindowTitle");

                IsBusy = false;
            };
            bw.DoWork += (s, e) =>
            {
                string p = (string)e.Argument;
                Scenario.IO.ScenarioStream st = new Scenario.IO.ScenarioStream(p);
                _scenario = st.Read();

                _scenario.Map.Init();
            };
            bw.RunWorkerAsync(path);
        }
        /// <summary>
        /// TEST Method
        /// </summary>
        public ScenarioModel CreateScenario()
        {
            ScenarioModel model = new ScenarioModel();
            using (StreamReader reader = new StreamReader(@"test.svg"))
            {
                List<string> mapSource = new List<string>();
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    mapSource.Add(line);
                }
            }
            //using (MapReader mreader = new MapReader(@"test.svg"))
            //{
            //    if (mreader.Read())
            //    {
            //        model.Map = mreader.GetMap(new Dictionary<string, byte>());
            //    }
            //}
            model.AgentGroups = new List<AgentsGroup>();
            model.StartTime = new DateTime(2013, 4, 15);
            model.EndTime = new DateTime(2013, 4, 16);
            var group = new AgentsGroup(0,"");
            group.AgentsDistibution.Add(DayOfWeek.Monday, new int[] { 200, 200, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 });
            //group.AgentTypes = new Dictionary<string, double>();
            //group.AgentTypes.Add("passenger", 1.0);
            var settings = new Dictionary<string, object>();
            settings.Add("startPosition", new Point());
            settings.Add("checkPoints", new List<WayPoint>() { new WayPoint(100, 100), new WayPoint(400, 100), new WayPoint(780, 580) });
            settings.Add("size", new Size3D(0.5, 1.8, 0.3));
            settings.Add("maxSpeed", 1);
            settings.Add("acceleration", 0);
            settings.Add("deceleration", 0);
            //group.AgentsConfig.Add("passenger", settings);
            group.Type = AgentGroupInitType.Distribution;
            group.Name = "Тестовая группа";
            group.SourcePoint = new Enviroment.WayPoint(0, 0, 0, 1, 8);
            model.AgentGroups = new List<AgentsGroup>();
            model.AgentGroups.Add(group);

            return model;
        }
 private void OpenScenario(string path)
 {
     ScenarioReader reader = null;
     try
     {
         reader = new ScenarioReader(path);
     }
     catch (ArgumentNullException)
     {
         MessageBox.Show("Путь не задан");
         return;
     }
     catch (DirectoryNotFoundException)
     {
         MessageBox.Show("Пути " + path + " не существует");
         return;
     }
     Scenario sc = reader.ReadScenario();
     if (sc == null)
     {
         return;
     }
     scenario = sc;
     experimentCnfg = null;
     SpeedRatio = 1.0D;
     if (FirstGrid.Visibility == System.Windows.Visibility.Visible)
     {
         FirstGrid.Visibility = System.Windows.Visibility.Hidden;
     }
     PaintMap();
     menuEnableVariator.IsEnabled = true;
     Properties.Settings.Default.ScenarioPath = path;
     Properties.Settings.Default.Save();
 }
        private void NewScenario()
        {
            scenario = new Scenario();
            scenario.agentGroups = new List<AgentsGroup>();
            scenario.agentsList = new List<AgentBase>();
            scenario.ServicesList = new List<ServiceBase>();
            //scenario.RoadGraph = new Graph<WayPoint, PathFigure>();
            scenario.paintObjectList = new List<PaintObject>();
            scenario.map = new MapOld(600, 400);

            Properties.Settings.Default.ScenarioPath = null;

            SpeedRatio = 1.0D;
            experimentCnfg = null;
            PaintMap();
            menuEnableVariator.IsEnabled = true;
        }
 public VehicleAgentBase(int id, ScenarioModel scenario, int group, int speed)
     : base(id, scenario, group, speed)
 {
 }