Skip to content

Commit

Permalink
Merge pull request #628 from lihqi/lhq-1224alpha
Browse files Browse the repository at this point in the history
feat(lb-annotation): Add size validation for rectangle drawing
  • Loading branch information
lihqi authored Jan 14, 2025
2 parents 8d0bf36 + 0a2ad63 commit b90efca
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
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

0 comments on commit b90efca

Please sign in to comment.