Spaces:
Running
Running
File size: 9,802 Bytes
b4f9490 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
<template>
<div
class="object-item"
:class="{ 'selected': isSelected }"
@click="toggleSelection"
>
<div class="object-id">
<span>{{ objectId }}</span>
</div>
<div class="object-timeline" ref="timelineRef">
<div class="timeline-line"></div>
<!-- Points pour chaque annotation -->
<div
v-for="(frameKey, index) in annotatedFrames"
:key="index"
class="annotation-point"
:style="{
left: `${calculatePositionExact(parseInt(frameKey))}%`,
backgroundColor: getObjectColor
}"
:title="`Frame ${frameKey}`"
@click.stop="goToFrame(parseInt(frameKey))"
></div>
</div>
</div>
<!-- Popup de confirmation simplifiée -->
<div v-if="showDeleteConfirm" class="delete-overlay" @click="cancelDelete">
<div class="delete-modal" @click.stop>
<h3>Supprimer {{ objectId }} ?</h3>
<p>Cette action est irréversible.</p>
<div class="delete-actions">
<button class="btn-cancel" @click="cancelDelete">Annuler</button>
<button class="btn-delete" @click="confirmDelete">Supprimer</button>
</div>
</div>
</div>
</template>
<script>
import { useAnnotationStore } from '@/stores/annotationStore'
import { useVideoStore } from '@/stores/videoStore'
import { computed, ref, onMounted, onUnmounted } from 'vue'
export default {
name: 'ObjectItem',
props: {
objectId: {
type: String,
default: 'object1'
},
colorIndex: {
type: Number,
default: 0
}
},
setup(props) {
const annotationStore = useAnnotationStore()
const videoStore = useVideoStore()
const timelineRef = ref(null)
const showDeleteConfirm = ref(false)
// Keyboard shortcut handler
const handleKeyDown = (event) => {
// Add new object when pressing 'N' key
if (event.key === 'n' || event.key === 'N') {
// Prevent default behavior (like typing 'n' in an input field)
event.preventDefault()
// Only process the event if this is the first object item
// This prevents multiple objects from being created when multiple ObjectItems exist
if (props.objectId !== Object.keys(annotationStore.objects)[0]) {
return;
}
// Check available methods and use the correct one
if (typeof annotationStore.addObject === 'function') {
annotationStore.addObject();
} else if (typeof annotationStore.createNewObject === 'function') {
annotationStore.createNewObject();
} else {
// Fallback: Create a new object ID based on the last object ID + 1
const objectIds = Object.keys(annotationStore.objects);
let lastId = 0;
// Find the highest numeric ID
objectIds.forEach(id => {
// Extract numeric part from objectX format
const numericPart = parseInt(id.replace('object', ''));
if (!isNaN(numericPart) && numericPart > lastId) {
lastId = numericPart;
}
});
// Create new object with ID = last ID + 1
const newObjectId = `object${lastId + 1}`;
annotationStore.objects[newObjectId] = {
id: newObjectId,
color: annotationStore.getNextColor(),
// Add any other required properties
};
console.log(`Created new object: ${newObjectId}`);
}
}
// Delete selected object when pressing Ctrl+Delete key
if (event.key === 'Delete' && event.ctrlKey && annotationStore.selectedObjectId === props.objectId) {
event.preventDefault()
showDeleteConfirm.value = true
}
// Fermer la popup avec Escape
if (event.key === 'Escape' && showDeleteConfirm.value) {
event.preventDefault()
showDeleteConfirm.value = false
}
}
// Add and remove event listeners
onMounted(() => {
window.addEventListener('keydown', handleKeyDown)
})
onUnmounted(() => {
window.removeEventListener('keydown', handleKeyDown)
})
// Vérifier si cet objet est actuellement sélectionné
const isSelected = computed(() => {
return annotationStore.selectedObjectId === props.objectId
})
// Fonction pour basculer la sélection de l'objet
const toggleSelection = () => {
if (isSelected.value) {
annotationStore.deselectObject()
} else {
annotationStore.selectObject(props.objectId)
}
}
// Fonctions pour la popup de confirmation
const confirmDelete = () => {
annotationStore.deleteObject(props.objectId)
showDeleteConfirm.value = false
}
const cancelDelete = () => {
showDeleteConfirm.value = false
}
// Récupérer toutes les frames où cet objet a des annotations
const annotatedFrames = computed(() => {
const frames = []
Object.keys(annotationStore.frameAnnotations).forEach(frameKey => {
const hasObjectAnnotation = annotationStore.frameAnnotations[frameKey].some(
annotation => annotation.objectId === props.objectId
)
if (hasObjectAnnotation) {
frames.push(frameKey)
}
})
return frames
})
// Obtenir la couleur de l'objet
const getObjectColor = computed(() => {
return annotationStore.objects[props.objectId]?.color || '#4CAF50'
})
// Calculer la position en pourcentage pour une frame donnée
const calculatePositionExact = (frameNumber) => {
const frameRate = annotationStore.currentSession.frameRate || 30
const timeInSeconds = frameNumber / frameRate
const videoDuration = videoStore.duration || videoStore.selectedVideo?.duration || 0
if (!videoDuration || videoDuration <= 0) {
console.warn('Attention: Durée de vidéo non disponible, utilisation d\'une valeur par défaut')
return 0 // Ou retourner une position par défaut
}
return (timeInSeconds / videoDuration) * 100
}
// Fonction pour naviguer vers une frame spécifique
const goToFrame = (frameNumber) => {
// Convertir le numéro de frame en temps (secondes)
const frameRate = annotationStore.currentSession.frameRate || 30
// Utiliser une valeur exacte pour le temps en secondes
// Ajouter un petit décalage (0.001) pour éviter les problèmes d'arrondi
const timeInSeconds = frameNumber / frameRate + 0.001
// Mettre à jour le temps courant dans le videoStore
videoStore.setCurrentTime(timeInSeconds)
// Utiliser la méthode seek si disponible
if (videoStore.seek) {
videoStore.seek(timeInSeconds)
} else {
// Fallback: essayer d'accéder directement à l'élément vidéo
const videoElement = document.querySelector('video')
if (videoElement) {
videoElement.currentTime = timeInSeconds
}
}
// Forcer la mise à jour de l'interface
videoStore.updateProgressBar(timeInSeconds)
}
return {
annotatedFrames,
calculatePositionExact,
getObjectColor,
timelineRef,
isSelected,
toggleSelection,
goToFrame,
showDeleteConfirm,
confirmDelete,
cancelDelete
}
}
}
</script>
<style scoped>
.object-item {
display: flex;
height: 24px;
margin-bottom: 18px;
align-items: center;
gap: 14px;
cursor: pointer;
transition: background-color 0.2s ease;
border-radius: 4px;
padding: 2px 4px;
position: relative;
}
.object-item:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.object-item.selected {
background-color: rgba(255, 255, 255, 0.2);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.object-id {
width: 35px;
font-weight: bold;
font-size: 0.9rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: white;
}
.object-timeline {
flex-grow: 1;
height: 100%;
position: relative;
border-radius: 4px;
display: flex;
align-items: center;
border-color: white;
}
.timeline-line {
height: 1px;
width: 100%;
background-color: white;
}
.annotation-point {
position: absolute;
width: 8px;
height: 8px;
background-color: #4CAF50;
border-radius: 50%;
transform: translateX(-50%);
z-index: 2;
}
/* Popup de confirmation simplifiée */
.delete-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.delete-modal {
background: #2c2c2c;
border-radius: 8px;
padding: 20px;
max-width: 300px;
width: 90%;
text-align: center;
color: white;
}
.delete-modal h3 {
margin: 0 0 12px 0;
font-size: 1.1rem;
color: #fff;
}
.delete-modal p {
margin: 0 0 20px 0;
color: #ccc;
font-size: 0.9rem;
}
.delete-actions {
display: flex;
gap: 12px;
justify-content: center;
}
.btn-cancel,
.btn-delete {
padding: 8px 16px;
border: none;
border-radius: 4px;
font-size: 0.9rem;
cursor: pointer;
transition: all 0.2s ease;
}
.btn-cancel {
background: #555;
color: white;
}
.btn-cancel:hover {
background: #666;
}
.btn-delete {
background: #dc3545;
color: white;
}
.btn-delete:hover {
background: #c82333;
}
</style> |