Skip to content

Conversation

lizlooney
Copy link
Collaborator

When editing the robot, the toolbox now shows blocks in the "Hardware > Mechanisms > + Mechanism" so the user can add a mechanism to the robot.

Once the user has added a mechanism, there is a category for that mechanism, but it currently doesn't have any blocks in it. I've added a TODO to add blocks for each method that is declared in the mechanism and I'll have a future PR for that.

Pass project to Editor.loadModuleBlocks
Call Editor.abandon and Editor.makeCurrent when switching between modules.

In editor.ts:
Added static variable currentEditor. Updated getEditorForBlocklyWorkspace to return currentEditor if workspace isn't found.
Added static method getCurrentEditor.
Added methods abandon and makeCurrent, which are called from App.tsx when switching between modules.
Add project parameter to loadModuleBlocks. Fetch all the mechanisms in the project.
In block event handler, call block.mrcOnLoad instead of block.onLoad.
Added methods getMechanisms, getComponentsFromMechanism, getEventsFromMechanism, and getMethodsFromMechanism.

In extended_python_generator.ts:
Renamed field hasHardware to hasAnyComponents.
Renamed field ports to componentPorts.
Renamed field hasEventHandler to hasAnyEventHandlers.
Removed method getListOfPorts. Added method getComponentPortParameters.

In hardware_category.ts:
Updated getHardwareCategory function so it fills in the + Mechanism category with blocks representing each the mechanisms in the project.
Changed getComponentsCategory function so it takes moduleType (string) instead hideParams (boolean).

In mrc_mechanism.ts:
Added method mrcOnLoad to handle changes to the mechanism definition.
Added function createMechanismBlock, which is called to put a add mechanism block in the toolbox when editing a robot.

In mrc_mechanism_component_holder.ts:
Updated code in pythonFromBlockInMechanism that calls generator.getComponentPortParameters().
Removed function getHardwarePorts. Added functions hasAnyComponents and getComponentPorts.

In mrc_component.ts:
Modified getComponent to collect the ports for the component.
Modified getAllPossibleComponents and createComponentBlock to take moduleType instead of hideParams.
Removed function getHardwarePorts. Added function getComponentPorts.

In mrc_class_method_def.ts, updated code in pythonFromBlock that calls generator.getComponentPortParameters().

In mrc_call_python_function.ts, renamed onLoad to mrcOnLoad.

In mrc_event_handler.ts:
Renamed mrcTypeOfSender to mrcSenderType.
Renamed typeOfSender to senderType.
Renamed onLoad to mrcOnLoad.

In client_sid_storage.ts, removed temporary code that handled old module type 'project'.

In server_python_scripts/blocks_base_classes/mechanism.py, added code for events.

Updated src/modules/ json files to set editable = false in the non-deletable mrc_class_method_def blocks. This prevents the user from disabling these blocks.
…ms for each mechanism that has been added to the robot. Currently the subcategories don't have any blocks in them, but there is a TODO to add blocks for each method define in the mechanism.
… blocks to look at all components that are in scope. If the current module is a mechanism then the components of the mechanism are in scope.
@lizlooney lizlooney requested a review from alan412 August 3, 2025 19:17
Copy link
Collaborator

@alan412 alan412 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One thing we will need that I didn't notice (but I sped through this) is the ability to have uploaded mechanisms (ones not created in this project) as options for adding to the robot. That should be a TODO for later, but I don't want us to forget about it.

@alan412 alan412 merged commit 485a6a7 into wpilibsuite:main Aug 5, 2025
1 check passed
@lizlooney lizlooney deleted the pr_mechanisms_1 branch August 6, 2025 01:08
lizlooney added a commit to lizlooney/systemcore-blocks-interface that referenced this pull request Aug 31, 2025
I forgot to update the json in PR wpilibsuite#187.
@lizlooney lizlooney mentioned this pull request Aug 31, 2025
alan412 pushed a commit that referenced this pull request Aug 31, 2025
I forgot to update the json in PR #187.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants