Skip to content

Commit 843c678

Browse files
committed
In process of merging
2 parents b56ab0a + 08ca765 commit 843c678

File tree

110 files changed

+4767
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+4767
-533
lines changed

API.md

+285
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
# Open MCT API
2+
3+
The Open MCT framework public api can be utilized by building the application
4+
(`gulp install`) and then copying the file from `dist/main.js` to your
5+
directory of choice.
6+
7+
Open MCT supports AMD, CommonJS, and loading via a script tag; it's easy to use
8+
in your project. The [`openmct`]{@link module:openmct} module is exported
9+
via AMD and CommonJS, and is also exposed as `openmct` in the global scope
10+
if loaded via a script tag.
11+
12+
## Overview
13+
14+
Open MCT's goal is to allow you to browse, create, edit, and visualize all of
15+
the domain knowledge you need on a daily basis.
16+
17+
To do this, the main building block provided by Open MCT is the _domain object_.
18+
The temperature sensor on the starboard solar panel,
19+
an overlay plot comparing the results of all temperature sensor,
20+
the command dictionary for a spacecraft,
21+
the individual commands in that dictionary, your "my documents" folder:
22+
All of these things are domain objects.
23+
24+
Domain objects have Types, so a specific instrument temperature sensor is a
25+
"Telemetry Point," and turning on a drill for a certain duration of time is
26+
an "Activity". Types allow you to form an ontology of knowledge and provide
27+
an abstraction for grouping, visualizing, and interpreting data.
28+
29+
And then we have Views. Views allow you to visualize domain objects. Views can
30+
apply to specific domain objects; they may also apply to certain types of
31+
domain objects, or they may apply to everything. Views are simply a method
32+
of visualizing domain objects.
33+
34+
Regions allow you to specify what views are displayed for specific types of
35+
domain objects in response to different user actions. For instance, you may
36+
want to display a different view while editing, or you may want to update the
37+
toolbar display when objects are selected. Regions allow you to map views to
38+
specific user actions.
39+
40+
Domain objects can be mutated and persisted, developers can create custom
41+
actions and apply them to domain objects, and many more things can be done.
42+
For more information, read on!
43+
44+
## Running Open MCT
45+
46+
Once the [`openmct`](@link module:openmct) module has been loaded, you can
47+
simply invoke [`start`]{@link module:openmct.MCT#start} to run Open MCT:
48+
49+
50+
```
51+
openmct.start();
52+
```
53+
54+
Generally, however, you will want to configure Open MCT by adding plugins
55+
before starting it. It is important to install plugins and configure Open MCT
56+
_before_ calling [`start`]{@link module:openmct.MCT#start}; Open MCT is not
57+
designed to be reconfigured once started.
58+
59+
## Configuring Open MCT
60+
61+
The [`openmct`]{@link module:openmct} module (more specifically, the
62+
[`MCT`]{@link module:openmct.MCT} class, of which `openmct` is an instance)
63+
exposes a variety of methods to allow the application to be configured,
64+
extended, and customized before running.
65+
66+
Short examples follow; see the linked documentation for further details.
67+
68+
### Adding Domain Object Types
69+
70+
Custom types may be registered via
71+
[`openmct.types`]{@link module:openmct.MCT#types}:
72+
73+
```
74+
openmct.types.addType('my-type', new openmct.Type({
75+
label: "My Type",
76+
description: "This is a type that I added!"
77+
});
78+
```
79+
80+
### Adding Views
81+
82+
Custom views may be registered based on the region in the application
83+
where they should appear:
84+
85+
* [`openmct.mainViews`]{@link module:openmct.MCT#mainViews} is a registry
86+
of views of domain objects which should appear in the main viewing area.
87+
* [`openmct.inspectors`]{@link module:openmct.MCT#inspectors} is a registry
88+
of views of domain objects and/or active selections, which should appear in
89+
the Inspector.
90+
* [`openmct.toolbars`]{@link module:openmct.MCT#toolbars} is a registry
91+
of views of domain objects and/or active selections, which should appear in
92+
the toolbar area while editing.
93+
* [`openmct.indicators`]{@link module:openmct.MCT#inspectors} is a registry
94+
of views which should appear in the status area of the application.
95+
96+
Example:
97+
98+
```
99+
openmct.mainViews.addProvider({
100+
canView: function (domainObject) {
101+
return domainObject.type === 'my-type';
102+
},
103+
view: function (domainObject) {
104+
return new MyView(domainObject);
105+
}
106+
});
107+
```
108+
109+
### Adding a Root-level Object
110+
111+
In many cases, you'd like a certain object (or a certain hierarchy of
112+
objects) to be accessible from the top level of the application (the
113+
tree on the left-hand side of Open MCT.) It is typical to expose a telemetry
114+
dictionary as a hierarchy of telemetry-providing domain objects in this
115+
fashion.
116+
117+
To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method
118+
of the [object API]{@link module:openmct.ObjectAPI}:
119+
120+
```
121+
openmct.objects.addRoot({
122+
identifier: { key: "my-key", namespace: "my-namespace" }
123+
name: "My Root-level Object",
124+
type: "my-type"
125+
});
126+
```
127+
128+
You can also remove this root-level object via its identifier:
129+
130+
```
131+
openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" });
132+
```
133+
134+
### Adding Composition Providers
135+
136+
The "composition" of a domain object is the list of objects it contains,
137+
as shown (for example) in the tree for browsing. Open MCT provides a
138+
default solution for composition, but there may be cases where you want
139+
to provide the composition of a certain object (or type of object) dynamically.
140+
For instance, you may want to populate a hierarchy under a custom root-level
141+
object based on the contents of a telemetry dictionary.
142+
To do this, you can add a new CompositionProvider:
143+
144+
```
145+
openmct.composition.addProvider({
146+
appliesTo: function (domainObject) {
147+
return domainObject.type === 'my-type';
148+
},
149+
load: function (domainObject) {
150+
return Promise.resolve(myDomainObjects);
151+
}
152+
});
153+
```
154+
155+
### Adding Telemetry Providers
156+
157+
When connecting to a new telemetry source, you will want to register a new
158+
[telemetry provider]{@link module:openmct.TelemetryAPI~TelemetryProvider}
159+
with the [telemetry API]{@link module:openmct.TelemetryAPI#addProvider}:
160+
161+
```
162+
openmct.telemetry.addProvider({
163+
canProvideTelemetry: function (domainObject) {
164+
return domainObject.type === 'my-type';
165+
},
166+
properties: function (domainObject) {
167+
return [
168+
{ key: 'value', name: "Temperature", units: "degC" },
169+
{ key: 'time', name: "UTC" }
170+
];
171+
},
172+
request: function (domainObject, options) {
173+
var telemetryId = domainObject.myTelemetryId;
174+
return myAdapter.request(telemetryId, options.start, options.end);
175+
},
176+
subscribe: function (domainObject, callback) {
177+
var telemetryId = domainObject.myTelemetryId;
178+
myAdapter.subscribe(telemetryId, callback);
179+
return myAdapter.unsubscribe.bind(myAdapter, telemetryId, callback);
180+
}
181+
});
182+
```
183+
184+
The implementations for `request` and `subscribe` can vary depending on the
185+
nature of the endpoint which will provide telemetry. In the example above,
186+
it is assumed that `myAdapter` contains the specific implementations
187+
(HTTP requests, WebSocket connections, etc.) associated with some telemetry
188+
source.
189+
190+
## Using Open MCT
191+
192+
When implementing new features, it is useful and sometimes necessary to
193+
utilize functionality exposed by Open MCT.
194+
195+
### Retrieving Composition
196+
197+
To limit which objects are loaded at any given time, the composition of
198+
a domain object must be requested asynchronously:
199+
200+
```
201+
openmct.composition(myObject).load().then(function (childObjects) {
202+
childObjects.forEach(doSomething);
203+
});
204+
```
205+
206+
### Support Common Gestures
207+
208+
Custom views may also want to support common gestures using the
209+
[gesture API]{@link module:openmct.GestureAPI}. For instance, to make
210+
a view (or part of a view) selectable:
211+
212+
```
213+
openmct.gestures.selectable(myHtmlElement, myDomainObject);
214+
```
215+
216+
### Working with Domain Objects
217+
218+
The [object API]{@link module:openmct.ObjectAPI} provides useful methods
219+
for working with domain objects.
220+
221+
To make changes to a domain object, use the
222+
[`mutate`]{@link module:openmct.ObjectAPI#mutate} method:
223+
224+
```
225+
openmct.objects.mutate(myDomainObject, "name", "New name!");
226+
```
227+
228+
Making modifications in this fashion allows other usages of the domain
229+
object to remain up to date using the
230+
[`observe`]{@link module:openmct.ObjectAPI#observe} method:
231+
232+
```
233+
openmct.objects.observe(myDomainObject, "name", function (newName) {
234+
myLabel.textContent = newName;
235+
});
236+
```
237+
238+
### Using Telemetry
239+
240+
Very often in Open MCT, you wish to work with telemetry data (for instance,
241+
to display it in a custom visualization.)
242+
243+
244+
### Synchronizing with the Time Conductor
245+
246+
Views which wish to remain synchronized with the state of Open MCT's
247+
time conductor should utilize
248+
[`openmct.conductor`]{@link module:openmct.TimeConductor}:
249+
250+
```
251+
openmct.conductor.on('bounds', function (newBounds) {
252+
requestTelemetry(newBounds.start, newBounds.end).then(displayTelemetry);
253+
});
254+
```
255+
256+
## Plugins
257+
258+
While you can register new features with Open MCT directly, it is generally
259+
more useful to package these as a plugin. A plugin is a function that takes
260+
[`openmct`]{@link module:openmct} as an argument, and performs configuration
261+
upon `openmct` when invoked.
262+
263+
### Installing Plugins
264+
265+
To install plugins, use the [`install`]{@link module:openmct.MCT#install}
266+
method:
267+
268+
```
269+
openmct.install(myPlugin);
270+
```
271+
272+
The plugin will be invoked to configure Open MCT before it is started.
273+
274+
### Writing Plugins
275+
276+
Plugins configure Open MCT, and should utilize the
277+
[`openmct`]{@link module:openmct} module to do so, as summarized above in
278+
"Configuring Open MCT" and "Using Open MCT" above.
279+
280+
### Distributing Plugins
281+
282+
Hosting or downloading plugins is outside of the scope of this documentation.
283+
We recommend distributing plugins as UMD modules which export a single
284+
function.
285+

0 commit comments

Comments
 (0)