Skip to content

Commit

Permalink
Add command icons
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Jan 10, 2023
1 parent 806d09d commit 7078e07
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"lint-staged": {
"*": [
"prettier --write ."
"prettier --write"
]
},
"workspaces": [
Expand Down
4 changes: 4 additions & 0 deletions packages/chili-shared/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export class Commands {
LastCommand = "LastCommand";
NewGroup = "NewGroup";
Line = "Line";
PLine = "PLine";
Circle = "Circle";
Rect = "Rect";
Box = "Box";
Delete = "Delete";
Undo = "Undo";
Redo = "Redo";
Expand Down
33 changes: 33 additions & 0 deletions packages/chili/src/commands/create/box.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. MPL-2.0 license.

import { command, ICommand, Id, IDocument, LineBody, Model, Dimension, Snapper } from "chili-core";
import { IEdgeFactory } from "chili-geo";
import { inject, injectable, Token, XYZ } from "chili-shared";

@injectable()
@command({
name: "Box",
display: "command.line",
icon: "icon-box",
})
export class Box implements ICommand {
constructor(@inject(Token.EdgeFactory) private factory: IEdgeFactory) {}

async excute(document: IDocument): Promise<boolean> {
let snap = new Snapper(document);
let start = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickStart");
if (start === undefined) return false;
let end = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickEnd", start, (p) =>
this.handleTempLine(start!, p)
);
if (end === undefined) return false;
document.addModel(new Model(document, `Line ${document.modelCount + 1}`, Id.new(), new LineBody(start, end)));
document.viewer.redraw();
return true;
}

private handleTempLine = (start: XYZ, end: XYZ) => {
if (start.isEqualTo(end)) return undefined;
return this.factory.byStartAndEnd(start, end).ok();
};
}
33 changes: 33 additions & 0 deletions packages/chili/src/commands/create/circle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. MPL-2.0 license.

import { command, ICommand, Id, IDocument, LineBody, Model, Dimension, Snapper } from "chili-core";
import { IEdgeFactory } from "chili-geo";
import { inject, injectable, Token, XYZ } from "chili-shared";

@injectable()
@command({
name: "Circle",
display: "command.line",
icon: "icon-circle",
})
export class Circle implements ICommand {
constructor(@inject(Token.EdgeFactory) private factory: IEdgeFactory) {}

async excute(document: IDocument): Promise<boolean> {
let snap = new Snapper(document);
let start = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickStart");
if (start === undefined) return false;
let end = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickEnd", start, (p) =>
this.handleTempLine(start!, p)
);
if (end === undefined) return false;
document.addModel(new Model(document, `Line ${document.modelCount + 1}`, Id.new(), new LineBody(start, end)));
document.viewer.redraw();
return true;
}

private handleTempLine = (start: XYZ, end: XYZ) => {
if (start.isEqualTo(end)) return undefined;
return this.factory.byStartAndEnd(start, end).ok();
};
}
4 changes: 4 additions & 0 deletions packages/chili/src/commands/create/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. MPL-2.0 license.

export * from "./box";
export * from "./circle";
export * from "./group";
export * from "./line";
export * from "./pline";
export * from "./rect";
33 changes: 33 additions & 0 deletions packages/chili/src/commands/create/pline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. MPL-2.0 license.

import { command, ICommand, Id, IDocument, LineBody, Model, Dimension, Snapper } from "chili-core";
import { IEdgeFactory } from "chili-geo";
import { inject, injectable, Token, XYZ } from "chili-shared";

@injectable()
@command({
name: "PLine",
display: "command.line",
icon: "icon-pline",
})
export class PLine implements ICommand {
constructor(@inject(Token.EdgeFactory) private factory: IEdgeFactory) {}

async excute(document: IDocument): Promise<boolean> {
let snap = new Snapper(document);
let start = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickStart");
if (start === undefined) return false;
let end = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickEnd", start, (p) =>
this.handleTempLine(start!, p)
);
if (end === undefined) return false;
document.addModel(new Model(document, `Line ${document.modelCount + 1}`, Id.new(), new LineBody(start, end)));
document.viewer.redraw();
return true;
}

private handleTempLine = (start: XYZ, end: XYZ) => {
if (start.isEqualTo(end)) return undefined;
return this.factory.byStartAndEnd(start, end).ok();
};
}
33 changes: 33 additions & 0 deletions packages/chili/src/commands/create/rect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. MPL-2.0 license.

import { command, ICommand, Id, IDocument, LineBody, Model, Dimension, Snapper } from "chili-core";
import { IEdgeFactory } from "chili-geo";
import { inject, injectable, Token, XYZ } from "chili-shared";

@injectable()
@command({
name: "Rect",
display: "command.line",
icon: "icon-rect",
})
export class Rect implements ICommand {
constructor(@inject(Token.EdgeFactory) private factory: IEdgeFactory) {}

async excute(document: IDocument): Promise<boolean> {
let snap = new Snapper(document);
let start = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickStart");
if (start === undefined) return false;
let end = await snap.snapPointAsync(Dimension.D1D2D3, "command.line.pickEnd", start, (p) =>
this.handleTempLine(start!, p)
);
if (end === undefined) return false;
document.addModel(new Model(document, `Line ${document.modelCount + 1}`, Id.new(), new LineBody(start, end)));
document.viewer.redraw();
return true;
}

private handleTempLine = (start: XYZ, end: XYZ) => {
if (start.isEqualTo(end)) return undefined;
return this.factory.byStartAndEnd(start, end).ok();
};
}
2 changes: 1 addition & 1 deletion packages/chili/src/ribbon.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"groups": [
{
"groupName": "ui.ribbon.group.drawing",
"items": ["Line", "Circle", ["Line", "Circle"]]
"items": ["Line", "PLine", "Circle", "Box", ["Rect", "Circle"]]
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion public/iconfont.js

Large diffs are not rendered by default.

0 comments on commit 7078e07

Please sign in to comment.