public ZoneRoamAreasDatabase(string zone, MySqlConnection connection, QueryConfig config)
            : base(zone, config)
        {
            _connection = connection;

            var sql = String.Format(SelectString, SelectArgValues);
            var results = Database.QueryHelper.RunQuery(_connection, sql);

            foreach (var row in results)
            {
                var ra = new RoamArea(_queryConfig);
                ra.SetProperties(Queries, row);
                RoamAreas.Add(ra);
            }

            foreach (var area in RoamAreas)
            {
                sql = String.Format(area.SelectString, area.SelectArgValues);
                results = Database.QueryHelper.RunQuery(_connection, sql);
                foreach (var row in results)
                {
                    var entry = new RoamAreaEntry(_queryConfig);
                    entry.SetProperties(area.Queries, row);
                    area.Vertices.Add(entry);
                    entry.Created();
                }

                area.Created();
            }

            this.Created();
        }
        private void CreateArea(RoamArea area)
        {
            Model3DGroup group = Model as Model3DGroup;

            Model3DCollection collection = new Model3DCollection();
            if (_mapping.ContainsKey(area))
            {
                foreach (Model3D model in _mapping[area])
                {
                    group.Children.Remove(model);
                }
            }

            foreach (var vertex in area.Vertices)
            {
                MeshBuilder builder = new MeshBuilder();
                Point3D p1 = new Point3D(vertex.X, vertex.Y, area.MaxZ);
                Point3D p2 = new Point3D(vertex.X, vertex.Y, area.MinZ);

                //if (Clipping != null && !Clipping.DrawPoint(p)) continue;

                builder.AddBox(p1, 4, 4, 4);
                builder.AddBox(p2, 4, 4, 4);
                builder.AddPipe(p1, p2, 1.5, 1.5, 50);

                GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Yellow);
                collection.Add(box);

                builder = new MeshBuilder();

                Point3D next = new Point3D();
                if (vertex == area.Vertices.Last())
                {
                    next.X = area.Vertices[0].X;
                    next.Y = area.Vertices[0].Y;
                }
                else
                {
                    next.X = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1).X;
                    next.Y = area.Vertices.ElementAt(area.Vertices.IndexOf(vertex) + 1).Y;
                }
                Point3D n1 = new Point3D(next.X, next.Y, area.MaxZ);
                Point3D n2 = new Point3D(next.X, next.Y, area.MinZ);

                //builder.AddPipe(p1, p2);
                builder.AddPipe(p1, n1, 0.5, 0.5, 50);
                builder.AddPipe(p2, n2, 0.5, 0.5, 50);
                collection.Add(new GeometryModel3D(builder.ToMesh(), Materials.Yellow));

            }

            _mapping[area] = collection;
            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }
        public void ShowArea(RoamArea area)
        {
            Model3DGroup group = Model as Model3DGroup;
            group.Children.Clear();

            if (area != null)
            {
                CreateArea(area);
                _activeArea = area;
            }
        }
        public void AddArea(RoamArea area)
        {
            if (RoamAreas.Contains(area)) return;

            if (RoamAreas.FirstOrDefault(x => x.Id == area.Id) != null || area.Zone != this.Zone)
            {
                throw new Exception("Roam Area ID/Zone conflict");
            }

            AddObject(area);
            RoamAreas.Add(area);
        }
 public RoamArea NewArea()
 {
     int newId = GetNextRoamAreaID();
     var area = new RoamArea(newId, _queryConfig);
     area.Zone = this.Zone;
     area.Created();
     return area;
 }