Skip to content

Commit 940f1cc

Browse files
committed
refacto code + edit functions
1 parent ca3ddee commit 940f1cc

File tree

2 files changed

+86
-149
lines changed

2 files changed

+86
-149
lines changed

app/components/CreateAOI.vue

Lines changed: 82 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
UIStore.setShowCreateTools(true)
155155
UIStore.setShowCreatePoint(false)
156156
UIStore.setShowCreateAOI(false)
157+
UIStore.setShowCreateVOI(false)
157158
}
158159
159160
const UIStore = useUIStore()
@@ -166,7 +167,6 @@
166167
const max_x = ref("")
167168
const max_y = ref("")
168169
const z = ref("")
169-
170170
const loading = ref(false)
171171
172172
const isFormFilled = computed(() => {
@@ -182,12 +182,6 @@
182182
UIStore.setShowCreateAOI(false)
183183
}
184184
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-
191185
function visibleBoundingBox() {
192186
if (!hybridViewerStore.genericRenderWindow.value)
193187
return [-1, 1, -1, 1, -1, 1]
@@ -217,7 +211,7 @@
217211
max_x.value = newMaxX.toFixed(2)
218212
min_y.value = newMinY.toFixed(2)
219213
max_y.value = newMaxY.toFixed(2)
220-
z.value = (bounds[4] + bounds[5]) / 2
214+
z.value = ((bounds[4] + bounds[5]) / 2).toFixed(2)
221215
}
222216
223217
onMounted(() => {
@@ -229,10 +223,70 @@
229223
(newVal) => {
230224
if (newVal) {
231225
initializeAOICoordinates()
226+
name.value = ""
232227
}
233228
},
234229
)
235230
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+
236290
async function registerObject(data) {
237291
await viewer_call(
238292
{
@@ -243,40 +297,24 @@
243297
},
244298
{
245299
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, {
260301
object_type: data.object_type,
261302
geode_object: data.geode_object,
262303
native_filename: data.native_file_name,
263304
viewable_filename: data.viewable_file_name,
264305
displayed_name: data.name,
265-
points: aoiPoints,
266-
z: z_val,
306+
is_aoi: true,
267307
vtk_js: {
268308
binary_light_viewable: data.binary_light_viewable,
269309
},
270-
}
271-
272-
await dataBaseStore.addItem(data.id, itemToAdd)
273-
310+
})
274311
closeDrawer()
275312
},
276313
},
277314
)
278315
}
279-
async function createAOI() {
316+
317+
const createAOI = async () => {
280318
const min_x_val = safeParseFloat(min_x.value)
281319
const min_y_val = safeParseFloat(min_y.value)
282320
const max_x_val = safeParseFloat(max_x.value)
@@ -290,13 +328,12 @@
290328
isNaN(max_y_val) ||
291329
isNaN(z_val)
292330
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+
) {
300337
return
301338
}
302339
@@ -314,15 +351,22 @@
314351
}
315352
316353
const aoiSchema = back_schemas.opengeodeweb_back.create.create_aoi
354+
355+
loading.value = true
317356
try {
318-
await api_fetch(
357+
const response = await api_fetch(
319358
{
320359
schema: aoiSchema,
321360
params: aoiData,
322361
},
323362
{
324363
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)
326370
},
327371
},
328372
)
@@ -331,72 +375,4 @@
331375
loading.value = false
332376
}
333377
}
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-
}
402378
</script>

app/components/CreateVOI.vue

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
size="large"
133133
variant="flat"
134134
:loading="loading"
135-
:disabled="!isFormFilled || !selectedAOICoordinates"
135+
:disabled="!isFormFilled"
136136
@click="createVOI"
137137
class="text-none ml-4"
138138
>
@@ -168,23 +168,14 @@
168168
169169
const name = ref("")
170170
const selectedAOI = ref(null)
171-
const selectedAOICoordinates = ref(null)
172171
const z_min = ref("")
173172
const z_max = ref("")
174173
const loading = ref(false)
175174
176175
const aoiList = computed(() => {
177176
const items = []
178177
for (const [id, item] of Object.entries(dataBaseStore.db)) {
179-
if (
180-
item.geode_object === "EdgedCurve3D" &&
181-
item.object_type === "mesh" &&
182-
item.displayed_name &&
183-
!item.aoi_id &&
184-
item &&
185-
((item.min_x != null && item.max_x != null) ||
186-
(item.points && item.points.length >= 2))
187-
) {
178+
if (item.is_aoi === true && item.displayed_name) {
188179
items.push({
189180
id: id,
190181
name: item.displayed_name || item.native_filename || id,
@@ -229,35 +220,7 @@
229220
z_max.value = newMaxZ.toFixed(2)
230221
}
231222
232-
const extractAOICoordinates = (aoiItem) => {
233-
if (!aoiItem) return null
234-
235-
if (aoiItem && aoiItem.points) {
236-
const points = aoiItem.points
237-
if (points.length >= 4) {
238-
const min_x = Math.min(...points.map((p) => p.x))
239-
const min_y = Math.min(...points.map((p) => p.y))
240-
const max_x = Math.max(...points.map((p) => p.x))
241-
const max_y = Math.max(...points.map((p) => p.y))
242-
const z = aoiItem.z || 0
243-
244-
return { min_x, min_y, max_x, max_y, z, points }
245-
}
246-
}
247-
248-
return null
249-
}
250-
251-
const onAOISelected = (aoiId) => {
252-
selectedAOICoordinates.value = null
253-
254-
if (!aoiId) return
255-
256-
const aoiItem = dataBaseStore.db[aoiId]
257-
if (aoiItem) {
258-
selectedAOICoordinates.value = extractAOICoordinates(aoiItem)
259-
}
260-
}
223+
const onAOISelected = (aoiId) => {}
261224
262225
onMounted(() => {
263226
initializeVOICoordinates()
@@ -268,7 +231,6 @@
268231
(newVal) => {
269232
if (newVal) {
270233
initializeVOICoordinates()
271-
selectedAOICoordinates.value = null
272234
selectedAOI.value = null
273235
}
274236
},
@@ -290,7 +252,6 @@
290252
native_filename: data.native_file_name,
291253
viewable_filename: data.viewable_file_name,
292254
displayed_name: data.name,
293-
aoi_id: data.aoi_id,
294255
vtk_js: {
295256
binary_light_viewable: data.binary_light_viewable,
296257
},
@@ -302,7 +263,7 @@
302263
}
303264
304265
const createVOI = async () => {
305-
if (!name.value || !selectedAOI.value) {
266+
if (!isFormFilled.value) {
306267
return
307268
}
308269

0 commit comments

Comments
 (0)