Skip to content
Draft
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
3 changes: 3 additions & 0 deletions app/stores/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export const useDataStore = defineStore("data", () => {
return components.map((component) => component.viewer_id)
}



async function exportStores() {
const items = await database.data.toArray()
return { items }
Expand Down Expand Up @@ -198,6 +200,7 @@ export const useDataStore = defineStore("data", () => {
getSurfacesGeodeIds,
getBlocksGeodeIds,
getMeshComponentsViewerIds,

exportStores,
importStores,
clear,
Expand Down
53 changes: 34 additions & 19 deletions app/stores/data_style.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
const modelStyleStore = useModelStyle()
const dataStore = useDataStore()

function addDataStyle(id, geode_object) {
dataStyleState.styles[id] = getDefaultStyle(geode_object)
async function addDataStyle(id, geode_object) {
await dataStyleState.updateStyle(id, getDefaultStyle(geode_object))
}

async function setVisibility(id, visibility) {
const item = await database.data.get(id)
const item = await dataStore.item(id)
const viewer_type = item?.viewer_type
if (!viewer_type) {
throw new Error(`Item not found or not loaded: ${id}`)
Expand All @@ -32,7 +32,7 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
}

async function applyDefaultStyle(id) {
const item = await database.data.get(id)
const item = await dataStore.item(id)
const viewer_type = item?.viewer_type
if (!viewer_type) {
throw new Error(`Item not found or not loaded: ${id}`)
Expand All @@ -48,40 +48,55 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
}

function exportStores() {
return { styles: dataStyleState.styles }
return {
styles: dataStyleState.styles,
componentStyles: dataStyleState.componentStyles,
}
}

function importStores(snapshot) {
async function importStores(snapshot) {
const stylesSnapshot = snapshot.styles || {}
for (const id of Object.keys(dataStyleState.styles)) {
delete dataStyleState.styles[id]
}
const componentStylesSnapshot = snapshot.componentStyles || {}

await dataStyleState.clear()

for (const [id, style] of Object.entries(stylesSnapshot)) {
dataStyleState.styles[id] = style
await dataStyleState.updateStyle(id, style)
}

for (const style of Object.values(componentStylesSnapshot)) {
await dataStyleState.updateComponentStyle(
style.id_model,
style.id_component,
style,
)
}
}

async function applyAllStylesFromState() {
const ids = Object.keys(dataStyleState.styles || {})
const rootIds = Object.keys(dataStyleState.styles || {})
const promises = []
for (const id of ids) {

// Apply root model/mesh styles
for (const id of rootIds) {
const meta = await dataStore.item(id)
const viewerType = meta?.viewer_type
const style = dataStyleState.styles[id]
if (style && viewerType === "mesh") {
if (!meta) continue
const viewerType = meta.viewer_type
if (viewerType === "mesh") {
promises.push(meshStyleStore.applyMeshStyle(id))
} else if (style && viewerType === "model") {
} else if (viewerType === "model") {
promises.push(modelStyleStore.applyModelStyle(id))
}
}

return Promise.all(promises)
}

return {
styles: dataStyleState.styles,
styles: computed(() => dataStyleState.styles),
getStyle: dataStyleState.getStyle,
objectVisibility: dataStyleState.objectVisibility,
selectedObjects: dataStyleState.selectedObjects,
objectVisibility: computed(() => dataStyleState.objectVisibility),
selectedObjects: computed(() => dataStyleState.selectedObjects),
...meshStyleStore,
...modelStyleStore,
addDataStyle,
Expand Down
3 changes: 3 additions & 0 deletions app/stores/infra.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { appMode, getAppMode } from "@ogw_front/utils/app_mode"
import Status from "@ogw_front/utils/status"
import { useLambdaStore } from "@ogw_front/stores/lambda"
import { database } from "../../internal/database/database"

export const useInfraStore = defineStore("infra", {
state: () => ({
Expand Down Expand Up @@ -39,6 +40,8 @@ export const useInfraStore = defineStore("infra", {
},
async create_backend() {
console.log("[INFRA] Starting create_backend - Mode:", this.app_mode)
await database.clear()

console.log(
"[INFRA] Registered microservices:",
this.microservices.map((store) => store.$id),
Expand Down
20 changes: 10 additions & 10 deletions app/stores/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ export const useMenuStore = defineStore("menu", () => {
}

async function openMenu(id, x, y, width, height, top, left, meta_data) {
await closeMenu()

if (meta_data) {
const items = getMenuItems(
meta_data.viewer_type,
meta_data.geode_object_type,
)
if (items.length === 0) {
return
}
if (!id || !meta_data) {
return
}
const items = getMenuItems(
meta_data.viewer_type,
meta_data.geode_object_type,
)
if (items.length === 0) {
return
}
await closeMenu()

current_id.value = id
current_meta_data.value = meta_data || {}
Expand Down
41 changes: 41 additions & 0 deletions app/utils/file_import_workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,49 @@ async function importWorkflow(files) {

function buildImportItemFromPayloadApi(value, geode_object_type) {
console.log("buildImportItemFromPayloadApi", { value, geode_object_type })
const mesh_types = [
"EdgedCurve2D",
"EdgedCurve3D",
"Graph",
"HybridSolid3D",
"LightRegularGrid2D",
"LightRegularGrid3D",
"PointSet2D",
"PointSet3D",
"PolygonalSurface2D",
"PolygonalSurface3D",
"PolyhedralSolid3D",
"RasterImage2D",
"RasterImage3D",
"RegularGrid2D",
"RegularGrid3D",
"TetrahedralSolid3D",
"TriangulatedSurface2D",
"TriangulatedSurface3D",
]
const model_types = [
"BRep",
"CrossSection",
"ImplicitCrossSection",
"ImplicitStructuralModel",
"Section",
"StructuralModel",
]

let viewer_type = value.viewer_type
const geode_type = value.geode_object_type || geode_object_type
if (!viewer_type) {
if (mesh_types.includes(geode_type)) {
viewer_type = "mesh"
} else if (model_types.includes(geode_type)) {
viewer_type = "model"
}
}

return {
...value,
geode_object_type: geode_type,
viewer_type: viewer_type,
}
}

Expand Down
14 changes: 14 additions & 0 deletions internal/database/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Dexie } from "dexie"
import { ExtendedDatabase } from "./extended_database"
import { dataTable } from "./tables/data_table"
import { modelComponentsTable } from "./tables/model_components"
import { dataStyleTable } from "./tables/data_style"
import { modelComponentDataStyleTable } from "./tables/model_component_datastyle"

class Database extends Dexie {
constructor() {
Expand All @@ -10,9 +12,15 @@ class Database extends Dexie {
this.version(1).stores({
[dataTable.name]: dataTable.schema,
[modelComponentsTable.name]: modelComponentsTable.schema,
[dataStyleTable.name]: dataStyleTable.schema,
[modelComponentDataStyleTable.name]: modelComponentDataStyleTable.schema,
})
}

async clear() {
return Promise.all(this.tables.map((table) => table.clear()))
}

static async addTable(tableName, schemaDefinition) {
await this.addTables({ [tableName]: schemaDefinition })
}
Expand All @@ -26,6 +34,9 @@ class Database extends Dexie {

currentStores[dataTable.name] = dataTable.schema
currentStores[modelComponentsTable.name] = modelComponentsTable.schema
currentStores[dataStyleTable.name] = dataStyleTable.schema
currentStores[modelComponentDataStyleTable.name] =
modelComponentDataStyleTable.schema

for (const table of tempDb.tables) {
const keyPath = table.schema.primKey.src
Expand All @@ -49,6 +60,9 @@ class Database extends Dexie {
existingDb.version(1).stores({
[dataTable.name]: dataTable.schema,
[modelComponentsTable.name]: modelComponentsTable.schema,
[dataStyleTable.name]: dataStyleTable.schema,
[modelComponentDataStyleTable.name]:
modelComponentDataStyleTable.schema,
})
} else {
existingDb.version(version).stores(currentStores)
Expand Down
4 changes: 4 additions & 0 deletions internal/database/extended_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export class ExtendedDatabase extends Dexie {
...newTables,
})
}

async clear() {
return Promise.all(this.tables.map((table) => table.clear()))
}
}
4 changes: 4 additions & 0 deletions internal/database/tables/data_style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const dataStyleTable = {
name: "data_style",
schema: "id",
}
4 changes: 4 additions & 0 deletions internal/database/tables/model_component_datastyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const modelComponentDataStyleTable = {
name: "model_component_datastyle",
schema: "[id_model+id_component]",
}
2 changes: 1 addition & 1 deletion internal/database/tables/model_components.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const modelComponentsTable = {
name: "model_components",
schema: "[id+geode_id], [id+type], viewer_id, name",
schema: "[id+geode_id], [id+type], viewer_id, geode_id, name",
}
Loading