-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop editing when n key pressed #7922
Changes from 6 commits
d338710
6b526cc
a9567e9
f5f907f
90a19a9
04ab539
4708548
99e7ed2
8a72123
2e09878
bcb9d79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Added | ||
|
||
- Polyline editing may be finished using corresponding shortcut | ||
(<https://github.com/cvat-ai/cvat/pull/7922>) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,8 +147,8 @@ export interface InteractionResult { | |
|
||
export interface PolyEditData { | ||
enabled: boolean; | ||
state: any; | ||
pointID: number; | ||
state?: any; | ||
pointID?: number; | ||
Comment on lines
+150
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor to avoid using - state?: any;
+ state?: StateType; // Define StateType appropriately based on the expected structure
|
||
} | ||
|
||
export interface MasksEditData { | ||
|
@@ -249,7 +249,7 @@ export interface CanvasModel { | |
readonly activeElement: ActiveElement; | ||
readonly highlightedElements: HighlightedElements; | ||
readonly drawData: DrawData; | ||
readonly editData: MasksEditData; | ||
readonly editData: MasksEditData | PolyEditData; | ||
readonly interactionData: InteractionData; | ||
readonly mergeData: MergeData; | ||
readonly splitData: SplitData; | ||
|
@@ -275,7 +275,7 @@ export interface CanvasModel { | |
grid(stepX: number, stepY: number): void; | ||
|
||
draw(drawData: DrawData): void; | ||
edit(editData: MasksEditData): void; | ||
edit(editData: MasksEditData | PolyEditData): void; | ||
group(groupData: GroupData): void; | ||
join(joinData: JoinData): void; | ||
slice(sliceData: SliceData): void; | ||
|
@@ -369,7 +369,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel { | |
fittedScale: number; | ||
zLayer: number | null; | ||
drawData: DrawData; | ||
editData: MasksEditData; | ||
editData: MasksEditData | PolyEditData; | ||
interactionData: InteractionData; | ||
mergeData: MergeData; | ||
groupData: GroupData; | ||
|
@@ -771,7 +771,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel { | |
this.notify(UpdateReasons.DRAW); | ||
} | ||
|
||
public edit(editData: MasksEditData): void { | ||
public edit(editData: MasksEditData | PolyEditData): void { | ||
if (![Mode.IDLE, Mode.EDIT].includes(this.data.mode)) { | ||
throw Error(`Canvas is busy. Action: ${this.data.mode}`); | ||
} | ||
|
@@ -1074,7 +1074,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel { | |
return { ...this.data.drawData }; | ||
} | ||
|
||
public get editData(): MasksEditData { | ||
public get editData(): MasksEditData | PolyEditData { | ||
return { ...this.data.editData }; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ export interface EditHandler { | |||||||||
transform(geometry: Geometry): void; | ||||||||||
configurate(configuration: Configuration): void; | ||||||||||
cancel(): void; | ||||||||||
enabled: boolean; | ||||||||||
} | ||||||||||
|
||||||||||
export class EditHandlerImpl implements EditHandler { | ||||||||||
|
@@ -31,9 +32,9 @@ export class EditHandlerImpl implements EditHandler { | |||||||||
private autobordersEnabled: boolean; | ||||||||||
private intelligentCutEnabled: boolean; | ||||||||||
private outlinedBorders: string; | ||||||||||
private isEditing: boolean; | ||||||||||
|
||||||||||
private setupTrailingPoint(circle: SVG.Circle): void { | ||||||||||
const head = this.editedShape.attr('points').split(' ').slice(0, this.editData.pointID).join(' '); | ||||||||||
circle.on('mouseenter', (): void => { | ||||||||||
circle.attr({ | ||||||||||
'stroke-width': consts.POINTS_SELECTED_STROKE_WIDTH / this.geometry.scale, | ||||||||||
|
@@ -46,22 +47,11 @@ export class EditHandlerImpl implements EditHandler { | |||||||||
}); | ||||||||||
}); | ||||||||||
|
||||||||||
const minimumPoints = 2; | ||||||||||
circle.on('mousedown', (e: MouseEvent): void => { | ||||||||||
if (e.button !== 0) return; | ||||||||||
const { offset } = this.geometry; | ||||||||||
const stringifiedPoints = `${head} ${this.editLine.node.getAttribute('points').slice(0, -2)}`; | ||||||||||
const points = pointsToNumberArray(stringifiedPoints) | ||||||||||
.slice(0, -2) | ||||||||||
.map((coord: number): number => coord - offset); | ||||||||||
|
||||||||||
if (points.length >= minimumPoints * 2) { | ||||||||||
const { state } = this.editData; | ||||||||||
this.edit({ | ||||||||||
enabled: false, | ||||||||||
}); | ||||||||||
this.onEditDone(state, points); | ||||||||||
} | ||||||||||
this.edit({ | ||||||||||
enabled: false, | ||||||||||
}); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
}); | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -380,6 +370,19 @@ export class EditHandlerImpl implements EditHandler { | |||||||||
} | ||||||||||
|
||||||||||
private closeEditing(): void { | ||||||||||
if (this.isEditing) { | ||||||||||
const { offset } = this.geometry; | ||||||||||
const head = this.editedShape.attr('points').split(' ').slice(0, this.editData.pointID).join(' '); | ||||||||||
const stringifiedPoints = `${head} ${this.editLine.node.getAttribute('points').slice(0, -2)}`; | ||||||||||
const points = pointsToNumberArray(stringifiedPoints) | ||||||||||
.slice(0, -2) | ||||||||||
.map((coord: number): number => coord - offset); | ||||||||||
if (points.length >= 2 * 2) { // minimumPoints * 2 | ||||||||||
const { state } = this.editData; | ||||||||||
this.onEditDone(state, points); | ||||||||||
} | ||||||||||
} | ||||||||||
this.isEditing = false; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Release method needs to be called whenever a polyline is edited, so i think it should be outside. As for the issue, I fixed it by cheking the shapeType of the editHandler and pass |
||||||||||
this.release(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we put these two lines under the condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the polygon editing was affected, i am thinking to add checktype for shape, something like this
` |
||||||||||
} | ||||||||||
|
||||||||||
|
@@ -400,12 +403,14 @@ export class EditHandlerImpl implements EditHandler { | |||||||||
this.editLine = null; | ||||||||||
this.geometry = null; | ||||||||||
this.clones = []; | ||||||||||
this.isEditing = false; | ||||||||||
} | ||||||||||
|
||||||||||
public edit(editData: any): void { | ||||||||||
if (editData.enabled) { | ||||||||||
if (editData.state.shapeType !== 'rectangle') { | ||||||||||
this.editData = editData; | ||||||||||
this.isEditing = true; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will suggest:
|
||||||||||
this.initEditing(); | ||||||||||
} else { | ||||||||||
this.cancel(); | ||||||||||
|
@@ -421,6 +426,10 @@ export class EditHandlerImpl implements EditHandler { | |||||||||
this.onEditDone(null, null); | ||||||||||
} | ||||||||||
|
||||||||||
get enabled(): boolean { | ||||||||||
return this.isEditing; | ||||||||||
} | ||||||||||
|
||||||||||
public configurate(configuration: Configuration): void { | ||||||||||
this.autobordersEnabled = configuration.autoborders; | ||||||||||
this.outlinedBorders = configuration.outlinedBorders || 'black'; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider specifying a more precise type than
any
forobjects
inCanvasController
.