2026-03-11 15:16:44 +03:00
|
|
|
|
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
2025-05-23 05:51:23 +03:00
|
|
|
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
2024-05-29 17:01:39 +03:00
|
|
|
|
import { PolygonCanvas } from "@/components/settings/PolygonCanvas";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
import { Polygon, PolygonType } from "@/types/canvas";
|
|
|
|
|
|
import { interpolatePoints, parseCoordinates } from "@/utils/canvasUtil";
|
2024-05-29 17:01:39 +03:00
|
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
import { useResizeObserver } from "@/hooks/resize-observer";
|
|
|
|
|
|
import { LuExternalLink, LuPlus } from "react-icons/lu";
|
|
|
|
|
|
import {
|
|
|
|
|
|
HoverCard,
|
|
|
|
|
|
HoverCardContent,
|
|
|
|
|
|
HoverCardTrigger,
|
|
|
|
|
|
} from "@/components/ui/hover-card";
|
|
|
|
|
|
import copy from "copy-to-clipboard";
|
|
|
|
|
|
import { toast } from "sonner";
|
2024-05-29 17:01:39 +03:00
|
|
|
|
import { Toaster } from "@/components/ui/sonner";
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
import {
|
|
|
|
|
|
Tooltip,
|
|
|
|
|
|
TooltipContent,
|
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
|
} from "@/components/ui/tooltip";
|
|
|
|
|
|
import Heading from "@/components/ui/heading";
|
|
|
|
|
|
import ZoneEditPane from "@/components/settings/ZoneEditPane";
|
|
|
|
|
|
import MotionMaskEditPane from "@/components/settings/MotionMaskEditPane";
|
|
|
|
|
|
import ObjectMaskEditPane from "@/components/settings/ObjectMaskEditPane";
|
|
|
|
|
|
import PolygonItem from "@/components/settings/PolygonItem";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
|
import { isDesktop } from "react-device-detect";
|
2025-03-16 18:36:20 +03:00
|
|
|
|
|
2025-02-11 19:08:28 +03:00
|
|
|
|
import { useSearchEffect } from "@/hooks/use-overlay-state";
|
2025-03-16 18:36:20 +03:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2025-05-28 15:10:45 +03:00
|
|
|
|
import { useDocDomain } from "@/hooks/use-doc-domain";
|
2025-11-26 16:23:51 +03:00
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-03-11 15:16:44 +03:00
|
|
|
|
import { ProfileState } from "@/types/profile";
|
2024-05-29 17:01:39 +03:00
|
|
|
|
type MasksAndZoneViewProps = {
|
2024-04-19 14:34:07 +03:00
|
|
|
|
selectedCamera: string;
|
|
|
|
|
|
selectedZoneMask?: PolygonType[];
|
|
|
|
|
|
setUnsavedChanges: React.Dispatch<React.SetStateAction<boolean>>;
|
2026-03-11 15:16:44 +03:00
|
|
|
|
profileState?: ProfileState;
|
2024-04-19 14:34:07 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-29 17:01:39 +03:00
|
|
|
|
export default function MasksAndZonesView({
|
2024-04-19 14:34:07 +03:00
|
|
|
|
selectedCamera,
|
|
|
|
|
|
selectedZoneMask,
|
|
|
|
|
|
setUnsavedChanges,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
profileState,
|
2024-05-29 17:01:39 +03:00
|
|
|
|
}: MasksAndZoneViewProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
|
const { t } = useTranslation(["views/settings"]);
|
2025-05-28 15:10:45 +03:00
|
|
|
|
const { getLocaleDocUrl } = useDocDomain();
|
2024-04-19 14:34:07 +03:00
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
const [allPolygons, setAllPolygons] = useState<Polygon[]>([]);
|
|
|
|
|
|
const [editingPolygons, setEditingPolygons] = useState<Polygon[]>([]);
|
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
2026-02-28 17:04:43 +03:00
|
|
|
|
const [loadingPolygonIndex, setLoadingPolygonIndex] = useState<
|
|
|
|
|
|
number | undefined
|
|
|
|
|
|
>(undefined);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
const [activePolygonIndex, setActivePolygonIndex] = useState<
|
|
|
|
|
|
number | undefined
|
|
|
|
|
|
>(undefined);
|
|
|
|
|
|
const [hoveredPolygonIndex, setHoveredPolygonIndex] = useState<number | null>(
|
|
|
|
|
|
null,
|
|
|
|
|
|
);
|
|
|
|
|
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
|
const [editPane, setEditPane] = useState<PolygonType | undefined>(undefined);
|
2026-03-01 23:41:33 +03:00
|
|
|
|
const editPaneRef = useRef(editPane);
|
|
|
|
|
|
editPaneRef.current = editPane;
|
|
|
|
|
|
const prevScaledRef = useRef<{ w: number; h: number } | null>(null);
|
2025-02-10 23:23:42 +03:00
|
|
|
|
const [activeLine, setActiveLine] = useState<number | undefined>();
|
2025-02-11 19:08:28 +03:00
|
|
|
|
const [snapPoints, setSnapPoints] = useState(false);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
// Profile state
|
|
|
|
|
|
const currentEditingProfile =
|
2026-03-11 20:35:13 +03:00
|
|
|
|
profileState?.editingProfile[selectedCamera] ?? null;
|
2026-03-11 15:16:44 +03:00
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
const cameraConfig = useMemo(() => {
|
|
|
|
|
|
if (config && selectedCamera) {
|
|
|
|
|
|
return config.cameras[selectedCamera];
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [config, selectedCamera]);
|
|
|
|
|
|
|
|
|
|
|
|
const [{ width: containerWidth, height: containerHeight }] =
|
|
|
|
|
|
useResizeObserver(containerRef);
|
|
|
|
|
|
|
|
|
|
|
|
const aspectRatio = useMemo(() => {
|
|
|
|
|
|
if (!config) {
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const camera = config.cameras[selectedCamera];
|
|
|
|
|
|
|
|
|
|
|
|
if (!camera) {
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return camera.detect.width / camera.detect.height;
|
|
|
|
|
|
}, [config, selectedCamera]);
|
|
|
|
|
|
|
|
|
|
|
|
const detectHeight = useMemo(() => {
|
|
|
|
|
|
if (!config) {
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const camera = config.cameras[selectedCamera];
|
|
|
|
|
|
|
|
|
|
|
|
if (!camera) {
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return camera.detect.height;
|
|
|
|
|
|
}, [config, selectedCamera]);
|
|
|
|
|
|
|
|
|
|
|
|
const stretch = true;
|
2024-05-23 16:30:16 +03:00
|
|
|
|
|
|
|
|
|
|
const fitAspect = useMemo(
|
|
|
|
|
|
() => (isDesktop ? containerWidth / containerHeight : 3 / 4),
|
|
|
|
|
|
[containerWidth, containerHeight],
|
|
|
|
|
|
);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
|
|
|
|
|
const scaledHeight = useMemo(() => {
|
|
|
|
|
|
if (containerRef.current && aspectRatio && detectHeight) {
|
|
|
|
|
|
const scaledHeight =
|
|
|
|
|
|
aspectRatio < (fitAspect ?? 0)
|
|
|
|
|
|
? Math.floor(
|
|
|
|
|
|
Math.min(containerHeight, containerRef.current?.clientHeight),
|
|
|
|
|
|
)
|
|
|
|
|
|
: isDesktop || aspectRatio > fitAspect
|
|
|
|
|
|
? Math.floor(containerWidth / aspectRatio)
|
|
|
|
|
|
: Math.floor(containerWidth / aspectRatio) / 1.5;
|
|
|
|
|
|
const finalHeight = stretch
|
|
|
|
|
|
? scaledHeight
|
|
|
|
|
|
: Math.min(scaledHeight, detectHeight);
|
|
|
|
|
|
|
|
|
|
|
|
if (finalHeight > 0) {
|
|
|
|
|
|
return finalHeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [
|
|
|
|
|
|
aspectRatio,
|
|
|
|
|
|
containerWidth,
|
|
|
|
|
|
containerHeight,
|
|
|
|
|
|
fitAspect,
|
|
|
|
|
|
detectHeight,
|
|
|
|
|
|
stretch,
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const scaledWidth = useMemo(() => {
|
|
|
|
|
|
if (aspectRatio && scaledHeight) {
|
|
|
|
|
|
return Math.ceil(scaledHeight * aspectRatio);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [scaledHeight, aspectRatio]);
|
|
|
|
|
|
|
2025-02-11 19:08:28 +03:00
|
|
|
|
const handleNewPolygon = (type: PolygonType, coordinates?: number[][]) => {
|
2024-04-19 14:34:07 +03:00
|
|
|
|
if (!cameraConfig) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setActivePolygonIndex(allPolygons.length);
|
|
|
|
|
|
|
|
|
|
|
|
let polygonColor = [128, 128, 0];
|
|
|
|
|
|
|
|
|
|
|
|
if (type == "motion_mask") {
|
|
|
|
|
|
polygonColor = [0, 0, 220];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (type == "object_mask") {
|
|
|
|
|
|
polygonColor = [128, 128, 128];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setEditingPolygons([
|
|
|
|
|
|
...(allPolygons || []),
|
|
|
|
|
|
{
|
2025-02-11 19:08:28 +03:00
|
|
|
|
points: coordinates ?? [],
|
2025-02-10 23:23:42 +03:00
|
|
|
|
distances: [],
|
2025-02-11 19:08:28 +03:00
|
|
|
|
isFinished: coordinates ? true : false,
|
2024-04-19 14:34:07 +03:00
|
|
|
|
type,
|
|
|
|
|
|
typeIndex: 9999,
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
objects: [],
|
|
|
|
|
|
camera: selectedCamera,
|
|
|
|
|
|
color: polygonColor,
|
2026-02-28 17:04:43 +03:00
|
|
|
|
enabled: true,
|
2024-04-19 14:34:07 +03:00
|
|
|
|
},
|
|
|
|
|
|
]);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleCancel = useCallback(() => {
|
|
|
|
|
|
setEditPane(undefined);
|
|
|
|
|
|
setEditingPolygons([...allPolygons]);
|
|
|
|
|
|
setActivePolygonIndex(undefined);
|
|
|
|
|
|
setHoveredPolygonIndex(null);
|
|
|
|
|
|
setUnsavedChanges(false);
|
2025-03-16 18:36:20 +03:00
|
|
|
|
document.title = t("documentTitle.masksAndZones");
|
|
|
|
|
|
}, [allPolygons, setUnsavedChanges, t]);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
|
|
|
|
|
const handleSave = useCallback(() => {
|
|
|
|
|
|
setAllPolygons([...(editingPolygons ?? [])]);
|
|
|
|
|
|
setHoveredPolygonIndex(null);
|
|
|
|
|
|
setUnsavedChanges(false);
|
2025-05-23 05:51:23 +03:00
|
|
|
|
}, [editingPolygons, setUnsavedChanges]);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!isLoading && editPane !== undefined) {
|
|
|
|
|
|
setActivePolygonIndex(undefined);
|
|
|
|
|
|
setEditPane(undefined);
|
|
|
|
|
|
}
|
|
|
|
|
|
// we know that these deps are correct
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
}, [isLoading]);
|
|
|
|
|
|
|
|
|
|
|
|
const handleCopyCoordinates = useCallback(
|
|
|
|
|
|
(index: number) => {
|
|
|
|
|
|
if (allPolygons && scaledWidth && scaledHeight) {
|
|
|
|
|
|
const poly = allPolygons[index];
|
|
|
|
|
|
copy(
|
|
|
|
|
|
interpolatePoints(poly.points, scaledWidth, scaledHeight, 1, 1)
|
|
|
|
|
|
.map((point) => `${point[0]},${point[1]}`)
|
|
|
|
|
|
.join(","),
|
|
|
|
|
|
);
|
2025-03-16 18:36:20 +03:00
|
|
|
|
toast.success(
|
|
|
|
|
|
t("masksAndZones.toast.success.copyCoordinates", {
|
|
|
|
|
|
polyName: poly.name,
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
} else {
|
2025-03-16 18:36:20 +03:00
|
|
|
|
toast.error(t("masksAndZones.toast.error.copyCoordinatesFailed"));
|
2024-04-19 14:34:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-03-16 18:36:20 +03:00
|
|
|
|
[allPolygons, scaledHeight, scaledWidth, t],
|
2024-04-19 14:34:07 +03:00
|
|
|
|
);
|
|
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
// Helper to dim colors for base polygons in profile mode
|
|
|
|
|
|
const dimColor = useCallback(
|
|
|
|
|
|
(color: number[]): number[] => {
|
|
|
|
|
|
if (!currentEditingProfile) return color;
|
|
|
|
|
|
return color.map((c) => Math.round(c * 0.4 + 153 * 0.6));
|
|
|
|
|
|
},
|
|
|
|
|
|
[currentEditingProfile],
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (cameraConfig && containerRef.current && scaledWidth && scaledHeight) {
|
2026-03-11 15:16:44 +03:00
|
|
|
|
const profileData = currentEditingProfile
|
|
|
|
|
|
? cameraConfig.profiles?.[currentEditingProfile]
|
|
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
|
|
|
|
// Build base zone names set for source tracking
|
|
|
|
|
|
const baseZoneNames = new Set(Object.keys(cameraConfig.zones));
|
|
|
|
|
|
const profileZoneNames = new Set(Object.keys(profileData?.zones ?? {}));
|
|
|
|
|
|
const baseMotionMaskNames = new Set(
|
|
|
|
|
|
Object.keys(cameraConfig.motion.mask || {}),
|
|
|
|
|
|
);
|
|
|
|
|
|
const profileMotionMaskNames = new Set(
|
|
|
|
|
|
Object.keys(profileData?.motion?.mask ?? {}),
|
|
|
|
|
|
);
|
|
|
|
|
|
const baseGlobalObjectMaskNames = new Set(
|
|
|
|
|
|
Object.keys(cameraConfig.objects.mask || {}),
|
|
|
|
|
|
);
|
|
|
|
|
|
const profileGlobalObjectMaskNames = new Set(
|
|
|
|
|
|
Object.keys(profileData?.objects?.mask ?? {}),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Merge zones: profile zones override base zones with same name
|
|
|
|
|
|
const mergedZones = new Map<
|
|
|
|
|
|
string,
|
|
|
|
|
|
{
|
|
|
|
|
|
data: CameraConfig["zones"][string];
|
|
|
|
|
|
source: "base" | "profile" | "override";
|
|
|
|
|
|
}
|
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
|
|
for (const [name, zoneData] of Object.entries(cameraConfig.zones)) {
|
|
|
|
|
|
if (currentEditingProfile && profileZoneNames.has(name)) {
|
|
|
|
|
|
// Profile overrides this base zone
|
|
|
|
|
|
mergedZones.set(name, {
|
|
|
|
|
|
data: profileData!.zones![name]!,
|
|
|
|
|
|
source: "override",
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mergedZones.set(name, {
|
|
|
|
|
|
data: zoneData,
|
|
|
|
|
|
source: currentEditingProfile ? "base" : "base",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add profile-only zones
|
|
|
|
|
|
if (profileData?.zones) {
|
|
|
|
|
|
for (const [name, zoneData] of Object.entries(profileData.zones)) {
|
|
|
|
|
|
if (!baseZoneNames.has(name)) {
|
|
|
|
|
|
mergedZones.set(name, { data: zoneData!, source: "profile" });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let zoneIndex = 0;
|
|
|
|
|
|
const zones: Polygon[] = [];
|
|
|
|
|
|
for (const [name, { data: zoneData, source }] of mergedZones) {
|
|
|
|
|
|
const isBase = source === "base" && !!currentEditingProfile;
|
|
|
|
|
|
const baseColor = zoneData.color ?? [128, 128, 0];
|
|
|
|
|
|
zones.push({
|
2024-04-19 14:34:07 +03:00
|
|
|
|
type: "zone" as PolygonType,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
typeIndex: zoneIndex,
|
2024-04-19 14:34:07 +03:00
|
|
|
|
camera: cameraConfig.name,
|
|
|
|
|
|
name,
|
2025-11-07 17:02:06 +03:00
|
|
|
|
friendly_name: zoneData.friendly_name,
|
2026-02-28 17:04:43 +03:00
|
|
|
|
enabled: zoneData.enabled,
|
|
|
|
|
|
enabled_in_config: zoneData.enabled_in_config,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
objects: zoneData.objects ?? [],
|
2024-04-19 14:34:07 +03:00
|
|
|
|
points: interpolatePoints(
|
|
|
|
|
|
parseCoordinates(zoneData.coordinates),
|
|
|
|
|
|
1,
|
|
|
|
|
|
1,
|
|
|
|
|
|
scaledWidth,
|
|
|
|
|
|
scaledHeight,
|
|
|
|
|
|
),
|
2025-02-10 23:23:42 +03:00
|
|
|
|
distances:
|
2026-03-11 15:16:44 +03:00
|
|
|
|
zoneData.distances?.map((distance: string) =>
|
|
|
|
|
|
parseFloat(distance),
|
|
|
|
|
|
) ?? [],
|
2024-04-19 14:34:07 +03:00
|
|
|
|
isFinished: true,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
color: isBase ? dimColor(baseColor) : baseColor,
|
|
|
|
|
|
polygonSource: currentEditingProfile ? source : undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
zoneIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Merge motion masks
|
|
|
|
|
|
const mergedMotionMasks = new Map<
|
|
|
|
|
|
string,
|
|
|
|
|
|
{
|
|
|
|
|
|
data: CameraConfig["motion"]["mask"][string];
|
|
|
|
|
|
source: "base" | "profile" | "override";
|
|
|
|
|
|
}
|
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
|
|
for (const [maskId, maskData] of Object.entries(
|
|
|
|
|
|
cameraConfig.motion.mask || {},
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (currentEditingProfile && profileMotionMaskNames.has(maskId)) {
|
|
|
|
|
|
mergedMotionMasks.set(maskId, {
|
|
|
|
|
|
data: profileData!.motion!.mask![maskId],
|
|
|
|
|
|
source: "override",
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mergedMotionMasks.set(maskId, {
|
|
|
|
|
|
data: maskData,
|
|
|
|
|
|
source: currentEditingProfile ? "base" : "base",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
if (profileData?.motion?.mask) {
|
|
|
|
|
|
for (const [maskId, maskData] of Object.entries(
|
|
|
|
|
|
profileData.motion.mask,
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (!baseMotionMaskNames.has(maskId)) {
|
|
|
|
|
|
mergedMotionMasks.set(maskId, {
|
|
|
|
|
|
data: maskData,
|
|
|
|
|
|
source: "profile",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
let motionMaskIndex = 0;
|
|
|
|
|
|
const motionMasks: Polygon[] = [];
|
|
|
|
|
|
for (const [maskId, { data: maskData, source }] of mergedMotionMasks) {
|
|
|
|
|
|
const isBase = source === "base" && !!currentEditingProfile;
|
|
|
|
|
|
const baseColor = [0, 0, 255];
|
|
|
|
|
|
motionMasks.push({
|
2026-02-28 17:04:43 +03:00
|
|
|
|
type: "motion_mask" as PolygonType,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
typeIndex: motionMaskIndex,
|
2026-02-28 17:04:43 +03:00
|
|
|
|
camera: cameraConfig.name,
|
|
|
|
|
|
name: maskId,
|
|
|
|
|
|
friendly_name: maskData.friendly_name,
|
|
|
|
|
|
enabled: maskData.enabled,
|
|
|
|
|
|
enabled_in_config: maskData.enabled_in_config,
|
|
|
|
|
|
objects: [],
|
|
|
|
|
|
points: interpolatePoints(
|
|
|
|
|
|
parseCoordinates(maskData.coordinates),
|
|
|
|
|
|
1,
|
|
|
|
|
|
1,
|
|
|
|
|
|
scaledWidth,
|
|
|
|
|
|
scaledHeight,
|
|
|
|
|
|
),
|
|
|
|
|
|
distances: [],
|
|
|
|
|
|
isFinished: true,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
color: isBase ? dimColor(baseColor) : baseColor,
|
|
|
|
|
|
polygonSource: currentEditingProfile ? source : undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
motionMaskIndex++;
|
|
|
|
|
|
}
|
2026-02-28 17:04:43 +03:00
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
// Merge global object masks
|
|
|
|
|
|
const mergedGlobalObjectMasks = new Map<
|
|
|
|
|
|
string,
|
|
|
|
|
|
{
|
|
|
|
|
|
data: CameraConfig["objects"]["mask"][string];
|
|
|
|
|
|
source: "base" | "profile" | "override";
|
|
|
|
|
|
}
|
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
|
|
for (const [maskId, maskData] of Object.entries(
|
|
|
|
|
|
cameraConfig.objects.mask || {},
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (currentEditingProfile && profileGlobalObjectMaskNames.has(maskId)) {
|
|
|
|
|
|
mergedGlobalObjectMasks.set(maskId, {
|
|
|
|
|
|
data: profileData!.objects!.mask![maskId],
|
|
|
|
|
|
source: "override",
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mergedGlobalObjectMasks.set(maskId, {
|
|
|
|
|
|
data: maskData,
|
|
|
|
|
|
source: currentEditingProfile ? "base" : "base",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (profileData?.objects?.mask) {
|
|
|
|
|
|
for (const [maskId, maskData] of Object.entries(
|
|
|
|
|
|
profileData.objects.mask,
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (!baseGlobalObjectMaskNames.has(maskId)) {
|
|
|
|
|
|
mergedGlobalObjectMasks.set(maskId, {
|
|
|
|
|
|
data: maskData,
|
|
|
|
|
|
source: "profile",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let objectMaskIndex = 0;
|
|
|
|
|
|
const globalObjectMasks: Polygon[] = [];
|
|
|
|
|
|
for (const [
|
|
|
|
|
|
maskId,
|
|
|
|
|
|
{ data: maskData, source },
|
|
|
|
|
|
] of mergedGlobalObjectMasks) {
|
|
|
|
|
|
const isBase = source === "base" && !!currentEditingProfile;
|
|
|
|
|
|
const baseColor = [128, 128, 128];
|
|
|
|
|
|
globalObjectMasks.push({
|
2026-02-28 17:04:43 +03:00
|
|
|
|
type: "object_mask" as PolygonType,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
typeIndex: objectMaskIndex,
|
2026-02-28 17:04:43 +03:00
|
|
|
|
camera: cameraConfig.name,
|
|
|
|
|
|
name: maskId,
|
|
|
|
|
|
friendly_name: maskData.friendly_name,
|
|
|
|
|
|
enabled: maskData.enabled,
|
|
|
|
|
|
enabled_in_config: maskData.enabled_in_config,
|
|
|
|
|
|
objects: [],
|
|
|
|
|
|
points: interpolatePoints(
|
|
|
|
|
|
parseCoordinates(maskData.coordinates),
|
|
|
|
|
|
1,
|
|
|
|
|
|
1,
|
|
|
|
|
|
scaledWidth,
|
|
|
|
|
|
scaledHeight,
|
|
|
|
|
|
),
|
|
|
|
|
|
distances: [],
|
|
|
|
|
|
isFinished: true,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
color: isBase ? dimColor(baseColor) : baseColor,
|
|
|
|
|
|
polygonSource: currentEditingProfile ? source : undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
objectMaskIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
objectMaskIndex = globalObjectMasks.length;
|
|
|
|
|
|
|
|
|
|
|
|
// Build per-object filter mask names for profile tracking
|
|
|
|
|
|
const baseFilterMaskNames = new Set<string>();
|
|
|
|
|
|
for (const [, filterConfig] of Object.entries(
|
|
|
|
|
|
cameraConfig.objects.filters,
|
|
|
|
|
|
)) {
|
|
|
|
|
|
for (const maskId of Object.keys(filterConfig.mask || {})) {
|
|
|
|
|
|
if (!maskId.startsWith("global_")) {
|
|
|
|
|
|
baseFilterMaskNames.add(maskId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
const profileFilterMaskNames = new Set<string>();
|
|
|
|
|
|
if (profileData?.objects?.filters) {
|
|
|
|
|
|
for (const [, filterConfig] of Object.entries(
|
|
|
|
|
|
profileData.objects.filters,
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (filterConfig?.mask) {
|
|
|
|
|
|
for (const maskId of Object.keys(filterConfig.mask)) {
|
|
|
|
|
|
profileFilterMaskNames.add(maskId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
// Per-object filter masks (base)
|
|
|
|
|
|
const objectMasks: Polygon[] = Object.entries(
|
|
|
|
|
|
cameraConfig.objects.filters,
|
|
|
|
|
|
)
|
2026-02-28 17:04:43 +03:00
|
|
|
|
.filter(
|
|
|
|
|
|
([, filterConfig]) =>
|
|
|
|
|
|
filterConfig.mask && Object.keys(filterConfig.mask).length > 0,
|
|
|
|
|
|
)
|
|
|
|
|
|
.flatMap(([objectName, filterConfig]): Polygon[] => {
|
|
|
|
|
|
return Object.entries(filterConfig.mask || {}).flatMap(
|
|
|
|
|
|
([maskId, maskData]) => {
|
|
|
|
|
|
if (maskId.startsWith("global_")) {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
const source: "base" | "override" = currentEditingProfile
|
|
|
|
|
|
? profileFilterMaskNames.has(maskId)
|
|
|
|
|
|
? "override"
|
|
|
|
|
|
: "base"
|
|
|
|
|
|
: "base";
|
|
|
|
|
|
const isBase = source === "base" && !!currentEditingProfile;
|
|
|
|
|
|
|
|
|
|
|
|
// If override, use profile data
|
|
|
|
|
|
const finalData =
|
|
|
|
|
|
source === "override" && profileData?.objects?.filters
|
|
|
|
|
|
? (profileData.objects.filters[objectName]?.mask?.[maskId] ??
|
|
|
|
|
|
maskData)
|
|
|
|
|
|
: maskData;
|
|
|
|
|
|
|
|
|
|
|
|
const baseColor = [128, 128, 128];
|
|
|
|
|
|
const newMask: Polygon = {
|
2026-02-28 17:04:43 +03:00
|
|
|
|
type: "object_mask" as PolygonType,
|
|
|
|
|
|
typeIndex: objectMaskIndex,
|
|
|
|
|
|
camera: cameraConfig.name,
|
|
|
|
|
|
name: maskId,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
friendly_name: finalData.friendly_name,
|
|
|
|
|
|
enabled: finalData.enabled,
|
|
|
|
|
|
enabled_in_config: finalData.enabled_in_config,
|
2026-02-28 17:04:43 +03:00
|
|
|
|
objects: [objectName],
|
|
|
|
|
|
points: interpolatePoints(
|
2026-03-11 15:16:44 +03:00
|
|
|
|
parseCoordinates(finalData.coordinates),
|
2026-02-28 17:04:43 +03:00
|
|
|
|
1,
|
|
|
|
|
|
1,
|
|
|
|
|
|
scaledWidth,
|
|
|
|
|
|
scaledHeight,
|
|
|
|
|
|
),
|
|
|
|
|
|
distances: [],
|
|
|
|
|
|
isFinished: true,
|
2026-03-11 15:16:44 +03:00
|
|
|
|
color: isBase ? dimColor(baseColor) : baseColor,
|
|
|
|
|
|
polygonSource: currentEditingProfile ? source : undefined,
|
2026-02-28 17:04:43 +03:00
|
|
|
|
};
|
|
|
|
|
|
objectMaskIndex++;
|
2024-04-19 14:34:07 +03:00
|
|
|
|
return [newMask];
|
2026-02-28 17:04:43 +03:00
|
|
|
|
},
|
|
|
|
|
|
);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
// Add profile-only per-object filter masks
|
|
|
|
|
|
if (profileData?.objects?.filters) {
|
|
|
|
|
|
for (const [objectName, filterConfig] of Object.entries(
|
|
|
|
|
|
profileData.objects.filters,
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (filterConfig?.mask) {
|
|
|
|
|
|
for (const [maskId, maskData] of Object.entries(
|
|
|
|
|
|
filterConfig.mask,
|
|
|
|
|
|
)) {
|
|
|
|
|
|
if (!baseFilterMaskNames.has(maskId) && maskData) {
|
|
|
|
|
|
const baseColor = [128, 128, 128];
|
|
|
|
|
|
objectMasks.push({
|
|
|
|
|
|
type: "object_mask" as PolygonType,
|
|
|
|
|
|
typeIndex: objectMaskIndex,
|
|
|
|
|
|
camera: cameraConfig.name,
|
|
|
|
|
|
name: maskId,
|
|
|
|
|
|
friendly_name: maskData.friendly_name,
|
|
|
|
|
|
enabled: maskData.enabled,
|
|
|
|
|
|
enabled_in_config: maskData.enabled_in_config,
|
|
|
|
|
|
objects: [objectName],
|
|
|
|
|
|
points: interpolatePoints(
|
|
|
|
|
|
parseCoordinates(maskData.coordinates),
|
|
|
|
|
|
1,
|
|
|
|
|
|
1,
|
|
|
|
|
|
scaledWidth,
|
|
|
|
|
|
scaledHeight,
|
|
|
|
|
|
),
|
|
|
|
|
|
distances: [],
|
|
|
|
|
|
isFinished: true,
|
|
|
|
|
|
color: baseColor,
|
|
|
|
|
|
polygonSource: "profile",
|
|
|
|
|
|
});
|
|
|
|
|
|
objectMaskIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
setAllPolygons([
|
|
|
|
|
|
...zones,
|
|
|
|
|
|
...motionMasks,
|
|
|
|
|
|
...globalObjectMasks,
|
|
|
|
|
|
...objectMasks,
|
|
|
|
|
|
]);
|
2026-03-01 23:41:33 +03:00
|
|
|
|
// Don't overwrite editingPolygons during editing – layout shifts
|
|
|
|
|
|
// from switching to the edit pane can trigger a resize which
|
|
|
|
|
|
// recalculates scaledWidth/scaledHeight and would discard the
|
|
|
|
|
|
// newly-added polygon. Instead, rescale existing points
|
|
|
|
|
|
// proportionally.
|
|
|
|
|
|
if (editPaneRef.current === undefined) {
|
|
|
|
|
|
setEditingPolygons([
|
|
|
|
|
|
...zones,
|
|
|
|
|
|
...motionMasks,
|
|
|
|
|
|
...globalObjectMasks,
|
|
|
|
|
|
...objectMasks,
|
|
|
|
|
|
]);
|
|
|
|
|
|
} else if (
|
|
|
|
|
|
prevScaledRef.current &&
|
|
|
|
|
|
(prevScaledRef.current.w !== scaledWidth ||
|
|
|
|
|
|
prevScaledRef.current.h !== scaledHeight)
|
|
|
|
|
|
) {
|
|
|
|
|
|
const prevW = prevScaledRef.current.w;
|
|
|
|
|
|
const prevH = prevScaledRef.current.h;
|
|
|
|
|
|
setEditingPolygons((prev) =>
|
|
|
|
|
|
prev.map((poly) => ({
|
|
|
|
|
|
...poly,
|
|
|
|
|
|
points: poly.points.map(([x, y]) => [
|
|
|
|
|
|
(x / prevW) * scaledWidth,
|
|
|
|
|
|
(y / prevH) * scaledHeight,
|
|
|
|
|
|
]),
|
|
|
|
|
|
})),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
prevScaledRef.current = { w: scaledWidth, h: scaledHeight };
|
2024-04-19 14:34:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
// we know that these deps are correct
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2026-03-11 15:16:44 +03:00
|
|
|
|
}, [
|
|
|
|
|
|
cameraConfig,
|
|
|
|
|
|
containerRef,
|
|
|
|
|
|
scaledHeight,
|
|
|
|
|
|
scaledWidth,
|
|
|
|
|
|
currentEditingProfile,
|
|
|
|
|
|
dimColor,
|
|
|
|
|
|
]);
|
2024-04-19 14:34:07 +03:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (editPane === undefined) {
|
|
|
|
|
|
setEditingPolygons([...allPolygons]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// we know that these deps are correct
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
}, [setEditingPolygons, allPolygons]);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (selectedCamera) {
|
|
|
|
|
|
setActivePolygonIndex(undefined);
|
|
|
|
|
|
setEditPane(undefined);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [selectedCamera]);
|
|
|
|
|
|
|
2026-03-11 15:16:44 +03:00
|
|
|
|
// Cancel editing when profile selection changes
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (editPaneRef.current !== undefined) {
|
|
|
|
|
|
handleCancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
// we only want to react to profile changes
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
}, [currentEditingProfile]);
|
|
|
|
|
|
|
2025-02-11 19:08:28 +03:00
|
|
|
|
useSearchEffect("object_mask", (coordinates: string) => {
|
|
|
|
|
|
if (!scaledWidth || !scaledHeight || isLoading) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
// convert box points string to points array
|
|
|
|
|
|
const points = coordinates.split(",").map((p) => parseFloat(p));
|
|
|
|
|
|
|
|
|
|
|
|
const [x1, y1, w, h] = points;
|
|
|
|
|
|
|
|
|
|
|
|
// bottom center
|
|
|
|
|
|
const centerX = x1 + w / 2;
|
|
|
|
|
|
const bottomY = y1 + h;
|
|
|
|
|
|
|
|
|
|
|
|
const centerXAbs = centerX * scaledWidth;
|
|
|
|
|
|
const bottomYAbs = bottomY * scaledHeight;
|
|
|
|
|
|
|
|
|
|
|
|
// padding and clamp
|
|
|
|
|
|
const minPadding = 0.1 * w * scaledWidth;
|
|
|
|
|
|
const maxPadding = 0.3 * w * scaledWidth;
|
|
|
|
|
|
const padding = Math.min(
|
|
|
|
|
|
Math.max(minPadding, 0.15 * w * scaledWidth),
|
|
|
|
|
|
maxPadding,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const top = Math.max(0, bottomYAbs - padding);
|
|
|
|
|
|
const bottom = Math.min(scaledHeight, bottomYAbs + padding);
|
|
|
|
|
|
const left = Math.max(0, centerXAbs - padding);
|
|
|
|
|
|
const right = Math.min(scaledWidth, centerXAbs + padding);
|
|
|
|
|
|
|
|
|
|
|
|
const paddedBox = [
|
|
|
|
|
|
[left, top],
|
|
|
|
|
|
[right, top],
|
|
|
|
|
|
[right, bottom],
|
|
|
|
|
|
[left, bottom],
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
setEditPane("object_mask");
|
|
|
|
|
|
setActivePolygonIndex(undefined);
|
|
|
|
|
|
handleNewPolygon("object_mask", paddedBox);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-04-27 20:02:01 +03:00
|
|
|
|
useEffect(() => {
|
2025-03-16 18:36:20 +03:00
|
|
|
|
document.title = t("documentTitle.masksAndZones");
|
|
|
|
|
|
}, [t]);
|
2024-04-27 20:02:01 +03:00
|
|
|
|
|
2024-04-19 14:34:07 +03:00
|
|
|
|
if (!cameraConfig && !selectedCamera) {
|
|
|
|
|
|
return <ActivityIndicator />;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{cameraConfig && editingPolygons && (
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="flex size-full flex-col md:flex-row">
|
2024-05-04 22:54:50 +03:00
|
|
|
|
<Toaster position="top-center" closeButton={true} />
|
2026-03-01 23:41:33 +03:00
|
|
|
|
<div className="scrollbar-container order-last mb-2 mt-2 flex h-full w-full flex-col overflow-y-auto rounded-lg border-[1px] border-secondary-foreground bg-background_alt p-2 md:order-none md:mr-3 md:mt-0 md:w-3/12 md:min-w-0 md:shrink-0">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
{editPane == "zone" && (
|
|
|
|
|
|
<ZoneEditPane
|
|
|
|
|
|
polygons={editingPolygons}
|
|
|
|
|
|
setPolygons={setEditingPolygons}
|
|
|
|
|
|
activePolygonIndex={activePolygonIndex}
|
|
|
|
|
|
scaledWidth={scaledWidth}
|
|
|
|
|
|
scaledHeight={scaledHeight}
|
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
|
onCancel={handleCancel}
|
|
|
|
|
|
onSave={handleSave}
|
2025-02-10 23:23:42 +03:00
|
|
|
|
setActiveLine={setActiveLine}
|
2025-02-11 19:08:28 +03:00
|
|
|
|
snapPoints={snapPoints}
|
|
|
|
|
|
setSnapPoints={setSnapPoints}
|
2026-03-11 15:16:44 +03:00
|
|
|
|
editingProfile={currentEditingProfile}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{editPane == "motion_mask" && (
|
|
|
|
|
|
<MotionMaskEditPane
|
|
|
|
|
|
polygons={editingPolygons}
|
|
|
|
|
|
setPolygons={setEditingPolygons}
|
|
|
|
|
|
activePolygonIndex={activePolygonIndex}
|
|
|
|
|
|
scaledWidth={scaledWidth}
|
|
|
|
|
|
scaledHeight={scaledHeight}
|
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
|
onCancel={handleCancel}
|
|
|
|
|
|
onSave={handleSave}
|
2025-02-11 19:08:28 +03:00
|
|
|
|
snapPoints={snapPoints}
|
|
|
|
|
|
setSnapPoints={setSnapPoints}
|
2026-03-11 15:16:44 +03:00
|
|
|
|
editingProfile={currentEditingProfile}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{editPane == "object_mask" && (
|
|
|
|
|
|
<ObjectMaskEditPane
|
|
|
|
|
|
polygons={editingPolygons}
|
|
|
|
|
|
setPolygons={setEditingPolygons}
|
|
|
|
|
|
activePolygonIndex={activePolygonIndex}
|
|
|
|
|
|
scaledWidth={scaledWidth}
|
|
|
|
|
|
scaledHeight={scaledHeight}
|
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
|
onCancel={handleCancel}
|
|
|
|
|
|
onSave={handleSave}
|
2025-02-11 19:08:28 +03:00
|
|
|
|
snapPoints={snapPoints}
|
|
|
|
|
|
setSnapPoints={setSnapPoints}
|
2026-03-11 15:16:44 +03:00
|
|
|
|
editingProfile={currentEditingProfile}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{editPane === undefined && (
|
|
|
|
|
|
<>
|
2026-03-11 15:16:44 +03:00
|
|
|
|
<div className="mb-2 flex items-center justify-between">
|
|
|
|
|
|
<Heading as="h4">{t("menu.masksAndZones")}</Heading>
|
|
|
|
|
|
</div>
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="flex w-full flex-col">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
{(selectedZoneMask === undefined ||
|
|
|
|
|
|
selectedZoneMask.includes("zone" as PolygonType)) && (
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="mt-0 pt-0 last:border-b-[1px] last:border-secondary last:pb-3">
|
|
|
|
|
|
<div className="my-3 flex flex-row items-center justify-between">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<HoverCard>
|
|
|
|
|
|
<HoverCardTrigger asChild>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
<div className="text-md cursor-default">
|
|
|
|
|
|
{t("masksAndZones.zones.label")}
|
|
|
|
|
|
</div>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</HoverCardTrigger>
|
|
|
|
|
|
<HoverCardContent>
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="my-2 flex flex-col gap-2 text-sm text-primary-variant">
|
2025-03-17 15:26:01 +03:00
|
|
|
|
<p>{t("masksAndZones.zones.desc.title")}</p>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<div className="flex items-center text-primary">
|
|
|
|
|
|
<Link
|
2025-05-28 15:10:45 +03:00
|
|
|
|
to={getLocaleDocUrl("configuration/zones")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
target="_blank"
|
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
|
className="inline"
|
|
|
|
|
|
>
|
2025-08-23 01:19:00 +03:00
|
|
|
|
{t("readTheDocumentation", { ns: "common" })}
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<LuExternalLink className="ml-2 inline-flex size-3" />
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</Link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</HoverCardContent>
|
|
|
|
|
|
</HoverCard>
|
|
|
|
|
|
<Tooltip>
|
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="secondary"
|
2024-05-14 18:06:44 +03:00
|
|
|
|
className="size-6 rounded-md bg-secondary-foreground p-1 text-background"
|
2025-03-16 18:36:20 +03:00
|
|
|
|
aria-label={t("masksAndZones.zones.add")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setEditPane("zone");
|
|
|
|
|
|
handleNewPolygon("zone");
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<LuPlus />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</TooltipTrigger>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
<TooltipContent>
|
|
|
|
|
|
{t("masksAndZones.zones.add")}
|
|
|
|
|
|
</TooltipContent>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</Tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{allPolygons
|
|
|
|
|
|
.flatMap((polygon, index) =>
|
|
|
|
|
|
polygon.type === "zone" ? [{ polygon, index }] : [],
|
|
|
|
|
|
)
|
|
|
|
|
|
.map(({ polygon, index }) => (
|
|
|
|
|
|
<PolygonItem
|
|
|
|
|
|
key={index}
|
|
|
|
|
|
polygon={polygon}
|
|
|
|
|
|
index={index}
|
|
|
|
|
|
hoveredPolygonIndex={hoveredPolygonIndex}
|
|
|
|
|
|
setHoveredPolygonIndex={setHoveredPolygonIndex}
|
|
|
|
|
|
setActivePolygonIndex={setActivePolygonIndex}
|
|
|
|
|
|
setEditPane={setEditPane}
|
|
|
|
|
|
handleCopyCoordinates={handleCopyCoordinates}
|
2026-02-28 17:04:43 +03:00
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
|
loadingPolygonIndex={loadingPolygonIndex}
|
|
|
|
|
|
setLoadingPolygonIndex={setLoadingPolygonIndex}
|
2026-03-11 15:16:44 +03:00
|
|
|
|
editingProfile={currentEditingProfile}
|
|
|
|
|
|
allProfileNames={profileState?.allProfileNames}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{(selectedZoneMask === undefined ||
|
|
|
|
|
|
selectedZoneMask.includes(
|
|
|
|
|
|
"motion_mask" as PolygonType,
|
|
|
|
|
|
)) && (
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="mt-3 border-t-[1px] border-secondary pt-3 first:mt-0 first:border-transparent first:pt-0 last:border-b-[1px] last:pb-3">
|
|
|
|
|
|
<div className="my-3 flex flex-row items-center justify-between">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<HoverCard>
|
|
|
|
|
|
<HoverCardTrigger asChild>
|
|
|
|
|
|
<div className="text-md cursor-default">
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{t("masksAndZones.motionMasks.label")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
</HoverCardTrigger>
|
|
|
|
|
|
<HoverCardContent>
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="my-2 flex flex-col gap-2 text-sm text-primary-variant">
|
2025-03-17 15:26:01 +03:00
|
|
|
|
<p>{t("masksAndZones.motionMasks.desc.title")}</p>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<div className="flex items-center text-primary">
|
|
|
|
|
|
<Link
|
2025-05-28 15:10:45 +03:00
|
|
|
|
to={getLocaleDocUrl(
|
|
|
|
|
|
"configuration/masks#motion-masks",
|
|
|
|
|
|
)}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
target="_blank"
|
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
|
className="inline"
|
|
|
|
|
|
>
|
2025-08-23 01:19:00 +03:00
|
|
|
|
{t("readTheDocumentation", { ns: "common" })}
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<LuExternalLink className="ml-2 inline-flex size-3" />
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</Link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</HoverCardContent>
|
|
|
|
|
|
</HoverCard>
|
|
|
|
|
|
<Tooltip>
|
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="secondary"
|
2024-05-14 18:06:44 +03:00
|
|
|
|
className="size-6 rounded-md bg-secondary-foreground p-1 text-background"
|
2025-03-16 18:36:20 +03:00
|
|
|
|
aria-label={t("masksAndZones.motionMasks.add")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setEditPane("motion_mask");
|
|
|
|
|
|
handleNewPolygon("motion_mask");
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<LuPlus />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</TooltipTrigger>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
<TooltipContent>
|
|
|
|
|
|
{t("masksAndZones.motionMasks.add")}
|
|
|
|
|
|
</TooltipContent>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</Tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{allPolygons
|
|
|
|
|
|
.flatMap((polygon, index) =>
|
|
|
|
|
|
polygon.type === "motion_mask"
|
|
|
|
|
|
? [{ polygon, index }]
|
|
|
|
|
|
: [],
|
|
|
|
|
|
)
|
|
|
|
|
|
.map(({ polygon, index }) => (
|
|
|
|
|
|
<PolygonItem
|
|
|
|
|
|
key={index}
|
|
|
|
|
|
polygon={polygon}
|
|
|
|
|
|
index={index}
|
|
|
|
|
|
hoveredPolygonIndex={hoveredPolygonIndex}
|
|
|
|
|
|
setHoveredPolygonIndex={setHoveredPolygonIndex}
|
|
|
|
|
|
setActivePolygonIndex={setActivePolygonIndex}
|
|
|
|
|
|
setEditPane={setEditPane}
|
|
|
|
|
|
handleCopyCoordinates={handleCopyCoordinates}
|
2026-02-28 17:04:43 +03:00
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
|
loadingPolygonIndex={loadingPolygonIndex}
|
|
|
|
|
|
setLoadingPolygonIndex={setLoadingPolygonIndex}
|
2026-03-11 15:16:44 +03:00
|
|
|
|
editingProfile={currentEditingProfile}
|
|
|
|
|
|
allProfileNames={profileState?.allProfileNames}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{(selectedZoneMask === undefined ||
|
|
|
|
|
|
selectedZoneMask.includes(
|
|
|
|
|
|
"object_mask" as PolygonType,
|
|
|
|
|
|
)) && (
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="mt-3 border-t-[1px] border-secondary pt-3 first:mt-0 first:border-transparent first:pt-0 last:border-b-[1px] last:pb-3">
|
|
|
|
|
|
<div className="my-3 flex flex-row items-center justify-between">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<HoverCard>
|
|
|
|
|
|
<HoverCardTrigger asChild>
|
|
|
|
|
|
<div className="text-md cursor-default">
|
2025-03-16 18:36:20 +03:00
|
|
|
|
{t("masksAndZones.objectMasks.label")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
</HoverCardTrigger>
|
|
|
|
|
|
<HoverCardContent>
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="my-2 flex flex-col gap-2 text-sm text-primary-variant">
|
2025-03-17 15:26:01 +03:00
|
|
|
|
<p>{t("masksAndZones.objectMasks.desc.title")}</p>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
<div className="flex items-center text-primary">
|
|
|
|
|
|
<Link
|
2025-05-28 15:10:45 +03:00
|
|
|
|
to={getLocaleDocUrl(
|
|
|
|
|
|
"configuration/masks#object-filter-masks",
|
|
|
|
|
|
)}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
target="_blank"
|
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
|
className="inline"
|
|
|
|
|
|
>
|
2025-08-23 01:19:00 +03:00
|
|
|
|
{t("readTheDocumentation", { ns: "common" })}
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<LuExternalLink className="ml-2 inline-flex size-3" />
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</Link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</HoverCardContent>
|
|
|
|
|
|
</HoverCard>
|
|
|
|
|
|
<Tooltip>
|
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="secondary"
|
2024-05-14 18:06:44 +03:00
|
|
|
|
className="size-6 rounded-md bg-secondary-foreground p-1 text-background"
|
2025-03-16 18:36:20 +03:00
|
|
|
|
aria-label={t("masksAndZones.objectMasks.add")}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setEditPane("object_mask");
|
|
|
|
|
|
handleNewPolygon("object_mask");
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<LuPlus />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</TooltipTrigger>
|
2025-03-16 18:36:20 +03:00
|
|
|
|
<TooltipContent>
|
|
|
|
|
|
{t("masksAndZones.objectMasks.add")}
|
|
|
|
|
|
</TooltipContent>
|
2024-04-19 14:34:07 +03:00
|
|
|
|
</Tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{allPolygons
|
|
|
|
|
|
.flatMap((polygon, index) =>
|
|
|
|
|
|
polygon.type === "object_mask"
|
|
|
|
|
|
? [{ polygon, index }]
|
|
|
|
|
|
: [],
|
|
|
|
|
|
)
|
|
|
|
|
|
.map(({ polygon, index }) => (
|
|
|
|
|
|
<PolygonItem
|
|
|
|
|
|
key={index}
|
|
|
|
|
|
polygon={polygon}
|
|
|
|
|
|
index={index}
|
|
|
|
|
|
hoveredPolygonIndex={hoveredPolygonIndex}
|
|
|
|
|
|
setHoveredPolygonIndex={setHoveredPolygonIndex}
|
|
|
|
|
|
setActivePolygonIndex={setActivePolygonIndex}
|
|
|
|
|
|
setEditPane={setEditPane}
|
|
|
|
|
|
handleCopyCoordinates={handleCopyCoordinates}
|
2026-02-28 17:04:43 +03:00
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
|
loadingPolygonIndex={loadingPolygonIndex}
|
|
|
|
|
|
setLoadingPolygonIndex={setLoadingPolygonIndex}
|
2026-03-11 15:16:44 +03:00
|
|
|
|
editingProfile={currentEditingProfile}
|
|
|
|
|
|
allProfileNames={profileState?.allProfileNames}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
|
|
|
|
ref={containerRef}
|
2025-11-26 16:23:51 +03:00
|
|
|
|
className={cn(
|
2026-03-01 23:41:33 +03:00
|
|
|
|
"flex max-h-[50%] min-w-0 md:h-dvh md:max-h-full md:w-7/12 md:grow",
|
2025-11-26 16:23:51 +03:00
|
|
|
|
isDesktop && "md:mr-3",
|
|
|
|
|
|
)}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
>
|
2024-05-14 18:06:44 +03:00
|
|
|
|
<div className="mx-auto flex size-full flex-row justify-center">
|
2024-04-19 14:34:07 +03:00
|
|
|
|
{cameraConfig &&
|
|
|
|
|
|
scaledWidth &&
|
|
|
|
|
|
scaledHeight &&
|
|
|
|
|
|
editingPolygons ? (
|
|
|
|
|
|
<PolygonCanvas
|
2024-05-04 17:37:35 +03:00
|
|
|
|
containerRef={containerRef}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
camera={cameraConfig.name}
|
|
|
|
|
|
width={scaledWidth}
|
|
|
|
|
|
height={scaledHeight}
|
|
|
|
|
|
polygons={editingPolygons}
|
|
|
|
|
|
setPolygons={setEditingPolygons}
|
|
|
|
|
|
activePolygonIndex={activePolygonIndex}
|
|
|
|
|
|
hoveredPolygonIndex={hoveredPolygonIndex}
|
|
|
|
|
|
selectedZoneMask={selectedZoneMask}
|
2025-02-10 23:23:42 +03:00
|
|
|
|
activeLine={activeLine}
|
2025-07-18 17:28:52 +03:00
|
|
|
|
snapPoints={snapPoints}
|
2024-04-19 14:34:07 +03:00
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Skeleton className="size-full" />
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|