measure_configuation_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import 'package:fis_i18n/i18n.dart';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:fis_measure/interfaces/process/player/play_controller.dart';
  4. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  5. import 'package:fis_measure/process/language/measure_language.dart';
  6. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  7. import 'package:fis_measure/process/workspace/measure_handler.dart';
  8. import 'package:fis_measure/view/measure/measure_config/widgets/measurement_tool_selection.dart';
  9. import 'package:fis_measure/view/measure/measure_view_controller.dart';
  10. import 'package:fis_measure/view/player/controller.dart';
  11. import 'package:fis_theme/theme.dart';
  12. import 'package:fis_ui/index.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:get/get.dart';
  15. ///条目元数据组
  16. class ItemMetaGroup {
  17. ItemMetaGroup(
  18. this.itemMetaGroupTitle,
  19. this.itemMeta,
  20. this.isExpend,
  21. );
  22. /// 当前测量组的名称
  23. final String itemMetaGroupTitle;
  24. /// 当前测量组的测量数组
  25. final List<ItemMetaDTO> itemMeta;
  26. /// 是否展开
  27. bool? isExpend;
  28. }
  29. /// 测量工具配置
  30. class MeasureConfigurationPage extends StatelessWidget {
  31. const MeasureConfigurationPage({Key? key}) : super(key: key);
  32. @override
  33. FWidget build(BuildContext context) {
  34. return const _MeasureConfigurationDialog();
  35. }
  36. }
  37. ///测量配置对话框
  38. class _MeasureConfigurationDialog extends StatefulWidget implements FWidget {
  39. const _MeasureConfigurationDialog({
  40. Key? key,
  41. }) : super(key: key);
  42. @override
  43. State<_MeasureConfigurationDialog> createState() =>
  44. _MeasureConfigurationDialogState();
  45. }
  46. class _MeasureConfigurationDialogState
  47. extends State<_MeasureConfigurationDialog> {
  48. int measureToolsTab = 0;
  49. /// 切换标签栏
  50. void changeTab(int index) {
  51. measureToolsTab = index;
  52. setState(() {});
  53. }
  54. late final application = Get.find<IApplication>();
  55. late final measureHandler = Get.find<MeasureHandler>();
  56. final playerController = Get.find<IPlayerController>() as VidPlayerController;
  57. /// 数据
  58. final measureData = Get.find<MeasureDataController>();
  59. /// 测量项控制器
  60. final measureMetaController = Get.find<MeasureMetaController>();
  61. /// 选中的测量项
  62. List<String> chooseMeasureList = [];
  63. List<ItemMetaGroup> itemMetaListGroup = [];
  64. String activeName = '';
  65. /// 打开已选测量工具设置
  66. ///
  67. /// [name] 测量的名字 后期改版后应该是一个测量对象
  68. void openHasSelectedSettingDialog(String name) {
  69. // state.childItemMeta = state.allItemMeta.firstWhere(
  70. // (element) => element.name == name,
  71. // );
  72. // router.dialog(() => HasSelectedSettingDialog(name: name));
  73. }
  74. Future<void> getName() async {
  75. List<String> getModes = [];
  76. for (var element in playerController.currentFrame?.visuals[0].modes ?? []) {
  77. getModes.add(element.type.toString().split('.')[1]);
  78. }
  79. var measureModeSelection = MeasureModeSelection(
  80. application.applicationName,
  81. application.categoryName,
  82. application.isThirdPart ? ['TPPTissue'] : getModes,
  83. );
  84. measureHandler.measureModeChanged = measureModeSelection;
  85. measureData.getMeasureApplicationList = [];
  86. var measureApplicationDTO =
  87. await measureData.getMeasureApplication.call(measureModeSelection);
  88. if (measureApplicationDTO != null) {
  89. /// 模式版本
  90. measureData.measureApplicationVersion =
  91. measureApplicationDTO.version ?? '';
  92. measureData.availableModes = measureApplicationDTO.availableModes ?? [];
  93. measureMetaController.setAvailableModes(measureData.currentMode);
  94. activeName = measureData.getItemMetaList[0].name;
  95. }
  96. }
  97. void changeItem(String? name) {
  98. activeName = name ?? '';
  99. application.switchItemByName(activeName);
  100. if (mounted) {
  101. setState(() {});
  102. }
  103. }
  104. void submit() async {
  105. var measureModeSubmitChanged = MeasureModeSubmit(
  106. measureData.measureApplicationVersion,
  107. application.applicationName,
  108. application.categoryName,
  109. UserDefinedMeasureModeDTO(
  110. modeName: measureData.currentMode,
  111. workingGroups: [
  112. UserDefinedMeasureGroupDTO(
  113. name: 'General',
  114. folders: [
  115. UserDefinedMeasureFolderDTO(
  116. name: 'General',
  117. workingItemNames: chooseMeasureList,
  118. ),
  119. ],
  120. ),
  121. ],
  122. ),
  123. );
  124. measureHandler.measureModeSubmitChanged = measureModeSubmitChanged;
  125. await measureData.saveUserDefinedMeasureApplicationAsync
  126. .call(measureModeSubmitChanged);
  127. getName();
  128. measureMetaController.setAvailableModes(measureData.currentMode);
  129. }
  130. @override
  131. void initState() {
  132. super.initState();
  133. List<String> chooseMeasure = [];
  134. measureMetaController.measureConfig();
  135. itemMetaListGroup = measureData.itemMetaListGroup;
  136. chooseMeasure = measureData.getMeasureApplicationList;
  137. chooseMeasureList = chooseMeasure.toSet().toList();
  138. }
  139. @override
  140. void dispose() {
  141. super.dispose();
  142. }
  143. @override
  144. FWidget build(BuildContext context) {
  145. return FSimpleDialog(
  146. title: FText(
  147. i18nBook.measure.measureToolConfig.t,
  148. style: const TextStyle(
  149. color: Colors.white,
  150. fontSize: 18,
  151. ),
  152. ),
  153. isDefault: true,
  154. onOk: () {
  155. submit();
  156. },
  157. onCancel: () {
  158. chooseMeasureList = measureData.getMeasureApplicationList;
  159. Get.back();
  160. setState(() {});
  161. },
  162. children: [
  163. FContainer(
  164. width: 830,
  165. height: 500,
  166. child: _buildMeasureconfiguration(),
  167. ),
  168. ],
  169. );
  170. }
  171. FWidget _buildMeasureconfiguration() {
  172. return FContainer(
  173. padding: const EdgeInsets.symmetric(horizontal: 15),
  174. child: FRow(
  175. crossAxisAlignment: CrossAxisAlignment.start,
  176. children: [
  177. FContainer(
  178. width: 170,
  179. decoration: const BoxDecoration(
  180. border: Border(
  181. right: BorderSide(
  182. color: Color.fromRGBO(235, 235, 235, 1),
  183. width: 1,
  184. ),
  185. ),
  186. ),
  187. child: FColumn(
  188. crossAxisAlignment: CrossAxisAlignment.end,
  189. children: [
  190. const FSizedBox(
  191. height: 10,
  192. ),
  193. FContainer(
  194. width: 160,
  195. child: FInkWell(
  196. onTap: () {
  197. changeTab(0);
  198. },
  199. child: FContainer(
  200. padding: const EdgeInsets.symmetric(
  201. vertical: 10,
  202. horizontal: 5,
  203. ),
  204. child: FText(
  205. i18nBook.measure.measureToolSelect.t,
  206. style: measureToolsTab == 0
  207. ? TextStyle(
  208. color: FTheme.ins.colorScheme.primary,
  209. )
  210. : const TextStyle(),
  211. textAlign: TextAlign.end,
  212. ),
  213. ),
  214. ),
  215. ),
  216. FContainer(
  217. width: 160,
  218. child: FInkWell(
  219. onTap: () {
  220. changeTab(1);
  221. },
  222. child: FContainer(
  223. padding: const EdgeInsets.symmetric(
  224. vertical: 10,
  225. horizontal: 5,
  226. ),
  227. child: FText(
  228. i18nBook.measure.selectedMeasureTool.t,
  229. style: measureToolsTab == 1
  230. ? TextStyle(
  231. color: FTheme.ins.colorScheme.primary,
  232. )
  233. : const TextStyle(),
  234. textAlign: TextAlign.end,
  235. ),
  236. ),
  237. ),
  238. ),
  239. ],
  240. ),
  241. ),
  242. measureToolsTab == 0
  243. ? FExpanded(
  244. child: FSingleChildScrollView(
  245. child: SelectModulePage(
  246. itemMetaListGroup: itemMetaListGroup,
  247. chooseMeasureList: chooseMeasureList,
  248. ),
  249. ),
  250. )
  251. : FExpanded(
  252. child: _HasSelectedModulePage(
  253. chooseMeasureList: chooseMeasureList,
  254. ),
  255. ),
  256. ],
  257. ),
  258. );
  259. }
  260. }
  261. class _HasSelectedModulePage extends StatelessWidget implements FWidget {
  262. final List<String> chooseMeasureList;
  263. /// 数据
  264. final measureData = Get.find<MeasureDataController>();
  265. _HasSelectedModulePage({
  266. required this.chooseMeasureList,
  267. });
  268. // /// 根据语言包翻译
  269. // ///
  270. // /// [code] 翻译编码
  271. // String getValues(String code) {
  272. // final value = MeasureLanguage().languageValue(code);
  273. // return value ?? code;
  274. // }
  275. @override
  276. FWidget build(BuildContext context) {
  277. return FListView(
  278. shrinkWrap: true,
  279. children: [
  280. FColumn(
  281. crossAxisAlignment: CrossAxisAlignment.start,
  282. children: [
  283. FContainer(
  284. padding: const EdgeInsets.only(left: 15, top: 15, bottom: 15),
  285. child: FWrap(
  286. spacing: 16.0, // 主轴(水平)方向间距
  287. runSpacing: 8.0, // 纵轴(垂直)方向间距
  288. direction: Axis.horizontal,
  289. crossAlignment: WrapCrossAlignment.center,
  290. alignment: WrapAlignment.start,
  291. children: List<FWidget>.generate(
  292. chooseMeasureList.length,
  293. (index) {
  294. return
  295. // FElevatedButton(
  296. // onPressed: () {
  297. // // controller.openHasSelectedSettingDialog(
  298. // // controller.state.chooseMeasureList[index],
  299. // // );
  300. // },
  301. // style: ButtonStyle(
  302. // backgroundColor: MaterialStateProperty.all(
  303. // Colors.white,
  304. // ),
  305. // ),
  306. // child:
  307. FContainer(
  308. width: 180,
  309. height: 60,
  310. decoration: BoxDecoration(
  311. border: Border.all(
  312. width: 0.5,
  313. color: FTheme.ins.colorScheme.primary,
  314. ),
  315. ),
  316. child: FColumn(
  317. mainAxisAlignment: MainAxisAlignment.center,
  318. children: [
  319. FText(
  320. chooseMeasureList[index].toString(),
  321. style: const TextStyle(
  322. color: Colors.black,
  323. ),
  324. ),
  325. FText(
  326. MeasureLanguage.t(
  327. chooseMeasureList[index].toString(),
  328. ),
  329. style: const TextStyle(
  330. color: Colors.black,
  331. ),
  332. ),
  333. ],
  334. ),
  335. // ),
  336. );
  337. },
  338. ),
  339. ),
  340. ),
  341. ],
  342. ),
  343. ],
  344. );
  345. }
  346. }