Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/src/data/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface OptionInterface {
options?: string[];
childOptions?: OptionInterface[];
valueExpression?: any; //{ expression: string; modelicaPath: string };
/** Never synthesized to `false` by the parser: undefined for non-selectable
* composite groups; a defined value evaluating to false (explicit
* Dialog(enable=...) annotation or dead end) disables the whole subtree of
* an instance of this option. */
enable?: any; // { modelicaPath: string; expression: string };
modifiers: any;
choiceModifiers?: { [key: string]: Modifiers };
Expand Down
20,613 changes: 9,360 additions & 11,253 deletions client/src/data/templates.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions client/src/interpreter/display-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ export function _formatDisplayItem(
_formatDisplayOption(optionInstance, parentModelicaPath, context),
);
}

// An instance disabled by Dialog(enable=...) hides its whole subtree:
// don't descend into its type
if (context._isInstanceDisabled(optionInstance.instancePath)) {
return displayList;
}
// check if the type needs to be rendered
// Use optionInstance.value for type lookup:
// - For non-replaceable components with no binding (value is undefined), lookup fails -> no nested components rendered
Expand Down
38 changes: 38 additions & 0 deletions client/src/interpreter/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,41 @@ export class ConfigContext {
}
}

/**
* True if the instance is explicitly disabled by a Dialog(enable=...)
* annotation that evaluates to false. A disabled instance disables its
* whole subtree: parameters under it are not user-editable regardless of
* their own enable annotation. The check operates on the instance tree
* (not the class definition) since the same class may be reachable through
* both a disabled and an enabled instance path.
*/
_isInstanceDisabled(instancePath: string): boolean {
if (!instancePath) {
return false;
}
const { optionPath } = resolvePaths(instancePath, this);
const option = optionPath ? this.options[optionPath] : undefined;
// `enable` is never synthesized to false by the parser: undefined marks a
// plain composite group, whose children remain live
if (option?.enable === undefined) {
return false;
}
const scope = instancePath.split(".").slice(0, -1).join(".");
const enable = evaluate(option.enable, this, scope);
// an unresolvable expression is NOT treated as disabled
return !isExpression(enable) && !enable;
}

_isAncestorDisabled(instancePath: string): boolean {
const segments = instancePath.split(".");
for (let i = segments.length - 1; i > 0; i--) {
if (this._isInstanceDisabled(segments.slice(0, i).join("."))) {
return true;
}
}
return false;
}

/**
* Returns an OptionInstance for the provided instance path. OptionInstance
* bakes in useful info related to make it easier to map to a display format
Expand Down Expand Up @@ -1234,6 +1269,9 @@ export class ConfigContext {
display = outerOption
? false // outer elements are always hidden
: !!(display && option.visible);
if (display && this._isAncestorDisabled(instancePath)) {
display = false; // any disabled ancestor hides the whole subtree
}

return { ...optionInstance, display };
}
Expand Down
59 changes: 41 additions & 18 deletions client/tests/data/options-TestRecord.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {
"TestRecord.Nested.mod.rec": {
"expression": "localRec",
Expand All @@ -202,7 +201,10 @@
}
},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Mod.localRec",
"TestRecord.BaseModel.rec"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -229,10 +231,12 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Mod1.localRec",
"TestRecord.BaseModel.rec"
],
"definition": false,
"shortExclType": false
},
Expand Down Expand Up @@ -271,10 +275,12 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Mod.localRec",
"TestRecord.BaseModel.rec"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -285,10 +291,12 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Mod1.localRec",
"TestRecord.BaseModel.rec"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -299,7 +307,6 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {
"TestRecord.mod2.localRec": {
"expression": "mod1.localRec",
Expand All @@ -308,7 +315,10 @@
}
},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Mod.localRec",
"TestRecord.BaseModel.rec"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -319,7 +329,6 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {
"TestRecord.mod3.rec": {
"expression": {
Expand All @@ -338,7 +347,10 @@
}
},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Mod.localRec",
"TestRecord.BaseModel.rec"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -349,10 +361,13 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"options": [
"TestRecord.Nested.localRecFirst",
"TestRecord.Nested.localRec",
"TestRecord.Nested.mod"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -363,10 +378,14 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"options": [
"TestRecord.NestedExtended.mod1",
"TestRecord.Nested.localRecFirst",
"TestRecord.Nested.localRec",
"TestRecord.Nested.mod"
],
"definition": false,
"shortExclType": false
},
Expand All @@ -377,15 +396,19 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {
"TestRecord.nesExt1.mod1.localRec.p": {
"expression": -3,
"final": false
}
},
"replaceable": false,
"options": [],
"options": [
"TestRecord.NestedExtended.mod1",
"TestRecord.Nested.localRecFirst",
"TestRecord.Nested.localRec",
"TestRecord.Nested.mod"
],
"definition": false,
"shortExclType": false
},
Expand Down
61 changes: 52 additions & 9 deletions client/tests/data/options-TestTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@
"tab": "",
"visible": false,
"modifiers": {},
"enable": false,
"choiceModifiers": {},
"replaceable": true,
"options": [
Expand Down Expand Up @@ -516,7 +515,6 @@
"tab": "",
"visible": true,
"modifiers": {},
"enable": false,
"choiceModifiers": {},
"replaceable": true,
"options": [
Expand Down Expand Up @@ -550,15 +548,20 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {
"TestPackage.Template.TestTemplate.third.component_param": {
"expression": "\"Third Component Template Override\"",
"final": false
}
},
"replaceable": false,
"options": [],
"options": [
"TestPackage.Component.ThirdComponent.component_param",
"TestPackage.Component.ThirdComponent.selectable_component",
"TestPackage.Component.ThirdComponent.container_from_outer",
"TestPackage.Interface.PartialComponent.container",
"TestPackage.Interface.PartialComponent.icecream"
],
"definition": false,
"shortExclType": false
},
Expand Down Expand Up @@ -945,6 +948,25 @@
"definition": false,
"shortExclType": false
},
"TestPackage.Template.TestTemplate.disabled_component": {
"modelicaPath": "TestPackage.Template.TestTemplate.disabled_component",
"type": "TestPackage.Component.FirstComponent",
"name": "Disabled composite component",
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [
"TestPackage.Component.FirstComponent.component_param",
"TestPackage.Component.FirstComponent.datAll",
"TestPackage.Interface.PartialComponent.container",
"TestPackage.Interface.PartialComponent.icecream"
],
"definition": false,
"shortExclType": false
},
"TestPackage.Template.TestTemplate.connector_param": {
"modelicaPath": "TestPackage.Template.TestTemplate.connector_param",
"type": "Integer",
Expand Down Expand Up @@ -987,6 +1009,20 @@
"definition": false,
"shortExclType": false
},
"TestPackage.Template.TestTemplate.dead_end_component": {
"modelicaPath": "TestPackage.Template.TestTemplate.dead_end_component",
"type": "TestPackage.Component.DeadEndComponent",
"name": "Dead-end component",
"group": "Skipped Group",
"tab": "Skipped Tab",
"visible": false,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"definition": false,
"shortExclType": false
},
"TestPackage.Template.TestTemplate.typ": {
"modelicaPath": "TestPackage.Template.TestTemplate.typ",
"type": "TestPackage.Types.IceCream",
Expand Down Expand Up @@ -1092,15 +1128,18 @@
"group": "",
"tab": "",
"visible": false,
"enable": false,
"modifiers": {
"TestPackage.Template.TestTemplate.short_path_component.replaceable_param": {
"final": false,
"redeclare": "TestPackage.Component.FifthComponent"
}
},
"replaceable": false,
"options": [],
"options": [
"TestPackage.Component.FourthComponent.replaceable_param",
"TestPackage.Interface.PartialComponent.container",
"TestPackage.Interface.PartialComponent.icecream"
],
"definition": false,
"shortExclType": false
},
Expand Down Expand Up @@ -1274,10 +1313,12 @@
"group": "",
"tab": "",
"visible": true,
"enable": false,
"modifiers": {},
"replaceable": false,
"options": [],
"options": [
"TestPackage.Component.FirstComponent",
"TestPackage.Component.SecondComponent"
],
"definition": false,
"shortExclType": false
},
Expand Down Expand Up @@ -1508,8 +1549,11 @@
"TestPackage.Template.TestTemplate.test_string_initialized",
"TestPackage.Template.TestTemplate.test_real",
"TestPackage.Template.TestTemplate.test_int",
"TestPackage.Template.TestTemplate.disabled_component",
"TestPackage.Template.TestTemplate.connector_param",
"TestPackage.Template.TestTemplate.connector_param_false",
"TestPackage.Template.TestTemplate.linkage_keyword_false",
"TestPackage.Template.TestTemplate.dead_end_component",
"TestPackage.Template.TestTemplate.typ",
"TestPackage.Template.TestTemplate.typ_limited",
"TestPackage.Template.TestTemplate.final_group_member_bool",
Expand Down Expand Up @@ -1547,7 +1591,6 @@
"tab": "",
"visible": true,
"modifiers": {},
"enable": false,
"choiceModifiers": {},
"replaceable": true,
"options": [
Expand Down
Binary file modified client/tests/data/templates.json.gz
Binary file not shown.
Loading