@@ -85,7 +85,6 @@ interface CallPythonFunctionMixin extends CallPythonFunctionMixinType {
8585 mrcComponentClassName : string ,
8686 mrcOriginalComponentName : string ,
8787 mrcMechanismClassName : string ,
88- mrcComponentNames : string [ ] ,
8988 mrcMapComponentNameToId : { [ componentName : string ] : string } ,
9089}
9190type CallPythonFunctionMixinType = typeof CALL_PYTHON_FUNCTION ;
@@ -318,8 +317,7 @@ const CALL_PYTHON_FUNCTION = {
318317 this . mrcMechanismId = extraState . mechanismId ? extraState . mechanismId : '' ;
319318 this . mrcComponentClassName = extraState . componentClassName ? extraState . componentClassName : '' ;
320319 this . mrcMechanismClassName = extraState . mechanismClassName ? extraState . mechanismClassName : '' ;
321- // Initialize mrcComponentNames and mrcMapComponentNameToId here. They will be filled during mrcOnLoad.
322- this . mrcComponentNames = [ ] ;
320+ // Initialize mrcMapComponentNameToId here. It will be filled during mrcOnLoad.
323321 this . mrcMapComponentNameToId = { } ;
324322 this . updateBlock_ ( ) ;
325323 } ,
@@ -505,7 +503,7 @@ const CALL_PYTHON_FUNCTION = {
505503 methodOrEvent : storageModuleContent . Method | storageModuleContent . Event
506504 ) : void {
507505 // mutateMethodCaller is called when the method or event definition block in the same module is modified.
508- if ( this . mrcFunctionKind == FunctionKind . EVENT ) {
506+ if ( this . mrcFunctionKind === FunctionKind . EVENT ) {
509507 const event = methodOrEvent as storageModuleContent . Event ;
510508 this . mrcArgs = [ ] ;
511509 event . args . forEach ( ( arg ) => {
@@ -514,7 +512,7 @@ const CALL_PYTHON_FUNCTION = {
514512 type : arg . type ,
515513 } ) ;
516514 } ) ;
517- } else if ( this . mrcFunctionKind == FunctionKind . INSTANCE_WITHIN ) {
515+ } else if ( this . mrcFunctionKind === FunctionKind . INSTANCE_WITHIN ) {
518516 const method = methodOrEvent as storageModuleContent . Method ;
519517 this . mrcReturnType = method . returnType ;
520518 this . mrcArgs = [ ] ;
@@ -581,12 +579,14 @@ const CALL_PYTHON_FUNCTION = {
581579 // If the component belongs to a mechanism, also check whether the mechanism
582580 // still exists and whether it has been changed.
583581 if ( this . mrcFunctionKind === FunctionKind . INSTANCE_COMPONENT ) {
582+ const componentNames : string [ ] = [ ] ;
583+ this . mrcMapComponentNameToId = { }
584584 this . getComponents ( ) . forEach ( component => {
585- this . mrcComponentNames . push ( component . name ) ;
585+ componentNames . push ( component . name ) ;
586586 this . mrcMapComponentNameToId [ component . name ] = component . componentId ;
587587 } ) ;
588588 let foundComponent = false ;
589- for ( const componentName of this . mrcComponentNames ) {
589+ for ( const componentName of componentNames ) {
590590 const componentId = this . mrcMapComponentNameToId [ componentName ] ;
591591 if ( componentId === this . mrcComponentId ) {
592592 foundComponent = true ;
@@ -605,12 +605,12 @@ const CALL_PYTHON_FUNCTION = {
605605 break ;
606606 }
607607 }
608- if ( indexOfComponentNameField == - 1 ) {
608+ if ( indexOfComponentNameField === - 1 ) {
609609 throw new Error ( 'Could not find the component name field' ) ;
610610 }
611611 titleInput . removeField ( FIELD_COMPONENT_NAME ) ;
612612 titleInput . insertFieldAt ( indexOfComponentNameField ,
613- createFieldDropdown ( this . mrcComponentNames ) , FIELD_COMPONENT_NAME ) ;
613+ createFieldDropdown ( componentNames ) , FIELD_COMPONENT_NAME ) ;
614614 // TODO(lizlooney): If the current module is the robot or a mechanism, we need to update the
615615 // items in the dropdown if the user adds or removes a component.
616616
@@ -620,6 +620,39 @@ const CALL_PYTHON_FUNCTION = {
620620 break ;
621621 }
622622 }
623+ if ( ! foundComponent ) {
624+ if ( this . mrcMechanismId ) {
625+ // Check whether the the component still exists, but is a private component in the mechanism.
626+ for ( const mechanismInRobot of editor . getMechanismsFromRobot ( ) ) {
627+ if ( mechanismInRobot . mechanismId === this . mrcMechanismId ) {
628+ for ( const mechanism of editor . getMechanisms ( ) ) {
629+ if ( mechanism . moduleId === mechanismInRobot . moduleId ) {
630+ for ( const privateComponent of editor . getPrivateComponentsFromMechanism ( mechanism ) ) {
631+ if ( privateComponent . className === this . mrcComponentClassName &&
632+ privateComponent . componentId === this . mrcComponentId ) {
633+ foundComponent = true ;
634+ warnings . push (
635+ 'This blocks calls a method on a private component in the ' +
636+ mechanism . className + ' mechanism.'
637+ ) ;
638+ break
639+ }
640+ }
641+ break ;
642+ }
643+ if ( foundComponent ) {
644+ break ;
645+ }
646+ }
647+ break ;
648+ }
649+ if ( foundComponent ) {
650+ break ;
651+ }
652+ }
653+ }
654+ }
655+
623656 if ( ! foundComponent ) {
624657 warnings . push ( 'This block calls a method on a component that no longer exists.' ) ;
625658 }
0 commit comments