Skip to content

Commit 303cafc

Browse files
committed
Added reason parameter to mrcOnLoad methods.
In mrc_mechanism_component_holder.ts: Removed code that uses change framework. Replaced function setName with method MechanismComponentHolderBlock.setNameOfChildBlock. Replaced function updateToolboxAfterDelay with method MechanismComponentHolderBlock.updateToolboxAfterDelay. Added function mrcDescenantsMayHaveChanged, which calls method MechanismComponentHolderBlock.mrcDescenantsMayHaveChanged. MechanismComponentHolderBlock.mrcDescenantsMayHaveChanged collects the ids of mechanisms, components, private components, and events and if they have changed, calls updateToolboxAfterDelay. Updated mrc_mechanism, mrc_component, and mrc_event to call MechanismComponentHolderBlock.setNameOfChildBlock when they are connected to the holder. Update mrc_mechanism, mrc_component, and mrc_event to call mrcDescendantsMayHaveChanged when they are moved.
1 parent 395c1de commit 303cafc

File tree

7 files changed

+214
-60
lines changed

7 files changed

+214
-60
lines changed

src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import * as clientSideStorage from './storage/client_side_storage';
4545
import * as CustomBlocks from './blocks/setup_custom_blocks';
4646

4747
import { initialize as initializePythonBlocks } from './blocks/utils/python';
48-
import * as ChangeFramework from './blocks/utils/change_framework'
4948
import { registerToolboxButton } from './blocks/mrc_event_handler'
5049
import { mutatorOpenListener } from './blocks/mrc_param_container'
5150
import { TOOLBOX_UPDATE_EVENT } from './blocks/mrc_mechanism_component_holder';
@@ -487,7 +486,6 @@ const AppContent: React.FC<AppContentProps> = ({ project, setProject }): React.J
487486
return;
488487
}
489488

490-
ChangeFramework.setup(newWorkspace);
491489
newWorkspace.addChangeListener(mutatorOpenListener);
492490
newWorkspace.addChangeListener(handleBlocksChanged);
493491

src/blocks/mrc_component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import { getAllowedTypesForSetCheck, getClassData, getSubclassNames } from './ut
3030
import * as toolboxItems from '../toolbox/items';
3131
import * as storageModule from '../storage/module';
3232
import * as storageModuleContent from '../storage/module_content';
33-
import { BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER } from './mrc_mechanism_component_holder';
33+
import {
34+
BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER,
35+
MechanismComponentHolderBlock,
36+
mrcDescendantsMayHaveChanged } from './mrc_mechanism_component_holder';
3437
import { createPort } from './mrc_port';
3538
import { ClassData, FunctionData } from './utils/python_json_types';
3639
import { renameMethodCallers } from './mrc_call_python_function'
@@ -164,6 +167,9 @@ const COMPONENT = {
164167
}
165168
return legalName;
166169
},
170+
getComponentId: function (this: ComponentBlock): string {
171+
return this.mrcComponentId;
172+
},
167173
getComponent: function (this: ComponentBlock): storageModuleContent.Component | null {
168174
const componentName = this.getFieldValue(FIELD_NAME);
169175
const componentType = this.getFieldValue(FIELD_TYPE);
@@ -195,8 +201,15 @@ const COMPONENT = {
195201
/**
196202
* mrcOnMove is called when a ComponentBlock is moved.
197203
*/
198-
mrcOnMove: function(this: ComponentBlock): void {
204+
mrcOnMove: function(this: ComponentBlock, reason: string[]): void {
199205
this.checkBlockIsInHolder();
206+
if (reason.includes('connect')) {
207+
const rootBlock: Blockly.Block | null = this.getRootBlock();
208+
if (rootBlock && rootBlock.type === MRC_MECHANISM_COMPONENT_HOLDER) {
209+
(rootBlock as MechanismComponentHolderBlock).setNameOfChildBlock(this);
210+
}
211+
}
212+
mrcDescendantsMayHaveChanged(this.workspace);
200213
},
201214
checkBlockIsInHolder: function(this: ComponentBlock): void {
202215
const rootBlock: Blockly.Block | null = this.getRootBlock();

src/blocks/mrc_event.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { MRC_STYLE_EVENTS } from '../themes/styles'
2525
import { Parameter } from './mrc_class_method_def';
2626
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2727
import { MUTATOR_BLOCK_NAME, PARAM_CONTAINER_BLOCK_NAME, MethodMutatorArgBlock } from './mrc_param_container'
28-
import { BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER } from './mrc_mechanism_component_holder';
28+
import {
29+
BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER,
30+
MechanismComponentHolderBlock,
31+
mrcDescendantsMayHaveChanged } from './mrc_mechanism_component_holder';
2932
import * as toolboxItems from '../toolbox/items';
3033
import * as storageModuleContent from '../storage/module_content';
3134
import { renameMethodCallers, mutateMethodCallers } from './mrc_call_python_function'
@@ -211,8 +214,15 @@ const EVENT = {
211214
/**
212215
* mrcOnMove is called when an EventBlock is moved.
213216
*/
214-
mrcOnMove: function(this: EventBlock): void {
217+
mrcOnMove: function(this: EventBlock, reason: string[]): void {
215218
this.checkBlockIsInHolder();
219+
if (reason.includes('connect')) {
220+
const rootBlock: Blockly.Block | null = this.getRootBlock();
221+
if (rootBlock && rootBlock.type === MRC_MECHANISM_COMPONENT_HOLDER) {
222+
(rootBlock as MechanismComponentHolderBlock).setNameOfChildBlock(this);
223+
}
224+
}
225+
mrcDescendantsMayHaveChanged(this.workspace);
216226
},
217227
checkBlockIsInHolder: function(this: EventBlock): void {
218228
const rootBlock: Blockly.Block | null = this.getRootBlock();
@@ -234,6 +244,9 @@ const EVENT = {
234244
}
235245
}
236246
},
247+
getEventId: function (this: EventBlock): string {
248+
return this.mrcEventId;
249+
},
237250
getEvent: function (this: EventBlock): storageModuleContent.Event {
238251
const event: storageModuleContent.Event = {
239252
eventId: this.mrcEventId,

src/blocks/mrc_get_parameter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const GET_PARAMETER_BLOCK = {
8282
/**
8383
* mrcOnMove is called when an EventBlock is moved.
8484
*/
85-
mrcOnMove: function(this: GetParameterBlock): void {
85+
mrcOnMove: function(this: GetParameterBlock, _reason: string[]): void {
8686
this.checkBlockPlacement();
8787
},
8888
mrcOnAncestorMove: function(this: GetParameterBlock): void {
@@ -91,7 +91,7 @@ const GET_PARAMETER_BLOCK = {
9191
checkBlockPlacement: function(this: GetParameterBlock): void {
9292
const legalParameterNames: string[] = [];
9393

94-
const rootBlock: Blockly.Block = this.getRootBlock();
94+
const rootBlock: Blockly.Block | null = this.getRootBlock();
9595
if (rootBlock.type === MRC_CLASS_METHOD_DEF) {
9696
// This block is within a class method definition.
9797
const classMethodDefBlock = rootBlock as ClassMethodDefBlock;

src/blocks/mrc_mechanism.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import * as toolboxItems from '../toolbox/items';
3131
import * as storageModule from '../storage/module';
3232
import * as storageModuleContent from '../storage/module_content';
3333
import * as storageNames from '../storage/names';
34-
import { BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER } from './mrc_mechanism_component_holder';
34+
import {
35+
BLOCK_NAME as MRC_MECHANISM_COMPONENT_HOLDER,
36+
MechanismComponentHolderBlock,
37+
mrcDescendantsMayHaveChanged } from './mrc_mechanism_component_holder';
3538
import { renameMethodCallers } from './mrc_call_python_function'
3639
import { renameMechanismName as renameMechanismNameInEventHandlers } from './mrc_event_handler'
3740
import { createPort } from './mrc_port';
@@ -176,6 +179,9 @@ const MECHANISM = {
176179
}
177180
return legalName;
178181
},
182+
getMechanismId: function (this: MechanismBlock): string {
183+
return this.mrcMechanismId;
184+
},
179185
getMechanism: function (this: MechanismBlock): storageModuleContent.MechanismInRobot | null {
180186
const mechanismName = this.getFieldValue(FIELD_NAME);
181187
const mechanismType = this.mrcImportModule + '.' + this.getFieldValue(FIELD_TYPE);
@@ -204,8 +210,15 @@ const MECHANISM = {
204210
/**
205211
* mrcOnMove is called when a MechanismBlock is moved.
206212
*/
207-
mrcOnMove: function(this: MechanismBlock): void {
213+
mrcOnMove: function(this: MechanismBlock, reason: string[]): void {
208214
this.checkBlockIsInHolder();
215+
if (reason.includes('connect')) {
216+
const rootBlock: Blockly.Block | null = this.getRootBlock();
217+
if (rootBlock && rootBlock.type === MRC_MECHANISM_COMPONENT_HOLDER) {
218+
(rootBlock as MechanismComponentHolderBlock).setNameOfChildBlock(this);
219+
}
220+
}
221+
mrcDescendantsMayHaveChanged(this.workspace);
209222
},
210223
checkBlockIsInHolder: function(this: MechanismBlock): void {
211224
const rootBlock: Blockly.Block | null = this.getRootBlock();

0 commit comments

Comments
 (0)