From 83bcb1d87254da12c17ec251de1fdaccb82eb9c6 Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Thu, 20 Nov 2025 20:38:41 -0800 Subject: [PATCH 1/2] In upgrade_project.ts: Incremented version to 0.0.6. Added upgradeFrom_005_to_006. In mrc_mechanism.ts: Store component information for each parameter. --- src/blocks/mrc_mechanism.ts | 44 +++++++++++++++++++++++++++------- src/storage/upgrade_project.ts | 20 +++++++++++++++- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/blocks/mrc_mechanism.ts b/src/blocks/mrc_mechanism.ts index 7a754f68..2f4c44b5 100644 --- a/src/blocks/mrc_mechanism.ts +++ b/src/blocks/mrc_mechanism.ts @@ -48,6 +48,8 @@ export const FIELD_TYPE = 'TYPE'; type Parameter = { name: string, type: string, + componentId?: string, + componentPortsIndex?: number, // The zero-based number when iterating through component.ports. }; type MechanismExtraState = { @@ -55,6 +57,7 @@ type MechanismExtraState = { mechanismId?: string, importModule?: string, parameters?: Parameter[], + parametersHaveComponentInformation?: boolean, } const WARNING_ID_NOT_IN_HOLDER = 'not in holder'; @@ -66,6 +69,7 @@ interface MechanismMixin extends MechanismMixinType { mrcMechanismId: string, mrcImportModule: string, mrcParameters: Parameter[], + mrcParametersHaveComponentInformation: boolean, /** * mrcHasNotInHolderWarning is set to true if we set the NOT_IN_HOLDER warning text on the block. @@ -83,6 +87,7 @@ const MECHANISM = { * Block initialization. */ init: function (this: MechanismBlock): void { + this.mrcParametersHaveComponentInformation = false; this.mrcHasNotInHolderWarning = false; this.setStyle(MRC_STYLE_MECHANISMS); const nameField = new Blockly.FieldTextInput('') @@ -102,13 +107,11 @@ const MECHANISM = { const extraState: MechanismExtraState = { mechanismModuleId: this.mrcMechanismModuleId, mechanismId: this.mrcMechanismId, + parametersHaveComponentInformation: this.mrcParametersHaveComponentInformation, }; extraState.parameters = []; this.mrcParameters.forEach((arg) => { - extraState.parameters!.push({ - name: arg.name, - type: arg.type, - }); + extraState.parameters!.push({...arg}); }); if (this.mrcImportModule) { extraState.importModule = this.mrcImportModule; @@ -125,12 +128,11 @@ const MECHANISM = { this.mrcParameters = []; if (extraState.parameters) { extraState.parameters.forEach((arg) => { - this.mrcParameters.push({ - name: arg.name, - type: arg.type, - }); + this.mrcParameters.push({...arg}); }); } + this.mrcParametersHaveComponentInformation = (extraState.parametersHaveComponentInformation == undefined) + ? false : extraState.parametersHaveComponentInformation; this.updateBlock_(); }, /** @@ -289,13 +291,18 @@ const MECHANISM = { } this.mrcParameters = []; components.forEach(component => { + let componentPortsIndex = 0; for (const port in component.ports) { this.mrcParameters.push({ name: port, type: component.ports[port], + componentId: component.componentId, + componentPortsIndex, }); + componentPortsIndex++; } }); + this.mrcParametersHaveComponentInformation = true; this.updateBlock_(); } else { // Did not find the mechanism. @@ -324,6 +331,12 @@ const MECHANISM = { this.mrcMechanismId = oldIdToNewId[this.mrcMechanismId]; } }, + upgrade_005_to_006: function(this: MechanismBlock) { + // At the time when this upgrade method is called, we can't look up the component information + // for each parameter. Instead, we just mark this block as not having the information. Later, + // in the checkMechanism method, we will retrieve the component information for each parameter. + this.mrcParametersHaveComponentInformation = false; + }, }; export const setup = function () { @@ -359,17 +372,22 @@ export function createMechanismBlock( mechanismModuleId: mechanism.moduleId, importModule: snakeCaseName, parameters: [], + parametersHaveComponentInformation: true, }; const inputs: {[key: string]: any} = {}; let i = 0; components.forEach(component => { + let componentPortsIndex = 0; for (const port in component.ports) { const parameterType = component.ports[port]; extraState.parameters?.push({ name: port, type: parameterType, + componentId: component.componentId, + componentPortsIndex, }); inputs['ARG' + i] = createPort(parameterType); + componentPortsIndex++; i++; } }); @@ -378,3 +396,13 @@ export function createMechanismBlock( fields[FIELD_TYPE] = mechanism.className; return new toolboxItems.Block(BLOCK_NAME, extraState, fields, inputs); } + +/** + * Upgrades the MechanismBlocks in the given workspace from version 005 to 006. + * This function should only be called when upgrading old projects. + */ +export function upgrade_005_to_006(workspace: Blockly.Workspace): void { + workspace.getBlocksByType(BLOCK_NAME).forEach(block => { + (block as MechanismBlock).upgrade_005_to_006(); + }); +} diff --git a/src/storage/upgrade_project.ts b/src/storage/upgrade_project.ts index 47d4acd2..2fc4d9c9 100644 --- a/src/storage/upgrade_project.ts +++ b/src/storage/upgrade_project.ts @@ -29,10 +29,11 @@ import * as storageNames from './names'; import * as storageProject from './project'; import { upgrade_001_to_002 } from '../blocks/mrc_mechanism_component_holder'; import { upgrade_002_to_003, upgrade_004_to_005 } from '../blocks/mrc_class_method_def'; +import { upgrade_005_to_006 } from '../blocks/mrc_mechanism'; import * as workspaces from '../blocks/utils/workspaces'; export const NO_VERSION = '0.0.0'; -export const CURRENT_VERSION = '0.0.5'; +export const CURRENT_VERSION = '0.0.6'; export async function upgradeProjectIfNecessary( storage: commonStorage.Storage, projectName: string): Promise { @@ -66,6 +67,11 @@ export async function upgradeProjectIfNecessary( // @ts-ignore case '0.0.4': upgradeFrom_004_to_005(storage, projectName, projectInfo); + + // Intentional fallthrough after case '0.0.5' + // @ts-ignore + case '0.0.5': + upgradeFrom_005_to_006(storage, projectName, projectInfo); } await storageProject.saveProjectInfo(storage, projectName); } @@ -212,3 +218,15 @@ async function upgradeFrom_004_to_005( anyModuleType, upgrade_004_to_005); projectInfo.version = '0.0.5'; } + +async function upgradeFrom_005_to_006( + storage: commonStorage.Storage, + projectName: string, + projectInfo: storageProject.ProjectInfo): Promise { + // mrc_mechanism blocks may have component information for each parameter. + await upgradeBlocksFiles( + storage, projectName, + noModuleTypes, noPreupgrade, + anyModuleType, upgrade_005_to_006); + projectInfo.version = '0.0.6'; +} From ec3a08e2e24a15d2beb9948235c8d667eb12ef2a Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Fri, 21 Nov 2025 18:42:12 -0800 Subject: [PATCH 2/2] Reverted changes to upgrade_project.ts. Removed parametersHaveComponentInformation and mrcParametersHaveComponentInformation from mrc_mechanism.ts. These were set, but never actually used. Removed upgrade_005_to_006 from mrc_mechanism.ts. --- src/blocks/mrc_mechanism.ts | 24 ------------------------ src/storage/upgrade_project.ts | 20 +------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/src/blocks/mrc_mechanism.ts b/src/blocks/mrc_mechanism.ts index 2f4c44b5..54801932 100644 --- a/src/blocks/mrc_mechanism.ts +++ b/src/blocks/mrc_mechanism.ts @@ -57,7 +57,6 @@ type MechanismExtraState = { mechanismId?: string, importModule?: string, parameters?: Parameter[], - parametersHaveComponentInformation?: boolean, } const WARNING_ID_NOT_IN_HOLDER = 'not in holder'; @@ -69,7 +68,6 @@ interface MechanismMixin extends MechanismMixinType { mrcMechanismId: string, mrcImportModule: string, mrcParameters: Parameter[], - mrcParametersHaveComponentInformation: boolean, /** * mrcHasNotInHolderWarning is set to true if we set the NOT_IN_HOLDER warning text on the block. @@ -87,7 +85,6 @@ const MECHANISM = { * Block initialization. */ init: function (this: MechanismBlock): void { - this.mrcParametersHaveComponentInformation = false; this.mrcHasNotInHolderWarning = false; this.setStyle(MRC_STYLE_MECHANISMS); const nameField = new Blockly.FieldTextInput('') @@ -107,7 +104,6 @@ const MECHANISM = { const extraState: MechanismExtraState = { mechanismModuleId: this.mrcMechanismModuleId, mechanismId: this.mrcMechanismId, - parametersHaveComponentInformation: this.mrcParametersHaveComponentInformation, }; extraState.parameters = []; this.mrcParameters.forEach((arg) => { @@ -131,8 +127,6 @@ const MECHANISM = { this.mrcParameters.push({...arg}); }); } - this.mrcParametersHaveComponentInformation = (extraState.parametersHaveComponentInformation == undefined) - ? false : extraState.parametersHaveComponentInformation; this.updateBlock_(); }, /** @@ -302,7 +296,6 @@ const MECHANISM = { componentPortsIndex++; } }); - this.mrcParametersHaveComponentInformation = true; this.updateBlock_(); } else { // Did not find the mechanism. @@ -331,12 +324,6 @@ const MECHANISM = { this.mrcMechanismId = oldIdToNewId[this.mrcMechanismId]; } }, - upgrade_005_to_006: function(this: MechanismBlock) { - // At the time when this upgrade method is called, we can't look up the component information - // for each parameter. Instead, we just mark this block as not having the information. Later, - // in the checkMechanism method, we will retrieve the component information for each parameter. - this.mrcParametersHaveComponentInformation = false; - }, }; export const setup = function () { @@ -372,7 +359,6 @@ export function createMechanismBlock( mechanismModuleId: mechanism.moduleId, importModule: snakeCaseName, parameters: [], - parametersHaveComponentInformation: true, }; const inputs: {[key: string]: any} = {}; let i = 0; @@ -396,13 +382,3 @@ export function createMechanismBlock( fields[FIELD_TYPE] = mechanism.className; return new toolboxItems.Block(BLOCK_NAME, extraState, fields, inputs); } - -/** - * Upgrades the MechanismBlocks in the given workspace from version 005 to 006. - * This function should only be called when upgrading old projects. - */ -export function upgrade_005_to_006(workspace: Blockly.Workspace): void { - workspace.getBlocksByType(BLOCK_NAME).forEach(block => { - (block as MechanismBlock).upgrade_005_to_006(); - }); -} diff --git a/src/storage/upgrade_project.ts b/src/storage/upgrade_project.ts index 2fc4d9c9..47d4acd2 100644 --- a/src/storage/upgrade_project.ts +++ b/src/storage/upgrade_project.ts @@ -29,11 +29,10 @@ import * as storageNames from './names'; import * as storageProject from './project'; import { upgrade_001_to_002 } from '../blocks/mrc_mechanism_component_holder'; import { upgrade_002_to_003, upgrade_004_to_005 } from '../blocks/mrc_class_method_def'; -import { upgrade_005_to_006 } from '../blocks/mrc_mechanism'; import * as workspaces from '../blocks/utils/workspaces'; export const NO_VERSION = '0.0.0'; -export const CURRENT_VERSION = '0.0.6'; +export const CURRENT_VERSION = '0.0.5'; export async function upgradeProjectIfNecessary( storage: commonStorage.Storage, projectName: string): Promise { @@ -67,11 +66,6 @@ export async function upgradeProjectIfNecessary( // @ts-ignore case '0.0.4': upgradeFrom_004_to_005(storage, projectName, projectInfo); - - // Intentional fallthrough after case '0.0.5' - // @ts-ignore - case '0.0.5': - upgradeFrom_005_to_006(storage, projectName, projectInfo); } await storageProject.saveProjectInfo(storage, projectName); } @@ -218,15 +212,3 @@ async function upgradeFrom_004_to_005( anyModuleType, upgrade_004_to_005); projectInfo.version = '0.0.5'; } - -async function upgradeFrom_005_to_006( - storage: commonStorage.Storage, - projectName: string, - projectInfo: storageProject.ProjectInfo): Promise { - // mrc_mechanism blocks may have component information for each parameter. - await upgradeBlocksFiles( - storage, projectName, - noModuleTypes, noPreupgrade, - anyModuleType, upgrade_005_to_006); - projectInfo.version = '0.0.6'; -}