实例介绍
【实例截图】STKX开发
【核心代码】
//-------------------------------------------------------------------------
//
// This is part of the STK 8 Object Model Examples
// Copyright (C) 2006 Analytical Graphics, Inc.
//
// This source code is intended as a reference to users of the
// STK 8 Object Model.
//
// File: Form1.cs
// DataProviders
//
//
// The features used in this example show how to hook event notification
// up to STK through C# so that you can listen to events such as animation
// and object creation.
//
//--------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DataProviders
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button GraphButton;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private AGI.STKObjects.AgStkObjectRootClass objModelRoot;
private AGI.STKObjects.AgSatelliteClass Satellite = null;
private AGI.STKObjects.AgFacilityClass Facility = null;
private AGI.STKObjects.IAgStkAccess Access = null;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button ComputeButton;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button MarkerColorButton;
private System.Windows.Forms.CheckBox checkBox1;
private bool IsPlacingFacility = false;
private System.Windows.Forms.Button PlaceFacilityButton;
private System.Windows.Forms.Label placetext;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button MarkerColorButton2;
private AxAGI.STKX.AxAgUiAx2DCntrl axAgUiAx2DCntrl1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.GraphButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.MarkerColorButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.MarkerColorButton2 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.placetext = new System.Windows.Forms.Label();
this.PlaceFacilityButton = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.ComputeButton = new System.Windows.Forms.Button();
this.axAgUiAx2DCntrl1 = new AxAGI.STKX.AxAgUiAx2DCntrl();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axAgUiAx2DCntrl1)).BeginInit();
this.SuspendLayout();
//
// GraphButton
//
this.GraphButton.Enabled = false;
this.GraphButton.Location = new System.Drawing.Point(25, 85);
this.GraphButton.Name = "GraphButton";
this.GraphButton.Size = new System.Drawing.Size(96, 37);
this.GraphButton.TabIndex = 0;
this.GraphButton.Text = "Graph";
this.GraphButton.Click = new System.EventHandler(this.GraphButton_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Controls.Add(this.MarkerColorButton);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Location = new System.Drawing.Point(10, 471);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(288, 147);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Satellite Setup";
//
// checkBox1
//
this.checkBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.checkBox1.Location = new System.Drawing.Point(48, 106);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(182, 28);
this.checkBox1.TabIndex = 5;
this.checkBox1.Text = "Use Elevation Contours";
this.checkBox1.CheckedChanged = new System.EventHandler(this.checkBox1_CheckedChanged);
//
// MarkerColorButton
//
this.MarkerColorButton.BackColor = System.Drawing.Color.IndianRed;
this.MarkerColorButton.Cursor = System.Windows.Forms.Cursors.Hand;
this.MarkerColorButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.MarkerColorButton.Location = new System.Drawing.Point(125, 65);
this.MarkerColorButton.Name = "MarkerColorButton";
this.MarkerColorButton.Size = new System.Drawing.Size(105, 27);
this.MarkerColorButton.TabIndex = 4;
this.MarkerColorButton.Click = new System.EventHandler(this.MarkerColorButton_Click);
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(11, 70);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(96, 19);
this.label2.TabIndex = 3;
this.label2.Text = "MarkerColor:";
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(10, 31);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 19);
this.label1.TabIndex = 2;
this.label1.Text = "Propagator:";
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(106, 28);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(153, 24);
this.comboBox1.TabIndex = 1;
this.comboBox1.Text = "comboBox1";
this.comboBox1.SelectedIndexChanged = new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.MarkerColorButton2);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.placetext);
this.groupBox2.Controls.Add(this.PlaceFacilityButton);
this.groupBox2.Location = new System.Drawing.Point(307, 471);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(288, 147);
this.groupBox2.TabIndex = 3;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Facility Setup";
//
// MarkerColorButton2
//
this.MarkerColorButton2.BackColor = System.Drawing.Color.Snow;
this.MarkerColorButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.MarkerColorButton2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.MarkerColorButton2.Location = new System.Drawing.Point(134, 65);
this.MarkerColorButton2.Name = "MarkerColorButton2";
this.MarkerColorButton2.Size = new System.Drawing.Size(106, 27);
this.MarkerColorButton2.TabIndex = 6;
this.MarkerColorButton2.Click = new System.EventHandler(this.MarkerColorButton2_Click);
//
// label4
//
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(29, 70);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 19);
this.label4.TabIndex = 5;
this.label4.Text = "LabelColor:";
//
// label3
//
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(19, 31);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(67, 19);
this.label3.TabIndex = 3;
this.label3.Text = "Location:";
//
// placetext
//
this.placetext.Location = new System.Drawing.Point(29, 103);
this.placetext.Name = "placetext";
this.placetext.Size = new System.Drawing.Size(240, 37);
this.placetext.TabIndex = 1;
this.placetext.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// PlaceFacilityButton
//
this.PlaceFacilityButton.Cursor = System.Windows.Forms.Cursors.Hand;
this.PlaceFacilityButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.PlaceFacilityButton.Location = new System.Drawing.Point(106, 28);
this.PlaceFacilityButton.Name = "PlaceFacilityButton";
this.PlaceFacilityButton.Size = new System.Drawing.Size(163, 24);
this.PlaceFacilityButton.TabIndex = 0;
this.PlaceFacilityButton.Text = "Place Facility On Map";
this.PlaceFacilityButton.Click = new System.EventHandler(this.PlaceFacilityButton_Click);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.ComputeButton);
this.groupBox3.Controls.Add(this.GraphButton);
this.groupBox3.Location = new System.Drawing.Point(605, 471);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(144, 147);
this.groupBox3.TabIndex = 4;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Access";
//
// ComputeButton
//
this.ComputeButton.Location = new System.Drawing.Point(26, 33);
this.ComputeButton.Name = "ComputeButton";
this.ComputeButton.Size = new System.Drawing.Size(96, 37);
this.ComputeButton.TabIndex = 1;
this.ComputeButton.Text = "Compute";
this.ComputeButton.Click = new System.EventHandler(this.ComputeButton_Click);
//
// axAgUiAx2DCntrl1
//
this.axAgUiAx2DCntrl1.Enabled = true;
this.axAgUiAx2DCntrl1.Location = new System.Drawing.Point(0, 0);
this.axAgUiAx2DCntrl1.Name = "axAgUiAx2DCntrl1";
this.axAgUiAx2DCntrl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgUiAx2DCntrl1.OcxState")));
this.axAgUiAx2DCntrl1.Size = new System.Drawing.Size(776, 464);
this.axAgUiAx2DCntrl1.TabIndex = 5;
this.axAgUiAx2DCntrl1.MouseDownEvent = new AxAGI.STKX.IAgUiAx2DCntrlEvents_MouseDownEventHandler(this.axAgUiAx2DCntrl1_MouseDownEvent);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(774, 622);
this.Controls.Add(this.axAgUiAx2DCntrl1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox3);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximumSize = new System.Drawing.Size(784, 664);
this.MinimumSize = new System.Drawing.Size(784, 664);
this.Name = "Form1";
this.Text = "Form1";
this.Load = new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.axAgUiAx2DCntrl1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
/// <summary>
/// Creates a new scenario, adds a Facility and a Satellite and changes some basic properties
/// </summary>
private void Form1_Load(object sender, System.EventArgs e)
{
objModelRoot = new AGI.STKObjects.AgStkObjectRootClass();
objModelRoot.NewScenario("AccessTest");
Satellite = (AGI.STKObjects.AgSatelliteClass)objModelRoot.CurrentScenario.Children.New(
AGI.STKObjects.AgESTKObjectType.eSatellite, "AccSat");
SetSatelliteColor(MarkerColorButton.BackColor);
Facility = (AGI.STKObjects.AgFacilityClass)objModelRoot.CurrentScenario.Children.New(
AGI.STKObjects.AgESTKObjectType.eFacility, "AccFac");
SetFacilityColor(MarkerColorButton2.BackColor);
UpdateFacPositionText();
comboBox1.Items.AddRange(new object[] {"TwoBody","J2Perturbation","J4Perturbation","SGP4","HPOP"});
comboBox1.Text = "TwoBody";
}
/// <summary>
/// Setting the satellite's color
/// </summary>
private void SetSatelliteColor(Color _color)
{
Satellite.Graphics.SetAttributesType(AGI.STKObjects.AgEVeGfxAttributes.eAttributesBasic);
AGI.STKObjects.IAgVeGfxAttributesBasic gfx = (AGI.STKObjects.IAgVeGfxAttributesBasic)Satellite.Graphics.Attributes;
gfx.Inherit = false;
gfx.IsVisible = true;
gfx.Color = ToOMColor(_color);
}
/// <summary>
/// Setting the facility's color
/// </summary>
private void SetFacilityColor(Color _color)
{
Facility.Graphics.InheritFromScenario = false;
Facility.Graphics.LabelVisible = true;
Facility.Graphics.LabelColor = ToOMColor(_color);
}
/// <summary>
/// Updates the facilities text to indicate where the facility is located
/// </summary>
private void UpdateFacPositionText()
{
AGI.STKObjects.IAgGeodetic pos = (AGI.STKObjects.IAgGeodetic)Facility.Position.ConvertTo(
AGI.STKObjects.AgEPositionType.eGeodetic);
placetext.Text = "Lat: " pos.Lat "\n Lon: " pos.Lon;
}
/// <summary>
/// Helper function for setting colors.
/// </summary>
private uint ToOMColor(Color _color)
{
return System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(_color));
}
/// <summary>
/// Shows a graph of the data
/// </summary>
private void GraphButton_Click(object sender, System.EventArgs e)
{
ArrayList xaxis = new ArrayList();
ArrayList yaxis = new ArrayList();
AGI.STKObjects.IAgScenario sc = (AGI.STKObjects.IAgScenario)objModelRoot.CurrentScenario;
System.Array cols = new object[] { "Start Time", "Duration" };
AGI.STKObjects.IAgDataProvider dpInfo = (AGI.STKObjects.IAgDataProvider)Access.DataProviders["Access Data"];
AGI.STKObjects.IAgDrResult resInfo = ((AGI.STKObjects.IAgDataPrvInterval)dpInfo).ExecElements(
sc.StartTime,
sc.StopTime,
ref cols);
if (resInfo.Intervals.Count > 0)
{
foreach(AGI.STKObjects.IAgDrInterval interval in resInfo.Intervals)
{
foreach(double value in interval.DataSets[0].GetValues())
{
xaxis.Add(value / 180 );
}
foreach(double value in interval.DataSets[1].GetValues())
{
yaxis.Add(value / 5 );
}
}
}
GraphForm graphform = new GraphForm(Satellite.InstanceName " Access to " Facility.InstanceName,
"Date", "Duration", xaxis,yaxis) ;
graphform.Show();
graphform.Focus();
}
/// <summary>
/// Sets the satellite's propagator type and propagates it.
/// </summary>
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(comboBox1.SelectedIndex == 0)
{
Satellite.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorTwoBody);
AGI.STKObjects.IAgVePropagatorTwoBody prop = (AGI.STKObjects.IAgVePropagatorTwoBody)Satellite.Propagator;
prop.Propagate();
}
else if(comboBox1.SelectedIndex == 1)
{
Satellite.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorJ2Perturbation);
AGI.STKObjects.IAgVePropagatorJ2Perturbation prop = (AGI.STKObjects.IAgVePropagatorJ2Perturbation)Satellite.Propagator;
prop.Propagate();
}
else if(comboBox1.SelectedIndex == 2)
{
Satellite.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorJ4Perturbation);
AGI.STKObjects.IAgVePropagatorJ4Perturbation prop = (AGI.STKObjects.IAgVePropagatorJ4Perturbation)Satellite.Propagator;
prop.Propagate();
}
else if(comboBox1.SelectedIndex == 3)
{
Satellite.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorSGP4);
AGI.STKObjects.IAgVePropagatorSGP4 prop = (AGI.STKObjects.IAgVePropagatorSGP4)Satellite.Propagator;
prop.Propagate();
}
else if(comboBox1.SelectedIndex == 4)
{
Satellite.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorHPOP);
AGI.STKObjects.IAgVePropagatorHPOP prop = (AGI.STKObjects.IAgVePropagatorHPOP)Satellite.Propagator;
prop.Propagate();
}
}
/// <summary>
/// Sets the satellite's color with the chosen type.
/// </summary>
private void MarkerColorButton_Click(object sender, System.EventArgs e)
{
ColorDialog colordial = new ColorDialog();
colordial.AllowFullOpen = false ;
colordial.ShowHelp = true ;
colordial.Color = MarkerColorButton.BackColor;
if (colordial.ShowDialog() == DialogResult.OK)
{
MarkerColorButton.BackColor = colordial.Color;
SetSatelliteColor(MarkerColorButton.BackColor);
}
}
/// <summary>
/// Changes the satellite's elevation contours visible and fillvisible properties.
/// </summary>
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
if (checkBox1.Checked)
{
Satellite.Graphics.ElevContours.IsVisible = true;
Satellite.Graphics.ElevContours.IsFillVisible = true;
}
else
{
Satellite.Graphics.ElevContours.IsFillVisible = false;
Satellite.Graphics.ElevContours.IsVisible = false;
}
}
/// <summary>
/// Uses the mouse down event in STKX to position the facility
/// </summary>
private void PlaceFacilityButton_Click(object sender, System.EventArgs e)
{
Cursor.Current = PlaceFacilityButton.Cursor;
IsPlacingFacility = true;
placetext.Text = "Click on the 2D Map to set position.";
PlaceFacilityButton.Enabled = false;
}
/// <summary>
/// Moves the facility to the mouse's coordinates.
/// </summary>
private void axAgUiAx2DCntrl1_MouseDownEvent(object sender, AxAGI.STKX.IAgUiAx2DCntrlEvents_MouseDownEvent e)
{
if (IsPlacingFacility)
{
AGI.STKX.IAgPickInfoData pickInfoData = axAgUiAx2DCntrl1.PickInfo(e.x, e.y);
AGI.STKObjects.IAgGeodetic pos = (AGI.STKObjects.IAgGeodetic)Facility.Position.ConvertTo(
AGI.STKObjects.AgEPositionType.eGeodetic);
pos.Lat = pickInfoData.Lat;
pos.Lon = pickInfoData.Lon;
pos.Alt = pickInfoData.Alt;
Facility.Position.Assign(pos);
UpdateFacPositionText();
IsPlacingFacility = false;
PlaceFacilityButton.Enabled = true;
}
}
/// <summary>
/// Changes the facilities color with the given value.
/// </summary>
private void MarkerColorButton2_Click(object sender, System.EventArgs e)
{
ColorDialog colordial = new ColorDialog();
colordial.AllowFullOpen = false ;
colordial.ShowHelp = true ;
colordial.Color = MarkerColorButton.BackColor;
if (colordial.ShowDialog() == DialogResult.OK)
{
MarkerColorButton2.BackColor = colordial.Color;
SetFacilityColor(MarkerColorButton2.BackColor);
}
}
/// <summary>
/// Computes access between a satellite and a facility.
/// </summary>
private void ComputeButton_Click(object sender, System.EventArgs e)
{
objModelRoot.UnitPreferences.SetCurrentUnit("DateFormat", "EpSec");
Access = (AGI.STKObjects.IAgStkAccess)Satellite.GetAccessToObject(Facility);
Access.AccessTimePeriod = AGI.STKObjects.AgEAccessTimeType.eScenarioAccessTime;
Access.ComputeAccess();
SetFacilityColor(MarkerColorButton2.BackColor);
ComputeButton.Enabled = false;
GraphButton.Enabled = true;
}
}
}
标签: 开发
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论