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
1 change: 1 addition & 0 deletions packages/chili-builder/src/ribbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const DefaultRibbon: RibbonTab[] = [
"create.cone",
"create.sphere",
"create.thickSolid",
"create.pipe",
],
},
],
Expand Down
10 changes: 10 additions & 0 deletions packages/chili-core/src/command/decarator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ export class CommandUtils {
static getCommond(name: CommandKeys): CommandConstructor | undefined {
return commandRegistry.get(name);
}

static getAllCommands(): CommandData[] {
const commands: CommandData[] = [];
for (const ctor of commandRegistry.values()) {
if (ctor.prototype.data) {
commands.push(ctor.prototype.data);
}
}
return commands;
}
}
2 changes: 2 additions & 0 deletions packages/chili-core/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
export * from "./command";
export * from "./commandKeys";
export * from "./decarator";

export * from "./shortcutProfiles";
77 changes: 77 additions & 0 deletions packages/chili-core/src/command/shortcutProfiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { Navigation3DType } from "../navigation";
import type { CommandKeys } from "./commandKeys";

type ShortcutMap = Partial<Record<CommandKeys, string | string[]>>;

export const Chili3dShortcuts: ShortcutMap = {
// System
"doc.save": "ctrl+s",
"doc.open": "ctrl+o",
"edit.undo": "ctrl+z",
"edit.redo": ["ctrl+y", "ctrl+shift+z"],
"modify.deleteNode": ["Delete", "Backspace"],
"special.last": [" ", "Enter"],

// Sketching
"create.line": "l",
"create.rect": "r",
"create.circle": "c",
"measure.length": "d",

// Primitives
"create.box": "b",
"create.pyramid": "p",
"create.sphere": "s",
"create.cylinder": "y",
"create.cone": "n",
"create.pipe": "shift+p",

// Modify
"modify.trim": "t",
"create.offset": "o",
"modify.rotate": "shift+r",
"create.extrude": "shift+e",
"modify.move": "shift+m",
"modify.array": "shift+a",
"boolean.common": "shift+i",
"modify.explode": "shift+x",
"modify.chamfer": "shift+c",
"modify.fillet": "shift+f",
};

export const DefaultShortcuts: ShortcutMap = Chili3dShortcuts;

export const RevitShortcuts: ShortcutMap = {
...Chili3dShortcuts,
"modify.move": "m+v", // MV
"modify.rotate": "r+o", // RO
"modify.trim": "t+r", // TR
"create.line": "l+i", // LI
// Add more as needed
};

export const BlenderShortcuts: ShortcutMap = {
...DefaultShortcuts,
"modify.move": "g",
"modify.rotate": "r",
"create.extrude": "e",
// "delete": "x" // if key exists
};

export const SolidworksShortcuts: ShortcutMap = {
...DefaultShortcuts,
"create.line": "l",
// Often heavily mouse/gesture based or S-key menu
};

export const CreoShortcuts: ShortcutMap = {
...DefaultShortcuts,
};

export const ShortcutProfiles: Record<Navigation3DType, ShortcutMap> = {
Chili3d: Chili3dShortcuts,
Revit: RevitShortcuts,
Blender: BlenderShortcuts,
Creo: CreoShortcuts,
Solidworks: SolidworksShortcuts,
};
4 changes: 4 additions & 0 deletions packages/chili-core/src/i18n/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const I18N_KEYS = [
"body.line",
"body.multiShape",
"body.polygon",
"body.pipe",
"body.prism",
"body.rect",
"body.revol",
Expand Down Expand Up @@ -67,6 +68,7 @@ const I18N_KEYS = [
"command.create.line",
"command.create.loft",
"command.create.offset",
"command.create.pipe",
"command.create.polygon",
"command.create.pyramid",
"command.create.rect",
Expand Down Expand Up @@ -194,6 +196,8 @@ const I18N_KEYS = [
"option.command.isConvertInstance",
"option.command.insertPoint",
"polygon.points",
"pipe.bendRadius",
"pipe.bendType",
"prompt.default{0}{1}",
"prompt.deleteDocument{0}",
"prompt.polygon.close",
Expand Down
4 changes: 4 additions & 0 deletions packages/chili-i18n/src/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export default {
"command.create.line": "Line",
"command.create.loft": "Loft",
"command.create.offset": "Offset",
"body.pipe": "Pipe",
"command.create.pipe": "Pipe",
"command.create.polygon": "Pline",
"command.create.pyramid": "Pyramid",
"command.create.rect": "Rectangle",
Expand Down Expand Up @@ -195,6 +197,8 @@ export default {
"option.command.isConvertInstance": "Convert Instance",
"option.command.insertPoint": "Insert Point",
"polygon.points": "Points",
"pipe.bendRadius": "Bend Radius",
"pipe.bendType": "Bend Type",
"prompt.default{0}{1}":
"{0} to pan the view, {1} to rotate the view, Mouse wheel to scroll the zoom view",
"prompt.deleteDocument{0}": "Do you want to delete {0}?",
Expand Down
1 change: 1 addition & 0 deletions packages/chili-i18n/src/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default {
"command.create.folder": "Criar Pasta",
"command.create.group": "Agrupar",
"command.create.line": "Linha",
"command.create.pipe": "Tubo",
"command.create.offset": "Deslocar",
"command.create.polygon": "Polilinha",
"command.create.pyramid": "Piramide",
Expand Down
4 changes: 4 additions & 0 deletions packages/chili-i18n/src/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default {
"body.imported": "导入的模型",
"body.line": "直线",
"body.polygon": "多段线",
"body.pipe": "管状体",
"body.prism": "拉伸",
"body.rect": "矩形",
"body.revol": "旋转",
Expand Down Expand Up @@ -72,6 +73,7 @@ export default {
"command.create.line": "直线",
"command.create.loft": "放样",
"command.create.offset": "偏移",
"command.create.pipe": "管状体",
"command.create.polygon": "多段线",
"command.create.pyramid": "棱锥",
"command.create.rect": "矩形",
Expand Down Expand Up @@ -195,6 +197,8 @@ export default {
"option.command.isConvertInstance": "转为实例",
"option.command.insertPoint": "插入点",
"polygon.points": "点",
"pipe.bendRadius": "弯管半径",
"pipe.bendType": "弯管类型",
"prompt.default{0}{1}": "{0} 平移视图,{1} 旋转视图,滚轮缩放视图",
"prompt.deleteDocument{0}": "是否删除 {0} ?",
"prompt.pickCircleCenter": "请选择圆心 按 ESC 键取消",
Expand Down
45 changes: 40 additions & 5 deletions packages/chili-ui/src/ribbon/ribbonButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type CommandData,
type CommandKeys,
CommandUtils,
DefaultShortcuts,
I18n,
type I18nKeys,
type IConverter,
Expand All @@ -18,14 +19,17 @@ import {
import style from "./ribbonButton.module.css";

export class RibbonButton extends HTMLElement {
private observer?: MutationObserver;

constructor(
display: I18nKeys,
icon: string,
size: ButtonSize,
readonly onClick: () => void,
shortcut?: string,
) {
super();
this.initHTML(display, icon, size);
this.initHTML(display, icon, size, shortcut);
this.addEventListener("click", onClick);
}

Expand All @@ -38,24 +42,55 @@ export class RibbonButton extends HTMLElement {
if (data.toggle) {
return new RibbonToggleButton(data, size);
}
return new RibbonButton(`command.${data.key}`, data.icon, size, () => {
PubSub.default.pub("executeCommand", commandName);
});

const shortcutData = DefaultShortcuts[commandName];
const shortcut = Array.isArray(shortcutData) ? shortcutData[0] : shortcutData;

return new RibbonButton(
`command.${data.key}`,
data.icon,
size,
() => {
PubSub.default.pub("executeCommand", commandName);
},
shortcut,
);
}

dispose(): void {
this.removeEventListener("click", this.onClick);
this.observer?.disconnect();
}

private initHTML(display: I18nKeys, icon: string, size: ButtonSize) {
private initHTML(display: I18nKeys, icon: string, size: ButtonSize, shortcut?: string) {
const image = svg({ icon });
this.className = size === ButtonSize.large ? style.normal : style.small;
image.classList.add(size === ButtonSize.large ? style.icon : style.smallIcon);
const text = label({
className: size === ButtonSize.large ? style.largeButtonText : style.smallButtonText,
textContent: new Localize(display),
});

I18n.set(this, "title", display);

if (shortcut) {
const updateTitle = () => {
const current = this.getAttribute("title");
if (current && !current.includes(`(${shortcut})`)) {
this.setAttribute("title", `${current} (${shortcut})`);
}
};
updateTitle();
this.observer = new MutationObserver((mutations) => {
for (const m of mutations) {
if (m.type === "attributes" && m.attributeName === "title") {
updateTitle();
}
}
});
this.observer.observe(this, { attributes: true });
}

this.append(image, text);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/chili/src/bodys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./cone";
export * from "./cylinder";
export * from "./ellipse";
export * from "./line";
export * from "./pipe";
export * from "./polygon";
export * from "./prism";
export * from "./pyramid";
Expand Down
Loading