Skip to content

Commit

Permalink
Selected Command panel now show Load and Activite arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
goetzrrGit committed Nov 5, 2024
1 parent f41bd0e commit a8eb3a1
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 38 deletions.
59 changes: 36 additions & 23 deletions src/components/sequencing/form/ArgTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<script lang="ts">
import type { FswCommandArgument } from '@nasa-jpl/aerie-ampcs';
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
import { isArray } from 'lodash-es';
import Collapse from '../../Collapse.svelte';
import {
Expand All @@ -10,9 +11,10 @@
isFswCommandArgumentRepeat,
isFswCommandArgumentUnsigned,
isFswCommandArgumentVarString,
isVariableDeclaration,
} from './../../../utilities/codemirror/codemirror-utils';
export let argDef: FswCommandArgument;
export let argDef: FswCommandArgument | VariableDeclaration;
$: title = getArgTitle(argDef);
Expand All @@ -30,30 +32,39 @@
return '';
}
function getArgTitle(argDef: FswCommandArgument) {
if (
isFswCommandArgumentRepeat(argDef) &&
typeof argDef.repeat?.max === 'number' &&
typeof argDef.repeat?.min === 'number'
) {
return `${argDef.name} - [${argDef.repeat?.min}, ${argDef.repeat?.max}] sets`;
}
function getArgTitle(argDef: FswCommandArgument | VariableDeclaration) {
let base = '';
if (isVariableDeclaration(argDef)) {
argDef = argDef as VariableDeclaration;
base = `${argDef.name} [${argDef.type}]`;
if (argDef.allowable_ranges) {
base += ` [${argDef.allowable_ranges.map(r => `${r.min} – ${r.max}`).join(', ')}]`;
}
} else {
if (
isFswCommandArgumentRepeat(argDef) &&
typeof argDef.repeat?.max === 'number' &&
typeof argDef.repeat?.min === 'number'
) {
return `${argDef.name} - [${argDef.repeat?.min}, ${argDef.repeat?.max}] sets`;
}
let compactTypeInfo = compactType(argDef);
if (compactTypeInfo) {
compactTypeInfo = ` [${compactTypeInfo}]`;
}
let base = `${argDef.name}${compactTypeInfo}`;
if ('range' in argDef && argDef.range) {
if (isArray(argDef.range)) {
base += ` [${argDef.range.join(', ')}]`;
} else {
base += ` [${argDef.range.min} – ${argDef.range.max}]`;
let compactTypeInfo = compactType(argDef);
if (compactTypeInfo) {
compactTypeInfo = ` [${compactTypeInfo}]`;
}
let base = `${argDef.name}${compactTypeInfo}`;
if ('range' in argDef && argDef.range) {
if (isArray(argDef.range)) {
base += ` [${argDef.range.join(', ')}]`;
} else {
base += ` [${argDef.range.min} – ${argDef.range.max}]`;
}
}
}
if ('units' in argDef) {
return `${base} – (${argDef.units})`;
if ('units' in argDef) {
return `${base} – (${argDef.units})`;
}
}
return base;
Expand All @@ -62,6 +73,8 @@

<Collapse headerHeight={24} padContent={false} {title} defaultExpanded={false}>
<div style="padding-bottom: 4px">
{argDef.description}
{#if argDef.description}
{argDef.description}
{/if}
</div>
</Collapse>
19 changes: 15 additions & 4 deletions src/components/sequencing/form/EnumEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

<script lang="ts">
import type { CommandDictionary, FswCommandArgumentEnum } from '@nasa-jpl/aerie-ampcs';
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
import type { SelectedDropdownOptionValue } from '../../../types/dropdown';
import { quoteEscape, unquoteUnescape } from '../../../utilities/codemirror/codemirror-utils';
import { isVariableDeclaration, quoteEscape, unquoteUnescape } from '../../../utilities/codemirror/codemirror-utils';
import SearchableDropdown from '../../ui/SearchableDropdown.svelte';
const SEARCH_THRESHOLD = 100;
const MAX_SEARCH_ITEMS = 1_000;
export let argDef: FswCommandArgumentEnum;
export let commandDictionary: CommandDictionary;
export let argDef: FswCommandArgumentEnum | VariableDeclaration;
export let commandDictionary: CommandDictionary | undefined = undefined;
export let initVal: string;
export let setInEditor: (val: string) => void;
Expand All @@ -19,7 +20,7 @@
let value: string;
$: value = unquoteUnescape(initVal);
$: enumValues = commandDictionary.enumMap[argDef.enum_name]?.values?.map(v => v.symbol) ?? argDef.range ?? [];
$: enumValues = getEnumValues(argDef);
$: isValueInEnum = !!enumValues.find(ev => ev === value);
$: {
setInEditor(quoteEscape(value));
Expand All @@ -36,6 +37,16 @@
setInEditor(quoteEscape(enumVal));
}
}
function getEnumValues(argDef: FswCommandArgumentEnum | VariableDeclaration): string[] {
if (isVariableDeclaration(argDef)) {
const varDef = argDef as VariableDeclaration;
return (varDef.allowable_values ? varDef.allowable_values : []) as string[];
}
const enumDef = argDef as FswCommandArgumentEnum;
return commandDictionary?.enumMap[enumDef.enum_name]?.values?.map(v => v.symbol) ?? enumDef.range ?? [];
}
</script>

<div>
Expand Down
35 changes: 31 additions & 4 deletions src/components/sequencing/form/NumEditor.svelte
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
<svelte:options immutable={true} />

<script lang="ts">
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
// This uses JS number to represents arguments
// ("+" | "-")? (@digit ("_" | @digit)* ("." ("_" | @digit)*)? | "." @digit ("_" | @digit)*)
// (("e" | "E") ("+" | "-")? ("_" | @digit)+)? |
// @digit ("_" | @digit)* "n" |
import { isFswCommandArgumentUnsigned, type NumberArg } from './../../../utilities/codemirror/codemirror-utils';
import {
isFswCommandArgumentUnsigned,
isVariableDeclaration,
type NumberArg,
} from './../../../utilities/codemirror/codemirror-utils';
export let argDef: NumberArg;
export let argDef: NumberArg | VariableDeclaration;
export let initVal: number;
export let setInEditor: (val: number) => void;
let max: number = Infinity;
let min: number = -Infinity;
let value: number;
$: max = argDef.range?.max ?? Infinity;
$: min = argDef.range?.min ?? (isFswCommandArgumentUnsigned(argDef) ? 0 : -Infinity);
$: max = findMax(argDef);
$: min = findMin(argDef);
$: value = initVal;
$: valFloat = Number(value);
$: {
if (typeof value === 'number' && !isNaN(valFloat)) {
setInEditor(value);
}
}
function findMax(argDef: NumberArg | VariableDeclaration): number {
if (isVariableDeclaration(argDef)) {
const varDef = argDef as VariableDeclaration;
return varDef && varDef.allowable_ranges
? varDef.allowable_ranges?.reduce((acc, current) => Math.max(acc, current.max), 0)
: Infinity;
}
const numDef = argDef as NumberArg;
return numDef.range?.max ?? Infinity;
}
function findMin(argDef: NumberArg | VariableDeclaration): number {
if (isVariableDeclaration(argDef)) {
const varDef = argDef as VariableDeclaration;
return varDef && varDef.allowable_ranges
? varDef.allowable_ranges?.reduce((acc, current) => Math.min(acc, current.min), 0)
: ((argDef.type === 'UINT' ? 0 : -Infinity) as number);
}
const numDef = argDef as NumberArg;
return argDef.range?.min ?? (isFswCommandArgumentUnsigned(numDef) ? 0 : -Infinity);
}
</script>

<div>
Expand Down
81 changes: 77 additions & 4 deletions src/components/sequencing/form/SelectedCommand.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,37 @@
FswCommandArgumentVarString,
ParameterDictionary,
} from '@nasa-jpl/aerie-ampcs';
import type { VariableDeclaration } from '@nasa-jpl/seq-json-schema/types';
import type { EditorView } from 'codemirror';
import { debounce } from 'lodash-es';
import { TOKEN_ERROR } from '../../../constants/seq-n-grammar-constants';
import { RULE_SEQUENCE_NAME, TOKEN_ERROR } from '../../../constants/seq-n-grammar-constants';
import type { LibrarySequence } from '../../../types/sequencing';
import type { CommandInfoMapper } from '../../../utilities/codemirror/commandInfoMapper';
import { getCustomArgDef } from '../../../utilities/sequence-editor/extension-points';
import Collapse from '../../Collapse.svelte';
import Panel from '../../ui/Panel.svelte';
import SectionTitle from '../../ui/SectionTitle.svelte';
import {
addDefaultArgs,
addDefaultVariableArgs,
getMissingArgDefs,
getMissingVariableDefs,
isFswCommandArgumentRepeat,
type ArgTextDef,
type VariableTextDef,
} from './../../../utilities/codemirror/codemirror-utils';
import AddMissingArgsButton from './AddMissingArgsButton.svelte';
import ArgEditor from './ArgEditor.svelte';
import StringEditor from './StringEditor.svelte';
import VariableEditor from './VariableEditor.svelte';
type TimeTagInfo = { node: SyntaxNode; text: string } | null | undefined;
export let editorSequenceView: EditorView;
export let channelDictionary: ChannelDictionary | null = null;
export let commandDictionary: CommandDictionary;
export let parameterDictionaries: ParameterDictionary[];
export let librarySequences: LibrarySequence[];
export let node: SyntaxNode | null;
export let commandInfoMapper: CommandInfoMapper;
Expand All @@ -52,14 +59,30 @@
$: commandNameNode = commandInfoMapper.getNameNode(commandNode);
$: commandName = commandNameNode && editorSequenceView.state.sliceDoc(commandNameNode.from, commandNameNode.to);
$: commandDef = getCommandDef(commandDictionary, commandName ?? '');
$: argInfoArray = getArgumentInfo(
$: argInfoArray = getCommandArgumentInfo(
commandInfoMapper.getArgumentNodeContainer(commandNode),
commandDef?.arguments,
undefined,
parameterDictionaries,
);
$: editorArgInfoArray = argInfoArray.filter(argInfo => !!argInfo.node);
$: missingArgDefArray = getMissingArgDefs(argInfoArray);
// Library Sequence arguments
$: librarySequence = librarySequences.find(sequence => {
const seqName = commandNode?.getChild(RULE_SEQUENCE_NAME);
if (!seqName) {
return false;
}
return sequence.name === editorSequenceView.state.sliceDoc(seqName.from, seqName.to).replace(/^"|"$/g, '');
}) as LibrarySequence | undefined;
$: variableInfoArray = getVariableArgumentInfo(
commandInfoMapper.getArgumentNodeContainer(commandNode),
librarySequence?.parameters,
);
$: editorVarInfoArray = variableInfoArray.filter(varInfo => !!varInfo.node);
$: missingVarDefArray = getMissingVariableDefs(variableInfoArray);
$: timeTagNode = getTimeTagInfo(commandNode);
function getTimeTagInfo(commandNode: SyntaxNode | null): TimeTagInfo {
Expand All @@ -73,7 +96,43 @@
);
}
function getArgumentInfo(
function getVariableArgumentInfo(
args: SyntaxNode | null,
argumentDefs: VariableDeclaration[] | undefined,
): VariableTextDef[] {
const variableArgArray: VariableTextDef[] = [];
if (args) {
for (const node of commandInfoMapper.getArgumentsFromContainer(args)) {
if (node.name === TOKEN_ERROR) {
continue;
}
let varDef: VariableDeclaration | undefined = undefined;
if (argumentDefs) {
let argDefIndex = variableArgArray.length;
varDef = argumentDefs[argDefIndex];
}
const argValue = editorSequenceView.state.sliceDoc(node.from, node.to);
variableArgArray.push({
node,
text: argValue,
varDef,
});
}
}
if (argumentDefs) {
variableArgArray.push(...argumentDefs.slice(variableArgArray.length).map(varDef => ({ varDef })));
}
// add entries for defined arguments missing from editor
return variableArgArray;
}
function getCommandArgumentInfo(
args: SyntaxNode | null,
argumentDefs: FswCommandArgument[] | undefined,
parentArgDef: FswCommandArgumentRepeat | undefined,
Expand Down Expand Up @@ -111,7 +170,7 @@
let children: ArgTextDef[] | undefined = undefined;
if (!!argDef && isFswCommandArgumentRepeat(argDef)) {
children = getArgumentInfo(node, argDef.repeat?.arguments, argDef, parameterDictionaries);
children = getCommandArgumentInfo(node, argDef.repeat?.arguments, argDef, parameterDictionaries);
}
const argValue = editorSequenceView.state.sliceDoc(node.from, node.to);
argArray.push({
Expand Down Expand Up @@ -267,6 +326,20 @@
}}
/>
</div>
{#each editorVarInfoArray as varInfo}
<VariableEditor {varInfo} setInEditor={debounce(setInEditor, 250)} />
{/each}
{#if missingVarDefArray.length}
<fieldset>
<AddMissingArgsButton
setInEditor={() => {
if (commandNode) {
addDefaultVariableArgs(missingVarDefArray, editorSequenceView, commandNode, commandInfoMapper);
}
}}
/>
</fieldset>
{/if}
</fieldset>
{/if}
{:else}
Expand Down
4 changes: 2 additions & 2 deletions src/components/sequencing/form/StringEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { FswCommandArgumentVarString } from '@nasa-jpl/aerie-ampcs';
import { isQuoted, quoteEscape, unquoteUnescape } from './../../../utilities/codemirror/codemirror-utils';
export let argDef: FswCommandArgumentVarString;
export let argDef: FswCommandArgumentVarString | undefined = undefined;
export let initVal: string;
export let setInEditor: (val: string) => void;
Expand All @@ -26,4 +26,4 @@
}
</script>

<input class="st-input w-100" spellcheck="false" bind:value title={argDef.description} />
<input class="st-input w-100" spellcheck="false" bind:value title={argDef && argDef.description} />
Loading

0 comments on commit a8eb3a1

Please sign in to comment.