Skip to content

Commit

Permalink
fix(bcf): select the right window/model when opening a BCF topic
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jul 20, 2022
1 parent a965595 commit ee72ea8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
24 changes: 23 additions & 1 deletion src/config/viewer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { MODEL_TYPE } from "./models.js";

const { DWG, DXF, IFC, JPEG, JPG, META_BUILDING, PDF, PNG } = MODEL_TYPE;

const AVAILABLE_PLUGINS = Object.freeze({
backgroundColor:
"https://unpkg.com/@bimdata/background-color-viewer-plugin@1.0.1",
Expand All @@ -18,6 +22,18 @@ const WINDOWS = Object.freeze({
V3D: "3d"
});

/**
* Define the type of models that can opened
* in each viewer window
*/
const WINDOW_MODELS = Object.freeze({
[WINDOWS.DWG]: [DWG],
[WINDOWS.DXF]: [DXF],
[WINDOWS.PLAN]: [JPEG, JPG, META_BUILDING, PDF, PNG],
[WINDOWS.V2D]: [IFC],
[WINDOWS.V3D]: [IFC]
});

const DEFAULT_WINDOW = WINDOWS.V3D;

const PLUGINS_CONFIG = {
Expand Down Expand Up @@ -47,4 +63,10 @@ const PLUGINS_CONFIG = {
bcfManager: true
};

export { AVAILABLE_PLUGINS, DEFAULT_WINDOW, PLUGINS_CONFIG, WINDOWS };
export {
AVAILABLE_PLUGINS,
DEFAULT_WINDOW,
PLUGINS_CONFIG,
WINDOW_MODELS,
WINDOWS
};
54 changes: 30 additions & 24 deletions src/views/project-board/project-bcf/ProjectBcf.vue
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,21 @@ import {
} from "@bimdata/bcf-components";
import { ref, watch } from "vue";
import { useRouter } from "vue-router";
import { useAppSidePanel } from "@/components/specific/app/app-side-panel/app-side-panel.js";
import { useStandardBreakpoints } from "@/composables/responsive.js";
import { useToggle } from "@/composables/toggle.js";
import { MODEL_STATUS, MODEL_TYPE } from "@/config/models.js";
import routeNames from "@/router/route-names.js";
import { useBcf } from "@/state/bcf.js";
import { useProjects } from "@/state/projects.js";
import { useModels } from "@/state/models.js";
import { useAppSidePanel } from "../../../components/specific/app/app-side-panel/app-side-panel.js";
import { useStandardBreakpoints } from "../../../composables/responsive.js";
import { useToggle } from "../../../composables/toggle.js";
import { MODEL_STATUS } from "../../../config/models.js";
import { DEFAULT_WINDOW, WINDOW_MODELS } from "../../../config/viewer.js";
import routeNames from "../../../router/route-names.js";
import { useBcf } from "../../../state/bcf.js";
import { useProjects } from "../../../state/projects.js";
import { useModels } from "../../../state/models.js";
// Components
import BcfStatisticsEmptyImage from "@/components/images/BcfStatisticsEmptyImage.vue";
import NoSearchResultsImage from "@/components/images/NoSearchResultsImage.vue";
import AppSlotContent from "@/components/specific/app/app-slot/AppSlotContent.vue";
import AppSidePanel from "@/components/specific/app/app-side-panel/AppSidePanel.vue";
import FileUploadButton from "@/components/specific/files/file-upload-button/FileUploadButton.vue";
import BcfStatisticsEmptyImage from "../../../components/images/BcfStatisticsEmptyImage.vue";
import NoSearchResultsImage from "../../../components/images/NoSearchResultsImage.vue";
import AppSlotContent from "../../../components/specific/app/app-slot/AppSlotContent.vue";
import AppSidePanel from "../../../components/specific/app/app-side-panel/AppSidePanel.vue";
import FileUploadButton from "../../../components/specific/files/file-upload-button/FileUploadButton.vue";
export default {
components: {
Expand Down Expand Up @@ -482,23 +483,27 @@ export default {
};
const openBcfTopicViewer = topic => {
let window = topic.viewpoints[0]?.authoring_tool_id ?? DEFAULT_WINDOW;
let modelIDs = [];
if (topic.ifcs?.length) {
modelIDs = topic.ifcs;
if (topic.models?.length > 0) {
modelIDs = topic.models;
} else {
const ifcs = projectModels.value
// If no models are specified on the topic
// get the last created model of proper type
// with respect to the target window
const models = projectModels.value
.filter(
model =>
model.type === MODEL_TYPE.IFC &&
model.status === MODEL_STATUS.COMPLETED
m =>
m.status === MODEL_STATUS.COMPLETED &&
WINDOW_MODELS[window].includes(m.type)
)
.sort((a, b) =>
a.created_at.getTime() > b.created_at.getTime() ? 1 : -1
);
if (ifcs.length > 0) {
modelIDs.push(ifcs[0].id);
.sort((a, b) => (a.created_at > b.created_at ? 1 : -1));
if (models.length > 0) {
modelIDs.push(models[0].id);
}
}
router.push({
name: routeNames.modelViewer,
params: {
Expand All @@ -507,6 +512,7 @@ export default {
modelIDs: modelIDs.join(",")
},
query: {
window,
topicGuid: topic.guid
}
});
Expand Down

0 comments on commit ee72ea8

Please sign in to comment.