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: Support invalid settings from external sources / fix: Point tool support settings are invalid #621

Merged
merged 2 commits into from
Dec 20, 2024
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
25 changes: 25 additions & 0 deletions packages/lb-annotation/src/core/toolOperation/pointOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,26 @@ class PointOperation extends BasicToolOperation {
this.render();
}

public setPointValidAndRender(id?: string) {
const hasValid = this.pointList.some((point) => point?.valid);
this.setPointList(
this.pointList.map((point) => {
if (point.id === id) {
return {
...point,
valid: !point.valid,
};
}
if (this.selection.isIdSelected(point.id)) {
point.valid = !hasValid;
}
return point;
}),
true,
);
this.render();
}

public onDragMove(e: MouseEvent) {
if (!this.imgInfo) return;
this.dragStatus = EDragStatus.Move;
Expand Down Expand Up @@ -445,6 +465,11 @@ class PointOperation extends BasicToolOperation {
this.onTabKeyDown(e);
break;
}
case EKeyCode.F:
if (this.selectedIDs.length > 0) {
this.setPointValidAndRender(this.selectedID);
}
break;
case EKeyCode.Z:
this.setIsHidden(!this.isHidden);
this.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ export interface IPointCloudContext
selectedIDs: string[];
setSelectedIDs: (ids?: string[] | string) => void;
valid: boolean;
visibleBatchSetValid: boolean;
setPointCloudResult: (resultList: IPointCloudBoxList) => void;
setPointCloudSphereList: (sphereList: IPointCloudSphereList) => void;
selectedPointCloudBox?: IPointCloudBox;
setPointCloudValid: (valid?: boolean) => void;
setBatchSetValidModal: (visible: boolean) => void;
addSelectedID: (selectedID: string) => void;
addHighlightID: (highlightID: number) => void;
selectedAllBoxes: () => void;
Expand Down Expand Up @@ -196,10 +198,12 @@ export const PointCloudContext = React.createContext<IPointCloudContext>({
highlightIDs: [],
setHighlightIDs: () => {},
valid: true,
visibleBatchSetValid: false,
setSelectedIDs: () => {},
setPointCloudResult: () => {},
setPointCloudSphereList: () => {},
setPointCloudValid: () => {},
setBatchSetValidModal: () => {},
setTopViewInstance: () => {},
setSideViewInstance: () => {},
setBackViewInstance: () => {},
Expand Down Expand Up @@ -300,6 +304,7 @@ export const PointCloudProvider: React.FC<PropsWithChildren<{}>> = ({ children }
const [highlight2DDataList, setHighlight2DDataList] = useState<IHighlight2DData[]>([]);
const [highlight2DLoading, setHighlight2DLoading] = useState<boolean>(false);
const state = useAnnotatedBoxStore();
const [visibleBatchSetValid, setVisibleBatchSetValid] = useState<boolean>(false);

const [imageSizes, setImageSizes] = useState<{
[key: string]: ISize;
Expand Down Expand Up @@ -532,6 +537,10 @@ export const PointCloudProvider: React.FC<PropsWithChildren<{}>> = ({ children }
setValid(valid === false ? false : true);
};

const setBatchSetValidModal = (visible: boolean) => {
setVisibleBatchSetValid(visible);
};

const setSelectedIDs = (selectedIDs?: string[] | string) => {
if (selectedIDs === undefined) {
setSelectedIDsState([]);
Expand Down Expand Up @@ -755,8 +764,10 @@ export const PointCloudProvider: React.FC<PropsWithChildren<{}>> = ({ children }
addPointCloudSphere,
setPointCloudSphereList,
valid,
visibleBatchSetValid,
selectedPointCloudBox,
setPointCloudValid,
setBatchSetValidModal,
addSelectedID,
addHighlightID,
selectedAllBoxes,
Expand Down Expand Up @@ -825,6 +836,7 @@ export const PointCloudProvider: React.FC<PropsWithChildren<{}>> = ({ children }
};
}, [
valid,
visibleBatchSetValid,
selectedIDs,
pointCloudBoxList,
pointCloudSphereList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSingleBox } from './hooks/useSingleBox';
import { useSphere } from './hooks/useSphere';
import React, { useContext, useEffect } from 'react';
import { cTool, CommonToolUtils, EToolName } from '@labelbee/lb-annotation';
import { message } from 'antd';
import { message, Modal } from 'antd';
import { connect } from 'react-redux';
import { a2MapStateToProps, IA2MapStateProps } from '@/store/annotation/map';
import { ICustomToolInstance } from '@/hooks/annotation';
Expand All @@ -30,6 +30,7 @@ interface IProps extends IA2MapStateProps {
checkMode?: boolean;
toolInstanceRef: React.MutableRefObject<ICustomToolInstance>;
setResourceLoading?: (loading: boolean) => void;
isBatchSetValid?: boolean;
}

const PointCloudListener: React.FC<IProps> = ({
Expand All @@ -40,6 +41,7 @@ const PointCloudListener: React.FC<IProps> = ({
imgIndex,
toolInstanceRef,
setResourceLoading,
isBatchSetValid,
}) => {
const ptCtx = useContext(PointCloudContext);
const {
Expand Down Expand Up @@ -146,7 +148,12 @@ const PointCloudListener: React.FC<IProps> = ({
break;

case 'v':
ptCtx.setPointCloudValid(!ptCtx.valid);
if (isBatchSetValid) {
Modal.destroyAll();
ptCtx.setBatchSetValidModal(!ptCtx.visibleBatchSetValid);
} else {
ptCtx.setPointCloudValid(!ptCtx.valid);
}
break;

case 'tab':
Expand Down
12 changes: 12 additions & 0 deletions packages/lb-components/src/components/pointCloudView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ import classNames from 'classnames';
import SideAndBackOverView from './components/sideAndBackOverView';
import { SetLoadPCDFileLoading } from '@/store/annotation/actionCreators';
import DynamicResizer from '@/components/DynamicResizer';
import { IBatchSetValid } from '@/views/MainView/sidebar/GeneralOperation';

interface IProps extends IA2MapStateProps {
drawLayerSlot?: DrawLayerSlot;
checkMode?: boolean;
intelligentFit?: boolean;
measureVisible?: boolean;
setResourceLoading?: (loading: boolean) => void;
setBatchSetValid?: (values: IBatchSetValid) => void;
}

const PointCloudView: React.FC<IProps> = (props) => {
Expand All @@ -61,6 +63,7 @@ const PointCloudView: React.FC<IProps> = (props) => {
measureVisible,
setResourceLoading,
stepInfo,
setBatchSetValid,
} = props;
const ptCtx = useContext(PointCloudContext);
const { globalPattern, setGlobalPattern, selectedIDs } = ptCtx;
Expand Down Expand Up @@ -179,6 +182,7 @@ const PointCloudView: React.FC<IProps> = (props) => {
checkMode={checkMode}
toolInstanceRef={toolInstanceRef}
setResourceLoading={setResourceLoading}
isBatchSetValid={!!setBatchSetValid}
/>
<div className={getClassName('point-cloud-layout')} onContextMenu={(e) => e.preventDefault()}>
<div className={getClassName('point-cloud-wrapper')}>
Expand Down Expand Up @@ -261,6 +265,14 @@ const PointCloudView: React.FC<IProps> = (props) => {
<AnnotatedAttributesPanelFixedRight />
</div>
</div>
{ptCtx.visibleBatchSetValid &&
setBatchSetValid?.({
valid: ptCtx.valid,
isModal: true,
visibleModal: ptCtx.visibleBatchSetValid,
onClose: () => ptCtx.setBatchSetValidModal(false),
singleSetQuestionImg: () => ptCtx.setPointCloudValid(!ptCtx.valid),
})}
</>
);
};
Expand Down
4 changes: 4 additions & 0 deletions packages/lb-components/src/views/MainView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import { LoadingOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { EPointCloudName } from '@labelbee/lb-annotation';
import LLMMultiWheelLayout from './LLMMultiWheelLayout';
import { IBatchSetValid } from './sidebar/GeneralOperation';

interface IProps {
path: string;
loading: boolean;
measureVisible?: boolean;
setBatchSetValid?: (values: IBatchSetValid) => void;
}

const { Sider, Content } = Layout;
Expand All @@ -59,6 +61,7 @@ const PointCloudAnnotate: React.FC<AppProps & IProps> = (props) => {
intelligentFit={props.intelligentFit}
measureVisible={props.measureVisible}
setResourceLoading={props.setResourceLoading}
setBatchSetValid={props?.setBatchSetValid}
/>
<ToolFooter style={props.style?.footer} mode={props.mode} footer={props?.footer} />
</>
Expand Down Expand Up @@ -185,6 +188,7 @@ const MainView: React.FC<AppProps & IProps> = (props) => {
enableColorPicker={props?.enableColorPicker}
setSiderWidth={setSiderWidth}
propsSiderWidth={props.style?.sider?.width}
setBatchSetValid={props.setBatchSetValid}
/>
</Sider>
</Layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useRef, useState } from 'react';
import { Col, Popconfirm } from 'antd';
import { useTranslation } from 'react-i18next';
import { prefix } from '@/constant';
import { IBatchSetValid } from '../GeneralOperation';

export interface IOperationConfig {
name: string;
Expand Down Expand Up @@ -68,12 +69,40 @@ const ShowIcon = ({ isHover, info }: { isHover: string | null; info: IOperationC
);
};

const ActionsConfirm: React.FC<{ allOperation: IOperationConfig[] }> = ({ allOperation }) => {
const ActionsConfirm: React.FC<{
allOperation: IOperationConfig[];
setBatchSetValid?: (values: IBatchSetValid) => void;
valid?: boolean;
}> = ({ allOperation, setBatchSetValid, valid }) => {
const ref = useRef<HTMLDivElement>(null);
const [isHover, setHover] = useState<string | null>(null);
const { t } = useTranslation();
const annotationLength = Math.floor(24 / allOperation.length);

const itemBox = (info: IOperationConfig) => {
if (info.forbidConfirm) {
return <ShowIcon info={info} isHover={isHover} />;
}
if (setBatchSetValid && info.key === 'setValidity') {
return setBatchSetValid({ valid, isHover: !!isHover, singleSetQuestionImg: info.onClick });
}
return (
<Popconfirm
title={<PopconfirmTitle info={info} />}
placement='topRight'
okText={t('Confirm')}
cancelText={t('Cancel')}
getPopupContainer={() => ref.current ?? document.body}
onConfirm={info.onClick}
overlayClassName={`${prefix}-pop-confirm`}
>
<div>
<ShowIcon info={info} isHover={isHover} />
</div>
</Popconfirm>
);
};

return (
<div className='generalOperation' ref={ref}>
{allOperation.map((info, index) => (
Expand All @@ -88,23 +117,7 @@ const ActionsConfirm: React.FC<{ allOperation: IOperationConfig[] }> = ({ allOpe
setHover(null);
}}
>
{info.forbidConfirm ? (
<ShowIcon info={info} isHover={isHover} />
) : (
<Popconfirm
title={<PopconfirmTitle info={info} />}
placement='topRight'
okText={t('Confirm')}
cancelText={t('Cancel')}
getPopupContainer={() => ref.current ?? document.body}
onConfirm={info.onClick}
overlayClassName={`${prefix}-pop-confirm`}
>
<div>
<ShowIcon info={info} isHover={isHover} />
</div>
</Popconfirm>
)}
{itemBox(info)}
</div>
</Col>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ const mapStateToProps = (state: AppState) => {
stepList: state.annotation.stepList,
};
};
export interface IBatchSetValid {
isHover?: boolean;
valid?: boolean;
isModal?: boolean;
visibleModal?: boolean;
onClose?: () => void;
singleSetQuestionImg?: () => void;
}

interface IProps {
toolInstance: ToolInstance;
stepInfo: IStepInfo;
imgList: AnnotationFileList;
imgIndex: number;
stepList: IStepInfo[];
hideValidity?: boolean;
setBatchSetValid?: (values: IBatchSetValid) => void;
}

const GeneralOperation: React.FC<IProps> = ({ toolInstance, stepInfo, hideValidity }) => {
Expand Down Expand Up @@ -63,7 +73,7 @@ export const PointCloudOperation: ConnectedComponent<
'toolInstance' | 'stepInfo' | 'imgList' | 'imgIndex' | 'stepList'
>
> = connect(mapStateToProps, null, null, { context: LabelBeeContext })(
({ toolInstance, stepInfo, imgList, stepList, imgIndex }) => {
({ toolInstance, stepInfo, imgList, stepList, imgIndex, setBatchSetValid }) => {
const { t } = useTranslation();
const { selectedBox } = useSingleBox();
const operationList = useOperationList(toolInstance);
Expand Down Expand Up @@ -114,7 +124,12 @@ export const PointCloudOperation: ConnectedComponent<

return (
<>
<ActionsConfirm allOperation={allOperation} />
<ActionsConfirm
allOperation={allOperation}
setBatchSetValid={setBatchSetValid}
valid={toolInstance?.valid}
/>

<UnifyParamsModal
id={selectedBoxInfo?.trackID}
visible={isShowModal}
Expand Down
6 changes: 4 additions & 2 deletions packages/lb-components/src/views/MainView/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import AnnotationText from './AnnotationText';
import ClearIcon from './ClearIcon';
import GeneralOperation, { PointCloudOperation } from './GeneralOperation';
import GeneralOperation, { IBatchSetValid, PointCloudOperation } from './GeneralOperation';
import ImgAttributeInfo from './ImgAttributeInfo';
import SwitchAttributeList from './SwitchAttributeList';
import TagSidebar, { expandIconFuc } from './TagSidebar';
Expand Down Expand Up @@ -39,6 +39,7 @@ interface IProps {
setSiderWidth?: (width: number | undefined) => void;
propsSiderWidth?: number | undefined;
checkMode?: boolean;
setBatchSetValid?: (values: IBatchSetValid) => void;
}

export const sidebarCls = `${prefix}-sidebar`;
Expand All @@ -48,6 +49,7 @@ const Sidebar: React.FC<IProps> = ({
setSiderWidth,
propsSiderWidth,
checkMode,
setBatchSetValid,
}) => {
const stepInfo = useSelector((state: AppState) =>
StepUtils.getCurrentStepInfo(state.annotation.step, state.annotation.stepList),
Expand Down Expand Up @@ -138,7 +140,7 @@ const Sidebar: React.FC<IProps> = ({

const pointCloudToolSidebar = <PointCloudToolSidebar enableColorPicker={enableColorPicker} />;

const pointCloudOperation = <PointCloudOperation />;
const pointCloudOperation = <PointCloudOperation setBatchSetValid={setBatchSetValid} />;

if (sider) {
if (typeof sider === 'function') {
Expand Down
Loading