基本信息
源码名称:开发基于STKX组件的展示软件
源码大小:1.24M
文件格式:.rar
开发语言:C#
更新时间:2019-10-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
属于实时性要求比较高的开发案例
属于实时性要求比较高的开发案例
//-------------------------------------------------------------------------
//
// 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);
}
}
}