//----------------------------------------------------------------------------
// NAME: Globe cursor
// VERSION: 1.0
// DESCRIPTION: Displays a floating cursor on the globe showing where a mouse click will land (and illustrating any raytracing error that may be present)
// DEVELOPER: Erik Newman, modified by Joel Bradshaw to use LineFeature
//----------------------------------------------------------------------------
//
// This file is in the Public Domain, and comes with no warranty.
//
using System;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Drawing;
using System.Xml.Serialization;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Windows.Forms;
using WorldWind;
using WorldWind.Renderable;
using WorldWind.Net;
using System.Xml;
namespace FiveOfOh.Plugins
{
public class GlobeCursorPlugin : WorldWind.PluginEngine.Plugin
{
MenuItem menuItem;
GlobeCursorLayer layer;
///
/// Plugin entry point
///
public override void Load()
{
layer = new GlobeCursorLayer(
ParentApplication.WorldWindow.CurrentWorld, ParentApplication.WorldWindow.DrawArgs);
ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Add(layer);
menuItem = new MenuItem("Globe Cursor\tM");
menuItem.Click += new EventHandler(menuItemClicked);
ParentApplication.ToolsMenu.MenuItems.Add(menuItem);
// Subscribe events
ParentApplication.WorldWindow.MouseMove += new MouseEventHandler(layer.MouseMove);
//Set tool inactive by default
layer.IsOn = false;
menuItem.Checked = layer.IsOn;
base.Load();
}
///
/// Unload our plugin
///
public override void Unload()
{
if (menuItem != null)
{
ParentApplication.ToolsMenu.MenuItems.Remove(menuItem);
menuItem.Dispose();
menuItem = null;
}
ParentApplication.WorldWindow.MouseMove -= new MouseEventHandler(layer.MouseMove);
ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Remove(layer);
//DrawArgs.NewRootWidget.Remove(resultwindow);
base.Unload();
}
private void menuItemClicked(object sender, EventArgs e)
{
layer.IsOn = !layer.IsOn;
menuItem.Checked = layer.IsOn;
}
}
///
/// This class is a Mouse gesture sensitive
/// Line Drawing class.
/// The mouse gestures should function as follows
/// in
/// 1: Single Line mode
/// * Left Click begins a single measurement line
/// * Mouse move dynamically updates line
/// * Second left click confirms the position of the line
/// * Right Click clears points and restarts measurements
///
class GlobeCursorLayer : LineFeature
{
#region Private Variables
private DrawArgs m_drawArgs;
#endregion
#region Accessor Methods
#endregion
public GlobeCursorLayer(World world, DrawArgs drawArgs) : base("Globe Cursor", world, new Point3d[0], Color.White)
{
m_drawArgs = drawArgs;
this.AltitudeMode = AltitudeMode.ClampedToGround;
/*
for(int i=0; i<11; i++) {
AddPoint(0,0,0);
}
this.NeedsUpdate = true;
*/
}
public override void Render(DrawArgs drawArgs)
{
base.Render(drawArgs);
}
#region Mouse Handlers
public void MouseMove(object sender, MouseEventArgs e)
{
if(!IsOn) {
return;
}
//TODO: Implement Dynamic generation of line segments for preview as mouse moves
// Don't know if this is best way to do things...
Angle Latitude, Longitude;
m_drawArgs.WorldCamera.PickingRayIntersection(
e.X,
e.Y,
out Latitude,
out Longitude);
Angle W, N;
m_drawArgs.WorldCamera.PickingRayIntersection(
e.X-10,
e.Y-10,
out N,
out W);
Angle E, S;
m_drawArgs.WorldCamera.PickingRayIntersection(
e.X+10,
e.Y+10,
out S,
out E);
double NS, EW;
NS = (N.Degrees + S.Degrees)/2;
EW = (E.Degrees + W.Degrees)/2;
//clear current thingie
this.Points = new Point3d[0];
double alt = 1000;
AddPoint(W.Degrees, NS, alt);
AddPoint(W.Degrees, N.Degrees, alt);
AddPoint(EW, N.Degrees, alt);
AddPoint(E.Degrees, N.Degrees,alt);
AddPoint(E.Degrees, S.Degrees,alt);
AddPoint(W.Degrees, S.Degrees,alt);
AddPoint(W.Degrees, NS, alt);
AddPoint(E.Degrees, NS, alt);
AddPoint(E.Degrees, N.Degrees, alt);
AddPoint(EW, N.Degrees, alt);
AddPoint(EW, S.Degrees, alt);
this.NeedsUpdate = true;
/*
Points[0].X = W.Degrees;
Points[0].Y = NS;
Points[1].X = W.Degrees;
Points[1].Y = N.Degrees;
Points[2].X = EW;
Points[2].Y = N.Degrees;
Points[3].X = E.Degrees;
Points[3].Y = N.Degrees;
Points[4].X = E.Degrees;
Points[4].Y = S.Degrees;
Points[5].X = W.Degrees;
Points[5].Y = S.Degrees;
Points[6].X = W.Degrees;
Points[6].Y = NS;
Points[7].X = E.Degrees;
Points[7].Y = NS;
Points[8].X = E.Degrees;
Points[8].Y = N.Degrees;
Points[9].X = EW;
Points[9].Y = N.Degrees;
Points[10].X = EW;
Points[10].Y = S.Degrees;
*/
}
#endregion
}
}