Pg 1 of 30AGI www.agiuc.com
Application Programming using the STK Object Model
Sylvain Dupont & Alan OcampoAnalytical Graphics, Inc
October 2005
Pg 2 of 30AGI www.agiuc.com
Our goal
• Make it easier for integrators to reuse AGI technology– Reliance on industry standards– Shorter learning curve & development cycle
Pg 3 of 30AGI www.agiuc.com
History
Connect• TCP/IP socket• String based language
6.05.0 7.0 …5.04.0…
Plugin scriptsScripting languages only(perl, VBScript & matlab)
Application Object Model
• Control STK windows• ExecuteCommandInternal HTML Viewer• Window.external
STK/X – 4DX• Map & globe controls• ExecuteCommand
STK PluginsCOM based plugins
STK Objects Library• Manipulate the STK objects• Available with STK, STK/X & 4DX• Data providers
Pg 4 of 30AGI www.agiuc.com
STK Objects Library - Technology
• Based on COM (Component Object Model)
• Available development environments– .Net (C#, Visual Basic .Net)– Java– C++– Visual Basic 6– Scripting languages
Pg 5 of 30AGI www.agiuc.com
Scope for STK 7
• First release covers:
(~ PRO & AVO licenses)
• 484 interfaces, 2019 properties, 214 methods
• Coverage will increase with subsequent releases
• Fall back to Connect for capabilities not yet supported
Pg 6 of 30AGI www.agiuc.com
Example: Target object
Pg 7 of 30AGI www.agiuc.com
Benefits
• Better development tools support
– Errors detected at compile time– Rich exception information provided at run-time
• Less code to write for 3rd party developers– Avoid tedious string parsing & formatting
Pg 8 of 30AGI www.agiuc.com
Next…
• How to perform the most common Connect tasks with the STK Object Model
Pg 9 of 30AGI www.agiuc.com
Agenda
• Life before the API: Connect
• What is the STK Object Model API?
• Features
• Basics of application development (using VB6)
• Benefits and Limitations
• Recommendations
Pg 10 of 30AGI www.agiuc.com
Life Before the API : Connect Revisited
• What is ‘Connect’?– Connect is the ‘language’ of STK.– You can send Connect commands to STK via TCP/IP or COM
• Sample code using Connect (via COM)
‘m_stkApp is an instance of an STK/X application object
‘Load a scenariom_stkApp.ExecuteCommand "Load / Scenario """ & “c:\temp\scenario.sc”
& """"
‘get a string containing a list of all object pathsDim result As AgExecCmdResultDim instanceNames As StringDim objectList() As String Set result = m_stkApp.ExecuteCommand("AllInstanceNames /")instanceNames = result.item(0)
Pg 11 of 30AGI www.agiuc.com
Life Before the API : Connect Revisited
• Benefits– Straightforward implementation, does not require a lot of
development skill or experience– Almost all of the functionality available from the STK
GUI can be executed using Connect
• Limitations– It is difficult to memorize the syntax of commands– Limited exception handling– Most commands with a return value need further parsing
to be more useful
Pg 12 of 30AGI www.agiuc.com
Overview of the API
• What is it?– COM type library that provides an object model that
represents STK objects– Version History
• Released starting with STK version 6.1.3 as the ‘STK Data Provider API’
• Renamed to ‘STK Object Model API’ in STK version 7
Pg 13 of 30AGI www.agiuc.com
Overview of the API
– Object Model Features• Application / Scenario level
interfaces• STK object-related interfaces• Data Provider-related
interfaces
– Object Model Diagram
Pg 14 of 30AGI www.agiuc.com
Using the API
• Installation– System requirements same as STK– Installation procedure
• Before STK 7, separate installation package
• Setting up a development project• Add a reference to ‘AGI STK/Objects 7’
(AgStkObjects.dll – located in the bin folder)
Pg 15 of 30AGI www.agiuc.com
Using the API
• Demo application– Object Initialization– The Object Root (AgStkObjectRoot)– Working with scenario objects (IAgStkObject)– Accessing Data Provider information– Multiple Threshold Crossings– Events
Pg 16 of 30AGI www.agiuc.com
Using the API
• Object Initialization– Using with STK/X
Dim m_stkApp As AgStkObjectRootSet m_stkApp = New AgStkObjectRoot
Pg 17 of 30AGI www.agiuc.com
Using the API
• Object Initialization (continued)– Using with STK
‘Load STK (reference AgUiApplicationLib)Dim uiApp As AgUiAppDispImplSet uiApp = New AgUiAppDispImplWith uiApp.LoadPersonality "STK".Visible = True.UserControl = True
End With‘get object rootDim m_stkApp As AgStkObjectRootSet m_stkApp = uiApp.Personality2
Pg 18 of 30AGI www.agiuc.com
Using the API
• The Object Root (AgStkObjectRoot)– Implements various interfaces
• Application-level (IAgStkObjectRoot)– NewScenario, LoadScenario, CloseScenario, SaveScenario– CurrentScenario– UnitPreferences– ExecuteCommand
• Animation (IAgAnimation)– PlayForward, PlayBackward– Rewind– Faster, Slower– StepBackward, StepForward– CurrentTime
• Batch Update (IAgSupportBatchUpdate)– BeginUpdate– EndUpdate
Pg 19 of 30AGI www.agiuc.com
Using the API
• Working with Scenario Objects– IAgStkObject - Interface for a generic object
• InstanceName• ClassType, ClassName• Path• ShortDescription, LongDescription• Parent• Children• DataProviders• GetAccess, GetAccessToObject
Pg 20 of 30AGI www.agiuc.com
Using the API
• Working with Scenario Objects (cont’d)– Other interfaces specific to an STK object type
• Aircraft (IAgAircraft)• Area Target (IAgAreaTarget)• Facility (IAgFacility)• Ground Vehicle (IAgGroundVehicle)• Launch Vehicle (IAgLaunchVehicle)• Missile (IAgMissile)• Planet (IAgPlanet)• Satellite (IAgSatellite)• Scenario (IAgScenario)• Sensor (IAgSensor)• Ship (IAgShip)• Star (IAgStar)• Target (IAgTarget)
Pg 21 of 30AGI www.agiuc.com
Using the API
• Data Providers– Enumerating Data Providers
• In STK, the data providers available to an object are listed in the ‘Content’ properties page when creating or editing a report. There is no Connect command to retrieve the list.
• In the API, the data providers can be accessed using the DataProviders property of an STK Object.
– By iterating through the collection (fine grained: provides full access to data provider objects)
– using the GetSchema method (coarse grained: returns an XML string)
Pg 22 of 30AGI www.agiuc.com
Using the API
– Retrieving Data Provider Information• Commonly-used data provider types:
– Fixed– Time Varying (Start Time, Stop Time)– Interval (Start Time, Stop Time, Interval)
• Steps for retrieving data provider information1. Get a reference to a scenario object2. Retrieve the data provider from its DataProviders collection3. Call Exec
» Returns an IAgDrResult value
Pg 23 of 30AGI www.agiuc.com
Using the API
– Basics of IAgDrResult• Category
– eDrCatDataSetList– eDrCatIntervalList– eDrCatMessage– eDrCatSubSectionList
Pg 24 of 30AGI www.agiuc.com
• DataSets – map to the collection of columns in a report– DataSet
» ElementName» ElementType» GetValues
Using the API
Dataset
Dataset
Dataset
Dataset
Values
ElementName
Pg 25 of 30AGI www.agiuc.com
Using the API
– Multiple Threshold Crossings• The API features the ability to filter a data provider result to
return time intervals where dataset values cross specific ranges– For example: return time intervals where an aircraft’s altitude
crosses 3, 4, and 5 (km); that is, return time intervals where:1. Altitude < 32. 3 < Altitude < 43. 4 < Altitude < 54. Altitude > 5
Pg 26 of 30AGI www.agiuc.com
Using the API
• Events– OnAnimationPause– OnAnimationPlayback– OnAnimationRewind– OnAnimUpdate– OnLogMessage– OnScenarioClose– OnScenarioLoad– OnScenarioNew– OnScenarioSave– OnStkObjectAdded– OnStkObjectCollectionChanged– OnStkObjectDeleted– OnStkObjectRenamed
Pg 27 of 30AGI www.agiuc.com
Benefits and Limitations
• Benefits– Extra features not available using Connect
• Enumerate Data Providers• Multiple Threshold Crossings• Events
– Rich object model results in strongly-typed code; easier to track errors at compile time
– Intellisense – More robust runtime exception handling
Pg 28 of 30AGI www.agiuc.com
Benefits and Limitations
• Limitations– Currently supports functionality available in PRO and
AVO– Some Connect commands currently have no equivalent
• ‘VO View’• Batch update using wildcards in object paths (‘*’)
– One Connect command does not necessarily map to one API command
Pg 29 of 30AGI www.agiuc.com
Recommendations
• When to use– Data Provider API
• Use the API as much as possible unless there is no equivalent to a Connect command
– Connect• Still good for ‘one-off’ applications
Pg 30 of 30AGI www.agiuc.com
Summary / Conclusion
• The API provides many conveniences over Connect from a development standpoint
• Connect is not going away
Top Related