123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- import 'package:fis_common/logger/logger.dart';
- import 'package:fis_measure/interfaces/process/items/item.dart';
- import 'package:fis_measure/interfaces/process/items/item_metas.dart';
- import 'package:fis_measure/interfaces/process/player/play_controller.dart';
- import 'package:fis_measure/interfaces/process/workspace/application.dart';
- import 'package:fis_measure/process/items/item_meta_convert.dart';
- import 'package:fis_measure/process/workspace/measure_data_controller.dart';
- import 'package:fis_measure/process/workspace/measure_handler.dart';
- import 'package:fis_measure/view/player/controller.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vid/us/vid_us_image.dart';
- /// 测量项页面
- class LeftSiderSelectMeasure extends FStatefulWidget {
- const LeftSiderSelectMeasure({Key? key}) : super(key: key);
- @override
- FState<LeftSiderSelectMeasure> createState() => LeftSiderSelectMeasureState();
- }
- class LeftSiderSelectMeasureState extends FState<LeftSiderSelectMeasure> {
- final ScrollController scrollController = ScrollController();
- late final application = Get.find<IApplication>();
- late final measureHandler = Get.find<MeasureHandler>();
- /// 数据
- late final measureData = Get.find<MeasureDataController>();
- final playerController = Get.find<IPlayerController>() as VidPlayerController;
- // final topMeasureItem = Get.put<ITopMeasureItem>();
- /// 当前选中的测量项目
- String activeName = '';
- /// 当前组合测量项
- ItemMeta? comboItemMeta;
- int? comboItemMetaActivedIndex;
- /// 是否展开组合测量项
- bool isCombo = false;
- void workingChildChanged(sender, int e) {
- comboItemMetaActivedIndex = e;
- setState(() {});
- }
- /// 切换测量项
- void changeItem(ItemMeta itemMeta) {
- activeName = itemMeta.name;
- try {
- application.switchItem(itemMeta);
- final item = application.activeMeasureItem!;
- if (item is ITopMeasureItem) {
- item.switchChild(0);
- item.workingChildChanged.addListener(workingChildChanged);
- }
- } catch (e) {
- logger.e("changeItem failed", e);
- }
- if (mounted) {
- setState(() {});
- }
- }
- /// 当前测量数据源变更
- void itemMetaList(Object s, dynamic e) {
- try {
- if (e != null) {
- setState(() {});
- }
- } catch (e) {
- debugPrint("callmethod fail " + e.toString());
- }
- }
- /// 获取组合测量项
- void comboList() {
- /// 格式化数据
- List<ItemMeta> itemMetaList = [];
- for (var element in measureData.itemMetaList) {
- if (measureData.getMeasureApplicationList.contains(element.name)) {
- itemMetaList.add(element);
- }
- }
- measureData.getItemMetaList = itemMetaList;
- measureData.getTopItemMetaList = measureData.getItemMetaList;
- }
- /// 获取当前图像的测量项,从第一帧取
- void currentFrameHandler(Object sender, VidUsImage e) async {
- List<String> getModes = [];
- for (var element in e.visuals[0].modes) {
- getModes.add(element.type.toString().split('.')[1]);
- }
- measureData.applicationModes = e.visuals[0].modes;
- measureData.currentMode = e.visuals[0].modes.first.type.name;
- var measureModeSelection = MeasureModeSelection(
- application.applicationName,
- application.categoryName,
- application.isThirdPart ? ['TPPTissue'] : getModes,
- );
- measureHandler.measureModeChanged = measureModeSelection;
- var measureApplicationDTO =
- await measureData.getMeasureApplication.call(measureModeSelection);
- if (measureApplicationDTO != null) {
- /// 模式版本
- measureData.measureApplicationVersion =
- measureApplicationDTO.version ?? '';
- measureData.availableModes = measureApplicationDTO.availableModes ?? [];
- ///模式列表
- var models = measureApplicationDTO.availableModes;
- if (models != null && models.isNotEmpty) {
- ///群组列表
- var groups = models[0].availableGroups;
- if (groups != null && groups.isNotEmpty) {
- ///项目列表
- var folders = groups[0].availableFolders;
- if (folders != null && folders.isNotEmpty) {
- measureData.getMeasureApplicationList =
- folders[0].workingItemNames ?? [];
- if (folders[0].availableItems != null) {
- measureData.itemMetaList =
- folders[0].availableItems!.map((element) {
- return ItemMetaConverter(element).output();
- }).toList();
- comboList();
- }
- print('测量方法集: ${measureData.getMeasureApplicationList.toString()}');
- if (measureData.getMeasureApplicationList.isNotEmpty) {
- changeItem(measureData.getItemMetaList[0]);
- }
- }
- }
- }
- }
- getNoteCommentsList();
- }
- /// 注释获取
- void getNoteCommentsList() async {
- List<String> commentsList = [];
- var measureCommentItemResult =
- await measureData.getCommentsByApplicationAsync(
- application.applicationName,
- application.categoryName,
- );
- measureData.measureCommentItemResult =
- measureCommentItemResult?.commentItems ?? [];
- measureCommentItemResult?.commentItems?.forEach((element) {
- commentsList.add(element.text ?? '');
- });
- measureData.getCommentsList = commentsList;
- }
- void getItemMetaListChanged(sender, e) {
- measureData.getTopItemMetaList = measureData.getItemMetaList;
- setState(() {});
- }
- @override
- void initState() {
- playerController.currentFrameHandler.addListener(
- (currentFrameHandler),
- );
- measureData.getItemMetaListChanged.addListener(getItemMetaListChanged);
- measureData.itemMetaListChanged.addListener(itemMetaList);
- super.initState();
- }
- @override
- dispose() {
- super.dispose();
- playerController.currentFrameHandler.removeListener(
- (currentFrameHandler),
- );
- measureData.getItemMetaListChanged.removeListener(getItemMetaListChanged);
- measureData.itemMetaListChanged.removeListener(itemMetaList);
- final item = application.activeMeasureItem!;
- if (item is ITopMeasureItem) {
- item.workingChildChanged.removeListener(workingChildChanged);
- }
- }
- @override
- FWidget build(BuildContext context) {
- return FSingleChildScrollView(
- controller: ScrollController(),
- child: FScrollbar(
- isAlwaysShown: true,
- child: FColumn(
- children: [
- _buildFGridView(measureData.getTopItemMetaList),
- if (isCombo) _buildCombo(),
- _buildFGridView(measureData.getBottomItemMetaList),
- ],
- ),
- ),
- );
- }
- /// 未选中的普通测量项 选中事件
- void chooseMeasure(ItemMeta itemMeta) {
- isCombo = false;
- changeItem(itemMeta);
- measureData.getTopItemMetaList = measureData.getItemMetaList;
- measureData.getBottomItemMetaList = [];
- }
- void chooseComboMeasure(ItemMeta itemMeta) {
- isCombo = true;
- changeItem(itemMeta);
- List<ItemMeta> top = [];
- List<ItemMeta> bottom = [];
- List<ItemMeta> getItemMetaList = measureData.getItemMetaList;
- for (int i = 0; i < getItemMetaList.length; i++) {
- if (i <= getItemMetaList.indexOf(itemMeta)) {
- top.add(getItemMetaList[i]);
- } else {
- bottom.add(getItemMetaList[i]);
- }
- measureData.getTopItemMetaList = top;
- measureData.getBottomItemMetaList = bottom;
- if (i == getItemMetaList.indexOf(itemMeta)) {
- comboItemMeta = getItemMetaList[i];
- comboItemMetaActivedIndex = 0;
- }
- }
- }
- FWidget _buildComboItem(ItemMeta itemMeta, int index) {
- FWidget child;
- if (comboItemMetaActivedIndex == index) {
- child = FElevatedButton(
- onPressed: () {
- final item = application.activeMeasureItem!;
- if (item is ITopMeasureItem) {
- item.switchChild(index);
- comboItemMetaActivedIndex = index;
- }
- setState(() {});
- },
- child: FText(
- itemMeta.name,
- style: const TextStyle(
- color: Colors.white,
- ),
- ),
- );
- } else {
- child = FOutlinedButton(
- onPressed: () {
- final item = application.activeMeasureItem!;
- if (item is ITopMeasureItem) {
- item.switchChild(index);
- comboItemMetaActivedIndex = index;
- }
- setState(() {});
- },
- style: OutlinedButton.styleFrom(
- side: const BorderSide(
- color: Color.fromRGBO(124, 124, 124, 1),
- ),
- ),
- child: FText(
- itemMeta.name,
- style: const TextStyle(
- color: Colors.white,
- ),
- ),
- );
- }
- return child;
- }
- /// 组合测量项打开的ui
- FWidget _buildCombo() {
- return FColumn(
- mainAxisSize: MainAxisSize.max,
- children: [
- FContainer(
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
- color: const Color.fromRGBO(70, 70, 70, 1),
- child: FColumn(
- children: (comboItemMeta?.childItems ?? [])
- .asMap()
- .entries
- .map(
- (e) => FContainer(
- width: double.infinity,
- padding: const EdgeInsets.symmetric(
- vertical: 2,
- ),
- child: _buildComboItem(
- e.value,
- e.key,
- ),
- ),
- )
- .toList(),
- ),
- ),
- ],
- );
- }
- FWidget _buildFGridView(List<ItemMeta> itemMeta) {
- return FGridView.count(
- shrinkWrap: true,
- crossAxisCount: 2,
- childAspectRatio: 3,
- controller: ScrollController(),
- children: itemMeta.map((e) {
- if (e.name == activeName) {
- // 选中的测量项
- return _buildItemMetaContainer(e, () {});
- } else {
- if (e.childItems.isEmpty) {
- return _buildItemMetaContainer(
- e,
- () => chooseMeasure(e),
- );
- } else {
- return _buildItemMetaContainer(
- e,
- () => chooseComboMeasure(e),
- );
- }
- }
- }).toList(),
- );
- }
- FWidget _buildItemMetaContainer(ItemMeta e, Function onTap) {
- FWidget measure;
- if (e.name == activeName) {
- measure = FElevatedButton(
- onPressed: () => onTap.call(),
- child: FText(e.name),
- style: ElevatedButton.styleFrom(
- fixedSize: const Size.fromHeight(
- 40,
- ),
- ),
- );
- } else {
- measure = FOutlinedButton(
- onPressed: () => onTap.call(),
- child: FText(
- e.name,
- style: const TextStyle(
- color: Colors.white,
- ),
- ),
- style: OutlinedButton.styleFrom(
- fixedSize: const Size.fromHeight(
- 40,
- ),
- side: const BorderSide(
- color: Color.fromRGBO(124, 124, 124, 1),
- ),
- textStyle: const TextStyle(
- color: Colors.white,
- ),
- ),
- );
- }
- return FRow(
- children: [
- const FSizedBox(
- width: 12,
- ),
- FExpanded(
- child: measure,
- ),
- const FSizedBox(
- width: 12,
- ),
- ],
- );
- }
- }
|