forked from xiangechen/chili3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
806d09d
commit 7078e07
Showing
9 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
}, | ||
"lint-staged": { | ||
"*": [ | ||
"prettier --write ." | ||
"prettier --write" | ||
] | ||
}, | ||
"workspaces": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.