Skip to content
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

feat(lb-annotation): Add size validation for rectangle drawing #628

Merged
merged 1 commit into from
Jan 14, 2025
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
38 changes: 33 additions & 5 deletions packages/lb-annotation/src/core/toolOperation/rectOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,27 @@ class RectOperation extends BasicToolOperation {
}
}

public checkSize({
width,
height,
minWidth,
minHeight,
}: {
width: number;
height: number;
minWidth: number;
minHeight: number;
}) {
if (Math.round(width) < minWidth || Math.round(height) < minHeight) {
this.emit('messageInfo', locale.getMessagesByLocale(EMessage.RectErrorSizeNotice, this.lang));

this.clearDrawingStatus();
this.render();
return false;
}
return true;
}

/**
* 将绘制中的框体添加进 rectList 中
* @returns
Expand All @@ -1183,12 +1204,19 @@ class RectOperation extends BasicToolOperation {
width /= this.zoom;
height /= this.zoom;

// 小于最小尺寸设置为无效框
if (Math.round(width) < this.config.minWidth || Math.round(height) < this.config.minHeight) {
this.emit('messageInfo', locale.getMessagesByLocale(EMessage.RectErrorSizeNotice, this.lang));
const { attribute } = this.drawingRect;

this.clearDrawingStatus();
this.render();
let limit = { minWidth: this.config.minWidth, minHeight: this.config.minHeight };

if (attribute && this.config.attributeConfigurable) {
const attributeList = this.config?.attributeList ?? [];
const attributeLimit = attributeList.find((i: any) => i.value === attribute)?.limit;
if (attributeLimit) {
limit = attributeLimit;
}
}

if (!this.checkSize({ width, height, ...limit })) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions packages/lb-annotation/src/types/tool/tagTool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare interface IInputList {
isMulti?: boolean;
subSelected?: IInfoList[];
color?: string; // Custom Color for scribbleTool
limit?: ILimit;
}

/** v3.2.0 仅标点工具 列表标注 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import { Tooltip } from 'antd';
import defaultSizeSvg from '@/assets/toolStyle/icon_defaultSize.svg';
import { ILimit, IDefaultSize } from '@labelbee/lb-utils';
import { ILimit, IDefaultSize, IPointCloudLimit } from '@labelbee/lb-utils';
import { useTranslation } from 'react-i18next';

const LimitPopover = ({
limit,
updateSize,
}: {
limit: ILimit;
limit: IPointCloudLimit;
updateSize?: (size: IDefaultSize) => void;
}) => {
const { t } = useTranslation();
Expand Down
9 changes: 8 additions & 1 deletion packages/lb-utils/src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ interface IPositionLimit {
ZMin?: string;
ZMax?: string;
}
export interface ILimit {

export interface IRectLimit {
minWidth: number;
minHeight: number;
}

export interface IPointCloudLimit {
sizeLimit: {
sizeRange: ISizeRange;
defaultSize?: IDefaultSize;
logicalCondition: ILogicalCondition[];
};
positionLimit: IPositionLimit;
}
export type ILimit = IPointCloudLimit | IRectLimit;
export interface IInfoList {
key: string;
value: string;
Expand Down
Loading