@@ -1142,6 +1142,34 @@ export function getInstanceComponentBlocks(
11421142 return contents ;
11431143}
11441144
1145+ export function getInstanceMechanismComponentBlocks (
1146+ component : storageModuleContent . Component , mechanismInRobot : storageModuleContent . MechanismInRobot ) : toolboxItems . ContentsType [ ] {
1147+ const contents : toolboxItems . ContentsType [ ] = [ ] ;
1148+
1149+ const classData = getClassData ( component . className ) ;
1150+ if ( ! classData ) {
1151+ throw new Error ( 'Could not find classData for ' + component . className ) ;
1152+ }
1153+ const functions = classData . instanceMethods ;
1154+
1155+ const componentClassData = getClassData ( 'component.Component' ) ;
1156+ if ( ! componentClassData ) {
1157+ throw new Error ( 'Could not find classData for component.Component' ) ;
1158+ }
1159+ const componentFunctions = componentClassData . instanceMethods ;
1160+
1161+ for ( const functionData of functions ) {
1162+ // Skip the functions that are also defined in componentFunctions.
1163+ if ( findSuperFunctionData ( functionData , componentFunctions ) ) {
1164+ continue ;
1165+ }
1166+ const block = createInstanceMechanismComponentBlock ( component , functionData , mechanismInRobot ) ;
1167+ contents . push ( block ) ;
1168+ }
1169+
1170+ return contents ;
1171+ }
1172+
11451173function createInstanceComponentBlock (
11461174 component : storageModuleContent . Component , functionData : FunctionData ) : toolboxItems . Block {
11471175 const extraState : CallPythonFunctionExtraState = {
@@ -1166,6 +1194,32 @@ function createInstanceComponentBlock(
11661194 return createBlock ( extraState , fields , inputs ) ;
11671195}
11681196
1197+ function createInstanceMechanismComponentBlock (
1198+ component : storageModuleContent . Component ,
1199+ functionData : FunctionData ,
1200+ mechanismInRobot : storageModuleContent . MechanismInRobot ) : toolboxItems . Block {
1201+ const extraState : CallPythonFunctionExtraState = {
1202+ functionKind : FunctionKind . INSTANCE_COMPONENT ,
1203+ returnType : functionData . returnType ,
1204+ args : [ ] ,
1205+ tooltip : functionData . tooltip ,
1206+ importModule : '' ,
1207+ componentClassName : component . className ,
1208+ componentName : mechanismInRobot . name + '.' + component . name , // Prefix with mechanism name
1209+ componentId : component . componentId ,
1210+ } ;
1211+ const fields : { [ key : string ] : any } = { } ;
1212+ fields [ FIELD_COMPONENT_NAME ] = mechanismInRobot . name + '.' + component . name ; // Prefix with mechanism name
1213+ fields [ FIELD_FUNCTION_NAME ] = functionData . functionName ;
1214+ const inputs : { [ key : string ] : any } = { } ;
1215+ // For INSTANCE_COMPONENT functions, the 0 argument is 'self', but
1216+ // self is represented by the FIELD_COMPONENT_NAME field.
1217+ // We don't include the arg for the self argument because we don't need a socket for it.
1218+ const argsWithoutSelf = functionData . args . slice ( 1 ) ;
1219+ processArgs ( argsWithoutSelf , extraState , inputs ) ;
1220+ return createBlock ( extraState , fields , inputs ) ;
1221+ }
1222+
11691223export function addInstanceRobotBlocks (
11701224 methods : storageModuleContent . Method [ ] ,
11711225 contents : toolboxItems . ContentsType [ ] ) {
0 commit comments