﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Windows.Controls;
using System.Collections;
using System.IO;

using IS3.Core;
using IS3.Core.Geometry;
using IS3.Core.Graphics;

namespace IS3.Desktop
{
    //************************  Notice  **********************************
    //** This file is part of iS3
    //**
    //** Copyright (c) 2015 Tongji University iS3 Team. All rights reserved.
    //**
    //** This library is free software; you can redistribute it and/or
    //** modify it under the terms of the GNU Lesser General Public
    //** License as published by the Free Software Foundation; either
    //** version 3 of the License, or (at your option) any later version.
    //**
    //** This library is distributed in the hope that it will be useful,
    //** but WITHOUT ANY WARRANTY; without even the implied warranty of
    //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    //** Lesser General Public License for more details.
    //**
    //** In addition, as a special exception,  that plugins developed for iS3,
    //** are allowed to remain closed sourced and can be distributed under any license .
    //** These rights are included in the file LGPL_EXCEPTION.txt in this package.
    //**
    //**************************************************************************
    public class IS3View3D : IS3ViewBase, IView
    {
        #region IView interface
        public ViewType type { get { return ViewType.General3DView; } }
        public IEnumerable<IGraphicsLayer> layers { get { return null; } }
        public IGraphicsLayer drawingLayer { get { return null; } }
        public ISpatialReference spatialReference { get { return null; } }
        public void initializeView(){}

        public void onClose(){}

        public void highlightObject(DGObject obj, bool on = true){}
        public void highlightObjects(IEnumerable<DGObject> objs, bool on = true){}
        public void highlightObjects(IEnumerable<DGObject> objs,
            string layerID, bool on = true){}
        public void highlightAll(bool on = true){}

        public IMapPoint screenToLocation(System.Windows.Point screenPoint)
        { return null; }
        public System.Windows.Point locationToScreen(IMapPoint mapPoint)
        { return new System.Windows.Point(); }

        public void addSeletableLayer(string layerID) { }
        public void removeSelectableLayer(string layerID) { }

        public void zoomTo(IGeometry geom) { }

        public void addLayer(IGraphicsLayer layer){}
        public IGraphicsLayer getLayer(string layerID)
        {
            return null;
        }
        public IGraphicsLayer removeLayer(string layerID)
        {
            return null;
        }

        public void addLocalTiledLayer(string filePath, string id) { }
        public Task<IGraphicsLayer> addGdbLayer(LayerDef layerDef,
            string dbFile, int start = 0, int maxFeatures = 0)
        {
            return null;
        }

        public Task<IGraphicsLayer> addShpLayer(LayerDef layerDef,
            string shpFile, int start = 0, int maxFeatures = 0) 
        {
            return null;
        }


        public int syncObjects()
        {
            return 0;
        }
        public async Task loadPredefinedLayers()
        {
            Load3DScene();
        }
        public void objSelectionChangedListener(object sender,
            ObjSelectionChangedEventArgs e) { }
        public event EventHandler<ObjSelectionChangedEventArgs>
            objSelectionChangedTrigger;
        public event EventHandler<DrawingGraphicsChangedEventArgs>
            drawingGraphicsChangedTrigger;
        #endregion

        U3DPlayerAxLib.U3DPlayerControl _u3dPlayerControl;

        public IS3View3D(UserControl parent,
            U3DPlayerAxLib.U3DPlayerControl u3dPlayerControl)
        {
            _parent = parent;
            _u3dPlayerControl = u3dPlayerControl;
        }
        public bool IsValidFileName(string filename)
        {

            if (filename == null || filename.Count() == 0)
                return false;
            else
                return true;
        }


        public void Load3DScene()
        {
            // check file exists
            string filePath = _prj.projDef.LocalFilePath + "\\"
                + _eMap.LocalMapFileName;
            if (File.Exists(filePath))
            {
                _u3dPlayerControl.LoadScence(filePath);
            }
        }
    }
}
