File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -219,11 +219,10 @@ export const pythonFromBlock = function (
219219 block : MechanismComponentHolderBlock ,
220220 generator : ExtendedPythonGenerator ,
221221) {
222- generator . setHasHardware ( ) ;
223222 let code = 'def define_hardware(self):\n' ;
224223
225224 let body = '' ;
226- for ( let i = 1 ; i <= this . mrcNumMechanismInputs ; i ++ ) {
225+ for ( let i = 1 ; i <= block . mrcNumMechanismInputs ; i ++ ) {
227226 const name = 'MECHANISM_' + i ;
228227 if ( block . getInput ( name ) ) {
229228 let mechanismCode = generator . valueToCode ( block , name , Order . NONE ) || '' ;
@@ -232,7 +231,7 @@ export const pythonFromBlock = function (
232231 }
233232 }
234233 }
235- for ( let i = 1 ; i <= this . mrcNumComponentInputs ; i ++ ) {
234+ for ( let i = 1 ; i <= block . mrcNumComponentInputs ; i ++ ) {
236235 const name = 'COMPONENT_' + i ;
237236 if ( block . getInput ( name ) ) {
238237 let componentCode = generator . valueToCode ( block , name , Order . NONE ) || '' ;
Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ import * as Blockly from 'blockly/core';
2323import { PythonGenerator } from 'blockly/python' ;
2424import { GeneratorContext } from './generator_context' ;
2525import { Block } from '../toolbox/items' ;
26- import { CallPythonFunctionBlock , FunctionArg } from '../blocks/mrc_call_python_function' ;
26+ import { FunctionArg } from '../blocks/mrc_call_python_function' ;
27+ import * as MechanismContainerHolder from '../blocks/mrc_mechanism_component_holder' ;
2728import * as commonStorage from '../storage/common_storage' ;
2829
2930// Extends the python generator to collect some information about functions and
@@ -82,6 +83,10 @@ export class ExtendedPythonGenerator extends PythonGenerator {
8283 this . context = context ;
8384 this . context . clear ( ) ;
8485
86+ if ( this . workspace . getBlocksByType ( MechanismContainerHolder . BLOCK_NAME ) . length > 0 ) {
87+ this . setHasHardware ( ) ;
88+ }
89+
8590 const code = super . workspaceToCode ( workspace ) ;
8691
8792 this . workspace = workspace ;
You can’t perform that action at this time.
0 commit comments