Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ const CALL_PYTHON_FUNCTION = {
let foundComponent = false;
const componentsInScope: storageModuleContent.Component[] = [];
componentsInScope.push(...this.getComponentsFromRobot());
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.ModuleType.MECHANISM) {
componentsInScope.push(...editor.getComponentsFromWorkspace());
}
for (const component of componentsInScope) {
Expand Down Expand Up @@ -600,7 +600,7 @@ const CALL_PYTHON_FUNCTION = {
// If the robot method has changed, update the block if possible or put a
// visible warning on it.
if (this.mrcFunctionKind === FunctionKind.INSTANCE_ROBOT) {
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.ModuleType.MECHANISM) {
warnings.push('This block is not allowed to be used inside a mechanism.');
} else {
let foundRobotMethod = false;
Expand Down Expand Up @@ -646,7 +646,7 @@ const CALL_PYTHON_FUNCTION = {
// If the method has changed, update the block if possible or put a
// visible warning on it.
if (this.mrcFunctionKind === FunctionKind.INSTANCE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.ModuleType.MECHANISM) {
warnings.push('This block is not allowed to be used inside a mechanism.');
} else {
let foundMechanism = false;
Expand Down Expand Up @@ -805,11 +805,11 @@ export function pythonFromBlock(
: block.getFieldValue(FIELD_FUNCTION_NAME);
// Generate the correct code depending on the module type.
switch (generator.getModuleType()) {
case storageModule.MODULE_TYPE_ROBOT:
case storageModule.MODULE_TYPE_MECHANISM:
case storageModule.ModuleType.ROBOT:
case storageModule.ModuleType.MECHANISM:
code = 'self.';
break;
case storageModule.MODULE_TYPE_OPMODE:
case storageModule.ModuleType.OPMODE:
code = 'self.robot.';
break;
}
Expand All @@ -830,13 +830,13 @@ export function pythonFromBlock(
: block.getFieldValue(FIELD_FUNCTION_NAME);
// Generate the correct code depending on the module type.
switch (generator.getModuleType()) {
case storageModule.MODULE_TYPE_ROBOT:
case storageModule.ModuleType.ROBOT:
code = 'self.' + mechanismName;
break;
case storageModule.MODULE_TYPE_OPMODE:
case storageModule.ModuleType.OPMODE:
code = 'self.robot.' + mechanismName;
break;
case storageModule.MODULE_TYPE_MECHANISM:
case storageModule.ModuleType.MECHANISM:
// The INSTANCE_MECHANISM version should not be used in a mechanism.
// TODO(lizlooney): What if the user copies a block from an robot or opmode and pastes
// it into a mechanism?
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/mrc_class_method_def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export const pythonFromBlock = function (
// After executing the function body, revisit this block for the return.
xfix2 = xfix1;
}
if (block.mrcPythonMethodName == '__init__') {
if (block.mrcPythonMethodName === '__init__') {
let class_specific = generator.getClassSpecificForInit();
branch = generator.INDENT + 'super().__init__(' + class_specific + ')\n' +
generator.generateInitStatements() + branch;
Expand All @@ -440,7 +440,7 @@ export const pythonFromBlock = function (

let params = block.mrcParameters;
let paramString = "self";
if (generator.getModuleType() == storageModule.MODULE_TYPE_MECHANISM && block.mrcPythonMethodName == '__init__') {
if (generator.getModuleType() === storageModule.ModuleType.MECHANISM && block.mrcPythonMethodName === '__init__') {
const ports: string[] = generator.getComponentPortParameters();
if (ports.length) {
paramString += ', ' + ports.join(', ');
Expand Down
14 changes: 9 additions & 5 deletions src/blocks/mrc_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const COMPONENT = {
*/
updateBlock_: function (this: ComponentBlock): void {
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace);
if (editor && editor.getCurrentModuleType() === storageModule.MODULE_TYPE_ROBOT) {
if (editor && editor.getCurrentModuleType() === storageModule.ModuleType.ROBOT) {
// Add input sockets for the arguments.
for (let i = 0; i < this.mrcArgs.length; i++) {
const input = this.appendValueInput('ARG' + i)
Expand Down Expand Up @@ -207,7 +207,7 @@ export const pythonFromBlock = function (
if (i != 0) {
code += ', ';
}
if (generator.getModuleType() === storageModule.MODULE_TYPE_ROBOT) {
if (generator.getModuleType() === storageModule.ModuleType.ROBOT) {
code += block.mrcArgs[i].name + ' = ' + generator.valueToCode(block, 'ARG' + i, Order.NONE);
} else {
code += block.mrcArgs[i].name + ' = ' + block.getArgName(i);
Expand All @@ -217,7 +217,8 @@ export const pythonFromBlock = function (
return code;
}

export function getAllPossibleComponents(moduleType: string): toolboxItems.ContentsType[] {
export function getAllPossibleComponents(
moduleType: storageModule.ModuleType): toolboxItems.ContentsType[] {
const contents: toolboxItems.ContentsType[] = [];
// Iterate through all the components subclasses and add definition blocks.
const componentTypes = getSubclassNames('component.Component');
Expand All @@ -244,7 +245,10 @@ export function getAllPossibleComponents(moduleType: string): toolboxItems.Conte
}

function createComponentBlock(
componentName: string, classData: ClassData, staticFunctionData: FunctionData, moduleType: string): toolboxItems.Block {
componentName: string,
classData: ClassData,
staticFunctionData: FunctionData,
moduleType: storageModule.ModuleType): toolboxItems.Block {
const extraState: ComponentExtraState = {
importModule: classData.moduleName,
staticFunctionName: staticFunctionData.functionName,
Expand All @@ -260,7 +264,7 @@ function createComponentBlock(
'name': argData.name,
'type': argData.type,
});
if (moduleType == storageModule.MODULE_TYPE_ROBOT) {
if (moduleType == storageModule.ModuleType.ROBOT) {
if (argData.type === 'int') {
const portType = getPortTypeForArgument(argData.name);
if (portType) {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/mrc_event_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ function generateRegisterEventHandler(
fullSender = 'self.' + sender;
} else if (block.mrcSenderType === SenderType.MECHANISM) {
switch (generator.getModuleType()) {
case storageModule.MODULE_TYPE_ROBOT:
case storageModule.ModuleType.ROBOT:
fullSender = 'self.' + sender;
break;
case storageModule.MODULE_TYPE_OPMODE:
case storageModule.ModuleType.OPMODE:
fullSender = 'self.robot.' + sender;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/mrc_mechanism_component_holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ export const pythonFromBlock = function (
block: MechanismComponentHolderBlock,
generator: ExtendedPythonGenerator) {
switch (generator.getModuleType()) {
case storageModule.MODULE_TYPE_ROBOT:
case storageModule.ModuleType.ROBOT:
pythonFromBlockInRobot(block, generator);
break;
case storageModule.MODULE_TYPE_MECHANISM:
case storageModule.ModuleType.MECHANISM:
pythonFromBlockInMechanism(block, generator);
break;
}
Expand Down
26 changes: 13 additions & 13 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ export class Editor {
return this.blocklyWorkspace;
}

public getCurrentModuleType(): string {
public getCurrentModuleType(): storageModule.ModuleType | null {
if (this.currentModule) {
return this.currentModule.moduleType;
}
return storageModule.MODULE_TYPE_UNKNOWN;
return null;
}

private getModuleContentText(): string {
Expand All @@ -248,8 +248,8 @@ export class Editor {
const components: storageModuleContent.Component[] = this.getComponentsFromWorkspace();
const events: storageModuleContent.Event[] = this.getEventsFromWorkspace();
const methods: storageModuleContent.Method[] = (
this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === storageModule.MODULE_TYPE_MECHANISM)
this.currentModule?.moduleType === storageModule.ModuleType.ROBOT ||
this.currentModule?.moduleType === storageModule.ModuleType.MECHANISM)
? this.getMethodsForOutsideFromWorkspace()
: [];
return storageModuleContent.makeModuleContentText(
Expand All @@ -258,16 +258,16 @@ export class Editor {

public getMechanismsFromWorkspace(): storageModuleContent.MechanismInRobot[] {
const mechanisms: storageModuleContent.MechanismInRobot[] = [];
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT) {
mechanismComponentHolder.getMechanisms(this.blocklyWorkspace, mechanisms);
}
return mechanisms;
}

public getComponentsFromWorkspace(): storageModuleContent.Component[] {
const components: storageModuleContent.Component[] = [];
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === storageModule.MODULE_TYPE_MECHANISM) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT ||
this.currentModule?.moduleType === storageModule.ModuleType.MECHANISM) {
mechanismComponentHolder.getComponents(this.blocklyWorkspace, components);
}
return components;
Expand All @@ -294,8 +294,8 @@ export class Editor {

public getEventsFromWorkspace(): storageModuleContent.Event[] {
const events: storageModuleContent.Event[] = [];
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === storageModule.MODULE_TYPE_MECHANISM) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT ||
this.currentModule?.moduleType === storageModule.ModuleType.MECHANISM) {
mechanismComponentHolder.getEvents(this.blocklyWorkspace, events);
}
return events;
Expand Down Expand Up @@ -329,7 +329,7 @@ export class Editor {
* Returns the mechanisms defined in the robot.
*/
public getMechanismsFromRobot(): storageModuleContent.MechanismInRobot[] {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT) {
return this.getMechanismsFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -342,7 +342,7 @@ export class Editor {
* Returns the components defined in the robot.
*/
public getComponentsFromRobot(): storageModuleContent.Component[] {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT) {
return this.getComponentsFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -355,7 +355,7 @@ export class Editor {
* Returns the events defined in the robot.
*/
public getEventsFromRobot(): storageModuleContent.Event[] {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT) {
return this.getEventsFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -368,7 +368,7 @@ export class Editor {
* Returns the methods defined in the robot.
*/
public getMethodsFromRobot(): storageModuleContent.Method[] {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.ModuleType.ROBOT) {
return this.getMethodsForWithinFromWorkspace();
}
if (this.robotContent) {
Expand Down
6 changes: 3 additions & 3 deletions src/editor/extended_python_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {
generateInitStatements() : string {
let initStatements = '';

if (this.getModuleType() === storageModule.MODULE_TYPE_MECHANISM && this.hasAnyComponents) {
if (this.getModuleType() === storageModule.ModuleType.MECHANISM && this.hasAnyComponents) {
initStatements += this.INDENT + 'self.define_hardware(' +
this.getComponentPortParameters().join(', ') + ')\n';
}
Expand All @@ -134,7 +134,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {

this.hasAnyComponents = false;
this.componentPorts = Object.create(null);
if (this.getModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
if (this.getModuleType() === storageModule.ModuleType.MECHANISM) {
this.hasAnyComponents = mechanismContainerHolder.hasAnyComponents(this.workspace);
mechanismContainerHolder.getComponentPorts(this.workspace, this.componentPorts);
}
Expand All @@ -147,7 +147,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {
return code;
}

getModuleType(): string | null {
getModuleType(): storageModule.ModuleType | null {
if (this.context) {
return this.context.getModuleType();
}
Expand Down
17 changes: 8 additions & 9 deletions src/editor/generator_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GeneratorContext {
this.module = module;
}

getModuleType(): string | null {
getModuleType(): storageModule.ModuleType | null {
if (this.module) {
return this.module.moduleType;
}
Expand All @@ -52,14 +52,13 @@ export class GeneratorContext {
if (!this.module) {
throw new Error('getParentClassName: this.module is null.');
}
if (this.module.moduleType === storageModule.MODULE_TYPE_ROBOT) {
return CLASS_NAME_ROBOT_BASE;
}
if (this.module.moduleType === storageModule.MODULE_TYPE_OPMODE) {
return CLASS_NAME_OPMODE;
}
if (this.module.moduleType === storageModule.MODULE_TYPE_MECHANISM) {
return CLASS_NAME_MECHANISM;
switch (this.module.moduleType) {
case storageModule.ModuleType.ROBOT:
return CLASS_NAME_ROBOT_BASE;
case storageModule.ModuleType.OPMODE:
return CLASS_NAME_OPMODE;
case storageModule.ModuleType.MECHANISM:
return CLASS_NAME_MECHANISM;
}
return '';
}
Expand Down
8 changes: 4 additions & 4 deletions src/reactComponents/AddTabDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ export default function AddTabDialog(props: AddTabDialogProps) {
return;
}

const storageType = tabType === TabType.MECHANISM ?
storageModule.MODULE_TYPE_MECHANISM :
storageModule.MODULE_TYPE_OPMODE;
const moduleType = (tabType === TabType.MECHANISM)
? storageModule.ModuleType.MECHANISM
: storageModule.ModuleType.OPMODE;

await storageProject.addModuleToProject(
props.storage, props.project, storageType, newClassName);
props.storage, props.project, moduleType, newClassName);

const newModule = storageProject.findModuleByClassName(props.project, newClassName);
if (newModule) {
Expand Down
Loading