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
23 changes: 14 additions & 9 deletions src/blocks/mrc_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import * as ToolboxItems from '../toolbox/items';
import * as CommonStorage from '../storage/common_storage';
import { createPortShadow } from './mrc_port';
import { createNumberShadowValue } from './utils/value';
import { ClassData, FunctionData } from './utils/python_json_types';


export const BLOCK_NAME = 'mrc_component';
export const OUTPUT_NAME = 'mrc_component';
Expand Down Expand Up @@ -177,6 +179,7 @@ export function getAllPossibleComponents(hideParams: boolean): ToolboxItems.Cont
const contents: ToolboxItems.ContentsType[] = [];
// Iterate through all the components subclasses and add definition blocks.
const componentTypes = getSubclassNames('component.Component');

componentTypes.forEach(componentType => {
const classData = getClassData(componentType);
if (!classData) {
Expand Down Expand Up @@ -212,7 +215,7 @@ function createComponentBlock(
const inputs: {[key: string]: any} = {};
for (let i = 0; i < staticFunctionData.args.length; i++) {
const argData = staticFunctionData.args[i];
extraState.params.push({
extraState.params!.push({
'name': argData.name,
'type': argData.type,
});
Expand All @@ -233,14 +236,16 @@ function createComponentBlock(
function getPortTypeForArgument(argName: string): string | null {
const argNameLower = argName.toLowerCase();
const moduleData = getModuleData('component');
for (const enumData of moduleData.enums) {
if (enumData.enumClassName === 'component.PortType') {
for (const value of enumData.enumValues) {
if (argNameLower === value.toLowerCase()) {
return value;
}
}
break;
if (moduleData) {
for (const enumData of moduleData.enums) {
if (enumData.enumClassName === 'component.PortType') {
for (const value of enumData.enumValues) {
if (argNameLower === value.toLowerCase()) {
return value;
}
}
break;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/mrc_get_parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {ExtendedPythonGenerator} from '../editor/extended_python_generator';
import {createFieldNonEditableText} from '../fields/FieldNonEditableText';
import {MRC_STYLE_VARIABLES} from '../themes/styles';
import {BLOCK_NAME as MRC_CLASS_METHOD_DEF, ClassMethodDefBlock} from './mrc_class_method_def';
import {BLOCK_NAME as MRC_EVENT_HANDLER, EventHandlerBlock} from './mrc_event_handler';
import {BLOCK_NAME as MRC_EVENT_HANDLER } from './mrc_event_handler';
import * as ChangeFramework from './utils/change_framework';


Expand Down
2 changes: 1 addition & 1 deletion src/blocks/mrc_port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const pythonFromBlock = function (
return [code, Order.ATOMIC];
}

export function createPortShadow(portType: string, portNum: int) {
export function createPortShadow(portType: string, portNum: Number) {
return {
shadow: {
type: 'mrc_port',
Expand Down
6 changes: 3 additions & 3 deletions src/blocks/utils/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author [email protected] (Liz Looney)
*/

import { ClassData, PythonData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types';
import { ClassData, PythonData, ModuleData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types';
import { robotPyData } from './robotpy_data';
import { externalSamplesData } from './external_samples_data';

Expand Down Expand Up @@ -157,15 +157,15 @@ export function getAlias(type: string): string | null {
// Returns the list of subclass names for the given type.
// For example, if type is 'wpilib.drive.RobotDriveBase', this function will
// return ['wpilib.drive.DifferentialDrive', 'wpilib.drive.MecanumDrive'].
export function getSubclassNames(type: string): string[] | null {
export function getSubclassNames(type: string): string[] {
for (const pythonData of allPythonData) {
for (const className in pythonData.subclasses) {
if (type === className) {
return pythonData.subclasses[className];
}
}
}
return null;
return [];
}

// Returns the array of allowed types for the given string.
Expand Down
27 changes: 14 additions & 13 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import { GeneratorContext } from './generator_context';
import * as commonStorage from '../storage/common_storage';
import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder';
//import { testAllBlocksInToolbox } from '../toolbox/toolbox_tests';
import { MethodsCategory} from '../toolbox/methods_category';
import { EventsCategory} from '../toolbox/event_category';
import { MethodsCategory } from '../toolbox/methods_category';
import { EventsCategory } from '../toolbox/event_category';
import { getToolboxJSON } from '../toolbox/toolbox';

const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
kind: 'categoryToolbox',
contents: [],
kind: 'categoryToolbox',
contents: [],
};

export class Editor {
private static workspaceIdToEditor: {[key: string]: Editor} = {};
private static workspaceIdToEditor: { [key: string]: Editor } = {};

private blocklyWorkspace: Blockly.WorkspaceSvg;
private generatorContext: GeneratorContext;
Expand Down Expand Up @@ -136,14 +136,14 @@ export class Editor {
if (currentModule) {
// Fetch the content for the current module and the robot.
// TODO: Also fetch the content for the mechanisms?
const promises: {[key: string]: Promise<string>} = {}; // key is module path, value is promise of module content.
const promises: { [key: string]: Promise<string> } = {}; // key is module path, value is promise of module content.
promises[this.modulePath] = this.storage.fetchModuleContent(this.modulePath);
if (this.robotPath !== this.modulePath) {
// Also fetch the robot module content. It contains components, etc, that can be used.
promises[this.robotPath] = this.storage.fetchModuleContent(this.robotPath)
}

const moduleContents: {[key: string]: string} = {}; // key is module path, value is module content
const moduleContents: { [key: string]: string } = {}; // key is module path, value is module content
await Promise.all(
Object.entries(promises).map(async ([modulePath, promise]) => {
moduleContents[modulePath] = await promise;
Expand Down Expand Up @@ -173,7 +173,7 @@ export class Editor {
if (toolbox != this.toolbox) {
this.toolbox = toolbox;
this.blocklyWorkspace.updateToolbox(toolbox);
// testAllBlocksInToolbox(toolbox);
// testAllBlocksInToolbox(toolbox);
}
}

Expand Down Expand Up @@ -220,23 +220,24 @@ export class Editor {
throw new Error('getModuleContent: this.currentModule is null.');
}
const pythonCode = extendedPythonGenerator.mrcWorkspaceToCode(
this.blocklyWorkspace, this.generatorContext);
this.blocklyWorkspace, this.generatorContext);
const exportedBlocks = JSON.stringify(this.generatorContext.getExportedBlocks());
const blocksContent = JSON.stringify(
Blockly.serialization.workspaces.save(this.blocklyWorkspace));
Blockly.serialization.workspaces.save(this.blocklyWorkspace));
const componentsContent = JSON.stringify(this.getComponents());
return commonStorage.makeModuleContent(
this.currentModule, pythonCode, blocksContent, exportedBlocks, componentsContent);
this.currentModule, pythonCode, blocksContent, exportedBlocks, componentsContent);
}

private getComponents(): commonStorage.Component[] {
const components: commonStorage.Component[] = [];
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT ||
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) {
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) {
// Get the holder block and ask it for the components.
const holderBlocks = this.blocklyWorkspace.getBlocksByType(mechanismComponentHolder.BLOCK_NAME);
holderBlocks.forEach(holderBlock => {
const componentsFromHolder: commonStorage.Component[] = holderBlock.getComponents();
const componentsFromHolder: commonStorage.Component[] =
(holderBlock as mechanismComponentHolder.MechanismComponentHolderBlock).getComponents();
componentsFromHolder.forEach(component => {
components.push(component);
});
Expand Down
3 changes: 0 additions & 3 deletions src/reactComponents/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import * as Antd from 'antd';
import * as commonStorage from '../storage/common_storage';
import * as I18Next from 'react-i18next';
import {
RobotOutlined,
CodeOutlined,
BlockOutlined,
CloseOutlined,
DeleteOutlined,
CopyOutlined,
Expand Down
1 change: 0 additions & 1 deletion src/reactComponents/ThemeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const ThemeModal: React.FC<ThemeModalProps> = ({
setSelectedTheme(currentTheme);
onClose();
};
const { token } = Antd.theme.useToken();

return (
<Antd.Modal
Expand Down
2 changes: 1 addition & 1 deletion src/toolbox/hardware_category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function getComponentsBlocks(currentModule: commonStorage.Module, hideParams : b

holderBlocks.forEach(holderBlock => {
const componentsFromHolder: commonStorage.Component[] =
(holderBlock as mechanismComponentHolder.MechanismComponentHolderBlock).getComponents();
(holderBlock as MechanismComponentHolder.MechanismComponentHolderBlock).getComponents();
componentsFromHolder.forEach(component => {
// Get the blocks for this specific component
contents.push({
Expand Down