Skip to content

Commit

Permalink
Merge pull request #330 from Kitware/fix-view-loading
Browse files Browse the repository at this point in the history
fix(VtkView): Mount views when they are created
  • Loading branch information
floryst authored May 3, 2020
2 parents 0706cb7 + 8b481c2 commit eae975d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
52 changes: 36 additions & 16 deletions src/components/core/VtkView/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default {
},
data() {
return {
internalViewId: -1,
internalIsActive: false,
palette: BACKGROUND,
backgroundSheet: false,
Expand Down Expand Up @@ -104,6 +105,11 @@ export default {
);
},
},
watch: {
view(view) {
this.tryMountView(view);
},
},
proxyManagerHooks: {
onActiveViewChange(view) {
this.internalIsActive = view === this.view;
Expand Down Expand Up @@ -141,30 +147,16 @@ export default {
},
mounted() {
if (this.view) {
this.view.setContainer(this.$el.querySelector('.js-view'));
const widgetManager = this.view.getReferenceByName('widgetManager');
if (widgetManager) {
widgetManager.setUseSvgLayer(true);
// workaround to disable picking if previously disabled
if (!widgetManager.getPickingEnabled()) {
widgetManager.disablePicking();
}
}
this.tryMountView(this.view);
}

window.addEventListener('resize', this.resizeCurrentView);

// Initial setup
this.resizeCurrentView();
},
beforeDestroy() {
if (this.view) {
const widgetManager = this.view.getReferenceByName('widgetManager');
if (widgetManager) {
// we can't use svg anyways if there is no container
widgetManager.setUseSvgLayer(false);
}
this.view.setContainer(null);
this.unmountView(this.view);
}
window.removeEventListener('resize', this.resizeCurrentView);
},
Expand All @@ -174,6 +166,34 @@ export default {
}
},
methods: {
tryMountView(view) {
if (this.internalViewId > -1) {
const oldView = this.$proxyManager.getProxyById(this.internalViewId);
this.unmountView(oldView);
this.internalViewId = -1;
}

if (view) {
this.internalViewId = view.getProxyId();
view.setContainer(this.$el.querySelector('.js-view'));
const widgetManager = view.getReferenceByName('widgetManager');
if (widgetManager) {
widgetManager.setUseSvgLayer(true);
// workaround to disable picking if previously disabled
if (!widgetManager.getPickingEnabled()) {
widgetManager.disablePicking();
}
}
}
},
unmountView(view) {
const widgetManager = view.getReferenceByName('widgetManager');
if (widgetManager) {
// we can't use svg anyways if there is no container
widgetManager.setUseSvgLayer(false);
}
view.setContainer(null);
},
changeViewType(viewType) {
this.swapViews({
index: this.layoutIndex,
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/VtkView/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<v-spacer />
<v-tooltip
top
v-if="view.getProxyName() === 'View3D'"
v-if="type === 'View3D'"
:disabled="smallScreen || viewPointMenuVisible"
>
<template v-slot:activator="{ on: tooltip }">
Expand Down

0 comments on commit eae975d

Please sign in to comment.