home *** CD-ROM | disk | FTP | other *** search
/ Mundo do CD-ROM 119 / cdrom119.iso / internet / wwind / World_Wind_1.3.5_Full.exe / Plugins / doublezoom / doublezoom.cs
Encoding:
Text File  |  2006-05-08  |  30.9 KB  |  955 lines

  1. //----------------------------------------------------------------------------
  2. // NAME: Zoom Extender
  3. // VERSION: 2.0
  4. // DESCRIPTION: Adds options for zooming, based on Planimetric Measure Tool by Mashi.  Right-click on the entry in the layer manager to access options.  Thanks to Guest_Jim for his additions.
  5. // DEVELOPER: 5of0
  6. // WEBSITE: http://angrycatproductions.blogspot.com
  7. // REFERENCES:
  8. //----------------------------------------------------------------------------
  9. //
  10. // This file is in the Public Domain, and comes with no warranty. 
  11. // Thanks, Mashi and all those who helped in this process.
  12. //
  13. using System;
  14. using System.IO;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using Microsoft.DirectX;
  18. using Microsoft.DirectX.Direct3D;
  19. using System.Windows.Forms;
  20. using WorldWind;
  21. using WorldWind.Renderable;
  22. using WorldWind.Net;
  23.  
  24. namespace FiveofOh.Plugins
  25. {
  26.     /// <summary>
  27.     /// Zoom m_dialog.
  28.     /// </summary>
  29.     public class ZoomDialog : System.Windows.Forms.Form
  30.     {
  31.         public enum zoomFields
  32.         {
  33.             ZoomFact,
  34.             Shift,
  35.             Ctrl,
  36.             Alt,
  37.             IsLeftButton,
  38.             IsDoubleClick
  39.         }
  40.     
  41.         private System.Windows.Forms.Button btnCancel;
  42.         private System.Windows.Forms.Button btnOK;
  43.         private System.Windows.Forms.GroupBox grpZoomIn;
  44.         private System.Windows.Forms.Label lblZoomIn;
  45.         private System.Windows.Forms.CheckBox chkShiftIn;
  46.         private System.Windows.Forms.CheckBox chkCtrlIn;
  47.         private System.Windows.Forms.CheckBox chkAltIn;
  48.         private System.Windows.Forms.RadioButton optLeftIn;
  49.         private System.Windows.Forms.RadioButton optRightIn;
  50.         private System.Windows.Forms.RadioButton optSingleIn;
  51.         private System.Windows.Forms.RadioButton optDoubleIn;
  52.         private System.Windows.Forms.Label lblZoomFactIn;
  53.         private System.Windows.Forms.TextBox txtZoomFactIn;
  54.         private System.Windows.Forms.GroupBox grpButtonIn;
  55.         private System.Windows.Forms.GroupBox grpClickIn;
  56.         
  57.         private System.Windows.Forms.GroupBox grpZoomOut;
  58.         private System.Windows.Forms.Label lblZoomOut;
  59.         private System.Windows.Forms.CheckBox chkShiftOut;
  60.         private System.Windows.Forms.CheckBox chkCtrlOut;
  61.         private System.Windows.Forms.CheckBox chkAltOut;
  62.         private System.Windows.Forms.RadioButton optLeftOut;
  63.         private System.Windows.Forms.RadioButton optRightOut;
  64.         private System.Windows.Forms.RadioButton optSingleOut;
  65.         private System.Windows.Forms.RadioButton optDoubleOut;
  66.         private System.Windows.Forms.Label lblZoomFactOut;
  67.         private System.Windows.Forms.TextBox txtZoomFactOut;
  68.         private System.Windows.Forms.GroupBox grpButtonOut;
  69.         private System.Windows.Forms.GroupBox grpClickOut;
  70.         
  71.         private DoubleClickZoomerLayer m_Layer;
  72.         private string m_FilePath;
  73.  
  74.         public ZoomDialog(DoubleClickZoomerLayer layer, string zoomFilePath)
  75.         {
  76.             m_Layer = layer;
  77.             m_FilePath = zoomFilePath;
  78.             InitializeComponent();
  79.             UpdateUI( zoomFilePath );
  80.         }
  81.         
  82.         #region Windows Form Designer generated code
  83.         /// <summary>
  84.         /// Required method for Designer support - do not modify
  85.         /// the contents of this method with the code editor.
  86.         /// </summary>
  87.         private void InitializeComponent()
  88.         {
  89.             this.btnCancel = new System.Windows.Forms.Button();
  90.             this.btnOK = new System.Windows.Forms.Button();
  91.             this.grpZoomIn = new System.Windows.Forms.GroupBox();
  92.             this.lblZoomIn = new System.Windows.Forms.Label();
  93.             this.chkShiftIn = new System.Windows.Forms.CheckBox();
  94.             this.chkCtrlIn = new System.Windows.Forms.CheckBox();
  95.             this.chkAltIn = new System.Windows.Forms.CheckBox();
  96.             this.optLeftIn = new System.Windows.Forms.RadioButton();
  97.             this.optRightIn = new System.Windows.Forms.RadioButton();
  98.             this.optSingleIn = new System.Windows.Forms.RadioButton();
  99.             this.optDoubleIn = new System.Windows.Forms.RadioButton();
  100.             this.lblZoomFactIn = new System.Windows.Forms.Label();
  101.             this.txtZoomFactIn = new System.Windows.Forms.TextBox();
  102.             this.grpButtonIn = new System.Windows.Forms.GroupBox();
  103.             this.grpClickIn = new System.Windows.Forms.GroupBox();
  104.             
  105.             this.grpZoomOut = new System.Windows.Forms.GroupBox();
  106.             this.lblZoomOut = new System.Windows.Forms.Label();
  107.             this.chkShiftOut = new System.Windows.Forms.CheckBox();
  108.             this.chkCtrlOut = new System.Windows.Forms.CheckBox();
  109.             this.chkAltOut = new System.Windows.Forms.CheckBox();
  110.             this.optLeftOut = new System.Windows.Forms.RadioButton();
  111.             this.optRightOut = new System.Windows.Forms.RadioButton();
  112.             this.optSingleOut = new System.Windows.Forms.RadioButton();
  113.             this.optDoubleOut = new System.Windows.Forms.RadioButton();
  114.             this.lblZoomFactOut = new System.Windows.Forms.Label();
  115.             this.txtZoomFactOut = new System.Windows.Forms.TextBox();
  116.             this.grpButtonOut = new System.Windows.Forms.GroupBox();
  117.             this.grpClickOut = new System.Windows.Forms.GroupBox();
  118.             
  119.             this.grpZoomIn.SuspendLayout();
  120.             this.grpZoomOut.SuspendLayout();
  121.             this.SuspendLayout();
  122.             
  123.             // 
  124.             // chkShift
  125.             // 
  126.             this.chkShiftIn.Checked = true;
  127.             this.chkShiftIn.CheckState = System.Windows.Forms.CheckState.Checked;
  128.             this.chkShiftIn.Location = new System.Drawing.Point(8, 16);
  129.             this.chkShiftIn.Name = "chkShift";
  130.             this.chkShiftIn.Size = new System.Drawing.Size(72, 24);
  131.             this.chkShiftIn.TabIndex = 14;
  132.             this.chkShiftIn.Text = "Shift";
  133.             
  134.             // 
  135.             // chkCtrl
  136.             // 
  137.             this.chkCtrlIn.Checked = true;
  138.             this.chkCtrlIn.CheckState = System.Windows.Forms.CheckState.Checked;
  139.             this.chkCtrlIn.Location = new System.Drawing.Point(8, 40);
  140.             this.chkCtrlIn.Name = "chkCtrl";
  141.             this.chkCtrlIn.Size = new System.Drawing.Size(72, 24);
  142.             this.chkCtrlIn.TabIndex = 14;
  143.             this.chkCtrlIn.Text = "Control";
  144.             
  145.             // 
  146.             // chkAltIn
  147.             // 
  148.             this.chkAltIn.Checked = true;
  149.             this.chkAltIn.CheckState = System.Windows.Forms.CheckState.Checked;
  150.             this.chkAltIn.Location = new System.Drawing.Point(8, 64);
  151.             this.chkAltIn.Name = "chkAlt";
  152.             this.chkAltIn.Size = new System.Drawing.Size(72, 24);
  153.             this.chkAltIn.TabIndex = 14;
  154.             this.chkAltIn.Text = "Alt";
  155.             
  156.             //
  157.             // lblZoomFactIn
  158.             //
  159.             this.lblZoomFactIn.Location = new System.Drawing.Point(8, 96);
  160.             this.lblZoomFactIn.Name = "lblZoomFactIn";
  161.             this.lblZoomFactIn.Size = new System.Drawing.Size(72, 16);
  162.             this.lblZoomFactIn.TabIndex = 9;
  163.             this.lblZoomFactIn.Text = "Zoom Factor:";
  164.             
  165.             ///
  166.             /// txtZoomFactIn
  167.             ///
  168.             this.txtZoomFactIn.Location = new System.Drawing.Point(8, 112);
  169.             this.txtZoomFactIn.Name = "txtZoomFactIn";
  170.             this.txtZoomFactIn.Size = new System.Drawing.Size(72, 24);
  171.             this.txtZoomFactIn.TabIndex = 16;
  172.             this.txtZoomFactIn.Text = "";
  173.             
  174.             //
  175.             // optLeftIn
  176.             //
  177.             this.optLeftIn.Checked = true;
  178.             this.optLeftIn.Location = new System.Drawing.Point(8, 16);
  179.             this.optLeftIn.Name = "optLeftIn";
  180.             this.optLeftIn.Size = new System.Drawing.Size(64, 16);
  181.             this.optLeftIn.TabIndex = 1;
  182.             this.optLeftIn.TabStop = true;
  183.             this.optLeftIn.Text = "Left";
  184.             
  185.             //
  186.             // optRightIn
  187.             //
  188.             this.optRightIn.Checked = true;
  189.             this.optRightIn.Location = new System.Drawing.Point(8, optLeftIn.Top + optLeftIn.Height);
  190.             this.optRightIn.Name = "optRightIn";
  191.             this.optRightIn.Size = new System.Drawing.Size(64, 16);
  192.             this.optRightIn.TabIndex = 1;
  193.             this.optRightIn.TabStop = true;
  194.             this.optRightIn.Text = "Right";
  195.             
  196.             // 
  197.             // grpButtonIn
  198.             // 
  199.             this.grpButtonIn.Controls.Add(this.optLeftIn);
  200.             this.grpButtonIn.Controls.Add(this.optRightIn);
  201.             this.grpButtonIn.Location = new System.Drawing.Point(88, 16);
  202.             this.grpButtonIn.Name = "grpButtonIn";
  203.             this.grpButtonIn.Size = new System.Drawing.Size(88, 56);
  204.             this.grpButtonIn.TabIndex = 26;
  205.             this.grpButtonIn.TabStop = false;
  206.             this.grpButtonIn.Text = "Button:";
  207.             this.grpButtonIn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  208.             this.grpButtonIn.Visible = true;
  209.  
  210.             //
  211.             // optSingleIn
  212.             //
  213.             this.optSingleIn.Checked = true;
  214.             this.optSingleIn.Location = new System.Drawing.Point(8, 16);
  215.             this.optSingleIn.Name = "optSingleIn";
  216.             this.optSingleIn.Size = new System.Drawing.Size(64, 16);
  217.             this.optSingleIn.TabIndex = 1;
  218.             this.optSingleIn.TabStop = true;
  219.             this.optSingleIn.Text = "Single";
  220.             
  221.             //
  222.             // optDoubleIn
  223.             //
  224.             this.optDoubleIn.Checked = true;
  225.             this.optDoubleIn.Location = new System.Drawing.Point(8, optSingleIn.Top + optSingleIn.Height);
  226.             this.optDoubleIn.Name = "optDoubleIn";
  227.             this.optDoubleIn.Size = new System.Drawing.Size(64, 16);
  228.             this.optDoubleIn.TabIndex = 1;
  229.             this.optDoubleIn.TabStop = true;
  230.             this.optDoubleIn.Text = "Double";
  231.             
  232.             // 
  233.             // grpClickIn
  234.             // 
  235.             this.grpClickIn.Controls.Add(this.optSingleIn);
  236.             this.grpClickIn.Controls.Add(this.optDoubleIn);
  237.             this.grpClickIn.Location = new System.Drawing.Point(88, 72);
  238.             this.grpClickIn.Name = "grpClickIn";
  239.             this.grpClickIn.Size = new System.Drawing.Size(88, 56);
  240.             this.grpClickIn.TabIndex = 26;
  241.             this.grpClickIn.TabStop = false;
  242.             this.grpClickIn.Text = "Click:";
  243.             this.grpClickIn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  244.             this.grpClickIn.Visible = true;
  245.  
  246.             // 
  247.             // grpZoomIn
  248.             // 
  249.             this.grpZoomIn.Controls.Add(this.chkShiftIn);
  250.             this.grpZoomIn.Controls.Add(this.chkCtrlIn);
  251.             this.grpZoomIn.Controls.Add(this.chkAltIn);
  252.             this.grpZoomIn.Controls.Add(this.lblZoomFactIn);
  253.             this.grpZoomIn.Controls.Add(this.txtZoomFactIn);
  254.             this.grpZoomIn.Controls.Add(this.grpButtonIn);
  255.             this.grpZoomIn.Controls.Add(this.grpClickIn);
  256.             this.grpZoomIn.Location = new System.Drawing.Point(8, 8);
  257.             this.grpZoomIn.Name = "grpZoomIn";
  258.             this.grpZoomIn.Size = new System.Drawing.Size(184, 144);
  259.             this.grpZoomIn.TabIndex = 26;
  260.             this.grpZoomIn.TabStop = false;
  261.             this.grpZoomIn.Text = "Zoom In:";
  262.             this.grpZoomIn.Visible = true;
  263.  
  264.             // 
  265.             // chkShiftOut
  266.             // 
  267.             this.chkShiftOut.Checked = true;
  268.             this.chkShiftOut.CheckState = System.Windows.Forms.CheckState.Checked;
  269.             this.chkShiftOut.Location = this.chkShiftIn.Location;
  270.             this.chkShiftOut.Name = "chkShiftOut";
  271.             this.chkShiftOut.Size = this.chkShiftIn.Size;
  272.             this.chkShiftOut.TabIndex = 14;
  273.             this.chkShiftOut.Text = "Shift";
  274.             
  275.             // 
  276.             // chkCtrlOut
  277.             // 
  278.             this.chkCtrlOut.Checked = true;
  279.             this.chkCtrlOut.CheckState = System.Windows.Forms.CheckState.Checked;
  280.             this.chkCtrlOut.Location = this.chkCtrlIn.Location;
  281.             this.chkCtrlOut.Name = "chkCtrlOut";
  282.             this.chkCtrlOut.Size = this.chkCtrlIn.Size;
  283.             this.chkCtrlOut.TabIndex = 14;
  284.             this.chkCtrlOut.Text = "Control";
  285.             
  286.             // 
  287.             // chkAltOut
  288.             // 
  289.             this.chkAltOut.Checked = true;
  290.             this.chkAltOut.CheckState = System.Windows.Forms.CheckState.Checked;
  291.             this.chkAltOut.Location = this.chkAltIn.Location;
  292.             this.chkAltOut.Name = "chkAltOut";
  293.             this.chkAltOut.Size = this.chkAltIn.Size;
  294.             this.chkAltOut.TabIndex = 14;
  295.             this.chkAltOut.Text = "Alt";
  296.             
  297.             //
  298.             // lblZoomFactOut
  299.             //
  300.             this.lblZoomFactOut.Location = this.lblZoomFactIn.Location;
  301.             this.lblZoomFactOut.Name = "lblZoomFactOut";
  302.             this.lblZoomFactOut.Size = this.lblZoomFactIn.Size;
  303.             this.lblZoomFactOut.TabIndex = 9;
  304.             this.lblZoomFactOut.Text = "Zoom Factor:";
  305.             
  306.             //
  307.             // txtZoomFactOut
  308.             //
  309.             this.txtZoomFactOut.Location = this.txtZoomFactIn.Location;
  310.             this.txtZoomFactOut.Name = "txtZoomFactOut";
  311.             this.txtZoomFactOut.Size = this.txtZoomFactIn.Size;
  312.             this.txtZoomFactOut.TabIndex = 16;
  313.             this.txtZoomFactOut.Text = "";
  314.             
  315.             //
  316.             // optLeftOut
  317.             //
  318.             this.optLeftOut.Checked = true;
  319.             this.optLeftOut.Location = this.optLeftIn.Location;
  320.             this.optLeftOut.Name = "optLeftOut";
  321.             this.optLeftOut.Size = this.optLeftIn.Size;
  322.             this.optLeftOut.TabIndex = 1;
  323.             this.optLeftOut.TabStop = true;
  324.             this.optLeftOut.Text = this.optLeftIn.Text;
  325.             
  326.             //
  327.             // optRightOut
  328.             //
  329.             this.optRightOut.Checked = true;
  330.             this.optRightOut.Location = this.optRightIn.Location;
  331.             this.optRightOut.Name = "optRightOut";
  332.             this.optRightOut.Size = this.optRightIn.Size;
  333.             this.optRightOut.TabIndex = 1;
  334.             this.optRightOut.TabStop = true;
  335.             this.optRightOut.Text = this.optRightIn.Text;
  336.             
  337.             // 
  338.             // grpButtonOut
  339.             // 
  340.             this.grpButtonOut.Controls.Add(this.optLeftOut);
  341.             this.grpButtonOut.Controls.Add(this.optRightOut);
  342.             this.grpButtonOut.Location = this.grpButtonIn.Location;
  343.             this.grpButtonOut.Name = "grpButtonOut";
  344.             this.grpButtonOut.Size = this.grpButtonIn.Size;
  345.             this.grpButtonOut.TabIndex = 26;
  346.             this.grpButtonOut.TabStop = false;
  347.             this.grpButtonOut.Text = this.grpButtonIn.Text;
  348.             this.grpButtonOut.FlatStyle = this.grpButtonIn.FlatStyle;
  349.             this.grpButtonOut.Visible = true;
  350.  
  351.             //
  352.             // optSingleOut
  353.             //
  354.             this.optSingleOut.Checked = true;
  355.             this.optSingleOut.Location = this.optSingleIn.Location;
  356.             this.optSingleOut.Name = "optSingleOut";
  357.             this.optSingleOut.Size = this.optSingleIn.Size;
  358.             this.optSingleOut.TabIndex = 1;
  359.             this.optSingleOut.TabStop = true;
  360.             this.optSingleOut.Text = this.optSingleIn.Text;
  361.             
  362.             //
  363.             // optDoubleOut
  364.             //
  365.             this.optDoubleOut.Checked = true;
  366.             this.optDoubleOut.Location = this.optDoubleIn.Location;
  367.             this.optDoubleOut.Name = "optDoubleOut";
  368.             this.optDoubleOut.Size = this.optDoubleIn.Size;
  369.             this.optDoubleOut.TabIndex = 1;
  370.             this.optDoubleOut.TabStop = true;
  371.             this.optDoubleOut.Text = this.optDoubleIn.Text;
  372.             
  373.             // 
  374.             // grpClickOut
  375.             // 
  376.             this.grpClickOut.Controls.Add(this.optSingleOut);
  377.             this.grpClickOut.Controls.Add(this.optDoubleOut);
  378.             this.grpClickOut.Location = this.grpClickIn.Location;
  379.             this.grpClickOut.Name = "grpClickOut";
  380.             this.grpClickOut.Size = this.grpClickIn.Size;
  381.             this.grpClickOut.TabIndex = 26;
  382.             this.grpClickOut.TabStop = false;
  383.             this.grpClickOut.Text = this.grpClickIn.Text;
  384.             this.grpClickOut.FlatStyle = this.grpClickIn.FlatStyle;
  385.             this.grpClickOut.Visible = true;
  386.  
  387.             // 
  388.             // grpZoomOut
  389.             // 
  390.             this.grpZoomOut.Controls.Add(this.chkShiftOut);
  391.             this.grpZoomOut.Controls.Add(this.chkCtrlOut);
  392.             this.grpZoomOut.Controls.Add(this.chkAltOut);
  393.             this.grpZoomOut.Controls.Add(this.lblZoomFactOut);
  394.             this.grpZoomOut.Controls.Add(this.txtZoomFactOut);
  395.             this.grpZoomOut.Controls.Add(this.grpButtonOut);
  396.             this.grpZoomOut.Controls.Add(this.grpClickOut);
  397.             this.grpZoomOut.Location = new System.Drawing.Point(this.grpZoomIn.Left+this.grpZoomIn.Width+8, this.grpZoomIn.Top);
  398.             this.grpZoomOut.Name = "grpZoomOut";
  399.             this.grpZoomOut.Size = this.grpZoomIn.Size;
  400.             this.grpZoomOut.TabIndex = 26;
  401.             this.grpZoomOut.TabStop = false;
  402.             this.grpZoomOut.Text = "Zoom Out:";
  403.             this.grpZoomOut.Visible = true;
  404.     
  405.             // 
  406.             // btnOK
  407.             // 
  408.             this.btnOK.Location = new System.Drawing.Point(grpZoomIn.Left + (grpZoomIn.Width - 72)/2, grpZoomIn.Top + grpZoomIn.Height + 8);
  409.             this.btnOK.Name = "btnOK";
  410.             this.btnOK.TabIndex = 1;
  411.             this.btnOK.Text = "OK";
  412.             this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
  413.  
  414.             // 104 wide, 104 tall
  415.             // btnCancel
  416.             // 
  417.             this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  418.             this.btnCancel.Location = new System.Drawing.Point(grpZoomOut.Left + (grpZoomOut.Width - 72)/2, grpZoomOut.Top + grpZoomOut.Height + 8);
  419.             this.btnCancel.Name = "btnCancel";
  420.             this.btnCancel.TabIndex = 0;
  421.             this.btnCancel.Text = "Cancel";
  422.             this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  423.  
  424.             // 
  425.             // zDialog
  426.             // 
  427.             this.AcceptButton = this.btnOK;
  428.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  429.             this.CancelButton = this.btnCancel;
  430.             this.ClientSize = new System.Drawing.Size(grpZoomOut.Left + grpZoomOut.Width + 8, btnCancel.Top + btnCancel.Height + 8);
  431.             this.ControlBox = false;
  432.             this.Controls.Add(this.btnOK);
  433.             this.Controls.Add(this.btnCancel);
  434.             this.Controls.Add(this.grpZoomIn);
  435.             this.Controls.Add(this.grpZoomOut);
  436.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  437.             this.MaximizeBox = false;
  438.             this.MinimizeBox = false;
  439.             this.Name = "ZoomDialog";
  440.             this.ShowInTaskbar = true;
  441.             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  442.             this.Text = "Zoom Options";
  443.             //this.TopMost = true;
  444.             this.Load += new System.EventHandler(this.ZoomDialog_Load);
  445.             this.grpZoomIn.ResumeLayout(false);
  446.             this.grpZoomOut.ResumeLayout(false);
  447.             this.ResumeLayout(false);
  448.         }
  449.         #endregion
  450.     
  451.         /// <summary>
  452.         /// UI settings
  453.         /// </summary>
  454.         private void UpdateUI(string zoomFilePath)
  455.         {
  456.             //Get our favorites from text file
  457.             try
  458.             {
  459.                 using(TextReader tr = File.OpenText(zoomFilePath))
  460.                 {
  461.                     
  462.                     //Get the Zoom In Settings
  463.                     string line = tr.ReadLine();
  464.                     string[] fields = line.Split(';');
  465.                     txtZoomFactIn.Text = double.Parse(fields[(int)zoomFields.ZoomFact]).ToString();
  466.                     
  467.                     chkShiftIn.Checked = bool.Parse(fields[(int)zoomFields.Shift]);
  468.                     chkCtrlIn.Checked = bool.Parse(fields[(int)zoomFields.Ctrl]);
  469.                     chkAltIn.Checked = bool.Parse(fields[(int)zoomFields.Alt]);
  470.                     
  471.                     optLeftIn.Checked = bool.Parse(fields[(int)zoomFields.IsLeftButton]);
  472.                     optRightIn.Checked = !optLeftIn.Checked;
  473.                     
  474.                     optDoubleIn.Checked = bool.Parse(fields[(int)zoomFields.IsDoubleClick]);
  475.                     optSingleIn.Checked = !optDoubleIn.Checked;
  476.  
  477.                     //Get the Zoom In Settings
  478.                     line = tr.ReadLine();
  479.                     fields = line.Split(';');
  480.                     txtZoomFactOut.Text = double.Parse(fields[(int)zoomFields.ZoomFact]).ToString();
  481.                     
  482.                     chkShiftOut.Checked = bool.Parse(fields[(int)zoomFields.Shift]);
  483.                     chkCtrlOut.Checked = bool.Parse(fields[(int)zoomFields.Ctrl]);
  484.                     chkAltOut.Checked = bool.Parse(fields[(int)zoomFields.Alt]);
  485.                     
  486.                     optLeftOut.Checked = bool.Parse(fields[(int)zoomFields.IsLeftButton]);
  487.                     optRightOut.Checked = !optLeftOut.Checked;
  488.                     
  489.                     optDoubleOut.Checked = bool.Parse(fields[(int)zoomFields.IsDoubleClick]);
  490.                     optSingleOut.Checked = !optDoubleOut.Checked;
  491.  
  492.                     tr.Close();
  493.                 }
  494.             }
  495.             catch(Exception caught)
  496.             {
  497.                 Utility.Log.Write( caught );
  498.                 string msg = "Failed to parse " + zoomFilePath + "\n\n" + caught.Message;
  499.                 // Clean up, remove menu item
  500.                 throw new ApplicationException( msg );
  501.             }
  502.         }
  503.     
  504.         private void btnOK_Click(object sender, System.EventArgs e)
  505.         {
  506.             try 
  507.             {
  508.                 if ( double.Parse(txtZoomFactIn.Text) < 1 ) { txtZoomFactIn.Text = (1/double.Parse(txtZoomFactIn.Text)).ToString(); }
  509.                 if ( double.Parse(txtZoomFactOut.Text) < 1 ) { txtZoomFactOut.Text = (1/double.Parse(txtZoomFactOut.Text)).ToString(); }
  510.  
  511.             }
  512.             catch (Exception caught)
  513.             {
  514.               return;
  515.             }
  516.             
  517.             //Get our favorites from text file
  518.             try
  519.             {
  520.                 StreamWriter objSW = new StreamWriter(m_FilePath);
  521.                 
  522.                 //Write it
  523.  
  524.                 string keyLine1 = string.Format("{0};{1};{2};{3};{4};{5}", double.Parse(txtZoomFactIn.Text), chkShiftIn.Checked, chkCtrlIn.Checked, chkAltIn.Checked, optLeftIn.Checked, optDoubleIn.Checked);
  525.                 objSW.WriteLine ( keyLine1.ToLower() );
  526.  
  527.                 string keyLine2 = string.Format("{0};{1};{2};{3};{4};{5}", double.Parse(txtZoomFactOut.Text), chkShiftOut.Checked, chkCtrlOut.Checked, chkAltOut.Checked, optLeftOut.Checked, optDoubleOut.Checked);
  528.                 objSW.WriteLine ( keyLine2.ToLower() );
  529.                 
  530.                 objSW.Close();
  531.             }
  532.             catch(Exception caught)
  533.             {
  534.                 Utility.Log.Write( caught );
  535.                 string msg = "Failed to write to " + m_FilePath + "\n\n" + caught.Message;
  536.                 // Clean up, remove menu item
  537.                 throw new ApplicationException( msg );
  538.             }
  539.             
  540.             m_Layer.LoadSettings();        //Force the settings to be enacted
  541.             // Close this form
  542.             this.Close();
  543.         }
  544.     
  545.         private void btnCancel_Click(object sender, System.EventArgs e)
  546.         {
  547.             // Close this form
  548.             this.Close();
  549.         }
  550.     
  551.         private void ZoomDialog_Load(object sender, System.EventArgs e)
  552.         {
  553.         
  554.         }            
  555.     }
  556.  
  557.  
  558.     /// <summary>
  559.     /// Planimetric Measure Tool plug-in
  560.     /// </summary>
  561.     public class DoubleClickZoomer : WorldWind.PluginEngine.Plugin
  562.     {
  563.         MenuItem menuItem;
  564.         DoubleClickZoomerLayer layer;
  565.         string zoomFilePath;
  566.         string zoomFile = "DoubleZoom.ini";
  567.         ZoomDialog m_Dialog;
  568.         
  569.         public enum zoomFields
  570.         {
  571.             ZoomFact,
  572.             Shift,
  573.             Ctrl,
  574.             Alt,
  575.             IsLeftButton,
  576.             IsDoubleClick
  577.         }
  578.  
  579.         /// <summary>
  580.         /// Plugin entry point 
  581.         /// </summary>
  582.         public override void Load() 
  583.         {
  584.             zoomFilePath = Path.Combine(PluginDirectory, zoomFile);
  585.  
  586.             menuItem = new MenuItem("Zoom Extender\tZ");
  587.             menuItem.Click += new EventHandler(menuItemClicked);
  588.             ParentApplication.ToolsMenu.MenuItems.Add( menuItem );
  589.  
  590.             layer = new DoubleClickZoomerLayer(
  591.                 ParentApplication.WorldWindow.CurrentWorld,
  592.                 ParentApplication.WorldWindow.DrawArgs,
  593.                 ParentApplication.WorldWindow, 
  594.                 menuItem,
  595.                 zoomFilePath );
  596.  
  597.             ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Add(layer);
  598.  
  599.             //Get the saved settings
  600.             //Code blatantly lifted from Doug Hill's Favorites plugin - thanks Doug!
  601.             
  602.             //Check for ini file and create if not there.
  603.             if (!File.Exists(zoomFilePath)) 
  604.             {
  605.                 string zoomLineIn = string.Format("{0};{1};{2};{3};{4};{5}", 2, false, false, false, true, true);
  606.                 string zoomLineOut = string.Format("{0};{1};{2};{3};{4};{5}", 2, false, false, false, false, true);
  607.                 StreamWriter sr = new StreamWriter(zoomFilePath);
  608.                 sr.WriteLine ( zoomLineIn.ToLower() );
  609.                 sr.WriteLine ( zoomLineOut.ToLower() );
  610.                 sr.Close();
  611.             }
  612.             
  613.             layer.LoadSettings();
  614.             
  615.             // Subscribe events
  616.             ParentApplication.WorldWindow.DoubleClick +=new EventHandler(layer.DoubleClick);
  617.             ParentApplication.WorldWindow.MouseDown +=new MouseEventHandler(layer.MouseDown);
  618.             ParentApplication.WorldWindow.KeyUp += new KeyEventHandler(layer.KeyUp);
  619.             ParentApplication.WorldWindow.Click +=new EventHandler(layer.Click);
  620.  
  621.             // Display the dialog
  622. //            m_Dialog = new ZoomDialog( this.zoomFilePath );
  623. //            m_Dialog.Show();
  624.         }
  625.         
  626.         /// <summary>
  627.         /// Unload our plugin
  628.         /// </summary>
  629.         public override void Unload() 
  630.         {
  631.             if(menuItem!=null)
  632.             {
  633.                 ParentApplication.ToolsMenu.MenuItems.Remove( menuItem );
  634.                 menuItem.Dispose();
  635.                 menuItem = null;
  636.             }
  637.             
  638.             
  639.             //Writes settings, again stolen from favorites
  640.             // Write the file
  641.             bool ShiftIn = false; bool CtrlIn = false; bool AltIn = false;
  642.  
  643.             StreamWriter objSW = new StreamWriter(zoomFilePath);
  644.  
  645.             //Set variables for Zooming In modifier keys
  646.             if ( ( layer.ShiftKeysIn & Keys.Shift ) == Keys.Shift ) { ShiftIn = true; }
  647.             if ( ( layer.ShiftKeysIn & Keys.Control ) == Keys.Control ) { CtrlIn = true; }
  648.             if ( ( layer.ShiftKeysIn & Keys.Alt ) == Keys.Alt ) { AltIn = true; }
  649.             
  650.             //Write it
  651.             string keyLineIn = string.Format("{0};{1};{2};{3};{4};{5}", layer.ZoomFactIn, ShiftIn, CtrlIn, AltIn, layer.IsLeftButtonIn, layer.IsDoubleClickIn);
  652.             objSW.WriteLine ( keyLineIn.ToLower() );
  653.  
  654.             bool ShiftOut = false; bool CtrlOut = false; bool AltOut = false;
  655.  
  656.             //Set variables for Zooming In modifier keys
  657.             if ( ( layer.ShiftKeysOut & Keys.Shift ) == Keys.Shift ) { ShiftOut = true; }
  658.             if ( ( layer.ShiftKeysOut & Keys.Control ) == Keys.Control ) { CtrlOut = true; }
  659.             if ( ( layer.ShiftKeysOut & Keys.Alt ) == Keys.Alt ) { AltOut = true; }
  660.             
  661.             //Write it
  662.             string keyLineOut = string.Format("{0};{1};{2};{3};{4};{5}", layer.ZoomFactOut, ShiftOut, CtrlOut, AltOut, layer.IsLeftButtonOut, layer.IsDoubleClickOut);
  663.             objSW.WriteLine ( keyLineOut.ToLower() );
  664.             
  665.             objSW.Close();
  666.             
  667.             
  668.             ParentApplication.WorldWindow.DoubleClick -= new EventHandler(layer.DoubleClick);
  669.             ParentApplication.WorldWindow.MouseDown -= new MouseEventHandler(layer.MouseDown);
  670.             ParentApplication.WorldWindow.KeyUp -= new KeyEventHandler(layer.KeyUp);
  671.             ParentApplication.WorldWindow.Click -= new EventHandler(layer.Click);
  672.             
  673.             ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Remove(layer);
  674.         }
  675.     
  676.         void menuItemClicked(object sender, EventArgs e)
  677.         {
  678.             layer.IsOn = !layer.IsOn;
  679.             menuItem.Checked = layer.IsOn;
  680.         }
  681.     }
  682.  
  683.     public class DoubleClickZoomerLayer : WorldWind.Renderable.RenderableObject
  684.     {
  685.  
  686.         public Keys ShiftKeysIn;
  687.         public double ZoomFactIn;
  688.         public bool IsLeftButtonIn;
  689.         public bool IsDoubleClickIn;
  690.         public Keys ShiftKeysOut;
  691.         public double ZoomFactOut;
  692.         public bool IsLeftButtonOut;
  693.         public bool IsDoubleClickOut;
  694.  
  695.         public enum zoomFields
  696.         {
  697.             ZoomFact,
  698.             Shift,
  699.             Ctrl,
  700.             Alt,
  701.             IsLeftButton,
  702.             IsDoubleClick
  703.         }
  704.  
  705.         #region Private parts
  706.         DrawArgs m_drawArgs;
  707.         World m_world;
  708.         WorldWindow m_window;
  709.         bool isPointGotoEnabled;
  710.         Point mouseDownPoint;
  711.         Angle qLatitude;
  712.         Angle qLongitude;
  713.         bool LeftClicked;
  714.         MenuItem m_menuItem;
  715.         ZoomDialog zDialog;
  716.         string m_FilePath;
  717.         
  718.         #endregion
  719.  
  720.         public DoubleClickZoomerLayer(World world, DrawArgs drawArgs, WorldWindow worldWindow, MenuItem menuItem, string ZoomFilePath) : base("Zoom Extender")
  721.         {
  722.             m_world = world;
  723.             m_drawArgs = drawArgs;
  724.             m_window = worldWindow;
  725.             m_menuItem = menuItem;
  726.             m_FilePath = ZoomFilePath;
  727.  
  728.             RenderPriority = RenderPriority.Placenames;
  729.             IsOn = true;
  730.         }
  731.         
  732.         public void KeyUp(object sender, KeyEventArgs e)
  733.         {
  734.             if (e.KeyData==Keys.Z)
  735.             {
  736.                 IsOn = !IsOn;
  737.                 e.Handled = true;
  738.             }
  739.         }
  740.         
  741.         public void DoubleClick( object sender, EventArgs e )
  742.         {
  743.             double Coeff;
  744.             
  745.             if(!isOn)
  746.                 return;
  747.             
  748.             mouseDownPoint = DrawArgs.LastMousePosition;
  749.             m_drawArgs.WorldCamera.PickingRayIntersection(
  750.                 (int)mouseDownPoint.X,
  751.                 (int)mouseDownPoint.Y,
  752.                 out qLatitude,
  753.                 out qLongitude);
  754.             if ( this.IsDoubleClickIn && ( ( Control.ModifierKeys & this.ShiftKeysIn ) == this.ShiftKeysIn ) && ( LeftClicked == this.IsLeftButtonIn ) ) {
  755.                 Coeff = 1/ZoomFactIn;
  756.             }
  757.             else if ( this.IsDoubleClickOut && ( ( Control.ModifierKeys & this.ShiftKeysOut ) == this.ShiftKeysOut ) && ( LeftClicked == this.IsLeftButtonOut ) ) {
  758.                 Coeff = ZoomFactOut;
  759.             }
  760.             else {
  761.                 return;
  762.             }
  763.             m_window.GotoLatLonAltitude( qLatitude.Degrees, qLongitude.Degrees, Coeff*m_drawArgs.WorldCamera.Altitude );
  764.         }
  765.         
  766.         public void Click( object sender, EventArgs e )
  767.         {
  768.             double Coeff;
  769.             
  770.             if(!isOn)
  771.                 return;
  772.             
  773.             mouseDownPoint = DrawArgs.LastMousePosition;
  774.             m_drawArgs.WorldCamera.PickingRayIntersection(
  775.                 (int)mouseDownPoint.X,
  776.                 (int)mouseDownPoint.Y,
  777.                 out qLatitude,
  778.                 out qLongitude);
  779.             if ( !this.IsDoubleClickIn && ( Control.ModifierKeys == this.ShiftKeysIn ) && ( LeftClicked == this.IsLeftButtonIn ) ) {
  780.                 Coeff = 1/ZoomFactIn;
  781.             }
  782.             else if ( !this.IsDoubleClickOut && ( Control.ModifierKeys == this.ShiftKeysOut ) && ( LeftClicked == this.IsLeftButtonOut ) ) {
  783.                 Coeff = ZoomFactOut;
  784.             }
  785.             else {
  786.                 return;
  787.             }
  788.             m_window.GotoLatLonAltitude( qLatitude.Degrees, qLongitude.Degrees, Coeff*m_drawArgs.WorldCamera.Altitude );
  789.         }
  790.           
  791.         public void MouseDown( object sender, MouseEventArgs e )
  792.         {
  793.             LeftClicked = false;
  794.             if(!isOn)
  795.                 return;
  796.             if (e.Button == MouseButtons.Left) {     
  797.                 LeftClicked = true;
  798.             }
  799.         }
  800.         
  801.         public void SetShiftKeys( int r, bool Shift, bool Ctrl, bool Alt )
  802.         {
  803.             if ( r == 0 ) {
  804.                 this.ShiftKeysIn = Keys.None;
  805.                 if( Shift ) { this.ShiftKeysIn = this.ShiftKeysIn | Keys.Shift; }
  806.                 if( Ctrl ) { this.ShiftKeysIn = this.ShiftKeysIn | Keys.Control; }
  807.                 if( Alt ) { this.ShiftKeysIn = this.ShiftKeysIn | Keys.Alt; }
  808.             }
  809.             else if ( r == 1 ) {
  810.                 this.ShiftKeysOut = Keys.None;
  811.                 if( Shift ) { this.ShiftKeysOut = this.ShiftKeysOut | Keys.Shift; }
  812.                 if( Ctrl ) { this.ShiftKeysOut = this.ShiftKeysOut | Keys.Control; }
  813.                 if( Alt ) { this.ShiftKeysOut = this.ShiftKeysOut | Keys.Alt; }
  814.             }
  815.         }
  816.         
  817.         public void LoadSettings()
  818.         {
  819.             //Get our favorites from text file
  820.             try
  821.             {
  822.                 using(TextReader tr = File.OpenText(m_FilePath))
  823.                 {
  824.                     
  825.                     //Get the Zoom In Settings
  826.                     string line = tr.ReadLine();
  827.                     string[] fields = line.Split(';');
  828.                     ZoomFactIn = double.Parse(fields[(int)zoomFields.ZoomFact]);
  829.                     
  830.                     bool ShiftIn = bool.Parse(fields[(int)zoomFields.Shift]);
  831.                     bool CtrlIn = bool.Parse(fields[(int)zoomFields.Ctrl]);
  832.                     bool AltIn = bool.Parse(fields[(int)zoomFields.Alt]);
  833.                     SetShiftKeys( 0, ShiftIn, CtrlIn, AltIn );
  834.                     
  835.                     IsLeftButtonIn = bool.Parse(fields[(int)zoomFields.IsLeftButton]);
  836.                     IsDoubleClickIn = bool.Parse(fields[(int)zoomFields.IsDoubleClick]);
  837.  
  838.                     //Get the Zoom In Settings
  839.                     line = tr.ReadLine();
  840.                     fields = line.Split(';');
  841.                     ZoomFactOut = double.Parse(fields[(int)zoomFields.ZoomFact]);
  842.                     
  843.                     bool ShiftOut = bool.Parse(fields[(int)zoomFields.Shift]);
  844.                     bool AltOut = bool.Parse(fields[(int)zoomFields.Alt]);
  845.                     bool CtrlOut = bool.Parse(fields[(int)zoomFields.Ctrl]);
  846.                     SetShiftKeys( 1, ShiftOut, CtrlOut, AltOut );
  847.                     
  848.                     IsLeftButtonOut = bool.Parse(fields[(int)zoomFields.IsLeftButton]);
  849.                     IsDoubleClickOut = bool.Parse(fields[(int)zoomFields.IsDoubleClick]);
  850.  
  851.                     tr.Close();
  852.                 }
  853.             }
  854.             catch(Exception caught)
  855.             {
  856.                 Utility.Log.Write( caught );
  857.                 string msg = "Failed to parse " + m_FilePath + "\n\n" + caught.Message;
  858.                 // Clean up, remove menu item
  859.                 throw new ApplicationException( msg );
  860.             }
  861.         }
  862.  
  863.         public override bool IsOn
  864.         {
  865.             get
  866.             {
  867.                 return base.IsOn;
  868.             }
  869.             set
  870.             {
  871.                 if(value==isOn)
  872.                     return;
  873.  
  874.                 base.IsOn = value;
  875.                 if(isOn)
  876.                 {
  877.                     // Can't use point goto while measuring
  878.                     isPointGotoEnabled = World.Settings.CameraIsPointGoto;
  879.                     World.Settings.CameraIsPointGoto = false;
  880.                 }
  881.                 else
  882.                 {
  883.                     World.Settings.CameraIsPointGoto = isPointGotoEnabled;
  884.                 }
  885.                 m_menuItem.Checked = base.IsOn;
  886.             }
  887.         }
  888.  
  889.         public override void Render(DrawArgs drawArgs)
  890.         {
  891.  
  892.         }
  893.  
  894.         /// <summary>
  895.         /// RenderableObject abstract member (needed) 
  896.         /// OBS: Worker thread (don't update UI directly from this thread)
  897.         /// </summary>
  898.         public override void Initialize(DrawArgs drawArgs)
  899.         {
  900.             isInitialized = true;
  901.         }
  902.  
  903.         /// <summary>
  904.         /// RenderableObject abstract member (needed)
  905.         /// OBS: Worker thread (don't update UI directly from this thread)
  906.         /// </summary>
  907.         public override void Update(DrawArgs drawArgs)
  908.         {
  909.             if(!isInitialized)
  910.                 Initialize(drawArgs);
  911.         }
  912.  
  913.         /// <summary>
  914.         /// RenderableObject abstract member (needed)
  915.         /// OBS: Worker thread (don't update UI directly from this thread)
  916.         /// </summary>
  917.         public override void Dispose()
  918.         {
  919.             isInitialized = false;
  920.         }
  921.  
  922.         /// <summary>
  923.         /// RenderableObject abstract member (needed)
  924.         /// Called from UI thread = UI code safe in this function
  925.         /// </summary>
  926.         public override bool PerformSelectionAction(DrawArgs drawArgs)
  927.         {
  928.             return false;
  929.         }
  930.          
  931.         /// <summary>
  932.          /// Fills the context menu with menu items specific to the layer.
  933.          /// </summary>
  934.          public override void BuildContextMenu( ContextMenu menu )
  935.          {
  936.               menu.MenuItems.Add("Properties", new System.EventHandler(OnPropertiesClick));
  937.          }
  938.         
  939.          /// <summary>
  940.          /// Properties context menu clicked.
  941.          /// </summary>
  942.          public void OnPropertiesClick(object sender, EventArgs e)
  943.          {
  944.             if( zDialog != null && ! zDialog.IsDisposed)
  945.                 // Already open
  946.                 return;
  947.  
  948.             // Display the dialog
  949.             zDialog = new ZoomDialog( this, this.m_FilePath );
  950.             zDialog.Show();
  951.          }
  952.         
  953.     }
  954.     
  955. }