Skip to content

Commit

Permalink
Merge pull request #264 from MMMMoriaty/size-whq
Browse files Browse the repository at this point in the history
feat: Support default size function
  • Loading branch information
Glenfiddish authored Aug 12, 2023
2 parents 62995db + 99c3864 commit 586a351
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 50 deletions.
14 changes: 14 additions & 0 deletions packages/lb-components/src/assets/toolStyle/icon_defaultSize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 0 additions & 18 deletions packages/lb-components/src/assets/toolStyle/icon_styleLock.svg

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import React from 'react';
import { Tooltip } from 'antd';
import styleLockSvg from '@/assets/toolStyle/icon_styleLock.svg';
import styleLockActivateSvg from '@/assets/toolStyle/icon_styleLock_a.svg';
import { ILimit } from '@labelbee/lb-utils';
import defaultSizeSvg from '@/assets/toolStyle/icon_defaultSize.svg';
import { ILimit, IDefaultSize } from '@labelbee/lb-utils';
import { useTranslation } from 'react-i18next';

const LimitPopover = ({
limit,
isDefaultSize,
onChange,
updateSize,
}: {
limit: ILimit;
isDefaultSize: boolean;
onChange: () => void;
updateSize?: (size: IDefaultSize) => void;
}) => {
const { t } = useTranslation();
const defaultSize = limit?.sizeLimit?.defaultSize;
const sizeRange = limit?.sizeLimit?.sizeRange;
const positionLimit = limit?.positionLimit;

const { heightDefault, lengthDefault, widthDefault } = defaultSize;
const { heightMax, heightMin, lengthMax, lengthMin, widthMax, widthMin } = sizeRange;
const { heightDefault, depthDefault, widthDefault } = defaultSize;
const { heightMax, heightMin, depthMax, depthMin, widthMax, widthMin } = sizeRange;
const { XMin, XMax, YMin, YMax, ZMin, ZMax } = positionLimit;

return (
Expand All @@ -31,25 +28,25 @@ const LimitPopover = ({
{defaultSize && (
<div style={{ marginBottom: '24px' }}>
<div>
{t('DefaultSize')}({isDefaultSize ? t('Locked') : t('Unlocked')})
{t('DefaultSize')}
</div>
<span>{`${t('Length')}: ${lengthDefault}、`}</span>
<span>{`${t('Width')}: ${widthDefault}、`}</span>
<span>{`${t('Height')}: ${heightDefault}`}</span>
<span>{`${t('Length')}: ${depthDefault}m、`}</span>
<span>{`${t('Width')}: ${widthDefault}m、`}</span>
<span>{`${t('Height')}: ${heightDefault}m`}</span>
</div>
)}

{sizeRange && (
<div style={{ marginBottom: '24px' }}>
<div>{t('NormalSizeRange')}</div>
<span>{`${t('Length')}:: ${lengthMin}~${lengthMax}、`}</span>
<span>{`${t('Width')}: ${widthMin}~${widthMax}、`}</span>
<span>{`${t('Height')}: ${heightMin}~${heightMax}`}</span>
<div>*{t('NormalSizeRange')}</div>
<span>{`${t('Length')}:: ${depthMin}~${depthMax}m、`}</span>
<span>{`${t('Width')}: ${widthMin}~${widthMax}m、`}</span>
<span>{`${t('Height')}: ${heightMin}~${heightMax}m`}</span>
</div>
)}
{positionLimit && (
<div>
<div>{t('NormalCenterPointRange')}</div>
<div>*{t('NormalCenterPointRange')}</div>
<span>{`X: ${XMin}~${XMax}、`}</span>
<span>{`Y: ${YMin}~${YMax}、`}</span>
<span>{`Z: ${ZMin}~${ZMax}`}</span>
Expand All @@ -60,8 +57,14 @@ const LimitPopover = ({
placement='bottomRight'
>
<img
src={isDefaultSize ? styleLockActivateSvg : styleLockSvg}
src={defaultSizeSvg}
style={{ margin: '0px 8px' }}
onClick={(e) => {
e.preventDefault()
if (defaultSize) {
updateSize?.(defaultSize)
}
}}
/>
</Tooltip>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/lb-components/src/components/attributeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Popover } from 'antd';
import ColorPalette from '../colorPalette';
import { CloseOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { ILimit } from '@labelbee/lb-utils';
import { ILimit, IDefaultSize } from '@labelbee/lb-utils';
import LimitPopover from './components/limitPopover';

export const ATTRIBUTE_COLORS = [NULL_COLOR].concat(COLORS_ARRAY);
Expand All @@ -27,6 +27,7 @@ interface IProps {
style?: React.CSSProperties;
enableColorPicker?: boolean;
updateColorConfig?: (value: string, color: string) => void;
updateSize?: (size: IDefaultSize) => void;
}

const AttributeList = React.forwardRef((props: IProps, ref) => {
Expand Down Expand Up @@ -66,6 +67,7 @@ const AttributeList = React.forwardRef((props: IProps, ref) => {
>
{list.map((i: any, index: number) => {
let hotKey: number | string = props?.num ?? index;
const isChosen = i?.value === props?.selectedAttribute

if (props.forbidDefault === true && typeof hotKey === 'number') {
// 禁止 default 将从 1 开始
Expand Down Expand Up @@ -132,8 +134,8 @@ const AttributeList = React.forwardRef((props: IProps, ref) => {
{i.label}
</span>

{i?.limit && (
<LimitPopover limit={i.limit} isDefaultSize={true} onChange={() => {}} />
{i?.limit && isChosen && (
<LimitPopover limit={i.limit} updateSize={props?.updateSize} />
)}
<span className='sensebee-radio-num'>{hotKey}</span>
</Radio>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
IPointUnit,
UpdatePolygonByDragList,
ILine,
DEFAULT_SPHERE_PARAMS,
DEFAULT_SPHERE_PARAMS, IDefaultSize, IPolygonData,
} from '@labelbee/lb-utils';
import { useContext } from 'react';
import { PointCloudContext } from '../PointCloudContext';
Expand Down Expand Up @@ -1047,6 +1047,27 @@ export const usePointCloudViews = () => {
}
};

const updateViewsByDefaultSize = (defaultSize: IDefaultSize) => {
if (selectedBox) {
const selectedBoxTrackID = selectedBox?.info.trackID;
const polygonList = topViewInstance?.toolInstance?.polygonList
const originPolygon = polygonList.find((v: IPolygonData) => v?.trackID === selectedBoxTrackID)
const newBoxParams: IPointCloudBox = {
...selectedBox.info,
width: Number(defaultSize.widthDefault),
depth: Number(defaultSize.depthDefault),
height: Number(defaultSize.heightDefault),
}
const newPointCloudBoxList = updateSelectedBoxes([newBoxParams]);
syncPointCloudViews(
PointCloudView['3D'],
originPolygon,
newBoxParams,
undefined,
newPointCloudBoxList,
);
}
}
/**
* Sync views after adding a point
*/
Expand Down Expand Up @@ -1234,5 +1255,6 @@ export const usePointCloudViews = () => {
pointCloudBoxListUpdated,
initPointCloud3d,
updatePointCloudData,
updateViewsByDefaultSize,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTranslation } from 'react-i18next';
import { LabelBeeContext, useDispatch } from '@/store/ctx';
import BatchUpdateModal from './components/batchUpdateModal';
import { IFileItem } from '@/types/data';
import { PointCloudUtils, IInputList } from '@labelbee/lb-utils';
import { PointCloudUtils, IInputList, IDefaultSize } from '@labelbee/lb-utils';
import AttributeList from '@/components/attributeList';
import { useAttribute } from '@/components/pointCloudView/hooks/useAttribute';
import LassoSelectorSvg from '@/assets/annotation/pointCloudTool/lassoSelector.svg';
Expand All @@ -25,6 +25,7 @@ import CirCleSelectorSvg from '@/assets/annotation/pointCloudTool/circleSelector
import CirCleSelectorSvgA from '@/assets/annotation/pointCloudTool/circleSelector_a.svg';
import { sidebarCls } from '..';
import { SetTaskStepList } from '@/store/annotation/actionCreators';
import { usePointCloudViews } from '@/components/pointCloudView/hooks/usePointCloudViews';

interface IProps {
stepInfo: IStepInfo;
Expand Down Expand Up @@ -223,6 +224,8 @@ const AttributeUpdater = ({
const ptx = useContext(PointCloudContext);
const { t } = useTranslation();
const { defaultAttribute } = useAttribute();
const pointCloudViews = usePointCloudViews();

const dispatch = useDispatch();

const titleStyle = {
Expand Down Expand Up @@ -261,6 +264,12 @@ const AttributeUpdater = ({
dispatch(SetTaskStepList({ stepList: formatStepList }));
};

const updateSize = (size: IDefaultSize) => {
if (pointCloudViews.updateViewsByDefaultSize) {
pointCloudViews.updateViewsByDefaultSize(size)
}
}

const setAttribute = (attribute: string) => {
toolInstance.setDefaultAttribute(attribute);
};
Expand All @@ -287,6 +296,7 @@ const AttributeUpdater = ({
attributeChanged={(attribute: string) => setAttribute(attribute)}
updateColorConfig={updateColorConfig}
enableColorPicker={enableColorPicker}
updateSize={updateSize}
/>
<Divider style={{ margin: 0 }} />
{selectedBox && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IProps {
}

const SwitchAttributeList: React.FC<IProps> = (props) => {

const [_, forceRender] = useState(0);
const listRef = useRef<HTMLElement>(null);
const { toolInstance } = props;
Expand Down
4 changes: 2 additions & 2 deletions packages/lb-utils/src/i18n/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
"AdditionalContent":"AdditionalContent",
"Submit":"Submit",
"DragAndDrop":"Drag and drap",
"DefaultSize":"Default size",
"DefaultSize":"Click to use the default size.",
"NormalSizeRange":"Normal size range",
"NormalCenterPointRange":"Normal center point range",
"Unlocked":"Unlocked",
Expand Down Expand Up @@ -491,7 +491,7 @@
"AdditionalContent":"(选填)请填写任何你对答案的评价或其他补充内容",
"Submit":"提交",
"DragAndDrop":"按住拖动",
"DefaultSize":"默认尺寸",
"DefaultSize":"点击图标以使用默认尺寸",
"NormalSizeRange":"正常尺寸范围",
"NormalCenterPointRange":"正常中心点范围",
"Unlocked":"未开启",
Expand Down
12 changes: 6 additions & 6 deletions packages/lb-utils/src/types/base.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Size range
interface ISizeRange {
export interface ISizeRange {
heightMax?: string;
heightMin?: string;
lengthMax?: string;
lengthMin?: string;
depthMax?: string;
depthMin?: string;
widthMax?: string;
widthMin?: string;
}

// Default size
interface IDefaultSize {
export interface IDefaultSize {
heightDefault: string;
lengthDefault: string;
depthDefault: string;
widthDefault: string;
}

// logical condition
interface ILogicalCondition {
export interface ILogicalCondition {
condition: string;
dimensionLeft: string;
dimensionRight: string;
Expand Down

0 comments on commit 586a351

Please sign in to comment.