Skip to content

Commit 32e5143

Browse files
committed
Merge branch 'main' of github.com:wpilibsuite/systemcore-blocks-interface into pr_fix_add_tab
2 parents 5cc4272 + 84d05fb commit 32e5143

File tree

13 files changed

+411
-158
lines changed

13 files changed

+411
-158
lines changed

src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ const AppContent: React.FC<AppContentProps> = ({ project, setProject }): React.J
368368
await saveModule();
369369
}
370370
setCurrentModule(module);
371+
if (module) {
372+
setActiveTab(module.modulePath);
373+
}
371374
};
372375

373376
/** Handles toolbox settings modal close. */

src/blocks/mrc_call_python_function.ts

Lines changed: 109 additions & 46 deletions
Large diffs are not rendered by default.

src/blocks/mrc_class_method_def.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ const CLASS_METHOD_DEF = {
322322
this.mrcMethodId = oldIdToNewId[this.mrcMethodId];
323323
}
324324
},
325+
upgrade_002_to_003: function(this: ClassMethodDefBlock) {
326+
if (this.getFieldValue('NAME') === 'init') {
327+
// Remove robot parameter from init method
328+
const methodBlock = this as ClassMethodDefBlock;
329+
let filteredParams: Parameter[] = methodBlock.mrcParameters.filter(param => param.name !== 'robot');
330+
methodBlock.mrcParameters = filteredParams;
331+
}
332+
},
325333
};
326334

327335
/**
@@ -447,6 +455,10 @@ export const pythonFromBlock = function (
447455
}
448456
}
449457

458+
if (generator.getModuleType() === storageModule.ModuleType.OPMODE && block.mrcPythonMethodName === '__init__') {
459+
paramString = 'robot';
460+
}
461+
450462
if (params.length != 0) {
451463
block.mrcParameters.forEach((param) => {
452464
paramString += ', ' + param.name;

src/blocks/mrc_event_handler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ const EVENT_HANDLER = {
176176
* workspace.
177177
*/
178178
mrcOnLoad: function(this: EventHandlerBlock): void {
179+
this.mrcValidate();
180+
},
181+
/**
182+
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
183+
* It is called from mrcOnLoad above and from Editor.makeCurrent.
184+
*/
185+
mrcValidate: function(this: EventHandlerBlock): void {
179186
const warnings: string[] = [];
180187

181188
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);

src/blocks/mrc_mechanism.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,19 @@ const MECHANISM = {
174174
className: mechanismType,
175175
};
176176
},
177+
178+
/**
179+
* mrcOnLoad is called for each MechanismBlock when the blocks are loaded in the blockly
180+
* workspace.
181+
*/
177182
mrcOnLoad: function(this: MechanismBlock): void {
178-
// mrcOnLoad is called for each MechanismBlock when the blocks are loaded in the blockly workspace.
183+
this.mrcValidate();
184+
},
185+
/**
186+
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
187+
* It is called from mrcOnLoad above and from Editor.makeCurrent.
188+
*/
189+
mrcValidate: function(this: MechanismBlock): void {
179190
const warnings: string[] = [];
180191

181192
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);

src/blocks/tokens.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ export function customTokens(t: (key: string) => string): typeof Blockly.Msg {
6161
OPMODE_ENABLED_TOOLTIP: t('BLOCKLY.TOOLTIP.OPMODE_ENABLED'),
6262
OPMODE_NAME_TOOLTIP: t('BLOCKLY.TOOLTIP.OPMODE_NAME'),
6363
OPMODE_GROUP_TOOLTIP: t('BLOCKLY.TOOLTIP.OPMODE_GROUP'),
64+
CALL: t('BLOCKLY.CALL'),
65+
ROBOT_LOWER_CASE: t('BLOCKLY.ROBOT_LOWER_CASE'),
66+
CREATE: t('BLOCKLY.CREATE'),
67+
FIRE: t('BLOCKLY.FIRE'),
68+
WARNING_CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT: t('BLOCKLY.WARNING.CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT'),
69+
WARNING_CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT: t('BLOCKLY.WARNING.CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT'),
70+
WARNING_CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM: t('BLOCKLY.WARNING.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM'),
71+
WARNING_CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM: t('BLOCKLY.WARNING.CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM'),
72+
WARNING_CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD: t('BLOCKLY.WARNING.CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD'),
73+
WARNING_CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM: t('BLOCKLY.WARNING.CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM'),
74+
WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD: t('BLOCKLY.WARNING.CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD'),
75+
WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM: t('BLOCKLY.WARNING.CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM'),
76+
CALL_BUILTIN_FUNCTION_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_BUILTIN_FUNCTION'),
77+
CALL_MODULE_FUNCTION_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_MODULE_FUNCTION'),
78+
CALL_STATIC_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_STATIC_METHOD'),
79+
CALL_CONSTRUCTOR_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_CONSTRUCTOR'),
80+
CALL_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_INSTANCE_METHOD'),
81+
CALL_INSTANCE_METHOD_WITHIN_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_INSTANCE_METHOD_WITHIN'),
82+
FIRE_EVENT_TOOLTIP: t('BLOCKLY.TOOLTIP.FIRE_EVENT'),
83+
CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD'),
84+
CALL_COMPONENT_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_COMPONENT_INSTANCE_METHOD'),
85+
CALL_ROBOT_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_ROBOT_INSTANCE_METHOD'),
86+
CALL_MECHANISM_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_MECHANISM_INSTANCE_METHOD'),
6487
MRC_CATEGORY_HARDWARE: t('BLOCKLY.CATEGORY.HARDWARE'),
6588
MRC_CATEGORY_ROBOT: t('BLOCKLY.CATEGORY.ROBOT'),
6689
MRC_CATEGORY_COMPONENTS: t('BLOCKLY.CATEGORY.COMPONENTS'),

src/editor/editor.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
3838
contents: [],
3939
};
4040

41+
const MRC_ON_LOAD = 'mrcOnLoad';
42+
const MRC_VALIDATE = 'mrcValidate';
43+
4144
export class Editor {
4245
private static workspaceIdToEditor: { [workspaceId: string]: Editor } = {};
4346
private static currentEditor: Editor | null = null;
@@ -97,8 +100,8 @@ export class Editor {
97100
blockCreateEvent.ids.forEach(id => {
98101
const block = this.blocklyWorkspace.getBlockById(id);
99102
if (block) {
100-
if ('mrcOnLoad' in block && typeof block.mrcOnLoad === "function") {
101-
block.mrcOnLoad();
103+
if (MRC_ON_LOAD in block && typeof block[MRC_ON_LOAD] === 'function') {
104+
block[MRC_ON_LOAD]();
102105
}
103106
}
104107
});
@@ -129,6 +132,13 @@ export class Editor {
129132
// Parse modules since they might have changed.
130133
this.parseModules(project, modulePathToContentText);
131134
this.updateToolboxImpl();
135+
136+
// Go through all the blocks in the workspace and call their mrcValidate method.
137+
this.blocklyWorkspace.getAllBlocks().forEach(block => {
138+
if (MRC_VALIDATE in block && typeof block[MRC_VALIDATE] === 'function') {
139+
block[MRC_VALIDATE]();
140+
}
141+
});
132142
}
133143

134144
public abandon(): void {
@@ -158,8 +168,8 @@ export class Editor {
158168
for (const mechanism of this.mechanisms) {
159169
const moduleContent = this.modulePathToModuleContent[mechanism.modulePath];
160170
if (!moduleContent) {
161-
console.error(this.modulePath + " editor.parseModules - modulePathToModuleContent['" +
162-
mechanism.modulePath + "'] is undefined");
171+
console.error(this.modulePath + ' editor.parseModules - modulePathToModuleContent["' +
172+
mechanism.modulePath + '"] is undefined');
163173
continue;
164174
}
165175
this.mechanismClassNameToModuleContent[mechanism.className] = moduleContent;
@@ -441,7 +451,7 @@ export class Editor {
441451
}
442452

443453
/**
444-
* Returns the components defined in the given mechanism.
454+
* Returns the regular components defined in the given mechanism.
445455
*/
446456
public getComponentsFromMechanism(mechanism: storageModule.Mechanism): storageModuleContent.Component[] {
447457
if (this.module.modulePath === mechanism.modulePath) {
@@ -453,6 +463,19 @@ export class Editor {
453463
throw new Error('getComponentsFromMechanism: mechanism not found: ' + mechanism.className);
454464
}
455465

466+
/**
467+
* Returns the private components defined in the given mechanism.
468+
*/
469+
public getPrivateComponentsFromMechanism(mechanism: storageModule.Mechanism): storageModuleContent.Component[] {
470+
if (this.module.modulePath === mechanism.modulePath) {
471+
return this.getPrivateComponentsFromWorkspace();
472+
}
473+
if (mechanism.className in this.mechanismClassNameToModuleContent) {
474+
return this.mechanismClassNameToModuleContent[mechanism.className].getPrivateComponents();
475+
}
476+
throw new Error('getPrivateComponentsFromMechanism: mechanism not found: ' + mechanism.className);
477+
}
478+
456479
/**
457480
* Returns ALL components (including private components) defined in the given mechanism.
458481
* This is used when creating mechanism blocks that need all components for port parameters.

src/i18n/locales/en/translation.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
"DISPLAY_GROUP": "Display Group",
6363
"PRINT": "print",
6464
"NO_MECHANISM_CONTENTS": "No Mechanism Contents",
65+
"CALL": "call",
66+
"ROBOT": "robot",
67+
"CREATE": "create",
68+
"FIRE": "fire",
6569
"TOOLTIP":{
6670
"EVALUATE_BUT_IGNORE_RESULT": "Executes the connected block and ignores the result. Allows you to call a function and ignore the return value.",
6771
"NONE": "Returns None.",
@@ -70,7 +74,18 @@
7074
"OPMODE_NAME": "The name shown on the Driver Station. If blank will use the class name.",
7175
"OPMODE_GROUP": "An optional group to group OpModes on Driver Station",
7276
"COMPONENTS": "These components are visible in this mechanism, the robot, and all opmodes.",
73-
"PRIVATE_COMPONENTS": "These components will not be visible in the robot or opmodes. They are only accessible within this mechanism."
77+
"PRIVATE_COMPONENTS": "These components will not be visible in the robot or opmodes. They are only accessible within this mechanism.",
78+
"CALL_BUILTIN_FUNCTION": "Calls the builtin function {{functionName}}.",
79+
"CALL_MODULE_FUNCTION": "Calls the module function {{moduleName}}.{{functionName}}.",
80+
"CALL_STATIC_METHOD": "Calls the static method {{className}}.{{functionName}}.",
81+
"CALL_CONSTRUCTOR": "Constructs an instance of the class {{className}}.",
82+
"CALL_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}}.",
83+
"CALL_INSTANCE_METHOD_WITHIN": "Calls the instance method {{functionName}}.",
84+
"FIRE_EVENT": "Fires the event named {{eventName}}.",
85+
"CALL_MECHANISM_COMPONENT_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}} on the component named {{componentName}} in the mechanism named {{mechanismName}}.",
86+
"CALL_COMPONENT_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}} on the component named {{componentName}}.",
87+
"CALL_ROBOT_INSTANCE_METHOD": "Calls the robot method {{functionName}}.",
88+
"CALL_MECHANISM_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}} on the mechanism named {{mechanismName}}."
7489
},
7590
"CATEGORY":{
7691
"LISTS": "Lists",
@@ -89,6 +104,16 @@
89104
"ADD_MECHANISM": "+ Mechanism",
90105
"ADD_COMPONENT": "+ Component",
91106
"TEST": "Test"
107+
},
108+
"WARNING":{
109+
"CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT": "This blocks calls a method on a private component in the {{mechanismClassName}} mechanism.",
110+
"CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT": "This block calls a method on a component that no longer exists.",
111+
"CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM": "This block calls a method on a component that belongs to a mechanism that no longer exists.",
112+
"CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM": "This block is not allowed to be used inside a mechanism.",
113+
"CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD": "This block calls a method that no longer exists in the robot.",
114+
"CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM": "This block is not allowed to be used inside a mechanism.",
115+
"CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD": "This block calls a method that no longer exists in the mechanism.",
116+
"CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM": "This block calls a method in a mechanism that no longer exists."
92117
}
93118
}
94119
}

src/i18n/locales/es/translation.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
"DISPLAY_GROUP": "Grupo a Mostrar",
6464
"PRINT": "imprimir",
6565
"NO_MECHANISM_CONTENTS": "Sin Contenido de Mecanismo",
66+
"CALL": "llamar",
67+
"ROBOT": "robot",
68+
"CREATE": "crear",
69+
"FIRE": "disparar",
6670
"TOOLTIP": {
6771
"EVALUATE_BUT_IGNORE_RESULT": "Ejecuta el bloque conectado e ignora el resultado. Te permite llamar una función e ignorar el valor de retorno.",
6872
"NONE": "No devuelve ninguno.",
@@ -71,7 +75,18 @@
7175
"OPMODE_NAME": "El nombre mostrado en la Estación del Conductor. Si está en blanco usará el nombre de la clase.",
7276
"OPMODE_GROUP": "Un grupo opcional para agrupar OpModes en la Estación del Conductor",
7377
"COMPONENTS": "Estos componentes son visibles en este mecanismo, el robot y todos los opmodes.",
74-
"PRIVATE_COMPONENTS": "Estos componentes no serán visibles en el robot o en los opmodes. Solo son accesibles dentro de este mecanismo."
78+
"PRIVATE_COMPONENTS": "Estos componentes no serán visibles en el robot o en los opmodes. Solo son accesibles dentro de este mecanismo.",
79+
"CALL_BUILTIN_FUNCTION": "Llama a la función incorporada {{functionName}}.",
80+
"CALL_MODULE_FUNCTION": "Llama a la función del módulo {{moduleName}}.{{functionName}}.",
81+
"CALL_STATIC_METHOD": "Llama al método estático {{className}}.{{functionName}}.",
82+
"CALL_CONSTRUCTOR": "Construye una instancia de la clase {{className}}.",
83+
"CALL_INSTANCE_METHOD": "Llama al método de instancia {{className}}.{{functionName}}.",
84+
"CALL_INSTANCE_METHOD_WITHIN": "Llama al método de instancia {{functionName}}.",
85+
"FIRE_EVENT": "Dispara el evento llamado {{eventName}}.",
86+
"CALL_MECHANISM_COMPONENT_INSTANCE_METHOD": "Llama al método de instancia {{className}}.{{functionName}} en el componente llamado {{componentName}} en el mecanismo llamado {{mechanismName}}.",
87+
"CALL_COMPONENT_INSTANCE_METHOD": "Llama al método de instancia {{className}}.{{functionName}} en el componente llamado {{componentName}}.",
88+
"CALL_ROBOT_INSTANCE_METHOD": "Llama al método robot {{functionName}}.",
89+
"CALL_MECHANISM_INSTANCE_METHOD": "Llama al método de instancia {{className}}.{{functionName}} en el mecanismo llamado {{mechanismName}}."
7590
},
7691
"CATEGORY": {
7792
"LISTS": "Listas",
@@ -90,6 +105,16 @@
90105
"ADD_MECHANISM": "+ Mecanismo",
91106
"ADD_COMPONENT": "+ Componente",
92107
"TEST": "Prueba"
108+
},
109+
"WARNING":{
110+
"CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT": "Este bloque llama a un método en un componente privado en el mecanismo {{mechanismClassName}}.",
111+
"CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT": "Este bloque llama a un método en un componente que ya no existe.",
112+
"CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM": "Este bloque llama a un método de un componente que pertenece a un mecanismo que ya no existe.",
113+
"CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM": "No se permite utilizar este bloque dentro de un mecanismo.",
114+
"CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD": "Este bloque llama a un método que ya no existe en el robot.",
115+
"CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM": "No se permite utilizar este bloque dentro de un mecanismo.",
116+
"CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD": "Este bloque llama a un método que ya no existe en el mecanismo.",
117+
"CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM": "Este bloque llama a un método en un mecanismo que ya no existe."
93118
}
94119
}
95120
}

0 commit comments

Comments
 (0)