Skip to content

Commit

Permalink
Merge pull request #392 from boucaud/add-ruler-unit-choice
Browse files Browse the repository at this point in the history
feat(ruler): add global parameters for the ruler's unit symbol and factor
  • Loading branch information
floryst authored Apr 23, 2021
2 parents bb7bbc5 + a2707e4 commit 7e1c693
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/components/core/GlobalSettings/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ export default {
};
},
computed: {
distanceUnitSymbolModel: {
get() {
return this.distanceUnitSymbol;
},
set(symbol) {
this.setDistanceUnitSymbol(symbol);
},
},
distanceUnitFactorModel: {
get() {
return this.distanceUnitFactor;
},
set(factor) {
this.setDistanceUnitFactor(factor);
},
},
collapseDatasetPanelsModel: {
get() {
return this.collapseDatasetPanels;
Expand Down Expand Up @@ -150,6 +166,10 @@ export default {
firstPersonMovementSpeed: (state) => state.firstPersonMovementSpeed,
maxTextureLODSize: (state) => state.maxTextureLODSize,
}),
...mapState('widgets', {
distanceUnitSymbol: (state) => state.distanceUnitSymbol,
distanceUnitFactor: (state) => state.distanceUnitFactor,
}),
},
watch: {
physicalScale() {
Expand Down Expand Up @@ -226,5 +246,11 @@ export default {
setMaxTextureLODSize: (dispatch, size) =>
dispatch('setMaxTextureLODSize', size),
}),
...mapActions('widgets', {
setDistanceUnitSymbol: (dispatch, symbol) =>
dispatch('setDistanceUnitSymbol', symbol),
setDistanceUnitFactor: (dispatch, factor) =>
dispatch('setDistanceUnitFactor', factor),
}),
},
};
40 changes: 40 additions & 0 deletions src/components/core/GlobalSettings/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,46 @@
</v-layout>
</v-container>
</v-card>

<!-- measurement unit selection -->
<v-card flat :class="$style.card">
<div :class="$style.heading">
<span class="subtitle-2">Measurements</span>
</div>
<v-divider class="mb-4" />
<v-container grid-list-xs class="pa-0">
<v-layout row align-center class="pt-1">
<v-flex xs9>
<span class="body-2">Distance unit symbol</span>
</v-flex>
<v-flex xs3>
<v-text-field
:class="$style.slimInput"
hint="Symbol"
hide-details
v-model="distanceUnitSymbolModel"
required
/>
</v-flex>
<v-flex xs9>
<span class="body-2">Distance unit factor</span>
</v-flex>
<v-flex xs3>
<v-text-field
:class="$style.slimInput"
type="number"
hint="Factor"
hide-details
v-model="distanceUnitFactorModel"
:min="0"
:step="0.1"
required
/>
</v-flex>
</v-layout>
</v-container>
</v-card>

<v-card flat :class="$style.card">
<div :class="$style.heading">
<span class="subtitle-2">Background</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const RulerComponent = create2DTool('Ruler', {
},
getDisplayedMeasurements() {
return {
Length: `${this.measurements.length.toFixed(2)} mm`,
Length: `${(
this.measurements.length * (this.distanceUnitFactor || 1.0)
).toFixed(2)} ${this.distanceUnitSymbol || ''}`,
};
},
updateMeasurements() {
Expand Down Expand Up @@ -65,6 +67,14 @@ const RulerComponent = create2DTool('Ruler', {
});
},
},
watch: {
distanceUnitSymbol() {
this.widgetProxy.modified();
},
distanceUnitFactor() {
this.widgetProxy.modified();
},
},
});

export default RulerComponent;
5 changes: 5 additions & 0 deletions src/components/tools/MeasurementTools/tools/ToolTemplate2D.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WIDGETS } from 'paraview-glance/src/palette';
import { mapState } from 'vuex';

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -64,6 +65,10 @@ export default (toolName, extraComponent = {}) => ({
displayedMeasurements() {
return this.getDisplayedMeasurements();
},
...mapState('widgets', {
distanceUnitSymbol: (state) => state.distanceUnitSymbol,
distanceUnitFactor: (state) => state.distanceUnitFactor,
}),
},
watch: extraComponent.watch || {},
proxyManagerHooks: {
Expand Down
11 changes: 11 additions & 0 deletions src/store/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default ({ proxyManager }) => ({
state: {
measurements: {}, // dataset id -> [{component name, ...{measurement info}}]

distanceUnitSymbol: 'mm',
distanceUnitFactor: 1.0,

// paint
imageToLabelmaps: {}, // image id -> [labelmap ids]
labelmapStates: {}, // labelmap id -> { selectedLabel, lastColorIndex }
Expand All @@ -20,6 +23,12 @@ export default ({ proxyManager }) => ({
croppingStates: {}, // dataset id -> cropping state
},
mutations: {
setDistanceUnitSymbol(state, symbol) {
state.distanceUnitSymbol = symbol;
},
setDistanceUnitFactor(state, factor) {
state.distanceUnitFactor = factor;
},
addLabelmapToImage(state, { imageId, labelmapId }) {
if (!(imageId in state.imageToLabelmaps)) {
Vue.set(state.imageToLabelmaps, imageId, []);
Expand Down Expand Up @@ -72,6 +81,8 @@ export default ({ proxyManager }) => ({
removeMeasurementTool: wrapMutationAsAction('removeMeasurementTool'),
updateMeasurementTool: wrapMutationAsAction('updateMeasurementTool'),
setCroppingState: wrapMutationAsAction('setCroppingState'),
setDistanceUnitSymbol: wrapMutationAsAction('setDistanceUnitSymbol'),
setDistanceUnitFactor: wrapMutationAsAction('setDistanceUnitFactor'),
rewriteProxyIds: {
root: true,
handler: wrapMutationAsAction('rewriteProxyIds'),
Expand Down

0 comments on commit 7e1c693

Please sign in to comment.