|
154 | 154 | UIStore.setShowCreateTools(true) |
155 | 155 | UIStore.setShowCreatePoint(false) |
156 | 156 | UIStore.setShowCreateAOI(false) |
| 157 | + UIStore.setShowCreateVOI(false) |
157 | 158 | } |
158 | 159 |
|
159 | 160 | const UIStore = useUIStore() |
|
166 | 167 | const max_x = ref("") |
167 | 168 | const max_y = ref("") |
168 | 169 | const z = ref("") |
169 | | -
|
170 | 170 | const loading = ref(false) |
171 | 171 |
|
172 | 172 | const isFormFilled = computed(() => { |
|
182 | 182 | UIStore.setShowCreateAOI(false) |
183 | 183 | } |
184 | 184 |
|
185 | | - const safeParseFloat = (value) => { |
186 | | - const sanitizedValue = String(value).trim().replace(",", ".") |
187 | | - const result = parseFloat(sanitizedValue) |
188 | | - return isNaN(result) && sanitizedValue === "" ? NaN : result |
189 | | - } |
190 | | -
|
191 | 185 | function visibleBoundingBox() { |
192 | 186 | if (!hybridViewerStore.genericRenderWindow.value) |
193 | 187 | return [-1, 1, -1, 1, -1, 1] |
|
217 | 211 | max_x.value = newMaxX.toFixed(2) |
218 | 212 | min_y.value = newMinY.toFixed(2) |
219 | 213 | max_y.value = newMaxY.toFixed(2) |
220 | | - z.value = (bounds[4] + bounds[5]) / 2 |
| 214 | + z.value = ((bounds[4] + bounds[5]) / 2).toFixed(2) |
221 | 215 | } |
222 | 216 |
|
223 | 217 | onMounted(() => { |
|
229 | 223 | (newVal) => { |
230 | 224 | if (newVal) { |
231 | 225 | initializeAOICoordinates() |
| 226 | + name.value = "" |
232 | 227 | } |
233 | 228 | }, |
234 | 229 | ) |
235 | 230 |
|
| 231 | + const sanitizeNumberString = (str) => { |
| 232 | + if (str == null) return "" |
| 233 | + let value = String(str) |
| 234 | + .replace(/,/g, ".") |
| 235 | + .replace(/[^0-9eE+\-.]/g, "") |
| 236 | + if (/[eE]/.test(value)) { |
| 237 | + const parts = value.split(/[eE]/) |
| 238 | + if (parts.length > 2) { |
| 239 | + value = |
| 240 | + parts.slice(0, 2).join("e") + |
| 241 | + parts |
| 242 | + .slice(2) |
| 243 | + .join("") |
| 244 | + .replace(/[^0-9+\-.]/g, "") |
| 245 | + } |
| 246 | + } |
| 247 | + return value |
| 248 | + } |
| 249 | +
|
| 250 | + const handlePasteAOI = (event) => { |
| 251 | + const pastedText = |
| 252 | + (event && event.clipboardData && event.clipboardData.getData("text")) || |
| 253 | + "" |
| 254 | +
|
| 255 | + if (!pastedText) return |
| 256 | +
|
| 257 | + const coordinates = pastedText.match(/[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g) |
| 258 | + if (!coordinates || coordinates.length === 0) return |
| 259 | +
|
| 260 | + const sanitized = coordinates.map((c) => sanitizeNumberString(c)) |
| 261 | +
|
| 262 | + if (sanitized.length >= 4) { |
| 263 | + min_x.value = sanitized[0] |
| 264 | + min_y.value = sanitized[1] |
| 265 | + max_x.value = sanitized[2] |
| 266 | + max_y.value = sanitized[3] |
| 267 | + event.preventDefault() |
| 268 | + } else if (sanitized.length >= 2) { |
| 269 | + min_x.value = sanitized[0] |
| 270 | + min_y.value = sanitized[1] |
| 271 | + event.preventDefault() |
| 272 | + } |
| 273 | + } |
| 274 | +
|
| 275 | + const sanitizeInputAOI = (value, field) => { |
| 276 | + const sanitizedValue = sanitizeNumberString(value) |
| 277 | + if (field === "min_x") min_x.value = sanitizedValue |
| 278 | + else if (field === "min_y") min_y.value = sanitizedValue |
| 279 | + else if (field === "max_x") max_x.value = sanitizedValue |
| 280 | + else if (field === "max_y") max_y.value = sanitizedValue |
| 281 | + else if (field === "z") z.value = sanitizedValue |
| 282 | + } |
| 283 | +
|
| 284 | + const safeParseFloat = (value) => { |
| 285 | + const sanitizedValue = String(value).trim().replace(",", ".") |
| 286 | + const result = parseFloat(sanitizedValue) |
| 287 | + return isNaN(result) && sanitizedValue === "" ? NaN : result |
| 288 | + } |
| 289 | +
|
236 | 290 | async function registerObject(data) { |
237 | 291 | await viewer_call( |
238 | 292 | { |
|
243 | 297 | }, |
244 | 298 | { |
245 | 299 | response_function: async () => { |
246 | | - const min_x_val = safeParseFloat(min_x.value) |
247 | | - const min_y_val = safeParseFloat(min_y.value) |
248 | | - const max_x_val = safeParseFloat(max_x.value) |
249 | | - const max_y_val = safeParseFloat(max_y.value) |
250 | | - const z_val = safeParseFloat(z.value) |
251 | | -
|
252 | | - const aoiPoints = [ |
253 | | - { x: min_x_val, y: min_y_val }, |
254 | | - { x: max_x_val, y: min_y_val }, |
255 | | - { x: max_x_val, y: max_y_val }, |
256 | | - { x: min_x_val, y: max_y_val }, |
257 | | - ] |
258 | | -
|
259 | | - const itemToAdd = { |
| 300 | + await dataBaseStore.addItem(data.id, { |
260 | 301 | object_type: data.object_type, |
261 | 302 | geode_object: data.geode_object, |
262 | 303 | native_filename: data.native_file_name, |
263 | 304 | viewable_filename: data.viewable_file_name, |
264 | 305 | displayed_name: data.name, |
265 | | - points: aoiPoints, |
266 | | - z: z_val, |
| 306 | + is_aoi: true, |
267 | 307 | vtk_js: { |
268 | 308 | binary_light_viewable: data.binary_light_viewable, |
269 | 309 | }, |
270 | | - } |
271 | | -
|
272 | | - await dataBaseStore.addItem(data.id, itemToAdd) |
273 | | -
|
| 310 | + }) |
274 | 311 | closeDrawer() |
275 | 312 | }, |
276 | 313 | }, |
277 | 314 | ) |
278 | 315 | } |
279 | | - async function createAOI() { |
| 316 | +
|
| 317 | + const createAOI = async () => { |
280 | 318 | const min_x_val = safeParseFloat(min_x.value) |
281 | 319 | const min_y_val = safeParseFloat(min_y.value) |
282 | 320 | const max_x_val = safeParseFloat(max_x.value) |
|
290 | 328 | isNaN(max_y_val) || |
291 | 329 | isNaN(z_val) |
292 | 330 |
|
293 | | - if (hasNaN) { |
294 | | - loading.value = false |
295 | | - return |
296 | | - } |
297 | | -
|
298 | | - if (min_x_val >= max_x_val || min_y_val >= max_y_val) { |
299 | | - loading.value = false |
| 331 | + if ( |
| 332 | + hasNaN || |
| 333 | + min_x_val >= max_x_val || |
| 334 | + min_y_val >= max_y_val || |
| 335 | + !name.value |
| 336 | + ) { |
300 | 337 | return |
301 | 338 | } |
302 | 339 |
|
|
314 | 351 | } |
315 | 352 |
|
316 | 353 | const aoiSchema = back_schemas.opengeodeweb_back.create.create_aoi |
| 354 | +
|
| 355 | + loading.value = true |
317 | 356 | try { |
318 | | - await api_fetch( |
| 357 | + const response = await api_fetch( |
319 | 358 | { |
320 | 359 | schema: aoiSchema, |
321 | 360 | params: aoiData, |
322 | 361 | }, |
323 | 362 | { |
324 | 363 | response_function: async (response) => { |
325 | | - await registerObject(response._data) |
| 364 | + const dataToRegister = { |
| 365 | + ...response._data, |
| 366 | + points: aoiPoints, |
| 367 | + z: z_val, |
| 368 | + } |
| 369 | + await registerObject(dataToRegister) |
326 | 370 | }, |
327 | 371 | }, |
328 | 372 | ) |
|
331 | 375 | loading.value = false |
332 | 376 | } |
333 | 377 | } |
334 | | -
|
335 | | - const sanitizeNumberString = (str) => { |
336 | | - if (str == null) return "" |
337 | | - let value = String(str) |
338 | | - .replace(/,/g, ".") |
339 | | - .replace(/[^0-9eE+\-.]/g, "") |
340 | | - if (/[eE]/.test(value)) { |
341 | | - const parts = value.split(/[eE]/) |
342 | | - if (parts.length > 2) { |
343 | | - value = |
344 | | - parts.slice(0, 2).join("e") + |
345 | | - parts |
346 | | - .slice(2) |
347 | | - .join("") |
348 | | - .replace(/[^0-9+\-.]/g, "") |
349 | | - } |
350 | | - } |
351 | | - return value |
352 | | - } |
353 | | -
|
354 | | - const handlePasteAOI = (event, type, field) => { |
355 | | - const pastedText = |
356 | | - (event && event.clipboardData && event.clipboardData.getData("text")) || |
357 | | - "" |
358 | | -
|
359 | | - if (!pastedText) return |
360 | | -
|
361 | | - const coordinates = pastedText.match(/[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g) |
362 | | - if (!coordinates || coordinates.length === 0) return |
363 | | -
|
364 | | - const sanitized = coordinates.map((c) => sanitizeNumberString(c)) |
365 | | -
|
366 | | - if (sanitized.length >= 2) { |
367 | | - if (field === "x" || type === "min") { |
368 | | - min_x.value = sanitized[0] |
369 | | - } else { |
370 | | - max_x.value = sanitized[0] |
371 | | - } |
372 | | - if (field === "y" || type === "min") { |
373 | | - min_y.value = sanitized[1] |
374 | | - } else { |
375 | | - max_y.value = sanitized[1] |
376 | | - } |
377 | | - event.preventDefault() |
378 | | - } else if (sanitized.length === 1) { |
379 | | - if (field === "x") { |
380 | | - if (type === "min") { |
381 | | - min_x.value = sanitized[0] |
382 | | - } else { |
383 | | - max_x.value = sanitized[0] |
384 | | - } |
385 | | - } else { |
386 | | - if (type === "min") { |
387 | | - min_y.value = sanitized[0] |
388 | | - } else { |
389 | | - max_y.value = sanitized[0] |
390 | | - } |
391 | | - } |
392 | | - event.preventDefault() |
393 | | - } |
394 | | - } |
395 | | -
|
396 | | - const sanitizeInputAOI = (value, field) => { |
397 | | - if (field === "min_x") min_x.value = sanitizeNumberString(value) |
398 | | - else if (field === "min_y") min_y.value = sanitizeNumberString(value) |
399 | | - else if (field === "max_x") max_x.value = sanitizeNumberString(value) |
400 | | - else if (field === "max_y") max_y.value = sanitizeNumberString(value) |
401 | | - } |
402 | 378 | </script> |
0 commit comments