Skip to content

Commit 2d53e0b

Browse files
committed
Merge branch 'main' of github.com:alan412/systemcore-blocks-interface into pr_try_steps_block
2 parents e8346ca + 926d78d commit 2d53e0b

23 files changed

+451
-299
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
For each PR, make sure each of these works
2+
3+
# New items
4+
* [ ] Make a new project and make sure you can edit in Robot and TeleOp
5+
* [ ] Add an opmode "Auto" from the + next to Tabs
6+
* [ ] Add a mechanism "Arm" from the + next to Tabs
7+
# Using robot
8+
* [ ] Add a component to the Robot
9+
* [ ] Add a mechanism to the Robot
10+
* [ ] When editing an OpMode, make sure the component shows up in the toolbox Robot -> Components ->
11+
* [ ] When editing an OpMode, make sure the mechanism shows up in the toolbox Robot -> Mechanisms -> my_arm
12+
# Events
13+
* [ ] Add an event to the Mechanism
14+
* [ ] In Robot, make sure you can see the event handler in the toolbox Robot -> Mechanisms -> my_arm -> Events
15+
* [ ] In Opmode, make sure you can see the event handler in the toolbox Robot -> Mechanisms -> my_arm -> Events
16+
# Mechanims
17+
* [ ] Add a public component to the mechanism
18+
* [ ] Add a private component to the mechanism
19+
* [ ] Make sure that in the Robot you can see the public component (and not the private one) in the toolbox
20+
# Code Generation
21+
* [ ] Generate code (right now "Deploy") and make sure there are no errors in the console
22+
* [ ] Check that the deploy zip file contains robot.py, teleop.py, auto.py, and arm.py.

src/blocks/mrc_call_python_function.ts

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,22 @@ const CALL_PYTHON_FUNCTION = {
211211
}
212212
case FunctionKind.EVENT: {
213213
const eventName = this.getFieldValue(FIELD_EVENT_NAME);
214-
tooltip = Blockly.Msg.CALL_INSTANCE_METHOD_WITHIN_TOOLTIP;
214+
tooltip = Blockly.Msg.FIRE_EVENT_TOOLTIP;
215215
tooltip = tooltip.replace('{{eventName}}', eventName);
216216
break;
217217
}
218218
case FunctionKind.INSTANCE_COMPONENT: {
219219
const className = this.mrcComponentClassName;
220220
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
221221
if (this.mrcMechanismId) {
222-
tooltip = Blockly.Msg.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD;
222+
tooltip = Blockly.Msg.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_TOOLTIP;
223223
tooltip = tooltip
224224
.replace('{{className}}', className)
225225
.replace('{{functionName}}', functionName)
226226
.replace('{{componentName}}', this.getFieldValue(FIELD_COMPONENT_NAME))
227227
.replace('{{mechanismName}}', this.getFieldValue(FIELD_MECHANISM_NAME));
228228
} else {
229-
tooltip = Blockly.Msg.CALL_COMPONENT_INSTANCE_METHOD;
229+
tooltip = Blockly.Msg.CALL_COMPONENT_INSTANCE_METHOD_TOOLTIP;
230230
tooltip = tooltip
231231
.replace('{{className}}', className)
232232
.replace('{{functionName}}', functionName)
@@ -236,18 +236,18 @@ const CALL_PYTHON_FUNCTION = {
236236
}
237237
case FunctionKind.INSTANCE_ROBOT: {
238238
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
239-
tooltip = Blockly.Msg.CALL_INSTANCE_METHOD_WITHIN_TOOLTIP;
239+
tooltip = Blockly.Msg.CALL_ROBOT_INSTANCE_METHOD_TOOLTIP;
240240
tooltip = tooltip.replace('{{functionName}}', functionName);
241241
break;
242242
}
243243
case FunctionKind.INSTANCE_MECHANISM: {
244244
const className = this.mrcMechanismClassName;
245245
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
246-
tooltip = Blockly.Msg.CALL_MECHANISM_INSTANCE_METHOD;
247-
tooltip = tooltip
248-
.replace('{{className}}', className)
249-
.replace('{{functionName}}', functionName)
250-
.replace('{{mechanismName}}', this.getFieldValue(FIELD_MECHANISM_NAME));
246+
tooltip = Blockly.Msg.CALL_MECHANISM_INSTANCE_METHOD_TOOLTIP;
247+
tooltip = tooltip
248+
.replace('{{className}}', className)
249+
.replace('{{functionName}}', functionName)
250+
.replace('{{mechanismName}}', this.getFieldValue(FIELD_MECHANISM_NAME));
251251
break;
252252
}
253253
default:
@@ -436,7 +436,7 @@ const CALL_PYTHON_FUNCTION = {
436436
case FunctionKind.INSTANCE_ROBOT: {
437437
this.appendDummyInput(INPUT_TITLE)
438438
.appendField(Blockly.Msg.CALL)
439-
.appendField(createFieldNonEditableText(Blockly.Msg.ROBOT))
439+
.appendField(createFieldNonEditableText(Blockly.Msg.ROBOT_LOWER_CASE))
440440
.appendField('.')
441441
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
442442
break;
@@ -549,66 +549,59 @@ const CALL_PYTHON_FUNCTION = {
549549
}
550550
this.updateBlock_();
551551
},
552-
getComponents: function(this: CallPythonFunctionBlock): storageModuleContent.Component[] {
552+
getComponents: function(this: CallPythonFunctionBlock, editor: Editor): storageModuleContent.Component[] {
553553
// Get the list of components whose type matches this.mrcComponentClassName.
554554
const components: storageModuleContent.Component[] = [];
555-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
556-
if (editor) {
557-
let componentsToConsider: storageModuleContent.Component[] = [];
558-
if (this.mrcMechanismId) {
559-
// Only consider components that belong to the mechanism.
560-
// this.mrcMechanismId is the mechanismId from the MechanismInRobot.
561-
// We need to get the MechanismInRobot with that id, then get the mechanism, and then get
562-
// the public components defined in that mechanism.
563-
for (const mechanismInRobot of editor.getMechanismsFromRobot()) {
564-
if (mechanismInRobot.mechanismId === this.mrcMechanismId) {
565-
for (const mechanism of editor.getMechanisms()) {
566-
if (mechanism.moduleId === mechanismInRobot.moduleId) {
567-
componentsToConsider = editor.getComponentsFromMechanism(mechanism);
568-
break;
569-
}
555+
let componentsToConsider: storageModuleContent.Component[] = [];
556+
if (this.mrcMechanismId) {
557+
// Only consider components that belong to the mechanism.
558+
// this.mrcMechanismId is the mechanismId from the MechanismInRobot.
559+
// We need to get the MechanismInRobot with that id, then get the mechanism, and then get
560+
// the public components defined in that mechanism.
561+
for (const mechanismInRobot of editor.getMechanismsFromRobot()) {
562+
if (mechanismInRobot.mechanismId === this.mrcMechanismId) {
563+
for (const mechanism of editor.getMechanisms()) {
564+
if (mechanism.moduleId === mechanismInRobot.moduleId) {
565+
componentsToConsider = editor.getComponentsFromMechanism(mechanism);
566+
break;
570567
}
571-
break;
572568
}
569+
break;
573570
}
574-
} else if (editor.getModuleType() === storageModule.ModuleType.MECHANISM) {
575-
// Only consider components (regular and private) in the current workspace.
576-
componentsToConsider = editor.getAllComponentsFromWorkspace();
577-
} else {
578-
// Only consider components in the robot.
579-
componentsToConsider = editor.getComponentsFromRobot();
580571
}
581-
componentsToConsider.forEach(component => {
582-
if (component.className === this.mrcComponentClassName) {
583-
components.push(component);
584-
}
585-
});
572+
} else if (editor.getModuleType() === storageModule.ModuleType.MECHANISM) {
573+
// Only consider components (regular and private) in the current workspace.
574+
componentsToConsider = editor.getAllComponentsFromWorkspace();
575+
} else {
576+
// Only consider components in the robot.
577+
componentsToConsider = editor.getComponentsFromRobot();
586578
}
579+
componentsToConsider.forEach(component => {
580+
if (component.className === this.mrcComponentClassName) {
581+
components.push(component);
582+
}
583+
});
587584
return components;
588585
},
589586

590587
/**
591588
* mrcOnModuleCurrent is called for each CallPythonFunctionBlock when the module becomes the current module.
592589
*/
593-
mrcOnModuleCurrent: function(this: CallPythonFunctionBlock): void {
594-
this.checkFunction();
590+
mrcOnModuleCurrent: function(this: CallPythonFunctionBlock, editor: Editor): void {
591+
this.checkFunction(editor);
595592
},
596593
/**
597594
* mrcOnLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly
598595
* workspace.
599596
*/
600-
mrcOnLoad: function(this: CallPythonFunctionBlock): void {
601-
this.checkFunction();
597+
mrcOnLoad: function(this: CallPythonFunctionBlock, editor: Editor): void {
598+
this.checkFunction(editor);
602599
},
603600
/**
604601
* checkFunction checks the block, updates it, and/or adds a warning balloon if necessary.
605602
* It is called from mrcOnModuleCurrent and mrcOnLoad above.
606603
*/
607-
checkFunction: function(this: CallPythonFunctionBlock): void {
608-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
609-
if (!editor) {
610-
return;
611-
}
604+
checkFunction: function(this: CallPythonFunctionBlock, editor: Editor): void {
612605
const warnings: string[] = [];
613606

614607
// If this block is calling a component method, check whether the component
@@ -621,7 +614,7 @@ const CALL_PYTHON_FUNCTION = {
621614
if (this.mrcFunctionKind === FunctionKind.INSTANCE_COMPONENT) {
622615
const componentNames: string[] = [];
623616
this.mrcMapComponentNameToId = {}
624-
this.getComponents().forEach(component => {
617+
this.getComponents(editor).forEach(component => {
625618
componentNames.push(component.name);
626619
this.mrcMapComponentNameToId[component.name] = component.componentId;
627620
});
@@ -865,7 +858,7 @@ export function pythonFromBlock(
865858
generator: ExtendedPythonGenerator,
866859
) {
867860
if (block.mrcImportModule) {
868-
generator.addImport(block.mrcImportModule);
861+
generator.importModule(block.mrcImportModule);
869862
}
870863
let code = '';
871864
let needOpenParen = true;

src/blocks/mrc_component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { MRC_STYLE_COMPONENTS } from '../themes/styles'
2626
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
2727
import { Editor } from '../editor/editor';
2828
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
29+
import { getModuleTypeForWorkspace } from './utils/workspaces';
2930
import { getAllowedTypesForSetCheck, getClassData, getSubclassNames } from './utils/python';
3031
import * as toolboxItems from '../toolbox/items';
3132
import * as storageModule from '../storage/module';
@@ -142,8 +143,8 @@ const COMPONENT = {
142143
* Update the block to reflect the newly loaded extra state.
143144
*/
144145
updateBlock_: function (this: ComponentBlock): void {
145-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
146-
if (editor && editor.getModuleType() === storageModule.ModuleType.ROBOT) {
146+
const moduleType = getModuleTypeForWorkspace(this.workspace);
147+
if (moduleType === storageModule.ModuleType.ROBOT) {
147148
// Add input sockets for the arguments.
148149
for (let i = 0; i < this.mrcArgs.length; i++) {
149150
const input = this.appendValueInput('ARG' + i)
@@ -192,7 +193,7 @@ const COMPONENT = {
192193
/**
193194
* mrcOnLoad is called for each ComponentBlock when the blocks are loaded in the blockly workspace.
194195
*/
195-
mrcOnLoad: function(this: ComponentBlock): void {
196+
mrcOnLoad: function(this: ComponentBlock, _editor: Editor): void {
196197
this.checkBlockIsInHolder();
197198
},
198199
/**
@@ -246,7 +247,7 @@ export const pythonFromBlock = function (
246247
generator: ExtendedPythonGenerator,
247248
) {
248249
if (block.mrcImportModule) {
249-
generator.addImport(block.mrcImportModule);
250+
generator.importModule(block.mrcImportModule);
250251
}
251252
let code = 'self.' + block.getFieldValue(FIELD_NAME) + ' = ' + block.getFieldValue(FIELD_TYPE) + "(";
252253

src/blocks/mrc_event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Blockly from 'blockly';
2424
import { MRC_STYLE_EVENTS } from '../themes/styles'
2525
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
2626
import { Parameter } from './mrc_class_method_def';
27+
import { Editor } from '../editor/editor';
2728
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2829
import * as paramContainer from './mrc_param_container'
2930
import {
@@ -196,7 +197,7 @@ const EVENT = {
196197
/**
197198
* mrcOnLoad is called for each EventBlock when the blocks are loaded in the blockly workspace.
198199
*/
199-
mrcOnLoad: function(this: EventBlock): void {
200+
mrcOnLoad: function(this: EventBlock, _editor: Editor): void {
200201
this.checkBlockIsInHolder();
201202
},
202203
/**

0 commit comments

Comments
 (0)