Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import * as editor from './editor/editor';
import { extendedPythonGenerator } from './editor/extended_python_generator';

import * as commonStorage from './storage/common_storage';
import * as storageModule from './storage/module';
import * as clientSideStorage from './storage/client_side_storage';

import * as CustomBlocks from './blocks/setup_custom_blocks';
Expand Down Expand Up @@ -154,7 +155,7 @@ const AppContent: React.FC<AppContentProps> = ({ project, setProject }): React.J
const { settings, updateLanguage, updateTheme, storage, isLoading } = useUserSettings();

const [alertErrorMessage, setAlertErrorMessage] = React.useState('');
const [currentModule, setCurrentModule] = React.useState<commonStorage.Module | null>(null);
const [currentModule, setCurrentModule] = React.useState<storageModule.Module | null>(null);
const [messageApi, contextHolder] = Antd.message.useMessage();
const [generatedCode, setGeneratedCode] = React.useState<string>('');
const [toolboxSettingsModalIsOpen, setToolboxSettingsModalIsOpen] = React.useState(false);
Expand Down Expand Up @@ -340,7 +341,7 @@ const AppContent: React.FC<AppContentProps> = ({ project, setProject }): React.J
};

/** Changes current module with automatic saving if modified. */
const changeModule = async (module: commonStorage.Module | null): Promise<void> => {
const changeModule = async (module: storageModule.Module | null): Promise<void> => {
if (currentModule && areBlocksModified()) {
await saveBlocks();
}
Expand Down
19 changes: 10 additions & 9 deletions src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
import { MRC_STYLE_FUNCTIONS } from '../themes/styles'
import * as toolboxItems from '../toolbox/items';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';


// A block to call a python function.
Expand Down Expand Up @@ -552,7 +553,7 @@ const CALL_PYTHON_FUNCTION = {
let foundComponent = false;
const componentsInScope: commonStorage.Component[] = [];
componentsInScope.push(...this.getComponentsFromRobot());
if (editor.getCurrentModuleType() === commonStorage.MODULE_TYPE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
componentsInScope.push(...editor.getComponentsFromWorkspace());
}
for (const component of componentsInScope) {
Expand Down Expand Up @@ -599,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() === commonStorage.MODULE_TYPE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
warnings.push('This block is not allowed to be used inside a mechanism.');
} else {
let foundRobotMethod = false;
Expand Down Expand Up @@ -645,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() === commonStorage.MODULE_TYPE_MECHANISM) {
if (editor.getCurrentModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
warnings.push('This block is not allowed to be used inside a mechanism.');
} else {
let foundMechanism = false;
Expand Down Expand Up @@ -790,11 +791,11 @@ export const pythonFromBlock = function(
: block.getFieldValue(FIELD_FUNCTION_NAME);
// Generate the correct code depending on the module type.
switch (generator.getModuleType()) {
case commonStorage.MODULE_TYPE_ROBOT:
case commonStorage.MODULE_TYPE_MECHANISM:
case storageModule.MODULE_TYPE_ROBOT:
case storageModule.MODULE_TYPE_MECHANISM:
code = 'self.';
break;
case commonStorage.MODULE_TYPE_OPMODE:
case storageModule.MODULE_TYPE_OPMODE:
code = 'self.robot.';
break;
}
Expand All @@ -815,13 +816,13 @@ export const pythonFromBlock = function(
: block.getFieldValue(FIELD_FUNCTION_NAME);
// Generate the correct code depending on the module type.
switch (generator.getModuleType()) {
case commonStorage.MODULE_TYPE_ROBOT:
case storageModule.MODULE_TYPE_ROBOT:
code = 'self.' + mechanismName;
break;
case commonStorage.MODULE_TYPE_OPMODE:
case storageModule.MODULE_TYPE_OPMODE:
code = 'self.robot.' + mechanismName;
break;
case commonStorage.MODULE_TYPE_MECHANISM:
case storageModule.MODULE_TYPE_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
3 changes: 2 additions & 1 deletion src/blocks/mrc_class_method_def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createFieldFlydown } from '../fields/field_flydown';
import { Order } from 'blockly/python';
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';
import { renameMethodCallers, mutateMethodCallers } from './mrc_call_python_function'
import * as toolboxItems from '../toolbox/items';
import { getClassData } from './utils/python';
Expand Down Expand Up @@ -424,7 +425,7 @@ export const pythonFromBlock = function (

let params = block.mrcParameters;
let paramString = "self";
if (generator.getModuleType() == commonStorage.MODULE_TYPE_MECHANISM && block.mrcPythonMethodName == '__init__') {
if (generator.getModuleType() == storageModule.MODULE_TYPE_MECHANISM && block.mrcPythonMethodName == '__init__') {
const ports: string[] = generator.getComponentPortParameters();
if (ports.length) {
paramString += ', ' + ports.join(', ');
Expand Down
7 changes: 4 additions & 3 deletions src/blocks/mrc_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import { getAllowedTypesForSetCheck, getClassData, getModuleData, getSubclassNames } from './utils/python';
import * as toolboxItems from '../toolbox/items';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';
import * as storageNames from '../storage/names';
import { createPortShadow } from './mrc_port';
import { createNumberShadowValue } from './utils/value';
Expand Down Expand Up @@ -125,7 +126,7 @@ const COMPONENT = {
*/
updateBlock_: function (this: ComponentBlock): void {
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace);
if (editor && editor.getCurrentModuleType() === commonStorage.MODULE_TYPE_ROBOT) {
if (editor && editor.getCurrentModuleType() === storageModule.MODULE_TYPE_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 @@ -194,7 +195,7 @@ export const pythonFromBlock = function (
if (i != 0) {
code += ', ';
}
if (generator.getModuleType() === commonStorage.MODULE_TYPE_ROBOT) {
if (generator.getModuleType() === storageModule.MODULE_TYPE_ROBOT) {
code += block.mrcArgs[i].name + ' = ' + generator.valueToCode(block, 'ARG' + i, Order.NONE);
} else {
code += block.mrcArgs[i].name + ' = ' + block.getArgName(i);
Expand Down Expand Up @@ -247,7 +248,7 @@ function createComponentBlock(
'name': argData.name,
'type': argData.type,
});
if (moduleType == commonStorage.MODULE_TYPE_ROBOT) {
if (moduleType == storageModule.MODULE_TYPE_ROBOT) {
if (argData.type === 'int') {
const portType = getPortTypeForArgument(argData.name);
if (portType) {
Expand Down
5 changes: 3 additions & 2 deletions src/blocks/mrc_mechanism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import { getAllowedTypesForSetCheck } from './utils/python';
import * as toolboxItems from '../toolbox/items';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';
import * as storageNames from '../storage/names';
import * as value from './utils/value';
import { renameMethodCallers } from './mrc_call_python_function'
Expand Down Expand Up @@ -172,7 +173,7 @@ const MECHANISM = {
// each module JSON file so we can track mechanisms, etc, even if the name changes.
// Then here, we'd look for the mechanism with the marching UUID, and we'd update the
// FIELD_TYPE value if the mechanism's class name had changed.
let foundMechanism: commonStorage.Mechanism | null = null;
let foundMechanism: storageModule.Mechanism | null = null;
const components: commonStorage.Component[] = []
for (const mechanism of editor.getMechanisms()) {
if (mechanism.className === this.getFieldValue(FIELD_TYPE)) {
Expand Down Expand Up @@ -246,7 +247,7 @@ export const pythonFromBlock = function (
}

export function createMechanismBlock(
mechanism: commonStorage.Mechanism, components: commonStorage.Component[]): toolboxItems.Block {
mechanism: storageModule.Mechanism, components: commonStorage.Component[]): toolboxItems.Block {
const snakeCaseName = storageNames.pascalCaseToSnakeCase(mechanism.className);
const mechanismName = 'my_' + snakeCaseName;
const extraState: MechanismExtraState = {
Expand Down
5 changes: 3 additions & 2 deletions src/blocks/mrc_mechanism_component_holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as ChangeFramework from './utils/change_framework';
import { getLegalName } from './utils/python';
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';
import { BLOCK_NAME as MRC_MECHANISM_NAME } from './mrc_mechanism';
import { OUTPUT_NAME as MECHANISM_OUTPUT } from './mrc_mechanism';
import { MechanismBlock } from './mrc_mechanism';
Expand Down Expand Up @@ -251,10 +252,10 @@ export const pythonFromBlock = function (
block: MechanismComponentHolderBlock,
generator: ExtendedPythonGenerator) {
switch (generator.getModuleType()) {
case commonStorage.MODULE_TYPE_ROBOT:
case storageModule.MODULE_TYPE_ROBOT:
pythonFromBlockInRobot(block, generator);
break;
case commonStorage.MODULE_TYPE_MECHANISM:
case storageModule.MODULE_TYPE_MECHANISM:
pythonFromBlockInMechanism(block, generator);
break;
}
Expand Down
39 changes: 20 additions & 19 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Blockly from 'blockly/core';
import { extendedPythonGenerator } from './extended_python_generator';
import { GeneratorContext } from './generator_context';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';
import * as storageNames from '../storage/names';
import * as eventHandler from '../blocks/mrc_event_handler';
import * as classMethodDef from '../blocks/mrc_class_method_def';
Expand All @@ -46,7 +47,7 @@ export class Editor {
private blocklyWorkspace: Blockly.WorkspaceSvg;
private generatorContext: GeneratorContext;
private storage: commonStorage.Storage;
private currentModule: commonStorage.Module | null = null;
private currentModule: storageModule.Module | null = null;
private currentProject: commonStorage.Project | null = null;
private modulePath: string = '';
private robotPath: string = '';
Expand Down Expand Up @@ -120,7 +121,7 @@ export class Editor {
}

public async loadModuleBlocks(
currentModule: commonStorage.Module | null,
currentModule: storageModule.Module | null,
currentProject: commonStorage.Project | null) {
this.generatorContext.setModule(currentModule);
this.currentModule = currentModule;
Expand Down Expand Up @@ -233,7 +234,7 @@ export class Editor {
if (this.currentModule) {
return this.currentModule.moduleType;
}
return commonStorage.MODULE_TYPE_UNKNOWN;
return storageModule.MODULE_TYPE_UNKNOWN;
}

private getModuleContentText(): string {
Expand All @@ -249,8 +250,8 @@ export class Editor {
const components: commonStorage.Component[] = this.getComponentsFromWorkspace();
const events: commonStorage.Event[] = this.getEventsFromWorkspace();
const methods: commonStorage.Method[] = (
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM)
this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === storageModule.MODULE_TYPE_MECHANISM)
? this.getMethodsForOutsideFromWorkspace()
: [];
return commonStorage.makeModuleContentText(
Expand All @@ -259,16 +260,16 @@ export class Editor {

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

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

public getEventsFromWorkspace(): commonStorage.Event[] {
const events: commonStorage.Event[] = [];
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === storageModule.MODULE_TYPE_MECHANISM) {
mechanismComponentHolder.getEvents(this.blocklyWorkspace, events);
}
return events;
Expand All @@ -322,7 +323,7 @@ export class Editor {
* Returns the mechanisms defined in the robot.
*/
public getMechanismsFromRobot(): commonStorage.MechanismInRobot[] {
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
return this.getMechanismsFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -335,7 +336,7 @@ export class Editor {
* Returns the components defined in the robot.
*/
public getComponentsFromRobot(): commonStorage.Component[] {
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
return this.getComponentsFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -348,7 +349,7 @@ export class Editor {
* Returns the events defined in the robot.
*/
public getEventsFromRobot(): commonStorage.Event[] {
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
return this.getEventsFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -361,7 +362,7 @@ export class Editor {
* Returns the methods defined in the robot.
*/
public getMethodsFromRobot(): commonStorage.Method[] {
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT) {
if (this.currentModule?.moduleType === storageModule.MODULE_TYPE_ROBOT) {
return this.getMethodsForWithinFromWorkspace();
}
if (this.robotContent) {
Expand All @@ -373,14 +374,14 @@ export class Editor {
/**
* Returns the mechanisms in this project.
*/
public getMechanisms(): commonStorage.Mechanism[] {
public getMechanisms(): storageModule.Mechanism[] {
return this.currentProject ? this.currentProject.mechanisms : [];
}

/**
* Returns the Mechanism matching the given MechanismInRobot.
*/
public getMechanism(mechanismInRobot: commonStorage.MechanismInRobot): commonStorage.Mechanism | null {
public getMechanism(mechanismInRobot: commonStorage.MechanismInRobot): storageModule.Mechanism | null {
if (this.currentProject) {
for (const mechanism of this.currentProject.mechanisms) {
const fullClassName = storageNames.pascalCaseToSnakeCase(mechanism.className) + '.' + mechanism.className;
Expand All @@ -395,7 +396,7 @@ export class Editor {
/**
* Returns the components defined in the given mechanism.
*/
public getComponentsFromMechanism(mechanism: commonStorage.Mechanism): commonStorage.Component[] {
public getComponentsFromMechanism(mechanism: storageModule.Mechanism): commonStorage.Component[] {
if (this.currentModule?.modulePath === mechanism.modulePath) {
return this.getComponentsFromWorkspace();
}
Expand All @@ -408,7 +409,7 @@ export class Editor {
/**
* Returns the events defined in the given mechanism.
*/
public getEventsFromMechanism(mechanism: commonStorage.Mechanism): commonStorage.Event[] {
public getEventsFromMechanism(mechanism: storageModule.Mechanism): commonStorage.Event[] {
if (this.currentModule?.modulePath === mechanism.modulePath) {
return this.getEventsFromWorkspace();
}
Expand All @@ -421,7 +422,7 @@ export class Editor {
/**
* Returns the methods defined in the given mechanism.
*/
public getMethodsFromMechanism(mechanism: commonStorage.Mechanism): commonStorage.Method[] {
public getMethodsFromMechanism(mechanism: storageModule.Mechanism): commonStorage.Method[] {
if (this.currentModule?.modulePath === mechanism.modulePath) {
return this.getMethodsForWithinFromWorkspace();
}
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 @@ -29,7 +29,7 @@ import {
CLASS_NAME_OPMODE,
getClassData,
} from '../blocks/utils/python';
import * as commonStorage from '../storage/common_storage';
import * as storageModule from '../storage/module';

export class OpModeDetails {
constructor(private name: string, private group : string, private enabled : boolean, private type : string) {}
Expand Down Expand Up @@ -112,7 +112,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {
generateInitStatements() : string {
let initStatements = '';

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

this.hasAnyComponents = false;
this.componentPorts = Object.create(null);
if (this.getModuleType() === commonStorage.MODULE_TYPE_MECHANISM) {
if (this.getModuleType() === storageModule.MODULE_TYPE_MECHANISM) {
this.hasAnyComponents = mechanismContainerHolder.hasAnyComponents(this.workspace);
mechanismContainerHolder.getComponentPorts(this.workspace, this.componentPorts);
}
Expand Down
Loading