-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Showing
70 changed files
with
692 additions
and
505 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import {AnchorType} from "./AnchorType"; | ||
import {IPoint} from "../interfaces/IPoint"; | ||
import {Direction} from "./enums/Direction"; | ||
|
||
export interface RectAnchor { | ||
type: AnchorType, | ||
type: Direction, | ||
position: IPoint | ||
} |
File renamed without changes.
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
File renamed without changes.
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,4 @@ | ||
export enum AnchorType { | ||
export enum Direction { | ||
TOP = "TOP", | ||
BOTTOM = "BOTTOM", | ||
LEFT = "LEFT", | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/data/PointExportFormatData.ts → src/data/export/PointExportFormatData.ts
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
4 changes: 2 additions & 2 deletions
4
src/data/PolygonExportFormatData.ts → src/data/export/PolygonExportFormatData.ts
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/data/LabelToolkitData.ts → src/data/info/LabelToolkitData.ts
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
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,164 @@ | ||
import {LabelType} from "../../data/enums/LabelType"; | ||
import {EditorModel} from "../../model/EditorModel"; | ||
import {RectRenderEngine} from "../render/RectRenderEngine"; | ||
import {PointRenderEngine} from "../render/PointRenderEngine"; | ||
import {PolygonRenderEngine} from "../render/PolygonRenderEngine"; | ||
import {IRect} from "../../interfaces/IRect"; | ||
import {Settings} from "../../settings/Settings"; | ||
import {RectUtil} from "../../utils/RectUtil"; | ||
import {EditorData} from "../../data/EditorData"; | ||
import {CanvasUtil} from "../../utils/CanvasUtil"; | ||
import {ISize} from "../../interfaces/ISize"; | ||
import React from "react"; | ||
import {IPoint} from "../../interfaces/IPoint"; | ||
import {DrawUtil} from "../../utils/DrawUtil"; | ||
import {PrimaryEditorRenderEngine} from "../render/PrimaryEditorRenderEngine"; | ||
import {ContextManager} from "../context/ContextManager"; | ||
|
||
export class EditorActions { | ||
|
||
// ================================================================================================================= | ||
// RENDER ENGINES | ||
// ================================================================================================================= | ||
|
||
public static mountSupportRenderingEngine(activeLabelType: LabelType) { | ||
switch (activeLabelType) { | ||
case LabelType.RECTANGLE: | ||
EditorModel.supportRenderingEngine = new RectRenderEngine(EditorModel.canvas); | ||
break; | ||
case LabelType.POINT: | ||
EditorModel.supportRenderingEngine = new PointRenderEngine(EditorModel.canvas); | ||
break; | ||
case LabelType.POLYGON: | ||
EditorModel.supportRenderingEngine = new PolygonRenderEngine(EditorModel.canvas); | ||
break; | ||
default: | ||
EditorModel.supportRenderingEngine = null; | ||
break; | ||
} | ||
}; | ||
|
||
public static swapSupportRenderingEngine(activeLabelType: LabelType) { | ||
EditorActions.mountSupportRenderingEngine(activeLabelType); | ||
}; | ||
|
||
public static mountRenderEngines(activeLabelType: LabelType) { | ||
EditorModel.primaryRenderingEngine = new PrimaryEditorRenderEngine(EditorModel.canvas); | ||
EditorActions.mountSupportRenderingEngine(activeLabelType); | ||
} | ||
|
||
// ================================================================================================================= | ||
// RENDER | ||
// ================================================================================================================= | ||
|
||
public static fullRender() { | ||
DrawUtil.clearCanvas(EditorModel.canvas); | ||
EditorModel.primaryRenderingEngine.drawImage(EditorModel.image, EditorModel.imageRectOnCanvas); | ||
EditorModel.primaryRenderingEngine.render(EditorActions.getEditorData()); | ||
EditorModel.supportRenderingEngine && EditorModel.supportRenderingEngine.render(EditorActions.getEditorData()); | ||
} | ||
|
||
// ================================================================================================================= | ||
// SETTERS | ||
// ================================================================================================================= | ||
|
||
public static setLoadingStatus(status: boolean) { | ||
EditorModel.isLoading = status; | ||
} | ||
|
||
public static setActiveImage(image: HTMLImageElement) { | ||
EditorModel.image = image; | ||
} | ||
|
||
// ================================================================================================================= | ||
// GETTERS | ||
// ================================================================================================================= | ||
|
||
public static getImageRect(image: HTMLImageElement): IRect | null { | ||
if (!!image) { | ||
const canvasPaddingWidth: number = Settings.CANVAS_PADDING_WIDTH_PX; | ||
const imageRect: IRect = { x: 0, y: 0, width: image.width, height: image.height}; | ||
const canvasRect: IRect = { | ||
x: canvasPaddingWidth, | ||
y: canvasPaddingWidth, | ||
width: EditorModel.canvas.width - 2 * canvasPaddingWidth, | ||
height: EditorModel.canvas.height - 2 * canvasPaddingWidth | ||
}; | ||
return RectUtil.fitInsideRectWithRatio(canvasRect, RectUtil.getRatio(imageRect)); | ||
} | ||
return null; | ||
}; | ||
|
||
public static getImageScale(image: HTMLImageElement): number | null { | ||
if (!image || !EditorModel.imageRectOnCanvas) | ||
return null; | ||
|
||
return image.width / EditorModel.imageRectOnCanvas.width; | ||
} | ||
|
||
public static getEditorData(event?: Event): EditorData { | ||
return { | ||
mousePositionOnCanvas: EditorModel.mousePositionOnCanvas, | ||
canvasSize: CanvasUtil.getSize(EditorModel.canvas), | ||
activeImageScale: EditorModel.imageScale, | ||
activeImageRectOnCanvas: EditorModel.imageRectOnCanvas, | ||
activeKeyCombo: ContextManager.getActiveCombo(), | ||
event: event | ||
} | ||
} | ||
|
||
// ================================================================================================================= | ||
// HELPERS | ||
// ================================================================================================================= | ||
|
||
public static calculateActiveImageCharacteristics() { | ||
EditorModel.imageRectOnCanvas = EditorActions.getImageRect(EditorModel.image); | ||
EditorModel.imageScale = EditorActions.getImageScale(EditorModel.image); | ||
} | ||
|
||
public static resizeCanvas = (newCanvasSize: ISize) => { | ||
if (!!newCanvasSize && !!EditorModel.canvas) { | ||
EditorModel.canvas.width = newCanvasSize.width; | ||
EditorModel.canvas.height = newCanvasSize.height; | ||
} | ||
}; | ||
|
||
public static updateMousePositionIndicator(event: React.MouseEvent<HTMLCanvasElement, MouseEvent> | MouseEvent) { | ||
|
||
if (!EditorModel.imageRectOnCanvas || !EditorModel.canvas) { | ||
EditorModel.mousePositionIndicator.style.display = "none"; | ||
EditorModel.cursor.style.display = "none"; | ||
return; | ||
} | ||
|
||
const mousePositionOnCanvas: IPoint = CanvasUtil.getMousePositionOnCanvasFromEvent(event, EditorModel.canvas); | ||
const canvasRect: IRect = {x: 0, y: 0, ...CanvasUtil.getSize(EditorModel.canvas)}; | ||
const isOverCanvas: boolean = RectUtil.isPointInside(canvasRect, mousePositionOnCanvas); | ||
|
||
if (!isOverCanvas) { | ||
EditorModel.mousePositionIndicator.style.display = "none"; | ||
EditorModel.cursor.style.display = "none"; | ||
return; | ||
} | ||
|
||
const isOverImage: boolean = RectUtil.isPointInside(EditorModel.imageRectOnCanvas, mousePositionOnCanvas); | ||
|
||
if (isOverImage) { | ||
const scale = EditorModel.imageScale; | ||
const x: number = Math.round((mousePositionOnCanvas.x - EditorModel.imageRectOnCanvas.x) * scale); | ||
const y: number = Math.round((mousePositionOnCanvas.y - EditorModel.imageRectOnCanvas.y) * scale); | ||
const text: string = "x: " + x + ", y: " + y; | ||
|
||
EditorModel.mousePositionIndicator.innerHTML = text; | ||
EditorModel.mousePositionIndicator.style.left = (mousePositionOnCanvas.x + 15) + "px"; | ||
EditorModel.mousePositionIndicator.style.top = (mousePositionOnCanvas.y + 15) + "px"; | ||
EditorModel.mousePositionIndicator.style.display = "block"; | ||
} else { | ||
EditorModel.mousePositionIndicator.style.display = "none"; | ||
} | ||
|
||
EditorModel.cursor.style.left = mousePositionOnCanvas.x + "px"; | ||
EditorModel.cursor.style.top = mousePositionOnCanvas.y + "px"; | ||
EditorModel.cursor.style.display = "block"; | ||
}; | ||
} |
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,9 @@ | ||
import {HotKeyAction} from "../../data/HotKeyAction"; | ||
|
||
export class BaseContext { | ||
public static actions: HotKeyAction[] = []; | ||
|
||
public static getActions(): HotKeyAction[] { | ||
return this.actions; | ||
} | ||
} |
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,58 @@ | ||
import {HotKeyAction} from "../../data/HotKeyAction"; | ||
import {EditorModel} from "../../model/EditorModel"; | ||
import {LabelType} from "../../data/enums/LabelType"; | ||
import {EditorData} from "../../data/EditorData"; | ||
import {EditorActions} from "../actions/EditorActions"; | ||
import {PolygonRenderEngine} from "../render/PolygonRenderEngine"; | ||
import {EditorSelector} from "../../store/selectors/EditorSelector"; | ||
import {store} from "../../index"; | ||
import {updateActiveImageIndex} from "../../store/editor/actionCreators"; | ||
import {BaseContext} from "./BaseContext"; | ||
|
||
export class EditorContext extends BaseContext { | ||
public static actions: HotKeyAction[] = [ | ||
{ | ||
keyCombo: ["Enter"], | ||
action: (event: KeyboardEvent) => { | ||
if (EditorModel.supportRenderingEngine && EditorModel.supportRenderingEngine.labelType === LabelType.POLYGON) { | ||
const editorData: EditorData = EditorActions.getEditorData(); | ||
(EditorModel.supportRenderingEngine as PolygonRenderEngine).addLabelAndFinishCreation(editorData); | ||
} | ||
EditorActions.fullRender(); | ||
} | ||
}, | ||
{ | ||
keyCombo: ["Escape"], | ||
action: (event: KeyboardEvent) => { | ||
if (EditorModel.supportRenderingEngine && EditorModel.supportRenderingEngine.labelType === LabelType.POLYGON) | ||
(EditorModel.supportRenderingEngine as PolygonRenderEngine).cancelLabelCreation(); | ||
EditorActions.fullRender(); | ||
} | ||
}, | ||
{ | ||
keyCombo: ["ArrowLeft"], | ||
action: (event: KeyboardEvent) => { | ||
EditorContext.getPreviousImage(); | ||
} | ||
}, | ||
{ | ||
keyCombo: ["ArrowRight"], | ||
action: (event: KeyboardEvent) => { | ||
EditorContext.getNextImage(); | ||
} | ||
} | ||
]; | ||
|
||
private static getPreviousImage(): void { | ||
const currentImageIndex: number = EditorSelector.getActiveImageIndex(); | ||
const previousImageIndex: number = Math.max(0, currentImageIndex - 1); | ||
store.dispatch(updateActiveImageIndex(previousImageIndex)); | ||
} | ||
|
||
private static getNextImage(): void { | ||
const currentImageIndex: number = EditorSelector.getActiveImageIndex(); | ||
const imageCount: number = EditorSelector.getImagesData().length; | ||
const nextImageIndex: number = Math.min(imageCount - 1, currentImageIndex + 1); | ||
store.dispatch(updateActiveImageIndex(nextImageIndex)); | ||
} | ||
} |
Oops, something went wrong.