实例介绍
【实例截图】
【核心代码】
//-------------------------------------------------------------------------
//
// 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
// GPSDatabaseAccessDemo
//
// This program demonstrates use of the STK Object Model in conjunction
// with two other integrable technologies, an odbc data source in the form
// of a microsoft access database, and XML. The example loads a GPS constellation of
// satellites from a preexisting database, and does the same of a facility from a
// previously defined xml file containing positional data. It then computes and
// retreives access data, and writes the output to an XML file.
//
// The features used are: Basic object manipulation, SGP4 Propagation,
// Facility positioning, and Access computation/data providers.
//
//--------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Data.Odbc;
using System.Xml;
using AGI.STKObjects;
namespace OMDemo
{
/// <summary>
/// GPSDatabaseAccessDemo
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private AGI.STKObjects.AgStkObjectRootClass objModelRoot;
private AGI.STKObjects.IAgStkObjectElementCollection Satellites = null;
private AGI.STKObjects.AgFacilityClass Facility = null;
private AGI.STKObjects.IAgStkAccess Access = null;
#region FormSetup
#region FormControls
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button ComputeButton;
private System.Windows.Forms.Button loadSatButton;
private System.Windows.Forms.Button loadFacilityButton;
private AxAGI.STKX.AxAgUiAxVOCntrl axAgUiAxVOCntrl1;
/// <summary>
/// Required designer variable.
/// </summary>
///
private System.ComponentModel.Container components = null;
#endregion
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.groupBox1 = new System.Windows.Forms.GroupBox();
this.loadSatButton = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.loadFacilityButton = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.ComputeButton = new System.Windows.Forms.Button();
this.axAgUiAxVOCntrl1 = new AxAGI.STKX.AxAgUiAxVOCntrl();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axAgUiAxVOCntrl1)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.loadSatButton);
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";
//
// loadSatButton
//
this.loadSatButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.loadSatButton.Cursor = System.Windows.Forms.Cursors.Hand;
this.loadSatButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.loadSatButton.Location = new System.Drawing.Point(29, 28);
this.loadSatButton.Name = "loadSatButton";
this.loadSatButton.Size = new System.Drawing.Size(217, 102);
this.loadSatButton.TabIndex = 7;
this.loadSatButton.Text = "Load Satellites From Database";
this.loadSatButton.Click = new System.EventHandler(this.loadSatButton_Click);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.loadFacilityButton);
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";
//
// loadFacilityButton
//
this.loadFacilityButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.loadFacilityButton.Cursor = System.Windows.Forms.Cursors.Hand;
this.loadFacilityButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.loadFacilityButton.Location = new System.Drawing.Point(38, 28);
this.loadFacilityButton.Name = "loadFacilityButton";
this.loadFacilityButton.Size = new System.Drawing.Size(218, 102);
this.loadFacilityButton.TabIndex = 0;
this.loadFacilityButton.Text = "Load Facility From XML";
this.loadFacilityButton.Click = new System.EventHandler(this.loadFacilityButton_Click);
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.ComputeButton);
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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ComputeButton.Enabled = false;
this.ComputeButton.Location = new System.Drawing.Point(14, 28);
this.ComputeButton.Name = "ComputeButton";
this.ComputeButton.Size = new System.Drawing.Size(111, 101);
this.ComputeButton.TabIndex = 1;
this.ComputeButton.Text = "Compute And Write To XML";
this.ComputeButton.Click = new System.EventHandler(this.ComputeButton_Click);
//
// axAgUiAxVOCntrl1
//
this.axAgUiAxVOCntrl1.Enabled = true;
this.axAgUiAxVOCntrl1.Location = new System.Drawing.Point(0, 0);
this.axAgUiAxVOCntrl1.Name = "axAgUiAxVOCntrl1";
this.axAgUiAxVOCntrl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgUiAxVOCntrl1.OcxState")));
this.axAgUiAxVOCntrl1.Size = new System.Drawing.Size(760, 464);
this.axAgUiAxVOCntrl1.TabIndex = 5;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(758, 627);
this.Controls.Add(this.axAgUiAxVOCntrl1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox3);
this.MinimumSize = new System.Drawing.Size(640, 578);
this.Name = "Form1";
this.Text = "GPSDemo";
this.Load = new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.axAgUiAxVOCntrl1)).EndInit();
this.ResumeLayout(false);
}
#endregion
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
objModelRoot = new AGI.STKObjects.AgStkObjectRootClass();
objModelRoot.NewScenario("ObjectModelGPSDemo");
IAgScenario scene = (IAgScenario)objModelRoot.CurrentScenario;
scene.StartTime = "1 Jul 2005 12:00:00.000";
scene.StopTime = "5 Jul 2005 12:00:00.000";
}
private void loadSatButton_Click(object sender, System.EventArgs e)
{
loadSatButton.Enabled = false;
if (!loadFacilityButton.Enabled) ComputeButton.Enabled = true;
ConnectAndLoadGPSDatabase();
}
private void ConnectAndLoadGPSDatabase()
{
// Connect to GPS satellite database
string ConnectionString =
@"Driver={Microsoft Access Driver (*.mdb)};DBQ="
Directory.GetCurrentDirectory() @"\..\..\GPS.mdb";
OdbcConnection odbcConnection = new OdbcConnection(ConnectionString);
OdbcCommand odbcCmd = new OdbcCommand("Select * FROM TLETable");
odbcCmd.Connection = odbcConnection;
odbcConnection.Open();
OdbcDataReader odbcReader = odbcCmd.ExecuteReader();
while (odbcReader.Read())
{
AddGPSSatellite(odbcReader);
}
Satellites = objModelRoot.CurrentScenario.Children.GetElements(
AGI.STKObjects.AgESTKObjectType.eSatellite);
objModelRoot.Rewind();
odbcReader.Close();
odbcConnection.Close();
}
private void AddGPSSatellite(OdbcDataReader dataSource)
{
// Define GPS satellite from the datasource using the SGP4 propagator
// to configure and propagate the satellite.
AGI.STKObjects.IAgSatellite Satellite = (AGI.STKObjects.IAgSatellite)objModelRoot.
CurrentScenario.Children.New(AGI.STKObjects.AgESTKObjectType.eSatellite, "GPS" dataSource.GetString(0));
Satellite.SetPropagatorType(AGI.STKObjects.AgEVePropagatorType.ePropagatorSGP4);
AGI.STKObjects.IAgVePropagatorSGP4 SGP4 = (AGI.STKObjects.IAgVePropagatorSGP4)Satellite.Propagator;
SGP4.StartTime = "1 Jul 2005 12:00:00.000";
SGP4.StopTime = "5 Jul 2005 12:00:00.000";
SGP4.Segments.AddSeg();
AGI.STKObjects.IAgVeSGP4Segment Segment = (AGI.STKObjects.IAgVeSGP4Segment)SGP4.Segments[0];
Segment.SSCNum = dataSource.GetString(0);
Segment.Classification = dataSource.GetString(1);
Segment.IntlDesignator = dataSource.GetString(2);
Segment.Epoch = dataSource.GetDouble(3);
Segment.BStar = dataSource.GetDouble(4);
Segment.RevNumber = dataSource.GetInt32(5);
Segment.Inclination = dataSource.GetDouble(6);
Segment.RAAN = dataSource.GetDouble(7);
Segment.Eccentricity = dataSource.GetDouble(8);
Segment.ArgOfPerigee = dataSource.GetDouble(9);
Segment.MeanAnomaly = dataSource.GetDouble(10);
Segment.MeanMotion = dataSource.GetDouble(11);
SGP4.Propagate();
}
private void ComputeButton_Click(object sender, System.EventArgs e)
{
ComputeAndWriteAccessXML();
}
private void ComputeAndWriteAccessXML()
{
// Compute Access from each GPS satellite to the loaded facility,
// and write access data to XML document
XmlTextWriter AccessXML = new XmlTextWriter(Directory.GetCurrentDirectory() @"\..\..\Access.xml", null);
AccessXML.Formatting = Formatting.Indented;
AccessXML.WriteStartDocument();
AccessXML.WriteStartElement("GPS_Satellite_Access");
foreach (AGI.STKObjects.IAgStkObject Satellite in Satellites)
{
Access = (AGI.STKObjects.IAgStkAccess)Satellite.GetAccessToObject(Facility);
Access.AccessTimePeriod = AGI.STKObjects.AgEAccessTimeType.eScenarioAccessTime;
Access.ComputeAccess();
// Only report specific data using the data provider's ExecElements functionality
// to specify certain elements of the access data set
AGI.STKObjects.IAgScenario Scenario = (AGI.STKObjects.IAgScenario)objModelRoot.CurrentScenario;
System.Array Elements = new object[] { "Start Time", "Stop Time", "Duration" };
AGI.STKObjects.IAgDataProvider DataProvider = (AGI.STKObjects.IAgDataProvider)Access.DataProviders["Access Data"];
AGI.STKObjects.IAgDrResult Result = ((AGI.STKObjects.IAgDataPrvInterval)DataProvider).ExecElements(
Scenario.StartTime,
Scenario.StopTime,
ref Elements);
WriteAccessElement(Satellite, Result, AccessXML);
}
AccessXML.WriteEndElement();
AccessXML.Flush();
AccessXML.WriteEndDocument();
AccessXML.Close();
}
private void WriteAccessElement(IAgStkObject Satellite, IAgDrResult Result, XmlTextWriter AccessXML)
{
// Write access data to XML
AccessXML.WriteStartElement(Satellite.InstanceName "_To_" Facility.InstanceName);
foreach (AGI.STKObjects.IAgDrInterval AccessInterval in Result.Intervals)
{
for(int Access = 0; Access < AccessInterval.DataSets[0].Count; Access )
{
AccessXML.WriteStartElement("Access");
AccessXML.WriteStartElement("Start_Time");
AccessXML.WriteString(AccessInterval.DataSets[0].GetValues().GetValue(Access).ToString());
AccessXML.WriteEndElement();
AccessXML.WriteStartElement("Stop_Time");
AccessXML.WriteString(AccessInterval.DataSets[1].GetValues().GetValue(Access).ToString());
AccessXML.WriteEndElement();
AccessXML.WriteStartElement("Duration");
AccessXML.WriteString(AccessInterval.DataSets[2].GetValues().GetValue(Access).ToString());
AccessXML.WriteEndElement();
AccessXML.WriteEndElement();
}
}
AccessXML.WriteEndElement();
}
private void loadFacilityButton_Click(object sender, System.EventArgs e)
{
loadFacilityButton.Enabled = false;
if (!loadSatButton.Enabled) ComputeButton.Enabled = true;
LoadFacilityXML();
}
private void LoadFacilityXML()
{
// Define a facility from an existing XML file containing structured positional data
AGI.STKObjects.IAgGeodetic FacPosition = null;
XmlTextReader FacilityXML = new XmlTextReader (Directory.GetCurrentDirectory() @"\..\..\Facility.xml");
while (FacilityXML.Read())
{
if (FacilityXML.NodeType == XmlNodeType.Element)
{
if (FacilityXML.LocalName.Equals("InstanceName"))
{
Facility = (AGI.STKObjects.AgFacilityClass)objModelRoot.CurrentScenario.Children.New(
AGI.STKObjects.AgESTKObjectType.eFacility, FacilityXML.ReadString());
FacPosition = (AGI.STKObjects.IAgGeodetic)Facility.Position.ConvertTo(
AGI.STKObjects.AgEPositionType.eGeodetic);
}
if (FacilityXML.LocalName.Equals("Latitude")) FacPosition.Lat = Convert.ToDouble(FacilityXML.ReadString());
if (FacilityXML.LocalName.Equals("Longitude")) FacPosition.Lon = Convert.ToDouble(FacilityXML.ReadString());
if (FacilityXML.LocalName.Equals("Altitude")) FacPosition.Alt = Convert.ToDouble(FacilityXML.ReadString());
}
}
Facility.Position.Assign(FacPosition);
}
}
}
标签: 组件开发
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论