@@ -140,10 +140,13 @@ const COMPONENT = {
140140 getComponent : function ( this : ComponentBlock ) : commonStorage . Component | null {
141141 const componentName = this . getFieldValue ( FIELD_NAME ) ;
142142 const componentType = this . getFieldValue ( FIELD_TYPE ) ;
143+ const ports : { [ port : string ] : string } = { } ;
144+ this . getComponentPorts ( ports ) ;
143145 return {
144146 blockId : this . id ,
145147 name : componentName ,
146148 className : componentType ,
149+ ports : ports ,
147150 } ;
148151 } ,
149152 getNewPort : function ( this : ComponentBlock , i : number ) : string {
@@ -153,14 +156,12 @@ const COMPONENT = {
153156 }
154157 return this . getFieldValue ( FIELD_NAME ) + extension + '_port' ;
155158 } ,
156- getHardwarePorts : function ( this : ComponentBlock , ports : { [ key : string ] : string } ) : void {
157- // Collect the hardware ports for this component block that are needed to generate
158- // the define_hardware method. (The key is the port, the value is the type.)
159- if ( this . hideParams ) {
160- for ( let i = 0 ; i < this . mrcArgs . length ; i ++ ) {
161- const newPort = this . getNewPort ( i ) ;
162- ports [ newPort ] = this . mrcArgs [ i ] . type ;
163- }
159+ getComponentPorts : function ( this : ComponentBlock , ports : { [ key : string ] : string } ) : void {
160+ // Collect the ports for this component block.
161+ for ( let i = 0 ; i < this . mrcArgs . length ; i ++ ) {
162+ const newPort = this . getNewPort ( i ) ;
163+ // The key is the port, the value is the type.
164+ ports [ newPort ] = this . mrcArgs [ i ] . type ;
164165 }
165166 } ,
166167}
@@ -197,7 +198,7 @@ export const pythonFromBlock = function (
197198 return code ;
198199}
199200
200- export function getAllPossibleComponents ( hideParams : boolean ) : toolboxItems . ContentsType [ ] {
201+ export function getAllPossibleComponents ( moduleType : string ) : toolboxItems . ContentsType [ ] {
201202 const contents : toolboxItems . ContentsType [ ] = [ ] ;
202203 // Iterate through all the components subclasses and add definition blocks.
203204 const componentTypes = getSubclassNames ( 'component.Component' ) ;
@@ -215,7 +216,7 @@ export function getAllPossibleComponents(hideParams: boolean): toolboxItems.Cont
215216
216217 classData . staticMethods . forEach ( staticFunctionData => {
217218 if ( staticFunctionData . returnType === componentType ) {
218- contents . push ( createComponentBlock ( componentName , classData , staticFunctionData , hideParams ) ) ;
219+ contents . push ( createComponentBlock ( componentName , classData , staticFunctionData , moduleType ) ) ;
219220 }
220221 } ) ;
221222 } ) ;
@@ -224,12 +225,12 @@ export function getAllPossibleComponents(hideParams: boolean): toolboxItems.Cont
224225}
225226
226227function createComponentBlock (
227- componentName : string , classData : ClassData , staticFunctionData : FunctionData , hideParams : boolean ) : toolboxItems . Block {
228+ componentName : string , classData : ClassData , staticFunctionData : FunctionData , moduleType : string ) : toolboxItems . Block {
228229 const extraState : ComponentExtraState = {
229230 importModule : classData . moduleName ,
230231 staticFunctionName : staticFunctionData . functionName ,
231232 params : [ ] ,
232- hideParams : hideParams ,
233+ hideParams : ( moduleType == commonStorage . MODULE_TYPE_MECHANISM ) ,
233234 } ;
234235 const fields : { [ key : string ] : any } = { } ;
235236 fields [ FIELD_NAME ] = componentName ;
@@ -241,7 +242,7 @@ function createComponentBlock(
241242 'name' : argData . name ,
242243 'type' : argData . type ,
243244 } ) ;
244- if ( ! hideParams ) {
245+ if ( moduleType == commonStorage . MODULE_TYPE_ROBOT ) {
245246 if ( argData . type === 'int' ) {
246247 const portType = getPortTypeForArgument ( argData . name ) ;
247248 if ( portType ) {
0 commit comments