GetSourceParameters.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="row items-baseline">
  3. <div
  4. class="col-xs-12 col-sm-auto text-weight-bold text-center q-px-md q-py-sm"
  5. >
  6. <q-tooltip v-if="isInfoMode" anchor="top middle" self="center middle">
  7. current source settings<br />
  8. </q-tooltip>
  9. <div :style="flexRowTitleStyle">{{ rowTitle }}</div>
  10. </div>
  11. <div class="col-xs-grow col-sm">
  12. <div class="row justify-xs-center justify-sm-start items-baseline">
  13. <div class="col-auto">
  14. <input-with-units
  15. v-model:input-result="fromSource"
  16. v-model:is-showing-help="isShowingHelpForInputWithUnits"
  17. :initial-expression="fromSource.toString()"
  18. :units="sourceUnits"
  19. :is-info-mode="isInfoMode"
  20. :is-error="fromSource < $store.state.guiRuntime.safeFromWL"
  21. title="from"
  22. />
  23. </div>
  24. <div class="col-auto">
  25. <input-with-units
  26. v-model:input-result="toSource"
  27. v-model:is-showing-help="isShowingHelpForInputWithUnits"
  28. :initial-expression="toSource.toString()"
  29. :units="sourceUnits"
  30. :is-info-mode="isInfoMode"
  31. :is-error="toSource > $store.state.guiRuntime.safeToWL"
  32. title="to"
  33. />
  34. </div>
  35. <div v-if="!isInfoMode" class="col-auto">
  36. <input-with-units
  37. v-model:input-result="pointsSource"
  38. v-model:is-showing-help="isShowingHelpForInputWithUnits"
  39. :initial-expression="pointsSource.toString()"
  40. :title="isPointsToggle ? `points` : `step`"
  41. :units="isPointsToggle ? `` : sourceUnits"
  42. />
  43. <q-toggle v-model="isPointsToggle" dense class="q-ml-md" />
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script lang="ts">
  50. import { defineComponent, computed, ref } from 'vue';
  51. import { useStore } from 'src/store';
  52. import InputWithUnits from 'components/InputWithUnits.vue';
  53. import { fromUnits, toUnits, isAlmostSame } from 'components/utils';
  54. import { flexRowTitleStyle } from 'components/config';
  55. export default defineComponent({
  56. name: 'GetSourceParameters',
  57. components: { InputWithUnits },
  58. props: {
  59. isInfoMode: {
  60. type: Boolean,
  61. default: false,
  62. },
  63. },
  64. setup() {
  65. const isPointsToggle = ref(true);
  66. const $store = useStore();
  67. const isShowingHelpForInputWithUnits = computed({
  68. get: () => $store.state.guiRuntime.isShowingHelpForInputWithUnits,
  69. set: (val) =>
  70. $store.commit('guiRuntime/setIsShowingHelpForInputWithUnits', val),
  71. });
  72. const sourceUnits = computed(() => {
  73. return $store.state.guiRuntime.sourceUnits;
  74. });
  75. const fromWavelengthInSourceUnits = computed({
  76. get: () =>
  77. toUnits($store.state.simulationSetup.gui.fromWL, sourceUnits.value),
  78. set: (val) => {
  79. if (
  80. !isAlmostSame(
  81. $store.state.simulationSetup.gui.fromWL,
  82. fromUnits(sourceUnits.value, val)
  83. )
  84. ) {
  85. $store.commit(
  86. 'simulationSetup/setFromWL',
  87. fromUnits(sourceUnits.value, val)
  88. );
  89. }
  90. },
  91. });
  92. const toWavelengthInSourceUnits = computed({
  93. get: () =>
  94. toUnits($store.state.simulationSetup.gui.toWL, sourceUnits.value),
  95. set: (val) => {
  96. if (
  97. !isAlmostSame(
  98. $store.state.simulationSetup.gui.toWL,
  99. fromUnits(sourceUnits.value, val)
  100. )
  101. ) {
  102. $store.commit(
  103. 'simulationSetup/setToWL',
  104. fromUnits(sourceUnits.value, val)
  105. );
  106. }
  107. },
  108. });
  109. const rowTitle = computed(() => {
  110. if (sourceUnits.value.endsWith('Hz')) {
  111. return 'Frequency';
  112. }
  113. if (sourceUnits.value.endsWith('eV')) {
  114. return 'Energy';
  115. }
  116. if (sourceUnits.value.endsWith('s')) {
  117. return 'Period';
  118. }
  119. return 'Wavelength';
  120. });
  121. const directOrder = computed(() => {
  122. if (['Frequency', 'Energy'].includes(rowTitle.value)) return false;
  123. return true;
  124. });
  125. const fromSource = computed({
  126. get: () => {
  127. if (directOrder.value) return fromWavelengthInSourceUnits.value;
  128. return toWavelengthInSourceUnits.value;
  129. },
  130. set: (val) => {
  131. if (directOrder.value) fromWavelengthInSourceUnits.value = val;
  132. else toWavelengthInSourceUnits.value = val;
  133. },
  134. });
  135. const toSource = computed({
  136. get: () => {
  137. if (!directOrder.value) return fromWavelengthInSourceUnits.value;
  138. return toWavelengthInSourceUnits.value;
  139. },
  140. set: (val) => {
  141. if (!directOrder.value) fromWavelengthInSourceUnits.value = val;
  142. else toWavelengthInSourceUnits.value = val;
  143. },
  144. });
  145. const pointsSource = computed({
  146. get: () => {
  147. if (isPointsToggle.value)
  148. return $store.state.simulationSetup.gui.pointsWL;
  149. return (
  150. (toSource.value - fromSource.value) /
  151. ($store.state.simulationSetup.gui.pointsWL - 1)
  152. );
  153. },
  154. set: (val) => {
  155. if (isPointsToggle.value)
  156. $store.commit('simulationSetup/setPointsWL', val);
  157. else {
  158. $store.commit(
  159. 'simulationSetup/setPointsWL',
  160. 1 + (toSource.value - fromSource.value) / val
  161. );
  162. }
  163. },
  164. });
  165. return {
  166. fromSource,
  167. toSource,
  168. pointsSource,
  169. isShowingHelpForInputWithUnits,
  170. flexRowTitleStyle,
  171. rowTitle,
  172. sourceUnits,
  173. isPointsToggle,
  174. };
  175. },
  176. });
  177. </script>