public GeoFenceSetup(GPSGeoFence gpsGeoFence, GpsTrackerPlugin Plugin)
        {
            m_GpsGeoFence = gpsGeoFence;
            m_Plugin = Plugin;
            InitializeComponent();

            textBoxSoundFile.Text = GpsTrackerPlugin.m_sPluginDirectory + "\\GeoFence.wav";
            textBoxSoundFileOut.Text = GpsTrackerPlugin.m_sPluginDirectory + "\\GeoFenceOut.wav";

            comboBoxGeoFenceSource.Items.Add("All Gps Sources");
            for (int i = 0; i < m_Plugin.gpsTracker.m_gpsSourceList.Count; i++)
            {
                GPSSource gpsSource = (GPSSource)m_Plugin.gpsTracker.m_gpsSourceList[i];
                if (gpsSource.sType != "POI" &&
                    gpsSource.sType != "GeoFence" &&
                    gpsSource.bWaypoints == false &&
                    gpsSource.bSetup)
                    comboBoxGeoFenceSource.Items.Add(gpsSource.sDescription);
            }
            comboBoxGeoFenceSource.Text = "All Gps Sources";
        }
        public GpsSetup(GPSIcon gpsIcon, GPSTrackLine gpsTrackLine, GPSGeoFence geoFence)
        {
            m_gpsIcon = gpsIcon;
            m_gpsTrackLine = gpsTrackLine;
            m_gpsFence = geoFence;

            InitializeComponent();

            if (m_gpsIcon!=null)
            {
                if (m_gpsIcon.m_RenderInfo.bPOI)
                {
                    checkBoxDistanceFromPOI.Enabled = true;
                    checkBoxDistanceFromPOI.Text = "Distance && bearing to " + m_gpsIcon.m_RenderInfo.sDescription + " from all Gps";
                    checkBoxDistanceFromPOI.Checked = m_gpsIcon.m_bSignalDistance;
                    checkBoxDistanceToPOI.Enabled = false;
                    checkBoxDistanceToPOI.Text = "Distance from " + m_gpsIcon.m_RenderInfo.sDescription + " to all POIs";
                    checkBoxTrackHeading.Enabled = false;
                    checkBoxTrackLine.Enabled = false;
                }
                else
                {
                    checkBoxDistanceFromPOI.Enabled = false;
                    checkBoxDistanceFromPOI.Text = "Distance && bearing to " + m_gpsIcon.m_RenderInfo.sDescription + " from all Gps";
                    checkBoxDistanceToPOI.Enabled = true;
                    checkBoxDistanceToPOI.Text = "Distance from " + m_gpsIcon.m_RenderInfo.sDescription + " to all POIs";
                    checkBoxDistanceToPOI.Checked = m_gpsIcon.m_bSignalDistance;
                }

                checkBoxInformationText.Checked = m_gpsIcon.m_bShowInfo;
                checkBoxTrackHeading.Checked = m_gpsIcon.m_bTrackHeading;
                checkBoxTrackLine.Checked = m_gpsIcon.m_bTrackLine;
                labelTitle.Text = "Set options for " + m_gpsIcon.m_RenderInfo.sDescription;
            }
            else
            if (m_gpsTrackLine != null)
            {
                checkBoxInformationText.Checked = m_gpsTrackLine.m_bShowInfo;
                checkBoxTrackHeading.Enabled = false;
                checkBoxTrackLine.Enabled = false;
                checkBoxDistanceFromPOI.Text = "Distance && bearing to " + m_gpsTrackLine.m_sDescription + " from all Gps";
                checkBoxDistanceFromPOI.Enabled = false;
                checkBoxDistanceToPOI.Text = "Distance from " + m_gpsTrackLine.m_sDescription + " to all POIs";
                checkBoxDistanceToPOI.Enabled = false;
                labelTitle.Text = "Set options for " + m_gpsIcon.m_RenderInfo.sDescription;
            }
            else
                if (m_gpsFence != null)
            {
                checkBoxInformationText.Checked = m_gpsFence.m_bShowInfo;
                checkBoxTrackHeading.Enabled = false;
                checkBoxTrackLine.Enabled = false;
                checkBoxDistanceFromPOI.Text = "Distance && bearing to " + m_gpsFence.m_sDescription + " from all Gps";
                checkBoxDistanceFromPOI.Enabled = false;
                checkBoxDistanceToPOI.Text = "Distance from " + m_gpsFence.m_sDescription + " to all POIs";
                checkBoxDistanceToPOI.Enabled = false;
                labelTitle.Text = "Set options for " + m_gpsFence.m_sDescription;
            }

            
        }
        public void AddGeoFence(GPSGeoFenceData geoFence)
        {
            lock ("RenderAccess")
            {
                //Resize array if necessary
                if (m_iGpsGeoFenceIndex >= m_uGeoFenceResize)
                {
                    m_uGeoFenceResize += 5;
                    Array.Resize(ref m_gpsGeoFence, (int)m_uGeoFenceResize);
                }

                if (m_gpsGeoFence[m_iGpsGeoFenceIndex] == null)
                {
                    m_gpsGeoFence[m_iGpsGeoFenceIndex] = new GPSGeoFence(ParentApplication.WorldWindow.CurrentWorld, "New Geo Fence", Plugin);
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bDone = false;
                    
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sDescription = geoFence.sName;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLat = (ArrayList)geoFence.arrayLat.Clone();
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLat.Add(m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLat[0]);
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLon = (ArrayList)geoFence.arrayLon.Clone();
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLon.Add(m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLon[0]);
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sEmail = geoFence.sEmail;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bEmailIn = geoFence.bEmailIn;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bEmailOut = geoFence.bEmailOut;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sSound = geoFence.sSound;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sSoundOut = geoFence.sSoundOut;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bSoundIn = geoFence.bSoundIn;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bSoundOut = geoFence.bSoundOut;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bMsgBoxIn = geoFence.bMsgBoxIn;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bMsgBoxOut = geoFence.bMsgBoxOut;
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bShowInfo = geoFence.bShowInfo;

                    m_gpsGeoFence[m_iGpsGeoFenceIndex].Initialize(this.drawArgs);
                    Add(m_gpsGeoFence[m_iGpsGeoFenceIndex]);
                    m_iGpsGeoFenceIndex++;
                }
            }
        }
		/// <summary>
		/// Handle mouse click
		/// </summary>
		public override bool PerformSelectionAction(DrawArgs drawArgs)
		{
            Point pLastMousePoint = DrawArgs.LastMousePosition;

			foreach(RenderableObject ro in ChildObjects)
			{
				if(!ro.IsOn || !ro.isSelectable)
					continue;

				if (ro.PerformSelectionAction(drawArgs))
					return true;
			}

			byte [] pbKeyState = new byte[256];
			GetKeyboardState(pbKeyState);
			if ((pbKeyState[VK_LSHIFT] & 0x80)==0x80)
			{
				Angle StartLatitude;
				Angle StartLongitude;
				drawArgs.WorldCamera.PickingRayIntersection(
                    pLastMousePoint.X,
                    pLastMousePoint.Y,
					out StartLatitude,
					out StartLongitude);

				if (!double.IsNaN(StartLatitude.Degrees) && !double.IsNaN(StartLongitude.Degrees))
				{
					POIName poiName = new POIName(this);
					m_sPOIName="";
					poiName.ShowDialog();
					poiName.Dispose();

					Plugin.pluginAddPOI(m_sPOIName, (float)StartLatitude.Degrees, (float)StartLongitude.Degrees);
				}
			}
            else
            if ((pbKeyState[VK_LALT] & 0x80) == 0x80)
            {
                lock ("RenderAccess")
                {
                    //Resize array if necessary
                    if (m_iGpsGeoFenceIndex >= m_uGeoFenceResize)
                    {
                        m_uGeoFenceResize += 5;
                        Array.Resize(ref m_gpsGeoFence, (int)m_uGeoFenceResize);
                    }

                    if (m_gpsGeoFence[m_iGpsGeoFenceIndex]==null)
                    {
                        m_gpsGeoFence[m_iGpsGeoFenceIndex] = new GPSGeoFence(ParentApplication.WorldWindow.CurrentWorld, "New Geo Fence", Plugin);
                        m_gpsGeoFence[m_iGpsGeoFenceIndex].Initialize(this.drawArgs);
                        m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bDone = false;
                        m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bShowInfo = true;
                        Add(m_gpsGeoFence[m_iGpsGeoFenceIndex]);
                    }
                    m_gpsGeoFence[m_iGpsGeoFenceIndex].AddGeoFence(drawArgs, pLastMousePoint);
                    if (m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bDone && m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bCancel == false)
                    {
                        GPSGeoFenceData geoFence = new GPSGeoFenceData();
                        geoFence.sName = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sDescription;
                        geoFence.sSource = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sSource;
                        geoFence.arrayLat = m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLat;
                        geoFence.arrayLon = m_gpsGeoFence[m_iGpsGeoFenceIndex].arrayLon;
                        geoFence.sEmail = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sEmail;
                        geoFence.sSound = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sSound;
                        geoFence.sSoundOut = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_sSoundOut;
                        geoFence.bEmailIn = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bEmailIn;
                        geoFence.bEmailOut = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bEmailOut;
                        geoFence.bSoundIn = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bSoundIn;
                        geoFence.bSoundOut = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bSoundOut;
                        geoFence.bMsgBoxIn = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bMsgBoxIn;
                        geoFence.bMsgBoxOut = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bMsgBoxOut;
                        geoFence.bShowInfo = m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bShowInfo;
                        geoFence.SourcesIn = new ArrayList();
                        geoFence.SourcesOut = new ArrayList();
                        Plugin.pluginAddGeoFenceToGpsTracker(geoFence);

                        m_iGpsGeoFenceIndex++;
                    }
                    else
                    if (m_gpsGeoFence[m_iGpsGeoFenceIndex].m_bCancel)
                    {
                        Remove(m_gpsGeoFence[m_iGpsGeoFenceIndex]);
                        m_gpsGeoFence[m_iGpsGeoFenceIndex].Dispose();
                        m_gpsGeoFence[m_iGpsGeoFenceIndex] = null;
                    }
                }
            }
			return false;
		}